Skip to content

Commit 1beaba4

Browse files
authored
Merge pull request #35 from REVrobotics/fix/cancel-repeat-frames
2 parents 2dc58f7 + 32be8b4 commit 1beaba4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/native/include/rev/Drivers/DriverDeviceThread.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class DriverDeviceThread {
8888
m_sendQueue.erase(std::remove_if(m_sendQueue.begin(), m_sendQueue.end(), [targetId](detail::CANThreadSendQueueElement element) { return element.m_msg.GetMessageId() == targetId; }), m_sendQueue.end());
8989
}
9090

91+
void removeRepeatingWithId(uint32_t targetId) {
92+
m_sendQueue.erase(std::remove_if(m_sendQueue.begin(), m_sendQueue.end(), [targetId](detail::CANThreadSendQueueElement element) { return element.m_intervalMs > 0 && element.m_msg.GetMessageId() == targetId; }), m_sendQueue.end());
93+
}
94+
9195
bool EnqueueMessage(const CANMessage& msg, int32_t timeIntervalMs) {
9296
std::lock_guard<std::mutex> lock(m_writeMutex);
9397

@@ -96,10 +100,10 @@ class DriverDeviceThread {
96100
m_sendQueue.push_back(detail::CANThreadSendQueueElement(msg, timeIntervalMs));
97101

98102
// Cancel existing repeating frame with same id
99-
detail::CANThreadSendQueueElement* existing = findFirstMatchingIdWithNonZeroInterval(msg.GetMessageId());
100-
if(existing) {
101-
existing->m_intervalMs = -1;
102-
}
103+
removeRepeatingWithId(msg.GetMessageId());
104+
} else if(timeIntervalMs == -1) {
105+
// Remove any scheduled messages with this ID
106+
removeRepeatingWithId(msg.GetMessageId());
103107
} else {
104108
// We don't want to replace elements with zero as the interval. Those should be guaranteed to be sent
105109
detail::CANThreadSendQueueElement* existing = findFirstMatchingIdWithNonZeroInterval(msg.GetMessageId());

0 commit comments

Comments
 (0)