2023-12-13 11:23:55 +01:00
|
|
|
import struct
|
|
|
|
import datetime
|
|
|
|
import math
|
|
|
|
|
|
|
|
from spacepackets.ecss import PusService, PusTelecommand
|
2022-11-02 19:49:07 +01:00
|
|
|
from tmtccmd.config import CoreServiceList
|
|
|
|
from tmtccmd.config.tmtc import (
|
|
|
|
OpCodeEntry,
|
2023-12-13 11:23:55 +01:00
|
|
|
TmtcDefinitionWrapper,
|
|
|
|
tmtc_definitions_provider,
|
2022-11-02 19:49:07 +01:00
|
|
|
)
|
2023-12-13 11:23:55 +01:00
|
|
|
from tmtccmd.pus.s11_tc_sched import create_time_tagged_cmd
|
2023-01-19 13:29:01 +01:00
|
|
|
from tmtccmd.pus.s17_test import create_service_17_ping_command
|
2023-11-10 19:23:06 +01:00
|
|
|
from tmtccmd.tmtc import service_provider
|
|
|
|
from tmtccmd.tmtc.decorator import ServiceProviderParams
|
2022-11-02 19:49:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class OpCodes:
|
|
|
|
PING = "ping"
|
|
|
|
TRIGGER_EVENT = "trig_event"
|
|
|
|
PING_WITH_DATA = "ping_with_data"
|
2023-12-13 11:23:55 +01:00
|
|
|
SCHEDULE_PING = "sched_ping"
|
2022-11-02 19:49:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
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-12-13 11:23:55 +01:00
|
|
|
SCHEDULE_PING = "Schedule a ping"
|
2022-11-02 19:49:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
@tmtc_definitions_provider
|
2022-11-02 19:52:55 +01:00
|
|
|
def add_test_defs(defs: TmtcDefinitionWrapper):
|
2022-11-02 19:49:07 +01:00
|
|
|
oce = OpCodeEntry()
|
|
|
|
oce.add(keys=OpCodes.PING, info=Info.PING)
|
|
|
|
oce.add(keys=OpCodes.TRIGGER_EVENT, info=Info.TRIGGER_EVENT)
|
|
|
|
oce.add(keys=OpCodes.PING_WITH_DATA, info=Info.PING_WITH_DATA)
|
2023-12-13 11:23:55 +01:00
|
|
|
oce.add(keys=OpCodes.SCHEDULE_PING, info=Info.SCHEDULE_PING)
|
2022-11-02 19:49:07 +01:00
|
|
|
|
|
|
|
defs.add_service(
|
2022-11-02 19:52:55 +01:00
|
|
|
name=CoreServiceList.SERVICE_17_ALT,
|
|
|
|
info="PUS 17 Test Service",
|
|
|
|
op_code_entry=oce,
|
2022-11-02 19:49:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-02 19:52:55 +01:00
|
|
|
@service_provider(CoreServiceList.SERVICE_17_ALT)
|
2022-11-02 19:49:07 +01:00
|
|
|
def pack_test_command(p: ServiceProviderParams):
|
|
|
|
info = p.info
|
|
|
|
q = p.queue_helper
|
|
|
|
if info.op_code == OpCodes.PING:
|
|
|
|
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())
|
2022-11-02 19:49:07 +01:00
|
|
|
if info.op_code == OpCodes.TRIGGER_EVENT:
|
|
|
|
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-12-13 11:23:55 +01:00
|
|
|
if info.op_code == OpCodes.SCHEDULE_PING:
|
|
|
|
q.add_log_cmd("Sending scheduled PUS ping")
|
|
|
|
# Generate a UNIX timestamp 30 seconds in the future using the datetime API with a UTC timezone
|
|
|
|
now = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
|
|
second_offset_to_now = input("Please specify offset to now in seconds: ")
|
|
|
|
now += datetime.timedelta(seconds=int(second_offset_to_now))
|
|
|
|
unix_stamp = struct.pack("!I", math.floor(now.timestamp()))
|
|
|
|
print(f"Sending ping scheuled at {now}")
|
|
|
|
ping = PusTelecommand(service=PusService.S17_TEST, subservice=128)
|
|
|
|
q.add_pus_tc(
|
|
|
|
create_time_tagged_cmd(
|
|
|
|
release_time=unix_stamp,
|
|
|
|
tc_to_insert=ping,
|
|
|
|
)
|
|
|
|
)
|
2022-11-02 19:49:07 +01:00
|
|
|
if info.op_code == OpCodes.PING_WITH_DATA:
|
|
|
|
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
|
|
|
|
for i in range(data_size):
|
|
|
|
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
|
|
|
)
|
|
|
|
)
|