def test_parse(self): bytes = list(bytearray(self.valid_channel_header)) for _ in xrange(AccessProfile.NUMBER_OF_SUB_PROFILES): bytes.extend(list(bytearray(SubProfile()))) for _ in range(AccessProfile.MAX_NUMBER_OF_SUB_BANDS): bytes.extend(list(bytearray(SubBand()))) ap = AccessProfile.parse(ConstBitStream(bytes=bytes)) self.assertEqual(ap.channel_header.channel_band, self.valid_channel_header.channel_band) self.assertEqual(ap.channel_header.channel_coding, self.valid_channel_header.channel_coding) self.assertEqual(ap.channel_header.channel_class, self.valid_channel_header.channel_class) self.assertEqual(len(ap.sub_bands), AccessProfile.MAX_NUMBER_OF_SUB_BANDS) for sb in ap.sub_bands: self.assertEqual(sb.channel_index_start, SubBand().channel_index_start) self.assertEqual(sb.channel_index_end, SubBand().channel_index_end) self.assertEqual(sb.cca, SubBand().cca) self.assertEqual(sb.duty, SubBand().duty) self.assertEqual(sb.eirp, SubBand().eirp) for sp in ap.sub_profiles: self.assertEqual(sp.subband_bitmap, SubProfile().subband_bitmap) self.assertEqual(sp.scan_automation_period.exp, SubProfile().scan_automation_period.exp) self.assertEqual(sp.scan_automation_period.mant, SubProfile().scan_automation_period.mant) self.assertEqual(len(ap.sub_profiles), AccessProfile.NUMBER_OF_SUB_PROFILES)
def __init__(self): self.argparser = argparse.ArgumentParser( fromfile_prefix_chars="@", description="Test throughput over 2 serial D7 modems" ) self.argparser.add_argument("-n", "--msg-count", help="number of messages to transmit", type=int, default=10) self.argparser.add_argument("-p", "--payload-size", help="number of bytes of (appl level) payload to transmit", type=int, default=50) self.argparser.add_argument("-sw", "--serial-transmitter", help="serial device /dev file transmitter node", default=None) self.argparser.add_argument("-sr", "--serial-receiver", help="serial device /dev file receiver node", default=None) self.argparser.add_argument("-r", "--rate", help="baudrate for serial device", type=int, default=115200) self.argparser.add_argument("-uid", "--unicast-uid", help="UID to use for unicast transmission, " "when not using receiver " "(in hexstring, for example 0xb57000009151d)", default=None) self.argparser.add_argument("-to", "--receiver-timeout", help="timeout for the receiver (in seconds)", type=int, default=10) self.argparser.add_argument("-v", "--verbose", help="verbose", default=False, action="store_true") self.config = self.argparser.parse_args() configure_default_logger(self.config.verbose) if self.config.serial_transmitter == None and self.config.serial_receiver == None: self.argparser.error("At least a transmitter or receiver is required.") if self.config.serial_receiver == None and self.config.unicast_uid == None: self.argparser.error("When running without receiver a --unicast-uid parameter is required.") if self.config.serial_transmitter == None: self.transmitter_modem = None print("Running without transmitter") else: self.transmitter_modem = Modem(self.config.serial_transmitter, self.config.rate, None) access_profile = AccessProfile( channel_header=ChannelHeader(channel_band=ChannelBand.BAND_868, channel_coding=ChannelCoding.PN9, channel_class=ChannelClass.NORMAL_RATE), sub_profiles=[SubProfile(subband_bitmap=0x01, scan_automation_period=CT(exp=0, mant=0)), SubProfile(), SubProfile(), SubProfile()], sub_bands=[SubBand( channel_index_start=0, channel_index_end=0, eirp=10, cca=86 # TODO )] ) print("Write Access Profile") write_ap_cmd = Command.create_with_write_file_action_system_file(file=AccessProfileFile(access_profile=access_profile, access_specifier=0)) self.transmitter_modem.execute_command(write_ap_cmd, timeout_seconds=1) if self.config.serial_receiver == None: self.receiver_modem = None print("Running without receiver") else: self.receiver_modem = Modem(self.config.serial_receiver, self.config.rate, self.receiver_cmd_callback) self.receiver_modem.execute_command(Command.create_with_write_file_action_system_file(DllConfigFile(active_access_class=0x01)), timeout_seconds=1) print("Receiver scanning on Access Class = 0x01")
def test_parse(self): bytes = [ 0b10000001, # AP control: FG scan, UNC, 1 subband 5, # subnet 0, # scan automation period 0, # RFU ] + list(bytearray(self.valid_subband)) ap = AccessProfile.parse(ConstBitStream(bytes=bytes)) self.assertEqual(ap.scan_type_is_foreground, True) self.assertEqual(ap.csma_ca_mode, CsmaCaMode.UNC) self.assertEqual(ap.subnet, 5) self.assertEqual(ap.scan_automation_period.mant, CT(0).mant) self.assertEqual(ap.scan_automation_period.exp, CT(0).exp) self.assertEqual(len(ap.subbands), 1)
def test_byte_generation(self): expected = [ 0b00101000, # channel header ] for _ in xrange(AccessProfile.NUMBER_OF_SUB_PROFILES): expected.extend(list(bytearray(SubProfile()))) expected.extend(list(bytearray(SubBand()))) # only one sub_band ap = AccessProfile(channel_header=self.valid_channel_header, sub_bands=[SubBand()], sub_profiles=self.valid_sub_profiles) bytes = bytearray(ap) for i in xrange(len(bytes)): self.assertEqual(expected[i], bytes[i]) self.assertEqual(len(expected), len(bytes))
def parse(s): return AccessProfileFile( access_specifier=0, access_profile=AccessProfile.parse(s)) # TODO access_specifier?
def parse(s): return AccessProfileFile(access_specifier=0, access_profile=AccessProfile.parse(s)) # TODO access_specifier?
def bad(): sub_bands = [SubBand() for _ in range(10)] # too many ... ap = AccessProfile(channel_header=self.valid_channel_header, sub_profiles=self.valid_sub_profiles, sub_bands=sub_bands)
def bad(): ap = AccessProfile(channel_header=self.valid_channel_header, sub_profiles=self.valid_sub_profiles, sub_bands=[None])
def test_validation_ok(self): ap = AccessProfile(channel_header=self.valid_channel_header, sub_profiles=self.valid_sub_profiles, sub_bands=self.valid_sub_bands)
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) ) )