def test_byte_generation(self): tests = [ (Addressee(), '00010000'), # NOID (Addressee(id_type=IdType.NBID, id=CT(0)), '00000000'), (Addressee(id_type=IdType.VID, id=0), '00110000'), (Addressee(id_type=IdType.UID, id=0), '00100000'), (Addressee(id_type=IdType.NBID, id=CT(0), nls_method=NlsMethod.AES_CTR), '00000001') ] for test in tests: addressee_ctrl = bytearray(test[0])[0] self.assertEqual(addressee_ctrl, int(test[1], 2)) bs = bytearray(Addressee(id_type=IdType.VID, id=0x1234, access_class=5)) self.assertEqual(len(bs), 4) self.assertEqual(bs[0], int('00110000', 2)) self.assertEqual(bs[1], 5) self.assertEqual(bs[2], int('00010010', 2)) self.assertEqual(bs[3], int('00110100', 2)) bs = bytearray( Addressee(id_type=IdType.UID, id=0x1234567890123456, access_class=5)) self.assertEqual(len(bs), 10) self.assertEqual(bs[0], int('00100000', 2)) self.assertEqual(bs[1], 5) self.assertEqual(bs[2], int('00010010', 2)) self.assertEqual(bs[3], int('00110100', 2)) self.assertEqual(bs[4], int('01010110', 2)) self.assertEqual(bs[5], int('01111000', 2)) self.assertEqual(bs[6], int('10010000', 2)) self.assertEqual(bs[7], int('00010010', 2)) self.assertEqual(bs[8], int('00110100', 2)) self.assertEqual(bs[9], int('01010110', 2)) bs = bytearray( Addressee(id_type=IdType.NOID, access_class=5, nls_method=NlsMethod.AES_CBC_MAC_128)) self.assertEqual(len(bs), 2) self.assertEqual(bs[0], int('00010010', 2)) self.assertEqual(bs[1], 5) bs = bytearray(Addressee(id_type=IdType.NBID, id=CT.compress(100))) self.assertEqual(len(bs), 3) self.assertEqual(bs[0], int('00000000', 2)) self.assertEqual(bs[1], 0) self.assertEqual(bs[2], 0x39)
interface_configuration=Configuration( qos=QoS(resp_mod=ResponseMode.RESP_MODE_ANY), addressee=Addressee(access_class=2, id_type=IdType.UID, id=0xDEADBEEFCAFEBABE)))) output_serial_frame( "Read ID file, with QoS, broadcast", Command.create_with_read_file_action( file_id=0x00, offset=0, length=8, interface_type=InterfaceType.D7ASP, interface_configuration=Configuration( qos=QoS(resp_mod=ResponseMode.RESP_MODE_ANY), addressee=Addressee(id_type=IdType.NOID, access_class=0x01)))) output_serial_frame( "Dormant session, write file", Command.create_with_write_file_action( file_id=0x40, offset=0, data=[0], interface_type=InterfaceType.D7ASP, interface_configuration=Configuration( qos=QoS(resp_mod=ResponseMode.RESP_MODE_ANY), addressee=Addressee(id_type=IdType.UID, id=0xE0022600017B388F, access_class=0x21), dorm_to=CT.compress(60 * 5))))
if not config.not_exe: modem = Modem(config.device, config.rate, unsolicited_response_received_callback=received_command_callback, rebooted_callback=rebooted_callback) modem.connect() cmd = Command() if config.forward: cmd.add_forward_action( interface_type=InterfaceType.D7ASP, interface_configuration=Configuration( qos=QoS(resp_mod=ResponseMode.RESP_MODE_PREFERRED, retry_mod=RetryMode.RETRY_MODE_NO), addressee=Addressee( access_class=0x11, id_type=IdType.NBID, id=CT.compress(2) ) ) ) if (config.factory_gaussian != 0xFF) or (config.factory_paramp != 0xFF): if (config.factory_gaussian != 0xFF) or (config.factory_paramp != 0xFF): fact = FactorySettingsFile(gaussian=config.factory_gaussian, paramp=config.factory_paramp) elif config.factory_gaussian != 0xFF: fact = FactorySettingsFile(gaussian=config.factory_gaussian) else: fact = FactorySettingsFile(paramp=config.factory_paramp) cmd.add_action( RegularAction( operation=WriteFileData( operand=Data(
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), dorm_to=CT(), addressee=Addressee(access_class=0x11, id_type=IdType.NBID, id=CT.compress(3), nls_method=NlsMethod.NONE))) # the action cmd.add_action( RegularAction(operation=WriteFileData( operand=Data(offset=Offset(id=0x41, offset=Length(0)), data=list(query_sensor_file_cmd))))) # the interface config cmd.add_action( RegularAction(operation=WriteFileData( operand=Data(offset=Offset(id=0x42, offset=Length(0)), data=list(interface_config))))) # enable action on sensor file
def test_compress(self): self.assertEqual(1024, CT.compress(1024).decompress())
argparser.add_argument("-e", "--eirp", help="EIRP in dBm", type=int, default=14) argparser.add_argument("-s", "--specifier", help="specifier for access profile. Default 0 is continuous scan, 1 is bg scan, 2+ is no scan", type=int, default=0) argparser.add_argument("-sp", "--scan_automation_period", help="period in ms of scanning (786 ~ total 1 sec), 0 is continuous scan ", type=int, default=0) argparser.add_argument("-sb", "--subband_bitmap", help="subband bitmap of subprofiles, 0 is default, 1 is scanning", type=int, default=0) config = argparser.parse_args() configure_default_logger(config.verbose) ch = ChannelID.from_string(config.channel_id) modem = Modem(config.device, config.rate, unsolicited_response_received_callback=received_command_callback) modem.connect() channel_header = ChannelHeader( channel_class=ch.channel_header.channel_class, channel_coding=ch.channel_header.channel_coding, channel_band=ch.channel_header.channel_band ) access_profile = AccessProfile( channel_header=channel_header, sub_profiles=[SubProfile(subband_bitmap=config.subband_bitmap, scan_automation_period=CT.compress(config.scan_automation_period))] * 4, sub_bands=[SubBand(eirp=config.eirp, channel_index_start=ch.channel_index, channel_index_end=ch.channel_index)] * 8 ) modem.execute_command( alp_command=Command.create_with_write_file_action_system_file( file=AccessProfileFile(access_profile=access_profile, access_specifier=config.specifier) ) )