Ejemplo n.º 1
0
 def test_create_with_write_file_action(self):
   data = [0, 1, 2, 3, 4, 5]
   c = Command.create_with_write_file_action(file_id=1, data=data)
   self.assertEqual(len(c.actions), 1)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), WriteFileData)
   self.assertEqual(type(c.actions[0].operand), Data)
   self.assertEqual(c.actions[0].operand.offset.id, 1)
   self.assertEqual(c.actions[0].operand.offset.offset.value, 0)
   self.assertEqual(c.actions[0].operand.length.value, 6)
   self.assertEqual(c.actions[0].operand.data, data)
Ejemplo n.º 2
0
 def test_create_with_write_file_action(self):
   data = [0, 1, 2, 3, 4, 5]
   c = Command.create_with_write_file_action(file_id=1, data=data)
   self.assertEqual(len(c.actions), 1)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), WriteFileData)
   self.assertEqual(type(c.actions[0].operand), Data)
   self.assertEqual(c.actions[0].operand.offset.id, 1)
   self.assertEqual(c.actions[0].operand.offset.size, 1)
   self.assertEqual(c.actions[0].operand.offset.offset, 0)
   self.assertEqual(c.actions[0].operand.length, 6)
   self.assertEqual(c.actions[0].operand.data, data)
Ejemplo n.º 3
0
 def test_create_with_write_file_action_d7asp(self):
   data = [0, 1, 2, 3, 4, 5]
   c = Command.create_with_write_file_action(file_id=1, data=data, interface_type=InterfaceType.D7ASP)
   self.assertEqual(len(c.actions), 2)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), Forward)
   self.assertEqual(type(c.actions[0].operand), InterfaceConfiguration)
   self.assertEqual(c.actions[0].operand.interface_id.value, 0xD7)
   self.assertEqual(type(c.actions[0].operand.interface_configuration), Configuration)
   # TODO configuration properties
   self.assertEqual(type(c.actions[1].operation), WriteFileData)
   self.assertEqual(type(c.actions[1].operand), Data)
   self.assertEqual(c.actions[1].operand.offset.id, 1)
   self.assertEqual(c.actions[1].operand.offset.offset.value, 0)
   self.assertEqual(c.actions[1].operand.length.value, 6)
   self.assertEqual(c.actions[1].operand.data, data)
Ejemplo n.º 4
0
 def test_create_with_write_file_action_d7asp(self):
   data = [0, 1, 2, 3, 4, 5]
   c = Command.create_with_write_file_action(file_id=1, data=data, interface_type=InterfaceType.D7ASP)
   self.assertEqual(len(c.actions), 2)
   self.assertEqual(type(c.actions[0]), RegularAction)
   self.assertEqual(type(c.actions[0].operation), Forward)
   self.assertEqual(type(c.actions[0].operand), InterfaceConfiguration)
   self.assertEqual(c.actions[0].operand.interface_id, 0xD7)
   self.assertEqual(type(c.actions[0].operand.interface_configuration), Configuration)
   # TODO configuration properties
   self.assertEqual(type(c.actions[1].operation), WriteFileData)
   self.assertEqual(type(c.actions[1].operand), Data)
   self.assertEqual(c.actions[1].operand.offset.id, 1)
   self.assertEqual(c.actions[1].operand.offset.size, 1)
   self.assertEqual(c.actions[1].operand.offset.offset, 0)
   self.assertEqual(c.actions[1].operand.length, 6)
   self.assertEqual(c.actions[1].operand.data, data)
Ejemplo n.º 5
0
                                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],
#             app_eui=[0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01],
#             app_key=[0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]
#         )
#     )
# )

modem.execute_command(alp_command=Command.create_with_write_file_action(
    file_id=config.file_id,
    data=list(interface_file),
))

try:
    while True:
        pass
except KeyboardInterrupt:
    sys.exit(0)
Ejemplo n.º 6
0
print("Using mode {} for channel {} with TX EIRP {} dBm".format(
    config.mode, config.channel_id, config.eirp))
mode = EngineeringModeMode.from_string(config.mode)

