update gomspace commands

This commit is contained in:
2022-09-01 16:58:31 +02:00
parent abecbe4401
commit e162e5c51b
16 changed files with 382 additions and 215 deletions

View File

@ -37,7 +37,7 @@ class GomspaceOpCodes:
PRINT_SWITCH_V_I = ["print_switch_vi"]
PRINT_LATCHUPS = ["print_latchups"]
GET_PARAM = ["get_param"]
SET_PARAM = ["set_param"]
SET_INTEGER_PARAM = ["set_int_param"]
SAVE_TABLE = ["save_table"]
RESET_GND_WATCHDOG = ["reset_gnd_wdt"]
SAVE_TABLE_DEFAULT = ["save_table_default"]
@ -50,7 +50,7 @@ class GsInfo:
PRINT_SWITCH_V_I = "Print Switch V I Info"
PRINT_LATCHUPS = "Print latchups"
GET_PARAMETER = "Get parameter"
SET_PARAMETER = "Set parameter"
SET_PARAMETER = "Set integer parameter"
REQUEST_CONFIG_TABLE = "Request Config Table"
RESET_GND_WATCHDOG = "Reset GND watchdog"
SAVE_TABLE = "Save table non-volatile (file)"
@ -68,9 +68,20 @@ class SetIds:
ACU_AUX = 8
class ParamTypes(enum.Enum):
U8 = 0
U16 = 1
U32 = 2
I8 = 3
I16 = 4
I32 = 5
FLOAT = 6
STR = 7
class TableIds:
config = 1
hk = 4
CONFIG = 1
HK = 4
class TableEntry:
@ -78,7 +89,7 @@ class TableEntry:
uint16_size = 2
uint32_size = 4
def __init__(self, parameter_address: bytearray, parameter_size):
def __init__(self, parameter_address: bytes, parameter_size):
self.parameter_address = parameter_address
self.parameter_size = parameter_size
@ -121,34 +132,88 @@ def pack_get_param_command(
)
def pack_set_param_command(
object_id: bytes, memory_address: bytes, parameter_size: int, parameter: int
def pack_set_float_param_command(
object_id: bytes, memory_address: bytes, parameter: float
) -> PusTelecommand:
"""Function to generate a command to set a parameter
:param object_id: The object id of the gomspace device handler.
:param memory_address: Address offset within table of the value to set.
:param parameter: The parameter value to set.
:param parameter_size: Size of the value to set. There are uint8_t, uint16_t and uint32_t
in the device tables.
:return: The command as bytearray.
"""
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(parameter_size)
if parameter_size == 1:
app_data.append(parameter)
elif parameter_size == 2:
app_data += struct.pack("!H", parameter)
elif parameter_size == 4:
byte_one = 0xFF000000 & parameter >> 24
byte_two = 0xFF0000 & parameter >> 16
byte_three = 0xFF00 & parameter >> 8
byte_four = 0xFF & parameter
app_data.append(byte_one)
app_data.append(byte_two)
app_data.append(byte_three)
app_data.append(byte_four)
app_data.append(4)
app_data += struct.pack("!f", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_u8_param_command(
object_id: bytes, memory_address: bytes, parameter: int
) -> PusTelecommand:
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(1)
app_data.append(parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_i8_param_command(
object_id: bytes, memory_address: bytes, parameter: int
) -> PusTelecommand:
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(1)
app_data += struct.pack("!b", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_u16_param_command(
object_id: bytes, memory_address: bytes, parameter: int
) -> PusTelecommand:
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(2)
app_data += struct.pack("!H", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_i16_param_command(
object_id: bytes, memory_address: bytes, parameter: int
) -> PusTelecommand:
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(2)
app_data += struct.pack("!h", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_u32_param_command(object_id: bytes, memory_address: bytes, parameter: int):
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(4)
app_data += struct.pack("!I", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
def pack_set_i32_param_command(object_id: bytes, memory_address: bytes, parameter: int):
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(4)
app_data += struct.pack("!i", parameter)
return make_fsfw_action_cmd(
object_id=object_id, action_id=action_id, user_data=app_data
)
@ -165,16 +230,27 @@ def prompt_and_pack_get_param_command(q: DefaultPusQueueHelper, object_id: Objec
)
def prompt_and_pack_set_param_command(q: DefaultPusQueueHelper, object_id: ObjectIdU32):
def prompt_and_pack_set_integer_param_command(
q: DefaultPusQueueHelper, object_id: ObjectIdU32, ptype: ParamTypes
):
memory_address = int(input("Specify memory address: 0x"), 16)
memory_address = struct.pack("!H", memory_address)
parameter_size = int(input("Specify parameter size: "))
parameter = int(input("Specify parameter: "))
q.add_pus_tc(
pack_set_param_command(
object_id.as_bytes, memory_address, parameter_size, parameter
)
)
if ptype == ParamTypes.U8:
cmd = pack_set_u8_param_command(object_id.as_bytes, memory_address, parameter)
elif ptype == ParamTypes.U16:
cmd = pack_set_u16_param_command(object_id.as_bytes, memory_address, parameter)
elif ptype == ParamTypes.U32:
cmd = pack_set_u16_param_command(object_id.as_bytes, memory_address, parameter)
elif ptype == ParamTypes.I8:
cmd = pack_set_i8_param_command(object_id.as_bytes, memory_address, parameter)
elif ptype == ParamTypes.I16:
cmd = pack_set_i16_param_command(object_id.as_bytes, memory_address, parameter)
elif ptype == ParamTypes.I32:
cmd = pack_set_i32_param_command(object_id.as_bytes, memory_address, parameter)
else:
raise ValueError(f"Invalid parameter type {ptype} for this function")
q.add_pus_tc(cmd)
def pack_ping_command(object_id: ObjectIdU32, data: bytearray) -> PusTelecommand:

View File

@ -2,20 +2,30 @@ from gomspace.gomspace_common import TableEntry
class PduConfigTable:
out_en_0 = TableEntry(bytearray([0x00, 0x48]), TableEntry.uint8_size)
out_en_1 = TableEntry(bytearray([0x00, 0x49]), TableEntry.uint8_size)
out_en_2 = TableEntry(bytearray([0x00, 0x4A]), TableEntry.uint8_size)
out_en_3 = TableEntry(bytearray([0x00, 0x4B]), TableEntry.uint8_size)
out_en_4 = TableEntry(bytearray([0x00, 0x4C]), TableEntry.uint8_size)
out_en_5 = TableEntry(bytearray([0x00, 0x4D]), TableEntry.uint8_size)
out_en_6 = TableEntry(bytearray([0x00, 0x4E]), TableEntry.uint8_size)
out_en_7 = TableEntry(bytearray([0x00, 0x4F]), TableEntry.uint8_size)
out_en_8 = TableEntry(bytearray([0x00, 0x50]), TableEntry.uint8_size)
# When channel consumes more than cur_lu_lim, channel is turned of immediately
out_en_0 = TableEntry(bytes([0x00, 0x48]), TableEntry.uint8_size)
out_en_1 = TableEntry(bytes([0x00, 0x49]), TableEntry.uint8_size)
out_en_2 = TableEntry(bytes([0x00, 0x4A]), TableEntry.uint8_size)
out_en_3 = TableEntry(bytes([0x00, 0x4B]), TableEntry.uint8_size)
out_en_4 = TableEntry(bytes([0x00, 0x4C]), TableEntry.uint8_size)
out_en_5 = TableEntry(bytes([0x00, 0x4D]), TableEntry.uint8_size)
out_en_6 = TableEntry(bytes([0x00, 0x4E]), TableEntry.uint8_size)
out_en_7 = TableEntry(bytes([0x00, 0x4F]), TableEntry.uint8_size)
out_en_8 = TableEntry(bytes([0x00, 0x50]), TableEntry.uint8_size)
# When channel consumes more than cur_lu_lim, channel is turned off immediately
cur_lu_lim_0 = TableEntry(bytearray([0x00, 0xB8]), TableEntry.uint16_size)
INIT_OUT_SAFE_CH_0 = TableEntry(bytes([0x00, 0x80]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_1 = TableEntry(bytes([0x00, 0x80 + 1]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_2 = TableEntry(bytes([0x00, 0x80 + 2]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_3 = TableEntry(bytes([0x00, 0x80 + 3]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_4 = TableEntry(bytes([0x00, 0x80 + 4]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_5 = TableEntry(bytes([0x00, 0x80 + 5]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_6 = TableEntry(bytes([0x00, 0x80 + 6]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_7 = TableEntry(bytes([0x00, 0x80 + 7]), TableEntry.uint8_size)
INIT_OUT_SAFE_CH_8 = TableEntry(bytes([0x00, 0x80 + 8]), TableEntry.uint8_size)
PDU_CONFIG_LIST = [
OUT_ENABLE_LIST = [
PduConfigTable.out_en_0,
PduConfigTable.out_en_1,
PduConfigTable.out_en_2,