def __init__(self): self.driver = Ax5043( SPIDevice(busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO))) self.mgr = Manager(self.driver) self.last_transmit_time = datetime.today() self.last_telemetry_time = datetime.today()
def test_autorange_slow_xtal(self): mock = MockAx5043() mgr = Manager(mock) mgr.dispatch() self.assertTrue(isinstance(mgr.state, Manager.Autoranging)) mock.read_queue[Reg.XTALSTATUS] = Bits.XTAL_RUN mgr.dispatch() self.assertFalse(mgr.is_faulted())
class Radio: def __init__(self): self.driver = Ax5043( SPIDevice(busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO))) self.mgr = Manager(self.driver) self.last_transmit_time = datetime.today() self.last_telemetry_time = datetime.today() # Monitor radio health, request reset if faulted def monitorHealth(self): if self.mgr.is_faulted(): logging.error('Radio manager faulted') self.mgr.reset_requested = True return None # Gets the signal from the radio board and returns it in a bytearray def receiveSignal(self): self.mgr.rx_enabled = True self.mgr.dispatch() self.monitorHealth() if self.mgr.outbox.empty(): return None else: return self.mgr.outbox.get() # Downlink given bytearray to ground station def transmit(self, signal: Union[bytearray, bytes]): self.mgr.tx_enabled = True self.mgr.inbox.put(signal) cycles = 0 while True: self.mgr.dispatch() self.monitorHealth() cycles += 1 # After 5s, break for clean shutdown # (TODO: use interrupt handler to ensure clean shutdown when killed, # or monitor transmitting state and exit when complete) if cycles >= 10: break time.sleep(1) self.mgr.tx_enabled = False self.mgr.rx_enabled = False self.mgr.dispatch() self.last_transmit_time = datetime.today()
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))
import logging import time import board import busio from adafruit_bus_device.spi_device import SPIDevice from communications.ax5043_manager.ax5043_driver import Ax5043 from communications.ax5043_manager.ax5043_manager import Manager logging.basicConfig(level=logging.DEBUG) driver = Ax5043( SPIDevice(busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO))) mgr = Manager(driver) mgr.rx_enabled = True cycles = 0 while True: logging.debug('Start of control cycle') # Dispatch components mgr.dispatch() # Health monitoring if mgr.is_faulted(): logging.error('Radio manager faulted') mgr.reset_requested = True # Print any messages received while not mgr.outbox.empty(): m = mgr.outbox.get() print(m)
def test_rx(self): mock = MockAx5043() mock.read_defaults[Reg.XTALSTATUS] = Bits.XTAL_RUN mock.read_defaults[Reg.POWSTAT] |= Bits.SVMODEM mgr = Manager(mock) # Transition to autoranging mgr.dispatch() # Transition to idle mgr.dispatch() # Transition to receiving mgr.rx_enabled = True mgr.dispatch() self.assertTrue(isinstance(mgr.state, Manager.Receiving)) mgr.dispatch() self.assertFalse(mgr.is_faulted())
def test_tx(self): mock = MockAx5043() mock.read_defaults[Reg.XTALSTATUS] = Bits.XTAL_RUN mock.read_defaults[Reg.POWSTAT] |= Bits.SVMODEM mgr = Manager(mock) # Transition to autoranging mgr.dispatch() # Transition to idle mgr.dispatch() # Stay in idle when tx_enabled=False mgr.inbox.put(bytearray([0xCA, 0xFE, 0xBA, 0xBE])) mgr.dispatch() self.assertTrue(isinstance(mgr.state, Manager.Idle)) # Transition to transmitting mgr.tx_enabled = True mgr.dispatch() self.assertTrue(isinstance(mgr.state, Manager.Transmitting)) mgr.dispatch() self.assertFalse(mgr.is_faulted())