Skip to content
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

Temp Fix for Delayed Buffering of Stop Response during Device Construction on Raspberry Pi #74

Merged
merged 5 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v1.1.2

This release is compatible with device firmware v1.4.

Changes:
- libsweep:
- Adapts device construction to be compatible with RaspberryPi
- Removes implementation methods from API
- Propagates errors from background thread when accumulating scans

## v1.1.1

Expand Down
2 changes: 1 addition & 1 deletion libsweep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(sweep C CXX)

set(SWEEP_VERSION_MAJOR 1)
set(SWEEP_VERSION_MINOR 1)
set(SWEEP_VERSION_PATCH 1)
set(SWEEP_VERSION_PATCH 2)


option(DUMMY "Build dummy libsweep always returning static point cloud data. No device needed." OFF)
Expand Down
22 changes: 18 additions & 4 deletions libsweep/src/sweep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,28 @@ void sweep_device_stop_scanning(sweep_device_s device, sweep_error_s* error) try

sweep::protocol::write_command(device->serial, sweep::protocol::DATA_ACQUISITION_STOP);

// Wait some time, for the device to register the stop cmd and stop sending data blocks
// Wait some time for a few reasons:
// 1. allow time for the device to register the stop cmd and stop sending data blocks
// 2. allow time for slower performing devices (RaspberryPi) to buffer the stop response
// 3. allow a grace period for the device to perform its logging routine before sending a second stop command
Copy link
Collaborator

Choose a reason for hiding this comment

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

As said in the ticket, if we can just make the timeout below a bit longer I would go for that. Even hundreds of milliseconds are fine for construction if it makes things easier for us.

Copy link
Author

Choose a reason for hiding this comment

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

Check ticket for response.

std::this_thread::sleep_for(std::chrono::milliseconds(35));

// Flush the left over data blocks, received after sending the stop cmd
// This will also flush the response to the stop cmd
// Read the response from the first stop command
// It is possible this will contain garbage bytes (leftover from data stream), and will error
// But we are guaranteed to read at least as many bytes as the length of a stop response
sweep::protocol::response_header_s garbage_response;
try {
sweep::protocol::read_response_header(device->serial, sweep::protocol::DATA_ACQUISITION_STOP, &garbage_response);
} catch (const std::exception& ignore) {
// Catch and ignore the error in the case of the stop response containing garbage bytes
// Occurs if the device was actively streaming data before the stop cmd
(void)ignore;
}

// Flush any bytes left over, in case device was actively streaming data before the stop cmd
sweep::serial::device_flush(device->serial);

// Write another stop cmd so we can read a response
// Write another stop cmd so we can read a valid response
sweep::protocol::write_command(device->serial, sweep::protocol::DATA_ACQUISITION_STOP);

// read the response
Expand Down
2 changes: 1 addition & 1 deletion sweepjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sweepjs",
"version": "1.1.1",
"version": "1.1.2",
"description": "Native module for the Sweep LiDAR",
"keywords": [
"addon",
Expand Down