Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "hal/CAN.h" |
| 6 | |
| 7 | #include "mockdata/CanDataInternal.h" |
| 8 | |
| 9 | using namespace hal; |
| 10 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 11 | namespace hal::init { |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 12 | void InitializeCAN() {} |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 13 | } // namespace hal::init |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 14 | |
| 15 | extern "C" { |
| 16 | |
| 17 | void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data, |
| 18 | uint8_t dataSize, int32_t periodMs, int32_t* status) { |
| 19 | SimCanData->sendMessage(messageID, data, dataSize, periodMs, status); |
| 20 | } |
| 21 | void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask, |
| 22 | uint8_t* data, uint8_t* dataSize, |
| 23 | uint32_t* timeStamp, int32_t* status) { |
| 24 | // Use a data size of 42 as call check. Difficult to add check to invoke |
| 25 | // handler |
| 26 | *dataSize = 42; |
| 27 | auto tmpStatus = *status; |
| 28 | SimCanData->receiveMessage(messageID, messageIDMask, data, dataSize, |
| 29 | timeStamp, status); |
| 30 | // If no handler invoked, return message not found |
| 31 | if (*dataSize == 42 && *status == tmpStatus) { |
| 32 | *status = HAL_ERR_CANSessionMux_MessageNotFound; |
| 33 | } |
| 34 | } |
| 35 | void HAL_CAN_OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID, |
| 36 | uint32_t messageIDMask, uint32_t maxMessages, |
| 37 | int32_t* status) { |
| 38 | SimCanData->openStreamSession(sessionHandle, messageID, messageIDMask, |
| 39 | maxMessages, status); |
| 40 | } |
| 41 | void HAL_CAN_CloseStreamSession(uint32_t sessionHandle) { |
| 42 | SimCanData->closeStreamSession(sessionHandle); |
| 43 | } |
| 44 | void HAL_CAN_ReadStreamSession(uint32_t sessionHandle, |
| 45 | struct HAL_CANStreamMessage* messages, |
| 46 | uint32_t messagesToRead, uint32_t* messagesRead, |
| 47 | int32_t* status) { |
| 48 | SimCanData->readStreamSession(sessionHandle, messages, messagesToRead, |
| 49 | messagesRead, status); |
| 50 | } |
| 51 | void HAL_CAN_GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount, |
| 52 | uint32_t* txFullCount, uint32_t* receiveErrorCount, |
| 53 | uint32_t* transmitErrorCount, int32_t* status) { |
| 54 | SimCanData->getCANStatus(percentBusUtilization, busOffCount, txFullCount, |
| 55 | receiveErrorCount, transmitErrorCount, status); |
| 56 | } |
| 57 | |
| 58 | } // extern "C" |