示例#1
0
  def test_create_with_write_file_header(self):
    file_header = FileHeader(
      permissions=FilePermissions(
        executeable=True,
        encrypted=False,
        user_readable=True,
        user_writeable=True,
        user_executeable=False,
        guest_readable=True,
        guest_executeable=False,
        guest_writeable=False
      ),
      properties=FileProperties(act_enabled=False, act_condition=ActionCondition.WRITE, storage_class=StorageClass.PERMANENT),
      alp_command_file_id=0x41,
      interface_file_id=0x42,
      file_size=1,
      allocated_size=1
    )

    c = Command.create_with_write_file_header(file_id=0x40, file_header=file_header)
    self.assertEqual(len(c.actions), 1)
    self.assertEqual(type(c.actions[0]), RegularAction)
    self.assertEqual(type(c.actions[0].operation), WriteFileHeader)
    self.assertEqual(type(c.actions[0].operand), FileHeaderOperand)
    self.assertEqual(c.actions[0].operand.file_id, 0x40)
    self.assertEqual(c.actions[0].operand.file_header, file_header)
示例#2
0
    def test_byte_generation(self):
        file_header = FileHeader(permissions=FilePermissions(
            encrypted=True,
            executeable=True,
            user_readable=True,
            user_writeable=True,
            user_executeable=True,
            guest_readable=True,
            guest_writeable=False,
            guest_executeable=False),
                                 properties=FileProperties(
                                     act_enabled=True,
                                     act_condition=ActionCondition.WRITE_FLUSH,
                                     storage_class=StorageClass.PERMANENT),
                                 alp_command_file_id=0x41,
                                 interface_file_id=0x42,
                                 file_size=20,
                                 allocated_size=40)

        bytes = bytearray(file_header)
        self.assertEqual(bytes[0], 0xFC)
        self.assertEqual(bytes[1], 0xB3)
        self.assertEqual(bytes[2], 0x41)
        self.assertEqual(bytes[3], 0x42)
        self.assertEqual(struct.unpack(">I", bytes[4:8])[0], 20)
        self.assertEqual(struct.unpack(">I", bytes[8:12])[0], 40)
示例#3
0
 def parse(s):
   permissions = FilePermissions.parse(s)
   properties = FileProperties.parse(s)
   alp_command_file_id = s.read("uint:8")
   interface_file_id = s.read("uint:8")
   file_size = s.read("uint:32")
   allocated_size = s.read("uint:32")
   return FileHeader(permissions, properties, alp_command_file_id, interface_file_id, file_size, allocated_size)
示例#4
0
    def test_parsing(self):
        properties_bytes = [0xB3]

        prop = FileProperties.parse(ConstBitStream(bytes=properties_bytes))

        self.assertEqual(prop.act_enabled, True)
        self.assertEqual(prop.act_condition, ActionCondition.WRITE_FLUSH)
        self.assertEqual(prop.storage_class, StorageClass.PERMANENT)
示例#5
0
 def test_byte_generation(self):
   prop = FileProperties(act_enabled=True, act_condition=ActionCondition.WRITE, storage_class=StorageClass.VOLATILE)
   bytes = bytearray(prop)
   self.assertEqual(bytes, bytearray([0xA1]))
示例#6
0
# 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,
                         allocated_size=2,
                         permissions=FilePermissions())

cmd.add_action(
    RegularAction(operation=WriteFileHeader(
        operand=FileHeaderOperand(file_id=0x40, file_header=file_header))))

print("Executing ...")
responses = modem.execute_command(alp_command=cmd, timeout_seconds=30)

for resp in responses: