-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Crash in XY plot of Oscilloscope screen #2580 #2582
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,52 +446,58 @@ public int[] oscilloscopeProgress() { | |
} | ||
|
||
private boolean fetchData(int channelNumber) { | ||
int samples = this.aChannels.get(channelNumber - 1).length; | ||
if (channelNumber > this.channelsInBuffer) { | ||
Log.v(TAG, "Channel Unavailable"); | ||
return false; | ||
} | ||
Log.v("Samples", "" + samples); | ||
Log.v("Data Splitting", "" + this.dataSplitting); | ||
ArrayList<Integer> listData = new ArrayList<>(); | ||
try { | ||
for (int i = 0; i < samples / this.dataSplitting; i++) { | ||
mPacketHandler.sendByte(mCommandsProto.COMMON); | ||
mPacketHandler.sendByte(mCommandsProto.RETRIEVE_BUFFER); | ||
mPacketHandler.sendInt(this.aChannels.get(channelNumber - 1).bufferIndex + (i * this.dataSplitting)); | ||
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++) | ||
listData.add((int) data[j] & 0xff); | ||
int samples = this.aChannels.get(channelNumber - 1).length; | ||
if (channelNumber > this.channelsInBuffer) { | ||
Log.v(TAG, "Channel Unavailable"); | ||
return false; | ||
} | ||
Log.v("Samples", "" + samples); | ||
Log.v("Data Splitting", "" + this.dataSplitting); | ||
ArrayList<Integer> listData = new ArrayList<>(); | ||
try { | ||
for (int i = 0; i < samples / this.dataSplitting; i++) { | ||
mPacketHandler.sendByte(mCommandsProto.COMMON); | ||
mPacketHandler.sendByte(mCommandsProto.RETRIEVE_BUFFER); | ||
mPacketHandler.sendInt(this.aChannels.get(channelNumber - 1).bufferIndex + (i * this.dataSplitting)); | ||
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++) { | ||
listData.add((int) data[j] & 0xff); | ||
} | ||
} | ||
|
||
if ((samples % this.dataSplitting) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for here. Formatting issues. |
||
mPacketHandler.sendByte(mCommandsProto.COMMON); | ||
mPacketHandler.sendByte(mCommandsProto.RETRIEVE_BUFFER); | ||
mPacketHandler.sendInt(this.aChannels.get(channelNumber - 1).bufferIndex + samples - samples % this.dataSplitting); | ||
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++) | ||
listData.add((int) data[j] & 0xff); | ||
if ((samples % this.dataSplitting) != 0) { | ||
mPacketHandler.sendByte(mCommandsProto.COMMON); | ||
mPacketHandler.sendByte(mCommandsProto.RETRIEVE_BUFFER); | ||
mPacketHandler.sendInt(this.aChannels.get(channelNumber - 1).bufferIndex + samples - samples % this.dataSplitting); | ||
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++) { | ||
listData.add((int) data[j] & 0xff); | ||
} | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
|
||
for (int i = 0; i < listData.size() / 2; i++) { | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
Surajkumar5050 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for (int i = 0; i < listData.size() / 2; i++) { | ||
if (i * 2 + 1 < listData.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this. We already have checks in place if the amount of data required isn't read properly from the PSLab device. |
||
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))); | ||
Log.v("RAW DATA:", Arrays.toString(Arrays.copyOfRange(buffer, 0, samples))); | ||
|
||
this.aChannels.get(channelNumber - 1).yAxis = this.aChannels.get(channelNumber - 1).fixValue(Arrays.copyOfRange(this.buffer, 0, samples)); | ||
return true; | ||
} | ||
this.aChannels.get(channelNumber - 1).yAxis = this.aChannels.get(channelNumber - 1).fixValue(Arrays.copyOfRange(this.buffer, 0, samples)); | ||
return true; | ||
} | ||
|
||
/** | ||
* Configure trigger parameters for 10-bit capture commands | ||
|
@@ -2905,4 +2911,4 @@ public void disconnect() throws IOException { | |
mCommunicationHandler.close(); | ||
PacketHandler.version = ""; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some formatting issues there.
It'd be great if you could format your files after you finish work and before you commit them.
Just select the whole file (
Ctrl+A
) and then run reformat (Ctrl+Alt+L
).