- self._nova.setIOpinValue(0, 'LOW')
- for i in range(start, end):
- buf[start+i] = int(getSpiReceivedData(self._nova.transferSPI(0, 0x00)), 16)
- self._nova.setIOpinValue(0, 'HIGH')
-"""
- def write_readinto(self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None):
+ if int(self._novaCMDVer) >= 1:
+ chunks, rest = divmod(end - start, self.WHR_PAYLOAD_MAX_LENGTH)
+ i = 0
+ for i in range(chunks):
+ chunk_start = start + i * self.WHR_PAYLOAD_MAX_LENGTH
+ chunk_end = chunk_start + self.WHR_PAYLOAD_MAX_LENGTH
+ result = self._nova.writeToReadFromSPI(
+ 0, False, True, chunk_end - chunk_start, write_value
+ )
+ if result != "-NG":
+ resp = result.split(" ")
+ resp = resp[2]
+ # loop over half of resp len as we're reading 2 chars at a time to form a byte
+ loops = int(len(resp) / 2)
+ for j in range(loops):
+ buf[(i * self.WHR_PAYLOAD_MAX_LENGTH) + start + j] = int(
+ resp[j * 2] + resp[j * 2 + 1], 16
+ )
+ else:
+ raise RuntimeError(
+ "Received error response from Binho Nova, result = " + result
+ )
+ if rest:
+ result = self._nova.writeToReadFromSPI(
+ 0, False, True, rest, write_value
+ )
+ if result != "-NG":
+ resp = result.split(" ")
+ resp = resp[2]
+
+ # loop over half of resp len as we're reading 2 chars at a time to form a byte
+ loops = int(len(resp) / 2)
+ for j in range(loops):
+ buf[(i * self.WHR_PAYLOAD_MAX_LENGTH) + start + j] = int(
+ resp[j * 2] + resp[j * 2 + 1], 16
+ )
+ else:
+ raise RuntimeError(
+ "Received error response from Binho Nova, result = " + result
+ )
+ else:
+ for i in range(start, end):
+ buf[start + i] = int(
+ self.get_received_data(self._nova.transferSPI(0, write_value))
+ )
+
+ # pylint: disable=too-many-arguments,too-many-locals,too-many-branches
+ def write_readinto(
+ self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
+ ):
+ """Perform a half-duplex write from buffer_out and then
+ read data into buffer_in
+ """