Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health Command created; please check over #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_notify_channel() -> str | None:
return None

def extract(self, session: Session) -> Query:
commands = [Type.CUTDOWN, Type.PING, Type.VALVE]
commands = [Type.CUTDOWN, Type.PING, Type.VALVE, Type.HEALTH_QUERY_COMMAND]
return session.query(ReceivedPackets).filter(ReceivedPackets.packet_type.in_(commands), ReceivedPackets.processed == False)\
.order_by(ReceivedPackets.id)

Expand Down
13 changes: 12 additions & 1 deletion postgresDB/dbApp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from EosLib.format.definitions import Type
from EosLib.format.formats.cutdown import CutDown
from EosLib.format.formats.ping_format import Ping
from EosLib.format.formats.health.health_query import HealthQuery
from EosLib.device import Device
from EosLib.packet import Packet
from EosLib.packet.data_header import DataHeader
Expand Down Expand Up @@ -68,7 +69,7 @@ def transmitTableInsert(request):
transmitTable.priority = Priority.DATA
transmitTable.generate_time = datetime.now()

valid_commands = {"cutdown", "ping", "valve", "clear"}
valid_commands = {"cutdown", "ping", "valve", "clear", "healthQuery"}
if command not in valid_commands:
return Response({'message': 'Invalid command'}, status=status.HTTP_400_BAD_REQUEST)

Expand Down Expand Up @@ -108,6 +109,16 @@ def transmitTableInsert(request):
cursor.execute("NOTIFY update;")
connection.commit()
return Response({'message': 'Valve command sent ', 'ack': ack}, status=status.HTTP_200_OK)
elif command == "healthQuery":
healthQuery_body = HealthQuery(command_parts[1], command_parts[2])
healthQuery_body_bytes = healthQuery_body.encode()
transmitTable.packet_type = Type.HEALTHQUERY
transmitTable.destination = Device.HEALTHQUERY
transmitTable.body = healthQuery_body_bytes
transmitTable.save()
cursor.execute("NOTIFY update;")
connection.commit()
return Response({'message': 'Health Query command sent ', 'ack': ack}, status=status.HTTP_200_OK)

return Response({'message': 'Invalid input or method'}, status=status.HTTP_400_BAD_REQUEST)

Expand Down