예제 #1
0
  def test_byte_generation(self):
    expected = [
      0,                                              # channel_header
      16, 0,                                           # channel_id
      70,                                              # rxlevel (- dBm)
      80,                                              # link budget
      80,                                              # target rx level
      0,                                              # status
      100,                                              # fifo token
      0,                                              # seq
      20,                                              # response timeout
      16                                              # addressee ctrl (BCAST)
    ]
    bytes = bytearray(Status(
      channel_header=0, channel_index=16, rx_level=70, link_budget=80, target_rx_level=80,
      nls=False, missed=False, retry=False, unicast=False, fifo_token=100,
      seq_nr=0, response_to=CT(0, 20), addressee=Addressee()
    ))
    self.assertEqual(len(bytes), 11)
    for i in xrange(10):
      self.assertEqual(expected[i], bytes[i])

    bytes = bytearray(Status(
      channel_header=0, channel_index=16, rx_level=70, link_budget=80, target_rx_level=80,
      unicast=False, fifo_token=100, seq_nr=0, response_to=CT(0, 20), addressee=Addressee(),
      nls=True, missed=True, retry=True))

    expected[6] = int('11100000', 2) # nls, missed, retry, ucast
    self.assertEqual(len(bytes), 11)
    for i in xrange(10):
      self.assertEqual(expected[i], bytes[i])
예제 #2
0
    def parse(bitstream, payload_length):
        control = Control.parse(bitstream)
        payload_length = payload_length - 1  # subtract control byte

        dialog_id = bitstream.read("uint:8")
        payload_length = payload_length - 1

        transaction_id = bitstream.read("uint:8")
        payload_length = payload_length - 1

        target_rx_level_i = None
        if control.has_agc:
            target_rx_level_i = bitstream.read("uint:8")
            payload_length -= 1

        tl = None
        if control.has_tl:
            tl = CT.parse(bitstream)
            payload_length -= 1

        te = None
        if control.has_te:
            te = CT.parse(bitstream)
            payload_length -= 1

        tc = None
        # TODO currently we have no way to know if Tc is present or not
        # Tc is present when control.is_ack_requested AND when we are requester,
        # while responders copy this flag but do NOT provide a Tc.
        # When parsing single frames without knowledge of dialogs we cannot determine this.
        # We use control.is_dialog_start for now but this will break when we start supporting multiple transactions per dialog
        if control.is_ack_requested and control.is_dialog_start:
            tc = CT.parse(bitstream)
            payload_length -= 1

        ack_template = None
        if control.is_ack_not_void:
            transaction_id_start = bitstream.read("uint:8")
            payload_length = payload_length - 1
            transaction_id_stop = bitstream.read("uint:8")
            payload_length = payload_length - 1
            assert transaction_id_start == transaction_id, "Other case not implemented yet"
            assert transaction_id_stop == transaction_id, "Other case not implemented yet"
            # TODO ack bitmap (for when transaction_id_start != transaction_id)
            ack_template = [transaction_id_start, transaction_id_stop]

        assert control.is_ack_record_requested == False, "Not implemented yet"
        assert control.is_ack_not_void == False, "Not implemented yet"

        alp_command = AlpParser().parse(bitstream, payload_length)

        return Frame(control=control,
                     dialog_id=dialog_id,
                     transaction_id=transaction_id,
                     agc_rx_level_i=target_rx_level_i,
                     tl=tl,
                     te=te,
                     tc=tc,
                     ack_template=ack_template,
                     alp_command=alp_command)
    def test_parse(self):
        bytes = [
            0b10000001,  # subband bitmap
            0,  # scan automation period
        ]

        sp = SubProfile.parse(ConstBitStream(bytes=bytes))
        self.assertEqual(sp.subband_bitmap, 0b10000001)
        self.assertEqual(sp.scan_automation_period.mant, CT(0).mant)
        self.assertEqual(sp.scan_automation_period.exp, CT(0).exp)
