eive-tmtc/pus_tc/devs/imtq.py

203 lines
8.7 KiB
Python
Raw Normal View History

2021-03-25 17:53:05 +01:00
# -*- coding: utf-8 -*-
"""
@file imtq.py
@brief Tests for the ISIS IMTQ (Magnettorquer) device handler
@author J. Meier
@date 25.03.2021
"""
2022-06-03 18:04:59 +02:00
import struct
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tc import PusTelecommand
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2022-05-25 15:21:50 +02:00
from tmtccmd.tc.pus_3_fsfw_hk import (
make_sid,
generate_one_diag_command,
generate_one_hk_command,
)
2022-05-24 18:57:52 +02:00
from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2021-03-25 17:53:05 +01:00
2021-06-15 15:23:27 +02:00
class ImtqSetIds:
ENG_HK_SET = 1
CAL_MTM_SET = 2
RAW_MTM_SET = 3
POSITIVE_X_TEST = 4
NEGATIVE_X_TEST = 5
POSITIVE_Y_TEST = 6
NEGATIVE_Y_TEST = 7
POSITIVE_Z_TEST = 8
NEGATIVE_Z_TEST = 9
2021-03-25 17:53:05 +01:00
class ImtqActionIds:
start_actuation_dipole = bytearray([0x0, 0x0, 0x0, 0x02])
get_commanded_dipole = bytearray([0x0, 0x0, 0x0, 0x03])
2021-06-12 13:49:25 +02:00
perform_positive_x_test = bytearray([0x0, 0x0, 0x0, 0x07])
perform_negative_x_test = bytearray([0x0, 0x0, 0x0, 0x08])
perform_positive_y_test = bytearray([0x0, 0x0, 0x0, 0x09])
perform_negative_y_test = bytearray([0x0, 0x0, 0x0, 0x0A])
perform_positive_z_test = bytearray([0x0, 0x0, 0x0, 0x0B])
perform_negative_z_test = bytearray([0x0, 0x0, 0x0, 0x0C])
2022-07-04 15:22:53 +02:00
# Initiates the reading of the last performed self test. After sending this command the results
# can be downlinked via the housekeeping service by using the appropriate set ids listed above.
2021-06-12 13:49:25 +02:00
read_self_test_results = bytearray([0x0, 0x0, 0x0, 0x0D])
2021-03-25 17:53:05 +01:00
2022-08-08 16:32:18 +02:00
def pack_imtq_test_into(object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(
f"Testing ISIS IMTQ handler with object id: {object_id.as_hex_string}"
2021-03-25 17:53:05 +01:00
)
2022-05-24 18:57:52 +02:00
if op_code == "0":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Set mode off")
command = pack_mode_data(object_id.as_bytes, Modes.OFF, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command))
2022-05-24 18:57:52 +02:00
if op_code == "1":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Set mode on")
command = pack_mode_data(object_id.as_bytes, Modes.ON, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command))
2022-05-24 18:57:52 +02:00
if op_code == "2":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Mode Normal")
command = pack_mode_data(object_id.as_bytes, Modes.NORMAL, 0)
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command))
2022-05-24 18:57:52 +02:00
if op_code == "3":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform positive x self test")
command = object_id.as_bytes + ImtqActionIds.perform_positive_x_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-12 13:49:25 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Initiate reading of positive x self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-12 13:49:25 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Request dataset with positive x self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_X_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-12 13:49:25 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "4":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform negative x self test")
command = object_id.as_bytes + ImtqActionIds.perform_negative_x_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
q.add_log_cmd("IMTQ: Initiate reading of negative x self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
q.add_log_cmd("IMTQ: Request dataset with negative x self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_X_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "5":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform positive y self test")
command = object_id.as_bytes + ImtqActionIds.perform_positive_y_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
q.add_log_cmd("IMTQ: Initiate reading of positive y self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Request dataset with positive y self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_Y_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "6":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform negative y self test")
command = object_id.as_bytes + ImtqActionIds.perform_negative_y_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Initiate reading of negative y self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Request dataset with negative y self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_Y_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "7":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform positive z self test")
command = object_id.as_bytes + ImtqActionIds.perform_positive_z_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Initiate reading of positive z self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Request dataset with positive z self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_Y_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "8":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Perform negative z self test")
command = object_id.as_bytes + ImtqActionIds.perform_negative_z_test
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
q.add_log_cmd("IMTQ: Initiate reading of negative z self test results")
command = object_id.as_bytes + ImtqActionIds.read_self_test_results
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
q.add_log_cmd("IMTQ: Request dataset with negative z self test results")
sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_Z_TEST)
q.add_pus_tc(generate_one_hk_command(sid))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "9":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Commanding dipole")
2021-06-15 15:23:27 +02:00
x_dipole = 0
y_dipole = 0
z_dipole = 0
2022-01-18 14:03:56 +01:00
duration = 0 # ms
2022-07-04 15:22:53 +02:00
q.add_pus_tc(
pack_dipole_command(
object_id.as_bytes, x_dipole, y_dipole, z_dipole, duration
)
)
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "10":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Get commanded dipole")
command = object_id.as_bytes + ImtqActionIds.get_commanded_dipole
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-06-15 15:23:27 +02:00
2022-05-24 18:57:52 +02:00
if op_code == "11":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Get engineering hk set")
q.add_pus_tc(
generate_one_diag_command(
sid=make_sid(object_id=object_id.as_bytes, set_id=ImtqSetIds.ENG_HK_SET)
)
2022-05-24 18:57:52 +02:00
)
if op_code == "12":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Get calibrated MTM hk set")
q.add_pus_tc(
generate_one_diag_command(
sid=make_sid(
object_id=object_id.as_bytes, set_id=ImtqSetIds.CAL_MTM_SET
)
)
2022-05-24 18:57:52 +02:00
)
if op_code == "13":
2022-07-04 15:22:53 +02:00
q.add_log_cmd("IMTQ: Get raw MTM hk set")
q.add_pus_tc(
generate_one_diag_command(
sid=make_sid(
object_id=object_id.as_bytes, set_id=ImtqSetIds.RAW_MTM_SET
)
)
2022-05-24 18:57:52 +02:00
)
2021-06-12 13:49:25 +02:00
2021-03-25 17:53:05 +01:00
2022-01-18 14:03:56 +01:00
def pack_dipole_command(
2022-07-04 15:22:53 +02:00
object_id: bytes, x_dipole: int, y_dipole: int, z_dipole: int, duration: int
) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
"""This function packs the command causing the ISIS IMTQ to generate a dipole.
2021-06-25 12:07:16 +02:00
@param object_id The object id of the IMTQ handler.
2021-03-26 13:56:02 +01:00
@param x_dipole The dipole of the x coil in 10^-4*Am^2 (max. 2000)
@param y_dipole The dipole of the y coil in 10^-4*Am^2 (max. 2000)
@param z_dipole The dipole of the z coil in 10^-4*Am^2 (max. 2000)
2021-03-25 17:53:05 +01:00
@param duration The duration in milliseconds the dipole will be generated by the coils.
When set to 0, the dipole will be generated until a new dipole actuation
command is sent.
"""
action_id = ImtqActionIds.start_actuation_dipole
command = object_id + action_id
2022-07-04 15:22:53 +02:00
command += struct.pack("!h", x_dipole)
command += struct.pack("!h", y_dipole)
command += struct.pack("!h", z_dipole)
command += struct.pack("!h", duration)
command = PusTelecommand(service=8, subservice=128, app_data=command)
2021-03-26 13:56:02 +01:00
return command