Esempio n. 1
0
    def __event_handler(self, event):
        # self.logger.info("Got " + str(event._opcode))

        if self._event_filter_enabled and event._opcode in self._event_filter:
            # Ignore event
            return
        if event._opcode == evt.Event.DEVICE_STARTED:
            self.logger.info("Device rebooted.")

        elif event._opcode == evt.Event.CMD_RSP:
            if event._data["status"] != 0:
                self.logger.error("{}: {}".format(
                    cmd.response_deserialize(event),
                    STATUS_CODE_LUT[event._data["status"]]["code"]))
            else:
                text = str(cmd.response_deserialize(event))
                if text == "None":
                    text = "Success"
                self.logger.info(text)

        else:
            if self.PRINT_ALL_EVENTS and event is not None:
                self.logger.info(str(event))
            else:
                self._other_events.append(event)
Esempio n. 2
0
    def cmdRsp_handler(self, event):

        if event._opcode != evt.Event.CMD_RSP:
            return

        if event._data["status"] != 0:
            return

        rsp_packet = cmd.response_deserialize(event)

        if rsp_packet is None or isinstance(rsp_packet, str):
            return

        if rsp_packet._command_name in [
                "AddrSubscriptionAdd", "AddrSubscriptionAddVirtual",
                "AddrPublicationAddVirtual", "AddrPublicationAdd"
        ]:
            self.addrAdd(rsp_packet)

        if rsp_packet._command_name in ["DevkeyAdd"]:
            self.devkeyAdd(rsp_packet)

        if rsp_packet._command_name in ["AddrPublicationRemove"]:
            self.addrRemove(rsp_packet)

        if rsp_packet._command_name in ["DevkeyDelete"]:
            self.devKeyDelete(rsp_packet)
Esempio n. 3
0
    def _event_handler_thread(self, event):
        if event._opcode == evt.Event.PROV_COMPLETE:
            print('Node provisioned with address:',
                  hex(event._data["address"]))

            address_handle = self.address_queue.get()
            devkey_handle = self.devkey_queue.get()

            unicast_address = event._data["address"]

            print('Got handle for node:', unicast_address, 'devkey_handle:',
                  devkey_handle, 'address_handle:', address_handle)

            self.cc.publish_set(devkey_handle, address_handle)
            self.cc.appkey_add(0)

            time.sleep(1)

            self.cc.composition_data_get()

            # wait for composition data
            self.composition_data_event.wait()
            self.composition_data_event.clear()
            print("Received composition data.")

            # bind appkey 0 to all models
            node = self._find_node(unicast_address)
            for element in node.elements:
                for model in element.models:
                    if model.model_id.model_id >= 0x1000:
                        time.sleep(0.1)
                        self.cc.model_app_bind(unicast_address + element.index,
                                               0, model.model_id)

            time.sleep(0.5)

            self.db.store()

            self._free_handles(devkey_handle, address_handle)

            self.provision_complete_event.set()

        if event._opcode == evt.Event.CMD_RSP:
            result = cmd.response_deserialize(event)
            if type(result) is cmd.AddrPublicationAddRsp:
                self.address_queue.put(result._data["address_handle"])
            if type(result) is cmd.DevkeyAddRsp:
                self.devkey_queue.put(result._data["devkey_handle"])

        if event._opcode == evt.Event.MESH_MESSAGE_RECEIVED_UNICAST:
            opcode = access.opcode_from_message_get(event._data["data"])

            if (self.cc._COMPOSITION_DATA_STATUS.serialize() == opcode):
                self.composition_data_event.set()