Skip to content

Commit

Permalink
Update for 2025 firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 31, 2024
1 parent 14cb34b commit f340277
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ By default, this project builds against the latest WPILib development build. To

## Data Format

### Revision 2
### Revision 2/3

Revision 2 = 2024, Revision 3 = 2025 (no model frames)

- "Raw/Persistent"
- Buffer Length, Not Published (uint32)
Expand Down
37 changes: 6 additions & 31 deletions src/main/driver/cpp/URCLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ extern "C" {
constexpr HAL_CANManufacturer manufacturer = HAL_CAN_Man_kREV;
constexpr HAL_CANDeviceType deviceType = HAL_CAN_Dev_kMotorController;

constexpr int firmwareApi = 0x98;
constexpr int firmwareApiClass = 9;
constexpr int firmwareApiIndex = 8;
constexpr int firmwareApi =
(firmwareApiClass & 0x3f) << 4 | (firmwareApiIndex & 0xf);
constexpr int firmwareMessageId = ((deviceType & 0x1f) << 24) |
((manufacturer & 0xff) << 16) |
((firmwareApi & 0x3ff) << 6);
constexpr int firmwareMessageIdMask = 0x1fffffc0;

constexpr int modelApi =
0x300 | 155; // Parameter Access | Parameter Number (Device Model)
constexpr int modelMessageId = ((deviceType & 0x1f) << 24) |
((manufacturer & 0xff) << 16) |
((modelApi & 0x3ff) << 6);
constexpr int modelMessageIdMask = 0x1fffffc0;

constexpr int periodicApiClass = 6; // Periodic Status
constexpr int periodicApiClass = 46;
constexpr int periodicMessageId = ((deviceType & 0x1f) << 24) |
((manufacturer & 0xff) << 16) |
((periodicApiClass & 0x3f) << 10);
Expand All @@ -46,14 +42,12 @@ char *periodicBuffer;
int32_t halStatus;
uint32_t timeOffsetMillis;
uint32_t firmwareStreamHandle;
uint32_t modelStreamHandle;
uint32_t periodicStreamHandle;
uint32_t persistentMessageCount = 0;

uint32_t readCount = 0;
uint64_t devicesFound = 0;
uint64_t devicesFirmwareReceived = 0;
uint64_t devicesModelReceived = 0;
uint64_t devicesCANReady = 0;
HAL_CANHandle devicesCANHandles[64];

Expand All @@ -68,9 +62,6 @@ void URCLDriver_start(void) {
HAL_CAN_OpenStreamSession(&firmwareStreamHandle, firmwareMessageId,
firmwareMessageIdMask, maxPersistentMessages,
&halStatus);
HAL_CAN_OpenStreamSession(&modelStreamHandle, modelMessageId,
modelMessageIdMask, maxPersistentMessages,
&halStatus);
HAL_CAN_OpenStreamSession(&periodicStreamHandle, periodicMessageId,
periodicMessageIdMask, maxPeriodicMessages,
&halStatus);
Expand Down Expand Up @@ -132,22 +123,16 @@ void URCLDriver_read(void) {
if (readCount >= 20) {
readCount = 0;
uint64_t unknownFirmwareDevices = devicesFound & ~devicesFirmwareReceived;
uint64_t unknownModelDevices = devicesFound & ~devicesModelReceived;
for (uint8_t i = 0; i < 64; i++) {
bool unknownFirmware = (unknownFirmwareDevices >> i) & 1;
bool unknownModel = (unknownModelDevices >> i) & 1;
if ((unknownFirmware || unknownModel) &&
((devicesCANReady >> i) & 1) == 0) {
if (unknownFirmware && ((devicesCANReady >> i) & 1) == 0) {
devicesCANHandles[i] =
HAL_InitializeCAN(manufacturer, i, deviceType, &halStatus);
devicesCANReady |= (uint64_t)1 << i;
}
if (unknownFirmware) {
HAL_WriteCANRTRFrame(devicesCANHandles[i], 0, firmwareApi, &halStatus);
}
if (unknownModel) {
HAL_WriteCANRTRFrame(devicesCANHandles[i], 0, modelApi, &halStatus);
}
}
}

Expand All @@ -165,16 +150,6 @@ void URCLDriver_read(void) {
devicesFirmwareReceived |= (uint64_t)1 << deviceId;
}

// Read model messages
HAL_CAN_ReadStreamSession(modelStreamHandle, messages, maxPersistentMessages,
&messageCount, &halStatus);
for (uint32_t i = 0; i < messageCount; i++) {
writeMessagePersistent(messages[i]);
uint8_t deviceId = messages[i].messageID & 0x3f;
devicesFound |= (uint64_t)1 << deviceId;
devicesModelReceived |= (uint64_t)1 << deviceId;
}

// Read periodic messages
HAL_CAN_ReadStreamSession(periodicStreamHandle, messages, maxPeriodicMessages,
&messageCount, &halStatus);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/littletonrobotics/urcl/URCL.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public static void start(Map<Integer, String> aliases) {
// Start publishers
persistentPublisher = NetworkTableInstance.getDefault()
.getRawTopic("/URCL/Raw/Persistent")
.publish("URCLr2_persistent");
.publish("URCLr3_persistent");
periodicPublisher = NetworkTableInstance.getDefault()
.getRawTopic("/URCL/Raw/Periodic")
.publish("URCLr2_periodic");
.publish("URCLr3_periodic");
aliasesPublisher = NetworkTableInstance.getDefault()
.getRawTopic("/URCL/Raw/Aliases")
.publish("URCLr2_aliases");
.publish("URCLr3_aliases");
notifier = new Notifier(() -> {
var data = getData();
persistentPublisher.set(data[0]);
Expand Down Expand Up @@ -137,9 +137,9 @@ public static void start(Map<Integer, String> aliases, DataLog log) {
periodicBuffer.order(ByteOrder.LITTLE_ENDIAN);

persistentLogEntry = new RawLogEntry(log, "URCL/Raw/Persistent", "",
"URCLr2_persistent");
periodicLogEntry = new RawLogEntry(log, "/URCL/Raw/Periodic", "", "URCLr2_periodic");
aliasLogEntry = new RawLogEntry(log, "/URCL/Raw/Aliases", "", "URCLr2_aliases");
"URCLr3_persistent");
periodicLogEntry = new RawLogEntry(log, "/URCL/Raw/Periodic", "", "URCLr3_periodic");
aliasLogEntry = new RawLogEntry(log, "/URCL/Raw/Aliases", "", "URCLr3_aliases");
notifier = new Notifier(() -> {
var data = getData();
persistentLogEntry.update(data[0]);
Expand Down
12 changes: 6 additions & 6 deletions src/main/native/cpp/URCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ void URCL::Start(std::map<int, std::string_view> aliases) {
// Start publishers
persistentPublisher = nt::NetworkTableInstance::GetDefault()
.GetRawTopic("/URCL/Raw/Persistent")
.Publish("URCLr2_persistent");
.Publish("URCLr3_persistent");
periodicPublisher = nt::NetworkTableInstance::GetDefault()
.GetRawTopic("/URCL/Raw/Periodic")
.Publish("URCLr2_periodic");
.Publish("URCLr3_periodic");
aliasesPublisher = nt::NetworkTableInstance::GetDefault()
.GetRawTopic("/URCL/Raw/Aliases")
.Publish("URCLr2_aliases");
.Publish("URCLr3_aliases");

aliasesPublisher.Set(aliasesVector);

Expand Down Expand Up @@ -135,11 +135,11 @@ void URCL::Start(std::map<int, std::string_view> aliases,
periodicBuffer = URCLDriver_getPeriodicBuffer();

persistentLogEntry = wpi::log::RawLogEntry{log, "/URCL/Raw/Persistent", "",
"URCLr2_persistent"};
"URCLr3_persistent"};
periodicLogEntry =
wpi::log::RawLogEntry{log, "/URCL/Raw/Periodic", "", "URCLr2_periodic"};
wpi::log::RawLogEntry{log, "/URCL/Raw/Periodic", "", "URCLr3_periodic"};
aliasesLogEntry =
wpi::log::RawLogEntry{log, "/URCL/Raw/Aliases", "", "URCLr2_aliases"};
wpi::log::RawLogEntry{log, "/URCL/Raw/Aliases", "", "URCLr3_aliases"};

aliasesLogEntry.Append(aliasesVector);

Expand Down

0 comments on commit f340277

Please sign in to comment.