예제 #4
0
  def test_read_id_command_frame(self):
    read_id_command = [
      0x15, # length
      0x00, # subnet
      0x6a, # DLL control
      0x20, # D7ANP control
      0x01,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, # Origin Access ID
      0xa8, # D7ATP control
      0xe9, # dialog ID
      0x00, # transaction ID
      0x05, # Tl
      0x05, # Tc
      0x01, # ALP control (read file data operation)
      0x00, 0x00, 0x08, # file data request operand (file ID 0x00)
      0x25, 0xDA # CRC
    ]

    (frames, info) = self.parser.parse(read_id_command)
    self.assertEqual(len(frames), 1)
    frame = frames[0]
    self.assertEqual(frame.length, 21)
    self.assertEqual(frame.subnet, 0)
    self.assertEqual(frame.control.id_type, IdType.NOID)
    self.assertEqual(frame.control.eirp_index, 42)
    self.assertEqual(len(frame.target_address), 0)
    self.assertEqual(frame.d7anp_frame.control.nls_method, NlsMethod.NONE)
    self.assertFalse(frame.d7anp_frame.control.has_hopping)
    self.assertFalse(frame.d7anp_frame.control.has_no_origin_access_id)
    self.assertEqual(frame.d7anp_frame.control.origin_id_type, IdType.UID)
    self.assertEqual(frame.d7anp_frame.origin_access_class, 0x01)
    self.assertEqual(frame.d7anp_frame.origin_access_id, [0, 0, 0, 0, 0, 0, 0, 1])
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.is_dialog_start)
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.has_tl)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.has_te)
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.is_ack_requested)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.is_ack_not_void)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.is_ack_record_requested)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.has_agc)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.dialog_id, 0xe9)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.transaction_id, 0)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tl.exp, CT(exp=0, mant=5).exp)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tl.mant, CT(exp=0, mant=5).mant)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tc.exp, CT(exp=0, mant=5).exp)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tc.mant, CT(exp=0, mant=5).mant)
    self.assertEqual(len(frame.d7anp_frame.d7atp_frame.alp_command.actions), 1)
    alp_action = frame.d7anp_frame.d7atp_frame.alp_command.actions[0]
    self.assertEqual(type(alp_action.operation), ReadFileData)
    self.assertEqual(type(alp_action.operand), DataRequest)
    self.assertEqual(alp_action.operand.offset.id, 0)
    self.assertEqual(alp_action.operand.offset.offset.value, 0)
    self.assertEqual(alp_action.operand.length, 8)
    # TODO self.assertEqual(len(frame.payload), 16)
    hexstring = binascii.hexlify(bytearray(read_id_command[:-2])).decode('hex') # TODO there must be an easier way...
    self.assertEqual(frame.crc16, CRCCCITT(version='FFFF').calculate(hexstring))
예제 #5
0
  def test_read_id_response_frame(self):
    frame_data = [ 0x25,  # length
                   0x00,  # subnet
                   0x80,  # dll control
                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, # target_address
                   0x20,  # D7ANP control
                   0x01, # origin access class
                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, # origin access ID
                   0xa8,  # D7ATP control
                   0xe9,  # dialog ID
                   0x00,  # transaction ID
                   0x05,  # Tl
                   0x05,  # Tc
                   0x20,  # ALP control (return file data operation)
                   0x00, 0x00, 0x08, # file data operand
                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, # UID
                   ]

    frame_data = frame_data + calculate_crc(frame_data)

    (frames, info) = self.parser.parse(frame_data)
    self.assertEqual(len(frames), 1)
    frame = frames[0]
    self.assertEqual(frame.length, 37)
    self.assertEqual(frame.subnet, 0)
    self.assertEqual(frame.control.id_type, IdType.UID)
    self.assertEqual(frame.control.eirp_index, 0)
    self.assertEqual(len(frame.target_address), 8)
    self.assertEqual(frame.target_address, [0, 0, 0, 0, 0, 0, 0, 1])
    self.assertEqual(frame.d7anp_frame.control.nls_method, NlsMethod.NONE)
    self.assertFalse(frame.d7anp_frame.control.has_hopping)
    self.assertFalse(frame.d7anp_frame.control.has_no_origin_access_id)
    self.assertEqual(frame.d7anp_frame.control.origin_id_type, IdType.UID)
    self.assertEqual(frame.d7anp_frame.origin_access_class, 0x01)
    self.assertEqual(frame.d7anp_frame.origin_access_id, [0, 0, 0, 0, 0, 0, 0, 2])
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.is_dialog_start)
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.has_tl)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.has_te)
    self.assertTrue(frame.d7anp_frame.d7atp_frame.control.is_ack_requested)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.is_ack_not_void)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.is_ack_record_requested)
    self.assertFalse(frame.d7anp_frame.d7atp_frame.control.has_agc)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.dialog_id, 0xe9)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.transaction_id, 0)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tl.exp, CT(exp=0, mant=5).exp)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tl.mant, CT(exp=0, mant=5).mant)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tc.exp, CT(exp=0, mant=5).exp)
    self.assertEqual(frame.d7anp_frame.d7atp_frame.tc.mant, CT(exp=0, mant=5).mant)
    self.assertEqual(len(frame.d7anp_frame.d7atp_frame.alp_command.actions), 1)
    alp_action = frame.d7anp_frame.d7atp_frame.alp_command.actions[0]
    self.assertEqual(type(alp_action.operation), ReturnFileData)
    self.assertEqual(type(alp_action.operand), Data)
    self.assertEqual(alp_action.operand.offset.id, 0)
    self.assertEqual(alp_action.operand.offset.offset.value, 0)
    self.assertEqual(alp_action.operand.length, 8)
