def add_forward_action(self, interface_type=InterfaceType.HOST, interface_configuration=None): if interface_configuration is not None and interface_type == InterfaceType.HOST: raise ValueError( "interface_configuration is not supported for interface_type HOST" ) if interface_type == InterfaceType.D7ASP: if interface_configuration is None: interface_configuration = Configuration() self.actions.append( RegularAction(operation=Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.D7ASP, interface_configuration=interface_configuration)))) elif interface_type == InterfaceType.SERIAL: self.actions.append( RegularAction(operation=Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.SERIAL)))) elif interface_type == InterfaceType.LORAWAN_ABP: self.actions.append( RegularAction(operation=Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.LORAWAN_ABP, interface_configuration=interface_configuration)))) elif interface_type == InterfaceType.LORAWAN_OTAA: self.actions.append( RegularAction(operation=Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.LORAWAN_OTAA, interface_configuration=interface_configuration)))) elif interface_type == InterfaceType.HOST: pass else: raise ValueError( "interface_type {} is not supported".format(interface_type))
def __init__(self, interface_configuration=InterfaceConfiguration(interface_id=InterfaceType.D7ASP, interface_configuration=None), file_id=0x1D): self.interface_configuration = interface_configuration if interface_configuration.interface_id == InterfaceType.D7ASP: File.__init__(self, file_id, 13) elif interface_configuration.interface_id == InterfaceType.LORAWAN_OTAA: File.__init__(self, file_id, 36) elif interface_configuration.interface_id == InterfaceType.LORAWAN_ABP: File.__init__(self, file_id, 44) Validatable.__init__(self)
def parse_forward_action(self, b7, b6, s): if b7: raise ParseError("bit 7 is RFU") interface_id = InterfaceType(int(s.read("uint:8"))) assert(interface_id == InterfaceType.D7ASP) interface_config = Configuration.parse(s) return ForwardAction(resp=b6, operation=Forward(operand=InterfaceConfiguration(interface_id=interface_id, interface_configuration=interface_config)))
def test_byte_generation(self): d7asp_config = Configuration() forward_action = Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.D7ASP, interface_configuration=d7asp_config)) bytes = bytearray(forward_action) self.assertEqual(len(bytes), len(bytearray(d7asp_config)) + 1) self.assertEqual(bytes[0], 0xD7) self.assertEqual(bytes[1:], bytearray(d7asp_config))
def add_forward_action(self, interface_type=InterfaceType.HOST, interface_configuration=None): if interface_configuration is not None and interface_type == InterfaceType.HOST: raise ValueError( "interface_configuration is not supported for interface_type HOST" ) if interface_type == InterfaceType.D7ASP: if interface_configuration is None: interface_configuration = Configuration() self.actions.append( RegularAction(operation=Forward(operand=InterfaceConfiguration( interface_id=InterfaceType.D7ASP, interface_configuration=interface_configuration))))
def parse_forward_action(self, b7, b6, s): if b7: raise ParseError("bit 7 is RFU") interface_id = InterfaceType(int(s.read("uint:8"))) interface_config = None if (interface_id == InterfaceType.D7ASP): interface_config = Configuration.parse(s) elif (interface_id == InterfaceType.SERIAL): pass # no interface config else: assert (False) return ForwardAction(resp=b6, operation=Forward(operand=InterfaceConfiguration( interface_id=interface_id, interface_configuration=interface_config)))
def test_byte_generation_forward_LoRaWAN_OTAA_iface(self): lorawan_config = LoRaWANInterfaceConfigurationOTAA( adr_enabled=True, request_ack=False, app_port=0x01, data_rate=0, device_eui=[0xBE, 0X7A, 0X00, 0X00, 0X00, 0X00, 0X1B, 0X81], app_eui=[0xBE, 0X7A, 0X00, 0X00, 0X00, 0X00, 0X0D, 0X9F], app_key=[0X7E, 0XEF, 0X56, 0XEC, 0XDA, 0X1D, 0XD5, 0XA4, 0X70, 0X59, 0XFD, 0X35, 0X9C, 0XE6, 0X80, 0XCD] ) forward_action = Forward( operand=InterfaceConfiguration( interface_id=InterfaceType.LORAWAN_OTAA, interface_configuration=lorawan_config ) ) bytes = bytearray(forward_action) self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1) self.assertEqual(bytes[0], 0x03) self.assertEqual(bytes[1:], bytearray(lorawan_config))
def test_byte_generation_forward_LoRaWAN_ABP_iface(self): lorawan_config = LoRaWANInterfaceConfigurationABP( adr_enabled=True, request_ack=False, app_port=0x01, data_rate=0, netw_session_key=[0x53, 0X1b, 0Xd9, 0Xc5, 0Xec, 0X5d, 0X8b, 0Xa5, 0Xef, 0X3b, 0X26, 0X2c, 0Xeb, 0Xfb, 0X3e, 0X66], app_session_key=[0x53, 0X1b, 0Xd9, 0Xc5, 0Xec, 0X5d, 0X8b, 0Xa5, 0Xef, 0X3b, 0X26, 0X2c, 0Xeb, 0Xfb, 0X3e, 0X66], dev_addr=1, netw_id=2, ) forward_action = Forward( operand=InterfaceConfiguration( interface_id=InterfaceType.LORAWAN_ABP, interface_configuration=lorawan_config ) ) bytes = bytearray(forward_action) self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1) self.assertEqual(bytes[0], 0x02) self.assertEqual(bytes[1:], bytearray(lorawan_config))
config = argparser.parse_args() configure_default_logger(config.verbose) modem = Modem(config.device, config.rate, unsolicited_response_received_callback=received_command_callback) modem.connect() # D7 Example interface_file = InterfaceConfigurationFile( interface_configuration=InterfaceConfiguration( interface_id=InterfaceType.D7ASP, interface_configuration=Configuration( qos=QoS(resp_mod=ResponseMode.RESP_MODE_PREFERRED, retry_mod=RetryMode.RETRY_MODE_NO, stop_on_err=False, record=False), dorm_to=CT(), addressee=Addressee(nls_method=NlsMethod.NONE, id_type=IdType.UID, access_class=0x01, id=CT(mant=3, exp=0))))) # LORAWAN OTAA Example # interface_file = InterfaceConfigurationFile( # interface_configuration=InterfaceConfiguration( # interface_id=InterfaceType.LORAWAN_OTAA, # interface_configuration=LoRaWANInterfaceConfigurationOTAA( # adr_enabled=True, # request_ack=True, # app_port=2, # data_rate=0,
ord(b) for b in struct.pack(">H", int(config.temperature * 10)) ], file_a_offset=Offset(id=0x40, offset=Length(0)))))) # ...if the query succeeds, read the file query_sensor_file_cmd.add_action( RegularAction(operation=ReadFileData( operand=DataRequest(offset=Offset(id=0x40), length=Length(2))))) # the interface config to send the result of above action to interface_config = InterfaceConfiguration( InterfaceType.D7ASP, Configuration(qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO, retry_mod=RetryMode.RETRY_MODE_NO, stop_on_err=False, record=False), dorm_to=CT(), addressee=Addressee(access_class=0x01, id_type=IdType.NOID, id=None, nls_method=NlsMethod.NONE))) # create the command to write the action file and interface configuration file, # adapt the properties on the sensor file and forward using the downlink access profile cmd = Command() cmd.add_forward_action( InterfaceType.D7ASP, Configuration(qos=QoS(resp_mod=ResponseMode.RESP_MODE_ALL, retry_mod=RetryMode.RETRY_MODE_NO, stop_on_err=False, record=False),