[hal] Add CAN Bus Map (#8765)

We will want a better API for higher level devices that expect to be on
motioncore, but for ones that are not expected to be, it'll be really
nice to have an API that can let us map the motioncore can bus to its
HAL index.
This commit is contained in:
Thad House
2026-04-16 21:03:39 -07:00
committed by GitHub
parent 628ba1458f
commit 8c80cdcf28
3 changed files with 84 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package org.wpilib.hardware.hal;
public final class CANBusMap {
public static final int CAN_S0 = 0;
public static final int CAN_S1 = 1;
public static final int CAN_S2 = 2;
public static final int CAN_S3 = 3;
public static final int CAN_S4 = 4;
public static final int CAN_D0 = 5;
public static final int CAN_D1 = 6;
public static final int CAN_D2 = 7;
public static final int CAN_D3 = 8;
public static final int CAN_D4 = 9;
public static final int CAN_D5 = 10;
public static final int CAN_D6 = 11;
public static final int CAN_D7 = 12;
public static final int CAN_D8 = 13;
public static final int CAN_D9 = 14;
public static final int CAN_D10 = 15;
public static final int CAN_D11 = 16;
public static final int CAN_D12 = 17;
public static final int CAN_D13 = 18;
public static final int CAN_D14 = 19;
public static final int CAN_D15 = 20;
public static final int CAN_D16 = 21;
public static final int CAN_D17 = 22;
public static final int CAN_D18 = 23;
public static final int CAN_D19 = 24;
private CANBusMap() {
throw new UnsupportedOperationException("This is a utility class!");
}
}

View File

@@ -0,0 +1,45 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <stdint.h>
#include "wpi/hal/Types.h"
/**
* @defgroup hal_canapi CAN BUS Mapping Enums
* @ingroup hal_capi
* @{
*/
HAL_ENUM(HAL_CANBusMap) {
HAL_CAN_BUS_S0 = 0,
HAL_CAN_BUS_S1 = 1,
HAL_CAN_BUS_S2 = 2,
HAL_CAN_BUS_S3 = 3,
HAL_CAN_BUS_S4 = 4,
HAL_CAN_BUS_D0 = 5,
HAL_CAN_BUS_D1 = 6,
HAL_CAN_BUS_D2 = 7,
HAL_CAN_BUS_D3 = 8,
HAL_CAN_BUS_D4 = 9,
HAL_CAN_BUS_D5 = 10,
HAL_CAN_BUS_D6 = 11,
HAL_CAN_BUS_D7 = 12,
HAL_CAN_BUS_D8 = 13,
HAL_CAN_BUS_D9 = 14,
HAL_CAN_BUS_D10 = 15,
HAL_CAN_BUS_D11 = 16,
HAL_CAN_BUS_D12 = 17,
HAL_CAN_BUS_D13 = 18,
HAL_CAN_BUS_D14 = 19,
HAL_CAN_BUS_D15 = 20,
HAL_CAN_BUS_D16 = 21,
HAL_CAN_BUS_D17 = 22,
HAL_CAN_BUS_D18 = 23,
HAL_CAN_BUS_D19 = 24,
};
/** @} */

View File

@@ -8,6 +8,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wpi/hal/CANAPI.h" #include "wpi/hal/CANAPI.h"
#include "wpi/hal/CANBusMap.h"
#include "wpi/hal/simulation/CanData.h" #include "wpi/hal/simulation/CanData.h"
namespace wpi::hal { namespace wpi::hal {
@@ -44,7 +45,7 @@ struct CANSendCallbackStore {
TEST(CANTest, CanIdPacking) { TEST(CANTest, CanIdPacking) {
int32_t status = 0; int32_t status = 0;
int32_t deviceId = 12; int32_t deviceId = 12;
CANTestStore testStore(0, deviceId, &status); CANTestStore testStore(HAL_CAN_BUS_S0, deviceId, &status);
ASSERT_EQ(0, status); ASSERT_EQ(0, status);
std::pair<int32_t, bool> storePair; std::pair<int32_t, bool> storePair;