Compare commits

...

5 Commits

Author SHA1 Message Date
Irini Kosmidou
dbae41cb58 scex continued 2022-06-30 21:49:25 +02:00
Irini Kosmidou
1df9b0a91a continued scex.py 2022-06-27 20:18:26 +02:00
Irini Kosmidou
d7ee5a2229 tmtc scex continue 2022-06-21 18:15:17 +02:00
a1964f05ea update .gitignore 2022-06-21 17:57:16 +02:00
c2f597b671 basic scex_conf file 2022-06-21 17:56:31 +02:00
3 changed files with 165 additions and 2 deletions

3
.gitignore vendored
View File

@@ -5,4 +5,5 @@ __pycache__
log
/gps_log.txt
/config/*.json
tmtc_conf.json
/tmtc_conf.json
/scex_conf.json

View File

@@ -1,4 +1,6 @@
import enum
import json
import struct
from config.definitions import CustomServiceList
from tmtccmd.tc.pus_8_funccmd import generate_action_command
@@ -7,16 +9,40 @@ from tmtccmd.tc.definitions import TcQueueT
from config.object_ids import SCEX_HANDLER_ID
USE_SCEX_CONF_FILE = True
class OpCodes:
PING = ["0", "ping"]
ION_CMD = ["1", "ion"]
TEMP_CMD = ["2", "temp"]
EXP_STATUS_CMD = ["3", "expstatus"]
ONE_CELLS_CMD = ["4", "onecell"]
ALL_CELLS_CMD = ["5", "allcells"]
FRAM = ["6", "fram"]
class ActionIds(enum.IntEnum):
PING = 7
ION_CMD = 4
TEMP_CMD = 3
EXP_STATUS_CMD = 2
ONE_CELLS_CMD = 6
ALL_CELLS_CMD = 5
FRAM = 1
class Info:
PING = "Send Ping command"
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"
def add_scex_cmds(cmd_dict: ServiceOpCodeDictT):
@@ -24,6 +50,30 @@ def add_scex_cmds(cmd_dict: ServiceOpCodeDictT):
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.PING, info=Info.PING
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.ION_CMD, info=Info.ION_CMD
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.TEMP_CMD, info=Info.TEMP_CMD
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.EXP_STATUS_CMD, info=Info.EXP_STATUS_CMD
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.ONE_CELLS_CMD, info=Info.ONE_CELLS_CMD
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.ALL_CELLS_CMD, info=Info.ALL_CELLS_CMD
)
add_op_code_entry(
op_code_dict=op_code_dict, keys=OpCodes.FRAM, info=Info.FRAM
)
add_service_op_code_entry(
srv_op_code_dict=cmd_dict,
name=CustomServiceList.SCEX.value,
@@ -39,4 +89,107 @@ def pack_scex_cmds(tc_queue: TcQueueT, op_code: str):
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.PING, app_data)
tc_queue.appendleft(command.pack_command_tuple())
pass
if op_code in OpCodes.ION_CMD:
tc_queue.appendleft((QueueCommands.PRINT, Info.ION_CMD))
app_data = bytes([0])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.ION_CMD, app_data)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in OpCodes.TEMP_CMD:
tc_queue.appendleft((QueueCommands.PRINT, Info.TEMP_CMD))
app_data = bytes([0])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.TEMP_CMD, app_data)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in OpCodes.EXP_STATUS_CMD:
tc_queue.appendleft((QueueCommands.PRINT, Info.EXP_STATUS_CMD))
app_data = bytes([0])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.EXP_STATUS_CMD, app_data)
tc_queue.appendleft(command.pack_command_tuple())
# one cell
if op_code in OpCodes.ONE_CELLS_CMD:
tc_queue.appendleft((QueueCommands.PRINT, Info.ONE_CELLS_CMD))
app_data = bytearray()
# cell number
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(
f"Invalid cell number {cell_select}, "
f"Please enter a valid number: "
)
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"]
# 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])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.ONE_CELLS_CMD, app_data)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in OpCodes.ALL_CELLS_CMD:
tc_queue.appendleft((QueueCommands.PRINT, Info.ALL_CELLS_CMD))
app_data = bytearray()
# 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"]
# 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])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.ALL_CELLS_CMD, app_data)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in OpCodes.FRAM:
tc_queue.appendleft((QueueCommands.PRINT, Info.FRAM))
app_data = bytes([0])
command = generate_action_command(SCEX_HANDLER_ID, ActionIds.FRAM, app_data)
tc_queue.appendleft(command.pack_command_tuple())
def append_16_bit_val(packet: bytearray, val: int):
packet.append((val >> 8) & 0xFF)
packet.append(val & 0xFF)

9
template/scex_conf.json Normal file
View File

@@ -0,0 +1,9 @@
{
"first_dac": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"last_dac": [40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000],
"res_switch1": [8000, 8000, 8000, 7000, 8000, 8000, 8000, 8000, 8000, 8000],
"res_switch2": [15650, 15650, 15650, 13400, 15650, 13400, 13400, 13400, 13400, 13400],
"dac_weight1": [35, 35, 35, 35, 35, 37, 37, 37, 37, 37],
"dac_weight2": [30, 30, 30, 50, 30, 28, 28, 28, 28, 28],
"dac_weight3": [35, 35, 35, 35, 35, 35, 35, 35, 35, 35]
}