2022-06-21 16:49:11 +02:00
|
|
|
import enum
|
2022-06-27 20:18:26 +02:00
|
|
|
import json
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2022-09-27 17:35:58 +02:00
|
|
|
from spacepackets.ecss import PusTelecommand
|
2023-11-22 11:21:26 +01:00
|
|
|
from tmtccmd.config.tmtc import CmdTreeNode
|
2023-11-10 19:23:06 +01:00
|
|
|
from tmtccmd.pus.s8_fsfw_action import create_action_cmd
|
2023-11-22 11:21:26 +01:00
|
|
|
from tmtccmd.pus.s200_fsfw_mode import Mode, Subservice, pack_mode_data
|
|
|
|
from tmtccmd.tmtc import DefaultPusQueueHelper
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2023-11-22 11:21:26 +01:00
|
|
|
from eive_tmtc.config.object_ids import SCEX_HANDLER_ID
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2022-06-27 20:18:26 +02:00
|
|
|
USE_SCEX_CONF_FILE = True
|
|
|
|
|
|
|
|
|
2023-01-16 14:13:06 +01:00
|
|
|
class OpCode:
|
2023-07-27 09:59:34 +02:00
|
|
|
PING = "ping"
|
|
|
|
ION_CMD = "ion"
|
|
|
|
TEMP_CMD = "temp"
|
|
|
|
EXP_STATUS_CMD = "expstatus"
|
2022-06-27 20:18:26 +02:00
|
|
|
|
2023-07-27 09:59:34 +02:00
|
|
|
ONE_CELLS_CMD = "onecell"
|
|
|
|
ALL_CELLS_CMD = "allcells"
|
|
|
|
FRAM = "fram"
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2023-07-27 09:59:34 +02:00
|
|
|
SWITCH_ON = "on"
|
2023-11-22 11:21:26 +01:00
|
|
|
SWITCH_OFF = "off"
|
2023-10-10 18:29:07 +02:00
|
|
|
NORMAL = "normal"
|
2022-09-27 17:35:58 +02:00
|
|
|
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2023-01-16 14:13:06 +01:00
|
|
|
class ActionId(enum.IntEnum):
|
2022-06-21 16:49:11 +02:00
|
|
|
PING = 7
|
2022-06-21 18:15:17 +02:00
|
|
|
ION_CMD = 4
|
2022-06-27 20:18:26 +02:00
|
|
|
TEMP_CMD = 3
|
|
|
|
EXP_STATUS_CMD = 2
|
|
|
|
|
|
|
|
ONE_CELLS_CMD = 6
|
|
|
|
ALL_CELLS_CMD = 5
|
|
|
|
FRAM = 1
|
2022-06-21 16:49:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Info:
|
|
|
|
PING = "Send Ping command"
|
2022-06-27 20:18:26 +02:00
|
|
|
ION_CMD = "Read Ion"
|
|
|
|
TEMP_CMD = "Read Temperature"
|
|
|
|
EXP_STATUS_CMD = "Read Experiment Status"
|
|
|
|
|
|
|
|
ONE_CELLS_CMD = "One Cell"
|
|
|
|
ALL_CELLS_CMD = "All Cells"
|
|
|
|
FRAM = "Read FRAM"
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2022-09-27 17:35:58 +02:00
|
|
|
SWITCH_ON = "Switch Scex on"
|
2022-09-28 17:01:26 +02:00
|
|
|
SWITCH_OFF = "Switch Scex off"
|
2023-10-10 18:29:07 +02:00
|
|
|
NORMAL = "Switch SCEX to normal mode"
|
2022-09-27 17:35:58 +02:00
|
|
|
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2023-11-22 11:21:26 +01:00
|
|
|
def create_scex_node() -> CmdTreeNode:
|
|
|
|
op_code_strs = [
|
|
|
|
getattr(OpCode, key) for key in dir(OpCode) if not key.startswith("__")
|
|
|
|
]
|
|
|
|
info_strs = [getattr(Info, key) for key in dir(OpCode) if not key.startswith("__")]
|
|
|
|
combined_dict = dict(zip(op_code_strs, info_strs))
|
|
|
|
scex_node = CmdTreeNode("ploc_mpsoc", "PLOC MPSoC")
|
|
|
|
for op_code, info in combined_dict.items():
|
|
|
|
scex_node.add_child(CmdTreeNode(op_code, info))
|
|
|
|
return scex_node
|
2022-06-21 16:49:11 +02:00
|
|
|
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
def pack_scex_cmds(q: DefaultPusQueueHelper, cmd_str: str): # noqa C901
|
2023-11-22 11:21:26 +01:00
|
|
|
if cmd_str == OpCode.SWITCH_ON:
|
2022-09-27 17:35:58 +02:00
|
|
|
q.add_log_cmd(Info.SWITCH_ON)
|
|
|
|
q.add_pus_tc(
|
|
|
|
PusTelecommand(
|
|
|
|
service=200,
|
2023-01-17 18:37:16 +01:00
|
|
|
subservice=Subservice.TC_MODE_COMMAND,
|
2023-01-16 15:05:33 +01:00
|
|
|
app_data=pack_mode_data(SCEX_HANDLER_ID, Mode.ON, 0),
|
2022-09-27 17:35:58 +02:00
|
|
|
)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.NORMAL:
|
2023-10-10 18:29:07 +02:00
|
|
|
q.add_log_cmd(Info.NORMAL)
|
|
|
|
q.add_pus_tc(
|
|
|
|
PusTelecommand(
|
|
|
|
service=200,
|
|
|
|
subservice=Subservice.TC_MODE_COMMAND,
|
|
|
|
app_data=pack_mode_data(SCEX_HANDLER_ID, Mode.NORMAL, 0),
|
|
|
|
)
|
|
|
|
)
|
2023-11-22 11:21:26 +01:00
|
|
|
if cmd_str == OpCode.SWITCH_OFF:
|
2022-09-28 17:01:26 +02:00
|
|
|
q.add_log_cmd(Info.SWITCH_OFF)
|
|
|
|
q.add_pus_tc(
|
|
|
|
PusTelecommand(
|
|
|
|
service=200,
|
2023-01-17 18:37:16 +01:00
|
|
|
subservice=Subservice.TC_MODE_COMMAND,
|
2023-01-16 15:05:33 +01:00
|
|
|
app_data=pack_mode_data(SCEX_HANDLER_ID, Mode.OFF, 0),
|
2022-09-28 17:01:26 +02:00
|
|
|
)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.PING:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.PING)
|
2022-06-21 16:49:11 +02:00
|
|
|
app_data = bytes([0])
|
2023-01-18 11:32:21 +01:00
|
|
|
q.add_pus_tc(create_action_cmd(SCEX_HANDLER_ID, ActionId.PING, app_data))
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.ION_CMD:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.ION_CMD)
|
2022-06-27 20:18:26 +02:00
|
|
|
app_data = bytes([0])
|
2023-01-18 11:32:21 +01:00
|
|
|
q.add_pus_tc(create_action_cmd(SCEX_HANDLER_ID, ActionId.ION_CMD, app_data))
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.TEMP_CMD:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.TEMP_CMD)
|
2022-06-27 20:18:26 +02:00
|
|
|
app_data = bytes([0])
|
2023-01-18 11:32:21 +01:00
|
|
|
q.add_pus_tc(create_action_cmd(SCEX_HANDLER_ID, ActionId.TEMP_CMD, app_data))
|
2022-06-27 20:18:26 +02:00
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.EXP_STATUS_CMD:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.EXP_STATUS_CMD)
|
2022-06-21 18:15:17 +02:00
|
|
|
app_data = bytes([0])
|
2022-08-08 16:32:18 +02:00
|
|
|
q.add_pus_tc(
|
2023-01-18 11:32:21 +01:00
|
|
|
create_action_cmd(SCEX_HANDLER_ID, ActionId.EXP_STATUS_CMD, app_data)
|
2022-08-08 16:32:18 +02:00
|
|
|
)
|
2022-06-21 16:49:11 +02:00
|
|
|
|
2022-06-21 18:15:17 +02:00
|
|
|
# one cell
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.ONE_CELLS_CMD:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.ONE_CELLS_CMD)
|
2022-08-30 16:32:50 +02:00
|
|
|
app_data = bytearray([0])
|
2022-06-27 20:18:26 +02:00
|
|
|
|
|
|
|
# cell number
|
2022-07-08 16:21:01 +02:00
|
|
|
cn = 0
|
2022-06-27 20:18:26 +02:00
|
|
|
while True:
|
|
|
|
cell_select = input("Which solar cell should be measured? (1-10): ")
|
|
|
|
if not cell_select.isdigit():
|
|
|
|
print("Invalid cell number. Try again.")
|
|
|
|
continue
|
|
|
|
cell_select = int(cell_select)
|
|
|
|
if cell_select < 1 or cell_select > 10:
|
|
|
|
print(
|
2023-09-12 13:48:38 +02:00
|
|
|
f"Invalid cell number {cell_select}, Please enter a valid number: "
|
2022-06-27 20:18:26 +02:00
|
|
|
)
|
|
|
|
continue
|
|
|
|
cn = cell_select - 1
|
|
|
|
break
|
|
|
|
|
|
|
|
if USE_SCEX_CONF_FILE:
|
|
|
|
with open("template/scex_conf.json") as json_file:
|
|
|
|
json_data = json.load(json_file)
|
|
|
|
first_dac = json_data["first_dac"]
|
|
|
|
last_dac = json_data["last_dac"]
|
|
|
|
res_switch1 = json_data["res_switch1"]
|
|
|
|
res_switch2 = json_data["res_switch2"]
|
|
|
|
dac_weight1 = json_data["dac_weight1"]
|
|
|
|
dac_weight2 = json_data["dac_weight2"]
|
|
|
|
dac_weight3 = json_data["dac_weight3"]
|
2023-11-22 11:21:26 +01:00
|
|
|
else:
|
|
|
|
raise ValueError("CLI support for SCEX params not implemented")
|
2022-06-27 20:18:26 +02:00
|
|
|
# in app_data
|
2022-06-30 21:49:25 +02:00
|
|
|
# app_data.extend(struct.pack("!H", first_dac))
|
2022-08-30 16:32:50 +02:00
|
|
|
app_data.append(cell_select)
|
2022-06-27 20:18:26 +02:00
|
|
|
append_16_bit_val(packet=app_data, val=first_dac[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=last_dac[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=res_switch1[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=res_switch2[cn])
|
|
|
|
|
|
|
|
app_data.append(dac_weight1[cn])
|
|
|
|
app_data.append(dac_weight2[cn])
|
|
|
|
app_data.append(dac_weight3[cn])
|
|
|
|
|
2022-08-08 16:32:18 +02:00
|
|
|
q.add_pus_tc(
|
2023-01-18 11:32:21 +01:00
|
|
|
create_action_cmd(SCEX_HANDLER_ID, ActionId.ONE_CELLS_CMD, app_data)
|
2022-08-08 16:32:18 +02:00
|
|
|
)
|
2022-06-27 20:18:26 +02:00
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.ALL_CELLS_CMD:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.ALL_CELLS_CMD)
|
2022-08-30 16:32:50 +02:00
|
|
|
app_data = bytearray([0])
|
2022-06-30 21:49:25 +02:00
|
|
|
|
|
|
|
# cell number
|
|
|
|
cn = 0
|
|
|
|
if USE_SCEX_CONF_FILE:
|
|
|
|
with open("template/scex_conf.json") as json_file:
|
|
|
|
json_data = json.load(json_file)
|
|
|
|
first_dac = json_data["first_dac"]
|
|
|
|
last_dac = json_data["last_dac"]
|
|
|
|
res_switch1 = json_data["res_switch1"]
|
|
|
|
res_switch2 = json_data["res_switch2"]
|
|
|
|
dac_weight1 = json_data["dac_weight1"]
|
|
|
|
dac_weight2 = json_data["dac_weight2"]
|
|
|
|
dac_weight3 = json_data["dac_weight3"]
|
|
|
|
|
2023-11-22 11:21:26 +01:00
|
|
|
else:
|
|
|
|
raise ValueError("CLI support for SCEX params not implemented")
|
2022-06-30 21:49:25 +02:00
|
|
|
# in app_data
|
|
|
|
# app_data.extend(struct.pack("!H", first_dac))
|
|
|
|
append_16_bit_val(packet=app_data, val=first_dac[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=last_dac[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=res_switch1[cn])
|
|
|
|
append_16_bit_val(packet=app_data, val=res_switch2[cn])
|
|
|
|
|
|
|
|
app_data.append(dac_weight1[cn])
|
|
|
|
app_data.append(dac_weight2[cn])
|
|
|
|
app_data.append(dac_weight3[cn])
|
|
|
|
|
2022-08-08 16:32:18 +02:00
|
|
|
q.add_pus_tc(
|
2023-01-18 11:32:21 +01:00
|
|
|
create_action_cmd(SCEX_HANDLER_ID, ActionId.ALL_CELLS_CMD, app_data)
|
2022-08-08 16:32:18 +02:00
|
|
|
)
|
2022-06-30 21:49:25 +02:00
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
if cmd_str == OpCode.FRAM:
|
2022-07-08 16:21:01 +02:00
|
|
|
q.add_log_cmd(Info.FRAM)
|
2022-06-30 21:49:25 +02:00
|
|
|
app_data = bytes([0])
|
2023-01-18 11:32:21 +01:00
|
|
|
q.add_pus_tc(create_action_cmd(SCEX_HANDLER_ID, ActionId.FRAM, app_data))
|
2022-07-08 16:21:01 +02:00
|
|
|
|
2022-06-27 20:18:26 +02:00
|
|
|
|
|
|
|
def append_16_bit_val(packet: bytearray, val: int):
|
|
|
|
packet.append((val >> 8) & 0xFF)
|
2022-07-08 16:21:01 +02:00
|
|
|
packet.append(val & 0xFF)
|