def test_config2_command(): config2 = ps.eps_config2_t() config2.batt_maxvoltage = 8300 config2.batt_normalvoltage = 7600 config2.batt_safevoltage = 7200 config2.batt_criticalvoltage = 6800 config2_dict = dict_from_eps_config2(config2) COUNTER = 0 ch = CommandHandler() command_bytes = ch.pack_command(COUNTER, FMEnum.Normal.value, NormalCommandEnum.GomConf2Set.value, **config2_dict) mac, counter, mode, command_id, kwargs = ch.unpack_command(command_bytes) assert mac == MAC assert counter == COUNTER assert mode == FMEnum.Normal.value assert command_id == NormalCommandEnum.GomConf2Set.value unpacked_config2 = eps_config2_from_dict(kwargs) assert config2._fields_ == unpacked_config2._fields_ # ps.displayConfig2(config2) # ps.displayConfig2(unpacked_config2) assert config2.batt_maxvoltage == unpacked_config2.batt_maxvoltage assert config2.batt_normalvoltage == unpacked_config2.batt_normalvoltage assert config2.batt_safevoltage == unpacked_config2.batt_safevoltage assert config2.batt_criticalvoltage == unpacked_config2.batt_criticalvoltage
def test_command_serialization(self): # Both are doubles arg1 = "arg1" arg2 = "arg2" ch = CommandHandler() print(f"Packers: {ch.packers}") command_args = [arg1, arg2] command_data_tuple = (command_args, 16) application_id = 78 command_dict = {application_id: command_data_tuple} mode_id = 255 kwargs = { arg1: 78.1, arg2: 99.5, } command_counter = 1 ch.register_new_command(mode_id, application_id, **kwargs) command_buffer = ch.pack_command(command_counter, mode_id, application_id, **kwargs) assert len(command_buffer) == ch.get_command_size(mode_id, application_id) unpacked_mac, unpacked_counter, unpacked_mode, unpacked_app, unpacked_args = ch.unpack_command(command_buffer) print(unpacked_args) assert unpacked_mode == mode_id assert unpacked_app == application_id assert unpacked_args[arg1] == kwargs[arg1] assert unpacked_args[arg2] == kwargs[arg2] assert unpacked_counter == command_counter assert unpacked_mac == MAC
from communications.commands import CommandHandler import board import busio import time from adafruit_bus_device.spi_device import SPIDevice from communications.ax5043_manager.ax5043_driver import Ax5043 from communications.ax5043_manager.ax5043_manager import Manager #Radio setup driver = Ax5043(SPIDevice(busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO))) mgr = Manager(driver) ch = CommandHandler() #Pack command into a bytearray gs.registerCommand(ch,1,2,number1=7, number2=4) command = ch.pack_command(1,2,number1=7, number2=4) #Send the command to the satellite gs.transmitCommand(mgr, command) print('Transmitted') print('Entering Receiving Mode') cycleNumber = 1 #Enter listening mode while True: print('Cycle: ' + str(cycleNumber)) message = gs.receiveSignal(mgr)
def test_config_command(): config = ps.eps_config_t() config.ppt_mode = randint(1, 2) config.battheater_mode = randint(0, 1) config.battheater_low = randint(0, 5) config.battheater_high = randint(6, 20) config.output_normal_value[0] = randint(0, 1) config.output_normal_value[1] = randint(0, 1) config.output_normal_value[2] = randint(0, 1) config.output_normal_value[3] = randint(0, 1) config.output_normal_value[4] = randint(0, 1) config.output_normal_value[5] = randint(0, 1) config.output_normal_value[6] = randint(0, 1) config.output_normal_value[7] = randint(0, 1) config.output_safe_value[0] = randint(0, 1) config.output_safe_value[1] = randint(0, 1) config.output_safe_value[2] = randint(0, 1) config.output_safe_value[3] = randint(0, 1) config.output_safe_value[4] = randint(0, 1) config.output_safe_value[5] = randint(0, 1) config.output_safe_value[6] = randint(0, 1) config.output_safe_value[7] = randint(0, 1) initial_on = randint(0, 65535) config.output_initial_on_delay[0] = initial_on config.output_initial_on_delay[1] = initial_on config.output_initial_on_delay[2] = initial_on config.output_initial_on_delay[3] = initial_on config.output_initial_on_delay[4] = initial_on config.output_initial_on_delay[5] = initial_on config.output_initial_on_delay[6] = initial_on config.output_initial_on_delay[7] = initial_on initial_off = randint(0, 65535) config.output_initial_off_delay[0] = initial_off config.output_initial_off_delay[1] = initial_off config.output_initial_off_delay[2] = initial_off config.output_initial_off_delay[3] = initial_off config.output_initial_off_delay[4] = initial_off config.output_initial_off_delay[5] = initial_off config.output_initial_off_delay[6] = initial_off config.output_initial_off_delay[7] = initial_off config.vboost[0] = randint(1000, 4000) config.vboost[1] = randint(1000, 4000) config.vboost[2] = randint(1000, 4000) config_dict = dict_from_eps_config(config) COUNTER = 0 ch = CommandHandler() command_bytes = ch.pack_command(COUNTER, FMEnum.Normal.value, NormalCommandEnum.GomConf1Set.value, **config_dict) mac, counter, mode, command_id, kwargs = ch.unpack_command(command_bytes) assert mac == MAC assert counter == COUNTER assert mode == FMEnum.Normal.value assert command_id == NormalCommandEnum.GomConf1Set.value unpacked_config = eps_config_from_dict(**kwargs) # ps.displayConfig(config) # ps.displayConfig(unpacked_config) assert config.ppt_mode == unpacked_config.ppt_mode assert config.battheater_mode == unpacked_config.battheater_mode assert config.battheater_low == unpacked_config.battheater_low assert config.battheater_high == unpacked_config.battheater_high assert config.output_normal_value[ 0] == unpacked_config.output_normal_value[0] assert config.output_normal_value[ 1] == unpacked_config.output_normal_value[1] assert config.output_normal_value[ 2] == unpacked_config.output_normal_value[2] assert config.output_normal_value[ 3] == unpacked_config.output_normal_value[3] assert config.output_normal_value[ 4] == unpacked_config.output_normal_value[4] assert config.output_normal_value[ 5] == unpacked_config.output_normal_value[5] assert config.output_normal_value[ 6] == unpacked_config.output_normal_value[6] assert config.output_normal_value[ 7] == unpacked_config.output_normal_value[7] assert config.output_safe_value[0] == unpacked_config.output_safe_value[0] assert config.output_safe_value[1] == unpacked_config.output_safe_value[1] assert config.output_safe_value[2] == unpacked_config.output_safe_value[2] assert config.output_safe_value[3] == unpacked_config.output_safe_value[3] assert config.output_safe_value[4] == unpacked_config.output_safe_value[4] assert config.output_safe_value[5] == unpacked_config.output_safe_value[5] assert config.output_safe_value[6] == unpacked_config.output_safe_value[6] assert config.output_safe_value[7] == unpacked_config.output_safe_value[7] assert config.output_initial_on_delay[ 0] == unpacked_config.output_initial_on_delay[0] assert config.output_initial_off_delay[ 0] == unpacked_config.output_initial_off_delay[0] assert config.vboost[0] == unpacked_config.vboost[0] assert config.vboost[1] == unpacked_config.vboost[1] assert config.vboost[2] == unpacked_config.vboost[2]
from communications.satellite_radio import Radio from communications.commands import CommandHandler from communications.downlink import DownlinkHandler import time # Setup ch = CommandHandler() dh = DownlinkHandler() groundstation = Radio() # Send command to get gyro/mag/acc data gmaCommand = ch.pack_command(1, 8, 7) groundstation.transmit(gmaCommand) print('GMA Command Transmitted') # Listen for response print('Receiving...') cycle = 1 while True: print('Receiving Cycle: ' + str(cycle)) downlink = groundstation.receiveSignal() if downlink is not None: print('Downlink Received:') data = dh.unpack_downlink(downlink)[-1] print('Gyro: ' + str(data['gyro1']) + ', ' + str(data['gyro2']) + ', ' + str(data['gyro3'])) break
mode_id = int(commandArguments[0]) command_id = int(commandArguments[1]) kwargs = {} if len(commandArguments) > 2: argsList = commandArguments[2:] for i in range(len(argsList)): signIndex = argsList[i].index('=') argName = argsList[i][:signIndex] argValue = argsList[i][signIndex +1:] arg_type = FLIGHT_MODE_DICT[mode_id].command_arg_types[argName] if arg_type == 'int' or arg_type == 'short': argValue = int(argValue) elif arg_type == 'float' or arg_type == 'double': argValue = float(argValue) elif arg_type == 'bool': if argValue == 'True': argValue = True else: argValue = False kwargs[argName] = argValue commandToTransmit = ch.pack_command(commandCounter, mode_id, command_id, **kwargs) groundstation.transmit(commandToTransmit) commandCounter += 1 print('Successfully transmitted ' + str(ch.unpack_command(commandToTransmit))) time.sleep(transmitInterval)
"""command_queue_writer.py: a temporary workaround to not having functioning radio drivers. Instead of sending commands to the EDU/HITL through the radio board, use this to write commands to a txt file, which is then read by main.py's read_command_queue_from_file method """ from communications.commands import CommandHandler from utils.log import get_log logger = get_log() ch = CommandHandler() fm_num = int(0) filename = "command_queue.txt" command_counter = 1 while fm_num > -1: fm_num = int(input("What flight mode would you like to command in?\n")) if fm_num > -1: command_num = int(input("What command ID would you like to send?\n")) if command_num > -1: kwarg_str = input( "Please input any arguments as a valid python dictionary:\n") kwarg_dict = eval(kwarg_str) packed = ch.pack_command(command_counter, fm_num, command_num, **kwarg_dict) file = open(filename, "a") file.write(str(packed.hex()) + "\n") file.close() logger.info(f"Wrote hex bytes {str(packed.hex())}")