mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Added callbacks for CAN (#757)
Added callback scheme for a pass through to something higher level. Since the ID is embedded into the arbitration ID, and some devices can use different schemes whether it is plugged in through a device or put into the daisy chain (pigeonImu), I made one "internal data object" for max reusability.
This commit is contained in:
committed by
Peter Johnson
parent
0431cf97ff
commit
12c4418bda
74
hal/src/main/native/include/MockData/CanData.h
Normal file
74
hal/src/main/native/include/MockData/CanData.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL_Value.h"
|
||||
#include "NotifyListener.h"
|
||||
|
||||
typedef void (*HAL_CAN_SendMessageCallback)(const char* name, void* param,
|
||||
uint32_t messageID,
|
||||
const uint8_t* data,
|
||||
uint8_t dataSize, int32_t periodMs,
|
||||
int32_t* status);
|
||||
|
||||
typedef void (*HAL_CAN_ReceiveMessageCallback)(
|
||||
const char* name, void* param, uint32_t* messageID, uint32_t messageIDMask,
|
||||
uint8_t* data, uint8_t* dataSize, uint32_t* timeStamp, int32_t* status);
|
||||
|
||||
typedef void (*HAL_CAN_OpenStreamSessionCallback)(
|
||||
const char* name, void* param, uint32_t* sessionHandle, uint32_t messageID,
|
||||
uint32_t messageIDMask, uint32_t maxMessages, int32_t* status);
|
||||
|
||||
typedef void (*HAL_CAN_CloseStreamSessionCallback)(const char* name,
|
||||
void* param,
|
||||
uint32_t sessionHandle);
|
||||
|
||||
typedef void (*HAL_CAN_ReadStreamSessionCallback)(
|
||||
const char* name, void* param, uint32_t sessionHandle,
|
||||
struct HAL_CANStreamMessage* messages, uint32_t messagesToRead,
|
||||
uint32_t* messagesRead, int32_t* status);
|
||||
|
||||
typedef void (*HAL_CAN_GetCANStatusCallback)(
|
||||
const char* name, void* param, float* percentBusUtilization,
|
||||
uint32_t* busOffCount, uint32_t* txFullCount, uint32_t* receiveErrorCount,
|
||||
uint32_t* transmitErrorCount, int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HALSIM_ResetCanData();
|
||||
|
||||
int32_t HALSIM_RegisterCanSendMessageCallback(
|
||||
HAL_CAN_SendMessageCallback callback, void* param);
|
||||
void HALSIM_CancelCanSendMessageCallback(int32_t uid);
|
||||
|
||||
int32_t HALSIM_RegisterCanReceiveMessageCallback(
|
||||
HAL_CAN_ReceiveMessageCallback callback, void* param);
|
||||
void HALSIM_CancelCanReceiveMessageCallback(int32_t uid);
|
||||
|
||||
int32_t HALSIM_RegisterCanOpenStreamCallback(
|
||||
HAL_CAN_OpenStreamSessionCallback callback, void* param);
|
||||
void HALSIM_CancelCanOpenStreamCallback(int32_t uid);
|
||||
|
||||
int32_t HALSIM_RegisterCanCloseStreamCallback(
|
||||
HAL_CAN_CloseStreamSessionCallback callback, void* param);
|
||||
void HALSIM_CancelCanCloseStreamCallback(int32_t uid);
|
||||
|
||||
int32_t HALSIM_RegisterCanReadStreamCallback(
|
||||
HAL_CAN_ReadStreamSessionCallback callback, void* param);
|
||||
void HALSIM_CancelCanReadStreamCallback(int32_t uid);
|
||||
|
||||
int32_t HALSIM_RegisterCanGetCANStatusCallback(
|
||||
HAL_CAN_GetCANStatusCallback callback, void* param);
|
||||
void HALSIM_CancelCanGetCANStatusCallback(int32_t uid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -11,6 +11,29 @@
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
template <typename VectorType, typename CallbackType>
|
||||
std::shared_ptr<VectorType> RegisterCallbackImpl(
|
||||
std::shared_ptr<VectorType> currentVector, const char* name,
|
||||
CallbackType callback, void* param, int32_t* newUid) {
|
||||
std::shared_ptr<VectorType> newCallbacks;
|
||||
if (currentVector == nullptr) {
|
||||
newCallbacks = std::make_shared<VectorType>(
|
||||
param, callback, reinterpret_cast<unsigned int*>(newUid));
|
||||
} else {
|
||||
newCallbacks = currentVector->emplace_back(
|
||||
param, callback, reinterpret_cast<unsigned int*>(newUid));
|
||||
}
|
||||
return newCallbacks;
|
||||
}
|
||||
|
||||
template <typename VectorType, typename CallbackType>
|
||||
std::shared_ptr<VectorType> CancelCallbackImpl(
|
||||
std::shared_ptr<VectorType> currentVector, int32_t uid) {
|
||||
// Create a copy of the callbacks to erase from
|
||||
auto newCallbacks = currentVector->erase(uid);
|
||||
return newCallbacks;
|
||||
}
|
||||
|
||||
std::shared_ptr<hal::NotifyListenerVector> RegisterCallback(
|
||||
std::shared_ptr<hal::NotifyListenerVector> currentVector, const char* name,
|
||||
HAL_NotifyCallback callback, void* param, int32_t* newUid);
|
||||
|
||||
Reference in New Issue
Block a user