Skip to content

Update pi4j and address api changes #329

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ConnorWhalen
Copy link
Contributor

We have to update pi4j to fix #328. Doing so has broken some of our code, mostly catching new exceptions when using serial.

@cal-pratt check the changes to MaestroChannel closely because I might have screwed up your byte management. serial.read() returns a byte array instead of a char now.

Copy link
Contributor

@cal-pratt cal-pratt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be tested. Will be really evident if the rov works or not lol. Trail and error is the name of this game

@@ -156,9 +162,12 @@ private short getPosition() {
lock.lock();
try {
serial.write(new byte[] {START_BYTE, maestro, COMMAND_GET_POSITION, channel});
final ByteBuffer response = ByteBuffer.allocate(4).putChar(serial.read()).putChar(serial.read());
final ByteBuffer response = ByteBuffer.allocate(4).put(serial.read(), 0, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like different logic. You only have one serial read.

putChar also writes two bytes into the buffer.
This seems weird in the first place. We could maybe jut write:

return ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).put(
    new byte[]{serial.read(), serial.read()}).getShort(0);

try {
serial.write(new byte[] {START_BYTE, maestro, COMMAND_GET_ERRORS});
final ByteBuffer response = ByteBuffer.allocate(2).put(serial.read(), 0, 2);
return BitSet.valueOf(new byte[]{response.get(1), response.get(0)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again seems weird

@cal-pratt
Copy link
Contributor

On second thought, the byte reads don't even matter because we don't use the voltage or current sensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants