def writeTXBufferData(self, data, offset=0): """Writes data to the device's transmit buffer at the offset address. Args: data: Data to write to the Pozyx buffer. Has to be a ByteStructure derived object. offset (optional): Offset in buffer to start writing data Returns: POZYX_SUCCESS, POZYX_FAILURE """ if not dataCheck(data): data = Data(data) if offset + data.byte_size > PozyxConstants.MAX_BUF_SIZE: return POZYX_FAILURE # have to account for the parameter taking up a byte _MAX_SERIAL_SIZE = PozyxConstants.MAX_SERIAL_SIZE - 1 status = POZYX_SUCCESS data = Data(data.transform_to_bytes()) runs = int(data.byte_size / _MAX_SERIAL_SIZE) for i in range(runs): status &= self.regFunction( PozyxRegisters.WRITE_TX_DATA, Data([offset + i * _MAX_SERIAL_SIZE] + data[i * _MAX_SERIAL_SIZE:(i + 1) * _MAX_SERIAL_SIZE]), Data([])) return status & self.regFunction( PozyxRegisters.WRITE_TX_DATA, Data([offset + runs * _MAX_SERIAL_SIZE] + data[runs * _MAX_SERIAL_SIZE:]), Data([]))
def sendTX(self, destination, operation): """Sends the data in the transmit buffer to destination ID. Helper for sendData. Args: destination: Network ID of destination. integer ID or NetworkID(ID) operation: Type of TX operation. These vary depending on the desired operation. Returns: POZYX_SUCCESS, POZYX_FAILURE """ if dataCheck(destination): destination = destination[0] return self.regFunction(PozyxRegisters.SEND_TX_DATA, TXInfo(destination, operation), Data([]))
def sendTXBufferData(self, destination): """ Sends the transmit buffer's data to the destination device. Args: destination: Network ID of destination. integer ID or NetworkID(ID) Returns: POZYX_SUCCESS, POZYX_FAILURE """ if dataCheck(destination): destination = destination[0] # see what I did there. params = Data([destination, 0x06], 'HB') status = self.regFunction(POZYX_TX_SEND, params, Data([])) return status
def remoteRegRead(self, destination, address, data): """ Performs regRead 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. data: Container for the read data. ByteStructure-derived object. Returns: POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT """ if dataCheck(destination): destination = destination[0] if is_reg_readable(address) == 0: return POZYX_FAILURE if len(data) > MAX_BUF_SIZE: return POZYX_FAILURE if destination == 0: return POZYX_FAILURE send_data = Data([0, address, data.byte_size]) status = self.regFunction(POZYX_TX_DATA, send_data, Data([])) if status == POZYX_FAILURE: return status self.regRead(POZYX_INT_STATUS, SingleRegister()) params = Data([destination, 0x02], 'HB') status = self.regFunction(POZYX_TX_SEND, 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: status = self.readRXBufferData(data) return status else: return POZYX_FAILURE return status
def remoteRegRead(self, destination, address, data): """Performs regRead 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. data: Container for the read data. ByteStructure-derived object. Returns: POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT """ if dataCheck(destination): destination = destination[0] if len(data) > PozyxConstants.MAX_BUF_SIZE: return POZYX_FAILURE if destination == 0: return POZYX_FAILURE send_data = Data([0, address, data.byte_size]) status = self.regFunction(PozyxRegisters.WRITE_TX_DATA, send_data, Data([])) if status != POZYX_SUCCESS: return status self.getInterruptStatus(SingleRegister()) status = self.sendTXRead(destination) if status != POZYX_SUCCESS: return status status = self.checkForFlag(PozyxBitmasks.INT_STATUS_FUNC, 1) if status == POZYX_SUCCESS: rx_info = RXInfo() self.getRxInfo(rx_info) if rx_info.remote_id == destination and rx_info.amount_of_bytes == data.byte_size: status = self.readRXBufferData(data) return status else: return POZYX_FAILURE return status
def sendTX(self, destination, operation): if dataCheck(destination): destination = destination[0] return self.regFunction(PozyxRegisters.POZYX_TX_SEND, TXInfo(destination, operation), Data([]))