+ readlen = in_end - in_start
+ writelen = out_end - out_start
+ if readlen > writelen:
+ # resize out and pad with 0's
+ tmp = bytearray(buffer_out)
+ tmp.extend([0] * (readlen - len(buffer_out)))
+ buffer_out = tmp
+
+ if int(self._novaCMDVer) >= 1:
+ chunks, rest = divmod(len(buffer_out), self.WHR_PAYLOAD_MAX_LENGTH)
+ i = 0
+ for i in range(chunks):
+ chunk_start = out_start + i * self.WHR_PAYLOAD_MAX_LENGTH
+ chunk_end = chunk_start + self.WHR_PAYLOAD_MAX_LENGTH
+ result = self._nova.writeToReadFromSPI(
+ 0,
+ True,
+ True,
+ chunk_end - chunk_start,
+ buffer_out[chunk_start:chunk_end],
+ )
+
+ 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):
+ buffer_in[
+ (i * self.WHR_PAYLOAD_MAX_LENGTH) + in_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, True, True, rest, buffer_out[-1 * rest :]
+ )
+ 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):
+ buffer_in[
+ (i * self.WHR_PAYLOAD_MAX_LENGTH) + in_start + j
+ ] = int(resp[j * 2] + resp[j * 2 + 1], 16)
+ else:
+ raise RuntimeError(
+ "Received error response from Binho Nova, result = " + result
+ )
+ print(buffer_in)
+ else:
+ for data_out in buffer_out:
+ data_in = int(
+ self.get_received_data(self._nova.transferSPI(0, data_out))
+ )
+ if i < readlen:
+ buffer_in[in_start + i] = data_in
+ i += 1
+
+ # pylint: enable=too-many-arguments,too-many-locals,too-many-branches