+ if int(self._novaCMDVer) >= 1:
+ totalIn = in_end - in_start
+ totalOut = out_end - out_start
+ totalBytes = totalIn
+ if totalOut > totalIn:
+ totalBytes = totalOut
+ chunks, rest = divmod(totalBytes, self.WHR_PAYLOAD_MAX_LENGTH)
+ if rest > 0:
+ chunks += 1
+
+ for i in range(chunks):
+ # calculate the number of bytes to be written and read
+ numInBytes = self.WHR_PAYLOAD_MAX_LENGTH
+ if totalIn < self.WHR_PAYLOAD_MAX_LENGTH:
+ numInBytes = totalIn
+ numOutBytes = self.WHR_PAYLOAD_MAX_LENGTH
+ if totalOut < self.WHR_PAYLOAD_MAX_LENGTH:
+ numOutBytes = totalOut
+
+ # setup the buffer out chunk offset
+ buffer = "0"
+ if numOutBytes > 0:
+ chunk_start = out_start + i * self.WHR_PAYLOAD_MAX_LENGTH
+ chunk_end = chunk_start + numOutBytes
+ buffer = buffer_out[chunk_start:chunk_end]
+
+ result = self._nova.writeToReadFromI2C(
+ 0, address << 1, stop, numInBytes, numOutBytes, buffer
+ )
+ totalIn -= numInBytes
+ totalOut -= numOutBytes
+
+ if result != "-NG":
+ if numInBytes:
+ resp = result.split(" ")
+ resp = resp[2]
+
+ for j in range(numInBytes):
+ buffer_in[
+ in_start + i * self.WHR_PAYLOAD_MAX_LENGTH + j
+ ] = int(resp[j * 2] + resp[j * 2 + 1], 16)
+ else:
+ raise RuntimeError(
+ "Received error response from Binho Nova, result = " + result
+ )
+ else:
+ self._nova.startI2C(0, address << 1)
+
+ for i in range(out_start, out_end):
+ self._nova.writeByteI2C(0, buffer_out[i])
+
+ if stop:
+ self._nova.endI2C(0)
+ else:
+ self._nova.endI2C(0, True)
+
+ result = self._nova.readBytesI2C(
+ 0, address << 1, len(buffer_in[in_start:in_end])
+ )
+
+ if result != "-NG":
+ resp = result.split(" ")
+
+ for i in range(len(buffer_in[in_start:in_end])):
+ buffer_in[in_start + i] = int(resp[2 + i])
+ else:
+ raise RuntimeError(
+ "Received error response from Binho Nova, result = " + result
+ )
+
+
+# pylint: enable=unused-argument,too-many-locals,too-many-branches