Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update ScienceLab.java class for fixing the issue fossasia#2580
  • Loading branch information
Surajkumar5050 authored Dec 9, 2024
1 parent 5c4f88c commit fdb5d89
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/src/main/java/io/pslab/communication/ScienceLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,9 @@ private boolean fetchData(int channelNumber) {
mPacketHandler.sendInt(this.dataSplitting);
byte[] data = new byte[this.dataSplitting * 2 + 1];
mPacketHandler.read(data, this.dataSplitting * 2 + 1);
for (int j = 0; j < data.length - 1; j++)
for (int j = 0; j < data.length - 1; j++) {
listData.add((int) data[j] & 0xff);
}
}

if ((samples % this.dataSplitting) != 0) {
Expand All @@ -473,8 +474,9 @@ private boolean fetchData(int channelNumber) {
mPacketHandler.sendInt(samples % this.dataSplitting);
byte[] data = new byte[2 * (samples % this.dataSplitting) + 1];
mPacketHandler.read(data, 2 * (samples % this.dataSplitting) + 1);
for (int j = 0; j < data.length - 1; j++)
for (int j = 0; j < data.length - 1; j++) {
listData.add((int) data[j] & 0xff);
}
}

} catch (IOException e) {
Expand All @@ -483,8 +485,12 @@ private boolean fetchData(int channelNumber) {
}

for (int i = 0; i < listData.size() / 2; i++) {
this.buffer[i] = (listData.get(i * 2)) | (listData.get(i * 2 + 1) << 8);
while (this.buffer[i] > 1023) this.buffer[i] -= 1023;
if (i * 2 + 1 < listData.size()) {
this.buffer[i] = (listData.get(i * 2)) | (listData.get(i * 2 + 1) << 8);
while (this.buffer[i] > 1023) this.buffer[i] -= 1023;
} else {
Log.e(TAG, "Index out of bounds: " + (i * 2 + 1));
}
}

Log.v("RAW DATA:", Arrays.toString(Arrays.copyOfRange(buffer, 0, samples)));
Expand Down Expand Up @@ -2905,4 +2911,4 @@ public void disconnect() throws IOException {
mCommunicationHandler.close();
PacketHandler.version = "";
}
}
}

0 comments on commit fdb5d89

Please sign in to comment.