Skip to content

Commit 222f2fb

Browse files
committed
Added time-based wifi data logging
1 parent 93e5665 commit 222f2fb

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ demos/LoadDemo_v0.2.1.zip
99
demos/LoadDemo_v0.3.0.zip
1010
demos/LoadDemo_v0.3.0_v1.0.0.zip
1111
demos/LoadDemo_v0.3.1_v1.0.1.zip
12+
/.PVS-Studio

lib/LoadComms/LoadComms.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ etl::string<LoadComms::LOG_STRING_SIZE> LoadComms::getLogString() const {
145145
return logString;
146146
}
147147

148+
LoadComms::LogData LoadComms::getLogData() const {
149+
return LogData{txEvents, bytesSent, bytesNotSent, rxEvents, bytesReceived};
150+
}
151+
148152
void LoadComms::onDataSent_(const wifi_tx_info_t *tx_info, esp_now_send_status_t status) {
149153
// (void)tx_info;
150154
// Serial.print("Send status: ");

lib/LoadComms/LoadComms.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ class LoadComms {
9898
*/
9999
etl::string<LOG_STRING_SIZE> getLogString() const;
100100

101+
struct LogData {
102+
uint_fast32_t txEvents;
103+
uint_fast32_t bytesSent;
104+
uint_fast32_t bytesNotSent;
105+
uint_fast32_t rxEvents;
106+
uint_fast32_t bytesReceived;
107+
};
108+
109+
LogData getLogData() const;
110+
101111
private:
102112
NacellePacket incomingPacket_; ///< Received packet from nacelle.
103113
LoadboxPacket outgoingPacket_; ///< Outgoing packet to send.

src/main.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,38 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS = RUN::TASK_INTERVALS::TI_LOG_DATA_ms;
638638
// delay(LOG_ITEM_INTERVAL_MS);
639639

640640
ESP_LOGI(TAG, "%s", INA260::getLogString().c_str());
641-
642-
ESP_LOGI(TAG, "%s", loadComms.getLogString().c_str());
641+
642+
static unsigned int prevTime_us = 0;
643+
static LoadComms::LogData lastLogData = {0};
644+
unsigned int currentTime_us = micros();
645+
ESP_LOGI(TAG, "%s", loadComms.getLogString().c_str());
646+
LoadComms::LogData currentLogData = loadComms.getLogData();
647+
unsigned long deltaTime_us = currentTime_us - prevTime_us;
648+
uint_fast32_t deltaTxEvents =
649+
currentLogData.txEvents - lastLogData.txEvents;
650+
uint_fast32_t deltaBytesSent =
651+
currentLogData.bytesSent - lastLogData.bytesSent;
652+
uint_fast32_t deltaBytesFailed =
653+
currentLogData.bytesNotSent - lastLogData.bytesNotSent;
654+
uint_fast32_t deltaRxEvents =
655+
currentLogData.rxEvents - lastLogData.rxEvents;
656+
uint_fast32_t deltaBytesReceived =
657+
currentLogData.bytesReceived - lastLogData.bytesReceived;
658+
659+
constexpr unsigned long m_TO_BASE = 1000;
660+
constexpr unsigned long u_TO_m = 1000;
661+
constexpr unsigned long u_TO_BASE = m_TO_BASE * u_TO_m;
662+
ESP_LOGI(TAG, "TxE/s: %u, TxBS/s: %u, TxBF/s: %u, RxE/s: %u, RxB/s: %u",
663+
deltaTxEvents * u_TO_BASE / deltaTime_us,
664+
deltaBytesSent * u_TO_BASE / deltaTime_us,
665+
deltaBytesFailed * u_TO_BASE / deltaTime_us,
666+
deltaRxEvents * u_TO_BASE / deltaTime_us,
667+
deltaBytesReceived * u_TO_BASE / deltaTime_us);
668+
prevTime_us = currentTime_us;
669+
lastLogData = currentLogData;
670+
671+
unsigned int elapsedTime_us = currentTime_us - prevTime_us;
672+
prevTime_us = currentTime_us;
643673

644674
delay(LOG_ITEM_INTERVAL_MS);
645675

0 commit comments

Comments
 (0)