def __init__(self, serial_device): Device.__init__(self, mode='t', device_id=serial_device) self.logger = logging.getLogger( "mycodo.device.atlas_scientific_ftdi_{dev}".format(dev=serial_device)) time.sleep(1) self.flush() self.setup = True
def __init__(self, serial_device): Device.__init__(self, mode='t', device_id=serial_device) self.logger = logging.getLogger( "{}_{}".format(__name__, serial_device)) time.sleep(1) self.flush() self.setup = True
def __init__(self, serial_device): Device.__init__(self, mode='t', device_id=serial_device) self.logger = logging.getLogger( "mycodo.device.atlas_scientific_ftdi_{dev}".format( dev=serial_device)) time.sleep(1) self.flush() self.setup = True
def testOpen(self): # a lazy_open open() shouldn't do anything self.assertCallsExact(lambda: Device(lazy_open=True), []) # a non-lazy_open open() should open the port... self.assertCalls(lambda: Device(), 'ftdi_usb_open_desc_index') # should be the same with device_id... self.assertCalls(lambda: Device('bogus'), 'ftdi_usb_open_desc_index') # should be the same with device_id... self.assertCalls(lambda: Device(device_index=2), 'ftdi_usb_open_desc_index')
def testClose(self): d = Device() d.close() self.assertRaises(FtdiError, d.write, 'hello') d = Device() d.close() self.assertRaises(FtdiError, d.read, 1)
def findRadio(self): self.devices = Driver().list_devices() self.radio = None for d in self.devices: # ross - print('d[1]="{0}" self.radioName="{1}"'.format(d[1], self.radioName)) if (d[1] == self.radioName.decode('utf-8')): self.print('found radio') try: self.radio = Device(encoding='utf-8') except FtdiError as err: print('Device instantiation failed: {0}'.format(err)) if self.radio: print('connected to radio') self.radio.flush() self.boot() else: print('unable to connect to radio')
def __init__(self, serial_device): Device.__init__(self, mode='t', device_id=serial_device) super(AtlasScientificFTDI, self).__init__(interface='FTDI', name=serial_device.replace("/", "_")) self.logger = logging.getLogger( "{}_{}".format(__name__, serial_device)) self.send_cmd("C,0") # turn off continuous mode time.sleep(1) self.flush() (board, revision, firmware_version) = self.get_board_version() self.logger.info( "Atlas Scientific Board: {brd}, Rev: {rev}, Firmware: {fw}".format( brd=board, rev=revision, fw=firmware_version)) self.setup = True
def __init__(self, sn): Device.__init__(self, mode='t', device_id=sn)
def testFlush(self): with Device() as dev: self.assertCalls(dev.flush_input, 'ftdi_usb_purge_rx_buffer') self.assertCalls(dev.flush_output, 'ftdi_usb_purge_tx_buffer') self.assertCalls(dev.flush, 'ftdi_usb_purge_buffers')
def testReadWrite(self): with Device() as dev: self.assertCalls(lambda: dev.write('xxx'), 'ftdi_write_data') self.assertCalls(lambda: dev.read(10), 'ftdi_read_data')
def testOpenInterface(self): self.assertCalls(lambda: Device(interface_select=1), 'ftdi_set_interface') # check that opening a specific interface does that self.assertNotCalls(lambda: Device(), 'ftdi_set_interface')
def _(): with Device(): pass
def DelDevice(self): Device.__del__(self)
class Listener: def __init__(self): self.makeItStop = Event() self.warmBoot = False self.radioName = b'SDR-IQ' self.print = self.noOp self.boot = self.coldBoot self.doCommandline() self.findRadio() def doCommandline(self): try: opts, args = getopt.getopt(sys.argv[1:], 'br:v') except getopt.GetoptError: print('usage: server [-b,-r <radio>, -v]') sys.exit(2) for op in opts: if op[0] == '-b': self.boot = self.noOp elif op[0] == '-r': self.radioName = bytes(op[1], encoding='utf-8') elif op[0] == '-v': self.print = print else: print(f'unknown option: {op}') def stop(self): self.makeItStop.set() def noOp(self, *kargs): return def coldBoot(self): freq = self.GetFreq() if (freq == 680000): self.print('Cold boot detected') self.SetDSP() self.SetFreq(680001) def findRadio(self): self.devices = Driver().list_devices() self.radio = None for d in self.devices: # ross - print('d[1]="{0}" self.radioName="{1}"'.format(d[1], self.radioName)) if (d[1] == self.radioName.decode('utf-8')): self.print('found radio') try: self.radio = Device(encoding='utf-8') except FtdiError as err: print('Device instantiation failed: {0}'.format(err)) if self.radio: print('connected to radio') self.radio.flush() self.boot() else: print('unable to connect to radio') def GetFreq(self): self.radio.write(bc.GetFreq) rep = readMsg(self.radio.read) return sum([rep[k + 5] << (8 * k) for k in range(4)]) def SetFreq(self, freq): msg = list(bc.SetFreq) for k in range(4): msg[k + 5] = (freq >> (8 * k)) & 0xFF self.radio.write(bytes(msg)) return readMsg(self.radio.read) def SetDSP(self): for cmd in bc.BWKHZ_190: self.radio.write(cmd) self.radio.read(3) self.radio.flush() def SetIFGain(self): cmd = list(bc.SetIFGain) cmd[5] = 24 self.radio.write(bytes(cmd)) self.radio.read(5) def SetRFGain(self): cmd = list(bc.SetRFGain) cmd[5] = 0 self.radio.write(bytes(cmd)) def serve(self): if not self.radio: print(f'Radio {self.radioName.decode()} not found') return self.tcp = socket(AF_INET, SOCK_STREAM) # ross 2020-06-10: We want to accept connections from anywhere. # '' is equivalent to AF_ANY. #self.tcp.bind(('localhost',50000)) self.tcp.bind(('', 50000)) self.tcp.listen(1) self.udp = socket(AF_INET, SOCK_DGRAM) self.udp.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # ross 2020-06-10: We want to send data to anywhere # '' is equivalent to AF_ANY. #self.udp.bind(('localhost',50100)) self.udp.bind(('', 50100)) self.print('listening on port 50000') try: self.connect = self.tcp.accept() except: # ross TODO: print the exception return self.print( f'Connected: {self.connect[1][0]} on port {self.connect[1][1]}') # ross - Connected: 192.168.76.28 on port 60887 self.writer = RadioWriter(self) self.reader = RadioReader(self) self.writer.start() self.reader.start() self.makeItStop.wait() self.print('closing TCP and UDP sockets') self.tcp.close() self.udp.close() self.print('Server - done')