Skip to content

Fixed badly set bitrate causing sweep object creation to hang on Linux #117

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

Merged
merged 2 commits into from
Jul 18, 2017

Conversation

Vrong
Copy link
Contributor

@Vrong Vrong commented Jul 18, 2017

This bug was causing sweep object creation to hang when trying to read the returned value from serial port. ==> Issue #72

Bitrate of the serial communication was badly set during the creation of the sweep object when using the libsweep library on Linux.

cfsetispeed(...) and cfsetospeed(...) both take a termios bitrate constant and not the bitrate directly. So should the get_baud(115200) call return the B115200 value defined in termios.h.

The fix seems to have a limitation when compiling on some MAC OS X computers. Termios constants like B115200 doesn't seem to be always defined. That's why the code uses a #ifdef as a workaround for MAC.

Thanks.

@@ -26,6 +26,15 @@ static speed_t get_baud(int32_t bitrate) {
throw error{"Only baud rate 115200 is supported at this time."};
return -1;
}

// translate human readable bitrate to termios bitrate
if (bitrate == 115200)
Copy link

Choose a reason for hiding this comment

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

This conditional branch is redundant given the if (bitrate != 115200) above, which results in an error. Maybe just

// if defined, translate human readable bitrate to termios bitrate
#ifdef B115200
    return B115200
#endif
return bitrate;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well ok, I was supposing that more bitrates would be supported in the future.

// translate human readable bitrate to termios bitrate
if (bitrate == 115200)
{
#ifdef B115200
Copy link

Choose a reason for hiding this comment

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

Could you clang format as well. Format file included in the main repo. If not, let me know and I'll clean it up before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not use to it but I can figure out how it works

@dcyoung
Copy link

dcyoung commented Jul 18, 2017

Thanks for this second PR. Even if a more robust and elegant portability fix can't be resolved just yet, the library is currently broken.... so I'd like to get this merged ASAP!!

@Vrong
Copy link
Contributor Author

Vrong commented Jul 18, 2017

Done

@dcyoung
Copy link

dcyoung commented Jul 18, 2017

I'll do one more final check on mac and get this merged! Thanks so much.

@dcyoung dcyoung merged commit 3c6738e into scanse:master Jul 18, 2017
@daniel-j-h
Copy link
Collaborator

Urgh thanks for the deep dive here and fixing the bug.

I think we hit this last week when playing with Haskell bindings in #115 but didn't look further (since struggling with Haskell was already enough for the evening 😅).

@@ -148,7 +153,7 @@ void device_read(device_s serial, void* to, int32_t len) {
} else {
throw error{"reading from serial device failed"};
}
} else if(ret == 0){
} else if (ret == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should check for feof (?)

// translate human readable bitrate to termios bitrate
#ifdef B115200
return B115200;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good quick-fix but we should refactor the function (or how we allow for bitrates here).

We take a bitrate argument but in case we hit the branch here the argument is never used.

@Vrong
Copy link
Contributor Author

Vrong commented Jul 22, 2017

The first fix I made was actually including a condition testing the bitrate before setting a constant, but this one was not merged.

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

Successfully merging this pull request may close these issues.

3 participants