2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2017-09-07 21:40:30 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "hal/CAN.h"
|
2017-09-07 21:40:30 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "mockdata/CanDataInternal.h"
|
2017-11-22 19:48:32 -08:00
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
2020-12-28 01:19:59 -08:00
|
|
|
namespace hal::init {
|
2017-12-10 19:38:53 -08:00
|
|
|
void InitializeCAN() {}
|
2020-12-28 01:19:59 -08:00
|
|
|
} // namespace hal::init
|
2017-11-22 19:48:32 -08:00
|
|
|
|
2017-09-07 21:40:30 -07:00
|
|
|
extern "C" {
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
void HAL_CAN_SendMessage(int32_t busId, uint32_t messageId,
|
|
|
|
|
const struct HAL_CANMessage* message, int32_t periodMs,
|
|
|
|
|
int32_t* status) {
|
|
|
|
|
SimCanData->sendMessage(busId, messageId, message, periodMs, status);
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
void HAL_CAN_ReceiveMessage(int32_t busId, uint32_t messageId,
|
|
|
|
|
struct HAL_CANReceiveMessage* message,
|
|
|
|
|
int32_t* status) {
|
|
|
|
|
// Use a data size of 100 as call check. Difficult to add check to invoke
|
2019-11-25 21:45:44 -08:00
|
|
|
// handler
|
2025-02-25 19:07:01 -08:00
|
|
|
message->message.dataSize = 100;
|
2019-11-25 21:45:44 -08:00
|
|
|
auto tmpStatus = *status;
|
2025-02-25 19:07:01 -08:00
|
|
|
SimCanData->receiveMessage(busId, messageId, message, status);
|
2019-11-25 21:45:44 -08:00
|
|
|
// If no handler invoked, return message not found
|
2025-02-25 19:07:01 -08:00
|
|
|
if (message->message.dataSize == 100 && *status == tmpStatus) {
|
2019-11-25 21:45:44 -08:00
|
|
|
*status = HAL_ERR_CANSessionMux_MessageNotFound;
|
|
|
|
|
}
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
HAL_CANStreamHandle HAL_CAN_OpenStreamSession(int32_t busId, uint32_t messageId,
|
|
|
|
|
uint32_t messageIDMask,
|
|
|
|
|
uint32_t maxMessages,
|
|
|
|
|
int32_t* status) {
|
|
|
|
|
HAL_CANStreamHandle handle = 0;
|
|
|
|
|
SimCanData->openStreamSession(&handle, busId, messageId, messageIDMask,
|
2017-12-10 19:38:53 -08:00
|
|
|
maxMessages, status);
|
2025-02-25 19:07:01 -08:00
|
|
|
return handle;
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
void HAL_CAN_CloseStreamSession(HAL_CANStreamHandle sessionHandle) {
|
2018-09-03 16:08:07 -07:00
|
|
|
SimCanData->closeStreamSession(sessionHandle);
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
void HAL_CAN_ReadStreamSession(HAL_CANStreamHandle sessionHandle,
|
2017-09-07 21:40:30 -07:00
|
|
|
struct HAL_CANStreamMessage* messages,
|
|
|
|
|
uint32_t messagesToRead, uint32_t* messagesRead,
|
2017-11-22 19:48:32 -08:00
|
|
|
int32_t* status) {
|
2018-09-03 16:08:07 -07:00
|
|
|
SimCanData->readStreamSession(sessionHandle, messages, messagesToRead,
|
2017-12-10 19:38:53 -08:00
|
|
|
messagesRead, status);
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
void HAL_CAN_GetCANStatus(int32_t busId, float* percentBusUtilization,
|
|
|
|
|
uint32_t* busOffCount, uint32_t* txFullCount,
|
|
|
|
|
uint32_t* receiveErrorCount,
|
2017-11-22 19:48:32 -08:00
|
|
|
uint32_t* transmitErrorCount, int32_t* status) {
|
2025-02-25 19:07:01 -08:00
|
|
|
SimCanData->getCANStatus(busId, percentBusUtilization, busOffCount,
|
|
|
|
|
txFullCount, receiveErrorCount, transmitErrorCount,
|
|
|
|
|
status);
|
2017-11-22 19:48:32 -08:00
|
|
|
}
|
|
|
|
|
|
2017-10-16 19:56:08 -07:00
|
|
|
} // extern "C"
|