eive-tmtc/eive_tmtc/pus_tc/devs/bpx_batt.py

112 lines
3.7 KiB
Python
Raw Normal View History

2022-12-06 10:34:12 +01:00
from spacepackets.ecss import PusTelecommand
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.config.object_ids import BPX_HANDLER_ID
2022-12-06 10:34:12 +01:00
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
2022-11-29 16:53:29 +01:00
from tmtccmd.tc import service_provider
2022-08-18 14:08:05 +02:00
from tmtccmd.tc.decorator import ServiceProviderParams
2022-08-22 11:47:12 +02:00
from tmtccmd.tc.pus_8_funccmd import make_fsfw_action_cmd
from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid
2022-12-06 10:34:12 +01:00
from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes
from tmtccmd.tc.pus_200_fsfw_modes import Subservices as ModeSubservices
class BpxSetIds:
GET_HK_SET = 0
GET_CFG_SET = 5
class BpxActionIds:
REBOOT = 2
RESET_COUNTERS = 3
SET_CFG = 4
GET_CFG = 5
2022-02-03 16:02:55 +01:00
class BpxOpCodes:
HK = ["0", "hk"]
2022-12-06 10:34:12 +01:00
OFF = ["off"]
ON = ["on"]
2022-02-03 16:02:55 +01:00
RST_BOOT_CNT = ["1", "rst_boot_cnt"]
REQUEST_CFG = ["2", "cfg"]
REQUEST_CFG_HK = ["3", "cfg_hk"]
REBOOT = ["4", "reboot"]
2022-12-06 10:34:12 +01:00
@tmtc_definitions_provider
def add_bpx_cmd_definitions(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(keys=BpxOpCodes.ON, info="On command")
oce.add(keys=BpxOpCodes.OFF, info="Off command")
oce.add(keys=BpxOpCodes.HK, info="Request BPX HK")
oce.add(keys=BpxOpCodes.RST_BOOT_CNT, info="Reset Boot Count")
oce.add(keys=BpxOpCodes.REQUEST_CFG, info="Request Configuration Struct (Step 1)")
oce.add(
keys=BpxOpCodes.REQUEST_CFG_HK, info="Request Configuration Struct HK (Step 2)"
)
oce.add(keys=BpxOpCodes.REBOOT, info="Reboot Command")
defs.add_service(
name=CustomServiceList.BPX_BATTERY.value,
info="BPX Battery Handler",
op_code_entry=oce,
)
2022-08-12 22:33:16 +02:00
@service_provider(CustomServiceList.BPX_BATTERY.value)
2022-08-18 14:08:05 +02:00
def pack_bpx_commands(p: ServiceProviderParams):
op_code = p.op_code
q = p.queue_helper
2022-02-03 16:02:55 +01:00
if op_code in BpxOpCodes.HK:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Requesting BPX battery HK set")
sid = make_sid(object_id=BPX_HANDLER_ID, set_id=BpxSetIds.GET_HK_SET)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(generate_one_hk_command(sid=sid))
2022-12-06 10:34:12 +01:00
if op_code in BpxOpCodes.OFF:
q.add_log_cmd("Off mode")
mode_cmd = pack_mode_data(BPX_HANDLER_ID, Modes.OFF, 0)
q.add_pus_tc(
PusTelecommand(
service=200,
subservice=ModeSubservices.TC_MODE_COMMAND,
app_data=mode_cmd,
)
)
if op_code in BpxOpCodes.ON:
q.add_log_cmd("On mode")
mode_cmd = pack_mode_data(BPX_HANDLER_ID, Modes.ON, 0)
q.add_pus_tc(
PusTelecommand(
service=200,
subservice=ModeSubservices.TC_MODE_COMMAND,
app_data=mode_cmd,
)
)
2022-02-03 16:02:55 +01:00
if op_code in BpxOpCodes.RST_BOOT_CNT:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Resetting reboot counters")
q.add_pus_tc(
2022-08-22 11:47:12 +02:00
make_fsfw_action_cmd(
2022-07-04 15:22:53 +02:00
object_id=BPX_HANDLER_ID, action_id=BpxActionIds.RESET_COUNTERS
)
)
2022-02-03 16:02:55 +01:00
if op_code in BpxOpCodes.REQUEST_CFG:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Requesting configuration struct")
q.add_pus_tc(
2022-08-22 11:47:12 +02:00
make_fsfw_action_cmd(
2022-07-04 15:22:53 +02:00
object_id=BPX_HANDLER_ID, action_id=BpxActionIds.GET_CFG
)
2022-02-03 15:30:58 +01:00
)
2022-02-03 16:02:55 +01:00
if op_code in BpxOpCodes.REQUEST_CFG_HK:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Requesting configuration struct HK")
2022-02-03 15:30:58 +01:00
sid = make_sid(object_id=BPX_HANDLER_ID, set_id=BpxSetIds.GET_CFG_SET)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(generate_one_hk_command(sid=sid))
2022-02-03 16:02:55 +01:00
if op_code in BpxOpCodes.REBOOT:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Rebooting BPX battery")
q.add_pus_tc(
2022-08-22 11:47:12 +02:00
make_fsfw_action_cmd(
2022-07-04 15:22:53 +02:00
object_id=BPX_HANDLER_ID, action_id=BpxActionIds.REBOOT
)
2022-02-03 16:02:55 +01:00
)