예제 #1
0
    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
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
예제 #3
0
    def __init__(self):
        super().__init__()
        logger.info("Initializing...")
        self.init_parameters()
        self.command_queue = Queue()
        self.downlink_queue = Queue()
        self.FMQueue = Queue()
        self.commands_to_execute = []
        self.downlinks_to_execute = []
        self.telemetry = Telemetry(self)
        self.burn_queue = Queue()
        self.reorientation_queue = Queue()
        self.reorientation_list = []
        self.maneuver_queue = Queue()  # maneuver queue
        # self.init_comms()
        self.command_handler = CommandHandler()
        self.downlink_handler = DownlinkHandler()
        self.command_counter = 0
        self.downlink_counter = 0
        self.command_definitions = CommandDefinitions(self)
        self.init_sensors()
        self.last_opnav_run = datetime.now()  # Figure out what to set to for first opnav run
        self.log_dir = LOG_DIR
        self.logger = get_log()
        self.attach_sigint_handler()  # FIXME

        if os.path.isdir(self.log_dir):
            self.flight_mode = RestartMode(self)
        else:
            os.makedirs(CISLUNAR_BASE_DIR)
            os.mkdir(LOG_DIR)
            self.flight_mode = BootUpMode(self)
        self.create_session = create_sensor_tables_from_path(DB_FILE)
예제 #4
0
    def test_register_new_codec(self):
        arg = "testarg"
        ch = CommandHandler()
        ch.register_new_codec(arg, pack_double, unpack_double)
        assert arg in ch.unpackers and arg in ch.packers

        with raises(SerializationException):
            ch.register_new_codec(arg, pack_double, unpack_double)
예제 #5
0
    def __init__(self):
        super().__init__()
        logger.info("Initializing...")
        self.init_parameters()
        self.command_queue = Queue()
        self.downlink_queue = Queue()
        self.FMQueue = Queue()
        self.commands_to_execute = []
        self.downlinks_to_execute = []
        self.burn_queue = Queue()
        self.reorientation_queue = Queue()
        self.reorientation_list = []
        self.maneuver_queue = Queue()  # maneuver queue
        self.opnav_queue = Queue()  # determine state of opnav success
        # self.init_comms()
        logger.info("Initializing commands and downlinks")
        self.command_handler = CommandHandler()
        self.downlink_handler = DownlinkHandler()
        self.command_counter = 0
        self.downlink_counter = 0
        self.command_definitions = CommandDefinitions(self)
        self.last_opnav_run = datetime.now()  # Figure out what to set to for first opnav run
        self.log_dir = LOG_DIR
        self.logger = get_log()
        self.attach_sigint_handler()  # FIXME
        self.file_block_bank = {}
        self.need_to_reboot = False
        self.gom: Gomspace
        self.gyro: GyroSensor
        self.adc: ADC
        self.rtc: RTC
        self.radio: Radio
        self.mux: camera.CameraMux
        self.camera: camera.Camera
        self.nemo_manager: NemoManager
        self.init_sensors()

        # Opnav subprocess variables
        self.opnav_proc_queue = Queue()
        self.opnav_process = Process()  # define the subprocess

        if os.path.isdir(self.log_dir):
            logger.info("We are in Restart Mode")
            self.flight_mode = RestartMode(self)
        else:
            logger.info("We are in Bootup Mode")
            os.makedirs(CISLUNAR_BASE_DIR, exist_ok=True)
            os.mkdir(LOG_DIR)
            self.flight_mode = BootUpMode(self)
        self.create_session = create_sensor_tables_from_path(DB_FILE)
        logger.info("Initializing Telemetry")
        self.telemetry = Telemetry(self)
        logger.info("Done intializing")
예제 #6
0
    def __init__(self):
        super().__init__()
        logger.info("Initializing...")
        self.init_parameters()
        self.command_queue = Queue()
        self.downlink_queue = Queue()
        self.FMQueue = Queue()
        self.commands_to_execute = []
        self.downlinks_to_execute = []
        self.telemetry = Telemetry(self)
        self.burn_queue = Queue()
        self.reorientation_queue = Queue()
        self.reorientation_list = []
        self.maneuver_queue = Queue()  # maneuver queue
        self.opnav_queue = Queue()   # determine state of opnav success
        # self.init_comms()
        self.command_handler = CommandHandler()
        self.downlink_handler = DownlinkHandler()
        self.command_counter = 0
        self.downlink_counter = 0
        self.command_definitions = CommandDefinitions(self)
        self.last_opnav_run = datetime.now()  # Figure out what to set to for first opnav run
        self.log_dir = LOG_DIR
        self.logger = get_log()
        self.attach_sigint_handler()  # FIXME
        self.need_to_reboot = False

        self.gom = None
        self.gyro = None
        self.adc = None
        self.rtc = None
        self.radio = None
        self.mux = None
        self.camera = None
        self.init_sensors()

        # Telemetry
        self.tlm = Telemetry(self)

        # Opnav subprocess variables
        self.opnav_proc_queue = Queue()
        self.opnav_process = Process()  # define the subprocess

        if os.path.isdir(self.log_dir):
            self.flight_mode = RestartMode(self)
        else:
            os.makedirs(CISLUNAR_BASE_DIR, exist_ok=True)
            os.mkdir(LOG_DIR)
            self.flight_mode = BootUpMode(self)
        self.create_session = create_sensor_tables_from_path(DB_FILE)
예제 #7
0
import communications.groundstation as gs
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))
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]
예제 #9
0
    def test_packers_unpackers_match(self):
        ch = CommandHandler()

        assert set(ch.packers.keys()) == set(ch.unpackers.keys())