1313
1414// Initialization of static members
1515QueueHandle_t LoadComms::priorityDataQueue = nullptr ;
16- uint_fast32_t LoadComms::txEvents = 0 ; // DONE: check against last years code
17- uint_fast32_t LoadComms::bytesSent = 0 ;
18- uint_fast32_t LoadComms::bytesNotSent = 0 ;
19- uint_fast32_t LoadComms::rxEvents = 0 ;
20- uint_fast32_t LoadComms::bytesReceived = 0 ;
16+ std::atomic< uint_fast32_t > LoadComms::txEvents = 0 ; // DONE: check against last years code
17+ std::atomic< uint_fast32_t > LoadComms::bytesSent = 0 ;
18+ std::atomic< uint_fast32_t > LoadComms::bytesNotSent = 0 ;
19+ std::atomic< uint_fast32_t > LoadComms::rxEvents = 0 ;
20+ std::atomic< uint_fast32_t > LoadComms::bytesReceived = 0 ;
2121
2222/* *
2323 * @brief MAC address of the nacelle controller.
@@ -122,19 +122,19 @@ etl::string<LoadComms::LOG_STRING_SIZE> LoadComms::getLogString() const {
122122 * https://stackoverflow.com/questions/12346487/what-do-each-memory-order-mean
123123 * @see https://en.cppreference.com/cpp/atomic/memory_order
124124 */
125- etl::to_string (txEvents, logString, decFormatA, true ); // 6 chars
125+ etl::to_string (txEvents. load (std::memory_order_relaxed) , logString, decFormatA, true ); // 6 chars
126126 logString.append (" , TxBS: " ); // 8 chars
127127
128128 etl::format_spec decFormatB;
129129 decFormatB.width (7 ).fill (' 0' ); // [7 chars]
130- etl::to_string (bytesSent, logString, decFormatB, true ); // 7 chars
130+ etl::to_string (bytesSent. load (std::memory_order_relaxed) , logString, decFormatB, true ); // 7 chars
131131 logString.append (" , TxBF: " ); // 8 chars
132- etl::to_string (bytesNotSent, logString, decFormatB, true ); // 7 chars
132+ etl::to_string (bytesNotSent. load (std::memory_order_relaxed) , logString, decFormatB, true ); // 7 chars
133133
134134 logString.append (" , RxE: " ); // 7 chars
135- etl::to_string (rxEvents, logString, decFormatA, true ); // 6 chars
135+ etl::to_string (rxEvents. load (std::memory_order_relaxed) , logString, decFormatA, true ); // 6 chars
136136 logString.append (" , RxBS: " ); // 8 chars
137- etl::to_string (bytesReceived, logString, decFormatB, true ); // 7 chars
137+ etl::to_string (bytesReceived. load (std::memory_order_relaxed) , logString, decFormatB, true ); // 7 chars
138138
139139 return logString;
140140 }
@@ -154,6 +154,9 @@ void LoadComms::onDataSent_(const wifi_tx_info_t *tx_info, esp_now_send_status_t
154154}
155155
156156void LoadComms::onDataRecv_ (const esp_now_recv_info_t *recv_info, const uint8_t *data, int len) {
157+ rxEvents++;
158+ bytesReceived += len;
159+
157160 if (s_instance == nullptr ) {
158161 ESP_LOGE (TAG , " Rx CB: Invalid instance" );
159162 return ;
@@ -174,8 +177,6 @@ void LoadComms::onDataRecv_(const esp_now_recv_info_t *recv_info, const uint8_t
174177
175178 // Serial.println("Received NacellePacket:");
176179 // printNacellePacket(s_instance->incomingPacket_, Serial);
177- rxEvents++;
178- bytesReceived += len;
179180
180181 (void )xQueueOverwrite (priorityDataQueue, data); // Allegedly cannot fail
181182 } else {
0 commit comments