def useFunction(self, function, params=None, data=None, remote_id=None): """Activates a Pozyx register function either locally or remotely. Args: address: The function address Kwargs: params: A ByteStructure - derived object that contains the parameters for the function. data: A ByteStructure - derived object that is the container of the read data. remote_id: Remote ID for remote read. Returns: POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT Example: >>> self.useFunction(PozyxRegisters.CLEAR_DEVICES) """ if not is_functioncall(function): if not self.suppress_warnings: warn("Register 0x%0.02x isn't a function register" % function, stacklevel=3) params = Data([]) if params is None else params data = Data([]) if data is None else data if remote_id is None: return self.regFunction(function, params, data) else: return self.remoteRegFunction(remote_id, function, params, data)
def remoteRegFunction(self, destination, address, params, data): """ Performs regFunction on a remote Pozyx device. Args: destination: Network ID of destination device. integer ID or NetworkID(ID). address: Register address to start the read operation from. params: Parameters for the register function. ByteStructure-derived object of uint8s. data: Container for the data returned by the register function. ByteStructure-derived object. Returns: POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT """ if is_functioncall(address) == 0: return POZYX_FAILURE send_data = Data([0, address] + params.data, 'BB' + params.data_format) status = self.regFunction(POZYX_TX_DATA, send_data, Data([])) if status == POZYX_FAILURE: return status self.regRead(POZYX_INT_STATUS, SingleRegister()) tx_params = Data([destination, 0x08], 'HB') status = self.regFunction(POZYX_TX_SEND, tx_params, Data([])) if status == POZYX_FAILURE: return status status = self.checkForFlag(POZYX_INT_STATUS_FUNC, 1) if status == POZYX_SUCCESS: rx_info = Data([0, 0], 'HB') self.regRead(POZYX_RX_NETWORK_ID, rx_info) if rx_info[0] == destination and rx_info[1] == data.byte_size + 1: return_data = Data([0] + data.data, 'B' + data.data_format) status = self.readRXBufferData(return_data) if status == POZYX_FAILURE: return status if len(return_data) > 1: data.load(return_data[1:]) return return_data[0] else: return POZYX_FAILURE return status