예제 #6
0
    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)
예제 #7
0
def execute_command(data):
    logging.info("execute_command")
    logging.info(data)

    interface_configuration = None
    interface_type = InterfaceType(int(data["interface"]))
    if interface_type == InterfaceType.D7ASP:
        id_type = IdType[data["id_type"]]
        id = int(data["id"])
        if id_type == IdType.NOID:
            id = None
        if id_type == IdType.NBID:
            id = CT()  # TODO convert

        interface_configuration = Configuration(
            qos=QoS(resp_mod=ResponseMode[data["qos_response_mode"]]),
            addressee=Addressee(access_class=int(data["access_class"]),
                                id_type=id_type,
                                id=id))

    cmd = Command.create_with_read_file_action(
        interface_type=interface_type,
        interface_configuration=interface_configuration,
        file_id=int(data["file_id"]),
        offset=int(data["offset"]),
        length=int(data["length"]))

    logging.info("executing cmd: {}".format(cmd))
    modem.execute_command_async(cmd)
    return {
        'tag_id': cmd.tag_id,
        'interface': interface_type.name,
        'command_description': cmd.describe_actions()
    }
예제 #8
0
    def parse_alp_interface_status_d7asp(self, s):
        channel_header = ChannelHeader.parse(s)
        channel_index = struct.unpack(">h", s.read("bytes:2"))[0]
        rx_level = s.read("int:8")
        link_budget = s.read("uint:8")
        target_rx_level = s.read("uint:8")
        nls = s.read("bool")
        missed = s.read("bool")
        retry = s.read("bool")
        unicast = s.read("bool")
        _ = s.read("pad:4")
        fifo_token = s.read("uint:8")
        seq_nr = s.read("uint:8")
        response_to = CT.parse(s)
        addressee = Addressee.parse(s)

        status = Status(channel_header=channel_header,
                        channel_index=channel_index,
                        rx_level=rx_level,
                        link_budget=link_budget,
                        target_rx_level=target_rx_level,
                        nls=nls,
                        missed=missed,
                        retry=retry,
                        unicast=unicast,
                        fifo_token=fifo_token,
                        seq_nr=seq_nr,
                        response_to=response_to,
                        addressee=addressee)

        return InterfaceStatus(operand=InterfaceStatusOperand(
            interface_id=0xd7, interface_status=status))
    def test_configuration_bad_composed_objects(self):
        def bad(args, kwargs):
            Configuration(**kwargs)

        self.assertRaises(ValueError, bad, [], {"qos": CT()})
        self.assertRaises(ValueError, bad, [], {"dorm_to": QoS()})
        self.assertRaises(ValueError, bad, [], {"addressee": QoS()})
예제 #10
0
    def parse(s):
        channel_header = ChannelHeader.parse(s)
        channel_index = s.read("uint:16")
        rx_level = s.read("int:8")
        link_budget = s.read("uint:8")
        target_rx_level = s.read("uint:8")
        nls = s.read("bool")
        missed = s.read("bool")
        retry = s.read("bool")
        unicast = s.read("bool")
        _ = s.read("pad:4")
        fifo_token = s.read("uint:8")
        seq_nr = s.read("uint:8")
        response_to = CT.parse(s)
        addressee = Addressee.parse(s)

        return Status(channel_header=channel_header,
                      channel_index=channel_index,
                      rx_level=rx_level,
                      link_budget=link_budget,
                      target_rx_level=target_rx_level,
                      nls=nls,
                      missed=missed,
                      retry=retry,
                      unicast=unicast,
                      fifo_token=fifo_token,
                      seq_nr=seq_nr,
                      response_to=response_to,
                      addressee=addressee)
예제 #11
0
  def parse_alp_interface_status_d7asp(self, s):
    channel_header  = s.read("uint:8") # TODO parse
    channel_index   = struct.unpack(">h", s.read("bytes:2"))[0]
    rx_level        = s.read("int:8")
    link_budget     = s.read("uint:8")
    target_rx_level = s.read("uint:8")
    nls             = s.read("bool")
    missed          = s.read("bool")
    retry           = s.read("bool")
    unicast         = s.read("bool" )
    _               = s.read("pad:4")
    fifo_token      = s.read("uint:8")
    seq_nr          = s.read("uint:8")
    response_to     = CT.parse(s)
    addressee       = Addressee.parse(s)

    status = Status(channel_header=channel_header, channel_index=channel_index,
                    rx_level=rx_level, link_budget=link_budget,
                    target_rx_level=target_rx_level, nls=nls, missed=missed,
                    retry=retry, unicast=unicast, fifo_token=fifo_token,
                    seq_nr=seq_nr, response_to=response_to, addressee=addressee)

    return InterfaceStatus(
      operand=InterfaceStatusOperand(interface_id=0xd7, interface_status=status)
    )
