eive-tmtc/pus_tc/star_tracker.py

262 lines
14 KiB
Python
Raw Normal View History

2021-08-16 10:03:40 +02:00
# -*- coding: utf-8 -*-
"""
@file star_tracker.py
@brief Star tracker commanding
@author J. Meier
@date 14.08.2021
"""
import struct
from tmtccmd.config.definitions import QueueCommands
from tmtccmd.tc.packer import TcQueueT
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tc import PusTelecommand
2021-12-14 19:25:23 +01:00
from pus_tc.service_200_mode import pack_mode_data
2021-08-16 10:03:40 +02:00
class StarTrackerActionIds:
PING = 0
2021-12-02 08:01:18 +01:00
BOOT = 1
REQ_VERSION = 2
REQ_INTERFACE = 3
REQ_TIME = 4
REQ_POWER = 11
2021-12-14 19:25:23 +01:00
SWITCH_TO_BOOTLOADER_PROGRAM = 7
2021-12-06 15:44:34 +01:00
DOWNLOAD_IMAGE = 9
UPLOAD_IMAGE = 10
2021-12-02 08:01:18 +01:00
SUBSCRIBE_TO_TM = 18
REQ_SOLUTION = 24
2021-08-16 10:03:40 +02:00
REQ_TEMPERATURE = 25
REQ_HISTOGRAM = 28
2021-12-19 11:35:16 +01:00
REQ_CONTRAST = 29
2021-12-06 15:44:34 +01:00
LIMITS = 40
2021-12-13 07:55:34 +01:00
MOUNTING = 41
CAMERA = 42
BLOB = 43
CENTROIDING = 44
LISA = 45
MATCHING = 46
TRACKING = 47
VALIDATION = 48
ALGO = 49
2021-12-19 14:49:22 +01:00
CHECKSUM = 50
RAED = 51
WRITE = 52
2021-12-13 07:55:34 +01:00
TAKE_IMAGE = 15
STOP_IMAGE_LOADER = 55
RESET_ERROR = 56
CHANGE_DOWNLOAD_IMAGE = 57
2021-12-19 14:49:22 +01:00
SET_JSON_FILE_NAME = 58
2021-12-06 15:44:34 +01:00
class ImagePathDefs:
uploadFile = "/mnt/sd0/startracker/gemma.bin"
2021-12-13 07:55:34 +01:00
downloadFile = "test_image.bin"
downloadPath = "/mnt/sd0/startracker"
2021-12-19 14:49:22 +01:00
jsonFile = "/mnt/sd0/startracker/test.json"
2021-08-16 10:03:40 +02:00
2021-12-02 08:01:18 +01:00
def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str) -> TcQueueT:
2021-08-16 10:03:40 +02:00
tc_queue.appendleft(
(QueueCommands.PRINT,
"Generate command for star tracker with object id: 0x" + object_id.hex())
)
if op_code == "0":
2021-12-14 19:25:23 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode On"))
command = pack_mode_data(object_id, 1, 0)
command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "1":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Normal"))
command = pack_mode_data(object_id, 2, 0)
command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "2":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Off"))
command = pack_mode_data(object_id, 0, 0)
command = PusTelecommand(service=200, subservice=1, ssc=12, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "3":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Raw"))
command = pack_mode_data(object_id, 3, 0)
command = PusTelecommand(service=200, subservice=1, ssc=13, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "4":
2021-08-16 10:03:40 +02:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Ping"))
2021-12-02 08:01:18 +01:00
command = object_id + struct.pack('!I', StarTrackerActionIds.PING)
2021-08-16 10:03:40 +02:00
command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "5":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Switch to bootloader program"))
command = object_id + struct.pack('!I', StarTrackerActionIds.SWITCH_TO_BOOTLOADER_PROGRAM)
2021-12-02 08:01:18 +01:00
command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "6":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Temperature request"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_TEMPERATURE)
command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "7":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request version"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_VERSION)
command = PusTelecommand(service=8, subservice=128, ssc=33, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "8":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request interface"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_INTERFACE)
command = PusTelecommand(service=8, subservice=128, ssc=34, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "9":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request power"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_POWER)
command = PusTelecommand(service=8, subservice=128, ssc=35, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "10":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Subscribe to telemetry"))
tm_id = int(input("Specify Id of tm: "))
command = object_id + struct.pack('!I', StarTrackerActionIds.SUBSCRIBE_TO_TM) + struct.pack('B', tm_id)
command = PusTelecommand(service=8, subservice=128, ssc=36, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "11":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Boot"))
command = object_id + struct.pack('!I', StarTrackerActionIds.BOOT)
command = PusTelecommand(service=8, subservice=128, ssc=37, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "12":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request time"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_TIME)
command = PusTelecommand(service=8, subservice=128, ssc=38, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "13":
2021-12-02 08:01:18 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request solution"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_SOLUTION)
command = PusTelecommand(service=8, subservice=128, ssc=39, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "14":
2021-12-06 15:44:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Upload image"))
command = object_id + struct.pack('!I', StarTrackerActionIds.UPLOAD_IMAGE) + \
bytearray(ImagePathDefs.uploadFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=40, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "15":
2021-12-06 15:44:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download image"))
2021-12-13 07:55:34 +01:00
command = object_id + struct.pack('!I', StarTrackerActionIds.DOWNLOAD_IMAGE) + \
bytearray(ImagePathDefs.downloadPath, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=53, app_data=command)
2021-12-06 15:44:34 +01:00
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "16":
2021-12-06 15:44:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set limits"))
command = object_id + struct.pack('!I', StarTrackerActionIds.LIMITS) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
2021-12-13 07:55:34 +01:00
command = PusTelecommand(service=8, subservice=128, ssc=42, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "17":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set tracking parameters"))
command = object_id + struct.pack('!I', StarTrackerActionIds.TRACKING) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=43, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "18":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mounting"))
command = object_id + struct.pack('!I', StarTrackerActionIds.MOUNTING) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=44, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "19":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Camera"))
command = object_id + struct.pack('!I', StarTrackerActionIds.CAMERA) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=45, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "20":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Blob"))
command = object_id + struct.pack('!I', StarTrackerActionIds.BLOB) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=46, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "21":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Centroiding"))
command = object_id + struct.pack('!I', StarTrackerActionIds.CENTROIDING) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=47, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "22":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: LISA"))
command = object_id + struct.pack('!I', StarTrackerActionIds.LISA) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=48, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "23":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Matching"))
command = object_id + struct.pack('!I', StarTrackerActionIds.MATCHING) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=49, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "24":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Validation"))
command = object_id + struct.pack('!I', StarTrackerActionIds.VALIDATION) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=50, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "25":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Algo"))
command = object_id + struct.pack('!I', StarTrackerActionIds.ALGO) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=51, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "26":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Take image"))
2021-12-14 19:25:23 +01:00
actionid = int(input("Specify parameter ID (nominal - 4): "))
2021-12-13 07:55:34 +01:00
command = object_id + struct.pack('!I', StarTrackerActionIds.TAKE_IMAGE) + struct.pack('!B', actionid)
command = PusTelecommand(service=8, subservice=128, ssc=52, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "27":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Stop image loader"))
command = object_id + struct.pack('!I', StarTrackerActionIds.STOP_IMAGE_LOADER)
command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "28":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Reset error signal"))
command = object_id + struct.pack('!I', StarTrackerActionIds.RESET_ERROR)
command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-14 19:25:23 +01:00
if op_code == "29":
2021-12-13 07:55:34 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set name of download image"))
filename = input("Specify download image name: ")
command = object_id + struct.pack('!I', StarTrackerActionIds.CHANGE_DOWNLOAD_IMAGE) + \
bytearray(filename, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command)
2021-12-06 15:44:34 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "30":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request histogram"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_HISTOGRAM)
command = PusTelecommand(service=8, subservice=128, ssc=55, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-19 11:35:16 +01:00
if op_code == "31":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request contrast"))
command = object_id + struct.pack('!I', StarTrackerActionIds.REQ_CONTRAST)
command = PusTelecommand(service=8, subservice=128, ssc=56, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
2021-12-19 14:49:22 +01:00
if op_code == "32":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set json filename"))
command = object_id + struct.pack('!I', StarTrackerActionIds.SET_JSON_FILE_NAME) + \
bytearray(ImagePathDefs.jsonFile, 'utf-8')
command = PusTelecommand(service=8, subservice=128, ssc=57, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == "33":
tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Write"))
command = pack_write_command(object_id)
command = PusTelecommand(service=8, subservice=128, ssc=58, app_data=command)
tc_queue.appendleft(command.pack_command_tuple())
def pack_write_command(object_id: bytearray) -> bytearray:
region = 1
address = 0
length = 1024
data = bytearray([1] * 1024)
command = object_id + struct.pack('!I', StarTrackerActionIds.WRITE) + struct.pack('!B', region) + \
struct.pack('I', address) + struct.pack('!H', length) + data
return command