--- config.py.orig 2019-01-23 15:55:57.907511700 -0800 +++ config.py 2019-01-27 21:11:46.740857400 -0800 @@ -32,7 +32,7 @@ from mesh.access import Model, Opcode, AccessStatus import mesh.types as mt - +from time import sleep def log2b(value): """Binary log2""" @@ -118,7 +118,7 @@ _VENDOR_MODEL_APP_LIST = Opcode(0x804E) # noqa: E501,E221 _VENDOR_MODEL_SUBSCRIPTION_LIST = Opcode(0x802C) # noqa: E501,E221 - def __init__(self, prov_db): + def __init__(self, prov_db, blocking = False): self.opcodes = [ (self._APPKEY_LIST , self.__appkey_list_handler), # noqa: E501,E203 (self._APPKEY_STATUS , self.__appkey_status_handler), # noqa: E501,E203 @@ -148,7 +148,8 @@ self.prov_db = prov_db self.previous_command = None # FIXME: Hack to retain the virtual label UUID until we get an ack. - self._tmp_address = None + self._tmp_address = None + self.blocking = blocking super(ConfigurationClient, self).__init__(self.opcodes) @staticmethod @@ -160,9 +161,20 @@ if single_cnt > 0: keys.append(mt.KeyIndex.unpack(packed_keys[3 * pairs_cnt:])[0]) return keys - + + def _timeout_if_enabled(self, timeout = 10): + self.timeout = timeout + self.blocked = self.blocking + while ((self.timeout != 0) and (self.blocked == True)): + self.logger.info("Sleeping %d", self.timeout) + sleep(1) + self.timeout = self.timeout - 1 + self.logger.info("blocked = %d, timeout = %d", self.blocked, self.timeout) + def composition_data_get(self, page_number=0x00): self.send(self._COMPOSITION_DATA_GET, bytearray([page_number])) + self._timeout_if_enabled() + def appkey_add(self, appkey_index=0): key = self.prov_db.find_appkey(appkey_index) @@ -175,6 +187,7 @@ message += key.key self.previous_command = "add" self.send(self._APPKEY_ADD, message) + self._timeout_if_enabled() def appkey_update(self, appkey_index=0): key = self.prov_db.find_appkey(appkey_index) @@ -187,6 +200,7 @@ message += key.key self.previous_command = "update" self.send(self._APPKEY_UPDATE, message) + self._timeout_if_enabled() def appkey_delete(self, appkey_index=0): key = self.prov_db.find_appkey(appkey_index) @@ -197,11 +211,13 @@ key24 = mt.KeyIndex.pack(netkey_index, appkey_index) self.previous_command = "delete" self.send(self._APPKEY_DELETE, key24) + self._timeout_if_enabled() def appkey_get(self, netkey_index=0): message = bytearray() message += mt.KeyIndex.pack(netkey_index) self.send(self._APPKEY_GET, message) + self._timeout_if_enabled() def netkey_add(self, netkey_index=0): key = self.prov_db.find_netkey(netkey_index) @@ -213,6 +229,7 @@ message += key.key self.previous_command = "add" self.send(self._NETKEY_ADD, message) + self._timeout_if_enabled() def netkey_update(self, netkey_index=0): key = self.prov_db.find_netkey(netkey_index) @@ -224,14 +241,17 @@ message += key.key self.previous_command = "update" self.send(self._NETKEY_UPDATE, message) + self._timeout_if_enabled() def netkey_delete(self, netkey_index=0): message = mt.KeyIndex.pack(netkey_index) self.previous_command = "delete" self.send(self._NETKEY_DELETE, message) + self._timeout_if_enabled() def netkey_get(self): self.send(self._NETKEY_GET) + self._timeout_if_enabled() def model_app_bind(self, element_address, appkey_index, model_id): message = bytearray() @@ -240,6 +260,7 @@ message += model_id.pack() self.previous_command = "bind" self.send(self._MODEL_APP_BIND, message) + self._timeout_if_enabled() def model_app_unbind(self, element_address, appkey_index, model_id): message = bytearray() @@ -248,6 +269,7 @@ message += model_id.pack() self.previous_command = "unbind" self.send(self._MODEL_APP_UNBIND, message) + self._timeout_if_enabled() def model_app_get(self, element_address, model_id): message = bytearray() @@ -257,6 +279,7 @@ self.send(self._VENDOR_MODEL_APP_GET, message) else: self.send(self._SIG_MODEL_APP_GET, message) + self._timeout_if_enabled() def model_publication_set(self, element_address, model_id, publish): @@ -273,12 +296,14 @@ self.send(self._MODEL_PUBLICATION_VIRTUAL_ADDRESS_SET, message) else: self.send(self._MODEL_PUBLICATION_SET, message) - + self._timeout_if_enabled() + def model_publication_get(self, element_address, model_id): message = bytearray() message += struct.pack(" 0: node.net_keys = ConfigurationClient._unpack_key_ind(message.data) @@ -680,6 +749,7 @@ message.meta["src"], node.net_keys) def __node_identity_status_handler(self, opcode, message): + self.blocked = False status, netkey_index, identity = struct.unpack("