Skip to content

Protected Sensor Data Reads#95

Merged
butchhartman merged 17 commits into
development/appafrom
feature/rc/protected-sensor-data-writes
Feb 9, 2026
Merged

Protected Sensor Data Reads#95
butchhartman merged 17 commits into
development/appafrom
feature/rc/protected-sensor-data-writes

Conversation

@butchhartman

@butchhartman butchhartman commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Description

sensor_dump() now checks the status of sensors before performing any read operations. If sensors ready, interrupts are disabled before any reads to prevent data race issues.

Issue Link

Closes FCF #221

Testing

  • Passes existing unit tests
  • Unit tests modified (link the test changes as a child PR)
  • Integration test performed

Testing Artifacts

image

Reviewer Checklist

Standards

  • Follows FCF Architectural Standards
  • Follows SDR Coding Standards
  • Code complexity/function Size is minimized
  • Code is testable
  • Code is readable and commented properly
  • License terms are respected

Error Handling

  • Potentially unsafe functions return a status code
  • Error returns properly handled

Memory

  • Stack allocated memory is scoped correctly
  • Heap allocated memory is avoided
  • Globally allocated memory is minimized except when necessary
  • Pointers are used correctly
  • Concurrency has been considered

Performance

  • Rate limiters are respected
  • Busy waiting is avoided
  • "Delay" calls are not used in performance sensitive code

@butchhartman butchhartman requested a review from ETSells February 4, 2026 04:32

@ETSells ETSells left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Functionally, this looks right. However, there are quite a few standards issues I'm seeing, so I would like them fixed before re-reviewing.

Comment thread baro/baro.c Outdated
Comment thread baro/baro.h Outdated
Comment thread common/common.c Outdated
Comment thread imu/imu.c Outdated
Comment thread imu/imu.c Outdated
Comment thread sensor/sensor.c Outdated
Comment thread sensor/sensor.c Outdated
Comment thread sensor/sensor.c Outdated
@butchhartman

Copy link
Copy Markdown
Contributor Author

Everything you pointed out should be fixed now!

@butchhartman butchhartman requested a review from ETSells February 4, 2026 13:46
@ETSells

ETSells commented Feb 4, 2026

Copy link
Copy Markdown
Member

my god, man... do you sleep??

will take a look today, thanks for the quick turnaround lol

@ETSells ETSells left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Functionally looks good. I had some whitespace nitpicks that I went in and fixed myself. If you're curious about what these were, feel free to look. I also fixed one of my previous mistakes that I saw just under your work (failed to properly attribute a section of sensor.c to Bosch).

My big recommendation is to check your tabs vs spaces. Right now, it looks like your tabs are set up to introduce 8 spaces. Most other text editors (especially for C-style code syntax) default to 4.

Recommend holding merge pending a manual integration test on "Bad Drogue" FC.

Comment thread baro/baro.c
* Returns the baro_data_ready flag *
* *
*******************************************************************************/
bool baro_get_baro_data_ready

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixing this myself bc it's a total nitpick but whitespace is still a little off. it should be two lines between functions

Comment thread baro/baro.c

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You appear to be double indenting (8 spaces instead of 4) when you hit tab. This is likely a setting in vim that can be updated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also if you have a "tabs -> spaces" setting, I recommend enabling that as well. Tabs can be variable between different text editors, but if it converts to spaces then it'll render correctly across them.

Comment thread imu/imu.c
* *
* DESCRIPTION: *
* Returns the imu_data_ready flag *
* *

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Only one line of spacing at the bottom of a procedure header

Comment thread sensor/sensor.c Outdated
return baro_ready | imu_ready;
}
/* Ensure both the IMU and barometer are ready to be read */
if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready() )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My recommendation for compound conditions like this is to separate out to multiple lines if there are any more than 2 components. Tends to make it more readable.

Ex:

/* Ensure both the IMU and barometer are ready to be read */                
if ( imu_get_imu_data_ready() 
  && imu_get_mag_data_ready() 
  && baro_get_baro_data_ready() ) 
    {
	return SENSOR_OK;
    }

Note the alignment of the '&&' with the opening parentheses so that each component starts on the same column.

Comment thread sensor/sensor.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can remove this since the next block is under the same cond-def

@butchhartman

Copy link
Copy Markdown
Contributor Author

Gahh, I thought I them all. I wrote down some of the formatting conventions I've seen thus far so hopefully I'll be better about that in the future lol. You're totally right about the 8-indent tabs, though. I have tab -> spaces on, but sometimes there were secret hidden tabs which threw off my formatting in some cases. I'll make changes to my config.

Is the integration testing something we'll go over on Friday?

@ETSells

ETSells commented Feb 4, 2026

Copy link
Copy Markdown
Member

Yeah no worries lol! Wanted to save us from doing like 4 rounds of revisions on an otherwise spotless PR haha.

The integration test for this basically just needs to verify that we're still getting sensor data. Don't worry about checking the functional requirement (preventing race conditions in modifications) and instead focus on making sure it doesn't crash & all of the sensor data still exists. We can run this on bad drogue w/ the debugger. Alternatively, we might have an FC by friday morning, so we could also go over it then.

@ETSells

ETSells commented Feb 9, 2026

Copy link
Copy Markdown
Member

Integration test pass, looks good. Free to merge.

@butchhartman butchhartman merged commit da2ef77 into development/appa Feb 9, 2026
2 checks passed
@ETSells ETSells deleted the feature/rc/protected-sensor-data-writes branch April 29, 2026 08:02
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.

Sensor: Disable interrupts during critical sections to protect writes to sensor data struct

2 participants