Skip to content

Commit ae04549

Browse files
author
NoahAndrews
committed
Don't start heartbeats while the heartbeat ack timeout is expired
If the application attempts to do this, the heartbeat will not be started until after the next heartbeat ack is received.
1 parent da380de commit ae04549

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/canWrapper.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,13 @@ void startRevCommonHeartbeat(const Napi::CallbackInfo& info) {
719719
}
720720

721721
std::array<uint8_t, 1> payload = {1};
722-
_sendCANMessage(descriptor, REV_COMMON_HEARTBEAT_ID, payload.data(), 1, HEARTBEAT_PERIOD_MS);
723722

724723
std::scoped_lock lock{watchdogMtx};
724+
725+
if (!heartbeatTimeoutExpired) {
726+
_sendCANMessage(descriptor, REV_COMMON_HEARTBEAT_ID, payload.data(), 1, HEARTBEAT_PERIOD_MS);
727+
}
728+
725729
revCommonHeartbeatMap[descriptor] = payload;
726730

727731
if (heartbeatsRunning.size() == 0) {
@@ -753,18 +757,21 @@ void setSparkMaxHeartbeatData(const Napi::CallbackInfo& info) {
753757
if (deviceIterator == canDeviceMap.end()) return;
754758
}
755759

756-
// Clear the scheduled heartbeat that has outdated data so that the updated one gets sent out immediately
757-
_sendCANMessage(descriptor, SPARK_HEARTBEAT_ID, heartbeat.data(), 8, -1);
758-
759760
int sum = 0;
760761
for (uint32_t i = 0; i < dataParam.Length(); i++) {
761762
heartbeat[i] = dataParam.Get(i).As<Napi::Number>().Uint32Value();
762763
sum+= heartbeat[i];
763764
}
764765

765-
_sendCANMessage(descriptor, SPARK_HEARTBEAT_ID, heartbeat.data(), 8, HEARTBEAT_PERIOD_MS);
766-
767766
std::scoped_lock lock{watchdogMtx};
767+
768+
if (!heartbeatTimeoutExpired) {
769+
// Clear the scheduled heartbeat that has outdated data so that the updated one gets sent out immediately
770+
_sendCANMessage(descriptor, SPARK_HEARTBEAT_ID, heartbeat.data(), 8, -1);
771+
772+
_sendCANMessage(descriptor, SPARK_HEARTBEAT_ID, heartbeat.data(), 8, HEARTBEAT_PERIOD_MS);
773+
}
774+
768775
sparkHeartbeatMap[descriptor] = heartbeat;
769776

770777
if (heartbeatsRunning.size() == 0) {

0 commit comments

Comments
 (0)