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

circle buffer rough fix #785

Closed
wants to merge 4 commits into from
Closed

circle buffer rough fix #785

wants to merge 4 commits into from

Conversation

caila-marashaj
Copy link
Contributor

No description provided.

@@ -371,6 +395,8 @@ class MMR920 {
if (echo_this_time) {
auto response_pressure = pressure - current_pressure_baseline_pa;
// do we want pressure or response pressure
if (pressure_transations < 500) { pressure_transactions++; }
Copy link
Contributor

Choose a reason for hiding this comment

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

500 should be SENSOR_BUFFER_SIZE instead

// NOLINTNEXTLINE(div-by-zero)
int current_index = (i + sensor_buffer_index) %
static_cast<int>(SENSOR_BUFFER_SIZE);
if (pressure_transations >= 500) {
Copy link
Contributor

Choose a reason for hiding this comment

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

500 should be SENSOR_BUFFER_SIZE

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

This logic is kind of weird and fiddly. We should make it something that can be more easily tested. I'd suggest putting the indexing logic in its own file and class (like DoubleBuffer) with some methods to do various things and like a function called get_read_index() for getting data out (really, I'd suggest using a custom iterator, but that's kind of a pain). Then, we need to test the hell out of it.

.sensor_id = sensor_id,
.sensor_data = mmr920::reading_to_fixed_point(
(*sensor_buffer).at(i))});
if (i % 10 == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

let's add a todo here or something - send_can_message should return a success value so we can reactively do this when needed

include/sensors/core/tasks/pressure_driver.hpp Outdated Show resolved Hide resolved
include/sensors/core/tasks/pressure_driver.hpp Outdated Show resolved Hide resolved
if (pressure_transations >= 500) {
for (int i = 0; i < static_cast<int>(SENSOR_BUFFER_SIZE); i++) {
// send over buffer and then clear buffer values
// NOLINTNEXTLINE(div-by-zero)
Copy link
Member

Choose a reason for hiding this comment

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

is this warning because SENSOR_BUFFER_SIZE isn't defined in lint or something?

int current_index = (i + sensor_buffer_index) %
static_cast<int>(SENSOR_BUFFER_SIZE);
if (pressure_transations >= 500) {
for (int i = 0; i < static_cast<int>(SENSOR_BUFFER_SIZE); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: things used as indices should be unsigned

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