Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettsummerfi3ld committed Sep 16, 2024
2 parents 725b059 + 2dc58f7 commit 578acf5
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 29 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ jobs:
distribution: 'zulu'
java-version: 11

- name: Cache
uses: actions/cache@v4
with:
path: |
.gradle
bin
build
key: ${{ matrix.name }}-build-${{ github.sha }}
restore-keys: |
${{ matrix.name }}-build-
- name: Build
run: |
./gradlew outputVersions publish ${{ matrix.build-options }} -PreleaseMode
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea/

### Linux ###
*~

Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ updateFrameData(frame)
sendMessage(frame, 2000)
```

In this case, the first frame will be scheduled immediately, the second will be scheduled 5 seconds later, and after that, subsequent frames will be scheduled every 2 seconds. Note
that any change to the data in the second call will not be sent, meaning the second call is essentially a no-op if a new call with different data is sent before the previous
interval is up. Sending a frame with an interval of `-1` will cancel the repeat, and not send the frame. Sending with an interval of `0` will schedule the new frame once, then stop repeating.
In this case, the first frame will be scheduled immediately,
the second will be scheduled 5 seconds later, and after that,
subsequent frames will be scheduled every 2 seconds. Note
that any change to the data in the second call will not be
sent, meaning the second call is essentially a no-op if a
new call with different data is sent before the previous
interval is up. Sending a frame with an interval of -1
will cancel the repeat, and not send the frame. Sending with
an interval of 0 will schedule the new frame once, then stop
repeating. Unlike with a positive interval, an interval of 0
guarantees that each new message will be sent.

## Build Requirements

Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ allprojects {
repositories {
mavenCentral()
}
if (project.hasProperty('releaseMode')) {
wpilibRepositories.addAllReleaseRepositories(it)
} else {
wpilibRepositories.addAllDevelopmentRepositories(it)
}
// Replace this line with the commented-out lines if we ever start including CANBridge in the FRC Beta
wpilibRepositories.addAllReleaseRepositories(it)
// if (project.hasProperty('releaseMode')) {
// wpilibRepositories.addAllReleaseRepositories(it)
// } else {
// wpilibRepositories.addAllDevelopmentRepositories(it)
// }
}

apply from: 'config.gradle'
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'maven-publish'

ext.licenseFile = files("$rootDir/LICENSE.txt")

def pubVersion = '2.3.8'
def pubVersion = '2.4.0'

def outputsFolder = file("$buildDir/allOutputs")

Expand Down
16 changes: 16 additions & 0 deletions src/main/native/include/rev/CANDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ class CANDevice {

virtual int GetId() const = 0;

/**
* Start, stop, or update a periodic signal
*
* @param msg the message to send. See notes in periodMs.
* @param periodMs the period of the signal, 0, or -1. If this value is -1,
* the value of msg is irrelevant, and we stop any signals with the
* given id. If the value is 0, we queue a new message given by msg.
* This message will always be scheduled to be sent exactly once.
* If a repeating value is scheduled, passing 0 will cancel it.
* If this value is any positive value, schedule msg to be sent
* every periodMs milliseconds. If a message with this id was already
* scheduled to repeat, update the period and message contents. Note
* that this will not replace a message with periodMs set to 0.
*
* @return a CANStatus
*/
virtual CANStatus SendCANMessage(const CANMessage& msg, int periodMs) = 0;
virtual CANStatus ReceiveCANMessage(std::shared_ptr<CANMessage>& msg, uint32_t messageID, uint32_t messageMask) = 0;
virtual CANStatus OpenStreamSession(uint32_t* sessionHandle, CANBridge_CANFilter filter, uint32_t maxSize) = 0;
Expand Down
28 changes: 20 additions & 8 deletions src/main/native/include/rev/Drivers/DriverDeviceThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,41 @@ class DriverDeviceThread {
}
}

detail::CANThreadSendQueueElement* findFirstMatchingId(int targetId) {
detail::CANThreadSendQueueElement* findFirstMatchingIdWithNonZeroInterval(uint32_t targetId) {
for (auto& element : m_sendQueue) {
if (element.m_msg.GetMessageId() == targetId) {
if (element.m_msg.GetMessageId() == targetId && element.m_intervalMs > 0) {
return &element;
}
}
return nullptr; // If no matching element found
}

void removeElementsWithId(int targetId) {
void removeElementsWithId(uint32_t targetId) {
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());
}

bool EnqueueMessage(const CANMessage& msg, int32_t timeIntervalMs) {
std::lock_guard<std::mutex> lock(m_writeMutex);

detail::CANThreadSendQueueElement* existing = findFirstMatchingId(msg.GetMessageId());
if(timeIntervalMs == 0) {
// If the time interval is 0, we want to allow duplicates.
m_sendQueue.push_back(detail::CANThreadSendQueueElement(msg, timeIntervalMs));

if(existing) {
existing->m_intervalMs = timeIntervalMs;
existing->m_msg = msg;
// Cancel existing repeating frame with same id
detail::CANThreadSendQueueElement* existing = findFirstMatchingIdWithNonZeroInterval(msg.GetMessageId());
if(existing) {
existing->m_intervalMs = -1;
}
} else {
m_sendQueue.push_back(detail::CANThreadSendQueueElement(msg, timeIntervalMs));
// We don't want to replace elements with zero as the interval. Those should be guaranteed to be sent
detail::CANThreadSendQueueElement* existing = findFirstMatchingIdWithNonZeroInterval(msg.GetMessageId());

if(existing) {
existing->m_intervalMs = timeIntervalMs;
existing->m_msg = msg;
} else {
m_sendQueue.push_back(detail::CANThreadSendQueueElement(msg, timeIntervalMs));
}
}

// TODO: Limit the max queue size
Expand Down
2 changes: 1 addition & 1 deletion vendordeps/CANBridge.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileName": "CANBridge.json",
"name": "CANBridge",
"version": "2.3.8",
"version": "2.4.0",
"uuid": "34b37c7c-8acc-405f-9631-d21f20dc59d8",
"mavenUrls": [
"http://www.revrobotics.com/content/sw/max/sdk/maven/"
Expand Down

0 comments on commit 578acf5

Please sign in to comment.