From b42617e00a67f3d47a20898e8ba5270882345e2d Mon Sep 17 00:00:00 2001
From: "Robin.Mueller" <robin.mueller.m@gmail.com>
Date: Tue, 20 Oct 2020 19:11:38 +0200
Subject: [PATCH] leds commandable

---
 config/obsw_config.py    |  1 +
 tc/obsw_image_handler.py |  4 +++-
 tc/obsw_pus_tc_packer.py |  3 +++
 tc/obsw_tc_service8.py   |  7 +++++++
 tc/obsw_tc_utility.py    | 13 +++++++++++++
 5 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 tc/obsw_tc_utility.py

diff --git a/config/obsw_config.py b/config/obsw_config.py
index 68de043..1b5467c 100644
--- a/config/obsw_config.py
+++ b/config/obsw_config.py
@@ -29,6 +29,7 @@ DUMMY_DEVICE_ID = bytearray([0x44, 0x00, 0xAF, 0xFE])
 THERMAL_SENSOR_DEVICE_ID = bytearray([0x44, 0x11, 0x54, 0x00])
 GYRO_DEVICE_ID = bytearray([0x44, 0x11, 0x55, 0x00])
 TEST_TASK_ID = bytearray([0x42, 0x69, 0x42, 0x69])
+LED_TASK_ID = bytearray([0x62, 0x00, 0x00, 0x01])
 SD_CARD_HANDLER_ID = bytearray([0x4D, 0x00, 0x73, 0xAD])
 INTERNAL_ERROR_REPORTER_ID = bytearray([0x53, 0x04, 0x00, 0x00])
 
diff --git a/tc/obsw_image_handler.py b/tc/obsw_image_handler.py
index be5fd0b..6f32168 100644
--- a/tc/obsw_image_handler.py
+++ b/tc/obsw_image_handler.py
@@ -1,3 +1,5 @@
+from typing import Union
+
 from tmtc_core.tc.obsw_pus_tc_base import PusTelecommand, Deque
 from tc.obsw_tc_service8 import make_action_id
 from tc.obsw_tc_service20 import pack_boolean_parameter_setting
@@ -30,7 +32,7 @@ def generate_param_packet_hamming_from_sdcard(enable: bool, ssc: int,
                                           parameter=enable, ssc=ssc)
 
 
-def generate_img_handler_packet(service_queue: Deque, op_code: int):
+def generate_img_handler_packet(service_queue: Deque, op_code: Union[int, str]):
     # Action ID 4 (Copy SDC to Flash, Software Update Image)
     if op_code == "A4U":
         service_queue.appendleft(("print", "Generating command to copy SDC OBSW to flash."))
diff --git a/tc/obsw_pus_tc_packer.py b/tc/obsw_pus_tc_packer.py
index 5215268..77fc692 100644
--- a/tc/obsw_pus_tc_packer.py
+++ b/tc/obsw_pus_tc_packer.py
@@ -16,6 +16,7 @@ from tc.obsw_tc_service8 import pack_service8_test_into
 from tc.obsw_tc_service9 import pack_service9_test_into
 from tc.obsw_tc_service23_sdcard import pack_service23_commands_into
 from tc.obsw_tc_service20 import pack_service20_test_into
+from tc.obsw_tc_utility import pack_utility_command
 from tc.obsw_tc_service200 import pack_mode_data, pack_service200_test_into
 from tc.obsw_tc_service5_17 import pack_service5_test_into, pack_service17_test_into
 from tc.obsw_image_handler import generate_img_handler_packet
@@ -60,6 +61,8 @@ class ServiceQueuePacker:
             return generate_img_handler_packet(service_queue, op_code)
         if service.lower() == "core":
             return pack_core_command(service_queue, op_code)
+        if service.lower() == "led":
+            return pack_utility_command(service_queue, op_code)
         if service.lower() == "gps0":
             # Object ID: GPS Device
             object_id = g.GPS0_DEVICE_ID
diff --git a/tc/obsw_tc_service8.py b/tc/obsw_tc_service8.py
index 9166214..6449fcf 100644
--- a/tc/obsw_tc_service8.py
+++ b/tc/obsw_tc_service8.py
@@ -65,5 +65,12 @@ def pack_service8_test_into(tc_queue: Deque, called_externally: bool = False) ->
     return tc_queue
 
 
+def generate_action_command(object_id: bytearray, action_id: int, data: bytearray = bytearray([]),
+                            ssc: int = 0):
+    data_to_pack = bytearray(object_id)
+    data_to_pack += make_action_id(action_id) + data
+    return PusTelecommand(service=8, subservice=128, ssc=ssc, app_data=data_to_pack)
+
+
 def make_action_id(action_id: int) -> bytearray:
     return bytearray(struct.pack('!I', action_id))
diff --git a/tc/obsw_tc_utility.py b/tc/obsw_tc_utility.py
new file mode 100644
index 0000000..9f21283
--- /dev/null
+++ b/tc/obsw_tc_utility.py
@@ -0,0 +1,13 @@
+from typing import Union
+
+from tmtc_core.tc.obsw_pus_tc_base import TcQueueT
+from tc.obsw_tc_service8 import generate_action_command
+from config.obsw_config import LED_TASK_ID
+
+
+def pack_utility_command(service_queue: TcQueueT, op_code: Union[str, int]):
+    if op_code == "A0":
+        service_queue.appendleft(generate_action_command(LED_TASK_ID, 0x00).pack_command_tuple())
+    elif op_code == "A1":
+        service_queue.appendleft(generate_action_command(LED_TASK_ID, 0x01).pack_command_tuple())
+
-- 
GitLab