eive-tmtc/eive_tmtc/tmtc/test.py

51 lines
1.8 KiB
Python
Raw Normal View History

2023-11-22 13:51:33 +01:00
from spacepackets.ecss import PusService, PusTelecommand
from tmtccmd.config import CmdTreeNode
2023-01-19 13:29:01 +01:00
from tmtccmd.pus.s17_test import create_service_17_ping_command
2023-11-22 13:51:33 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
2022-11-02 19:49:07 +01:00
2023-11-22 13:51:33 +01:00
class OpCode:
2022-11-02 19:49:07 +01:00
PING = "ping"
TRIGGER_EVENT = "trig_event"
PING_WITH_DATA = "ping_with_data"
class Info:
PING = "Simple Ping and Connection Test"
TRIGGER_EVENT = "Trigger an event"
PING_WITH_DATA = "Ping with data. Size of sent data is sent back"
2023-11-22 13:51:33 +01:00
def create_test_node() -> CmdTreeNode:
node = CmdTreeNode("test", "Test Commands")
node.add_child(CmdTreeNode(OpCode.PING, Info.PING))
node.add_child(CmdTreeNode(OpCode.TRIGGER_EVENT, Info.TRIGGER_EVENT))
node.add_child(CmdTreeNode(OpCode.PING_WITH_DATA, Info.PING_WITH_DATA))
return node
2022-11-02 19:49:07 +01:00
2023-11-22 13:51:33 +01:00
def pack_test_command(q: DefaultPusQueueHelper, cmd_path: str):
if cmd_path == OpCode.PING:
2022-11-02 19:49:07 +01:00
q.add_log_cmd("Sending PUS TC [17,1]")
2023-01-19 13:29:01 +01:00
q.add_pus_tc(create_service_17_ping_command())
2023-11-22 13:51:33 +01:00
if cmd_path == OpCode.TRIGGER_EVENT:
2022-11-02 19:49:07 +01:00
q.add_log_cmd("Sending PUS TC Event Trigger [17, 128]")
2023-01-16 15:05:33 +01:00
q.add_pus_tc(PusTelecommand(service=PusService.S17_TEST, subservice=128))
2023-11-22 13:51:33 +01:00
if cmd_path == OpCode.PING_WITH_DATA:
2022-11-02 19:49:07 +01:00
q.add_log_cmd("Sending Ping With Data, Size Reported Back [17, 129]")
while True:
data_size = int(input("Please specify data size [0-1024]: "))
if data_size < 0 or data_size > 1024:
print("Invalid data size")
break
2022-11-02 20:02:00 +01:00
dummy_data = bytearray()
next_byte = True
2023-11-22 13:51:33 +01:00
for _ in range(data_size):
2022-11-02 20:02:00 +01:00
dummy_data.append(int(next_byte))
next_byte = not next_byte
2022-11-02 19:49:07 +01:00
q.add_pus_tc(
PusTelecommand(
2023-01-16 15:05:33 +01:00
service=PusService.S17_TEST, subservice=130, app_data=dummy_data
2022-11-02 19:49:07 +01:00
)
)