Skip to content

Commit 6073d05

Browse files
committed
Send power to nacelle
1 parent e02d843 commit 6073d05

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/LoadComms/LoadComms.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ void LoadComms::onDataRecv_(const esp_now_recv_info_t *recv_info,
207207
}
208208

209209
bool LoadComms::sendLoadboxData(int16_t d_mVPS, int16_t current_mA,
210-
int16_t dIPS, ESTOP_TYPE_NET safety) {
210+
int16_t dIPS, uint16_t powerIfWholeNum_mW,
211+
ESTOP_TYPE_NET safety) {
211212
// if (now - lastSendTime_ >= LOAD_COMMS_SEND_PERIOD_MS) {
212-
makeLoadboxPacket(outgoingPacket_, d_mVPS, current_mA, dIPS, safety);
213+
makeLoadboxPacket(outgoingPacket_, d_mVPS, current_mA, dIPS,
214+
powerIfWholeNum_mW, safety);
213215
esp_err_t result =
214216
esp_now_send(NACELLE_MAC, reinterpret_cast<uint8_t *>(&outgoingPacket_),
215217
sizeof(outgoingPacket_));

lib/LoadComms/LoadComms.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class LoadComms {
6868
* @param safety Safety value to send.
6969
*/
7070
bool sendLoadboxData(int16_t d_mVPS, int16_t current_mA, int16_t dIPS,
71-
ESTOP_TYPE_NET safety);
71+
uint16_t powerIfWholeNum_mW, ESTOP_TYPE_NET safety);
7272

7373
/**
7474
* @brief Process communication - call in main loop.

src/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,15 @@ vTaskSendData([[maybe_unused]] void *pvParameters) { // NOSONAR
571571
RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
572572

573573
uint32_t delay_ms = 0;
574+
// Prepare power reading
575+
int_fast32_t power_mW = INA260::power_mW;
576+
if (power_mW < 0) {
577+
power_mW = 0; // Don't send negative power readings
578+
}
579+
// Send
574580
if (loadComms.sendLoadboxData(
575581
INA260::dVoltage_mVPS, INA260::current_mA,
576-
INA260::dCurrent_mAPS,
582+
INA260::dCurrent_mAPS, static_cast<uint16_t>(power_mW),
577583
static_cast<ESTOP_TYPE_NET>(load.getSafetyFlag()))) {
578584
backoffFactor = RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
579585
delay_ms = RUN::TASK_INTERVALS::TI_SEND_ms;

0 commit comments

Comments
 (0)