예제 #12
0
  def parse(self, bitstream, payload_length):
    timeout = CT.parse(bitstream)
    payload_length = payload_length - 1 # substract timeout

    control = Control(
      has_network_layer_security=bitstream.read("bool"),
      has_multi_hop=bitstream.read("bool"),
      has_origin_access_id=bitstream.read("bool"),
      is_origin_access_id_vid=bitstream.read("bool"),
      origin_access_class=bitstream.read("uint:4")
    )
    payload_length = payload_length - 1 # substract control

    assert control.has_multi_hop == False, "Not implemented yet"
    assert control.has_network_layer_security == False, "Not implemented yet"

    if control.has_origin_access_id:
      if control.is_origin_access_id_vid:
        origin_access_id = map(ord, bitstream.read("bytes:2"))
        payload_length = payload_length - 2
      else:
        origin_access_id = map(ord, bitstream.read("bytes:8"))
        payload_length = payload_length - 8
    else:
      origin_access_id = []

    #payload=map(ord,bitstream.read("bytes:" + str(payload_length)))
    d7atp_frame = D7atpParser().parse(bitstream, payload_length)
    return Frame(timeout=timeout, control=control, origin_access_id=origin_access_id, d7atp_frame=d7atp_frame)
예제 #13
0
 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_header=0,
                                                  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
         0,  # channel header
         16,
         0,  # channel_id
         70,  # rxlevel (- dBm)
         80,  # link budget
         80,  # target rx level
         0,  # status
         200,  # fifo token
         0,  # seq
         20,  # response timeout
         16,  # addressee ctrl (BCAST)
         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])
예제 #14
0
 def test_ct_construction(self):
   for exp in [1, 7]:
     for mant in [1, 31]:
       try:
         t = CT(exp=exp, mant=mant)
       except ValueError:
         self.fail("CT constructor raised ExceptionType unexpectedly " +
                   "for exp={0}, mant={1}".format(exp, mant))
예제 #15
0
  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")
예제 #16
0
    def test_byte_generation(self):
        expected = [
            0b10000001,  # subband bitmap
            0,  # scan automation period
        ]

        sp = SubProfile(subband_bitmap=0b10000001,
                        scan_automation_period=CT(0))
        bytes = bytearray(sp)
        for i in xrange(len(bytes)):
            self.assertEqual(expected[i], bytes[i])

        self.assertEqual(len(expected), len(bytes))
예제 #17
0
    def parse(s):
        _ = s.read("pad:2")
        id_type = IdType(s.read("uint:2"))
        nls_method = NlsMethod(s.read("uint:4"))
        cl = s.read("uint:8")
        l = Addressee.length_for(id_type)
        id = s.read("uint:" + str(l * 8)) if l > 0 else None
        if id_type == IdType.NBID:
            id = CT(id)

        return Addressee(id_type=id_type,
                         access_class=cl,
                         id=id,
                         nls_method=nls_method)
예제 #18
0
파일: status.py 프로젝트: maximevince/pyd7a
 def test_get_short_channel_string(self):
     s = Status(channel_header=self.valid_channel_header,
                channel_index=16,
                rx_level=70,
                link_budget=80,
                target_rx_level=80,
                nls=False,
                missed=False,
                retry=False,
                unicast=False,
                fifo_token=100,
                seq_nr=0,
                response_to=CT(0, 20),
                addressee=Addressee())
     self.assertEqual(s.get_short_channel_string(), "433N016")
예제 #19
0
  def parse(s):
    scan_type_is_foreground = s.read("bool")
    csma_ca_mode = CsmaCaMode(s.read("uint:4"))
    nr_of_subbands = s.read("uint:3")
    subnet = s.read("int:8")
    scan_automation_period = CT.parse(s)
    s.read("uint:8") # RFU
    subbands = []
    for i in range(nr_of_subbands):
      subbands.append(Subband.parse(s))

    return AccessProfile(scan_type_is_foreground=scan_type_is_foreground,
                         csma_ca_mode=csma_ca_mode,
                         subnet=subnet,
                         scan_automation_period=scan_automation_period,
                         subbands=subbands)
