Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/CAN
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2021-01-18 22:02:11 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-01-18 22:02:11 +0300
commitbd8d82f7f23534905c1d574d70b1f5c2d453b7c1 (patch)
treef17b8d3df1ca23c372b25d5c0be61ba031f8db1f /src/CAN
parentb0cc1ee344a9ed3062331fb6ede615fb43a5bf58 (diff)
Only send real time once a second in CAN time sync messages
Diffstat (limited to 'src/CAN')
-rw-r--r--src/CAN/CanInterface.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/CAN/CanInterface.cpp b/src/CAN/CanInterface.cpp
index c6bb3cfb..3105c730 100644
--- a/src/CAN/CanInterface.cpp
+++ b/src/CAN/CanInterface.cpp
@@ -624,6 +624,7 @@ extern "C" [[noreturn]] void CanClockLoop(void *) noexcept
{
CanMessageBuffer buf(nullptr);
uint32_t lastWakeTime = xTaskGetTickCount();
+ uint32_t lastRealTimeSent = 0;
for (;;)
{
@@ -666,10 +667,20 @@ extern "C" [[noreturn]] void CanClockLoop(void *) noexcept
{
msg->lastTimeAcknowledgeDelay = 0;
}
-
- msg->realTime = (uint32_t)reprap.GetPlatform().GetDateTime(); // TODO save CAN bandwidth by sending this just once per second
msg->isPrinting = reprap.GetGCodes().IsReallyPrinting();
+ // Send the real time just once a second
+ const uint32_t realTime = (uint32_t)reprap.GetPlatform().GetDateTime();
+ if (realTime != lastRealTimeSent)
+ {
+ msg->realTime = realTime;
+ lastRealTimeSent = realTime;
+ }
+ else
+ {
+ buf.dataLength = CanMessageTimeSync::SizeWithoutRealTime; // send a short message to save CAN bandwidth
+ }
+
#if SAME70
lastTimeSent = StepTimer::GetTimerTicks();
#else
@@ -686,6 +697,7 @@ extern "C" [[noreturn]] void CanClockLoop(void *) noexcept
mcan_fd_send_ext_message_no_wait(&mcan_instance, buf.id.GetWholeId(), reinterpret_cast<uint8_t*>(&(buf.msg)), buf.dataLength, TxBufferIndexTimeSync, buf.useBrs, buf.marker);
#endif
}
+
// Delay until it is time again
vTaskDelayUntil(&lastWakeTime, CanClockIntervalMillis);
}