def __init__(self, mode=EngineeringModeMode.ENGINEERING_MODE_MODE_OFF, flags=0, timeout=0, channel_id=ChannelID(channel_header=ChannelHeader( ChannelCoding.PN9, ChannelClass.LO_RATE, ChannelBand.BAND_868), channel_index=0), eirp=0): self.mode = mode self.flags = flags self.timeout = timeout self.channel_id = channel_id self.eirp = eirp File.__init__(self, SystemFileIds.ENGINEERING_MODE, 9) Validatable.__init__(self)
def test_byte_generation(self): expected = [ 0b00101000, 0, 16 # channel_id ] channel_id = ChannelID( ChannelHeader(channel_coding=ChannelCoding.PN9, channel_class=ChannelClass.NORMAL_RATE,channel_band=ChannelBand.BAND_433), 16 ) bytes = bytearray(channel_id) for i in xrange(len(bytes)): self.assertEqual(expected[i], bytes[i]) self.assertEqual(len(expected), len(bytes))
def test_simple_received_return_file_data_command(self): cmd = Command( generate_tag_request_action=False, actions=[ RegularAction(operation=ReturnFileData( operand=Data(data=list(bytearray("Hello world")), offset=Offset(id=0x51)))), StatusAction( status_operand_extension=StatusActionOperandExtensions. INTERFACE_STATUS, operation=InterfaceStatus(operand=InterfaceStatusOperand( interface_id=0xD7, interface_status=D7ASpStatus(channel_id=ChannelID( channel_header=ChannelHeader( channel_band=ChannelBand.BAND_433, channel_class=ChannelClass.LO_RATE, channel_coding=ChannelCoding.PN9), channel_index=16), rx_level=70, link_budget=80, target_rx_level=80, nls=False, missed=False, retry=False, unicast=False, fifo_token=200, seq_nr=0, response_to=CT(mant=20), addressee=Addressee())))) ]) expected = [ 0x62, # Interface Status action 0xD7, # D7ASP interface 32, # channel header 0, 16, # channel_id 70, # rxlevel (- dBm) 80, # link budget 80, # target rx level 0, # status 200, # fifo token 0, # seq 20, # response timeout 0x10, # addressee ctrl (NOID) 0, # access class 0x20, # action=32/ReturnFileData 0x51, # File ID 0x00, # offset 0x0b, # length 0x48, 0x65, 0x6c, 0x6c, 0x6f, # Hello 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64 # World ] bytes = bytearray(cmd) self.assertEqual(len(bytes), len(expected)) for i in xrange(len(expected)): self.assertEqual(bytes[i], expected[i])
help= "for example 868LP000 ; format FFFRCIII where FFF={433, 868, 915}, R={L, N, H, R (LORA)}, C={P (PN9), F (FEC), C (CW)} III=000...280", default="868LP000") modes = ["OFF", "CONT_TX", "TRANSIENT_TX", "PER_RX", "PER_TX"] argparser.add_argument("-m", "--mode", choices=modes, required=True) argparser.add_argument("-e", "--eirp", help="EIRP in dBm", type=int, default=0) argparser.add_argument("-t", "--timeout", help="timeout", type=int, default=0) argparser.add_argument("-x", "--not_exe", help="Don't execute the command on the modem", default=False, action="store_true") config = argparser.parse_args() configure_default_logger(config.verbose) ch = ChannelID.from_string(config.channel_id) print("Using mode {} for channel {} with TX EIRP {} dBm".format( config.mode, config.channel_id, config.eirp)) mode = EngineeringModeMode.from_string(config.mode) emFile = EngineeringModeFile(mode=mode, flags=0, timeout=config.timeout, channel_id=ch, eirp=config.eirp) print(list(emFile)) if not config.not_exe: modem = Modem( config.device,