예제 #20
0
 def test_id_length_of_nbid(self):
     addr = Addressee(id_type=IdType.NBID, id=CT(1))
     self.assertEqual(addr.id_length, 1)
예제 #21
0
 def bad(args, kwargs): CT(**kwargs)
 self.assertRaises(ValueError, bad, [], { "exp"  : -1 })
예제 #22
0
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,
#             device_eui=[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07],
예제 #23
0
 def parse(s):
     qos = QoS.parse(s)
     dorm_to = CT.parse(s)
     addressee = Addressee.parse(s)
     return Configuration(qos=qos, dorm_to=dorm_to, addressee=addressee)
예제 #24
0
 def __init__(self, qos=QoS(), dorm_to=CT(), addressee=Addressee()):
     self.qos = qos
     self.dorm_to = dorm_to
     self.addressee = addressee
     super(Configuration, self).__init__()
예제 #25
0
 def test_simple_received_return_file_data_command_with_tag_request(self):
     cmd = Command(
         tag_id=25,
         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 = [
         0xB4,  # tag request with send response bit set
         25,  # tag ID
         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])
예제 #26
0
        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))))
예제 #27
0
 def parse(s):
   qos = QoS.parse(s)
   dorm_to = CT.parse(s)
   addressee = Addressee.parse(s)
   return Configuration(qos=qos, dorm_to=dorm_to, addressee=addressee)
예제 #28
0
 def test_default_constructor_is_zero(self):
   t = CT()
   self.assertEqual(int(t), 0)
예제 #29
0
    def start(self):
        self.received_commands = defaultdict(list)
        payload = range(self.config.payload_size)

        if self.receiver_modem != None:
            addressee_id = int(self.receiver_modem.uid, 16)
        else:
            addressee_id = int(self.config.unicast_uid, 16)

        if self.transmitter_modem != None:

            print(
                "\n==> broadcast, with QoS, transmitter active access class = 0x01 ===="
            )
            self.transmitter_modem.send_command(
                Command.create_with_write_file_action_system_file(
                    DllConfigFile(active_access_class=0x01)))
            interface_configuration = Configuration(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_ANY),
                addressee=Addressee(
                    access_class=0x01,
                    id_type=IdType.NBID,
                    id=CT(exp=0, mant=1)  # we expect one responder
                ))

            self.start_transmitting(
                interface_configuration=interface_configuration,
                payload=payload)
            self.wait_for_receiver(payload)

            print(
                "\n==> broadcast, no QoS, transmitter active access class = 0x01 ===="
            )
            self.transmitter_modem.send_command(
                Command.create_with_write_file_action_system_file(
                    DllConfigFile(active_access_class=0x01)))
            interface_configuration = Configuration(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                addressee=Addressee(access_class=0x01, id_type=IdType.NOID))

            self.start_transmitting(
                interface_configuration=interface_configuration,
                payload=payload)
            self.wait_for_receiver(payload)

            print(
                "\n==> unicast, with QoS, transmitter active access class = 0x01"
            )
            interface_configuration = Configuration(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_ANY),
                addressee=Addressee(access_class=0x01,
                                    id_type=IdType.UID,
                                    id=addressee_id))

            self.start_transmitting(
                interface_configuration=interface_configuration,
                payload=payload)
            self.wait_for_receiver(payload)

            print(
                "\n==> unicast, no QoS, transmitter active access class = 0x01"
            )
            interface_configuration = Configuration(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                addressee=Addressee(access_class=0x01,
                                    id_type=IdType.UID,
                                    id=addressee_id))

            self.start_transmitting(
                interface_configuration=interface_configuration,
                payload=payload)
            self.wait_for_receiver(payload)
        else:
            # receive only
            self.receiver_modem.start_reading()
            self.wait_for_receiver(payload)
예제 #30
0
 def test_ct_conversion_to_int(self):
   self.assertEqual(int(CT(1,1)),   4)
   self.assertEqual(int(CT(2,2)),  32)
   self.assertEqual(int(CT(3,3)), 192)
예제 #31
0
 def test_byte_generation(self):
   self.assertEqual( bytearray(CT(1, 1))[0], int('00100001', 2))
   self.assertEqual( bytearray(CT(7,31))[0], int('11111111', 2))
예제 #32
0
 def bad():
     addr = Addressee(id_type=IdType.NOID, id=CT(0))
예제 #33
0
 def parse(s):
     subband_bitmap = s.read("uint:8")
     scan_automation_period = CT.parse(s)
     return SubProfile(subband_bitmap=subband_bitmap,
                       scan_automation_period=scan_automation_period)