From ce6d6a0b638fa5408c1d2776886508d477c66b37 Mon Sep 17 00:00:00 2001 From: NoahAndrews Date: Thu, 9 Nov 2023 22:34:02 -0600 Subject: [PATCH 1/3] Make ReceiveMessage() return the most recent matching message --- .../native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp | 6 +++++- src/main/native/cpp/Drivers/Serial/SerialDevice.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp b/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp index 1db983a..aff1dfc 100644 --- a/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp +++ b/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp @@ -137,7 +137,11 @@ CANStatus CandleWinUSBDevice::ReceiveCANMessage(std::shared_ptr& msg m_thread.ReceiveMessage(messages); std::shared_ptr mostRecent; for (auto& m : messages) { - if (CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) && CANBridge_ProcessMask({messageID, messageMask}, m.first)) { + if ( + CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) + && CANBridge_ProcessMask({messageID, messageMask}, m.first) + && m.second->GetTimestampUs() > mostRecent->GetTimestampUs() + ) { mostRecent = m.second; status = CANStatus::kOk; } diff --git a/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp b/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp index e63507b..7984b4d 100644 --- a/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp +++ b/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp @@ -91,7 +91,11 @@ CANStatus SerialDevice::ReceiveCANMessage(std::shared_ptr& msg, uint m_thread.ReceiveMessage(messages); std::shared_ptr mostRecent; for (auto& m : messages) { - if (CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) && CANBridge_ProcessMask({messageID, messageMask}, m.first)) { + if ( + CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) + && CANBridge_ProcessMask({messageID, messageMask}, m.first) + && m.second->GetTimestampUs() > mostRecent->GetTimestampUs() + ) { mostRecent = m.second; status = CANStatus::kOk; } From 08f645c32764b8fa8a37f96cf73df1bb310d43d7 Mon Sep 17 00:00:00 2001 From: NoahAndrews Date: Thu, 9 Nov 2023 22:34:32 -0600 Subject: [PATCH 2/3] Bump version to 2.2.0 --- publish.gradle | 2 +- vendordeps/CANBridge.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/publish.gradle b/publish.gradle index 0485877..ec8e163 100644 --- a/publish.gradle +++ b/publish.gradle @@ -2,7 +2,7 @@ apply plugin: 'maven-publish' ext.licenseFile = files("$rootDir/LICENSE.txt") -def pubVersion = '2.1.0' +def pubVersion = '2.2.0' def outputsFolder = file("$buildDir/allOutputs") diff --git a/vendordeps/CANBridge.json b/vendordeps/CANBridge.json index 08ac69f..dc5d6b0 100644 --- a/vendordeps/CANBridge.json +++ b/vendordeps/CANBridge.json @@ -1,7 +1,7 @@ { "fileName": "CANBridge.json", "name": "CANBridge", - "version": "2.1.0", + "version": "2.2.0", "uuid": "34b37c7c-8acc-405f-9631-d21f20dc59d8", "mavenUrls": [ "http://www.revrobotics.com/content/sw/max/sdk/maven/" From 8b2f5e17c8c2ffeb98d5fc46086e84296aeb1200 Mon Sep 17 00:00:00 2001 From: NoahAndrews Date: Fri, 10 Nov 2023 10:29:17 -0600 Subject: [PATCH 3/3] Fix null dereference --- src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp | 2 +- src/main/native/cpp/Drivers/Serial/SerialDevice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp b/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp index aff1dfc..ef53acb 100644 --- a/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp +++ b/src/main/native/cpp/Drivers/CandleWinUSB/CandleWinUSBDevice.cpp @@ -140,7 +140,7 @@ CANStatus CandleWinUSBDevice::ReceiveCANMessage(std::shared_ptr& msg if ( CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) && CANBridge_ProcessMask({messageID, messageMask}, m.first) - && m.second->GetTimestampUs() > mostRecent->GetTimestampUs() + && (!mostRecent || m.second->GetTimestampUs() > mostRecent->GetTimestampUs()) ) { mostRecent = m.second; status = CANStatus::kOk; diff --git a/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp b/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp index 7984b4d..c227b07 100644 --- a/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp +++ b/src/main/native/cpp/Drivers/Serial/SerialDevice.cpp @@ -94,7 +94,7 @@ CANStatus SerialDevice::ReceiveCANMessage(std::shared_ptr& msg, uint if ( CANBridge_ProcessMask({m.second->GetMessageId(), 0}, m.first) && CANBridge_ProcessMask({messageID, messageMask}, m.first) - && m.second->GetTimestampUs() > mostRecent->GetTimestampUs() + && (!mostRecent || m.second->GetTimestampUs() > mostRecent->GetTimestampUs()) ) { mostRecent = m.second; status = CANStatus::kOk;