RW CMDs #61

Merged
muellerr merged 21 commits from mueller/rw-cmds into develop 2022-05-11 17:59:50 +02:00
4 changed files with 48 additions and 23 deletions
Showing only changes of commit a648b7f76f - Show all commits

View File

@ -6,7 +6,11 @@
"""
import struct
from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT
from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid
from tmtccmd.tc.pus_3_fsfw_hk import (
generate_one_hk_command,
generate_one_diag_command,
make_sid,
)
from tmtccmd.config.globals import add_op_code_entry, add_service_op_code_entry
from tmtccmd.tc.packer import TcQueueT
from spacepackets.ecss.tc import PusTelecommand
@ -19,7 +23,8 @@ class OpCodesDevs:
ON = ["1", "on"]
NML = ["2", "nml"]
OFF = ["3", "off"]
GET_TM = ["4", "tm"]
GET_STATUS = ["4", "status"]
GET_TM = ["5", "tm"]
class InfoDevs:
@ -27,6 +32,7 @@ class InfoDevs:
ON = "Set On"
NML = "Set Normal"
OFF = "Set Off"
GET_STATUS = "Get Status HK"
GET_TM = "Get TM HK"
@ -81,10 +87,12 @@ def add_rw_cmds(cmd_dict: ServiceOpCodeDictT):
add_op_code_entry(
op_code_dict=op_code_dict, info=InfoDevs.NML, keys=OpCodesDevs.NML
)
add_op_code_entry(
op_code_dict=op_code_dict, info=InfoDevs.GET_STATUS, keys=OpCodesDevs.GET_STATUS
)
add_op_code_entry(
op_code_dict=op_code_dict, info=InfoDevs.GET_TM, keys=OpCodesDevs.GET_TM
)
add_service_op_code_entry(
srv_op_code_dict=cmd_dict,
name=CustomServiceList.REACTION_WHEEL_1.value,
@ -156,21 +164,35 @@ def pack_single_rw_test_into(
sid=make_sid(object_id=object_id, set_id=RwSetIds.TM_SET), ssc=0
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in OpCodesDevs.GET_STATUS:
tc_queue.appendleft(
(QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.GET_STATUS}")
)
command = generate_one_diag_command(
sid=make_sid(object_id=object_id, set_id=RwSetIds.STATUS_SET_ID), ssc=0
)
tc_queue.appendleft(command.pack_command_tuple())
return tc_queue
def pack_rw_ass_cmds(tc_queue: TcQueueT, object_id: bytes, op_code: str):
if op_code in OpCodesAss.OFF:
data = pack_mode_data(object_id=object_id, mode=Modes.OFF, submode=0)
cmd = PusTelecommand(service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data)
cmd = PusTelecommand(
service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data
)
tc_queue.appendleft(cmd.pack_command_tuple())
if op_code in OpCodesAss.ON:
data = pack_mode_data(object_id=object_id, mode=Modes.ON, submode=0)
cmd = PusTelecommand(service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data)
cmd = PusTelecommand(
service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data
)
tc_queue.appendleft(cmd.pack_command_tuple())
if op_code in OpCodesAss.NML:
data = pack_mode_data(object_id=object_id, mode=Modes.NORMAL, submode=0)
cmd = PusTelecommand(service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data)
cmd = PusTelecommand(
service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data
)
tc_queue.appendleft(cmd.pack_command_tuple())

View File

@ -232,7 +232,7 @@ def pack_service_queue_user(
return pack_tcs_sys_commands(tc_queue=service_queue, op_code=op_code)
if service == CustomServiceList.TIME.value:
return pack_set_current_time_ascii_command(tc_queue=service_queue, ssc=0)
if service == CustomServiceList.RW_ASSEMBLY:
if service == CustomServiceList.RW_ASSEMBLY.value:
return pack_rw_ass_cmds(
tc_queue=service_queue, object_id=RW_ASSEMBLY, op_code=op_code
)

View File

@ -11,27 +11,30 @@ def handle_rw_hk_data(
pw = PrintWrapper(printer)
current_idx = 0
if set_id == RwSetIds.TEMPERATURE_SET_ID:
pw.dlog(
f"Received Temperature HK (ID {set_id}) from Reaction Wheel {object_id.name}"
)
temp = struct.unpack("!I", hk_data[0:4])
pw.dlog(f"Temperature {temp}")
current_idx += 4
if set_id == RwSetIds.STATUS_SET_ID:
pw.dlog(
f"Received Status HK (ID {set_id}) from Reaction Wheel {object_id.name}"
)
fmt_str = "!iiBB"
fmt_str = "!IiiBB"
inc_len = struct.calcsize(fmt_str)
(speed, ref_speed, state, clc_mode) = struct.unpack(
(temp, speed, ref_speed, state, clc_mode) = struct.unpack(
fmt_str, hk_data[current_idx : current_idx + inc_len]
)
current_idx += inc_len
speed_rpm = speed / 10.0
ref_speed_rpm = ref_speed / 10.0
pw.dlog(
f"Speed {speed} rpm | Reference Speed {ref_speed} rpm | State {state} | "
f"CLC Mode {clc_mode}"
f"Temperature {temp} C | Speed {speed_rpm} rpm | Reference Speed {ref_speed_rpm} rpm"
)
pw.dlog(
f"State {state}. 0: Error, 1: Idle, 2: Coasting, 3: Running, speed stable, "
f"4: Running, speed changing"
)
pw.dlog(
f"Current Limit Control mode {clc_mode}. 0: Low Current Mode (0.3 A), "
f"1: High Current Mode (0.6 A)"
)
printer.print_validity_buffer(hk_data[current_idx:], 5)
if set_id == RwSetIds.LAST_RESET:
pw.dlog(
f"Received Last Reset HK (ID {set_id}) from Reaction Wheel {object_id.name}"
@ -115,7 +118,7 @@ def handle_rw_hk_data(
f"{spi_num_bytes_written} | {spi_num_bytes_read} | {spi_num_reg_overrun_errors} | "
f"{spi_total_num_errors}"
)
if current_idx > 0:
printer.print_validity_buffer(
validity_buffer=hk_data[current_idx:], num_vars=27
)
if current_idx > 0:
printer.print_validity_buffer(
validity_buffer=hk_data[current_idx:], num_vars=27
)

View File

@ -19,7 +19,7 @@ from tmtccmd.utility.obj_id import ObjectId, ObjectIdDictT
import config.object_ids as obj_ids
from pus_tm.devs.reaction_wheels import handle_rw_hk_data
from pus_tm.defs import PrintWrapper, FsfwTmTcPrinter
from pus_tm.defs import PrintWrapper, FsfwTmTcPrinter, log_to_both
LOGGER = get_console_logger()