def __init__(self, port=None, baudrate=115200, freq=91500, power=15): if port is None: all_ports = self.listPorts() lora_ports = self.listLoRa(all_ports) if not lora_ports is None: self.lora = sxCmd.sxCmd(lora_ports[0]) else: raise ("Please specify which LoRa port to connect") else: self.lora = sxCmd.sxCmd(port)
def test_reset(self): lora = sxCmd.sxCmd("COM5") self.assertTrue(lora.reset()) lora.get_status() self.assertEqual(lora.mode, 0x01) self.assertEqual(lora.freq, 91500) self.assertEqual(lora.power, 0x00)
def listLoRa(self, ports): lora_port = [] for port in ports: tmp_port = sxCmd.sxCmd(port=port.device, auto_connect=True) if tmp_port.ping() == True: lora_port.append(port.device) tmp_port.closePort() if lora_port != None: for index, port in enumerate(lora_port): print(" " + str(index + 1) + ". " + port) print(str(len(lora_port)) + " ports found") return lora_port else: raise OSError('No LoRa device found.')
def test_setting(self): lora = sxCmd.sxCmd("COM5") self.assertTrue(lora.setting(mode=0x01, freq=90000)) self.assertEqual(lora.mode, 0x01) self.assertEqual(lora.freq, 90000) self.assertFalse(lora.setting(mode=6))
def test_getStatus(self): lora = sxCmd.sxCmd("COM5") self.assertTrue(lora.get_status())
def test_ping(self): lora = sxCmd.sxCmd("COM5") self.assertTrue(lora.ping())