emFile = EngineeringModeFile(mode=mode,
                             flags=0,
                             timeout=config.timeout,
                             channel_id=ch,
                             eirp=config.eirp)

print(list(emFile))

if not config.not_exe:
    modem = Modem(
        config.device,
        config.rate,
        unsolicited_response_received_callback=received_command_callback,
        rebooted_callback=rebooted_callback)
    modem.connect()

    modem.execute_command(alp_command=Command.create_with_write_file_action(
        file_id=5,
        data=list(emFile),
    ))

    try:
        while True:
            pass
    except KeyboardInterrupt:
        sys.exit(0)
Ejemplo n.º 7
0
    def on_mqtt_message(self, client, config, msg):
        try:
            payload = json.loads(msg.payload)
            uid = payload['device']
            method = payload['data']['method']
            request_id = payload['data']['id']
            self.log.info(
                "Received RPC command of type {} for {} (request id {})".
                format(method, uid, request_id))
            # if uid != self.modem.uid:
            #   self.log.info("RPC command not for this modem ({}), skipping".format(self.modem.uid))
            #   return

            if method == "execute-alp-async":
                try:
                    cmd = payload['data']['params']
                    self.log.info("Received command through RPC: %s" % cmd)

                    self.modem.execute_command_async(cmd)
                    self.log.info("Executed ALP command through RPC")

                    # TODO when the command is writing local files we could read them again automatically afterwards, to make sure the digital twin is updated
                except Exception as e:
                    self.log.exception("Could not deserialize: %s" % e)
            elif method == "alert":
                # TODO needs refactoring so different methods can be supported in a plugin, for now this is very specific case as an example
                self.log.info("Alert (payload={})".format(msg.payload))
                if msg.payload != "true" and msg.payload != "false":
                    self.log.info("invalid payload, skipping")
                    return

                file_data = 0
                if msg.payload == "true":
                    file_data = 1

                self.log.info("writing alert file")
                self.modem.execute_command_async(
                    Command.create_with_write_file_action(
                        file_id=0x60,
                        offset=4,
                        data=[file_data],
                        interface_type=InterfaceType.D7ASP,
                        interface_configuration=Configuration(
                            qos=QoS(resp_mod=ResponseMode.RESP_MODE_ALL),
                            addressee=Addressee(access_class=0x11,
                                                id_type=IdType.NOID))))

            else:
                self.log.info("RPC method not supported, skipping")
                return
        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            trace = "".join(lines)
            msg_info = "no msg info (missing __dict__ attribute)"  # TODO because of out of date paho??
            if hasattr(msg, '__dict__'):
                msg_info = str(msg.__dict__)

            self.log.error(
                "Exception while processing MQTT message: {} callstack:\n{}".
                format(msg_info, trace))
Ejemplo n.º 8
0
    paramp=config.paramp,
    gaussian=config.gaussian)

print(fsFile.__str__())

print('[{}]'.format(', '.join(hex(byte) for byte in list(fsFile))))

interface_type = InterfaceType.HOST
interface_configuration = None

if config.forward:
    interface_type = InterfaceType.D7ASP
    interface_configuration = Configuration(
        qos=QoS(resp_mod=ResponseMode.RESP_MODE_PREFERRED,
                retry_mod=RetryMode.RETRY_MODE_NO),
        addressee=Addressee(access_class=0x11,
                            id_type=IdType.NBID,
                            id=CT.compress(2)))

modem.execute_command(alp_command=Command.create_with_write_file_action(
    file_id=1,
    data=list(fsFile),
    interface_type=interface_type,
    interface_configuration=interface_configuration))

# try:
#     while True:
#         pass
# except KeyboardInterrupt:
#     sys.exit(0)
Ejemplo n.º 9
0
                       default=False,
                       action="store_true")
argparser.add_argument("-f", "--file", help="file for OTA", required=True)
config = argparser.parse_args()
configure_default_logger(config.verbose, logging_level=logging.WARNING)

modem = Modem(config.device,
              config.rate,
              unsolicited_response_received_callback=received_command_callback,
              rebooted_callback=rebooted_callback)
modem.connect()

data = [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