Пример #1
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])
Пример #2
0
    def test_byte_generation(self):
        bytes = bytearray(Data())
        self.assertEqual(len(bytes), 3)
        self.assertEqual(bytes[0], int('00000000', 2))  # offset
        self.assertEqual(bytes[1], int('00000000', 2))  # offset
        self.assertEqual(bytes[2], int('00000000', 2))

        bytes = bytearray(Data(data=[0x01, 0x02, 0x03, 0x04]))
        self.assertEqual(len(bytes), 7)
        self.assertEqual(bytes[0], int('00000000', 2))  # offset
        self.assertEqual(bytes[1], int('00000000', 2))  # offset
        self.assertEqual(bytes[2], int('00000100', 2))  # length = 4
        self.assertEqual(bytes[3], int('00000001', 2))
        self.assertEqual(bytes[4], int('00000010', 2))
        self.assertEqual(bytes[5], int('00000011', 2))
        self.assertEqual(bytes[6], int('00000100', 2))
Пример #3
0
    def create_with_return_file_data_action(file_id,
                                            data,
                                            interface_type=InterfaceType.HOST,
                                            interface_configuration=None):
        # default to host interface, when D7ASP interface is used prepend with Forward action
        cmd = Command()
        cmd.add_forward_action(interface_type, interface_configuration)
        cmd.add_action(
            RegularAction(operation=ReturnFileData(
                operand=Data(data=data, offset=Offset(id=file_id)))))

        return cmd
Пример #4
0
    def create_with_write_file_action_system_file(
            file,
            interface_type=InterfaceType.HOST,
            interface_configuration=None):
        # default to host interface, when D7ASP interface is used prepend with Forward action
        cmd = Command()
        cmd.add_forward_action(interface_type, interface_configuration)
        cmd.add_action(
            RegularAction(operation=WriteFileData(
                operand=Data(offset=Offset(id=file.id), data=list(file)))))

        return cmd
Пример #5
0
 def test_byte_generation(self):
     data = Data([0x01, 0x02, 0x03, 0x04])
     rfd = ReturnFileData(data)
     bytes = bytearray(rfd)
     self.assertEqual(len(bytes), 7)
     self.assertEqual(bytes[0], int('00000000', 2))  # offset
     self.assertEqual(bytes[1], int('00000000', 2))  # offset
     self.assertEqual(bytes[2], int('00000100', 2))  # length = 4
     self.assertEqual(bytes[3], int('00000001', 2))
     self.assertEqual(bytes[4], int('00000010', 2))
     self.assertEqual(bytes[5], int('00000011', 2))
     self.assertEqual(bytes[6], int('00000100', 2))
Пример #6
0
    def create_with_write_file_action(file_id,
                                      data,
                                      offset=0,
                                      interface_type=InterfaceType.HOST,
                                      interface_configuration=None):
        # default to host interface, when D7ASP interface is used prepend with Forward action
        cmd = Command()
        cmd.add_forward_action(interface_type, interface_configuration)
        cmd.add_action(
            RegularAction(operation=WriteFileData(operand=Data(
                offset=Offset(id=file_id, offset=offset),  # TODO offset size
                data=data))))

        return cmd
Пример #7
0
def cleanup(sig, frame):
  cmd = Command()
  emFile.mode = EngineeringModeMode.ENGINEERING_MODE_MODE_OFF
  cmd.add_action(
    RegularAction(
      operation=WriteFileData(
        operand=Data(
          offset=Offset(id=emFile.id),
          data=list(emFile)
        )
      )
    )
  )
  modem.execute_command(cmd)
  sys.exit(0)
Пример #8
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])
Пример #9
0
 def parse_alp_return_file_data_operand(self, s):
     offset = self.parse_offset(s)
     length = Length.parse(s)
     data = s.read("bytes:" + str(length.value))
     return Data(offset=offset, data=map(ord, data))
Пример #10
0
 def test_data_length(self):
     d = Data(data=[0xd7, 0x04, 0x00])
     self.assertEqual(d.length, 3)
     self.assertEqual(len(d), 3)
Пример #11
0
 def bad():
     Data(Data())
Пример #12
0
 def test_default_data_constructor(self):
     Data()
Пример #13
0
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
file_header = FileHeader(properties=FileProperties(
    act_enabled=True,
    act_condition=ActionCondition.WRITE,
    storage_class=StorageClass.TRANSIENT),
                         alp_command_file_id=0x41,
                         interface_file_id=0x42,
                         file_size=2,
Пример #14
0
 def parse_alp_return_file_data_operand(self, s):
     offset = self.parse_offset(s)
     length = s.read(
         "uint:8")  # TODO assuming 1 bute for now but can be 4 bytes
     data = s.read("bytes:" + str(length))
     return Data(offset=offset, data=map(ord, data))
Пример #15
0
print(data)

cmd = Command.create_with_write_file_action(file_id=199, data=data)
answ = modem.execute_command(cmd)
cmd = Command()

f = open(config.file, "rb")
total_length = os.path.getsize(config.file)

amount_of_bytes = 239
length = 0
try:
    bytes = list(bytearray(f.read(amount_of_bytes)))
    while len(bytes) != 0:
        cmd.add_action(
            RegularAction(operation=WriteFileData(operand=Data(
                offset=Offset(id=200, offset=Length(length)), data=bytes))))
        length += amount_of_bytes

        answ = modem.execute_command(cmd)
        worked = False
        for answer in answ:
            if answer.execution_completed and not answer.completed_with_error:
                worked = True
        if not worked:
            print("write failed")
            break
        cmd = Command()
        print(
            chr(27) + "[2J\n" + str(length) + "/" + str(total_length) + ": " +
            str(length * 100 / total_length) + "%")
Пример #16
0
 def test_constructor_and_op_code(self):
     data = Data([0x01, 0x02, 0x03, 0x04])
     rfd = ReturnFileData(data)
     self.assertEqual(rfd.op, 32)
     self.assertIs(rfd.operand, data)
     self.assertEqual(rfd.operand.length.value, 4)
Пример #17
0
        )
      )
    )

  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(
            offset=Offset(id=fact.id),
            data=list(fact)
          )
        )
      )
    )

  cmd.add_action(
    RegularAction(
      operation=WriteFileData(
        operand=Data(
          offset=Offset(id=emFile.id),
          data=list(emFile)
        )
      )
    )
  )
Пример #18
0
 def bad(): Data(Data())
 self.assertRaises(ValueError, bad)