bristlemouth / bm_protocol

Primary Bristlemouth firmware repository
https://www.bristlemouth.org/
Apache License 2.0
12 stars 8 forks source link

Sc 196635 - refactor aanderaaController.cpp to use one timer for all aggregations #26

Closed victorsowa12 closed 1 year ago

victorsowa12 commented 1 year ago

Refactored aanderaaController.cpp to use one timer to mark the end of an aggregation period for all of the aanderaa's instead of one timer per aanderaa.

This entailed creating a new software timer that will fire every currentAggPeriodMin. Originally I was going to process the aggregated readings in this timers callback, but realizzed this may involve blocking code(a big no-no in timer callbacks). Instead I modified the existing task notifications to use bits, such that the timer callback will set a bit when it is time to end the aggregation. Now the aandderaa controller task will be notified when the aggregation period is complete and it will do the computations on the buffers, send them to the "report builder" task (just a todo comment now), and then clear the buffers.

Since the buffers get new readings added to their buffers in the middleware when receive a message we subscribed to, I added a mutex lock so that we can safely access the buffers from the aanderaa controller app to calculate the mean/stdev + clear them for the next aggregation period.

I also added a small check to the buffers to make sure they have a minimum amount of readings within them and if not we will send NAN for the means/stdevs. This will guarantee that the "report builder" will get a struct for every aanderaa, even if the aanderaa node stops working part way through a sample, or between samples.

victorsowa12 commented 1 year ago

Need to test with a simulated aanderaa app - then I will mark it ready for review