Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 4
0
 def test_byte_generation(self):
     p = FilePermissions(encrypted=True,
                         executeable=True,
                         user_readable=True,
                         user_writeable=True,
                         user_executeable=True,
                         guest_readable=True,
                         guest_writeable=False,
                         guest_executeable=False)
     bytes = bytearray(p)
     self.assertEqual(bytes, bytearray([0xFC]))
Esempio n. 5
0
    def test_parsing(self):
        permission_bytes = [0xFC]

        permission = FilePermissions.parse(
            ConstBitStream(bytes=permission_bytes))

        self.assertEqual(permission.encrypted, True)
        self.assertEqual(permission.executable, True)
        self.assertEqual(permission.user_readable, True)
        self.assertEqual(permission.user_writeable, True)
        self.assertEqual(permission.user_executeable, True)
        self.assertEqual(permission.guest_readable, True)
        self.assertEqual(permission.guest_writeable, False)
        self.assertEqual(permission.guest_executeable, False)
Esempio n. 6
0
# 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:
    if not resp.execution_completed:
        print("{} reconfigured to use D7AActP".format(
            resp.get_d7asp_interface_status().addressee.id))

print("Done")