Change hal sim to use spinlocks (#1291)

This makes callback registration completely thread safe.

This patch also uses templates and macros to dramatically reduce the amount of
manual boilerplate.
This commit is contained in:
Peter Johnson
2018-09-03 16:08:07 -07:00
committed by GitHub
parent 67b1c85315
commit c0ff6198b3
65 changed files with 1305 additions and 7639 deletions

View File

@@ -1,71 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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
#ifndef __FRC_ROBORIO__
#include <memory>
#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);
std::shared_ptr<hal::NotifyListenerVector> CancelCallback(
std::shared_ptr<hal::NotifyListenerVector> currentVector, int32_t uid);
void InvokeCallback(std::shared_ptr<hal::NotifyListenerVector> currentVector,
const char* name, const HAL_Value* value);
std::shared_ptr<hal::BufferListenerVector> RegisterCallback(
std::shared_ptr<hal::BufferListenerVector> currentVector, const char* name,
HAL_BufferCallback callback, void* param, int32_t* newUid);
std::shared_ptr<hal::BufferListenerVector> CancelCallback(
std::shared_ptr<hal::BufferListenerVector> currentVector, int32_t uid);
void InvokeCallback(std::shared_ptr<hal::BufferListenerVector> currentVector,
const char* name, uint8_t* buffer, int32_t count);
std::shared_ptr<hal::ConstBufferListenerVector> RegisterCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
const char* name, HAL_ConstBufferCallback callback, void* param,
int32_t* newUid);
std::shared_ptr<hal::ConstBufferListenerVector> CancelCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector, int32_t uid);
void InvokeCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
const char* name, const uint8_t* buffer, int32_t count);
#endif

View File

@@ -1,142 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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
#ifndef __FRC_ROBORIO__
#include <memory>
#include <wpi/SmallVector.h>
#include "NotifyListener.h"
namespace hal {
// Vector which provides an integrated freelist for removal and reuse of
// individual elements.
template <typename ListenerType>
class HalCallbackListenerVectorImpl {
struct private_init {};
public:
typedef typename wpi::SmallVectorImpl<
HalCallbackListener<ListenerType>>::size_type size_type;
// Constructor for creating copies of the vector
HalCallbackListenerVectorImpl(const HalCallbackListenerVectorImpl* copyFrom,
const private_init&);
// Delete all default constructors so they cannot be used
HalCallbackListenerVectorImpl& operator=(
const HalCallbackListenerVectorImpl&) = delete;
HalCallbackListenerVectorImpl() = delete;
HalCallbackListenerVectorImpl(const HalCallbackListenerVectorImpl&) = delete;
// Create a new vector with a single callback inside of it
HalCallbackListenerVectorImpl(void* param, ListenerType callback,
unsigned int* newUid) {
*newUid = emplace_back_impl(param, callback);
}
size_type size() const { return m_vector.size(); }
HalCallbackListener<ListenerType>& operator[](size_type i) {
return m_vector[i];
}
const HalCallbackListener<ListenerType>& operator[](size_type i) const {
return m_vector[i];
}
// Add a new NotifyListener to a copy of the vector. If there are elements on
// the freelist,
// reuses the last one; otherwise adds to the end of the vector.
// Returns the resulting element index (+1).
std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>> emplace_back(
void* param, ListenerType callback, unsigned int* newUid);
// Removes the identified element by replacing it with a default-constructed
// one. The element is added to the freelist for later reuse. Returns a copy
std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>> erase(
unsigned int uid);
private:
wpi::SmallVector<HalCallbackListener<ListenerType>, 4> m_vector;
wpi::SmallVector<unsigned int, 4> m_free;
// Add a new NotifyListener to the vector. If there are elements on the
// freelist,
// reuses the last one; otherwise adds to the end of the vector.
// Returns the resulting element index (+1).
unsigned int emplace_back_impl(void* param, ListenerType callback);
// Removes the identified element by replacing it with a default-constructed
// one. The element is added to the freelist for later reuse.
void erase_impl(unsigned int uid);
};
template <typename ListenerType>
HalCallbackListenerVectorImpl<ListenerType>::HalCallbackListenerVectorImpl(
const HalCallbackListenerVectorImpl<ListenerType>* copyFrom,
const private_init&)
: m_vector(copyFrom->m_vector), m_free(copyFrom->m_free) {}
template <typename ListenerType>
std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>>
HalCallbackListenerVectorImpl<ListenerType>::emplace_back(
void* param, ListenerType callback, unsigned int* newUid) {
auto newVector =
std::make_shared<HalCallbackListenerVectorImpl<ListenerType>>(
this, private_init());
newVector->m_vector = m_vector;
newVector->m_free = m_free;
*newUid = newVector->emplace_back_impl(param, callback);
return newVector;
}
template <typename ListenerType>
std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>>
HalCallbackListenerVectorImpl<ListenerType>::erase(unsigned int uid) {
auto newVector =
std::make_shared<HalCallbackListenerVectorImpl<ListenerType>>(
this, private_init());
newVector->m_vector = m_vector;
newVector->m_free = m_free;
newVector->erase_impl(uid);
return newVector;
}
template <typename ListenerType>
unsigned int HalCallbackListenerVectorImpl<ListenerType>::emplace_back_impl(
void* param, ListenerType callback) {
unsigned int uid;
if (m_free.empty()) {
uid = m_vector.size();
m_vector.emplace_back(param, callback);
} else {
uid = m_free.back();
m_free.pop_back();
m_vector[uid] = HalCallbackListener<ListenerType>(param, callback);
}
return uid + 1;
}
template <typename ListenerType>
void HalCallbackListenerVectorImpl<ListenerType>::erase_impl(unsigned int uid) {
--uid;
if (uid >= m_vector.size() || !m_vector[uid]) return;
m_free.push_back(uid);
m_vector[uid] = HalCallbackListener<ListenerType>();
}
typedef HalCallbackListenerVectorImpl<HAL_NotifyCallback> NotifyListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_BufferCallback> BufferListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_ConstBufferCallback>
ConstBufferListenerVector;
} // namespace hal
#endif

View File

@@ -0,0 +1,151 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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 <memory>
#include <utility>
#include <wpi/Compiler.h>
#include <wpi/UidVector.h>
#include <wpi/spinlock.h>
#include "mockdata/NotifyListener.h"
namespace hal {
namespace impl {
class SimCallbackRegistryBase {
public:
using RawFunctor = void (*)();
protected:
using CallbackVector = wpi::UidVector<HalCallbackListener<RawFunctor>, 4>;
public:
void Cancel(int32_t uid) {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
if (m_callbacks) m_callbacks->erase(uid - 1);
}
void Reset() {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
DoReset();
}
wpi::recursive_spinlock& GetMutex() { return m_mutex; }
protected:
int32_t DoRegister(RawFunctor callback, void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
if (!m_callbacks) m_callbacks = std::make_unique<CallbackVector>();
return m_callbacks->emplace_back(param, callback) + 1;
}
LLVM_ATTRIBUTE_ALWAYS_INLINE void DoReset() {
if (m_callbacks) m_callbacks->clear();
}
mutable wpi::recursive_spinlock m_mutex;
std::unique_ptr<CallbackVector> m_callbacks;
};
} // namespace impl
/**
* Simulation callback registry. Provides callback functionality.
*
* @tparam CallbackFunction callback function type (e.g. HAL_BufferCallback)
* @tparam GetName function that returns a const char* for the name
*/
template <typename CallbackFunction, const char* (*GetName)()>
class SimCallbackRegistry : public impl::SimCallbackRegistryBase {
public:
int32_t Register(CallbackFunction callback, void* param) {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
return DoRegister(reinterpret_cast<RawFunctor>(callback), param);
}
template <typename... U>
void Invoke(U&&... u) const {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
if (m_callbacks) {
const char* name = GetName();
for (auto&& cb : *m_callbacks)
reinterpret_cast<CallbackFunction>(cb.callback)(name, cb.param,
std::forward<U>(u)...);
}
}
template <typename... U>
LLVM_ATTRIBUTE_ALWAYS_INLINE void operator()(U&&... u) const {
return Invoke(std::forward<U>(u)...);
}
};
/**
* Define a name functor for use with SimCallbackRegistry.
* This creates a function named GetNAMEName() that returns "NAME".
* @param NAME the name to return
*/
#define HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(NAME) \
static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr const char* \
Get##NAME##Name() { \
return #NAME; \
}
/**
* Define a standard C API for SimCallbackRegistry.
*
* Functions defined:
* - int32 NS_RegisterCAPINAMECallback(
* int32_t index, TYPE callback, void* param)
* - void NS_CancelCAPINAMECallback(int32_t index, int32_t uid)
*
* @param TYPE the underlying callback type (e.g. HAL_BufferCallback)
* @param NS the "namespace" (e.g. HALSIM)
* @param CAPINAME the C API name (usually first letter capitalized)
* @param DATA the backing data array
* @param LOWERNAME the lowercase name of the backing data registry
*/
#define HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, \
LOWERNAME) \
int32_t NS##_Register##CAPINAME##Callback(int32_t index, TYPE callback, \
void* param) { \
return DATA[index].LOWERNAME.Register(callback, param); \
} \
\
void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \
DATA[index].LOWERNAME.Cancel(uid); \
}
/**
* Define a standard C API for SimCallbackRegistry (no index variant).
*
* Functions defined:
* - int32 NS_RegisterCAPINAMECallback(TYPE callback, void* param)
* - void NS_CancelCAPINAMECallback(int32_t uid)
*
* @param TYPE the underlying callback type (e.g. HAL_BufferCallback)
* @param NS the "namespace" (e.g. HALSIM)
* @param CAPINAME the C API name (usually first letter capitalized)
* @param DATA the backing data pointer
* @param LOWERNAME the lowercase name of the backing data registry
*/
#define HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI_NOINDEX(TYPE, NS, CAPINAME, DATA, \
LOWERNAME) \
int32_t NS##_Register##CAPINAME##Callback(TYPE callback, void* param) { \
return DATA->LOWERNAME.Register(callback, param); \
} \
\
void NS##_Cancel##CAPINAME##Callback(int32_t uid) { \
DATA->LOWERNAME.Cancel(uid); \
}
} // namespace hal

View File

@@ -0,0 +1,227 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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 <memory>
#include <wpi/Compiler.h>
#include <wpi/UidVector.h>
#include <wpi/spinlock.h>
#include "mockdata/NotifyListener.h"
#include "mockdata/SimCallbackRegistry.h"
namespace hal {
namespace impl {
template <typename T, HAL_Value (*MakeValue)(T)>
class SimDataValueBase : protected SimCallbackRegistryBase {
public:
explicit SimDataValueBase(T value) : m_value(value) {}
LLVM_ATTRIBUTE_ALWAYS_INLINE void CancelCallback(int32_t uid) { Cancel(uid); }
T Get() const {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
return m_value;
}
LLVM_ATTRIBUTE_ALWAYS_INLINE operator T() const { return Get(); }
void Reset(T value) {
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
DoReset();
m_value = value;
}
wpi::recursive_spinlock& GetMutex() { return m_mutex; }
protected:
int32_t DoRegisterCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify, const char* name) {
std::unique_lock<wpi::recursive_spinlock> lock(m_mutex);
int32_t newUid = DoRegister(reinterpret_cast<RawFunctor>(callback), param);
if (newUid == -1) return -1;
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeValue(m_value);
lock.unlock();
callback(name, param, &value);
}
return newUid + 1;
}
void DoSet(T value, const char* name) {
std::lock_guard<wpi::recursive_spinlock> lock(this->m_mutex);
if (m_value != value) {
m_value = value;
if (m_callbacks) {
HAL_Value halValue = MakeValue(value);
for (auto&& cb : *m_callbacks)
reinterpret_cast<HAL_NotifyCallback>(cb.callback)(name, cb.param,
&halValue);
}
}
}
T m_value;
};
} // namespace impl
/**
* Simulation data value wrapper. Provides callback functionality when the
* data value is changed.
*
* @tparam T value type (e.g. double)
* @tparam MakeValue function that takes a T and returns a HAL_Value
* @tparam GetName function that returns a const char* for the name
* @tparam GetDefault function that returns the default T (used only for
* default constructor)
*/
template <typename T, HAL_Value (*MakeValue)(T), const char* (*GetName)(),
T (*GetDefault)() = nullptr>
class SimDataValue final : public impl::SimDataValueBase<T, MakeValue> {
public:
SimDataValue()
: impl::SimDataValueBase<T, MakeValue>(
GetDefault != nullptr ? GetDefault() : T()) {}
explicit SimDataValue(T value)
: impl::SimDataValueBase<T, MakeValue>(value) {}
LLVM_ATTRIBUTE_ALWAYS_INLINE int32_t RegisterCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return this->DoRegisterCallback(callback, param, initialNotify, GetName());
}
LLVM_ATTRIBUTE_ALWAYS_INLINE void Set(T value) {
this->DoSet(value, GetName());
}
LLVM_ATTRIBUTE_ALWAYS_INLINE SimDataValue& operator=(T value) {
Set(value);
return *this;
}
};
/**
* Define a name functor for use with SimDataValue.
* This creates a function named GetNAMEName() that returns "NAME".
* @param NAME the name to return
*/
#define HAL_SIMDATAVALUE_DEFINE_NAME(NAME) \
static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr const char* \
Get##NAME##Name() { \
return #NAME; \
}
/**
* Define a standard C API for simulation data.
*
* Functions defined:
* - int32 NS_RegisterCAPINAMECallback(
* int32_t index, HAL_NotifyCallback callback, void* param,
* HAL_Bool initialNotify)
* - void NS_CancelCAPINAMECallback(int32_t index, int32_t uid)
* - TYPE NS_GetCAPINAME(int32_t index)
* - void NS_SetCAPINAME(int32_t index, TYPE value)
*
* @param TYPE the underlying value type (e.g. double)
* @param NS the "namespace" (e.g. HALSIM)
* @param CAPINAME the C API name (usually first letter capitalized)
* @param DATA the backing data array
* @param LOWERNAME the lowercase name of the backing data variable
*/
#define HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, LOWERNAME) \
int32_t NS##_Register##CAPINAME##Callback( \
int32_t index, HAL_NotifyCallback callback, void* param, \
HAL_Bool initialNotify) { \
return DATA[index].LOWERNAME.RegisterCallback(callback, param, \
initialNotify); \
} \
\
void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \
DATA[index].LOWERNAME.CancelCallback(uid); \
} \
\
TYPE NS##_Get##CAPINAME(int32_t index) { return DATA[index].LOWERNAME; } \
\
void NS##_Set##CAPINAME(int32_t index, TYPE LOWERNAME) { \
DATA[index].LOWERNAME = LOWERNAME; \
}
/**
* Define a standard C API for simulation data (channel variant).
*
* Functions defined:
* - int32 NS_RegisterCAPINAMECallback(
* int32_t index, int32_t channel, HAL_NotifyCallback callback,
* void* param, HAL_Bool initialNotify)
* - void NS_CancelCAPINAMECallback(int32_t index, int32_t channel, int32_t uid)
* - TYPE NS_GetCAPINAME(int32_t index, int32_t channel)
* - void NS_SetCAPINAME(int32_t index, int32_t channel, TYPE value)
*
* @param TYPE the underlying value type (e.g. double)
* @param NS the "namespace" (e.g. HALSIM)
* @param CAPINAME the C API name (usually first letter capitalized)
* @param DATA the backing data array
* @param LOWERNAME the lowercase name of the backing data variable array
*/
#define HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(TYPE, NS, CAPINAME, DATA, \
LOWERNAME) \
int32_t NS##_Register##CAPINAME##Callback( \
int32_t index, int32_t channel, HAL_NotifyCallback callback, \
void* param, HAL_Bool initialNotify) { \
return DATA[index].LOWERNAME[channel].RegisterCallback(callback, param, \
initialNotify); \
} \
\
void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t channel, \
int32_t uid) { \
DATA[index].LOWERNAME[channel].CancelCallback(uid); \
} \
\
TYPE NS##_Get##CAPINAME(int32_t index, int32_t channel) { \
return DATA[index].LOWERNAME[channel]; \
} \
\
void NS##_Set##CAPINAME(int32_t index, int32_t channel, TYPE LOWERNAME) { \
DATA[index].LOWERNAME[channel] = LOWERNAME; \
}
/**
* Define a standard C API for simulation data (no index variant).
*
* Functions defined:
* - int32 NS_RegisterCAPINAMECallback(
* HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify)
* - void NS_CancelCAPINAMECallback(int32_t uid)
* - TYPE NS_GetCAPINAME(void)
* - void NS_SetCAPINAME(TYPE value)
*
* @param TYPE the underlying value type (e.g. double)
* @param NS the "namespace" (e.g. HALSIM)
* @param CAPINAME the C API name (usually first letter capitalized)
* @param DATA the backing data pointer
* @param LOWERNAME the lowercase name of the backing data variable
*/
#define HAL_SIMDATAVALUE_DEFINE_CAPI_NOINDEX(TYPE, NS, CAPINAME, DATA, \
LOWERNAME) \
int32_t NS##_Register##CAPINAME##Callback( \
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) { \
return DATA->LOWERNAME.RegisterCallback(callback, param, initialNotify); \
} \
\
void NS##_Cancel##CAPINAME##Callback(int32_t uid) { \
DATA->LOWERNAME.CancelCallback(uid); \
} \
\
TYPE NS##_Get##CAPINAME(void) { return DATA->LOWERNAME; } \
\
void NS##_Set##CAPINAME(TYPE LOWERNAME) { DATA->LOWERNAME = LOWERNAME; }
} // namespace hal

View File

@@ -19,13 +19,13 @@ void InitializeAccelerometer() {}
extern "C" {
void HAL_SetAccelerometerActive(HAL_Bool active) {
SimAccelerometerData[0].SetActive(active);
SimAccelerometerData[0].active = active;
}
void HAL_SetAccelerometerRange(HAL_AccelerometerRange range) {
SimAccelerometerData[0].SetRange(range);
SimAccelerometerData[0].range = range;
}
double HAL_GetAccelerometerX(void) { return SimAccelerometerData[0].GetX(); }
double HAL_GetAccelerometerY(void) { return SimAccelerometerData[0].GetY(); }
double HAL_GetAccelerometerZ(void) { return SimAccelerometerData[0].GetZ(); }
double HAL_GetAccelerometerX(void) { return SimAccelerometerData[0].x; }
double HAL_GetAccelerometerY(void) { return SimAccelerometerData[0].y; }
double HAL_GetAccelerometerZ(void) { return SimAccelerometerData[0].z; }
} // extern "C"

View File

@@ -44,7 +44,7 @@ void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetAccumulatorInitialized(true);
SimAnalogInData[port->channel].accumulatorInitialized = true;
}
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -54,9 +54,9 @@ void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetAccumulatorCenter(0);
SimAnalogInData[port->channel].SetAccumulatorCount(0);
SimAnalogInData[port->channel].SetAccumulatorValue(0);
SimAnalogInData[port->channel].accumulatorCenter = 0;
SimAnalogInData[port->channel].accumulatorCount = 0;
SimAnalogInData[port->channel].accumulatorValue = 0;
}
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status) {
@@ -66,7 +66,7 @@ void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetAccumulatorCenter(center);
SimAnalogInData[port->channel].accumulatorCenter = center;
}
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status) {
@@ -76,7 +76,7 @@ void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetAccumulatorDeadband(deadband);
SimAnalogInData[port->channel].accumulatorDeadband = deadband;
}
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -86,7 +86,7 @@ int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
return 0;
}
return SimAnalogInData[port->channel].GetAccumulatorValue();
return SimAnalogInData[port->channel].accumulatorValue;
}
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -96,7 +96,7 @@ int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
return 0;
}
return SimAnalogInData[port->channel].GetAccumulatorCount();
return SimAnalogInData[port->channel].accumulatorCount;
}
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status) {
@@ -106,7 +106,7 @@ void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
return;
}
*count = SimAnalogInData[port->channel].GetAccumulatorCount();
*value = SimAnalogInData[port->channel].GetAccumulatorValue();
*count = SimAnalogInData[port->channel].accumulatorCount;
*value = SimAnalogInData[port->channel].accumulatorValue;
}
} // extern "C"

View File

@@ -69,7 +69,7 @@ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
gyro->handle = analogHandle;
gyro->index = channel;
SimAnalogGyroData[channel].SetInitialized(true);
SimAnalogGyroData[channel].initialized = true;
return handle;
}
@@ -82,7 +82,7 @@ void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
auto gyro = analogGyroHandles->Get(handle);
analogGyroHandles->Free(handle);
if (gyro == nullptr) return;
SimAnalogGyroData[gyro->index].SetInitialized(false);
SimAnalogGyroData[gyro->index].initialized = false;
}
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
@@ -104,7 +104,7 @@ void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
return;
}
SimAnalogGyroData[gyro->index].SetAngle(0.0);
SimAnalogGyroData[gyro->index].angle = 0.0;
}
void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
@@ -124,7 +124,7 @@ double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
return 0;
}
return SimAnalogGyroData[gyro->index].GetAngle();
return SimAnalogGyroData[gyro->index].angle;
}
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
@@ -134,7 +134,7 @@ double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
return 0;
}
return SimAnalogGyroData[gyro->index].GetRate();
return SimAnalogGyroData[gyro->index].rate;
}
double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {

View File

@@ -50,8 +50,8 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
analog_port->isAccumulator = false;
}
SimAnalogInData[channel].SetInitialized(true);
SimAnalogInData[channel].SetAccumulatorInitialized(false);
SimAnalogInData[channel].initialized = true;
SimAnalogInData[channel].accumulatorInitialized = false;
return handle;
}
@@ -60,8 +60,8 @@ void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
// no status, so no need to check for a proper free.
analogInputHandles->Free(analogPortHandle);
if (port == nullptr) return;
SimAnalogInData[port->channel].SetInitialized(false);
SimAnalogInData[port->channel].SetAccumulatorInitialized(false);
SimAnalogInData[port->channel].initialized = false;
SimAnalogInData[port->channel].accumulatorInitialized = false;
}
HAL_Bool HAL_CheckAnalogModule(int32_t module) { return module == 1; }
@@ -82,7 +82,7 @@ void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetAverageBits(bits);
SimAnalogInData[port->channel].averageBits = bits;
}
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -92,7 +92,7 @@ int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
return 0;
}
return SimAnalogInData[port->channel].GetAverageBits();
return SimAnalogInData[port->channel].averageBits;
}
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status) {
@@ -102,7 +102,7 @@ void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
return;
}
SimAnalogInData[port->channel].SetOversampleBits(bits);
SimAnalogInData[port->channel].oversampleBits = bits;
}
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -112,7 +112,7 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
return 0;
}
return SimAnalogInData[port->channel].GetOversampleBits();
return SimAnalogInData[port->channel].oversampleBits;
}
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -122,7 +122,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
return 0;
}
double voltage = SimAnalogInData[port->channel].GetVoltage();
double voltage = SimAnalogInData[port->channel].voltage;
return HAL_GetAnalogVoltsToValue(analogPortHandle, voltage, status);
}
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
@@ -154,7 +154,7 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
return 0.0;
}
return SimAnalogInData[port->channel].GetVoltage();
return SimAnalogInData[port->channel].voltage;
}
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
@@ -165,8 +165,7 @@ double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
}
// No averaging supported
double voltage = SimAnalogInData[port->channel].GetVoltage();
return voltage;
return SimAnalogInData[port->channel].voltage;
}
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {

View File

@@ -62,7 +62,7 @@ HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
port->channel = static_cast<uint8_t>(channel);
// Initialize sim analog input
SimAnalogOutData[channel].SetInitialized(true);
SimAnalogOutData[channel].initialized = true;
return handle;
}
@@ -71,7 +71,7 @@ void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
auto port = analogOutputHandles->Get(analogOutputHandle);
if (port == nullptr) return;
analogOutputHandles->Free(analogOutputHandle);
SimAnalogOutData[port->channel].SetInitialized(false);
SimAnalogOutData[port->channel].initialized = false;
}
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
@@ -86,7 +86,7 @@ void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
return;
}
SimAnalogOutData[port->channel].SetVoltage(voltage);
SimAnalogOutData[port->channel].voltage = voltage;
}
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
@@ -97,6 +97,6 @@ double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
return 0.0;
}
return SimAnalogOutData[port->channel].GetVoltage();
return SimAnalogOutData[port->channel].voltage;
}
} // extern "C"

View File

@@ -85,7 +85,7 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
*index = trigger->index;
SimAnalogTriggerData[trigger->index].SetInitialized(true);
SimAnalogTriggerData[trigger->index].initialized = true;
trigger->trigState = false;
@@ -97,7 +97,7 @@ void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
analogTriggerHandles->Free(analogTriggerHandle);
if (trigger == nullptr) return;
SimAnalogTriggerData[trigger->index].SetInitialized(false);
SimAnalogTriggerData[trigger->index].initialized = false;
// caller owns the analog input handle.
}
@@ -130,8 +130,8 @@ void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
GetAnalogValueToVoltage(trigger->analogHandle, upper, status);
if (status != 0) return;
SimAnalogTriggerData[trigger->index].SetTriggerUpperBound(trigUpper);
SimAnalogTriggerData[trigger->index].SetTriggerLowerBound(trigLower);
SimAnalogTriggerData[trigger->index].triggerUpperBound = trigUpper;
SimAnalogTriggerData[trigger->index].triggerLowerBound = trigLower;
}
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
@@ -145,8 +145,8 @@ void HAL_SetAnalogTriggerLimitsVoltage(
*status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR;
}
SimAnalogTriggerData[trigger->index].SetTriggerUpperBound(upper);
SimAnalogTriggerData[trigger->index].SetTriggerLowerBound(lower);
SimAnalogTriggerData[trigger->index].triggerUpperBound = upper;
SimAnalogTriggerData[trigger->index].triggerLowerBound = lower;
}
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useAveragedValue, int32_t* status) {
@@ -158,14 +158,14 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index];
if (triggerData->GetTriggerMode() == HALSIM_AnalogTriggerFiltered) {
if (triggerData->triggerMode.Get() == HALSIM_AnalogTriggerFiltered) {
*status = INCOMPATIBLE_STATE;
return;
}
auto setVal = useAveragedValue ? HALSIM_AnalogTriggerAveraged
: HALSIM_AnalogTriggerUnassigned;
triggerData->SetTriggerMode(setVal);
triggerData->triggerMode = setVal;
}
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useFilteredValue, int32_t* status) {
@@ -177,14 +177,14 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index];
if (triggerData->GetTriggerMode() == HALSIM_AnalogTriggerAveraged) {
if (triggerData->triggerMode.Get() == HALSIM_AnalogTriggerAveraged) {
*status = INCOMPATIBLE_STATE;
return;
}
auto setVal = useFilteredValue ? HALSIM_AnalogTriggerAveraged
: HALSIM_AnalogTriggerUnassigned;
triggerData->SetTriggerMode(setVal);
triggerData->triggerMode = setVal;
}
static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) {
@@ -195,7 +195,7 @@ static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) {
return 0.0;
}
return SimAnalogInData[analogIn->channel].GetVoltage();
return SimAnalogInData[analogIn->channel].voltage;
}
HAL_Bool HAL_GetAnalogTriggerInWindow(
@@ -213,8 +213,8 @@ HAL_Bool HAL_GetAnalogTriggerInWindow(
return false;
}
auto trigUpper = SimAnalogTriggerData[trigger->index].GetTriggerUpperBound();
auto trigLower = SimAnalogTriggerData[trigger->index].GetTriggerLowerBound();
double trigUpper = SimAnalogTriggerData[trigger->index].triggerUpperBound;
double trigLower = SimAnalogTriggerData[trigger->index].triggerLowerBound;
return voltage >= trigLower && voltage <= trigUpper;
}
@@ -233,8 +233,8 @@ HAL_Bool HAL_GetAnalogTriggerTriggerState(
return false;
}
auto trigUpper = SimAnalogTriggerData[trigger->index].GetTriggerUpperBound();
auto trigLower = SimAnalogTriggerData[trigger->index].GetTriggerLowerBound();
double trigUpper = SimAnalogTriggerData[trigger->index].triggerUpperBound;
double trigLower = SimAnalogTriggerData[trigger->index].triggerLowerBound;
if (voltage < trigLower) {
trigger->trigState = false;

View File

@@ -21,34 +21,34 @@ extern "C" {
void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data,
uint8_t dataSize, int32_t periodMs, int32_t* status) {
SimCanData->SendMessage(messageID, data, dataSize, periodMs, status);
SimCanData->sendMessage(messageID, data, dataSize, periodMs, status);
}
void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
uint8_t* data, uint8_t* dataSize,
uint32_t* timeStamp, int32_t* status) {
SimCanData->ReceiveMessage(messageID, messageIDMask, data, dataSize,
SimCanData->receiveMessage(messageID, messageIDMask, data, dataSize,
timeStamp, status);
}
void HAL_CAN_OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
uint32_t messageIDMask, uint32_t maxMessages,
int32_t* status) {
SimCanData->OpenStreamSession(sessionHandle, messageID, messageIDMask,
SimCanData->openStreamSession(sessionHandle, messageID, messageIDMask,
maxMessages, status);
}
void HAL_CAN_CloseStreamSession(uint32_t sessionHandle) {
SimCanData->CloseStreamSession(sessionHandle);
SimCanData->closeStreamSession(sessionHandle);
}
void HAL_CAN_ReadStreamSession(uint32_t sessionHandle,
struct HAL_CANStreamMessage* messages,
uint32_t messagesToRead, uint32_t* messagesRead,
int32_t* status) {
SimCanData->ReadStreamSession(sessionHandle, messages, messagesToRead,
SimCanData->readStreamSession(sessionHandle, messages, messagesToRead,
messagesRead, status);
}
void HAL_CAN_GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount,
uint32_t* txFullCount, uint32_t* receiveErrorCount,
uint32_t* transmitErrorCount, int32_t* status) {
SimCanData->GetCANStatus(percentBusUtilization, busOffCount, txFullCount,
SimCanData->getCANStatus(percentBusUtilization, busOffCount, txFullCount,
receiveErrorCount, transmitErrorCount, status);
}

View File

@@ -28,7 +28,7 @@ HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status) {
// As compressors can have unlimited objects, just create a
// handle with the module number as the index.
SimPCMData[module].SetCompressorInitialized(true);
SimPCMData[module].compressorInitialized = true;
return (HAL_CompressorHandle)createHandle(static_cast<int16_t>(module),
HAL_HandleEnum::Compressor, 0);
}
@@ -46,7 +46,7 @@ HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressorHandle,
return false;
}
return SimPCMData[index].GetCompressorOn();
return SimPCMData[index].compressorOn;
}
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle,
@@ -58,7 +58,7 @@ void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle,
return;
}
SimPCMData[index].SetClosedLoopEnabled(value);
SimPCMData[index].closedLoopEnabled = value;
}
HAL_Bool HAL_GetCompressorClosedLoopControl(
@@ -70,7 +70,7 @@ HAL_Bool HAL_GetCompressorClosedLoopControl(
return false;
}
return SimPCMData[index].GetClosedLoopEnabled();
return SimPCMData[index].closedLoopEnabled;
}
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle,
@@ -82,7 +82,7 @@ HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle,
return false;
}
return SimPCMData[index].GetPressureSwitch();
return SimPCMData[index].pressureSwitch;
}
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle,
@@ -94,7 +94,7 @@ double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle,
return 0;
}
return SimPCMData[index].GetCompressorCurrent();
return SimPCMData[index].compressorCurrent;
}
HAL_Bool HAL_GetCompressorCurrentTooHighFault(
HAL_CompressorHandle compressorHandle, int32_t* status) {

View File

@@ -62,9 +62,9 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
port->channel = static_cast<uint8_t>(channel);
SimDIOData[channel].SetInitialized(true);
SimDIOData[channel].initialized = true;
SimDIOData[channel].SetIsInput(input);
SimDIOData[channel].isInput = input;
return handle;
}
@@ -78,7 +78,7 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
// no status, so no need to check for a proper free.
digitalChannelHandles->Free(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) return;
SimDIOData[port->channel].SetInitialized(true);
SimDIOData[port->channel].initialized = true;
}
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
@@ -95,7 +95,7 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
}
*id = static_cast<uint8_t>(getHandleIndex(handle));
SimDigitalPWMData[*id].SetInitialized(true);
SimDigitalPWMData[*id].initialized = true;
return handle;
}
@@ -105,7 +105,7 @@ void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
digitalPWMHandles->Free(pwmGenerator);
if (port == nullptr) return;
int32_t id = *port;
SimDigitalPWMData[id].SetInitialized(false);
SimDigitalPWMData[id].initialized = false;
}
void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
@@ -130,7 +130,7 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
int32_t id = *port;
if (dutyCycle > 1.0) dutyCycle = 1.0;
if (dutyCycle < 0.0) dutyCycle = 0.0;
SimDigitalPWMData[id].SetDutyCycle(dutyCycle);
SimDigitalPWMData[id].dutyCycle = dutyCycle;
}
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
@@ -141,7 +141,7 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
return;
}
int32_t id = *port;
SimDigitalPWMData[id].SetPin(channel);
SimDigitalPWMData[id].pin = channel;
}
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
@@ -154,7 +154,7 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
if (value != 0 && value != 1) {
if (value != 0) value = 1;
}
SimDIOData[port->channel].SetValue(value);
SimDIOData[port->channel].value = value;
}
void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
@@ -165,7 +165,7 @@ void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
return;
}
SimDIOData[port->channel].SetIsInput(input);
SimDIOData[port->channel].isInput = input;
}
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
@@ -174,7 +174,7 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return false;
}
HAL_Bool value = SimDIOData[port->channel].GetValue();
HAL_Bool value = SimDIOData[port->channel].value;
if (value > 1) value = 1;
if (value < 0) value = 0;
return value;
@@ -186,7 +186,7 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return false;
}
HAL_Bool value = SimDIOData[port->channel].GetIsInput();
HAL_Bool value = SimDIOData[port->channel].isInput;
if (value > 1) value = 1;
if (value < 0) value = 0;
return value;

View File

@@ -96,18 +96,18 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
}
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
controlWord->enabled = SimDriverStationData->GetEnabled();
controlWord->autonomous = SimDriverStationData->GetAutonomous();
controlWord->test = SimDriverStationData->GetTest();
controlWord->eStop = SimDriverStationData->GetEStop();
controlWord->fmsAttached = SimDriverStationData->GetFmsAttached();
controlWord->dsAttached = SimDriverStationData->GetDsAttached();
controlWord->enabled = SimDriverStationData->enabled;
controlWord->autonomous = SimDriverStationData->autonomous;
controlWord->test = SimDriverStationData->test;
controlWord->eStop = SimDriverStationData->eStop;
controlWord->fmsAttached = SimDriverStationData->fmsAttached;
controlWord->dsAttached = SimDriverStationData->dsAttached;
return 0;
}
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
*status = 0;
return SimDriverStationData->GetAllianceStationId();
return SimDriverStationData->allianceStationId;
}
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
@@ -166,7 +166,7 @@ int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
}
double HAL_GetMatchTime(int32_t* status) {
return SimDriverStationData->GetMatchTime();
return SimDriverStationData->matchTime;
}
int32_t HAL_GetMatchInfo(HAL_MatchInfo* info) {

View File

@@ -81,10 +81,9 @@ HAL_EncoderHandle HAL_InitializeEncoder(
return HAL_kInvalidHandle;
}
int16_t index = getHandleIndex(handle);
SimEncoderData[index].SetDigitalChannelA(
getHandleIndex(digitalSourceHandleA));
SimEncoderData[index].SetInitialized(true);
SimEncoderData[index].SetReverseDirection(reverseDirection);
SimEncoderData[index].digitalChannelA = getHandleIndex(digitalSourceHandleA);
SimEncoderData[index].initialized = true;
SimEncoderData[index].reverseDirection = reverseDirection;
// TODO: Add encoding type to Sim data
encoder->index = index;
encoder->nativeHandle = nativeHandle;
@@ -102,7 +101,7 @@ void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
} else if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::Counter)) {
counterHandles->Free(encoder->nativeHandle);
}
SimEncoderData[encoder->index].SetInitialized(false);
SimEncoderData[encoder->index].initialized = false;
}
static inline int EncodingScaleFactor(Encoder* encoder) {
@@ -138,7 +137,7 @@ int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
return 0;
}
return SimEncoderData[encoder->index].GetCount();
return SimEncoderData[encoder->index].count;
}
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles->Get(encoderHandle);
@@ -147,7 +146,7 @@ int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
return 0;
}
return SimEncoderData[encoder->index].GetCount() /
return SimEncoderData[encoder->index].count /
DecodingScaleFactor(encoder.get());
}
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
@@ -167,9 +166,9 @@ void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
return;
}
SimEncoderData[encoder->index].SetCount(0);
SimEncoderData[encoder->index].SetPeriod(std::numeric_limits<double>::max());
SimEncoderData[encoder->index].SetReset(true);
SimEncoderData[encoder->index].count = 0;
SimEncoderData[encoder->index].period = std::numeric_limits<double>::max();
SimEncoderData[encoder->index].reset = true;
}
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles->Get(encoderHandle);
@@ -178,7 +177,7 @@ double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
return 0;
}
return SimEncoderData[encoder->index].GetPeriod();
return SimEncoderData[encoder->index].period;
}
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
int32_t* status) {
@@ -188,7 +187,7 @@ void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
return;
}
SimEncoderData[encoder->index].SetMaxPeriod(maxPeriod);
SimEncoderData[encoder->index].maxPeriod = maxPeriod;
}
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
int32_t* status) {
@@ -198,8 +197,8 @@ HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
return 0;
}
return SimEncoderData[encoder->index].GetPeriod() >
SimEncoderData[encoder->index].GetMaxPeriod();
return SimEncoderData[encoder->index].period >
SimEncoderData[encoder->index].maxPeriod;
}
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
int32_t* status) {
@@ -209,7 +208,7 @@ HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
return 0;
}
return SimEncoderData[encoder->index].GetDirection();
return SimEncoderData[encoder->index].direction;
}
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
int32_t* status) {
@@ -219,7 +218,7 @@ double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
return 0;
}
return SimEncoderData[encoder->index].GetCount() * encoder->distancePerPulse;
return SimEncoderData[encoder->index].count * encoder->distancePerPulse;
}
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles->Get(encoderHandle);
@@ -228,7 +227,7 @@ double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
return 0;
}
return encoder->distancePerPulse / SimEncoderData[encoder->index].GetPeriod();
return encoder->distancePerPulse / SimEncoderData[encoder->index].period;
}
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
int32_t* status) {
@@ -243,8 +242,8 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
return;
}
SimEncoderData[encoder->index].SetMaxPeriod(encoder->distancePerPulse /
minRate);
SimEncoderData[encoder->index].maxPeriod =
encoder->distancePerPulse / minRate;
}
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
double distancePerPulse, int32_t* status) {
@@ -259,7 +258,7 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
return;
}
encoder->distancePerPulse = distancePerPulse;
SimEncoderData[encoder->index].SetDistancePerPulse(distancePerPulse);
SimEncoderData[encoder->index].distancePerPulse = distancePerPulse;
}
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
HAL_Bool reverseDirection,
@@ -270,7 +269,7 @@ void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
return;
}
SimEncoderData[encoder->index].SetReverseDirection(reverseDirection);
SimEncoderData[encoder->index].reverseDirection = reverseDirection;
}
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t samplesToAverage, int32_t* status) {
@@ -280,7 +279,7 @@ void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
return;
}
SimEncoderData[encoder->index].SetSamplesToAverage(samplesToAverage);
SimEncoderData[encoder->index].samplesToAverage = samplesToAverage;
}
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t* status) {
@@ -290,7 +289,7 @@ int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
return 0;
}
return SimEncoderData[encoder->index].GetSamplesToAverage();
return SimEncoderData[encoder->index].samplesToAverage;
}
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,

View File

@@ -7,6 +7,7 @@
#include "hal/HAL.h"
#include <wpi/mutex.h>
#include <wpi/raw_ostream.h>
#include "ErrorsInternal.h"
@@ -213,7 +214,7 @@ int64_t HAL_GetFPGARevision(int32_t* status) {
uint64_t HAL_GetFPGATime(int32_t* status) { return hal::GetFPGATime(); }
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
return SimRoboRioData[0].GetFPGAButton();
return SimRoboRioData[0].fpgaButton;
}
HAL_Bool HAL_GetSystemActive(int32_t* status) {

View File

@@ -21,7 +21,7 @@ void InitializeI2C() {}
extern "C" {
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
hal::init::CheckInit();
SimI2CData[port].SetInitialized(true);
SimI2CData[port].initialized = true;
}
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize,
@@ -40,5 +40,5 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
SimI2CData[port].Read(deviceAddress, buffer, count);
return 0;
}
void HAL_CloseI2C(HAL_I2CPort port) { SimI2CData[port].SetInitialized(false); }
void HAL_CloseI2C(HAL_I2CPort port) { SimI2CData[port].initialized = false; }
} // extern "C"

View File

@@ -205,9 +205,9 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
if (status != 0) return WaitResult::Timeout;
interrupt->previousState = SimDIOData[digitalIndex].GetValue();
interrupt->previousState = SimDIOData[digitalIndex].value;
int32_t uid = SimDIOData[digitalIndex].RegisterValueCallback(
int32_t uid = SimDIOData[digitalIndex].value.RegisterCallback(
&ProcessInterruptDigitalSynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(dataHandle)), false);
@@ -230,7 +230,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
}
// Cancel our callback
SimDIOData[digitalIndex].CancelValueCallback(uid);
SimDIOData[digitalIndex].value.CancelCallback(uid);
synchronousInterruptHandles->Free(dataHandle);
// Check for what to return
@@ -271,7 +271,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
if (status != 0) return WaitResult::Timeout;
int32_t uid = SimAnalogInData[analogIndex].RegisterVoltageCallback(
int32_t uid = SimAnalogInData[analogIndex].voltage.RegisterCallback(
&ProcessInterruptAnalogSynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(dataHandle)), false);
@@ -294,7 +294,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
}
// Cancel our callback
SimAnalogInData[analogIndex].CancelVoltageCallback(uid);
SimAnalogInData[analogIndex].voltage.CancelCallback(uid);
synchronousInterruptHandles->Free(dataHandle);
// Check for what to return
@@ -407,9 +407,9 @@ static void EnableInterruptsDigital(HAL_InterruptHandle handle,
int32_t digitalIndex = GetDigitalInputChannel(interrupt->portHandle, &status);
if (status != 0) return;
interrupt->previousState = SimDIOData[digitalIndex].GetValue();
interrupt->previousState = SimDIOData[digitalIndex].value;
int32_t uid = SimDIOData[digitalIndex].RegisterValueCallback(
int32_t uid = SimDIOData[digitalIndex].value.RegisterCallback(
&ProcessInterruptDigitalAsynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(handle)), false);
interrupt->callbackId = uid;
@@ -427,7 +427,7 @@ static void EnableInterruptsAnalog(HAL_InterruptHandle handle,
interrupt->portHandle, interrupt->trigType, &status);
if (status != 0) return;
int32_t uid = SimAnalogInData[analogIndex].RegisterVoltageCallback(
int32_t uid = SimAnalogInData[analogIndex].voltage.RegisterCallback(
&ProcessInterruptAnalogAsynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(handle)), false);
interrupt->callbackId = uid;
@@ -476,13 +476,13 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t analogIndex =
GetAnalogTriggerInputIndex(interrupt->portHandle, &status);
if (status != 0) return;
SimAnalogInData[analogIndex].CancelVoltageCallback(interrupt->callbackId);
SimAnalogInData[analogIndex].voltage.CancelCallback(interrupt->callbackId);
} else {
int32_t status = 0;
int32_t digitalIndex =
GetDigitalInputChannel(interrupt->portHandle, &status);
if (status != 0) return;
SimDIOData[digitalIndex].CancelValueCallback(interrupt->callbackId);
SimDIOData[digitalIndex].value.CancelCallback(interrupt->callbackId);
}
interrupt->callbackId = -1;
}

View File

@@ -35,7 +35,7 @@ HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
return HAL_kInvalidHandle;
}
hal::init::CheckInit();
SimPDPData[module].SetInitialized(true);
SimPDPData[module].initialized = true;
auto handle = HAL_InitializeCAN(manufacturer, module, deviceType, status);
if (*status != 0) {
@@ -61,14 +61,14 @@ double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) {
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].GetTemperature();
return SimPDPData[module].temperature;
}
double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].GetVoltage();
return SimPDPData[module].voltage;
}
double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
int32_t* status) {
@@ -76,7 +76,7 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].GetCurrent(channel);
return SimPDPData[module].current[channel];
}
double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
return 0.0;

View File

@@ -57,7 +57,7 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
port->channel = origChannel;
SimPWMData[origChannel].SetInitialized(true);
SimPWMData[origChannel].initialized = true;
// Defaults to allow an always valid config.
HAL_SetPWMConfig(handle, 2.0, 1.501, 1.5, 1.499, 1.0, status);
@@ -71,7 +71,7 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return;
}
SimPWMData[port->channel].SetInitialized(false);
SimPWMData[port->channel].initialized = false;
digitalChannelHandles->Free(pwmPortHandle, HAL_HandleEnum::PWM);
}
@@ -174,7 +174,7 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
return;
}
SimPWMData[port->channel].SetRawValue(value);
SimPWMData[port->channel].rawValue = value;
}
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
@@ -195,7 +195,7 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
speed = 1.0;
}
SimPWMData[port->channel].SetSpeed(speed);
SimPWMData[port->channel].speed = speed;
}
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
@@ -216,7 +216,7 @@ void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
pos = 1.0;
}
SimPWMData[port->channel].SetPosition(pos);
SimPWMData[port->channel].position = pos;
}
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
@@ -225,9 +225,9 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return;
}
SimPWMData[port->channel].SetRawValue(0);
SimPWMData[port->channel].SetPosition(0);
SimPWMData[port->channel].SetSpeed(0);
SimPWMData[port->channel].rawValue = 0;
SimPWMData[port->channel].position = 0;
SimPWMData[port->channel].speed = 0;
}
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
@@ -237,7 +237,7 @@ int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return 0;
}
return SimPWMData[port->channel].GetRawValue();
return SimPWMData[port->channel].rawValue;
}
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
@@ -251,7 +251,7 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return 0;
}
double speed = SimPWMData[port->channel].GetSpeed();
double speed = SimPWMData[port->channel].speed;
if (speed > 1) speed = 1;
if (speed < -1) speed = -1;
return speed;
@@ -268,7 +268,7 @@ double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return 0;
}
double position = SimPWMData[port->channel].GetPosition();
double position = SimPWMData[port->channel].position;
if (position > 1) position = 1;
if (position < 0) position = 0;
return position;
@@ -281,8 +281,8 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return;
}
SimPWMData[port->channel].SetZeroLatch(true);
SimPWMData[port->channel].SetZeroLatch(false);
SimPWMData[port->channel].zeroLatch = true;
SimPWMData[port->channel].zeroLatch = false;
}
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
@@ -293,7 +293,7 @@ void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
return;
}
SimPWMData[port->channel].SetPeriodScale(squelchMask);
SimPWMData[port->channel].periodScale = squelchMask;
}
int32_t HAL_GetPWMLoopTiming(int32_t* status) { return kExpectedLoopTiming; }

View File

@@ -20,45 +20,45 @@ void InitializePower() {}
// TODO: Fix the naming in here
extern "C" {
double HAL_GetVinVoltage(int32_t* status) {
return SimRoboRioData[0].GetVInVoltage();
return SimRoboRioData[0].vInVoltage;
}
double HAL_GetVinCurrent(int32_t* status) {
return SimRoboRioData[0].GetVInCurrent();
return SimRoboRioData[0].vInCurrent;
}
double HAL_GetUserVoltage6V(int32_t* status) {
return SimRoboRioData[0].GetUserVoltage6V();
return SimRoboRioData[0].userVoltage6V;
}
double HAL_GetUserCurrent6V(int32_t* status) {
return SimRoboRioData[0].GetUserCurrent6V();
return SimRoboRioData[0].userCurrent6V;
}
HAL_Bool HAL_GetUserActive6V(int32_t* status) {
return SimRoboRioData[0].GetUserActive6V();
return SimRoboRioData[0].userActive6V;
}
int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
return SimRoboRioData[0].GetUserFaults6V();
return SimRoboRioData[0].userFaults6V;
}
double HAL_GetUserVoltage5V(int32_t* status) {
return SimRoboRioData[0].GetUserVoltage5V();
return SimRoboRioData[0].userVoltage5V;
}
double HAL_GetUserCurrent5V(int32_t* status) {
return SimRoboRioData[0].GetUserCurrent5V();
return SimRoboRioData[0].userCurrent5V;
}
HAL_Bool HAL_GetUserActive5V(int32_t* status) {
return SimRoboRioData[0].GetUserActive5V();
return SimRoboRioData[0].userActive5V;
}
int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
return SimRoboRioData[0].GetUserFaults5V();
return SimRoboRioData[0].userFaults5V;
}
double HAL_GetUserVoltage3V3(int32_t* status) {
return SimRoboRioData[0].GetUserVoltage3V3();
return SimRoboRioData[0].userVoltage3V3;
}
double HAL_GetUserCurrent3V3(int32_t* status) {
return SimRoboRioData[0].GetUserCurrent3V3();
return SimRoboRioData[0].userCurrent3V3;
}
HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
return SimRoboRioData[0].GetUserActive3V3();
return SimRoboRioData[0].userActive3V3;
}
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
return SimRoboRioData[0].GetUserFaults3V3();
return SimRoboRioData[0].userFaults3V3;
}
} // extern "C"

View File

@@ -66,10 +66,10 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
port->fwd = false; // set to reverse
SimRelayData[channel].SetInitializedReverse(true);
SimRelayData[channel].initializedReverse = true;
} else {
port->fwd = true; // set to forward
SimRelayData[channel].SetInitializedForward(true);
SimRelayData[channel].initializedForward = true;
}
port->channel = static_cast<uint8_t>(channel);
@@ -82,9 +82,9 @@ void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
relayHandles->Free(relayPortHandle);
if (port == nullptr) return;
if (port->fwd)
SimRelayData[port->channel].SetInitializedForward(false);
SimRelayData[port->channel].initializedForward = false;
else
SimRelayData[port->channel].SetInitializedReverse(false);
SimRelayData[port->channel].initializedReverse = false;
}
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
@@ -102,9 +102,9 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
return;
}
if (port->fwd)
SimRelayData[port->channel].SetForward(on);
SimRelayData[port->channel].forward = on;
else
SimRelayData[port->channel].SetReverse(on);
SimRelayData[port->channel].reverse = on;
}
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
@@ -114,8 +114,8 @@ HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
return false;
}
if (port->fwd)
return SimRelayData[port->channel].GetForward();
return SimRelayData[port->channel].forward;
else
return SimRelayData[port->channel].GetReverse();
return SimRelayData[port->channel].reverse;
}
} // extern "C"

View File

@@ -20,7 +20,7 @@ void InitializeSPI() {}
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
hal::init::CheckInit();
SimSPIData[port].SetInitialized(true);
SimSPIData[port].initialized = true;
}
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
@@ -33,7 +33,7 @@ int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
return SimSPIData[port].Read(buffer, count);
}
void HAL_CloseSPI(HAL_SPIPort port) { SimSPIData[port].SetInitialized(false); }
void HAL_CloseSPI(HAL_SPIPort port) { SimSPIData[port].initialized = false; }
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {}
void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh) {}

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "AccelerometerDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,196 +21,11 @@ void InitializeAccelerometerData() {
AccelerometerData* hal::SimAccelerometerData;
void AccelerometerData::ResetData() {
m_active = false;
m_activeCallbacks = nullptr;
m_range = static_cast<HAL_AccelerometerRange>(0);
m_rangeCallbacks = nullptr;
m_x = 0.0;
m_xCallbacks = nullptr;
m_y = 0.0;
m_yCallbacks = nullptr;
m_z = 0.0;
m_zCallbacks = nullptr;
}
int32_t AccelerometerData::RegisterActiveCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_activeCallbacks =
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetActive());
callback("Active", param, &value);
}
return newUid;
}
void AccelerometerData::CancelActiveCallback(int32_t uid) {
m_activeCallbacks = CancelCallback(m_activeCallbacks, uid);
}
void AccelerometerData::InvokeActiveCallback(HAL_Value value) {
InvokeCallback(m_activeCallbacks, "Active", &value);
}
HAL_Bool AccelerometerData::GetActive() { return m_active; }
void AccelerometerData::SetActive(HAL_Bool active) {
HAL_Bool oldValue = m_active.exchange(active);
if (oldValue != active) {
InvokeActiveCallback(MakeBoolean(active));
}
}
int32_t AccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rangeCallbacks =
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeEnum(GetRange());
callback("Range", param, &value);
}
return newUid;
}
void AccelerometerData::CancelRangeCallback(int32_t uid) {
m_rangeCallbacks = CancelCallback(m_rangeCallbacks, uid);
}
void AccelerometerData::InvokeRangeCallback(HAL_Value value) {
InvokeCallback(m_rangeCallbacks, "Range", &value);
}
HAL_AccelerometerRange AccelerometerData::GetRange() { return m_range; }
void AccelerometerData::SetRange(HAL_AccelerometerRange range) {
HAL_AccelerometerRange oldValue = m_range.exchange(range);
if (oldValue != range) {
InvokeRangeCallback(MakeEnum(range));
}
}
int32_t AccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_xCallbacks =
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetX());
callback("X", param, &value);
}
return newUid;
}
void AccelerometerData::CancelXCallback(int32_t uid) {
m_xCallbacks = CancelCallback(m_xCallbacks, uid);
}
void AccelerometerData::InvokeXCallback(HAL_Value value) {
InvokeCallback(m_xCallbacks, "X", &value);
}
double AccelerometerData::GetX() { return m_x; }
void AccelerometerData::SetX(double x) {
double oldValue = m_x.exchange(x);
if (oldValue != x) {
InvokeXCallback(MakeDouble(x));
}
}
int32_t AccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_yCallbacks =
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetY());
callback("Y", param, &value);
}
return newUid;
}
void AccelerometerData::CancelYCallback(int32_t uid) {
m_yCallbacks = CancelCallback(m_yCallbacks, uid);
}
void AccelerometerData::InvokeYCallback(HAL_Value value) {
InvokeCallback(m_yCallbacks, "Y", &value);
}
double AccelerometerData::GetY() { return m_y; }
void AccelerometerData::SetY(double y) {
double oldValue = m_y.exchange(y);
if (oldValue != y) {
InvokeYCallback(MakeDouble(y));
}
}
int32_t AccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zCallbacks =
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetZ());
callback("Z", param, &value);
}
return newUid;
}
void AccelerometerData::CancelZCallback(int32_t uid) {
m_zCallbacks = CancelCallback(m_zCallbacks, uid);
}
void AccelerometerData::InvokeZCallback(HAL_Value value) {
InvokeCallback(m_zCallbacks, "Z", &value);
}
double AccelerometerData::GetZ() { return m_z; }
void AccelerometerData::SetZ(double z) {
double oldValue = m_z.exchange(z);
if (oldValue != z) {
InvokeZCallback(MakeDouble(z));
}
active.Reset(false);
range.Reset(static_cast<HAL_AccelerometerRange>(0));
x.Reset(0.0);
y.Reset(0.0);
z.Reset(0.0);
}
extern "C" {
@@ -219,116 +33,28 @@ void HALSIM_ResetAccelerometerData(int32_t index) {
SimAccelerometerData[index].ResetData();
}
int32_t HALSIM_RegisterAccelerometerActiveCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAccelerometerData[index].RegisterActiveCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Accelerometer##CAPINAME, \
SimAccelerometerData, LOWERNAME)
void HALSIM_CancelAccelerometerActiveCallback(int32_t index, int32_t uid) {
SimAccelerometerData[index].CancelActiveCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Active, active)
DEFINE_CAPI(HAL_AccelerometerRange, Range, range)
DEFINE_CAPI(double, X, x)
DEFINE_CAPI(double, Y, y)
DEFINE_CAPI(double, Z, z)
HAL_Bool HALSIM_GetAccelerometerActive(int32_t index) {
return SimAccelerometerData[index].GetActive();
}
void HALSIM_SetAccelerometerActive(int32_t index, HAL_Bool active) {
SimAccelerometerData[index].SetActive(active);
}
int32_t HALSIM_RegisterAccelerometerRangeCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAccelerometerData[index].RegisterRangeCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAccelerometerRangeCallback(int32_t index, int32_t uid) {
SimAccelerometerData[index].CancelRangeCallback(uid);
}
HAL_AccelerometerRange HALSIM_GetAccelerometerRange(int32_t index) {
return SimAccelerometerData[index].GetRange();
}
void HALSIM_SetAccelerometerRange(int32_t index, HAL_AccelerometerRange range) {
SimAccelerometerData[index].SetRange(range);
}
int32_t HALSIM_RegisterAccelerometerXCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAccelerometerData[index].RegisterXCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAccelerometerXCallback(int32_t index, int32_t uid) {
SimAccelerometerData[index].CancelXCallback(uid);
}
double HALSIM_GetAccelerometerX(int32_t index) {
return SimAccelerometerData[index].GetX();
}
void HALSIM_SetAccelerometerX(int32_t index, double x) {
SimAccelerometerData[index].SetX(x);
}
int32_t HALSIM_RegisterAccelerometerYCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAccelerometerData[index].RegisterYCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAccelerometerYCallback(int32_t index, int32_t uid) {
SimAccelerometerData[index].CancelYCallback(uid);
}
double HALSIM_GetAccelerometerY(int32_t index) {
return SimAccelerometerData[index].GetY();
}
void HALSIM_SetAccelerometerY(int32_t index, double y) {
SimAccelerometerData[index].SetY(y);
}
int32_t HALSIM_RegisterAccelerometerZCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAccelerometerData[index].RegisterZCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAccelerometerZCallback(int32_t index, int32_t uid) {
SimAccelerometerData[index].CancelZCallback(uid);
}
double HALSIM_GetAccelerometerZ(int32_t index) {
return SimAccelerometerData[index].GetZ();
}
void HALSIM_SetAccelerometerZ(int32_t index, double z) {
SimAccelerometerData[index].SetZ(z);
}
#define REGISTER(NAME) \
SimAccelerometerData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterAccelerometerAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimAccelerometerData[index].RegisterActiveCallback(callback, param,
initialNotify);
SimAccelerometerData[index].RegisterRangeCallback(callback, param,
initialNotify);
SimAccelerometerData[index].RegisterXCallback(callback, param, initialNotify);
SimAccelerometerData[index].RegisterYCallback(callback, param, initialNotify);
SimAccelerometerData[index].RegisterZCallback(callback, param, initialNotify);
REGISTER(active);
REGISTER(range);
REGISTER(x);
REGISTER(y);
REGISTER(z);
}
} // extern "C"

View File

@@ -7,67 +7,30 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/AccelerometerData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class AccelerometerData {
HAL_SIMDATAVALUE_DEFINE_NAME(Active)
HAL_SIMDATAVALUE_DEFINE_NAME(Range)
HAL_SIMDATAVALUE_DEFINE_NAME(X)
HAL_SIMDATAVALUE_DEFINE_NAME(Y)
HAL_SIMDATAVALUE_DEFINE_NAME(Z)
static inline HAL_Value MakeRangeValue(HAL_AccelerometerRange value) {
return MakeEnum(value);
}
public:
int32_t RegisterActiveCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelActiveCallback(int32_t uid);
void InvokeActiveCallback(HAL_Value value);
HAL_Bool GetActive();
void SetActive(HAL_Bool active);
int32_t RegisterRangeCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelRangeCallback(int32_t uid);
void InvokeRangeCallback(HAL_Value value);
HAL_AccelerometerRange GetRange();
void SetRange(HAL_AccelerometerRange range);
int32_t RegisterXCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelXCallback(int32_t uid);
void InvokeXCallback(HAL_Value value);
double GetX();
void SetX(double x);
int32_t RegisterYCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelYCallback(int32_t uid);
void InvokeYCallback(HAL_Value value);
double GetY();
void SetY(double y);
int32_t RegisterZCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelZCallback(int32_t uid);
void InvokeZCallback(HAL_Value value);
double GetZ();
void SetZ(double z);
SimDataValue<HAL_Bool, MakeBoolean, GetActiveName> active{false};
SimDataValue<HAL_AccelerometerRange, MakeRangeValue, GetRangeName> range{
static_cast<HAL_AccelerometerRange>(0)};
SimDataValue<double, MakeDouble, GetXName> x{0.0};
SimDataValue<double, MakeDouble, GetYName> y{0.0};
SimDataValue<double, MakeDouble, GetZName> z{0.0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_active{false};
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
std::atomic<HAL_AccelerometerRange> m_range{
static_cast<HAL_AccelerometerRange>(0)};
std::shared_ptr<NotifyListenerVector> m_rangeCallbacks = nullptr;
std::atomic<double> m_x{0.0};
std::shared_ptr<NotifyListenerVector> m_xCallbacks = nullptr;
std::atomic<double> m_y{0.0};
std::shared_ptr<NotifyListenerVector> m_yCallbacks = nullptr;
std::atomic<double> m_z{0.0};
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
};
extern AccelerometerData* SimAccelerometerData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "AnalogGyroDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,120 +21,9 @@ void InitializeAnalogGyroData() {
AnalogGyroData* hal::SimAnalogGyroData;
void AnalogGyroData::ResetData() {
m_angle = 0.0;
m_angleCallbacks = nullptr;
m_rate = 0.0;
m_rateCallbacks = nullptr;
m_initialized = false;
m_initializedCallbacks = nullptr;
}
int32_t AnalogGyroData::RegisterAngleCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_angleCallbacks =
RegisterCallback(m_angleCallbacks, "Angle", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetAngle());
callback("Angle", param, &value);
}
return newUid;
}
void AnalogGyroData::CancelAngleCallback(int32_t uid) {
m_angleCallbacks = CancelCallback(m_angleCallbacks, uid);
}
void AnalogGyroData::InvokeAngleCallback(HAL_Value value) {
InvokeCallback(m_angleCallbacks, "Angle", &value);
}
double AnalogGyroData::GetAngle() { return m_angle; }
void AnalogGyroData::SetAngle(double angle) {
double oldValue = m_angle.exchange(angle);
if (oldValue != angle) {
InvokeAngleCallback(MakeDouble(angle));
}
}
int32_t AnalogGyroData::RegisterRateCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rateCallbacks =
RegisterCallback(m_rateCallbacks, "Rate", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetRate());
callback("Rate", param, &value);
}
return newUid;
}
void AnalogGyroData::CancelRateCallback(int32_t uid) {
m_rateCallbacks = CancelCallback(m_rateCallbacks, uid);
}
void AnalogGyroData::InvokeRateCallback(HAL_Value value) {
InvokeCallback(m_rateCallbacks, "Rate", &value);
}
double AnalogGyroData::GetRate() { return m_rate; }
void AnalogGyroData::SetRate(double rate) {
double oldValue = m_rate.exchange(rate);
if (oldValue != rate) {
InvokeRateCallback(MakeDouble(rate));
}
}
int32_t AnalogGyroData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void AnalogGyroData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void AnalogGyroData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool AnalogGyroData::GetInitialized() { return m_initialized; }
void AnalogGyroData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
angle.Reset(0.0);
rate.Reset(0.0);
initialized.Reset(false);
}
extern "C" {
@@ -143,73 +31,23 @@ void HALSIM_ResetAnalogGyroData(int32_t index) {
SimAnalogGyroData[index].ResetData();
}
int32_t HALSIM_RegisterAnalogGyroAngleCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogGyroData[index].RegisterAngleCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogGyro##CAPINAME, \
SimAnalogGyroData, LOWERNAME)
void HALSIM_CancelAnalogGyroAngleCallback(int32_t index, int32_t uid) {
SimAnalogGyroData[index].CancelAngleCallback(uid);
}
DEFINE_CAPI(double, Angle, angle)
DEFINE_CAPI(double, Rate, rate)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
double HALSIM_GetAnalogGyroAngle(int32_t index) {
return SimAnalogGyroData[index].GetAngle();
}
void HALSIM_SetAnalogGyroAngle(int32_t index, double angle) {
SimAnalogGyroData[index].SetAngle(angle);
}
int32_t HALSIM_RegisterAnalogGyroRateCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogGyroData[index].RegisterRateCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogGyroRateCallback(int32_t index, int32_t uid) {
SimAnalogGyroData[index].CancelRateCallback(uid);
}
double HALSIM_GetAnalogGyroRate(int32_t index) {
return SimAnalogGyroData[index].GetRate();
}
void HALSIM_SetAnalogGyroRate(int32_t index, double rate) {
SimAnalogGyroData[index].SetRate(rate);
}
int32_t HALSIM_RegisterAnalogGyroInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogGyroData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogGyroInitializedCallback(int32_t index, int32_t uid) {
SimAnalogGyroData[index].CancelInitializedCallback(uid);
}
HAL_Bool HALSIM_GetAnalogGyroInitialized(int32_t index) {
return SimAnalogGyroData[index].GetInitialized();
}
void HALSIM_SetAnalogGyroInitialized(int32_t index, HAL_Bool initialized) {
SimAnalogGyroData[index].SetInitialized(initialized);
}
#define REGISTER(NAME) \
SimAnalogGyroData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterAnalogGyroAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimAnalogGyroData[index].RegisterAngleCallback(callback, param,
initialNotify);
SimAnalogGyroData[index].RegisterRateCallback(callback, param, initialNotify);
SimAnalogGyroData[index].RegisterInitializedCallback(callback, param,
initialNotify);
REGISTER(angle);
REGISTER(rate);
REGISTER(initialized);
}
} // extern "C"

View File

@@ -7,48 +7,21 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/AnalogGyroData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class AnalogGyroData {
HAL_SIMDATAVALUE_DEFINE_NAME(Angle)
HAL_SIMDATAVALUE_DEFINE_NAME(Rate)
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
public:
int32_t RegisterAngleCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelAngleCallback(int32_t uid);
void InvokeAngleCallback(HAL_Value value);
double GetAngle();
void SetAngle(double angle);
int32_t RegisterRateCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelRateCallback(int32_t uid);
void InvokeRateCallback(HAL_Value value);
double GetRate();
void SetRate(double rate);
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
SimDataValue<double, MakeDouble, GetAngleName> angle{0.0};
SimDataValue<double, MakeDouble, GetRateName> rate{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<double> m_angle{0.0};
std::shared_ptr<NotifyListenerVector> m_angleCallbacks = nullptr;
std::atomic<double> m_rate{0.0};
std::shared_ptr<NotifyListenerVector> m_rateCallbacks = nullptr;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
};
extern AnalogGyroData* SimAnalogGyroData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "AnalogInDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,355 +21,15 @@ void InitializeAnalogInData() {
AnalogInData* hal::SimAnalogInData;
void AnalogInData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_averageBits = 7;
m_averageBitsCallbacks = nullptr;
m_oversampleBits = 0;
m_oversampleBitsCallbacks = nullptr;
m_voltage = 0.0;
m_voltageCallbacks = nullptr;
m_accumulatorInitialized = false;
m_accumulatorInitializedCallbacks = nullptr;
m_accumulatorValue = 0;
m_accumulatorValueCallbacks = nullptr;
m_accumulatorCount = 0;
m_accumulatorCountCallbacks = nullptr;
m_accumulatorCenter = 0;
m_accumulatorCenterCallbacks = nullptr;
m_accumulatorDeadband = 0;
m_accumulatorDeadbandCallbacks = nullptr;
}
int32_t AnalogInData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void AnalogInData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void AnalogInData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool AnalogInData::GetInitialized() { return m_initialized; }
void AnalogInData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t AnalogInData::RegisterAverageBitsCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_averageBitsCallbacks = RegisterCallback(
m_averageBitsCallbacks, "AverageBits", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetAverageBits());
callback("AverageBits", param, &value);
}
return newUid;
}
void AnalogInData::CancelAverageBitsCallback(int32_t uid) {
m_averageBitsCallbacks = CancelCallback(m_averageBitsCallbacks, uid);
}
void AnalogInData::InvokeAverageBitsCallback(HAL_Value value) {
InvokeCallback(m_averageBitsCallbacks, "AverageBits", &value);
}
int32_t AnalogInData::GetAverageBits() { return m_averageBits; }
void AnalogInData::SetAverageBits(int32_t averageBits) {
int32_t oldValue = m_averageBits.exchange(averageBits);
if (oldValue != averageBits) {
InvokeAverageBitsCallback(MakeInt(averageBits));
}
}
int32_t AnalogInData::RegisterOversampleBitsCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_oversampleBitsCallbacks = RegisterCallback(
m_oversampleBitsCallbacks, "OversampleBits", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetOversampleBits());
callback("OversampleBits", param, &value);
}
return newUid;
}
void AnalogInData::CancelOversampleBitsCallback(int32_t uid) {
m_oversampleBitsCallbacks = CancelCallback(m_oversampleBitsCallbacks, uid);
}
void AnalogInData::InvokeOversampleBitsCallback(HAL_Value value) {
InvokeCallback(m_oversampleBitsCallbacks, "OversampleBits", &value);
}
int32_t AnalogInData::GetOversampleBits() { return m_oversampleBits; }
void AnalogInData::SetOversampleBits(int32_t oversampleBits) {
int32_t oldValue = m_oversampleBits.exchange(oversampleBits);
if (oldValue != oversampleBits) {
InvokeOversampleBitsCallback(MakeInt(oversampleBits));
}
}
int32_t AnalogInData::RegisterVoltageCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetVoltage());
callback("Voltage", param, &value);
}
return newUid;
}
void AnalogInData::CancelVoltageCallback(int32_t uid) {
m_voltageCallbacks = CancelCallback(m_voltageCallbacks, uid);
}
void AnalogInData::InvokeVoltageCallback(HAL_Value value) {
InvokeCallback(m_voltageCallbacks, "Voltage", &value);
}
double AnalogInData::GetVoltage() { return m_voltage; }
void AnalogInData::SetVoltage(double voltage) {
double oldValue = m_voltage.exchange(voltage);
if (oldValue != voltage) {
InvokeVoltageCallback(MakeDouble(voltage));
}
}
int32_t AnalogInData::RegisterAccumulatorInitializedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorInitializedCallbacks =
RegisterCallback(m_accumulatorInitializedCallbacks,
"AccumulatorInitialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetAccumulatorInitialized());
callback("AccumulatorInitialized", param, &value);
}
return newUid;
}
void AnalogInData::CancelAccumulatorInitializedCallback(int32_t uid) {
m_accumulatorInitializedCallbacks =
CancelCallback(m_accumulatorInitializedCallbacks, uid);
}
void AnalogInData::InvokeAccumulatorInitializedCallback(HAL_Value value) {
InvokeCallback(m_accumulatorInitializedCallbacks, "AccumulatorInitialized",
&value);
}
HAL_Bool AnalogInData::GetAccumulatorInitialized() {
return m_accumulatorInitialized;
}
void AnalogInData::SetAccumulatorInitialized(HAL_Bool accumulatorInitialized) {
HAL_Bool oldValue = m_accumulatorInitialized.exchange(accumulatorInitialized);
if (oldValue != accumulatorInitialized) {
InvokeAccumulatorInitializedCallback(MakeBoolean(accumulatorInitialized));
}
}
int32_t AnalogInData::RegisterAccumulatorValueCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorValueCallbacks =
RegisterCallback(m_accumulatorValueCallbacks, "AccumulatorValue",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeLong(GetAccumulatorValue());
callback("AccumulatorValue", param, &value);
}
return newUid;
}
void AnalogInData::CancelAccumulatorValueCallback(int32_t uid) {
m_accumulatorValueCallbacks =
CancelCallback(m_accumulatorValueCallbacks, uid);
}
void AnalogInData::InvokeAccumulatorValueCallback(HAL_Value value) {
InvokeCallback(m_accumulatorValueCallbacks, "AccumulatorValue", &value);
}
int64_t AnalogInData::GetAccumulatorValue() { return m_accumulatorValue; }
void AnalogInData::SetAccumulatorValue(int64_t accumulatorValue) {
int64_t oldValue = m_accumulatorValue.exchange(accumulatorValue);
if (oldValue != accumulatorValue) {
InvokeAccumulatorValueCallback(MakeLong(accumulatorValue));
}
}
int32_t AnalogInData::RegisterAccumulatorCountCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorCountCallbacks =
RegisterCallback(m_accumulatorCountCallbacks, "AccumulatorCount",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeLong(GetAccumulatorCount());
callback("AccumulatorCount", param, &value);
}
return newUid;
}
void AnalogInData::CancelAccumulatorCountCallback(int32_t uid) {
m_accumulatorCountCallbacks =
CancelCallback(m_accumulatorCountCallbacks, uid);
}
void AnalogInData::InvokeAccumulatorCountCallback(HAL_Value value) {
InvokeCallback(m_accumulatorCountCallbacks, "AccumulatorCount", &value);
}
int64_t AnalogInData::GetAccumulatorCount() { return m_accumulatorCount; }
void AnalogInData::SetAccumulatorCount(int64_t accumulatorCount) {
int64_t oldValue = m_accumulatorCount.exchange(accumulatorCount);
if (oldValue != accumulatorCount) {
InvokeAccumulatorCountCallback(MakeLong(accumulatorCount));
}
}
int32_t AnalogInData::RegisterAccumulatorCenterCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorCenterCallbacks =
RegisterCallback(m_accumulatorCenterCallbacks, "AccumulatorCenter",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetAccumulatorCenter());
callback("AccumulatorCenter", param, &value);
}
return newUid;
}
void AnalogInData::CancelAccumulatorCenterCallback(int32_t uid) {
m_accumulatorCenterCallbacks =
CancelCallback(m_accumulatorCenterCallbacks, uid);
}
void AnalogInData::InvokeAccumulatorCenterCallback(HAL_Value value) {
InvokeCallback(m_accumulatorCenterCallbacks, "AccumulatorCenter", &value);
}
int32_t AnalogInData::GetAccumulatorCenter() { return m_accumulatorCenter; }
void AnalogInData::SetAccumulatorCenter(int32_t accumulatorCenter) {
int32_t oldValue = m_accumulatorCenter.exchange(accumulatorCenter);
if (oldValue != accumulatorCenter) {
InvokeAccumulatorCenterCallback(MakeInt(accumulatorCenter));
}
}
int32_t AnalogInData::RegisterAccumulatorDeadbandCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorDeadbandCallbacks =
RegisterCallback(m_accumulatorDeadbandCallbacks, "AccumulatorDeadband",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetAccumulatorDeadband());
callback("AccumulatorDeadband", param, &value);
}
return newUid;
}
void AnalogInData::CancelAccumulatorDeadbandCallback(int32_t uid) {
m_accumulatorDeadbandCallbacks =
CancelCallback(m_accumulatorDeadbandCallbacks, uid);
}
void AnalogInData::InvokeAccumulatorDeadbandCallback(HAL_Value value) {
InvokeCallback(m_accumulatorDeadbandCallbacks, "AccumulatorDeadband", &value);
}
int32_t AnalogInData::GetAccumulatorDeadband() { return m_accumulatorDeadband; }
void AnalogInData::SetAccumulatorDeadband(int32_t accumulatorDeadband) {
int32_t oldValue = m_accumulatorDeadband.exchange(accumulatorDeadband);
if (oldValue != accumulatorDeadband) {
InvokeAccumulatorDeadbandCallback(MakeInt(accumulatorDeadband));
}
initialized.Reset(false);
averageBits.Reset(7);
oversampleBits.Reset(0);
voltage.Reset(0.0);
accumulatorInitialized.Reset(false);
accumulatorValue.Reset(0);
accumulatorCount.Reset(0);
accumulatorCenter.Reset(0);
accumulatorDeadband.Reset(0);
}
extern "C" {
@@ -378,208 +37,34 @@ void HALSIM_ResetAnalogInData(int32_t index) {
SimAnalogInData[index].ResetData();
}
int32_t HALSIM_RegisterAnalogInInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogIn##CAPINAME, \
SimAnalogInData, LOWERNAME)
void HALSIM_CancelAnalogInInitializedCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(int32_t, AverageBits, averageBits)
DEFINE_CAPI(int32_t, OversampleBits, oversampleBits)
DEFINE_CAPI(double, Voltage, voltage)
DEFINE_CAPI(HAL_Bool, AccumulatorInitialized, accumulatorInitialized)
DEFINE_CAPI(int64_t, AccumulatorValue, accumulatorValue)
DEFINE_CAPI(int64_t, AccumulatorCount, accumulatorCount)
DEFINE_CAPI(int32_t, AccumulatorCenter, accumulatorCenter)
DEFINE_CAPI(int32_t, AccumulatorDeadband, accumulatorDeadband)
HAL_Bool HALSIM_GetAnalogInInitialized(int32_t index) {
return SimAnalogInData[index].GetInitialized();
}
void HALSIM_SetAnalogInInitialized(int32_t index, HAL_Bool initialized) {
SimAnalogInData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterAnalogInAverageBitsCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAverageBitsCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogInAverageBitsCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelAverageBitsCallback(uid);
}
int32_t HALSIM_GetAnalogInAverageBits(int32_t index) {
return SimAnalogInData[index].GetAverageBits();
}
void HALSIM_SetAnalogInAverageBits(int32_t index, int32_t averageBits) {
SimAnalogInData[index].SetAverageBits(averageBits);
}
int32_t HALSIM_RegisterAnalogInOversampleBitsCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterOversampleBitsCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogInOversampleBitsCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelOversampleBitsCallback(uid);
}
int32_t HALSIM_GetAnalogInOversampleBits(int32_t index) {
return SimAnalogInData[index].GetOversampleBits();
}
void HALSIM_SetAnalogInOversampleBits(int32_t index, int32_t oversampleBits) {
SimAnalogInData[index].SetOversampleBits(oversampleBits);
}
int32_t HALSIM_RegisterAnalogInVoltageCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterVoltageCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogInVoltageCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelVoltageCallback(uid);
}
double HALSIM_GetAnalogInVoltage(int32_t index) {
return SimAnalogInData[index].GetVoltage();
}
void HALSIM_SetAnalogInVoltage(int32_t index, double voltage) {
SimAnalogInData[index].SetVoltage(voltage);
}
int32_t HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAccumulatorInitializedCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogInAccumulatorInitializedCallback(int32_t index,
int32_t uid) {
SimAnalogInData[index].CancelAccumulatorInitializedCallback(uid);
}
HAL_Bool HALSIM_GetAnalogInAccumulatorInitialized(int32_t index) {
return SimAnalogInData[index].GetAccumulatorInitialized();
}
void HALSIM_SetAnalogInAccumulatorInitialized(int32_t index,
HAL_Bool accumulatorInitialized) {
SimAnalogInData[index].SetAccumulatorInitialized(accumulatorInitialized);
}
int32_t HALSIM_RegisterAnalogInAccumulatorValueCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAccumulatorValueCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogInAccumulatorValueCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelAccumulatorValueCallback(uid);
}
int64_t HALSIM_GetAnalogInAccumulatorValue(int32_t index) {
return SimAnalogInData[index].GetAccumulatorValue();
}
void HALSIM_SetAnalogInAccumulatorValue(int32_t index,
int64_t accumulatorValue) {
SimAnalogInData[index].SetAccumulatorValue(accumulatorValue);
}
int32_t HALSIM_RegisterAnalogInAccumulatorCountCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAccumulatorCountCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogInAccumulatorCountCallback(int32_t index, int32_t uid) {
SimAnalogInData[index].CancelAccumulatorCountCallback(uid);
}
int64_t HALSIM_GetAnalogInAccumulatorCount(int32_t index) {
return SimAnalogInData[index].GetAccumulatorCount();
}
void HALSIM_SetAnalogInAccumulatorCount(int32_t index,
int64_t accumulatorCount) {
SimAnalogInData[index].SetAccumulatorCount(accumulatorCount);
}
int32_t HALSIM_RegisterAnalogInAccumulatorCenterCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAccumulatorCenterCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogInAccumulatorCenterCallback(int32_t index,
int32_t uid) {
SimAnalogInData[index].CancelAccumulatorCenterCallback(uid);
}
int32_t HALSIM_GetAnalogInAccumulatorCenter(int32_t index) {
return SimAnalogInData[index].GetAccumulatorCenter();
}
void HALSIM_SetAnalogInAccumulatorCenter(int32_t index,
int32_t accumulatorCenter) {
SimAnalogInData[index].SetAccumulatorCenter(accumulatorCenter);
}
int32_t HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogInData[index].RegisterAccumulatorDeadbandCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogInAccumulatorDeadbandCallback(int32_t index,
int32_t uid) {
SimAnalogInData[index].CancelAccumulatorDeadbandCallback(uid);
}
int32_t HALSIM_GetAnalogInAccumulatorDeadband(int32_t index) {
return SimAnalogInData[index].GetAccumulatorDeadband();
}
void HALSIM_SetAnalogInAccumulatorDeadband(int32_t index,
int32_t accumulatorDeadband) {
SimAnalogInData[index].SetAccumulatorDeadband(accumulatorDeadband);
}
#define REGISTER(NAME) \
SimAnalogInData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterAnalogInAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimAnalogInData[index].RegisterInitializedCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAverageBitsCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterOversampleBitsCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterVoltageCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAccumulatorInitializedCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAccumulatorValueCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAccumulatorCountCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAccumulatorCenterCallback(callback, param,
initialNotify);
SimAnalogInData[index].RegisterAccumulatorDeadbandCallback(callback, param,
initialNotify);
REGISTER(initialized);
REGISTER(averageBits);
REGISTER(oversampleBits);
REGISTER(voltage);
REGISTER(accumulatorInitialized);
REGISTER(accumulatorValue);
REGISTER(accumulatorCount);
REGISTER(accumulatorCenter);
REGISTER(accumulatorDeadband);
}
} // extern "C"

View File

@@ -7,107 +7,35 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/AnalogInData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class AnalogInData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(AverageBits)
HAL_SIMDATAVALUE_DEFINE_NAME(OversampleBits)
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorValue)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorCount)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorCenter)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorDeadband)
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterAverageBitsCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelAverageBitsCallback(int32_t uid);
void InvokeAverageBitsCallback(HAL_Value value);
int32_t GetAverageBits();
void SetAverageBits(int32_t averageBits);
int32_t RegisterOversampleBitsCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelOversampleBitsCallback(int32_t uid);
void InvokeOversampleBitsCallback(HAL_Value value);
int32_t GetOversampleBits();
void SetOversampleBits(int32_t oversampleBits);
int32_t RegisterVoltageCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelVoltageCallback(int32_t uid);
void InvokeVoltageCallback(HAL_Value value);
double GetVoltage();
void SetVoltage(double voltage);
int32_t RegisterAccumulatorInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelAccumulatorInitializedCallback(int32_t uid);
void InvokeAccumulatorInitializedCallback(HAL_Value value);
HAL_Bool GetAccumulatorInitialized();
void SetAccumulatorInitialized(HAL_Bool accumulatorInitialized);
int32_t RegisterAccumulatorValueCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelAccumulatorValueCallback(int32_t uid);
void InvokeAccumulatorValueCallback(HAL_Value value);
int64_t GetAccumulatorValue();
void SetAccumulatorValue(int64_t accumulatorValue);
int32_t RegisterAccumulatorCountCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelAccumulatorCountCallback(int32_t uid);
void InvokeAccumulatorCountCallback(HAL_Value value);
int64_t GetAccumulatorCount();
void SetAccumulatorCount(int64_t accumulatorCount);
int32_t RegisterAccumulatorCenterCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelAccumulatorCenterCallback(int32_t uid);
void InvokeAccumulatorCenterCallback(HAL_Value value);
int32_t GetAccumulatorCenter();
void SetAccumulatorCenter(int32_t accumulatorCenter);
int32_t RegisterAccumulatorDeadbandCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelAccumulatorDeadbandCallback(int32_t uid);
void InvokeAccumulatorDeadbandCallback(HAL_Value value);
int32_t GetAccumulatorDeadband();
void SetAccumulatorDeadband(int32_t accumulatorDeadband);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<int32_t, MakeInt, GetAverageBitsName> averageBits{7};
SimDataValue<int32_t, MakeInt, GetOversampleBitsName> oversampleBits{0};
SimDataValue<double, MakeDouble, GetVoltageName> voltage{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetAccumulatorInitializedName>
accumulatorInitialized{false};
SimDataValue<int64_t, MakeLong, GetAccumulatorValueName> accumulatorValue{0};
SimDataValue<int64_t, MakeLong, GetAccumulatorCountName> accumulatorCount{0};
SimDataValue<int32_t, MakeInt, GetAccumulatorCenterName> accumulatorCenter{0};
SimDataValue<int32_t, MakeInt, GetAccumulatorDeadbandName>
accumulatorDeadband{0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_averageBits{7};
std::shared_ptr<NotifyListenerVector> m_averageBitsCallbacks = nullptr;
std::atomic<int32_t> m_oversampleBits{0};
std::shared_ptr<NotifyListenerVector> m_oversampleBitsCallbacks = nullptr;
std::atomic<double> m_voltage{0.0};
std::shared_ptr<NotifyListenerVector> m_voltageCallbacks = nullptr;
std::atomic<HAL_Bool> m_accumulatorInitialized{false};
std::shared_ptr<NotifyListenerVector> m_accumulatorInitializedCallbacks =
nullptr;
std::atomic<int64_t> m_accumulatorValue{0};
std::shared_ptr<NotifyListenerVector> m_accumulatorValueCallbacks = nullptr;
std::atomic<int64_t> m_accumulatorCount{0};
std::shared_ptr<NotifyListenerVector> m_accumulatorCountCallbacks = nullptr;
std::atomic<int32_t> m_accumulatorCenter{0};
std::shared_ptr<NotifyListenerVector> m_accumulatorCenterCallbacks = nullptr;
std::atomic<int32_t> m_accumulatorDeadband{0};
std::shared_ptr<NotifyListenerVector> m_accumulatorDeadbandCallbacks =
nullptr;
};
extern AnalogInData* SimAnalogInData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "AnalogOutDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,82 +21,8 @@ void InitializeAnalogOutData() {
AnalogOutData* hal::SimAnalogOutData;
void AnalogOutData::ResetData() {
m_voltage = 0.0;
m_voltageCallbacks = nullptr;
m_initialized = 0;
m_initializedCallbacks = nullptr;
}
int32_t AnalogOutData::RegisterVoltageCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetVoltage());
callback("Voltage", param, &value);
}
return newUid;
}
void AnalogOutData::CancelVoltageCallback(int32_t uid) {
m_voltageCallbacks = CancelCallback(m_voltageCallbacks, uid);
}
void AnalogOutData::InvokeVoltageCallback(HAL_Value value) {
InvokeCallback(m_voltageCallbacks, "Voltage", &value);
}
double AnalogOutData::GetVoltage() { return m_voltage; }
void AnalogOutData::SetVoltage(double voltage) {
double oldValue = m_voltage.exchange(voltage);
if (oldValue != voltage) {
InvokeVoltageCallback(MakeDouble(voltage));
}
}
int32_t AnalogOutData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void AnalogOutData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void AnalogOutData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool AnalogOutData::GetInitialized() { return m_initialized; }
void AnalogOutData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
voltage.Reset(0.0);
initialized.Reset(0);
}
extern "C" {
@@ -105,52 +30,20 @@ void HALSIM_ResetAnalogOutData(int32_t index) {
SimAnalogOutData[index].ResetData();
}
int32_t HALSIM_RegisterAnalogOutVoltageCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogOutData[index].RegisterVoltageCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogOut##CAPINAME, \
SimAnalogOutData, LOWERNAME)
void HALSIM_CancelAnalogOutVoltageCallback(int32_t index, int32_t uid) {
SimAnalogOutData[index].CancelVoltageCallback(uid);
}
DEFINE_CAPI(double, Voltage, voltage)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
double HALSIM_GetAnalogOutVoltage(int32_t index) {
return SimAnalogOutData[index].GetVoltage();
}
void HALSIM_SetAnalogOutVoltage(int32_t index, double voltage) {
SimAnalogOutData[index].SetVoltage(voltage);
}
int32_t HALSIM_RegisterAnalogOutInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimAnalogOutData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
void HALSIM_CancelAnalogOutInitializedCallback(int32_t index, int32_t uid) {
SimAnalogOutData[index].CancelInitializedCallback(uid);
}
HAL_Bool HALSIM_GetAnalogOutInitialized(int32_t index) {
return SimAnalogOutData[index].GetInitialized();
}
void HALSIM_SetAnalogOutInitialized(int32_t index, HAL_Bool initialized) {
SimAnalogOutData[index].SetInitialized(initialized);
}
#define REGISTER(NAME) \
SimAnalogOutData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterAnalogOutAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimAnalogOutData[index].RegisterVoltageCallback(callback, param,
initialNotify);
SimAnalogOutData[index].RegisterInitializedCallback(callback, param,
initialNotify);
REGISTER(voltage);
REGISTER(initialized);
}
} // extern "C"

View File

@@ -7,39 +7,19 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/AnalogOutData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class AnalogOutData {
public:
int32_t RegisterVoltageCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelVoltageCallback(int32_t uid);
void InvokeVoltageCallback(HAL_Value value);
double GetVoltage();
void SetVoltage(double voltage);
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
public:
SimDataValue<double, MakeDouble, GetVoltageName> voltage{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<double> m_voltage{0.0};
std::shared_ptr<NotifyListenerVector> m_voltageCallbacks = nullptr;
std::atomic<HAL_Bool> m_initialized{0};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
};
extern AnalogOutData* SimAnalogOutData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "AnalogTriggerDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,160 +21,10 @@ void InitializeAnalogTriggerData() {
AnalogTriggerData* hal::SimAnalogTriggerData;
void AnalogTriggerData::ResetData() {
m_initialized = 0;
m_initializedCallbacks = nullptr;
m_triggerLowerBound = 0;
m_triggerLowerBoundCallbacks = nullptr;
m_triggerUpperBound = 0;
m_triggerUpperBoundCallbacks = nullptr;
m_triggerMode = static_cast<HALSIM_AnalogTriggerMode>(0);
m_triggerModeCallbacks = nullptr;
}
int32_t AnalogTriggerData::RegisterInitializedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void AnalogTriggerData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void AnalogTriggerData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool AnalogTriggerData::GetInitialized() { return m_initialized; }
void AnalogTriggerData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t AnalogTriggerData::RegisterTriggerLowerBoundCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerLowerBoundCallbacks =
RegisterCallback(m_triggerLowerBoundCallbacks, "TriggerLowerBound",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetTriggerLowerBound());
callback("TriggerLowerBound", param, &value);
}
return newUid;
}
void AnalogTriggerData::CancelTriggerLowerBoundCallback(int32_t uid) {
m_triggerLowerBoundCallbacks =
CancelCallback(m_triggerLowerBoundCallbacks, uid);
}
void AnalogTriggerData::InvokeTriggerLowerBoundCallback(HAL_Value value) {
InvokeCallback(m_triggerLowerBoundCallbacks, "TriggerLowerBound", &value);
}
double AnalogTriggerData::GetTriggerLowerBound() { return m_triggerLowerBound; }
void AnalogTriggerData::SetTriggerLowerBound(double triggerLowerBound) {
double oldValue = m_triggerLowerBound.exchange(triggerLowerBound);
if (oldValue != triggerLowerBound) {
InvokeTriggerLowerBoundCallback(MakeDouble(triggerLowerBound));
}
}
int32_t AnalogTriggerData::RegisterTriggerUpperBoundCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerUpperBoundCallbacks =
RegisterCallback(m_triggerUpperBoundCallbacks, "TriggerUpperBound",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetTriggerUpperBound());
callback("TriggerUpperBound", param, &value);
}
return newUid;
}
void AnalogTriggerData::CancelTriggerUpperBoundCallback(int32_t uid) {
m_triggerUpperBoundCallbacks =
CancelCallback(m_triggerUpperBoundCallbacks, uid);
}
void AnalogTriggerData::InvokeTriggerUpperBoundCallback(HAL_Value value) {
InvokeCallback(m_triggerUpperBoundCallbacks, "TriggerUpperBound", &value);
}
double AnalogTriggerData::GetTriggerUpperBound() { return m_triggerUpperBound; }
void AnalogTriggerData::SetTriggerUpperBound(double triggerUpperBound) {
double oldValue = m_triggerUpperBound.exchange(triggerUpperBound);
if (oldValue != triggerUpperBound) {
InvokeTriggerUpperBoundCallback(MakeDouble(triggerUpperBound));
}
}
int32_t AnalogTriggerData::RegisterTriggerModeCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerModeCallbacks = RegisterCallback(
m_triggerModeCallbacks, "TriggerMode", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeEnum(GetTriggerMode());
callback("TriggerMode", param, &value);
}
return newUid;
}
void AnalogTriggerData::CancelTriggerModeCallback(int32_t uid) {
m_triggerModeCallbacks = CancelCallback(m_triggerModeCallbacks, uid);
}
void AnalogTriggerData::InvokeTriggerModeCallback(HAL_Value value) {
InvokeCallback(m_triggerModeCallbacks, "TriggerMode", &value);
}
HALSIM_AnalogTriggerMode AnalogTriggerData::GetTriggerMode() {
return m_triggerMode;
}
void AnalogTriggerData::SetTriggerMode(HALSIM_AnalogTriggerMode triggerMode) {
HALSIM_AnalogTriggerMode oldValue = m_triggerMode.exchange(triggerMode);
if (oldValue != triggerMode) {
InvokeTriggerModeCallback(MakeEnum(triggerMode));
}
initialized.Reset(0);
triggerLowerBound.Reset(0);
triggerUpperBound.Reset(0);
triggerMode.Reset(static_cast<HALSIM_AnalogTriggerMode>(0));
}
extern "C" {
@@ -183,98 +32,26 @@ void HALSIM_ResetAnalogTriggerData(int32_t index) {
SimAnalogTriggerData[index].ResetData();
}
int32_t HALSIM_RegisterAnalogTriggerInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogTriggerData[index].RegisterInitializedCallback(
callback, param, initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogTrigger##CAPINAME, \
SimAnalogTriggerData, LOWERNAME)
void HALSIM_CancelAnalogTriggerInitializedCallback(int32_t index, int32_t uid) {
SimAnalogTriggerData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, TriggerLowerBound, triggerLowerBound)
DEFINE_CAPI(double, TriggerUpperBound, triggerUpperBound)
DEFINE_CAPI(HALSIM_AnalogTriggerMode, TriggerMode, triggerMode)
HAL_Bool HALSIM_GetAnalogTriggerInitialized(int32_t index) {
return SimAnalogTriggerData[index].GetInitialized();
}
void HALSIM_SetAnalogTriggerInitialized(int32_t index, HAL_Bool initialized) {
SimAnalogTriggerData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogTriggerData[index].RegisterTriggerLowerBoundCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback(int32_t index,
int32_t uid) {
SimAnalogTriggerData[index].CancelTriggerLowerBoundCallback(uid);
}
double HALSIM_GetAnalogTriggerTriggerLowerBound(int32_t index) {
return SimAnalogTriggerData[index].GetTriggerLowerBound();
}
void HALSIM_SetAnalogTriggerTriggerLowerBound(int32_t index,
double triggerLowerBound) {
SimAnalogTriggerData[index].SetTriggerLowerBound(triggerLowerBound);
}
int32_t HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogTriggerData[index].RegisterTriggerUpperBoundCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback(int32_t index,
int32_t uid) {
SimAnalogTriggerData[index].CancelTriggerUpperBoundCallback(uid);
}
double HALSIM_GetAnalogTriggerTriggerUpperBound(int32_t index) {
return SimAnalogTriggerData[index].GetTriggerUpperBound();
}
void HALSIM_SetAnalogTriggerTriggerUpperBound(int32_t index,
double triggerUpperBound) {
SimAnalogTriggerData[index].SetTriggerUpperBound(triggerUpperBound);
}
int32_t HALSIM_RegisterAnalogTriggerTriggerModeCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimAnalogTriggerData[index].RegisterTriggerModeCallback(
callback, param, initialNotify);
}
void HALSIM_CancelAnalogTriggerTriggerModeCallback(int32_t index, int32_t uid) {
SimAnalogTriggerData[index].CancelTriggerModeCallback(uid);
}
HALSIM_AnalogTriggerMode HALSIM_GetAnalogTriggerTriggerMode(int32_t index) {
return SimAnalogTriggerData[index].GetTriggerMode();
}
void HALSIM_SetAnalogTriggerTriggerMode(int32_t index,
HALSIM_AnalogTriggerMode triggerMode) {
SimAnalogTriggerData[index].SetTriggerMode(triggerMode);
}
#define REGISTER(NAME) \
SimAnalogTriggerData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterAnalogTriggerAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimAnalogTriggerData[index].RegisterInitializedCallback(callback, param,
initialNotify);
SimAnalogTriggerData[index].RegisterTriggerLowerBoundCallback(callback, param,
initialNotify);
SimAnalogTriggerData[index].RegisterTriggerUpperBoundCallback(callback, param,
initialNotify);
SimAnalogTriggerData[index].RegisterTriggerModeCallback(callback, param,
initialNotify);
REGISTER(initialized);
REGISTER(triggerLowerBound);
REGISTER(triggerUpperBound);
REGISTER(triggerMode);
}
} // extern "C"

View File

@@ -7,60 +7,32 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/AnalogTriggerData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class AnalogTriggerData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(TriggerLowerBound)
HAL_SIMDATAVALUE_DEFINE_NAME(TriggerUpperBound)
HAL_SIMDATAVALUE_DEFINE_NAME(TriggerMode)
static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value
MakeTriggerModeValue(HALSIM_AnalogTriggerMode value) {
return MakeEnum(value);
}
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterTriggerLowerBoundCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelTriggerLowerBoundCallback(int32_t uid);
void InvokeTriggerLowerBoundCallback(HAL_Value value);
double GetTriggerLowerBound();
void SetTriggerLowerBound(double triggerLowerBound);
int32_t RegisterTriggerUpperBoundCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelTriggerUpperBoundCallback(int32_t uid);
void InvokeTriggerUpperBoundCallback(HAL_Value value);
double GetTriggerUpperBound();
void SetTriggerUpperBound(double triggerUpperBound);
int32_t RegisterTriggerModeCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelTriggerModeCallback(int32_t uid);
void InvokeTriggerModeCallback(HAL_Value value);
HALSIM_AnalogTriggerMode GetTriggerMode();
void SetTriggerMode(HALSIM_AnalogTriggerMode triggerMode);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{0};
SimDataValue<double, MakeDouble, GetTriggerLowerBoundName> triggerLowerBound{
0};
SimDataValue<double, MakeDouble, GetTriggerUpperBoundName> triggerUpperBound{
0};
SimDataValue<HALSIM_AnalogTriggerMode, MakeTriggerModeValue,
GetTriggerModeName>
triggerMode{static_cast<HALSIM_AnalogTriggerMode>(0)};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{0};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_triggerLowerBound{0};
std::shared_ptr<NotifyListenerVector> m_triggerLowerBoundCallbacks = nullptr;
std::atomic<double> m_triggerUpperBound{0};
std::shared_ptr<NotifyListenerVector> m_triggerUpperBoundCallbacks = nullptr;
std::atomic<HALSIM_AnalogTriggerMode> m_triggerMode{
static_cast<HALSIM_AnalogTriggerMode>(0)};
std::shared_ptr<NotifyListenerVector> m_triggerModeCallbacks = nullptr;
};
extern AnalogTriggerData* SimAnalogTriggerData;
} // namespace hal

View File

@@ -7,8 +7,6 @@
#include "CanDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
namespace hal {
@@ -21,276 +19,29 @@ void InitializeCanData() {
} // namespace hal
CanData* hal::SimCanData;
void InvokeCallback(std::shared_ptr<CanSendMessageListenerVector> currentVector,
const char* name, uint32_t messageID, const uint8_t* data,
uint8_t dataSize, int32_t periodMs, int32_t* status) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, messageID, data, dataSize, periodMs,
status);
}
}
void InvokeCallback(
std::shared_ptr<CanReceiveMessageListenerVector> currentVector,
const char* name, uint32_t* messageID, uint32_t messageIDMask,
uint8_t* data, uint8_t* dataSize, uint32_t* timeStamp, int32_t* status) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, messageID, messageIDMask, data,
dataSize, timeStamp, status);
}
}
void InvokeCallback(
std::shared_ptr<CanOpenStreamSessionListenerVector> currentVector,
const char* name, uint32_t* sessionHandle, uint32_t messageID,
uint32_t messageIDMask, uint32_t maxMessages, int32_t* status) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, sessionHandle, messageID,
messageIDMask, maxMessages, status);
}
}
void InvokeCallback(
std::shared_ptr<CanCloseStreamSessionListenerVector> currentVector,
const char* name, uint32_t sessionHandle) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, sessionHandle);
}
}
void InvokeCallback(
std::shared_ptr<CanReadStreamSessionListenerVector> currentVector,
const char* name, uint32_t sessionHandle,
struct HAL_CANStreamMessage* messages, uint32_t messagesToRead,
uint32_t* messagesRead, int32_t* status) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, sessionHandle, messages,
messagesToRead, messagesRead, status);
}
}
void InvokeCallback(
std::shared_ptr<CanGetCANStatusListenerVector> currentVector,
const char* name, float* percentBusUtilization, uint32_t* busOffCount,
uint32_t* txFullCount, uint32_t* receiveErrorCount,
uint32_t* transmitErrorCount, int32_t* status) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, percentBusUtilization, busOffCount,
txFullCount, receiveErrorCount, transmitErrorCount,
status);
}
}
void CanData::ResetData() {
m_sendMessageCallback = nullptr;
m_receiveMessageCallback = nullptr;
m_openStreamSessionCallback = nullptr;
m_closeStreamSessionCallback = nullptr;
m_readStreamSessionCallback = nullptr;
m_getCanStatusCallback = nullptr;
}
void CanData::SendMessage(uint32_t messageID, const uint8_t* data,
uint8_t dataSize, int32_t periodMs, int32_t* status) {
InvokeCallback(m_sendMessageCallback, "SendMessage", messageID, data,
dataSize, periodMs, status);
}
void CanData::ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
uint8_t* data, uint8_t* dataSize,
uint32_t* timeStamp, int32_t* status) {
InvokeCallback(m_receiveMessageCallback, "ReceiveMessage", messageID,
messageIDMask, data, dataSize, timeStamp, status);
}
void CanData::OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
uint32_t messageIDMask, uint32_t maxMessages,
int32_t* status) {
InvokeCallback(m_openStreamSessionCallback, "OpenStream", sessionHandle,
messageID, messageIDMask, maxMessages, status);
}
void CanData::CloseStreamSession(uint32_t sessionHandle) {
InvokeCallback(m_closeStreamSessionCallback, "CloseStream", sessionHandle);
}
void CanData::ReadStreamSession(uint32_t sessionHandle,
struct HAL_CANStreamMessage* messages,
uint32_t messagesToRead, uint32_t* messagesRead,
int32_t* status) {
InvokeCallback(m_readStreamSessionCallback, "ReadStream", sessionHandle,
messages, messagesToRead, messagesRead, status);
}
void CanData::GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount,
uint32_t* txFullCount, uint32_t* receiveErrorCount,
uint32_t* transmitErrorCount, int32_t* status) {
InvokeCallback(m_getCanStatusCallback, "GetCanStatus", percentBusUtilization,
busOffCount, txFullCount, receiveErrorCount,
transmitErrorCount, status);
}
int32_t CanData::RegisterSendMessageCallback(
HAL_CAN_SendMessageCallback callback, void* param) {
return RegisterCanCallback<CanSendMessageListenerVector,
HAL_CAN_SendMessageCallback>(
callback, m_sendMessageCallback, "SendMessage", param);
}
void CanData::CancelSendMessageCallback(int32_t uid) {
m_sendMessageCallback = CancelCallbackImpl<CanSendMessageListenerVector,
HAL_CAN_SendMessageCallback>(
m_sendMessageCallback, uid);
}
int32_t CanData::RegisterReceiveMessageCallback(
HAL_CAN_ReceiveMessageCallback callback, void* param) {
return RegisterCanCallback<CanReceiveMessageListenerVector,
HAL_CAN_ReceiveMessageCallback>(
callback, m_receiveMessageCallback, "ReceiveMessage", param);
}
void CanData::CancelReceiveMessageCallback(int32_t uid) {
m_receiveMessageCallback = CancelCallbackImpl<CanReceiveMessageListenerVector,
HAL_CAN_ReceiveMessageCallback>(
m_receiveMessageCallback, uid);
}
int32_t CanData::RegisterOpenStreamCallback(
HAL_CAN_OpenStreamSessionCallback callback, void* param) {
return RegisterCanCallback<CanOpenStreamSessionListenerVector,
HAL_CAN_OpenStreamSessionCallback>(
callback, m_openStreamSessionCallback, "OpenStream", param);
}
void CanData::CancelOpenStreamCallback(int32_t uid) {
m_openStreamSessionCallback =
CancelCallbackImpl<CanOpenStreamSessionListenerVector,
HAL_CAN_OpenStreamSessionCallback>(
m_openStreamSessionCallback, uid);
}
int32_t CanData::RegisterCloseStreamCallback(
HAL_CAN_CloseStreamSessionCallback callback, void* param) {
return RegisterCanCallback<CanCloseStreamSessionListenerVector,
HAL_CAN_CloseStreamSessionCallback>(
callback, m_closeStreamSessionCallback, "CloseStream", param);
}
void CanData::CancelCloseStreamCallback(int32_t uid) {
m_closeStreamSessionCallback =
CancelCallbackImpl<CanCloseStreamSessionListenerVector,
HAL_CAN_CloseStreamSessionCallback>(
m_closeStreamSessionCallback, uid);
}
int32_t CanData::RegisterReadStreamCallback(
HAL_CAN_ReadStreamSessionCallback callback, void* param) {
return RegisterCanCallback<CanReadStreamSessionListenerVector,
HAL_CAN_ReadStreamSessionCallback>(
callback, m_readStreamSessionCallback, "ReadStream", param);
}
void CanData::CancelReadStreamCallback(int32_t uid) {
m_readStreamSessionCallback =
CancelCallbackImpl<CanReadStreamSessionListenerVector,
HAL_CAN_ReadStreamSessionCallback>(
m_readStreamSessionCallback, uid);
}
int32_t CanData::RegisterGetCANStatusCallback(
HAL_CAN_GetCANStatusCallback callback, void* param) {
return RegisterCanCallback<CanGetCANStatusListenerVector,
HAL_CAN_GetCANStatusCallback>(
callback, m_getCanStatusCallback, "GetCANStatus", param);
}
void CanData::CancelGetCANStatusCallback(int32_t uid) {
m_getCanStatusCallback =
CancelCallbackImpl<CanGetCANStatusListenerVector,
HAL_CAN_ReadStreamSessionCallback>(
m_getCanStatusCallback, uid);
sendMessage.Reset();
receiveMessage.Reset();
openStreamSession.Reset();
closeStreamSession.Reset();
readStreamSession.Reset();
getCANStatus.Reset();
}
extern "C" {
void HALSIM_ResetCanData(void) { SimCanData->ResetData(); }
int32_t HALSIM_RegisterCanSendMessageCallback(
HAL_CAN_SendMessageCallback callback, void* param) {
return SimCanData->RegisterSendMessageCallback(callback, param);
}
void HALSIM_CancelCanSendMessageCallback(int32_t uid) {
SimCanData->CancelSendMessageCallback(uid);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI_NOINDEX(TYPE, HALSIM, Can##CAPINAME, \
SimCanData, LOWERNAME)
int32_t HALSIM_RegisterCanReceiveMessageCallback(
HAL_CAN_ReceiveMessageCallback callback, void* param) {
return SimCanData->RegisterReceiveMessageCallback(callback, param);
}
void HALSIM_CancelCanReceiveMessageCallback(int32_t uid) {
SimCanData->CancelReceiveMessageCallback(uid);
}
int32_t HALSIM_RegisterCanOpenStreamCallback(
HAL_CAN_OpenStreamSessionCallback callback, void* param) {
return SimCanData->RegisterOpenStreamCallback(callback, param);
}
void HALSIM_CancelCanOpenStreamCallback(int32_t uid) {
SimCanData->CancelOpenStreamCallback(uid);
}
int32_t HALSIM_RegisterCanCloseStreamCallback(
HAL_CAN_CloseStreamSessionCallback callback, void* param) {
return SimCanData->RegisterCloseStreamCallback(callback, param);
}
void HALSIM_CancelCanCloseStreamCallback(int32_t uid) {
SimCanData->CancelCloseStreamCallback(uid);
}
int32_t HALSIM_RegisterCanReadStreamCallback(
HAL_CAN_ReadStreamSessionCallback callback, void* param) {
return SimCanData->RegisterReadStreamCallback(callback, param);
}
void HALSIM_CancelCanReadStreamCallback(int32_t uid) {
SimCanData->CancelReadStreamCallback(uid);
}
int32_t HALSIM_RegisterCanGetCANStatusCallback(
HAL_CAN_GetCANStatusCallback callback, void* param) {
return SimCanData->RegisterGetCANStatusCallback(callback, param);
}
void HALSIM_CancelCanGetCANStatusCallback(int32_t uid) {
SimCanData->CancelGetCANStatusCallback(uid);
}
DEFINE_CAPI(HAL_CAN_SendMessageCallback, SendMessage, sendMessage)
DEFINE_CAPI(HAL_CAN_ReceiveMessageCallback, ReceiveMessage, receiveMessage)
DEFINE_CAPI(HAL_CAN_OpenStreamSessionCallback, OpenStream, openStreamSession)
DEFINE_CAPI(HAL_CAN_CloseStreamSessionCallback, CloseStream, closeStreamSession)
DEFINE_CAPI(HAL_CAN_ReadStreamSessionCallback, ReadStream, readStreamSession)
DEFINE_CAPI(HAL_CAN_GetCANStatusCallback, GetCANStatus, getCANStatus)
} // extern "C"

View File

@@ -7,103 +7,34 @@
#pragma once
#include <atomic>
#include <limits>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/CanData.h"
#include "mockdata/NotifyCallbackHelpers.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimCallbackRegistry.h"
namespace hal {
typedef HalCallbackListenerVectorImpl<HAL_CAN_SendMessageCallback>
CanSendMessageListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_CAN_ReceiveMessageCallback>
CanReceiveMessageListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_CAN_OpenStreamSessionCallback>
CanOpenStreamSessionListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_CAN_CloseStreamSessionCallback>
CanCloseStreamSessionListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_CAN_ReadStreamSessionCallback>
CanReadStreamSessionListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_CAN_GetCANStatusCallback>
CanGetCANStatusListenerVector;
class CanData {
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(SendMessage)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(ReceiveMessage)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(OpenStream)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(CloseStream)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(ReadStream)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(GetCanStatus)
public:
SimCallbackRegistry<HAL_CAN_SendMessageCallback, GetSendMessageName>
sendMessage;
SimCallbackRegistry<HAL_CAN_ReceiveMessageCallback, GetReceiveMessageName>
receiveMessage;
SimCallbackRegistry<HAL_CAN_OpenStreamSessionCallback, GetOpenStreamName>
openStreamSession;
SimCallbackRegistry<HAL_CAN_CloseStreamSessionCallback, GetCloseStreamName>
closeStreamSession;
SimCallbackRegistry<HAL_CAN_ReadStreamSessionCallback, GetReadStreamName>
readStreamSession;
SimCallbackRegistry<HAL_CAN_GetCANStatusCallback, GetGetCanStatusName>
getCANStatus;
void ResetData();
void SendMessage(uint32_t messageID, const uint8_t* data, uint8_t dataSize,
int32_t periodMs, int32_t* status);
void ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
uint8_t* data, uint8_t* dataSize, uint32_t* timeStamp,
int32_t* status);
void OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
uint32_t messageIDMask, uint32_t maxMessages,
int32_t* status);
void CloseStreamSession(uint32_t sessionHandle);
void ReadStreamSession(uint32_t sessionHandle,
struct HAL_CANStreamMessage* messages,
uint32_t messagesToRead, uint32_t* messagesRead,
int32_t* status);
void GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount,
uint32_t* txFullCount, uint32_t* receiveErrorCount,
uint32_t* transmitErrorCount, int32_t* status);
int32_t RegisterSendMessageCallback(HAL_CAN_SendMessageCallback callback,
void* param);
void CancelSendMessageCallback(int32_t uid);
int32_t RegisterReceiveMessageCallback(
HAL_CAN_ReceiveMessageCallback callback, void* param);
void CancelReceiveMessageCallback(int32_t uid);
int32_t RegisterOpenStreamCallback(HAL_CAN_OpenStreamSessionCallback callback,
void* param);
void CancelOpenStreamCallback(int32_t uid);
int32_t RegisterCloseStreamCallback(
HAL_CAN_CloseStreamSessionCallback callback, void* param);
void CancelCloseStreamCallback(int32_t uid);
int32_t RegisterReadStreamCallback(HAL_CAN_ReadStreamSessionCallback callback,
void* param);
void CancelReadStreamCallback(int32_t uid);
int32_t RegisterGetCANStatusCallback(HAL_CAN_GetCANStatusCallback callback,
void* param);
void CancelGetCANStatusCallback(int32_t uid);
protected:
template <typename VectorType, typename CallbackType>
int32_t RegisterCanCallback(CallbackType& callback,
std::shared_ptr<VectorType>& callbackVector,
const char* callbackName, void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
callbackVector = RegisterCallbackImpl(callbackVector, callbackName,
callback, param, &newUid);
}
return newUid;
}
wpi::mutex m_registerMutex;
std::shared_ptr<CanSendMessageListenerVector> m_sendMessageCallback;
std::shared_ptr<CanReceiveMessageListenerVector> m_receiveMessageCallback;
std::shared_ptr<CanOpenStreamSessionListenerVector>
m_openStreamSessionCallback;
std::shared_ptr<CanCloseStreamSessionListenerVector>
m_closeStreamSessionCallback;
std::shared_ptr<CanReadStreamSessionListenerVector>
m_readStreamSessionCallback;
std::shared_ptr<CanGetCANStatusListenerVector> m_getCanStatusCallback;
};
extern CanData* SimCanData;

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "DIODataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,303 +21,35 @@ void InitializeDIOData() {
DIOData* hal::SimDIOData;
void DIOData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_value = true;
m_valueCallbacks = nullptr;
m_pulseLength = 0.0;
m_pulseLengthCallbacks = nullptr;
m_isInput = true;
m_isInputCallbacks = nullptr;
m_filterIndex = -1;
m_filterIndexCallbacks = nullptr;
}
int32_t DIOData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void DIOData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void DIOData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool DIOData::GetInitialized() { return m_initialized; }
void DIOData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t DIOData::RegisterValueCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_valueCallbacks =
RegisterCallback(m_valueCallbacks, "Value", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetValue());
callback("Value", param, &value);
}
return newUid;
}
void DIOData::CancelValueCallback(int32_t uid) {
m_valueCallbacks = CancelCallback(m_valueCallbacks, uid);
}
void DIOData::InvokeValueCallback(HAL_Value value) {
InvokeCallback(m_valueCallbacks, "Value", &value);
}
HAL_Bool DIOData::GetValue() { return m_value; }
void DIOData::SetValue(HAL_Bool value) {
HAL_Bool oldValue = m_value.exchange(value);
if (oldValue != value) {
InvokeValueCallback(MakeBoolean(value));
}
}
int32_t DIOData::RegisterPulseLengthCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pulseLengthCallbacks = RegisterCallback(
m_pulseLengthCallbacks, "PulseLength", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetPulseLength());
callback("PulseLength", param, &value);
}
return newUid;
}
void DIOData::CancelPulseLengthCallback(int32_t uid) {
m_pulseLengthCallbacks = CancelCallback(m_pulseLengthCallbacks, uid);
}
void DIOData::InvokePulseLengthCallback(HAL_Value value) {
InvokeCallback(m_pulseLengthCallbacks, "PulseLength", &value);
}
double DIOData::GetPulseLength() { return m_pulseLength; }
void DIOData::SetPulseLength(double pulseLength) {
double oldValue = m_pulseLength.exchange(pulseLength);
if (oldValue != pulseLength) {
InvokePulseLengthCallback(MakeDouble(pulseLength));
}
}
int32_t DIOData::RegisterIsInputCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_isInputCallbacks = RegisterCallback(m_isInputCallbacks, "IsInput",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetIsInput());
callback("IsInput", param, &value);
}
return newUid;
}
void DIOData::CancelIsInputCallback(int32_t uid) {
m_isInputCallbacks = CancelCallback(m_isInputCallbacks, uid);
}
void DIOData::InvokeIsInputCallback(HAL_Value value) {
InvokeCallback(m_isInputCallbacks, "IsInput", &value);
}
HAL_Bool DIOData::GetIsInput() { return m_isInput; }
void DIOData::SetIsInput(HAL_Bool isInput) {
HAL_Bool oldValue = m_isInput.exchange(isInput);
if (oldValue != isInput) {
InvokeIsInputCallback(MakeBoolean(isInput));
}
}
int32_t DIOData::RegisterFilterIndexCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_filterIndexCallbacks = RegisterCallback(
m_filterIndexCallbacks, "FilterIndex", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetFilterIndex());
callback("FilterIndex", param, &value);
}
return newUid;
}
void DIOData::CancelFilterIndexCallback(int32_t uid) {
m_filterIndexCallbacks = CancelCallback(m_filterIndexCallbacks, uid);
}
void DIOData::InvokeFilterIndexCallback(HAL_Value value) {
InvokeCallback(m_filterIndexCallbacks, "FilterIndex", &value);
}
int32_t DIOData::GetFilterIndex() { return m_filterIndex; }
void DIOData::SetFilterIndex(int32_t filterIndex) {
int32_t oldValue = m_filterIndex.exchange(filterIndex);
if (oldValue != filterIndex) {
InvokeFilterIndexCallback(MakeInt(filterIndex));
}
initialized.Reset(false);
value.Reset(true);
pulseLength.Reset(0.0);
isInput.Reset(true);
filterIndex.Reset(-1);
}
extern "C" {
void HALSIM_ResetDIOData(int32_t index) { SimDIOData[index].ResetData(); }
int32_t HALSIM_RegisterDIOInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDIOData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, DIO##CAPINAME, SimDIOData, \
LOWERNAME)
void HALSIM_CancelDIOInitializedCallback(int32_t index, int32_t uid) {
SimDIOData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(HAL_Bool, Value, value)
DEFINE_CAPI(double, PulseLength, pulseLength)
DEFINE_CAPI(HAL_Bool, IsInput, isInput)
DEFINE_CAPI(int32_t, FilterIndex, filterIndex)
HAL_Bool HALSIM_GetDIOInitialized(int32_t index) {
return SimDIOData[index].GetInitialized();
}
void HALSIM_SetDIOInitialized(int32_t index, HAL_Bool initialized) {
SimDIOData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterDIOValueCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
return SimDIOData[index].RegisterValueCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDIOValueCallback(int32_t index, int32_t uid) {
SimDIOData[index].CancelValueCallback(uid);
}
HAL_Bool HALSIM_GetDIOValue(int32_t index) {
return SimDIOData[index].GetValue();
}
void HALSIM_SetDIOValue(int32_t index, HAL_Bool value) {
SimDIOData[index].SetValue(value);
}
int32_t HALSIM_RegisterDIOPulseLengthCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDIOData[index].RegisterPulseLengthCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDIOPulseLengthCallback(int32_t index, int32_t uid) {
SimDIOData[index].CancelPulseLengthCallback(uid);
}
double HALSIM_GetDIOPulseLength(int32_t index) {
return SimDIOData[index].GetPulseLength();
}
void HALSIM_SetDIOPulseLength(int32_t index, double pulseLength) {
SimDIOData[index].SetPulseLength(pulseLength);
}
int32_t HALSIM_RegisterDIOIsInputCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
return SimDIOData[index].RegisterIsInputCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDIOIsInputCallback(int32_t index, int32_t uid) {
SimDIOData[index].CancelIsInputCallback(uid);
}
HAL_Bool HALSIM_GetDIOIsInput(int32_t index) {
return SimDIOData[index].GetIsInput();
}
void HALSIM_SetDIOIsInput(int32_t index, HAL_Bool isInput) {
SimDIOData[index].SetIsInput(isInput);
}
int32_t HALSIM_RegisterDIOFilterIndexCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDIOData[index].RegisterFilterIndexCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDIOFilterIndexCallback(int32_t index, int32_t uid) {
SimDIOData[index].CancelFilterIndexCallback(uid);
}
int32_t HALSIM_GetDIOFilterIndex(int32_t index) {
return SimDIOData[index].GetFilterIndex();
}
void HALSIM_SetDIOFilterIndex(int32_t index, int32_t filterIndex) {
SimDIOData[index].SetFilterIndex(filterIndex);
}
#define REGISTER(NAME) \
SimDIOData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterDIOAllCallbacks(int32_t index, HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimDIOData[index].RegisterInitializedCallback(callback, param, initialNotify);
SimDIOData[index].RegisterValueCallback(callback, param, initialNotify);
SimDIOData[index].RegisterPulseLengthCallback(callback, param, initialNotify);
SimDIOData[index].RegisterIsInputCallback(callback, param, initialNotify);
SimDIOData[index].RegisterFilterIndexCallback(callback, param, initialNotify);
REGISTER(initialized);
REGISTER(value);
REGISTER(pulseLength);
REGISTER(isInput);
REGISTER(filterIndex);
}
} // extern "C"

View File

@@ -7,66 +7,25 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/DIOData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class DIOData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(Value)
HAL_SIMDATAVALUE_DEFINE_NAME(PulseLength)
HAL_SIMDATAVALUE_DEFINE_NAME(IsInput)
HAL_SIMDATAVALUE_DEFINE_NAME(FilterIndex)
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterValueCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelValueCallback(int32_t uid);
void InvokeValueCallback(HAL_Value value);
HAL_Bool GetValue();
void SetValue(HAL_Bool value);
int32_t RegisterPulseLengthCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelPulseLengthCallback(int32_t uid);
void InvokePulseLengthCallback(HAL_Value value);
double GetPulseLength();
void SetPulseLength(double pulseLength);
int32_t RegisterIsInputCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelIsInputCallback(int32_t uid);
void InvokeIsInputCallback(HAL_Value value);
HAL_Bool GetIsInput();
void SetIsInput(HAL_Bool isInput);
int32_t RegisterFilterIndexCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelFilterIndexCallback(int32_t uid);
void InvokeFilterIndexCallback(HAL_Value value);
int32_t GetFilterIndex();
void SetFilterIndex(int32_t filterIndex);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<HAL_Bool, MakeBoolean, GetValueName> value{true};
SimDataValue<double, MakeDouble, GetPulseLengthName> pulseLength{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetIsInputName> isInput{true};
SimDataValue<int32_t, MakeInt, GetFilterIndexName> filterIndex{-1};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<HAL_Bool> m_value{true};
std::shared_ptr<NotifyListenerVector> m_valueCallbacks = nullptr;
std::atomic<double> m_pulseLength{0.0};
std::shared_ptr<NotifyListenerVector> m_pulseLengthCallbacks = nullptr;
std::atomic<HAL_Bool> m_isInput{true};
std::shared_ptr<NotifyListenerVector> m_isInputCallbacks = nullptr;
std::atomic<int32_t> m_filterIndex{-1};
std::shared_ptr<NotifyListenerVector> m_filterIndexCallbacks = nullptr;
};
extern DIOData* SimDIOData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "DigitalPWMDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,120 +21,9 @@ void InitializeDigitalPWMData() {
DigitalPWMData* hal::SimDigitalPWMData;
void DigitalPWMData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_dutyCycle = false;
m_dutyCycleCallbacks = nullptr;
m_pin = 0;
m_pinCallbacks = nullptr;
}
int32_t DigitalPWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void DigitalPWMData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void DigitalPWMData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool DigitalPWMData::GetInitialized() { return m_initialized; }
void DigitalPWMData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t DigitalPWMData::RegisterDutyCycleCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_dutyCycleCallbacks = RegisterCallback(m_dutyCycleCallbacks, "DutyCycle",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetDutyCycle());
callback("DutyCycle", param, &value);
}
return newUid;
}
void DigitalPWMData::CancelDutyCycleCallback(int32_t uid) {
m_dutyCycleCallbacks = CancelCallback(m_dutyCycleCallbacks, uid);
}
void DigitalPWMData::InvokeDutyCycleCallback(HAL_Value value) {
InvokeCallback(m_dutyCycleCallbacks, "DutyCycle", &value);
}
double DigitalPWMData::GetDutyCycle() { return m_dutyCycle; }
void DigitalPWMData::SetDutyCycle(double dutyCycle) {
double oldValue = m_dutyCycle.exchange(dutyCycle);
if (oldValue != dutyCycle) {
InvokeDutyCycleCallback(MakeDouble(dutyCycle));
}
}
int32_t DigitalPWMData::RegisterPinCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pinCallbacks =
RegisterCallback(m_pinCallbacks, "Pin", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetPin());
callback("Pin", param, &value);
}
return newUid;
}
void DigitalPWMData::CancelPinCallback(int32_t uid) {
m_pinCallbacks = CancelCallback(m_pinCallbacks, uid);
}
void DigitalPWMData::InvokePinCallback(HAL_Value value) {
InvokeCallback(m_pinCallbacks, "Pin", &value);
}
int32_t DigitalPWMData::GetPin() { return m_pin; }
void DigitalPWMData::SetPin(int32_t pin) {
int32_t oldValue = m_pin.exchange(pin);
if (oldValue != pin) {
InvokePinCallback(MakeInt(pin));
}
initialized.Reset(false);
dutyCycle.Reset(0.0);
pin.Reset(0);
}
extern "C" {
@@ -143,73 +31,23 @@ void HALSIM_ResetDigitalPWMData(int32_t index) {
SimDigitalPWMData[index].ResetData();
}
int32_t HALSIM_RegisterDigitalPWMInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimDigitalPWMData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, DigitalPWM##CAPINAME, \
SimDigitalPWMData, LOWERNAME)
void HALSIM_CancelDigitalPWMInitializedCallback(int32_t index, int32_t uid) {
SimDigitalPWMData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, DutyCycle, dutyCycle)
DEFINE_CAPI(int32_t, Pin, pin)
HAL_Bool HALSIM_GetDigitalPWMInitialized(int32_t index) {
return SimDigitalPWMData[index].GetInitialized();
}
void HALSIM_SetDigitalPWMInitialized(int32_t index, HAL_Bool initialized) {
SimDigitalPWMData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterDigitalPWMDutyCycleCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDigitalPWMData[index].RegisterDutyCycleCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDigitalPWMDutyCycleCallback(int32_t index, int32_t uid) {
SimDigitalPWMData[index].CancelDutyCycleCallback(uid);
}
double HALSIM_GetDigitalPWMDutyCycle(int32_t index) {
return SimDigitalPWMData[index].GetDutyCycle();
}
void HALSIM_SetDigitalPWMDutyCycle(int32_t index, double dutyCycle) {
SimDigitalPWMData[index].SetDutyCycle(dutyCycle);
}
int32_t HALSIM_RegisterDigitalPWMPinCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDigitalPWMData[index].RegisterPinCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDigitalPWMPinCallback(int32_t index, int32_t uid) {
SimDigitalPWMData[index].CancelPinCallback(uid);
}
int32_t HALSIM_GetDigitalPWMPin(int32_t index) {
return SimDigitalPWMData[index].GetPin();
}
void HALSIM_SetDigitalPWMPin(int32_t index, int32_t pin) {
SimDigitalPWMData[index].SetPin(pin);
}
#define REGISTER(NAME) \
SimDigitalPWMData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterDigitalPWMAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimDigitalPWMData[index].RegisterInitializedCallback(callback, param,
initialNotify);
SimDigitalPWMData[index].RegisterDutyCycleCallback(callback, param,
initialNotify);
SimDigitalPWMData[index].RegisterPinCallback(callback, param, initialNotify);
REGISTER(initialized);
REGISTER(dutyCycle);
REGISTER(pin);
}
} // extern "C"

View File

@@ -7,48 +7,21 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/DigitalPWMData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class DigitalPWMData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(DutyCycle)
HAL_SIMDATAVALUE_DEFINE_NAME(Pin)
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterDutyCycleCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelDutyCycleCallback(int32_t uid);
void InvokeDutyCycleCallback(HAL_Value value);
double GetDutyCycle();
void SetDutyCycle(double dutyCycle);
int32_t RegisterPinCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelPinCallback(int32_t uid);
void InvokePinCallback(HAL_Value value);
int32_t GetPin();
void SetPin(int32_t pin);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<double, MakeDouble, GetDutyCycleName> dutyCycle{0.0};
SimDataValue<int32_t, MakeInt, GetPinName> pin{0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_dutyCycle{false};
std::shared_ptr<NotifyListenerVector> m_dutyCycleCallbacks = nullptr;
std::atomic<int32_t> m_pin{0};
std::shared_ptr<NotifyListenerVector> m_pinCallbacks = nullptr;
};
extern DigitalPWMData* SimDigitalPWMData;
} // namespace hal

View File

@@ -10,7 +10,6 @@
#include <string>
#include "DriverStationDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
namespace hal {
struct JoystickOutputStore {
@@ -36,21 +35,17 @@ DriverStationData* hal::SimDriverStationData;
DriverStationData::DriverStationData() { ResetData(); }
void DriverStationData::ResetData() {
m_enabled = false;
m_enabledCallbacks = nullptr;
m_autonomous = false;
m_autonomousCallbacks = nullptr;
m_test = false;
m_testCallbacks = nullptr;
m_eStop = false;
m_eStopCallbacks = nullptr;
m_fmsAttached = false;
m_fmsAttachedCallbacks = nullptr;
m_dsAttached = false;
m_dsAttachedCallbacks = nullptr;
enabled.Reset(false);
autonomous.Reset(false);
test.Reset(false);
eStop.Reset(false);
fmsAttached.Reset(false);
dsAttached.Reset(false);
allianceStationId.Reset(static_cast<HAL_AllianceStationID>(0));
matchTime.Reset(0.0);
{
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickAxes = std::make_unique<HAL_JoystickAxes[]>(6);
m_joystickPOVs = std::make_unique<HAL_JoystickPOVs[]>(6);
m_joystickButtons = std::make_unique<HAL_JoystickButtons[]>(6);
@@ -67,319 +62,30 @@ void DriverStationData::ResetData() {
}
}
{
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
std::lock_guard<wpi::spinlock> lock(m_matchInfoMutex);
m_matchInfo = std::make_unique<HAL_MatchInfo>();
}
}
int32_t DriverStationData::RegisterEnabledCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_enabledCallbacks = RegisterCallback(m_enabledCallbacks, "Enabled",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetEnabled());
callback("Enabled", param, &value);
}
return newUid;
}
void DriverStationData::CancelEnabledCallback(int32_t uid) {
m_enabledCallbacks = CancelCallback(m_enabledCallbacks, uid);
}
void DriverStationData::InvokeEnabledCallback(HAL_Value value) {
InvokeCallback(m_enabledCallbacks, "Enabled", &value);
}
HAL_Bool DriverStationData::GetEnabled() { return m_enabled; }
void DriverStationData::SetEnabled(HAL_Bool enabled) {
HAL_Bool oldValue = m_enabled.exchange(enabled);
if (oldValue != enabled) {
InvokeEnabledCallback(MakeBoolean(enabled));
}
}
int32_t DriverStationData::RegisterAutonomousCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_autonomousCallbacks = RegisterCallback(
m_autonomousCallbacks, "Autonomous", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetAutonomous());
callback("Autonomous", param, &value);
}
return newUid;
}
void DriverStationData::CancelAutonomousCallback(int32_t uid) {
m_autonomousCallbacks = CancelCallback(m_autonomousCallbacks, uid);
}
void DriverStationData::InvokeAutonomousCallback(HAL_Value value) {
InvokeCallback(m_autonomousCallbacks, "Autonomous", &value);
}
HAL_Bool DriverStationData::GetAutonomous() { return m_autonomous; }
void DriverStationData::SetAutonomous(HAL_Bool autonomous) {
HAL_Bool oldValue = m_autonomous.exchange(autonomous);
if (oldValue != autonomous) {
InvokeAutonomousCallback(MakeBoolean(autonomous));
}
}
int32_t DriverStationData::RegisterTestCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_testCallbacks =
RegisterCallback(m_testCallbacks, "Test", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetTest());
callback("Test", param, &value);
}
return newUid;
}
void DriverStationData::CancelTestCallback(int32_t uid) {
m_testCallbacks = CancelCallback(m_testCallbacks, uid);
}
void DriverStationData::InvokeTestCallback(HAL_Value value) {
InvokeCallback(m_testCallbacks, "Test", &value);
}
HAL_Bool DriverStationData::GetTest() { return m_test; }
void DriverStationData::SetTest(HAL_Bool test) {
HAL_Bool oldValue = m_test.exchange(test);
if (oldValue != test) {
InvokeTestCallback(MakeBoolean(test));
}
}
int32_t DriverStationData::RegisterEStopCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_eStopCallbacks =
RegisterCallback(m_eStopCallbacks, "EStop", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetEStop());
callback("EStop", param, &value);
}
return newUid;
}
void DriverStationData::CancelEStopCallback(int32_t uid) {
m_eStopCallbacks = CancelCallback(m_eStopCallbacks, uid);
}
void DriverStationData::InvokeEStopCallback(HAL_Value value) {
InvokeCallback(m_eStopCallbacks, "EStop", &value);
}
HAL_Bool DriverStationData::GetEStop() { return m_eStop; }
void DriverStationData::SetEStop(HAL_Bool eStop) {
HAL_Bool oldValue = m_eStop.exchange(eStop);
if (oldValue != eStop) {
InvokeEStopCallback(MakeBoolean(eStop));
}
}
int32_t DriverStationData::RegisterFmsAttachedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_fmsAttachedCallbacks = RegisterCallback(
m_fmsAttachedCallbacks, "FmsAttached", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetFmsAttached());
callback("FmsAttached", param, &value);
}
return newUid;
}
void DriverStationData::CancelFmsAttachedCallback(int32_t uid) {
m_fmsAttachedCallbacks = CancelCallback(m_fmsAttachedCallbacks, uid);
}
void DriverStationData::InvokeFmsAttachedCallback(HAL_Value value) {
InvokeCallback(m_fmsAttachedCallbacks, "FmsAttached", &value);
}
HAL_Bool DriverStationData::GetFmsAttached() { return m_fmsAttached; }
void DriverStationData::SetFmsAttached(HAL_Bool fmsAttached) {
HAL_Bool oldValue = m_fmsAttached.exchange(fmsAttached);
if (oldValue != fmsAttached) {
InvokeFmsAttachedCallback(MakeBoolean(fmsAttached));
}
}
int32_t DriverStationData::RegisterDsAttachedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_dsAttachedCallbacks = RegisterCallback(
m_dsAttachedCallbacks, "DsAttached", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetDsAttached());
callback("DsAttached", param, &value);
}
return newUid;
}
void DriverStationData::CancelDsAttachedCallback(int32_t uid) {
m_dsAttachedCallbacks = CancelCallback(m_dsAttachedCallbacks, uid);
}
void DriverStationData::InvokeDsAttachedCallback(HAL_Value value) {
InvokeCallback(m_dsAttachedCallbacks, "DsAttached", &value);
}
HAL_Bool DriverStationData::GetDsAttached() { return m_dsAttached; }
void DriverStationData::SetDsAttached(HAL_Bool dsAttached) {
HAL_Bool oldValue = m_dsAttached.exchange(dsAttached);
if (oldValue != dsAttached) {
InvokeDsAttachedCallback(MakeBoolean(dsAttached));
}
}
int32_t DriverStationData::RegisterAllianceStationIdCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_allianceStationIdCallbacks =
RegisterCallback(m_allianceStationIdCallbacks, "AllianceStationId",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeEnum(GetAllianceStationId());
callback("AllianceStationId", param, &value);
}
return newUid;
}
void DriverStationData::CancelAllianceStationIdCallback(int32_t uid) {
m_allianceStationIdCallbacks =
CancelCallback(m_allianceStationIdCallbacks, uid);
}
void DriverStationData::InvokeAllianceStationIdCallback(HAL_Value value) {
InvokeCallback(m_allianceStationIdCallbacks, "AllianceStationId", &value);
}
HAL_AllianceStationID DriverStationData::GetAllianceStationId() {
return m_allianceStationId;
}
void DriverStationData::SetAllianceStationId(
HAL_AllianceStationID allianceStationId) {
HAL_AllianceStationID oldValue =
m_allianceStationId.exchange(allianceStationId);
if (oldValue != allianceStationId) {
InvokeAllianceStationIdCallback(MakeEnum(allianceStationId));
}
}
int32_t DriverStationData::RegisterMatchTimeCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_matchTimeCallbacks = RegisterCallback(m_matchTimeCallbacks, "MatchTime",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetMatchTime());
callback("MatchTime", param, &value);
}
return newUid;
}
void DriverStationData::CancelMatchTimeCallback(int32_t uid) {
m_matchTimeCallbacks = CancelCallback(m_matchTimeCallbacks, uid);
}
void DriverStationData::InvokeMatchTimeCallback(HAL_Value value) {
InvokeCallback(m_matchTimeCallbacks, "MatchTime", &value);
}
double DriverStationData::GetMatchTime() { return m_matchTime; }
void DriverStationData::SetMatchTime(double matchTime) {
double oldValue = m_matchTime.exchange(matchTime);
if (oldValue != matchTime) {
InvokeMatchTimeCallback(MakeDouble(matchTime));
}
}
void DriverStationData::GetJoystickAxes(int32_t joystickNum,
HAL_JoystickAxes* axes) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
*axes = m_joystickAxes[joystickNum];
}
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
HAL_JoystickPOVs* povs) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
*povs = m_joystickPOVs[joystickNum];
}
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
HAL_JoystickButtons* buttons) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
*buttons = m_joystickButtons[joystickNum];
}
void DriverStationData::GetJoystickDescriptor(
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
*descriptor = m_joystickDescriptor[joystickNum];
// Always ensure name is null terminated
descriptor->name[255] = '\0';
@@ -388,49 +94,49 @@ void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
int64_t* outputs,
int32_t* leftRumble,
int32_t* rightRumble) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
*leftRumble = m_joystickOutputs[joystickNum].leftRumble;
*outputs = m_joystickOutputs[joystickNum].outputs;
*rightRumble = m_joystickOutputs[joystickNum].rightRumble;
}
void DriverStationData::GetMatchInfo(HAL_MatchInfo* info) {
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
std::lock_guard<wpi::spinlock> lock(m_matchInfoMutex);
*info = *m_matchInfo;
}
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
const HAL_JoystickAxes* axes) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickAxes[joystickNum] = *axes;
}
void DriverStationData::SetJoystickPOVs(int32_t joystickNum,
const HAL_JoystickPOVs* povs) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickPOVs[joystickNum] = *povs;
}
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickButtons[joystickNum] = *buttons;
}
void DriverStationData::SetJoystickDescriptor(
int32_t joystickNum, const HAL_JoystickDescriptor* descriptor) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickDescriptor[joystickNum] = *descriptor;
}
void DriverStationData::SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble,
int32_t rightRumble) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
m_joystickOutputs[joystickNum].leftRumble = leftRumble;
m_joystickOutputs[joystickNum].outputs = outputs;
m_joystickOutputs[joystickNum].rightRumble = rightRumble;
}
void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
std::lock_guard<wpi::spinlock> lock(m_matchInfoMutex);
*m_matchInfo = *info;
*(std::end(m_matchInfo->eventName) - 1) = '\0';
}
@@ -440,129 +146,18 @@ void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
extern "C" {
void HALSIM_ResetDriverStationData(void) { SimDriverStationData->ResetData(); }
int32_t HALSIM_RegisterDriverStationEnabledCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDriverStationData->RegisterEnabledCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationEnabledCallback(int32_t uid) {
SimDriverStationData->CancelEnabledCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationEnabled(void) {
return SimDriverStationData->GetEnabled();
}
void HALSIM_SetDriverStationEnabled(HAL_Bool enabled) {
SimDriverStationData->SetEnabled(enabled);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI_NOINDEX(TYPE, HALSIM, DriverStation##CAPINAME, \
SimDriverStationData, LOWERNAME)
int32_t HALSIM_RegisterDriverStationAutonomousCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return SimDriverStationData->RegisterAutonomousCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationAutonomousCallback(int32_t uid) {
SimDriverStationData->CancelAutonomousCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationAutonomous(void) {
return SimDriverStationData->GetAutonomous();
}
void HALSIM_SetDriverStationAutonomous(HAL_Bool autonomous) {
SimDriverStationData->SetAutonomous(autonomous);
}
int32_t HALSIM_RegisterDriverStationTestCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDriverStationData->RegisterTestCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationTestCallback(int32_t uid) {
SimDriverStationData->CancelTestCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationTest(void) {
return SimDriverStationData->GetTest();
}
void HALSIM_SetDriverStationTest(HAL_Bool test) {
SimDriverStationData->SetTest(test);
}
int32_t HALSIM_RegisterDriverStationEStopCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimDriverStationData->RegisterEStopCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationEStopCallback(int32_t uid) {
SimDriverStationData->CancelEStopCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationEStop(void) {
return SimDriverStationData->GetEStop();
}
void HALSIM_SetDriverStationEStop(HAL_Bool eStop) {
SimDriverStationData->SetEStop(eStop);
}
int32_t HALSIM_RegisterDriverStationFmsAttachedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return SimDriverStationData->RegisterFmsAttachedCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationFmsAttachedCallback(int32_t uid) {
SimDriverStationData->CancelFmsAttachedCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationFmsAttached(void) {
return SimDriverStationData->GetFmsAttached();
}
void HALSIM_SetDriverStationFmsAttached(HAL_Bool fmsAttached) {
SimDriverStationData->SetFmsAttached(fmsAttached);
}
int32_t HALSIM_RegisterDriverStationDsAttachedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return SimDriverStationData->RegisterDsAttachedCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationDsAttachedCallback(int32_t uid) {
SimDriverStationData->CancelDsAttachedCallback(uid);
}
HAL_Bool HALSIM_GetDriverStationDsAttached(void) {
return SimDriverStationData->GetDsAttached();
}
void HALSIM_SetDriverStationDsAttached(HAL_Bool dsAttached) {
SimDriverStationData->SetDsAttached(dsAttached);
}
int32_t HALSIM_RegisterDriverStationAllianceStationIdCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return SimDriverStationData->RegisterAllianceStationIdCallback(
callback, param, initialNotify);
}
void HALSIM_CancelDriverStationAllianceStationIdCallback(int32_t uid) {
SimDriverStationData->CancelAllianceStationIdCallback(uid);
}
HAL_AllianceStationID HALSIM_GetDriverStationAllianceStationId(void) {
return SimDriverStationData->GetAllianceStationId();
}
void HALSIM_SetDriverStationAllianceStationId(
HAL_AllianceStationID allianceStationId) {
SimDriverStationData->SetAllianceStationId(allianceStationId);
}
int32_t HALSIM_RegisterDriverStationMatchTimeCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
return SimDriverStationData->RegisterMatchTimeCallback(callback, param,
initialNotify);
}
void HALSIM_CancelDriverStationMatchTimeCallback(int32_t uid) {
SimDriverStationData->CancelMatchTimeCallback(uid);
}
double HALSIM_GetDriverStationMatchTime(void) {
return SimDriverStationData->GetMatchTime();
}
void HALSIM_SetDriverStationMatchTime(double matchTime) {
SimDriverStationData->SetMatchTime(matchTime);
}
DEFINE_CAPI(HAL_Bool, Enabled, enabled)
DEFINE_CAPI(HAL_Bool, Autonomous, autonomous)
DEFINE_CAPI(HAL_Bool, Test, test)
DEFINE_CAPI(HAL_Bool, EStop, eStop)
DEFINE_CAPI(HAL_Bool, FmsAttached, fmsAttached)
DEFINE_CAPI(HAL_Bool, DsAttached, dsAttached)
DEFINE_CAPI(HAL_AllianceStationID, AllianceStationId, allianceStationId)
DEFINE_CAPI(double, MatchTime, matchTime)
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes) {
SimDriverStationData->SetJoystickAxes(joystickNum, axes);
@@ -595,21 +190,19 @@ void HALSIM_NotifyDriverStationNewData(void) {
SimDriverStationData->NotifyNewData();
}
#define REGISTER(NAME) \
SimDriverStationData->NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimDriverStationData->RegisterEnabledCallback(callback, param, initialNotify);
SimDriverStationData->RegisterAutonomousCallback(callback, param,
initialNotify);
SimDriverStationData->RegisterTestCallback(callback, param, initialNotify);
SimDriverStationData->RegisterEStopCallback(callback, param, initialNotify);
SimDriverStationData->RegisterFmsAttachedCallback(callback, param,
initialNotify);
SimDriverStationData->RegisterDsAttachedCallback(callback, param,
initialNotify);
SimDriverStationData->RegisterAllianceStationIdCallback(callback, param,
initialNotify);
SimDriverStationData->RegisterMatchTimeCallback(callback, param,
initialNotify);
REGISTER(enabled);
REGISTER(autonomous);
REGISTER(test);
REGISTER(eStop);
REGISTER(fmsAttached);
REGISTER(dsAttached);
REGISTER(allianceStationId);
REGISTER(matchTime);
}
} // extern "C"

View File

@@ -7,80 +7,35 @@
#pragma once
#include <array>
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include <wpi/spinlock.h>
#include "mockdata/DriverStationData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
struct JoystickOutputStore;
class DriverStationData {
HAL_SIMDATAVALUE_DEFINE_NAME(Enabled)
HAL_SIMDATAVALUE_DEFINE_NAME(Autonomous)
HAL_SIMDATAVALUE_DEFINE_NAME(Test)
HAL_SIMDATAVALUE_DEFINE_NAME(EStop)
HAL_SIMDATAVALUE_DEFINE_NAME(FmsAttached)
HAL_SIMDATAVALUE_DEFINE_NAME(DsAttached)
HAL_SIMDATAVALUE_DEFINE_NAME(AllianceStationId)
HAL_SIMDATAVALUE_DEFINE_NAME(MatchTime)
static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value
MakeAllianceStationIdValue(HAL_AllianceStationID value) {
return MakeEnum(value);
}
public:
DriverStationData();
void ResetData();
int32_t RegisterEnabledCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelEnabledCallback(int32_t uid);
void InvokeEnabledCallback(HAL_Value value);
HAL_Bool GetEnabled();
void SetEnabled(HAL_Bool enabled);
int32_t RegisterAutonomousCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelAutonomousCallback(int32_t uid);
void InvokeAutonomousCallback(HAL_Value value);
HAL_Bool GetAutonomous();
void SetAutonomous(HAL_Bool autonomous);
int32_t RegisterTestCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelTestCallback(int32_t uid);
void InvokeTestCallback(HAL_Value value);
HAL_Bool GetTest();
void SetTest(HAL_Bool test);
int32_t RegisterEStopCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelEStopCallback(int32_t uid);
void InvokeEStopCallback(HAL_Value value);
HAL_Bool GetEStop();
void SetEStop(HAL_Bool eStop);
int32_t RegisterFmsAttachedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelFmsAttachedCallback(int32_t uid);
void InvokeFmsAttachedCallback(HAL_Value value);
HAL_Bool GetFmsAttached();
void SetFmsAttached(HAL_Bool fmsAttached);
int32_t RegisterDsAttachedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelDsAttachedCallback(int32_t uid);
void InvokeDsAttachedCallback(HAL_Value value);
HAL_Bool GetDsAttached();
void SetDsAttached(HAL_Bool dsAttached);
int32_t RegisterAllianceStationIdCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelAllianceStationIdCallback(int32_t uid);
void InvokeAllianceStationIdCallback(HAL_Value value);
HAL_AllianceStationID GetAllianceStationId();
void SetAllianceStationId(HAL_AllianceStationID allianceStationId);
int32_t RegisterMatchTimeCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelMatchTimeCallback(int32_t uid);
void InvokeMatchTimeCallback(HAL_Value value);
double GetMatchTime();
void SetMatchTime(double matchTime);
void GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
void GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
void GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons* buttons);
@@ -103,28 +58,20 @@ class DriverStationData {
void NotifyNewData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_enabled{false};
std::shared_ptr<NotifyListenerVector> m_enabledCallbacks = nullptr;
std::atomic<HAL_Bool> m_autonomous{false};
std::shared_ptr<NotifyListenerVector> m_autonomousCallbacks = nullptr;
std::atomic<HAL_Bool> m_test{false};
std::shared_ptr<NotifyListenerVector> m_testCallbacks = nullptr;
std::atomic<HAL_Bool> m_eStop{false};
std::shared_ptr<NotifyListenerVector> m_eStopCallbacks = nullptr;
std::atomic<HAL_Bool> m_fmsAttached{false};
std::shared_ptr<NotifyListenerVector> m_fmsAttachedCallbacks = nullptr;
std::atomic<HAL_Bool> m_dsAttached{false};
std::shared_ptr<NotifyListenerVector> m_dsAttachedCallbacks = nullptr;
std::atomic<HAL_AllianceStationID> m_allianceStationId{
static_cast<HAL_AllianceStationID>(0)};
std::shared_ptr<NotifyListenerVector> m_allianceStationIdCallbacks = nullptr;
std::atomic<double> m_matchTime{0.0};
std::shared_ptr<NotifyListenerVector> m_matchTimeCallbacks = nullptr;
SimDataValue<HAL_Bool, MakeBoolean, GetEnabledName> enabled{false};
SimDataValue<HAL_Bool, MakeBoolean, GetAutonomousName> autonomous{false};
SimDataValue<HAL_Bool, MakeBoolean, GetTestName> test{false};
SimDataValue<HAL_Bool, MakeBoolean, GetEStopName> eStop{false};
SimDataValue<HAL_Bool, MakeBoolean, GetFmsAttachedName> fmsAttached{false};
SimDataValue<HAL_Bool, MakeBoolean, GetDsAttachedName> dsAttached{false};
SimDataValue<HAL_AllianceStationID, MakeAllianceStationIdValue,
GetAllianceStationIdName>
allianceStationId{static_cast<HAL_AllianceStationID>(0)};
SimDataValue<double, MakeDouble, GetMatchTimeName> matchTime{0.0};
wpi::mutex m_joystickDataMutex;
wpi::mutex m_matchInfoMutex;
private:
wpi::spinlock m_joystickDataMutex;
wpi::spinlock m_matchInfoMutex;
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "EncoderDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,357 +21,16 @@ void InitializeEncoderData() {
EncoderData* hal::SimEncoderData;
void EncoderData::ResetData() {
m_digitalChannelA = 0;
m_initialized = false;
m_initializedCallbacks = nullptr;
m_count = 0;
m_countCallbacks = nullptr;
m_period = std::numeric_limits<double>::max();
m_periodCallbacks = nullptr;
m_reset = false;
m_resetCallbacks = nullptr;
m_maxPeriod = 0;
m_maxPeriodCallbacks = nullptr;
m_direction = false;
m_directionCallbacks = nullptr;
m_reverseDirection = false;
m_reverseDirectionCallbacks = nullptr;
m_samplesToAverage = 0;
m_samplesToAverageCallbacks = nullptr;
m_distancePerPulse = 1;
m_distancePerPulseCallbacks = nullptr;
}
void EncoderData::SetDigitalChannelA(int16_t channel) {
m_digitalChannelA = channel;
}
int16_t EncoderData::GetDigitalChannelA() const { return m_digitalChannelA; }
int32_t EncoderData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void EncoderData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void EncoderData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool EncoderData::GetInitialized() { return m_initialized; }
void EncoderData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t EncoderData::RegisterCountCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_countCallbacks =
RegisterCallback(m_countCallbacks, "Count", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetCount());
callback("Count", param, &value);
}
return newUid;
}
void EncoderData::CancelCountCallback(int32_t uid) {
m_countCallbacks = CancelCallback(m_countCallbacks, uid);
}
void EncoderData::InvokeCountCallback(HAL_Value value) {
InvokeCallback(m_countCallbacks, "Count", &value);
}
int32_t EncoderData::GetCount() { return m_count; }
void EncoderData::SetCount(int32_t count) {
int32_t oldValue = m_count.exchange(count);
if (oldValue != count) {
InvokeCountCallback(MakeInt(count));
}
}
int32_t EncoderData::RegisterPeriodCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_periodCallbacks =
RegisterCallback(m_periodCallbacks, "Period", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetPeriod());
callback("Period", param, &value);
}
return newUid;
}
void EncoderData::CancelPeriodCallback(int32_t uid) {
m_periodCallbacks = CancelCallback(m_periodCallbacks, uid);
}
void EncoderData::InvokePeriodCallback(HAL_Value value) {
InvokeCallback(m_periodCallbacks, "Period", &value);
}
double EncoderData::GetPeriod() { return m_period; }
void EncoderData::SetPeriod(double period) {
double oldValue = m_period.exchange(period);
if (oldValue != period) {
InvokePeriodCallback(MakeDouble(period));
}
}
int32_t EncoderData::RegisterResetCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_resetCallbacks =
RegisterCallback(m_resetCallbacks, "Reset", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetReset());
callback("Reset", param, &value);
}
return newUid;
}
void EncoderData::CancelResetCallback(int32_t uid) {
m_resetCallbacks = CancelCallback(m_resetCallbacks, uid);
}
void EncoderData::InvokeResetCallback(HAL_Value value) {
InvokeCallback(m_resetCallbacks, "Reset", &value);
}
HAL_Bool EncoderData::GetReset() { return m_reset; }
void EncoderData::SetReset(HAL_Bool reset) {
HAL_Bool oldValue = m_reset.exchange(reset);
if (oldValue != reset) {
InvokeResetCallback(MakeBoolean(reset));
}
}
int32_t EncoderData::RegisterMaxPeriodCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_maxPeriodCallbacks = RegisterCallback(m_maxPeriodCallbacks, "MaxPeriod",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetMaxPeriod());
callback("MaxPeriod", param, &value);
}
return newUid;
}
void EncoderData::CancelMaxPeriodCallback(int32_t uid) {
m_maxPeriodCallbacks = CancelCallback(m_maxPeriodCallbacks, uid);
}
void EncoderData::InvokeMaxPeriodCallback(HAL_Value value) {
InvokeCallback(m_maxPeriodCallbacks, "MaxPeriod", &value);
}
double EncoderData::GetMaxPeriod() { return m_maxPeriod; }
void EncoderData::SetMaxPeriod(double maxPeriod) {
double oldValue = m_maxPeriod.exchange(maxPeriod);
if (oldValue != maxPeriod) {
InvokeMaxPeriodCallback(MakeDouble(maxPeriod));
}
}
int32_t EncoderData::RegisterDirectionCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_directionCallbacks = RegisterCallback(m_directionCallbacks, "Direction",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetDirection());
callback("Direction", param, &value);
}
return newUid;
}
void EncoderData::CancelDirectionCallback(int32_t uid) {
m_directionCallbacks = CancelCallback(m_directionCallbacks, uid);
}
void EncoderData::InvokeDirectionCallback(HAL_Value value) {
InvokeCallback(m_directionCallbacks, "Direction", &value);
}
HAL_Bool EncoderData::GetDirection() { return m_direction; }
void EncoderData::SetDirection(HAL_Bool direction) {
HAL_Bool oldValue = m_direction.exchange(direction);
if (oldValue != direction) {
InvokeDirectionCallback(MakeBoolean(direction));
}
}
int32_t EncoderData::RegisterReverseDirectionCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_reverseDirectionCallbacks =
RegisterCallback(m_reverseDirectionCallbacks, "ReverseDirection",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetReverseDirection());
callback("ReverseDirection", param, &value);
}
return newUid;
}
void EncoderData::CancelReverseDirectionCallback(int32_t uid) {
m_reverseDirectionCallbacks =
CancelCallback(m_reverseDirectionCallbacks, uid);
}
void EncoderData::InvokeReverseDirectionCallback(HAL_Value value) {
InvokeCallback(m_reverseDirectionCallbacks, "ReverseDirection", &value);
}
HAL_Bool EncoderData::GetReverseDirection() { return m_reverseDirection; }
void EncoderData::SetReverseDirection(HAL_Bool reverseDirection) {
HAL_Bool oldValue = m_reverseDirection.exchange(reverseDirection);
if (oldValue != reverseDirection) {
InvokeReverseDirectionCallback(MakeBoolean(reverseDirection));
}
}
int32_t EncoderData::RegisterSamplesToAverageCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_samplesToAverageCallbacks =
RegisterCallback(m_samplesToAverageCallbacks, "SamplesToAverage",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetSamplesToAverage());
callback("SamplesToAverage", param, &value);
}
return newUid;
}
void EncoderData::CancelSamplesToAverageCallback(int32_t uid) {
m_samplesToAverageCallbacks =
CancelCallback(m_samplesToAverageCallbacks, uid);
}
void EncoderData::InvokeSamplesToAverageCallback(HAL_Value value) {
InvokeCallback(m_samplesToAverageCallbacks, "SamplesToAverage", &value);
}
int32_t EncoderData::GetSamplesToAverage() { return m_samplesToAverage; }
void EncoderData::SetSamplesToAverage(int32_t samplesToAverage) {
int32_t oldValue = m_samplesToAverage.exchange(samplesToAverage);
if (oldValue != samplesToAverage) {
InvokeSamplesToAverageCallback(MakeInt(samplesToAverage));
}
}
int32_t EncoderData::RegisterDistancePerPulseCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_distancePerPulseCallbacks =
RegisterCallback(m_distancePerPulseCallbacks, "DistancePerPulse",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetDistancePerPulse());
callback("DistancePerPulse", param, &value);
}
return newUid;
}
void EncoderData::CancelDistancePerPulseCallback(int32_t uid) {
m_distancePerPulseCallbacks =
CancelCallback(m_distancePerPulseCallbacks, uid);
}
void EncoderData::InvokeDistancePerPulseCallback(HAL_Value value) {
InvokeCallback(m_distancePerPulseCallbacks, "DistancePerPulse", &value);
}
double EncoderData::GetDistancePerPulse() { return m_distancePerPulse; }
void EncoderData::SetDistancePerPulse(double distancePerPulse) {
double oldValue = m_distancePerPulse.exchange(distancePerPulse);
if (oldValue != distancePerPulse) {
InvokeDistancePerPulseCallback(MakeDouble(distancePerPulse));
}
digitalChannelA = 0;
initialized.Reset(false);
count.Reset(0);
period.Reset(std::numeric_limits<double>::max());
reset.Reset(false);
maxPeriod.Reset(0);
direction.Reset(false);
reverseDirection.Reset(false);
samplesToAverage.Reset(0);
distancePerPulse.Reset(1);
}
extern "C" {
@@ -381,205 +39,37 @@ void HALSIM_ResetEncoderData(int32_t index) {
}
int16_t HALSIM_GetDigitalChannelA(int32_t index) {
return SimEncoderData[index].GetDigitalChannelA();
return SimEncoderData[index].digitalChannelA;
}
int32_t HALSIM_RegisterEncoderInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Encoder##CAPINAME, \
SimEncoderData, LOWERNAME)
void HALSIM_CancelEncoderInitializedCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(int32_t, Count, count)
DEFINE_CAPI(double, Period, period)
DEFINE_CAPI(HAL_Bool, Reset, reset)
DEFINE_CAPI(double, MaxPeriod, maxPeriod)
DEFINE_CAPI(HAL_Bool, Direction, direction)
DEFINE_CAPI(HAL_Bool, ReverseDirection, reverseDirection)
DEFINE_CAPI(int32_t, SamplesToAverage, samplesToAverage)
DEFINE_CAPI(double, DistancePerPulse, distancePerPulse)
HAL_Bool HALSIM_GetEncoderInitialized(int32_t index) {
return SimEncoderData[index].GetInitialized();
}
void HALSIM_SetEncoderInitialized(int32_t index, HAL_Bool initialized) {
SimEncoderData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterEncoderCountCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterCountCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderCountCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelCountCallback(uid);
}
int32_t HALSIM_GetEncoderCount(int32_t index) {
return SimEncoderData[index].GetCount();
}
void HALSIM_SetEncoderCount(int32_t index, int32_t count) {
SimEncoderData[index].SetCount(count);
}
int32_t HALSIM_RegisterEncoderPeriodCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterPeriodCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderPeriodCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelPeriodCallback(uid);
}
double HALSIM_GetEncoderPeriod(int32_t index) {
return SimEncoderData[index].GetPeriod();
}
void HALSIM_SetEncoderPeriod(int32_t index, double period) {
SimEncoderData[index].SetPeriod(period);
}
int32_t HALSIM_RegisterEncoderResetCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterResetCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderResetCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelResetCallback(uid);
}
HAL_Bool HALSIM_GetEncoderReset(int32_t index) {
return SimEncoderData[index].GetReset();
}
void HALSIM_SetEncoderReset(int32_t index, HAL_Bool reset) {
SimEncoderData[index].SetReset(reset);
}
int32_t HALSIM_RegisterEncoderMaxPeriodCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterMaxPeriodCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderMaxPeriodCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelMaxPeriodCallback(uid);
}
double HALSIM_GetEncoderMaxPeriod(int32_t index) {
return SimEncoderData[index].GetMaxPeriod();
}
void HALSIM_SetEncoderMaxPeriod(int32_t index, double maxPeriod) {
SimEncoderData[index].SetMaxPeriod(maxPeriod);
}
int32_t HALSIM_RegisterEncoderDirectionCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterDirectionCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderDirectionCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelDirectionCallback(uid);
}
HAL_Bool HALSIM_GetEncoderDirection(int32_t index) {
return SimEncoderData[index].GetDirection();
}
void HALSIM_SetEncoderDirection(int32_t index, HAL_Bool direction) {
SimEncoderData[index].SetDirection(direction);
}
int32_t HALSIM_RegisterEncoderReverseDirectionCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterReverseDirectionCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderReverseDirectionCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelReverseDirectionCallback(uid);
}
HAL_Bool HALSIM_GetEncoderReverseDirection(int32_t index) {
return SimEncoderData[index].GetReverseDirection();
}
void HALSIM_SetEncoderReverseDirection(int32_t index,
HAL_Bool reverseDirection) {
SimEncoderData[index].SetReverseDirection(reverseDirection);
}
int32_t HALSIM_RegisterEncoderSamplesToAverageCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterSamplesToAverageCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderSamplesToAverageCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelSamplesToAverageCallback(uid);
}
int32_t HALSIM_GetEncoderSamplesToAverage(int32_t index) {
return SimEncoderData[index].GetSamplesToAverage();
}
void HALSIM_SetEncoderSamplesToAverage(int32_t index,
int32_t samplesToAverage) {
SimEncoderData[index].SetSamplesToAverage(samplesToAverage);
}
int32_t HALSIM_RegisterEncoderDistancePerPulseCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimEncoderData[index].RegisterDistancePerPulseCallback(callback, param,
initialNotify);
}
void HALSIM_CancelEncoderDistancePerPulseCallback(int32_t index, int32_t uid) {
SimEncoderData[index].CancelDistancePerPulseCallback(uid);
}
double HALSIM_GetEncoderDistancePerPulse(int32_t index) {
return SimEncoderData[index].GetDistancePerPulse();
}
void HALSIM_SetEncoderDistancePerPulse(int32_t index, double distancePerPulse) {
SimEncoderData[index].SetDistancePerPulse(distancePerPulse);
}
#define REGISTER(NAME) \
SimEncoderData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterEncoderAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimEncoderData[index].RegisterInitializedCallback(callback, param,
initialNotify);
SimEncoderData[index].RegisterCountCallback(callback, param, initialNotify);
SimEncoderData[index].RegisterPeriodCallback(callback, param, initialNotify);
SimEncoderData[index].RegisterResetCallback(callback, param, initialNotify);
SimEncoderData[index].RegisterMaxPeriodCallback(callback, param,
initialNotify);
SimEncoderData[index].RegisterDirectionCallback(callback, param,
initialNotify);
SimEncoderData[index].RegisterReverseDirectionCallback(callback, param,
initialNotify);
SimEncoderData[index].RegisterSamplesToAverageCallback(callback, param,
initialNotify);
SimEncoderData[index].RegisterDistancePerPulseCallback(callback, param,
initialNotify);
REGISTER(initialized);
REGISTER(count);
REGISTER(period);
REGISTER(reset);
REGISTER(maxPeriod);
REGISTER(direction);
REGISTER(reverseDirection);
REGISTER(samplesToAverage);
REGISTER(distancePerPulse);
}
} // extern "C"

View File

@@ -9,105 +9,37 @@
#include <atomic>
#include <limits>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/EncoderData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class EncoderData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(Count)
HAL_SIMDATAVALUE_DEFINE_NAME(Period)
HAL_SIMDATAVALUE_DEFINE_NAME(Reset)
HAL_SIMDATAVALUE_DEFINE_NAME(MaxPeriod)
HAL_SIMDATAVALUE_DEFINE_NAME(Direction)
HAL_SIMDATAVALUE_DEFINE_NAME(ReverseDirection)
HAL_SIMDATAVALUE_DEFINE_NAME(SamplesToAverage)
HAL_SIMDATAVALUE_DEFINE_NAME(DistancePerPulse)
public:
void SetDigitalChannelA(int16_t channel);
int16_t GetDigitalChannelA() const;
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterCountCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelCountCallback(int32_t uid);
void InvokeCountCallback(HAL_Value value);
int32_t GetCount();
void SetCount(int32_t count);
int32_t RegisterPeriodCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelPeriodCallback(int32_t uid);
void InvokePeriodCallback(HAL_Value value);
double GetPeriod();
void SetPeriod(double period);
int32_t RegisterResetCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelResetCallback(int32_t uid);
void InvokeResetCallback(HAL_Value value);
HAL_Bool GetReset();
void SetReset(HAL_Bool reset);
int32_t RegisterMaxPeriodCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelMaxPeriodCallback(int32_t uid);
void InvokeMaxPeriodCallback(HAL_Value value);
double GetMaxPeriod();
void SetMaxPeriod(double maxPeriod);
int32_t RegisterDirectionCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelDirectionCallback(int32_t uid);
void InvokeDirectionCallback(HAL_Value value);
HAL_Bool GetDirection();
void SetDirection(HAL_Bool direction);
int32_t RegisterReverseDirectionCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelReverseDirectionCallback(int32_t uid);
void InvokeReverseDirectionCallback(HAL_Value value);
HAL_Bool GetReverseDirection();
void SetReverseDirection(HAL_Bool reverseDirection);
int32_t RegisterSamplesToAverageCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelSamplesToAverageCallback(int32_t uid);
void InvokeSamplesToAverageCallback(HAL_Value value);
int32_t GetSamplesToAverage();
void SetSamplesToAverage(int32_t samplesToAverage);
int32_t RegisterDistancePerPulseCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelDistancePerPulseCallback(int32_t uid);
void InvokeDistancePerPulseCallback(HAL_Value value);
double GetDistancePerPulse();
void SetDistancePerPulse(double distancePerPulse);
std::atomic<int16_t> digitalChannelA{0};
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<int32_t, MakeInt, GetCountName> count{0};
SimDataValue<double, MakeDouble, GetPeriodName> period{
std::numeric_limits<double>::max()};
SimDataValue<HAL_Bool, MakeBoolean, GetResetName> reset{false};
SimDataValue<double, MakeDouble, GetMaxPeriodName> maxPeriod{0};
SimDataValue<HAL_Bool, MakeBoolean, GetDirectionName> direction{false};
SimDataValue<HAL_Bool, MakeBoolean, GetReverseDirectionName> reverseDirection{
false};
SimDataValue<int32_t, MakeInt, GetSamplesToAverageName> samplesToAverage{0};
SimDataValue<double, MakeDouble, GetDistancePerPulseName> distancePerPulse{1};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<int16_t> m_digitalChannelA{0};
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_count{0};
std::shared_ptr<NotifyListenerVector> m_countCallbacks = nullptr;
std::atomic<double> m_period{std::numeric_limits<double>::max()};
std::shared_ptr<NotifyListenerVector> m_periodCallbacks = nullptr;
std::atomic<HAL_Bool> m_reset{false};
std::shared_ptr<NotifyListenerVector> m_resetCallbacks = nullptr;
std::atomic<double> m_maxPeriod{0};
std::shared_ptr<NotifyListenerVector> m_maxPeriodCallbacks = nullptr;
std::atomic<HAL_Bool> m_direction{false};
std::shared_ptr<NotifyListenerVector> m_directionCallbacks = nullptr;
std::atomic<HAL_Bool> m_reverseDirection{false};
std::shared_ptr<NotifyListenerVector> m_reverseDirectionCallbacks = nullptr;
std::atomic<int32_t> m_samplesToAverage{0};
std::shared_ptr<NotifyListenerVector> m_samplesToAverageCallbacks = nullptr;
std::atomic<double> m_distancePerPulse{1};
std::shared_ptr<NotifyListenerVector> m_distancePerPulseCallbacks = nullptr;
};
extern EncoderData* SimEncoderData;
} // namespace hal

View File

@@ -9,7 +9,6 @@
#include "../PortsInternal.h"
#include "I2CDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -25,137 +24,35 @@ void InitializeI2CData() {
I2CData* hal::SimI2CData;
void I2CData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_readCallbacks = nullptr;
}
I2CData::I2CData() {}
I2CData::~I2CData() {}
///////////////////////////////////////////
// Initialize
///////////////////////////////////////////
int32_t I2CData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void I2CData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void I2CData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool I2CData::GetInitialized() { return m_initialized; }
void I2CData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t I2CData::RegisterReadCallback(HAL_BufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_readCallbacks =
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
}
return newUid;
}
void I2CData::CancelReadCallback(int32_t uid) {
m_readCallbacks = CancelCallback(m_readCallbacks, uid);
}
int32_t I2CData::RegisterWriteCallback(HAL_ConstBufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_writeCallbacks =
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
}
return newUid;
}
void I2CData::CancelWriteCallback(int32_t uid) {
m_writeCallbacks = CancelCallback(m_writeCallbacks, uid);
initialized.Reset(false);
read.Reset();
write.Reset();
}
void I2CData::Write(int32_t deviceAddress, const uint8_t* dataToSend,
int32_t sendSize) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", const_cast<uint8_t*>(dataToSend),
sendSize);
write(dataToSend, sendSize);
}
void I2CData::Read(int32_t deviceAddress, uint8_t* buffer, int32_t count) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_readCallbacks, "Read", buffer, count);
read(buffer, count);
}
extern "C" {
void HALSIM_ResetI2CData(int32_t index) { SimI2CData[index].ResetData(); }
int32_t HALSIM_RegisterI2CInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimI2CData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, I2C##CAPINAME, SimI2CData, \
LOWERNAME)
void HALSIM_CancelI2CInitializedCallback(int32_t index, int32_t uid) {
SimI2CData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
HAL_Bool HALSIM_GetI2CInitialized(int32_t index) {
return SimI2CData[index].GetInitialized();
}
#undef DEFINE_CAPI
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, HALSIM, I2C##CAPINAME, SimI2CData, \
LOWERNAME)
void HALSIM_SetI2CInitialized(int32_t index, HAL_Bool initialized) {
SimI2CData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterI2CReadCallback(int32_t index,
HAL_BufferCallback callback,
void* param) {
return SimI2CData[index].RegisterReadCallback(callback, param);
}
void HALSIM_CancelI2CReadCallback(int32_t index, int32_t uid) {
SimI2CData[index].CancelReadCallback(uid);
}
int32_t HALSIM_RegisterI2CWriteCallback(int32_t index,
HAL_ConstBufferCallback callback,
void* param) {
return SimI2CData[index].RegisterWriteCallback(callback, param);
}
void HALSIM_CancelI2CWriteCallback(int32_t index, int32_t uid) {
SimI2CData[index].CancelWriteCallback(uid);
}
DEFINE_CAPI(HAL_BufferCallback, Read, read)
DEFINE_CAPI(HAL_ConstBufferCallback, Write, write)
} // extern "C"

View File

@@ -7,47 +7,26 @@
#pragma once
#include <atomic>
#include <limits>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/I2CData.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SimCallbackRegistry.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class I2CData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Read)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Write)
public:
I2CData();
~I2CData();
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterReadCallback(HAL_BufferCallback callback, void* param);
void CancelReadCallback(int32_t uid);
int32_t RegisterWriteCallback(HAL_ConstBufferCallback callback, void* param);
void CancelWriteCallback(int32_t uid);
void Write(int32_t deviceAddress, const uint8_t* dataToSend,
int32_t sendSize);
void Read(int32_t deviceAddress, uint8_t* buffer, int32_t count);
void ResetData();
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimCallbackRegistry<HAL_BufferCallback, GetReadName> read;
SimCallbackRegistry<HAL_ConstBufferCallback, GetWriteName> write;
private:
wpi::mutex m_registerMutex;
wpi::mutex m_dataMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
void ResetData();
};
extern I2CData* SimI2CData;
} // namespace hal

View File

@@ -1,89 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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. */
/*----------------------------------------------------------------------------*/
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
std::shared_ptr<NotifyListenerVector> RegisterCallback(
std::shared_ptr<NotifyListenerVector> currentVector, const char* name,
HAL_NotifyCallback callback, void* param, int32_t* newUid) {
return RegisterCallbackImpl<NotifyListenerVector, HAL_NotifyCallback>(
currentVector, name, callback, param, newUid);
}
std::shared_ptr<NotifyListenerVector> CancelCallback(
std::shared_ptr<NotifyListenerVector> currentVector, int32_t uid) {
return CancelCallbackImpl<NotifyListenerVector, HAL_NotifyCallback>(
currentVector, uid);
}
void InvokeCallback(std::shared_ptr<NotifyListenerVector> currentVector,
const char* name, const HAL_Value* value) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, value);
}
}
std::shared_ptr<BufferListenerVector> RegisterCallback(
std::shared_ptr<BufferListenerVector> currentVector, const char* name,
HAL_BufferCallback callback, void* param, int32_t* newUid) {
return RegisterCallbackImpl<BufferListenerVector, HAL_BufferCallback>(
currentVector, name, callback, param, newUid);
}
std::shared_ptr<BufferListenerVector> CancelCallback(
std::shared_ptr<BufferListenerVector> currentVector, int32_t uid) {
return CancelCallbackImpl<BufferListenerVector, HAL_BufferCallback>(
currentVector, uid);
}
void InvokeCallback(std::shared_ptr<BufferListenerVector> currentVector,
const char* name, uint8_t* buffer, int32_t count) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, buffer, count);
}
}
std::shared_ptr<ConstBufferListenerVector> RegisterCallback(
std::shared_ptr<ConstBufferListenerVector> currentVector, const char* name,
HAL_ConstBufferCallback callback, void* param, int32_t* newUid) {
return RegisterCallbackImpl<ConstBufferListenerVector,
HAL_ConstBufferCallback>(currentVector, name,
callback, param, newUid);
}
std::shared_ptr<ConstBufferListenerVector> CancelCallback(
std::shared_ptr<ConstBufferListenerVector> currentVector, int32_t uid) {
return CancelCallbackImpl<ConstBufferListenerVector, HAL_ConstBufferCallback>(
currentVector, uid);
}
void InvokeCallback(std::shared_ptr<ConstBufferListenerVector> currentVector,
const char* name, const uint8_t* buffer, int32_t count) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, buffer, count);
}
}

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "PCMDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -23,464 +22,52 @@ void InitializePCMData() {
PCMData* hal::SimPCMData;
void PCMData::ResetData() {
for (int i = 0; i < kNumSolenoidChannels; i++) {
m_solenoidInitialized[i] = false;
m_solenoidInitializedCallbacks[i] = nullptr;
m_solenoidOutput[i] = false;
m_solenoidOutputCallbacks[i] = nullptr;
}
m_compressorInitialized = false;
m_compressorInitializedCallbacks = nullptr;
m_compressorOn = false;
m_compressorOnCallbacks = nullptr;
m_closedLoopEnabled = true;
m_closedLoopEnabledCallbacks = nullptr;
m_pressureSwitch = false;
m_pressureSwitchCallbacks = nullptr;
m_compressorCurrent = 0.0;
m_compressorCurrentCallbacks = nullptr;
}
int32_t PCMData::RegisterSolenoidInitializedCallback(
int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_solenoidInitializedCallbacks[channel] =
RegisterCallback(m_solenoidInitializedCallbacks[channel],
"SolenoidInitialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetSolenoidInitialized(channel));
callback("SolenoidInitialized", param, &value);
}
return newUid;
}
void PCMData::CancelSolenoidInitializedCallback(int32_t channel, int32_t uid) {
m_solenoidInitializedCallbacks[channel] =
CancelCallback(m_solenoidInitializedCallbacks[channel], uid);
}
void PCMData::InvokeSolenoidInitializedCallback(int32_t channel,
HAL_Value value) {
InvokeCallback(m_solenoidInitializedCallbacks[channel], "SolenoidInitialized",
&value);
}
HAL_Bool PCMData::GetSolenoidInitialized(int32_t channel) {
return m_solenoidInitialized[channel];
}
void PCMData::SetSolenoidInitialized(int32_t channel,
HAL_Bool solenoidInitialized) {
HAL_Bool oldValue =
m_solenoidInitialized[channel].exchange(solenoidInitialized);
if (oldValue != solenoidInitialized) {
InvokeSolenoidInitializedCallback(channel,
MakeBoolean(solenoidInitialized));
}
}
int32_t PCMData::RegisterSolenoidOutputCallback(int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_solenoidOutputCallbacks[channel] =
RegisterCallback(m_solenoidOutputCallbacks[channel], "SolenoidOutput",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetSolenoidOutput(channel));
callback("SolenoidOutput", param, &value);
}
return newUid;
}
void PCMData::CancelSolenoidOutputCallback(int32_t channel, int32_t uid) {
m_solenoidOutputCallbacks[channel] =
CancelCallback(m_solenoidOutputCallbacks[channel], uid);
}
void PCMData::InvokeSolenoidOutputCallback(int32_t channel, HAL_Value value) {
InvokeCallback(m_solenoidOutputCallbacks[channel], "SolenoidOutput", &value);
}
HAL_Bool PCMData::GetSolenoidOutput(int32_t channel) {
return m_solenoidOutput[channel];
}
void PCMData::SetSolenoidOutput(int32_t channel, HAL_Bool solenoidOutput) {
HAL_Bool oldValue = m_solenoidOutput[channel].exchange(solenoidOutput);
if (oldValue != solenoidOutput) {
InvokeSolenoidOutputCallback(channel, MakeBoolean(solenoidOutput));
}
}
int32_t PCMData::RegisterCompressorInitializedCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorInitializedCallbacks =
RegisterCallback(m_compressorInitializedCallbacks,
"CompressorInitialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetCompressorInitialized());
callback("CompressorInitialized", param, &value);
}
return newUid;
}
void PCMData::CancelCompressorInitializedCallback(int32_t uid) {
m_compressorInitializedCallbacks =
CancelCallback(m_compressorInitializedCallbacks, uid);
}
void PCMData::InvokeCompressorInitializedCallback(HAL_Value value) {
InvokeCallback(m_compressorInitializedCallbacks, "CompressorInitialized",
&value);
}
HAL_Bool PCMData::GetCompressorInitialized() { return m_compressorInitialized; }
void PCMData::SetCompressorInitialized(HAL_Bool compressorInitialized) {
HAL_Bool oldValue = m_compressorInitialized.exchange(compressorInitialized);
if (oldValue != compressorInitialized) {
InvokeCompressorInitializedCallback(MakeBoolean(compressorInitialized));
}
}
int32_t PCMData::RegisterCompressorOnCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorOnCallbacks = RegisterCallback(
m_compressorOnCallbacks, "CompressorOn", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetCompressorOn());
callback("CompressorOn", param, &value);
}
return newUid;
}
void PCMData::CancelCompressorOnCallback(int32_t uid) {
m_compressorOnCallbacks = CancelCallback(m_compressorOnCallbacks, uid);
}
void PCMData::InvokeCompressorOnCallback(HAL_Value value) {
InvokeCallback(m_compressorOnCallbacks, "CompressorOn", &value);
}
HAL_Bool PCMData::GetCompressorOn() { return m_compressorOn; }
void PCMData::SetCompressorOn(HAL_Bool compressorOn) {
HAL_Bool oldValue = m_compressorOn.exchange(compressorOn);
if (oldValue != compressorOn) {
InvokeCompressorOnCallback(MakeBoolean(compressorOn));
}
}
int32_t PCMData::RegisterClosedLoopEnabledCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_closedLoopEnabledCallbacks =
RegisterCallback(m_closedLoopEnabledCallbacks, "ClosedLoopEnabled",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetClosedLoopEnabled());
callback("ClosedLoopEnabled", param, &value);
}
return newUid;
}
void PCMData::CancelClosedLoopEnabledCallback(int32_t uid) {
m_closedLoopEnabledCallbacks =
CancelCallback(m_closedLoopEnabledCallbacks, uid);
}
void PCMData::InvokeClosedLoopEnabledCallback(HAL_Value value) {
InvokeCallback(m_closedLoopEnabledCallbacks, "ClosedLoopEnabled", &value);
}
HAL_Bool PCMData::GetClosedLoopEnabled() { return m_closedLoopEnabled; }
void PCMData::SetClosedLoopEnabled(HAL_Bool closedLoopEnabled) {
HAL_Bool oldValue = m_closedLoopEnabled.exchange(closedLoopEnabled);
if (oldValue != closedLoopEnabled) {
InvokeClosedLoopEnabledCallback(MakeBoolean(closedLoopEnabled));
}
}
int32_t PCMData::RegisterPressureSwitchCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pressureSwitchCallbacks = RegisterCallback(
m_pressureSwitchCallbacks, "PressureSwitch", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetPressureSwitch());
callback("PressureSwitch", param, &value);
}
return newUid;
}
void PCMData::CancelPressureSwitchCallback(int32_t uid) {
m_pressureSwitchCallbacks = CancelCallback(m_pressureSwitchCallbacks, uid);
}
void PCMData::InvokePressureSwitchCallback(HAL_Value value) {
InvokeCallback(m_pressureSwitchCallbacks, "PressureSwitch", &value);
}
HAL_Bool PCMData::GetPressureSwitch() { return m_pressureSwitch; }
void PCMData::SetPressureSwitch(HAL_Bool pressureSwitch) {
HAL_Bool oldValue = m_pressureSwitch.exchange(pressureSwitch);
if (oldValue != pressureSwitch) {
InvokePressureSwitchCallback(MakeBoolean(pressureSwitch));
}
}
int32_t PCMData::RegisterCompressorCurrentCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorCurrentCallbacks =
RegisterCallback(m_compressorCurrentCallbacks, "CompressorCurrent",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetCompressorCurrent());
callback("CompressorCurrent", param, &value);
}
return newUid;
}
void PCMData::CancelCompressorCurrentCallback(int32_t uid) {
m_compressorCurrentCallbacks =
CancelCallback(m_compressorCurrentCallbacks, uid);
}
void PCMData::InvokeCompressorCurrentCallback(HAL_Value value) {
InvokeCallback(m_compressorCurrentCallbacks, "CompressorCurrent", &value);
}
double PCMData::GetCompressorCurrent() { return m_compressorCurrent; }
void PCMData::SetCompressorCurrent(double compressorCurrent) {
double oldValue = m_compressorCurrent.exchange(compressorCurrent);
if (oldValue != compressorCurrent) {
InvokeCompressorCurrentCallback(MakeDouble(compressorCurrent));
solenoidInitialized[i].Reset(false);
solenoidOutput[i].Reset(false);
}
compressorInitialized.Reset(false);
compressorOn.Reset(false);
closedLoopEnabled.Reset(true);
pressureSwitch.Reset(false);
compressorCurrent.Reset(0.0);
}
extern "C" {
void HALSIM_ResetPCMData(int32_t index) { SimPCMData[index].ResetData(); }
int32_t HALSIM_RegisterPCMSolenoidInitializedCallback(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterSolenoidInitializedCallback(
channel, callback, param, initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PCM##CAPINAME, SimPCMData, \
LOWERNAME)
void HALSIM_CancelPCMSolenoidInitializedCallback(int32_t index, int32_t channel,
int32_t uid) {
SimPCMData[index].CancelSolenoidInitializedCallback(channel, uid);
}
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidInitialized,
SimPCMData, solenoidInitialized)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidOutput,
SimPCMData, solenoidOutput)
DEFINE_CAPI(HAL_Bool, CompressorInitialized, compressorInitialized)
DEFINE_CAPI(HAL_Bool, CompressorOn, compressorOn)
DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, closedLoopEnabled)
DEFINE_CAPI(HAL_Bool, PressureSwitch, pressureSwitch)
DEFINE_CAPI(double, CompressorCurrent, compressorCurrent)
HAL_Bool HALSIM_GetPCMSolenoidInitialized(int32_t index, int32_t channel) {
return SimPCMData[index].GetSolenoidInitialized(channel);
}
void HALSIM_SetPCMSolenoidInitialized(int32_t index, int32_t channel,
HAL_Bool solenoidInitialized) {
SimPCMData[index].SetSolenoidInitialized(channel, solenoidInitialized);
}
int32_t HALSIM_RegisterPCMSolenoidOutputCallback(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterSolenoidOutputCallback(channel, callback,
param, initialNotify);
}
void HALSIM_CancelPCMSolenoidOutputCallback(int32_t index, int32_t channel,
int32_t uid) {
SimPCMData[index].CancelSolenoidOutputCallback(channel, uid);
}
HAL_Bool HALSIM_GetPCMSolenoidOutput(int32_t index, int32_t channel) {
return SimPCMData[index].GetSolenoidOutput(channel);
}
void HALSIM_SetPCMSolenoidOutput(int32_t index, int32_t channel,
HAL_Bool solenoidOutput) {
SimPCMData[index].SetSolenoidOutput(channel, solenoidOutput);
}
int32_t HALSIM_RegisterPCMCompressorInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterCompressorInitializedCallback(
callback, param, initialNotify);
}
void HALSIM_CancelPCMCompressorInitializedCallback(int32_t index, int32_t uid) {
SimPCMData[index].CancelCompressorInitializedCallback(uid);
}
HAL_Bool HALSIM_GetPCMCompressorInitialized(int32_t index) {
return SimPCMData[index].GetCompressorInitialized();
}
void HALSIM_SetPCMCompressorInitialized(int32_t index,
HAL_Bool compressorInitialized) {
SimPCMData[index].SetCompressorInitialized(compressorInitialized);
}
int32_t HALSIM_RegisterPCMCompressorOnCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterCompressorOnCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPCMCompressorOnCallback(int32_t index, int32_t uid) {
SimPCMData[index].CancelCompressorOnCallback(uid);
}
HAL_Bool HALSIM_GetPCMCompressorOn(int32_t index) {
return SimPCMData[index].GetCompressorOn();
}
void HALSIM_SetPCMCompressorOn(int32_t index, HAL_Bool compressorOn) {
SimPCMData[index].SetCompressorOn(compressorOn);
}
int32_t HALSIM_RegisterPCMClosedLoopEnabledCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterClosedLoopEnabledCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPCMClosedLoopEnabledCallback(int32_t index, int32_t uid) {
SimPCMData[index].CancelClosedLoopEnabledCallback(uid);
}
HAL_Bool HALSIM_GetPCMClosedLoopEnabled(int32_t index) {
return SimPCMData[index].GetClosedLoopEnabled();
}
void HALSIM_SetPCMClosedLoopEnabled(int32_t index, HAL_Bool closedLoopEnabled) {
SimPCMData[index].SetClosedLoopEnabled(closedLoopEnabled);
}
int32_t HALSIM_RegisterPCMPressureSwitchCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterPressureSwitchCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPCMPressureSwitchCallback(int32_t index, int32_t uid) {
SimPCMData[index].CancelPressureSwitchCallback(uid);
}
HAL_Bool HALSIM_GetPCMPressureSwitch(int32_t index) {
return SimPCMData[index].GetPressureSwitch();
}
void HALSIM_SetPCMPressureSwitch(int32_t index, HAL_Bool pressureSwitch) {
SimPCMData[index].SetPressureSwitch(pressureSwitch);
}
int32_t HALSIM_RegisterPCMCompressorCurrentCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPCMData[index].RegisterCompressorCurrentCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPCMCompressorCurrentCallback(int32_t index, int32_t uid) {
SimPCMData[index].CancelCompressorCurrentCallback(uid);
}
double HALSIM_GetPCMCompressorCurrent(int32_t index) {
return SimPCMData[index].GetCompressorCurrent();
}
void HALSIM_SetPCMCompressorCurrent(int32_t index, double compressorCurrent) {
SimPCMData[index].SetCompressorCurrent(compressorCurrent);
}
#define REGISTER(NAME) \
SimPCMData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterPCMAllNonSolenoidCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimPCMData[index].RegisterCompressorInitializedCallback(callback, param,
initialNotify);
SimPCMData[index].RegisterCompressorOnCallback(callback, param,
initialNotify);
SimPCMData[index].RegisterClosedLoopEnabledCallback(callback, param,
initialNotify);
SimPCMData[index].RegisterPressureSwitchCallback(callback, param,
initialNotify);
SimPCMData[index].RegisterCompressorCurrentCallback(callback, param,
initialNotify);
REGISTER(compressorInitialized);
REGISTER(compressorOn);
REGISTER(closedLoopEnabled);
REGISTER(pressureSwitch);
REGISTER(compressorCurrent);
}
void HALSIM_RegisterPCMAllSolenoidCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimPCMData[index].RegisterSolenoidInitializedCallback(channel, callback,
param, initialNotify);
SimPCMData[index].RegisterSolenoidOutputCallback(channel, callback, param,
initialNotify);
REGISTER(solenoidInitialized[channel]);
REGISTER(solenoidOutput[channel]);
}
} // extern "C"

View File

@@ -7,94 +7,47 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "../PortsInternal.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/PCMData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class PCMData {
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidOutput)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorOn)
HAL_SIMDATAVALUE_DEFINE_NAME(ClosedLoopEnabled)
HAL_SIMDATAVALUE_DEFINE_NAME(PressureSwitch)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorCurrent)
static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr HAL_Bool
GetSolenoidInitializedDefault() {
return false;
}
static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr HAL_Bool
GetSolenoidOutputDefault() {
return false;
}
public:
int32_t RegisterSolenoidInitializedCallback(int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelSolenoidInitializedCallback(int32_t channel, int32_t uid);
void InvokeSolenoidInitializedCallback(int32_t channel, HAL_Value value);
HAL_Bool GetSolenoidInitialized(int32_t channel);
void SetSolenoidInitialized(int32_t channel, HAL_Bool solenoidInitialized);
int32_t RegisterSolenoidOutputCallback(int32_t channel,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelSolenoidOutputCallback(int32_t channel, int32_t uid);
void InvokeSolenoidOutputCallback(int32_t channel, HAL_Value value);
HAL_Bool GetSolenoidOutput(int32_t channel);
void SetSolenoidOutput(int32_t channel, HAL_Bool solenoidOutput);
int32_t RegisterCompressorInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelCompressorInitializedCallback(int32_t uid);
void InvokeCompressorInitializedCallback(HAL_Value value);
HAL_Bool GetCompressorInitialized();
void SetCompressorInitialized(HAL_Bool compressorInitialized);
int32_t RegisterCompressorOnCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelCompressorOnCallback(int32_t uid);
void InvokeCompressorOnCallback(HAL_Value value);
HAL_Bool GetCompressorOn();
void SetCompressorOn(HAL_Bool compressorOn);
int32_t RegisterClosedLoopEnabledCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelClosedLoopEnabledCallback(int32_t uid);
void InvokeClosedLoopEnabledCallback(HAL_Value value);
HAL_Bool GetClosedLoopEnabled();
void SetClosedLoopEnabled(HAL_Bool closedLoopEnabled);
int32_t RegisterPressureSwitchCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelPressureSwitchCallback(int32_t uid);
void InvokePressureSwitchCallback(HAL_Value value);
HAL_Bool GetPressureSwitch();
void SetPressureSwitch(HAL_Bool pressureSwitch);
int32_t RegisterCompressorCurrentCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelCompressorCurrentCallback(int32_t uid);
void InvokeCompressorCurrentCallback(HAL_Value value);
double GetCompressorCurrent();
void SetCompressorCurrent(double compressorCurrent);
SimDataValue<HAL_Bool, MakeBoolean, GetSolenoidInitializedName,
GetSolenoidInitializedDefault>
solenoidInitialized[kNumSolenoidChannels];
SimDataValue<HAL_Bool, MakeBoolean, GetSolenoidOutputName,
GetSolenoidOutputDefault>
solenoidOutput[kNumSolenoidChannels];
SimDataValue<HAL_Bool, MakeBoolean, GetCompressorInitializedName>
compressorInitialized{false};
SimDataValue<HAL_Bool, MakeBoolean, GetCompressorOnName> compressorOn{false};
SimDataValue<HAL_Bool, MakeBoolean, GetClosedLoopEnabledName>
closedLoopEnabled{true};
SimDataValue<HAL_Bool, MakeBoolean, GetPressureSwitchName> pressureSwitch{
false};
SimDataValue<double, MakeDouble, GetCompressorCurrentName> compressorCurrent{
0.0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_solenoidInitialized[kNumSolenoidChannels];
std::shared_ptr<NotifyListenerVector>
m_solenoidInitializedCallbacks[kNumSolenoidChannels];
std::atomic<HAL_Bool> m_solenoidOutput[kNumSolenoidChannels];
std::shared_ptr<NotifyListenerVector>
m_solenoidOutputCallbacks[kNumSolenoidChannels];
std::atomic<HAL_Bool> m_compressorInitialized{false};
std::shared_ptr<NotifyListenerVector> m_compressorInitializedCallbacks =
nullptr;
std::atomic<HAL_Bool> m_compressorOn{false};
std::shared_ptr<NotifyListenerVector> m_compressorOnCallbacks = nullptr;
std::atomic<HAL_Bool> m_closedLoopEnabled{true};
std::shared_ptr<NotifyListenerVector> m_closedLoopEnabledCallbacks = nullptr;
std::atomic<HAL_Bool> m_pressureSwitch{false};
std::shared_ptr<NotifyListenerVector> m_pressureSwitchCallbacks = nullptr;
std::atomic<double> m_compressorCurrent{0.0};
std::shared_ptr<NotifyListenerVector> m_compressorCurrentCallbacks = nullptr;
};
extern PCMData* SimPCMData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "PDPDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,250 +21,36 @@ void InitializePDPData() {
PDPData* hal::SimPDPData;
void PDPData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_temperature = 0.0;
m_temperatureCallbacks = nullptr;
m_voltage = 12.0;
m_voltageCallbacks = nullptr;
initialized.Reset(false);
temperature.Reset(0.0);
voltage.Reset(12.0);
for (int i = 0; i < kNumPDPChannels; i++) {
m_current[i] = 0;
m_currentCallbacks[i] = nullptr;
}
}
int32_t PDPData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void PDPData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void PDPData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool PDPData::GetInitialized() { return m_initialized; }
void PDPData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t PDPData::RegisterTemperatureCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_temperatureCallbacks = RegisterCallback(
m_temperatureCallbacks, "Temperature", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetTemperature());
callback("Temperature", param, &value);
}
return newUid;
}
void PDPData::CancelTemperatureCallback(int32_t uid) {
m_temperatureCallbacks = CancelCallback(m_temperatureCallbacks, uid);
}
void PDPData::InvokeTemperatureCallback(HAL_Value value) {
InvokeCallback(m_temperatureCallbacks, "Temperature", &value);
}
double PDPData::GetTemperature() { return m_temperature; }
void PDPData::SetTemperature(double temperature) {
double oldValue = m_temperature.exchange(temperature);
if (oldValue != temperature) {
InvokeTemperatureCallback(MakeDouble(temperature));
}
}
int32_t PDPData::RegisterVoltageCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetVoltage());
callback("Voltage", param, &value);
}
return newUid;
}
void PDPData::CancelVoltageCallback(int32_t uid) {
m_voltageCallbacks = CancelCallback(m_voltageCallbacks, uid);
}
void PDPData::InvokeVoltageCallback(HAL_Value value) {
InvokeCallback(m_voltageCallbacks, "Voltage", &value);
}
double PDPData::GetVoltage() { return m_voltage; }
void PDPData::SetVoltage(double voltage) {
double oldValue = m_voltage.exchange(voltage);
if (oldValue != voltage) {
InvokeVoltageCallback(MakeDouble(voltage));
}
}
int32_t PDPData::RegisterCurrentCallback(int32_t channel,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_currentCallbacks[channel] = RegisterCallback(
m_currentCallbacks[channel], "Current", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetCurrent(channel));
callback("Current", param, &value);
}
return newUid;
}
void PDPData::CancelCurrentCallback(int32_t channel, int32_t uid) {
m_currentCallbacks[channel] =
CancelCallback(m_currentCallbacks[channel], uid);
}
void PDPData::InvokeCurrentCallback(int32_t channel, HAL_Value value) {
InvokeCallback(m_currentCallbacks[channel], "Current", &value);
}
double PDPData::GetCurrent(int32_t channel) { return m_current[channel]; }
void PDPData::SetCurrent(int32_t channel, double current) {
double oldValue = m_current[channel].exchange(current);
if (oldValue != current) {
InvokeCurrentCallback(channel, MakeDouble(current));
current[i].Reset(0.0);
}
}
extern "C" {
void HALSIM_ResetPDPData(int32_t index) { SimPDPData[index].ResetData(); }
int32_t HALSIM_RegisterPDPInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPDPData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PDP##CAPINAME, SimPDPData, \
LOWERNAME)
void HALSIM_CancelPDPInitializedCallback(int32_t index, int32_t uid) {
SimPDPData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, Temperature, temperature)
DEFINE_CAPI(double, Voltage, voltage)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PDPCurrent, SimPDPData,
current)
HAL_Bool HALSIM_GetPDPInitialized(int32_t index) {
return SimPDPData[index].GetInitialized();
}
void HALSIM_SetPDPInitialized(int32_t index, HAL_Bool initialized) {
SimPDPData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterPDPTemperatureCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPDPData[index].RegisterTemperatureCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPDPTemperatureCallback(int32_t index, int32_t uid) {
SimPDPData[index].CancelTemperatureCallback(uid);
}
double HALSIM_GetPDPTemperature(int32_t index) {
return SimPDPData[index].GetTemperature();
}
void HALSIM_SetPDPTemperature(int32_t index, double temperature) {
SimPDPData[index].SetTemperature(temperature);
}
int32_t HALSIM_RegisterPDPVoltageCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
return SimPDPData[index].RegisterVoltageCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPDPVoltageCallback(int32_t index, int32_t uid) {
SimPDPData[index].CancelVoltageCallback(uid);
}
double HALSIM_GetPDPVoltage(int32_t index) {
return SimPDPData[index].GetVoltage();
}
void HALSIM_SetPDPVoltage(int32_t index, double voltage) {
SimPDPData[index].SetVoltage(voltage);
}
int32_t HALSIM_RegisterPDPCurrentCallback(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
return SimPDPData[index].RegisterCurrentCallback(channel, callback, param,
initialNotify);
}
void HALSIM_CancelPDPCurrentCallback(int32_t index, int32_t channel,
int32_t uid) {
SimPDPData[index].CancelCurrentCallback(channel, uid);
}
double HALSIM_GetPDPCurrent(int32_t index, int32_t channel) {
return SimPDPData[index].GetCurrent(channel);
}
void HALSIM_SetPDPCurrent(int32_t index, int32_t channel, double current) {
SimPDPData[index].SetCurrent(channel, current);
}
#define REGISTER(NAME) \
SimPDPData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimPDPData[index].RegisterInitializedCallback(callback, param, initialNotify);
SimPDPData[index].RegisterTemperatureCallback(callback, param, initialNotify);
SimPDPData[index].RegisterVoltageCallback(callback, param, initialNotify);
REGISTER(initialized);
REGISTER(temperature);
REGISTER(voltage);
}
} // extern "C"

View File

@@ -7,58 +7,29 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "../PortsInternal.h"
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/PDPData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class PDPData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(Temperature)
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
HAL_SIMDATAVALUE_DEFINE_NAME(Current)
static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr double GetCurrentDefault() {
return 0.0;
}
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterTemperatureCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelTemperatureCallback(int32_t uid);
void InvokeTemperatureCallback(HAL_Value value);
double GetTemperature();
void SetTemperature(double temperature);
int32_t RegisterVoltageCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelVoltageCallback(int32_t uid);
void InvokeVoltageCallback(HAL_Value value);
double GetVoltage();
void SetVoltage(double voltage);
int32_t RegisterCurrentCallback(int32_t channel, HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelCurrentCallback(int32_t channel, int32_t uid);
void InvokeCurrentCallback(int32_t channel, HAL_Value value);
double GetCurrent(int32_t channel);
void SetCurrent(int32_t channel, double current);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<double, MakeDouble, GetTemperatureName> temperature{0.0};
SimDataValue<double, MakeDouble, GetVoltageName> voltage{12.0};
SimDataValue<double, MakeDouble, GetCurrentName, GetCurrentDefault>
current[kNumPDPChannels];
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_temperature{0.0};
std::shared_ptr<NotifyListenerVector> m_temperatureCallbacks = nullptr;
std::atomic<double> m_voltage{12.0};
std::shared_ptr<NotifyListenerVector> m_voltageCallbacks = nullptr;
std::atomic<double> m_current[kNumPDPChannels];
std::shared_ptr<NotifyListenerVector> m_currentCallbacks[kNumPDPChannels];
};
extern PDPData* SimPDPData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "PWMDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,362 +21,38 @@ void InitializePWMData() {
PWMData* hal::SimPWMData;
void PWMData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_rawValue = 0;
m_rawValueCallbacks = nullptr;
m_speed = 0;
m_speedCallbacks = nullptr;
m_position = 0;
m_positionCallbacks = nullptr;
m_periodScale = 0;
m_periodScaleCallbacks = nullptr;
m_zeroLatch = false;
m_zeroLatchCallbacks = nullptr;
}
int32_t PWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void PWMData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void PWMData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool PWMData::GetInitialized() { return m_initialized; }
void PWMData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t PWMData::RegisterRawValueCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rawValueCallbacks = RegisterCallback(m_rawValueCallbacks, "RawValue",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetRawValue());
callback("RawValue", param, &value);
}
return newUid;
}
void PWMData::CancelRawValueCallback(int32_t uid) {
m_rawValueCallbacks = CancelCallback(m_rawValueCallbacks, uid);
}
void PWMData::InvokeRawValueCallback(HAL_Value value) {
InvokeCallback(m_rawValueCallbacks, "RawValue", &value);
}
int32_t PWMData::GetRawValue() { return m_rawValue; }
void PWMData::SetRawValue(int32_t rawValue) {
int32_t oldValue = m_rawValue.exchange(rawValue);
if (oldValue != rawValue) {
InvokeRawValueCallback(MakeInt(rawValue));
}
}
int32_t PWMData::RegisterSpeedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_speedCallbacks =
RegisterCallback(m_speedCallbacks, "Speed", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetSpeed());
callback("Speed", param, &value);
}
return newUid;
}
void PWMData::CancelSpeedCallback(int32_t uid) {
m_speedCallbacks = CancelCallback(m_speedCallbacks, uid);
}
void PWMData::InvokeSpeedCallback(HAL_Value value) {
InvokeCallback(m_speedCallbacks, "Speed", &value);
}
double PWMData::GetSpeed() { return m_speed; }
void PWMData::SetSpeed(double speed) {
double oldValue = m_speed.exchange(speed);
if (oldValue != speed) {
InvokeSpeedCallback(MakeDouble(speed));
}
}
int32_t PWMData::RegisterPositionCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_positionCallbacks = RegisterCallback(m_positionCallbacks, "Position",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetPosition());
callback("Position", param, &value);
}
return newUid;
}
void PWMData::CancelPositionCallback(int32_t uid) {
m_positionCallbacks = CancelCallback(m_positionCallbacks, uid);
}
void PWMData::InvokePositionCallback(HAL_Value value) {
InvokeCallback(m_positionCallbacks, "Position", &value);
}
double PWMData::GetPosition() { return m_position; }
void PWMData::SetPosition(double position) {
double oldValue = m_position.exchange(position);
if (oldValue != position) {
InvokePositionCallback(MakeDouble(position));
}
}
int32_t PWMData::RegisterPeriodScaleCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_periodScaleCallbacks = RegisterCallback(
m_periodScaleCallbacks, "PeriodScale", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetPeriodScale());
callback("PeriodScale", param, &value);
}
return newUid;
}
void PWMData::CancelPeriodScaleCallback(int32_t uid) {
m_periodScaleCallbacks = CancelCallback(m_periodScaleCallbacks, uid);
}
void PWMData::InvokePeriodScaleCallback(HAL_Value value) {
InvokeCallback(m_periodScaleCallbacks, "PeriodScale", &value);
}
int32_t PWMData::GetPeriodScale() { return m_periodScale; }
void PWMData::SetPeriodScale(int32_t periodScale) {
int32_t oldValue = m_periodScale.exchange(periodScale);
if (oldValue != periodScale) {
InvokePeriodScaleCallback(MakeInt(periodScale));
}
}
int32_t PWMData::RegisterZeroLatchCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zeroLatchCallbacks = RegisterCallback(m_zeroLatchCallbacks, "ZeroLatch",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetZeroLatch());
callback("ZeroLatch", param, &value);
}
return newUid;
}
void PWMData::CancelZeroLatchCallback(int32_t uid) {
m_zeroLatchCallbacks = CancelCallback(m_zeroLatchCallbacks, uid);
}
void PWMData::InvokeZeroLatchCallback(HAL_Value value) {
InvokeCallback(m_zeroLatchCallbacks, "ZeroLatch", &value);
}
HAL_Bool PWMData::GetZeroLatch() { return m_zeroLatch; }
void PWMData::SetZeroLatch(HAL_Bool zeroLatch) {
HAL_Bool oldValue = m_zeroLatch.exchange(zeroLatch);
if (oldValue != zeroLatch) {
InvokeZeroLatchCallback(MakeBoolean(zeroLatch));
}
initialized.Reset(false);
rawValue.Reset(0);
speed.Reset(0);
position.Reset(0);
periodScale.Reset(0);
zeroLatch.Reset(false);
}
extern "C" {
void HALSIM_ResetPWMData(int32_t index) { SimPWMData[index].ResetData(); }
int32_t HALSIM_RegisterPWMInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPWMData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PWM##CAPINAME, SimPWMData, \
LOWERNAME)
void HALSIM_CancelPWMInitializedCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(int32_t, RawValue, rawValue)
DEFINE_CAPI(double, Speed, speed)
DEFINE_CAPI(double, Position, position)
DEFINE_CAPI(int32_t, PeriodScale, periodScale)
DEFINE_CAPI(HAL_Bool, ZeroLatch, zeroLatch)
HAL_Bool HALSIM_GetPWMInitialized(int32_t index) {
return SimPWMData[index].GetInitialized();
}
void HALSIM_SetPWMInitialized(int32_t index, HAL_Bool initialized) {
SimPWMData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterPWMRawValueCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPWMData[index].RegisterRawValueCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPWMRawValueCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelRawValueCallback(uid);
}
int32_t HALSIM_GetPWMRawValue(int32_t index) {
return SimPWMData[index].GetRawValue();
}
void HALSIM_SetPWMRawValue(int32_t index, int32_t rawValue) {
SimPWMData[index].SetRawValue(rawValue);
}
int32_t HALSIM_RegisterPWMSpeedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
return SimPWMData[index].RegisterSpeedCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPWMSpeedCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelSpeedCallback(uid);
}
double HALSIM_GetPWMSpeed(int32_t index) {
return SimPWMData[index].GetSpeed();
}
void HALSIM_SetPWMSpeed(int32_t index, double speed) {
SimPWMData[index].SetSpeed(speed);
}
int32_t HALSIM_RegisterPWMPositionCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPWMData[index].RegisterPositionCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPWMPositionCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelPositionCallback(uid);
}
double HALSIM_GetPWMPosition(int32_t index) {
return SimPWMData[index].GetPosition();
}
void HALSIM_SetPWMPosition(int32_t index, double position) {
SimPWMData[index].SetPosition(position);
}
int32_t HALSIM_RegisterPWMPeriodScaleCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPWMData[index].RegisterPeriodScaleCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPWMPeriodScaleCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelPeriodScaleCallback(uid);
}
int32_t HALSIM_GetPWMPeriodScale(int32_t index) {
return SimPWMData[index].GetPeriodScale();
}
void HALSIM_SetPWMPeriodScale(int32_t index, int32_t periodScale) {
SimPWMData[index].SetPeriodScale(periodScale);
}
int32_t HALSIM_RegisterPWMZeroLatchCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimPWMData[index].RegisterZeroLatchCallback(callback, param,
initialNotify);
}
void HALSIM_CancelPWMZeroLatchCallback(int32_t index, int32_t uid) {
SimPWMData[index].CancelZeroLatchCallback(uid);
}
HAL_Bool HALSIM_GetPWMZeroLatch(int32_t index) {
return SimPWMData[index].GetZeroLatch();
}
void HALSIM_SetPWMZeroLatch(int32_t index, HAL_Bool zeroLatch) {
SimPWMData[index].SetZeroLatch(zeroLatch);
}
#define REGISTER(NAME) \
SimPWMData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterPWMAllCallbacks(int32_t index, HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimPWMData[index].RegisterInitializedCallback(callback, param, initialNotify);
SimPWMData[index].RegisterRawValueCallback(callback, param, initialNotify);
SimPWMData[index].RegisterSpeedCallback(callback, param, initialNotify);
SimPWMData[index].RegisterPositionCallback(callback, param, initialNotify);
SimPWMData[index].RegisterPeriodScaleCallback(callback, param, initialNotify);
SimPWMData[index].RegisterZeroLatchCallback(callback, param, initialNotify);
REGISTER(initialized);
REGISTER(rawValue);
REGISTER(speed);
REGISTER(position);
REGISTER(periodScale);
REGISTER(zeroLatch);
}
} // extern "C"

View File

@@ -7,75 +7,27 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/PWMData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class PWMData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(RawValue)
HAL_SIMDATAVALUE_DEFINE_NAME(Speed)
HAL_SIMDATAVALUE_DEFINE_NAME(Position)
HAL_SIMDATAVALUE_DEFINE_NAME(PeriodScale)
HAL_SIMDATAVALUE_DEFINE_NAME(ZeroLatch)
public:
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterRawValueCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelRawValueCallback(int32_t uid);
void InvokeRawValueCallback(HAL_Value value);
int32_t GetRawValue();
void SetRawValue(int32_t rawValue);
int32_t RegisterSpeedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelSpeedCallback(int32_t uid);
void InvokeSpeedCallback(HAL_Value value);
double GetSpeed();
void SetSpeed(double speed);
int32_t RegisterPositionCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelPositionCallback(int32_t uid);
void InvokePositionCallback(HAL_Value value);
double GetPosition();
void SetPosition(double position);
int32_t RegisterPeriodScaleCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelPeriodScaleCallback(int32_t uid);
void InvokePeriodScaleCallback(HAL_Value value);
int32_t GetPeriodScale();
void SetPeriodScale(int32_t periodScale);
int32_t RegisterZeroLatchCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelZeroLatchCallback(int32_t uid);
void InvokeZeroLatchCallback(HAL_Value value);
HAL_Bool GetZeroLatch();
void SetZeroLatch(HAL_Bool zeroLatch);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimDataValue<int32_t, MakeInt, GetRawValueName> rawValue{0};
SimDataValue<double, MakeDouble, GetSpeedName> speed{0};
SimDataValue<double, MakeDouble, GetPositionName> position{0};
SimDataValue<int32_t, MakeInt, GetPeriodScaleName> periodScale{0};
SimDataValue<HAL_Bool, MakeBoolean, GetZeroLatchName> zeroLatch{false};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_rawValue{0};
std::shared_ptr<NotifyListenerVector> m_rawValueCallbacks = nullptr;
std::atomic<double> m_speed{0};
std::shared_ptr<NotifyListenerVector> m_speedCallbacks = nullptr;
std::atomic<double> m_position{0};
std::shared_ptr<NotifyListenerVector> m_positionCallbacks = nullptr;
std::atomic<int32_t> m_periodScale{0};
std::shared_ptr<NotifyListenerVector> m_periodScaleCallbacks = nullptr;
std::atomic<HAL_Bool> m_zeroLatch{false};
std::shared_ptr<NotifyListenerVector> m_zeroLatchCallbacks = nullptr;
};
extern PWMData* SimPWMData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "RelayDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,253 +21,33 @@ void InitializeRelayData() {
RelayData* hal::SimRelayData;
void RelayData::ResetData() {
m_initializedForward = false;
m_initializedForwardCallbacks = nullptr;
m_initializedReverse = false;
m_initializedReverseCallbacks = nullptr;
m_forward = false;
m_forwardCallbacks = nullptr;
m_reverse = false;
m_reverseCallbacks = nullptr;
}
int32_t RelayData::RegisterInitializedForwardCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedForwardCallbacks =
RegisterCallback(m_initializedForwardCallbacks, "InitializedForward",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitializedForward());
callback("InitializedForward", param, &value);
}
return newUid;
}
void RelayData::CancelInitializedForwardCallback(int32_t uid) {
m_initializedForwardCallbacks =
CancelCallback(m_initializedForwardCallbacks, uid);
}
void RelayData::InvokeInitializedForwardCallback(HAL_Value value) {
InvokeCallback(m_initializedForwardCallbacks, "InitializedForward", &value);
}
HAL_Bool RelayData::GetInitializedForward() { return m_initializedForward; }
void RelayData::SetInitializedForward(HAL_Bool initializedForward) {
HAL_Bool oldValue = m_initializedForward.exchange(initializedForward);
if (oldValue != initializedForward) {
InvokeInitializedForwardCallback(MakeBoolean(initializedForward));
}
}
int32_t RelayData::RegisterInitializedReverseCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedReverseCallbacks =
RegisterCallback(m_initializedReverseCallbacks, "InitializedReverse",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitializedReverse());
callback("InitializedReverse", param, &value);
}
return newUid;
}
void RelayData::CancelInitializedReverseCallback(int32_t uid) {
m_initializedReverseCallbacks =
CancelCallback(m_initializedReverseCallbacks, uid);
}
void RelayData::InvokeInitializedReverseCallback(HAL_Value value) {
InvokeCallback(m_initializedReverseCallbacks, "InitializedReverse", &value);
}
HAL_Bool RelayData::GetInitializedReverse() { return m_initializedReverse; }
void RelayData::SetInitializedReverse(HAL_Bool initializedReverse) {
HAL_Bool oldValue = m_initializedReverse.exchange(initializedReverse);
if (oldValue != initializedReverse) {
InvokeInitializedReverseCallback(MakeBoolean(initializedReverse));
}
}
int32_t RelayData::RegisterForwardCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_forwardCallbacks = RegisterCallback(m_forwardCallbacks, "Forward",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetForward());
callback("Forward", param, &value);
}
return newUid;
}
void RelayData::CancelForwardCallback(int32_t uid) {
m_forwardCallbacks = CancelCallback(m_forwardCallbacks, uid);
}
void RelayData::InvokeForwardCallback(HAL_Value value) {
InvokeCallback(m_forwardCallbacks, "Forward", &value);
}
HAL_Bool RelayData::GetForward() { return m_forward; }
void RelayData::SetForward(HAL_Bool forward) {
HAL_Bool oldValue = m_forward.exchange(forward);
if (oldValue != forward) {
InvokeForwardCallback(MakeBoolean(forward));
}
}
int32_t RelayData::RegisterReverseCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_reverseCallbacks = RegisterCallback(m_reverseCallbacks, "Reverse",
callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetReverse());
callback("Reverse", param, &value);
}
return newUid;
}
void RelayData::CancelReverseCallback(int32_t uid) {
m_reverseCallbacks = CancelCallback(m_reverseCallbacks, uid);
}
void RelayData::InvokeReverseCallback(HAL_Value value) {
InvokeCallback(m_reverseCallbacks, "Reverse", &value);
}
HAL_Bool RelayData::GetReverse() { return m_reverse; }
void RelayData::SetReverse(HAL_Bool reverse) {
HAL_Bool oldValue = m_reverse.exchange(reverse);
if (oldValue != reverse) {
InvokeReverseCallback(MakeBoolean(reverse));
}
initializedForward.Reset(false);
initializedReverse.Reset(false);
forward.Reset(false);
reverse.Reset(false);
}
extern "C" {
void HALSIM_ResetRelayData(int32_t index) { SimRelayData[index].ResetData(); }
int32_t HALSIM_RegisterRelayInitializedForwardCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimRelayData[index].RegisterInitializedForwardCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Relay##CAPINAME, SimRelayData, \
LOWERNAME)
void HALSIM_CancelRelayInitializedForwardCallback(int32_t index, int32_t uid) {
SimRelayData[index].CancelInitializedForwardCallback(uid);
}
DEFINE_CAPI(HAL_Bool, InitializedForward, initializedForward)
DEFINE_CAPI(HAL_Bool, InitializedReverse, initializedReverse)
DEFINE_CAPI(HAL_Bool, Forward, forward)
DEFINE_CAPI(HAL_Bool, Reverse, reverse)
HAL_Bool HALSIM_GetRelayInitializedForward(int32_t index) {
return SimRelayData[index].GetInitializedForward();
}
void HALSIM_SetRelayInitializedForward(int32_t index,
HAL_Bool initializedForward) {
SimRelayData[index].SetInitializedForward(initializedForward);
}
int32_t HALSIM_RegisterRelayInitializedReverseCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimRelayData[index].RegisterInitializedReverseCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRelayInitializedReverseCallback(int32_t index, int32_t uid) {
SimRelayData[index].CancelInitializedReverseCallback(uid);
}
HAL_Bool HALSIM_GetRelayInitializedReverse(int32_t index) {
return SimRelayData[index].GetInitializedReverse();
}
void HALSIM_SetRelayInitializedReverse(int32_t index,
HAL_Bool initializedReverse) {
SimRelayData[index].SetInitializedReverse(initializedReverse);
}
int32_t HALSIM_RegisterRelayForwardCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRelayData[index].RegisterForwardCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRelayForwardCallback(int32_t index, int32_t uid) {
SimRelayData[index].CancelForwardCallback(uid);
}
HAL_Bool HALSIM_GetRelayForward(int32_t index) {
return SimRelayData[index].GetForward();
}
void HALSIM_SetRelayForward(int32_t index, HAL_Bool forward) {
SimRelayData[index].SetForward(forward);
}
int32_t HALSIM_RegisterRelayReverseCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRelayData[index].RegisterReverseCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRelayReverseCallback(int32_t index, int32_t uid) {
SimRelayData[index].CancelReverseCallback(uid);
}
HAL_Bool HALSIM_GetRelayReverse(int32_t index) {
return SimRelayData[index].GetReverse();
}
void HALSIM_SetRelayReverse(int32_t index, HAL_Bool reverse) {
SimRelayData[index].SetReverse(reverse);
}
#define REGISTER(NAME) \
SimRelayData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterRelayAllCallbacks(int32_t index,
HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
SimRelayData[index].RegisterInitializedForwardCallback(callback, param,
initialNotify);
SimRelayData[index].RegisterInitializedReverseCallback(callback, param,
initialNotify);
SimRelayData[index].RegisterForwardCallback(callback, param, initialNotify);
SimRelayData[index].RegisterReverseCallback(callback, param, initialNotify);
REGISTER(initializedForward);
REGISTER(initializedReverse);
REGISTER(forward);
REGISTER(reverse);
}
} // extern "C"

View File

@@ -7,59 +7,25 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/RelayData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class RelayData {
HAL_SIMDATAVALUE_DEFINE_NAME(InitializedForward)
HAL_SIMDATAVALUE_DEFINE_NAME(InitializedReverse)
HAL_SIMDATAVALUE_DEFINE_NAME(Forward)
HAL_SIMDATAVALUE_DEFINE_NAME(Reverse)
public:
int32_t RegisterInitializedForwardCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelInitializedForwardCallback(int32_t uid);
void InvokeInitializedForwardCallback(HAL_Value value);
HAL_Bool GetInitializedForward();
void SetInitializedForward(HAL_Bool initializedForward);
int32_t RegisterInitializedReverseCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void CancelInitializedReverseCallback(int32_t uid);
void InvokeInitializedReverseCallback(HAL_Value value);
HAL_Bool GetInitializedReverse();
void SetInitializedReverse(HAL_Bool initializedReverse);
int32_t RegisterForwardCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelForwardCallback(int32_t uid);
void InvokeForwardCallback(HAL_Value value);
HAL_Bool GetForward();
void SetForward(HAL_Bool forward);
int32_t RegisterReverseCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelReverseCallback(int32_t uid);
void InvokeReverseCallback(HAL_Value value);
HAL_Bool GetReverse();
void SetReverse(HAL_Bool reverse);
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedForwardName>
initializedForward{false};
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedReverseName>
initializedReverse{false};
SimDataValue<HAL_Bool, MakeBoolean, GetForwardName> forward{false};
SimDataValue<HAL_Bool, MakeBoolean, GetReverseName> reverse{false};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initializedForward{false};
std::shared_ptr<NotifyListenerVector> m_initializedForwardCallbacks = nullptr;
std::atomic<HAL_Bool> m_initializedReverse{false};
std::shared_ptr<NotifyListenerVector> m_initializedReverseCallbacks = nullptr;
std::atomic<HAL_Bool> m_forward{false};
std::shared_ptr<NotifyListenerVector> m_forwardCallbacks = nullptr;
std::atomic<HAL_Bool> m_reverse{false};
std::shared_ptr<NotifyListenerVector> m_reverseCallbacks = nullptr;
};
extern RelayData* SimRelayData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "RoboRioDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,576 +21,21 @@ void InitializeRoboRioData() {
RoboRioData* hal::SimRoboRioData;
void RoboRioData::ResetData() {
m_fPGAButton = false;
m_fPGAButtonCallbacks = nullptr;
m_vInVoltage = 0.0;
m_vInVoltageCallbacks = nullptr;
m_vInCurrent = 0.0;
m_vInCurrentCallbacks = nullptr;
m_userVoltage6V = 6.0;
m_userVoltage6VCallbacks = nullptr;
m_userCurrent6V = 0.0;
m_userCurrent6VCallbacks = nullptr;
m_userActive6V = false;
m_userActive6VCallbacks = nullptr;
m_userVoltage5V = 5.0;
m_userVoltage5VCallbacks = nullptr;
m_userCurrent5V = 0.0;
m_userCurrent5VCallbacks = nullptr;
m_userActive5V = false;
m_userActive5VCallbacks = nullptr;
m_userVoltage3V3 = 3.3;
m_userVoltage3V3Callbacks = nullptr;
m_userCurrent3V3 = 0.0;
m_userCurrent3V3Callbacks = nullptr;
m_userActive3V3 = false;
m_userActive3V3Callbacks = nullptr;
m_userFaults6V = 0;
m_userFaults6VCallbacks = nullptr;
m_userFaults5V = 0;
m_userFaults5VCallbacks = nullptr;
m_userFaults3V3 = 0;
m_userFaults3V3Callbacks = nullptr;
}
int32_t RoboRioData::RegisterFPGAButtonCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_fPGAButtonCallbacks = RegisterCallback(
m_fPGAButtonCallbacks, "FPGAButton", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetFPGAButton());
callback("FPGAButton", param, &value);
}
return newUid;
}
void RoboRioData::CancelFPGAButtonCallback(int32_t uid) {
m_fPGAButtonCallbacks = CancelCallback(m_fPGAButtonCallbacks, uid);
}
void RoboRioData::InvokeFPGAButtonCallback(HAL_Value value) {
InvokeCallback(m_fPGAButtonCallbacks, "FPGAButton", &value);
}
HAL_Bool RoboRioData::GetFPGAButton() { return m_fPGAButton; }
void RoboRioData::SetFPGAButton(HAL_Bool fPGAButton) {
HAL_Bool oldValue = m_fPGAButton.exchange(fPGAButton);
if (oldValue != fPGAButton) {
InvokeFPGAButtonCallback(MakeBoolean(fPGAButton));
}
}
int32_t RoboRioData::RegisterVInVoltageCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_vInVoltageCallbacks = RegisterCallback(
m_vInVoltageCallbacks, "VInVoltage", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetVInVoltage());
callback("VInVoltage", param, &value);
}
return newUid;
}
void RoboRioData::CancelVInVoltageCallback(int32_t uid) {
m_vInVoltageCallbacks = CancelCallback(m_vInVoltageCallbacks, uid);
}
void RoboRioData::InvokeVInVoltageCallback(HAL_Value value) {
InvokeCallback(m_vInVoltageCallbacks, "VInVoltage", &value);
}
double RoboRioData::GetVInVoltage() { return m_vInVoltage; }
void RoboRioData::SetVInVoltage(double vInVoltage) {
double oldValue = m_vInVoltage.exchange(vInVoltage);
if (oldValue != vInVoltage) {
InvokeVInVoltageCallback(MakeDouble(vInVoltage));
}
}
int32_t RoboRioData::RegisterVInCurrentCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_vInCurrentCallbacks = RegisterCallback(
m_vInCurrentCallbacks, "VInCurrent", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetVInCurrent());
callback("VInCurrent", param, &value);
}
return newUid;
}
void RoboRioData::CancelVInCurrentCallback(int32_t uid) {
m_vInCurrentCallbacks = CancelCallback(m_vInCurrentCallbacks, uid);
}
void RoboRioData::InvokeVInCurrentCallback(HAL_Value value) {
InvokeCallback(m_vInCurrentCallbacks, "VInCurrent", &value);
}
double RoboRioData::GetVInCurrent() { return m_vInCurrent; }
void RoboRioData::SetVInCurrent(double vInCurrent) {
double oldValue = m_vInCurrent.exchange(vInCurrent);
if (oldValue != vInCurrent) {
InvokeVInCurrentCallback(MakeDouble(vInCurrent));
}
}
int32_t RoboRioData::RegisterUserVoltage6VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage6VCallbacks = RegisterCallback(
m_userVoltage6VCallbacks, "UserVoltage6V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserVoltage6V());
callback("UserVoltage6V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserVoltage6VCallback(int32_t uid) {
m_userVoltage6VCallbacks = CancelCallback(m_userVoltage6VCallbacks, uid);
}
void RoboRioData::InvokeUserVoltage6VCallback(HAL_Value value) {
InvokeCallback(m_userVoltage6VCallbacks, "UserVoltage6V", &value);
}
double RoboRioData::GetUserVoltage6V() { return m_userVoltage6V; }
void RoboRioData::SetUserVoltage6V(double userVoltage6V) {
double oldValue = m_userVoltage6V.exchange(userVoltage6V);
if (oldValue != userVoltage6V) {
InvokeUserVoltage6VCallback(MakeDouble(userVoltage6V));
}
}
int32_t RoboRioData::RegisterUserCurrent6VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent6VCallbacks = RegisterCallback(
m_userCurrent6VCallbacks, "UserCurrent6V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserCurrent6V());
callback("UserCurrent6V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserCurrent6VCallback(int32_t uid) {
m_userCurrent6VCallbacks = CancelCallback(m_userCurrent6VCallbacks, uid);
}
void RoboRioData::InvokeUserCurrent6VCallback(HAL_Value value) {
InvokeCallback(m_userCurrent6VCallbacks, "UserCurrent6V", &value);
}
double RoboRioData::GetUserCurrent6V() { return m_userCurrent6V; }
void RoboRioData::SetUserCurrent6V(double userCurrent6V) {
double oldValue = m_userCurrent6V.exchange(userCurrent6V);
if (oldValue != userCurrent6V) {
InvokeUserCurrent6VCallback(MakeDouble(userCurrent6V));
}
}
int32_t RoboRioData::RegisterUserActive6VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive6VCallbacks = RegisterCallback(
m_userActive6VCallbacks, "UserActive6V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetUserActive6V());
callback("UserActive6V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserActive6VCallback(int32_t uid) {
m_userActive6VCallbacks = CancelCallback(m_userActive6VCallbacks, uid);
}
void RoboRioData::InvokeUserActive6VCallback(HAL_Value value) {
InvokeCallback(m_userActive6VCallbacks, "UserActive6V", &value);
}
HAL_Bool RoboRioData::GetUserActive6V() { return m_userActive6V; }
void RoboRioData::SetUserActive6V(HAL_Bool userActive6V) {
HAL_Bool oldValue = m_userActive6V.exchange(userActive6V);
if (oldValue != userActive6V) {
InvokeUserActive6VCallback(MakeBoolean(userActive6V));
}
}
int32_t RoboRioData::RegisterUserVoltage5VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage5VCallbacks = RegisterCallback(
m_userVoltage5VCallbacks, "UserVoltage5V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserVoltage5V());
callback("UserVoltage5V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserVoltage5VCallback(int32_t uid) {
m_userVoltage5VCallbacks = CancelCallback(m_userVoltage5VCallbacks, uid);
}
void RoboRioData::InvokeUserVoltage5VCallback(HAL_Value value) {
InvokeCallback(m_userVoltage5VCallbacks, "UserVoltage5V", &value);
}
double RoboRioData::GetUserVoltage5V() { return m_userVoltage5V; }
void RoboRioData::SetUserVoltage5V(double userVoltage5V) {
double oldValue = m_userVoltage5V.exchange(userVoltage5V);
if (oldValue != userVoltage5V) {
InvokeUserVoltage5VCallback(MakeDouble(userVoltage5V));
}
}
int32_t RoboRioData::RegisterUserCurrent5VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent5VCallbacks = RegisterCallback(
m_userCurrent5VCallbacks, "UserCurrent5V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserCurrent5V());
callback("UserCurrent5V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserCurrent5VCallback(int32_t uid) {
m_userCurrent5VCallbacks = CancelCallback(m_userCurrent5VCallbacks, uid);
}
void RoboRioData::InvokeUserCurrent5VCallback(HAL_Value value) {
InvokeCallback(m_userCurrent5VCallbacks, "UserCurrent5V", &value);
}
double RoboRioData::GetUserCurrent5V() { return m_userCurrent5V; }
void RoboRioData::SetUserCurrent5V(double userCurrent5V) {
double oldValue = m_userCurrent5V.exchange(userCurrent5V);
if (oldValue != userCurrent5V) {
InvokeUserCurrent5VCallback(MakeDouble(userCurrent5V));
}
}
int32_t RoboRioData::RegisterUserActive5VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive5VCallbacks = RegisterCallback(
m_userActive5VCallbacks, "UserActive5V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetUserActive5V());
callback("UserActive5V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserActive5VCallback(int32_t uid) {
m_userActive5VCallbacks = CancelCallback(m_userActive5VCallbacks, uid);
}
void RoboRioData::InvokeUserActive5VCallback(HAL_Value value) {
InvokeCallback(m_userActive5VCallbacks, "UserActive5V", &value);
}
HAL_Bool RoboRioData::GetUserActive5V() { return m_userActive5V; }
void RoboRioData::SetUserActive5V(HAL_Bool userActive5V) {
HAL_Bool oldValue = m_userActive5V.exchange(userActive5V);
if (oldValue != userActive5V) {
InvokeUserActive5VCallback(MakeBoolean(userActive5V));
}
}
int32_t RoboRioData::RegisterUserVoltage3V3Callback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage3V3Callbacks = RegisterCallback(
m_userVoltage3V3Callbacks, "UserVoltage3V3", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserVoltage3V3());
callback("UserVoltage3V3", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserVoltage3V3Callback(int32_t uid) {
m_userVoltage3V3Callbacks = CancelCallback(m_userVoltage3V3Callbacks, uid);
}
void RoboRioData::InvokeUserVoltage3V3Callback(HAL_Value value) {
InvokeCallback(m_userVoltage3V3Callbacks, "UserVoltage3V3", &value);
}
double RoboRioData::GetUserVoltage3V3() { return m_userVoltage3V3; }
void RoboRioData::SetUserVoltage3V3(double userVoltage3V3) {
double oldValue = m_userVoltage3V3.exchange(userVoltage3V3);
if (oldValue != userVoltage3V3) {
InvokeUserVoltage3V3Callback(MakeDouble(userVoltage3V3));
}
}
int32_t RoboRioData::RegisterUserCurrent3V3Callback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent3V3Callbacks = RegisterCallback(
m_userCurrent3V3Callbacks, "UserCurrent3V3", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetUserCurrent3V3());
callback("UserCurrent3V3", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserCurrent3V3Callback(int32_t uid) {
m_userCurrent3V3Callbacks = CancelCallback(m_userCurrent3V3Callbacks, uid);
}
void RoboRioData::InvokeUserCurrent3V3Callback(HAL_Value value) {
InvokeCallback(m_userCurrent3V3Callbacks, "UserCurrent3V3", &value);
}
double RoboRioData::GetUserCurrent3V3() { return m_userCurrent3V3; }
void RoboRioData::SetUserCurrent3V3(double userCurrent3V3) {
double oldValue = m_userCurrent3V3.exchange(userCurrent3V3);
if (oldValue != userCurrent3V3) {
InvokeUserCurrent3V3Callback(MakeDouble(userCurrent3V3));
}
}
int32_t RoboRioData::RegisterUserActive3V3Callback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive3V3Callbacks = RegisterCallback(
m_userActive3V3Callbacks, "UserActive3V3", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetUserActive3V3());
callback("UserActive3V3", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserActive3V3Callback(int32_t uid) {
m_userActive3V3Callbacks = CancelCallback(m_userActive3V3Callbacks, uid);
}
void RoboRioData::InvokeUserActive3V3Callback(HAL_Value value) {
InvokeCallback(m_userActive3V3Callbacks, "UserActive3V3", &value);
}
HAL_Bool RoboRioData::GetUserActive3V3() { return m_userActive3V3; }
void RoboRioData::SetUserActive3V3(HAL_Bool userActive3V3) {
HAL_Bool oldValue = m_userActive3V3.exchange(userActive3V3);
if (oldValue != userActive3V3) {
InvokeUserActive3V3Callback(MakeBoolean(userActive3V3));
}
}
int32_t RoboRioData::RegisterUserFaults6VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults6VCallbacks = RegisterCallback(
m_userFaults6VCallbacks, "UserFaults6V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetUserFaults6V());
callback("UserFaults6V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserFaults6VCallback(int32_t uid) {
m_userFaults6VCallbacks = CancelCallback(m_userFaults6VCallbacks, uid);
}
void RoboRioData::InvokeUserFaults6VCallback(HAL_Value value) {
InvokeCallback(m_userFaults6VCallbacks, "UserFaults6V", &value);
}
int32_t RoboRioData::GetUserFaults6V() { return m_userFaults6V; }
void RoboRioData::SetUserFaults6V(int32_t userFaults6V) {
int32_t oldValue = m_userFaults6V.exchange(userFaults6V);
if (oldValue != userFaults6V) {
InvokeUserFaults6VCallback(MakeInt(userFaults6V));
}
}
int32_t RoboRioData::RegisterUserFaults5VCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults5VCallbacks = RegisterCallback(
m_userFaults5VCallbacks, "UserFaults5V", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetUserFaults5V());
callback("UserFaults5V", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserFaults5VCallback(int32_t uid) {
m_userFaults5VCallbacks = CancelCallback(m_userFaults5VCallbacks, uid);
}
void RoboRioData::InvokeUserFaults5VCallback(HAL_Value value) {
InvokeCallback(m_userFaults5VCallbacks, "UserFaults5V", &value);
}
int32_t RoboRioData::GetUserFaults5V() { return m_userFaults5V; }
void RoboRioData::SetUserFaults5V(int32_t userFaults5V) {
int32_t oldValue = m_userFaults5V.exchange(userFaults5V);
if (oldValue != userFaults5V) {
InvokeUserFaults5VCallback(MakeInt(userFaults5V));
}
}
int32_t RoboRioData::RegisterUserFaults3V3Callback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults3V3Callbacks = RegisterCallback(
m_userFaults3V3Callbacks, "UserFaults3V3", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetUserFaults3V3());
callback("UserFaults3V3", param, &value);
}
return newUid;
}
void RoboRioData::CancelUserFaults3V3Callback(int32_t uid) {
m_userFaults3V3Callbacks = CancelCallback(m_userFaults3V3Callbacks, uid);
}
void RoboRioData::InvokeUserFaults3V3Callback(HAL_Value value) {
InvokeCallback(m_userFaults3V3Callbacks, "UserFaults3V3", &value);
}
int32_t RoboRioData::GetUserFaults3V3() { return m_userFaults3V3; }
void RoboRioData::SetUserFaults3V3(int32_t userFaults3V3) {
int32_t oldValue = m_userFaults3V3.exchange(userFaults3V3);
if (oldValue != userFaults3V3) {
InvokeUserFaults3V3Callback(MakeInt(userFaults3V3));
}
fpgaButton.Reset(false);
vInVoltage.Reset(0.0);
vInCurrent.Reset(0.0);
userVoltage6V.Reset(6.0);
userCurrent6V.Reset(0.0);
userActive6V.Reset(false);
userVoltage5V.Reset(5.0);
userCurrent5V.Reset(0.0);
userActive5V.Reset(false);
userVoltage3V3.Reset(3.3);
userCurrent3V3.Reset(0.0);
userActive3V3.Reset(false);
userFaults6V.Reset(0);
userFaults5V.Reset(0);
userFaults3V3.Reset(0);
}
extern "C" {
@@ -599,336 +43,46 @@ void HALSIM_ResetRoboRioData(int32_t index) {
SimRoboRioData[index].ResetData();
}
int32_t HALSIM_RegisterRoboRioFPGAButtonCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterFPGAButtonCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, RoboRio##CAPINAME, \
SimRoboRioData, LOWERNAME)
void HALSIM_CancelRoboRioFPGAButtonCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelFPGAButtonCallback(uid);
}
DEFINE_CAPI(HAL_Bool, FPGAButton, fpgaButton)
DEFINE_CAPI(double, VInVoltage, vInVoltage)
DEFINE_CAPI(double, VInCurrent, vInCurrent)
DEFINE_CAPI(double, UserVoltage6V, userVoltage6V)
DEFINE_CAPI(double, UserCurrent6V, userCurrent6V)
DEFINE_CAPI(HAL_Bool, UserActive6V, userActive6V)
DEFINE_CAPI(double, UserVoltage5V, userVoltage5V)
DEFINE_CAPI(double, UserCurrent5V, userCurrent5V)
DEFINE_CAPI(HAL_Bool, UserActive5V, userActive5V)
DEFINE_CAPI(double, UserVoltage3V3, userVoltage3V3)
DEFINE_CAPI(double, UserCurrent3V3, userCurrent3V3)
DEFINE_CAPI(HAL_Bool, UserActive3V3, userActive3V3)
DEFINE_CAPI(int32_t, UserFaults6V, userFaults6V)
DEFINE_CAPI(int32_t, UserFaults5V, userFaults5V)
DEFINE_CAPI(int32_t, UserFaults3V3, userFaults3V3)
HAL_Bool HALSIM_GetRoboRioFPGAButton(int32_t index) {
return SimRoboRioData[index].GetFPGAButton();
}
void HALSIM_SetRoboRioFPGAButton(int32_t index, HAL_Bool fPGAButton) {
SimRoboRioData[index].SetFPGAButton(fPGAButton);
}
int32_t HALSIM_RegisterRoboRioVInVoltageCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterVInVoltageCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioVInVoltageCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelVInVoltageCallback(uid);
}
double HALSIM_GetRoboRioVInVoltage(int32_t index) {
return SimRoboRioData[index].GetVInVoltage();
}
void HALSIM_SetRoboRioVInVoltage(int32_t index, double vInVoltage) {
SimRoboRioData[index].SetVInVoltage(vInVoltage);
}
int32_t HALSIM_RegisterRoboRioVInCurrentCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterVInCurrentCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioVInCurrentCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelVInCurrentCallback(uid);
}
double HALSIM_GetRoboRioVInCurrent(int32_t index) {
return SimRoboRioData[index].GetVInCurrent();
}
void HALSIM_SetRoboRioVInCurrent(int32_t index, double vInCurrent) {
SimRoboRioData[index].SetVInCurrent(vInCurrent);
}
int32_t HALSIM_RegisterRoboRioUserVoltage6VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserVoltage6VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserVoltage6VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserVoltage6VCallback(uid);
}
double HALSIM_GetRoboRioUserVoltage6V(int32_t index) {
return SimRoboRioData[index].GetUserVoltage6V();
}
void HALSIM_SetRoboRioUserVoltage6V(int32_t index, double userVoltage6V) {
SimRoboRioData[index].SetUserVoltage6V(userVoltage6V);
}
int32_t HALSIM_RegisterRoboRioUserCurrent6VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserCurrent6VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserCurrent6VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserCurrent6VCallback(uid);
}
double HALSIM_GetRoboRioUserCurrent6V(int32_t index) {
return SimRoboRioData[index].GetUserCurrent6V();
}
void HALSIM_SetRoboRioUserCurrent6V(int32_t index, double userCurrent6V) {
SimRoboRioData[index].SetUserCurrent6V(userCurrent6V);
}
int32_t HALSIM_RegisterRoboRioUserActive6VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserActive6VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserActive6VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserActive6VCallback(uid);
}
HAL_Bool HALSIM_GetRoboRioUserActive6V(int32_t index) {
return SimRoboRioData[index].GetUserActive6V();
}
void HALSIM_SetRoboRioUserActive6V(int32_t index, HAL_Bool userActive6V) {
SimRoboRioData[index].SetUserActive6V(userActive6V);
}
int32_t HALSIM_RegisterRoboRioUserVoltage5VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserVoltage5VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserVoltage5VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserVoltage5VCallback(uid);
}
double HALSIM_GetRoboRioUserVoltage5V(int32_t index) {
return SimRoboRioData[index].GetUserVoltage5V();
}
void HALSIM_SetRoboRioUserVoltage5V(int32_t index, double userVoltage5V) {
SimRoboRioData[index].SetUserVoltage5V(userVoltage5V);
}
int32_t HALSIM_RegisterRoboRioUserCurrent5VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserCurrent5VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserCurrent5VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserCurrent5VCallback(uid);
}
double HALSIM_GetRoboRioUserCurrent5V(int32_t index) {
return SimRoboRioData[index].GetUserCurrent5V();
}
void HALSIM_SetRoboRioUserCurrent5V(int32_t index, double userCurrent5V) {
SimRoboRioData[index].SetUserCurrent5V(userCurrent5V);
}
int32_t HALSIM_RegisterRoboRioUserActive5VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserActive5VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserActive5VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserActive5VCallback(uid);
}
HAL_Bool HALSIM_GetRoboRioUserActive5V(int32_t index) {
return SimRoboRioData[index].GetUserActive5V();
}
void HALSIM_SetRoboRioUserActive5V(int32_t index, HAL_Bool userActive5V) {
SimRoboRioData[index].SetUserActive5V(userActive5V);
}
int32_t HALSIM_RegisterRoboRioUserVoltage3V3Callback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserVoltage3V3Callback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserVoltage3V3Callback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserVoltage3V3Callback(uid);
}
double HALSIM_GetRoboRioUserVoltage3V3(int32_t index) {
return SimRoboRioData[index].GetUserVoltage3V3();
}
void HALSIM_SetRoboRioUserVoltage3V3(int32_t index, double userVoltage3V3) {
SimRoboRioData[index].SetUserVoltage3V3(userVoltage3V3);
}
int32_t HALSIM_RegisterRoboRioUserCurrent3V3Callback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserCurrent3V3Callback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserCurrent3V3Callback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserCurrent3V3Callback(uid);
}
double HALSIM_GetRoboRioUserCurrent3V3(int32_t index) {
return SimRoboRioData[index].GetUserCurrent3V3();
}
void HALSIM_SetRoboRioUserCurrent3V3(int32_t index, double userCurrent3V3) {
SimRoboRioData[index].SetUserCurrent3V3(userCurrent3V3);
}
int32_t HALSIM_RegisterRoboRioUserActive3V3Callback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserActive3V3Callback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserActive3V3Callback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserActive3V3Callback(uid);
}
HAL_Bool HALSIM_GetRoboRioUserActive3V3(int32_t index) {
return SimRoboRioData[index].GetUserActive3V3();
}
void HALSIM_SetRoboRioUserActive3V3(int32_t index, HAL_Bool userActive3V3) {
SimRoboRioData[index].SetUserActive3V3(userActive3V3);
}
int32_t HALSIM_RegisterRoboRioUserFaults6VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserFaults6VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserFaults6VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserFaults6VCallback(uid);
}
int32_t HALSIM_GetRoboRioUserFaults6V(int32_t index) {
return SimRoboRioData[index].GetUserFaults6V();
}
void HALSIM_SetRoboRioUserFaults6V(int32_t index, int32_t userFaults6V) {
SimRoboRioData[index].SetUserFaults6V(userFaults6V);
}
int32_t HALSIM_RegisterRoboRioUserFaults5VCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserFaults5VCallback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserFaults5VCallback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserFaults5VCallback(uid);
}
int32_t HALSIM_GetRoboRioUserFaults5V(int32_t index) {
return SimRoboRioData[index].GetUserFaults5V();
}
void HALSIM_SetRoboRioUserFaults5V(int32_t index, int32_t userFaults5V) {
SimRoboRioData[index].SetUserFaults5V(userFaults5V);
}
int32_t HALSIM_RegisterRoboRioUserFaults3V3Callback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimRoboRioData[index].RegisterUserFaults3V3Callback(callback, param,
initialNotify);
}
void HALSIM_CancelRoboRioUserFaults3V3Callback(int32_t index, int32_t uid) {
SimRoboRioData[index].CancelUserFaults3V3Callback(uid);
}
int32_t HALSIM_GetRoboRioUserFaults3V3(int32_t index) {
return SimRoboRioData[index].GetUserFaults3V3();
}
void HALSIM_SetRoboRioUserFaults3V3(int32_t index, int32_t userFaults3V3) {
SimRoboRioData[index].SetUserFaults3V3(userFaults3V3);
}
#define REGISTER(NAME) \
SimRoboRioData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterRoboRioAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify) {
SimRoboRioData[index].RegisterFPGAButtonCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterVInVoltageCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterVInCurrentCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserVoltage6VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserCurrent6VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserActive6VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserVoltage5VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserCurrent5VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserActive5VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserVoltage3V3Callback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserCurrent3V3Callback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserActive3V3Callback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserFaults6VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserFaults5VCallback(callback, param,
initialNotify);
SimRoboRioData[index].RegisterUserFaults3V3Callback(callback, param,
initialNotify);
REGISTER(fpgaButton);
REGISTER(vInVoltage);
REGISTER(vInCurrent);
REGISTER(userVoltage6V);
REGISTER(userCurrent6V);
REGISTER(userActive6V);
REGISTER(userVoltage5V);
REGISTER(userCurrent5V);
REGISTER(userActive5V);
REGISTER(userVoltage3V3);
REGISTER(userCurrent3V3);
REGISTER(userActive3V3);
REGISTER(userFaults6V);
REGISTER(userFaults5V);
REGISTER(userFaults3V3);
}
} // extern "C"

View File

@@ -7,156 +7,46 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/RoboRioData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class RoboRioData {
HAL_SIMDATAVALUE_DEFINE_NAME(FPGAButton)
HAL_SIMDATAVALUE_DEFINE_NAME(VInVoltage)
HAL_SIMDATAVALUE_DEFINE_NAME(VInCurrent)
HAL_SIMDATAVALUE_DEFINE_NAME(UserVoltage6V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserCurrent6V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserActive6V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserVoltage5V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserCurrent5V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserActive5V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserVoltage3V3)
HAL_SIMDATAVALUE_DEFINE_NAME(UserCurrent3V3)
HAL_SIMDATAVALUE_DEFINE_NAME(UserActive3V3)
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults6V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults5V)
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults3V3)
public:
int32_t RegisterFPGAButtonCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelFPGAButtonCallback(int32_t uid);
void InvokeFPGAButtonCallback(HAL_Value value);
HAL_Bool GetFPGAButton();
void SetFPGAButton(HAL_Bool fPGAButton);
int32_t RegisterVInVoltageCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelVInVoltageCallback(int32_t uid);
void InvokeVInVoltageCallback(HAL_Value value);
double GetVInVoltage();
void SetVInVoltage(double vInVoltage);
int32_t RegisterVInCurrentCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelVInCurrentCallback(int32_t uid);
void InvokeVInCurrentCallback(HAL_Value value);
double GetVInCurrent();
void SetVInCurrent(double vInCurrent);
int32_t RegisterUserVoltage6VCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserVoltage6VCallback(int32_t uid);
void InvokeUserVoltage6VCallback(HAL_Value value);
double GetUserVoltage6V();
void SetUserVoltage6V(double userVoltage6V);
int32_t RegisterUserCurrent6VCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserCurrent6VCallback(int32_t uid);
void InvokeUserCurrent6VCallback(HAL_Value value);
double GetUserCurrent6V();
void SetUserCurrent6V(double userCurrent6V);
int32_t RegisterUserActive6VCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelUserActive6VCallback(int32_t uid);
void InvokeUserActive6VCallback(HAL_Value value);
HAL_Bool GetUserActive6V();
void SetUserActive6V(HAL_Bool userActive6V);
int32_t RegisterUserVoltage5VCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserVoltage5VCallback(int32_t uid);
void InvokeUserVoltage5VCallback(HAL_Value value);
double GetUserVoltage5V();
void SetUserVoltage5V(double userVoltage5V);
int32_t RegisterUserCurrent5VCallback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserCurrent5VCallback(int32_t uid);
void InvokeUserCurrent5VCallback(HAL_Value value);
double GetUserCurrent5V();
void SetUserCurrent5V(double userCurrent5V);
int32_t RegisterUserActive5VCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelUserActive5VCallback(int32_t uid);
void InvokeUserActive5VCallback(HAL_Value value);
HAL_Bool GetUserActive5V();
void SetUserActive5V(HAL_Bool userActive5V);
int32_t RegisterUserVoltage3V3Callback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserVoltage3V3Callback(int32_t uid);
void InvokeUserVoltage3V3Callback(HAL_Value value);
double GetUserVoltage3V3();
void SetUserVoltage3V3(double userVoltage3V3);
int32_t RegisterUserCurrent3V3Callback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserCurrent3V3Callback(int32_t uid);
void InvokeUserCurrent3V3Callback(HAL_Value value);
double GetUserCurrent3V3();
void SetUserCurrent3V3(double userCurrent3V3);
int32_t RegisterUserActive3V3Callback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserActive3V3Callback(int32_t uid);
void InvokeUserActive3V3Callback(HAL_Value value);
HAL_Bool GetUserActive3V3();
void SetUserActive3V3(HAL_Bool userActive3V3);
int32_t RegisterUserFaults6VCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelUserFaults6VCallback(int32_t uid);
void InvokeUserFaults6VCallback(HAL_Value value);
int32_t GetUserFaults6V();
void SetUserFaults6V(int32_t userFaults6V);
int32_t RegisterUserFaults5VCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelUserFaults5VCallback(int32_t uid);
void InvokeUserFaults5VCallback(HAL_Value value);
int32_t GetUserFaults5V();
void SetUserFaults5V(int32_t userFaults5V);
int32_t RegisterUserFaults3V3Callback(HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void CancelUserFaults3V3Callback(int32_t uid);
void InvokeUserFaults3V3Callback(HAL_Value value);
int32_t GetUserFaults3V3();
void SetUserFaults3V3(int32_t userFaults3V3);
SimDataValue<HAL_Bool, MakeBoolean, GetFPGAButtonName> fpgaButton{false};
SimDataValue<double, MakeDouble, GetVInVoltageName> vInVoltage{0.0};
SimDataValue<double, MakeDouble, GetVInCurrentName> vInCurrent{0.0};
SimDataValue<double, MakeDouble, GetUserVoltage6VName> userVoltage6V{6.0};
SimDataValue<double, MakeDouble, GetUserCurrent6VName> userCurrent6V{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetUserActive6VName> userActive6V{false};
SimDataValue<double, MakeDouble, GetUserVoltage5VName> userVoltage5V{5.0};
SimDataValue<double, MakeDouble, GetUserCurrent5VName> userCurrent5V{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetUserActive5VName> userActive5V{false};
SimDataValue<double, MakeDouble, GetUserVoltage3V3Name> userVoltage3V3{3.3};
SimDataValue<double, MakeDouble, GetUserCurrent3V3Name> userCurrent3V3{0.0};
SimDataValue<HAL_Bool, MakeBoolean, GetUserActive3V3Name> userActive3V3{
false};
SimDataValue<int32_t, MakeInt, GetUserFaults6VName> userFaults6V{0};
SimDataValue<int32_t, MakeInt, GetUserFaults5VName> userFaults5V{0};
SimDataValue<int32_t, MakeInt, GetUserFaults3V3Name> userFaults3V3{0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_fPGAButton{false};
std::shared_ptr<NotifyListenerVector> m_fPGAButtonCallbacks = nullptr;
std::atomic<double> m_vInVoltage{0.0};
std::shared_ptr<NotifyListenerVector> m_vInVoltageCallbacks = nullptr;
std::atomic<double> m_vInCurrent{0.0};
std::shared_ptr<NotifyListenerVector> m_vInCurrentCallbacks = nullptr;
std::atomic<double> m_userVoltage6V{6.0};
std::shared_ptr<NotifyListenerVector> m_userVoltage6VCallbacks = nullptr;
std::atomic<double> m_userCurrent6V{0.0};
std::shared_ptr<NotifyListenerVector> m_userCurrent6VCallbacks = nullptr;
std::atomic<HAL_Bool> m_userActive6V{false};
std::shared_ptr<NotifyListenerVector> m_userActive6VCallbacks = nullptr;
std::atomic<double> m_userVoltage5V{5.0};
std::shared_ptr<NotifyListenerVector> m_userVoltage5VCallbacks = nullptr;
std::atomic<double> m_userCurrent5V{0.0};
std::shared_ptr<NotifyListenerVector> m_userCurrent5VCallbacks = nullptr;
std::atomic<HAL_Bool> m_userActive5V{false};
std::shared_ptr<NotifyListenerVector> m_userActive5VCallbacks = nullptr;
std::atomic<double> m_userVoltage3V3{3.3};
std::shared_ptr<NotifyListenerVector> m_userVoltage3V3Callbacks = nullptr;
std::atomic<double> m_userCurrent3V3{0.0};
std::shared_ptr<NotifyListenerVector> m_userCurrent3V3Callbacks = nullptr;
std::atomic<HAL_Bool> m_userActive3V3{false};
std::shared_ptr<NotifyListenerVector> m_userActive3V3Callbacks = nullptr;
std::atomic<int32_t> m_userFaults6V{0};
std::shared_ptr<NotifyListenerVector> m_userFaults6VCallbacks = nullptr;
std::atomic<int32_t> m_userFaults5V{0};
std::shared_ptr<NotifyListenerVector> m_userFaults5VCallbacks = nullptr;
std::atomic<int32_t> m_userFaults3V3{0};
std::shared_ptr<NotifyListenerVector> m_userFaults3V3Callbacks = nullptr;
};
extern RoboRioData* SimRoboRioData;
} // namespace hal

View File

@@ -7,7 +7,6 @@
#include "../PortsInternal.h"
#include "SPIAccelerometerDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
@@ -22,195 +21,11 @@ void InitializeSPIAccelerometerData() {
SPIAccelerometerData* hal::SimSPIAccelerometerData;
void SPIAccelerometerData::ResetData() {
m_active = false;
m_activeCallbacks = nullptr;
m_range = 0;
m_rangeCallbacks = nullptr;
m_x = 0.0;
m_xCallbacks = nullptr;
m_y = 0.0;
m_yCallbacks = nullptr;
m_z = 0.0;
m_zCallbacks = nullptr;
}
int32_t SPIAccelerometerData::RegisterActiveCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_activeCallbacks =
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetActive());
callback("Active", param, &value);
}
return newUid;
}
void SPIAccelerometerData::CancelActiveCallback(int32_t uid) {
m_activeCallbacks = CancelCallback(m_activeCallbacks, uid);
}
void SPIAccelerometerData::InvokeActiveCallback(HAL_Value value) {
InvokeCallback(m_activeCallbacks, "Active", &value);
}
HAL_Bool SPIAccelerometerData::GetActive() { return m_active; }
void SPIAccelerometerData::SetActive(HAL_Bool active) {
HAL_Bool oldValue = m_active.exchange(active);
if (oldValue != active) {
InvokeActiveCallback(MakeBoolean(active));
}
}
int32_t SPIAccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rangeCallbacks =
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeInt(GetRange());
callback("Range", param, &value);
}
return newUid;
}
void SPIAccelerometerData::CancelRangeCallback(int32_t uid) {
m_rangeCallbacks = CancelCallback(m_rangeCallbacks, uid);
}
void SPIAccelerometerData::InvokeRangeCallback(HAL_Value value) {
InvokeCallback(m_rangeCallbacks, "Range", &value);
}
int32_t SPIAccelerometerData::GetRange() { return m_range; }
void SPIAccelerometerData::SetRange(int32_t range) {
int32_t oldValue = m_range.exchange(range);
if (oldValue != range) {
InvokeRangeCallback(MakeInt(range));
}
}
int32_t SPIAccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_xCallbacks =
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetX());
callback("X", param, &value);
}
return newUid;
}
void SPIAccelerometerData::CancelXCallback(int32_t uid) {
m_xCallbacks = CancelCallback(m_xCallbacks, uid);
}
void SPIAccelerometerData::InvokeXCallback(HAL_Value value) {
InvokeCallback(m_xCallbacks, "X", &value);
}
double SPIAccelerometerData::GetX() { return m_x; }
void SPIAccelerometerData::SetX(double x) {
double oldValue = m_x.exchange(x);
if (oldValue != x) {
InvokeXCallback(MakeDouble(x));
}
}
int32_t SPIAccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_yCallbacks =
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetY());
callback("Y", param, &value);
}
return newUid;
}
void SPIAccelerometerData::CancelYCallback(int32_t uid) {
m_yCallbacks = CancelCallback(m_yCallbacks, uid);
}
void SPIAccelerometerData::InvokeYCallback(HAL_Value value) {
InvokeCallback(m_yCallbacks, "Y", &value);
}
double SPIAccelerometerData::GetY() { return m_y; }
void SPIAccelerometerData::SetY(double y) {
double oldValue = m_y.exchange(y);
if (oldValue != y) {
InvokeYCallback(MakeDouble(y));
}
}
int32_t SPIAccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zCallbacks =
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetZ());
callback("Z", param, &value);
}
return newUid;
}
void SPIAccelerometerData::CancelZCallback(int32_t uid) {
m_zCallbacks = CancelCallback(m_zCallbacks, uid);
}
void SPIAccelerometerData::InvokeZCallback(HAL_Value value) {
InvokeCallback(m_zCallbacks, "Z", &value);
}
double SPIAccelerometerData::GetZ() { return m_z; }
void SPIAccelerometerData::SetZ(double z) {
double oldValue = m_z.exchange(z);
if (oldValue != z) {
InvokeZCallback(MakeDouble(z));
}
active.Reset(false);
range.Reset(0);
x.Reset(0.0);
y.Reset(0.0);
z.Reset(0.0);
}
extern "C" {
@@ -218,117 +33,28 @@ void HALSIM_ResetSPIAccelerometerData(int32_t index) {
SimSPIAccelerometerData[index].ResetData();
}
int32_t HALSIM_RegisterSPIAccelerometerActiveCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimSPIAccelerometerData[index].RegisterActiveCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, SPIAccelerometer##CAPINAME, \
SimSPIAccelerometerData, LOWERNAME)
void HALSIM_CancelSPIAccelerometerActiveCallback(int32_t index, int32_t uid) {
SimSPIAccelerometerData[index].CancelActiveCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Active, active)
DEFINE_CAPI(int32_t, Range, range)
DEFINE_CAPI(double, X, x)
DEFINE_CAPI(double, Y, y)
DEFINE_CAPI(double, Z, z)
HAL_Bool HALSIM_GetSPIAccelerometerActive(int32_t index) {
return SimSPIAccelerometerData[index].GetActive();
}
void HALSIM_SetSPIAccelerometerActive(int32_t index, HAL_Bool active) {
SimSPIAccelerometerData[index].SetActive(active);
}
int32_t HALSIM_RegisterSPIAccelerometerRangeCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
return SimSPIAccelerometerData[index].RegisterRangeCallback(callback, param,
initialNotify);
}
void HALSIM_CancelSPIAccelerometerRangeCallback(int32_t index, int32_t uid) {
SimSPIAccelerometerData[index].CancelRangeCallback(uid);
}
int32_t HALSIM_GetSPIAccelerometerRange(int32_t index) {
return SimSPIAccelerometerData[index].GetRange();
}
void HALSIM_SetSPIAccelerometerRange(int32_t index, int32_t range) {
SimSPIAccelerometerData[index].SetRange(range);
}
int32_t HALSIM_RegisterSPIAccelerometerXCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimSPIAccelerometerData[index].RegisterXCallback(callback, param,
initialNotify);
}
void HALSIM_CancelSPIAccelerometerXCallback(int32_t index, int32_t uid) {
SimSPIAccelerometerData[index].CancelXCallback(uid);
}
double HALSIM_GetSPIAccelerometerX(int32_t index) {
return SimSPIAccelerometerData[index].GetX();
}
void HALSIM_SetSPIAccelerometerX(int32_t index, double x) {
SimSPIAccelerometerData[index].SetX(x);
}
int32_t HALSIM_RegisterSPIAccelerometerYCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimSPIAccelerometerData[index].RegisterYCallback(callback, param,
initialNotify);
}
void HALSIM_CancelSPIAccelerometerYCallback(int32_t index, int32_t uid) {
SimSPIAccelerometerData[index].CancelYCallback(uid);
}
double HALSIM_GetSPIAccelerometerY(int32_t index) {
return SimSPIAccelerometerData[index].GetY();
}
void HALSIM_SetSPIAccelerometerY(int32_t index, double y) {
SimSPIAccelerometerData[index].SetY(y);
}
int32_t HALSIM_RegisterSPIAccelerometerZCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimSPIAccelerometerData[index].RegisterZCallback(callback, param,
initialNotify);
}
void HALSIM_CancelSPIAccelerometerZCallback(int32_t index, int32_t uid) {
SimSPIAccelerometerData[index].CancelZCallback(uid);
}
double HALSIM_GetSPIAccelerometerZ(int32_t index) {
return SimSPIAccelerometerData[index].GetZ();
}
void HALSIM_SetSPIAccelerometerZ(int32_t index, double z) {
SimSPIAccelerometerData[index].SetZ(z);
}
#define REGISTER(NAME) \
SimSPIAccelerometerData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterSPIAccelerometerAllCallbcaks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
SimSPIAccelerometerData[index].RegisterActiveCallback(callback, param,
initialNotify);
SimSPIAccelerometerData[index].RegisterRangeCallback(callback, param,
initialNotify);
SimSPIAccelerometerData[index].RegisterXCallback(callback, param,
initialNotify);
SimSPIAccelerometerData[index].RegisterYCallback(callback, param,
initialNotify);
SimSPIAccelerometerData[index].RegisterZCallback(callback, param,
initialNotify);
REGISTER(active);
REGISTER(range);
REGISTER(x);
REGISTER(y);
REGISTER(z);
}
} // extern "C"

View File

@@ -7,66 +7,25 @@
#pragma once
#include <atomic>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SPIAccelerometerData.h"
#include "mockdata/SimDataValue.h"
namespace hal {
class SPIAccelerometerData {
HAL_SIMDATAVALUE_DEFINE_NAME(Active)
HAL_SIMDATAVALUE_DEFINE_NAME(Range)
HAL_SIMDATAVALUE_DEFINE_NAME(X)
HAL_SIMDATAVALUE_DEFINE_NAME(Y)
HAL_SIMDATAVALUE_DEFINE_NAME(Z)
public:
int32_t RegisterActiveCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelActiveCallback(int32_t uid);
void InvokeActiveCallback(HAL_Value value);
HAL_Bool GetActive();
void SetActive(HAL_Bool active);
int32_t RegisterRangeCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelRangeCallback(int32_t uid);
void InvokeRangeCallback(HAL_Value value);
int32_t GetRange();
void SetRange(int32_t range);
int32_t RegisterXCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelXCallback(int32_t uid);
void InvokeXCallback(HAL_Value value);
double GetX();
void SetX(double x);
int32_t RegisterYCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelYCallback(int32_t uid);
void InvokeYCallback(HAL_Value value);
double GetY();
void SetY(double y);
int32_t RegisterZCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelZCallback(int32_t uid);
void InvokeZCallback(HAL_Value value);
double GetZ();
void SetZ(double z);
SimDataValue<HAL_Bool, MakeBoolean, GetActiveName> active{false};
SimDataValue<int32_t, MakeInt, GetRangeName> range{0};
SimDataValue<double, MakeDouble, GetXName> x{0.0};
SimDataValue<double, MakeDouble, GetYName> y{0.0};
SimDataValue<double, MakeDouble, GetZName> z{0.0};
virtual void ResetData();
private:
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_active{false};
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
std::atomic<int32_t> m_range{0};
std::shared_ptr<NotifyListenerVector> m_rangeCallbacks = nullptr;
std::atomic<double> m_x{0.0};
std::shared_ptr<NotifyListenerVector> m_xCallbacks = nullptr;
std::atomic<double> m_y{0.0};
std::shared_ptr<NotifyListenerVector> m_yCallbacks = nullptr;
std::atomic<double> m_z{0.0};
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
};
extern SPIAccelerometerData* SimSPIAccelerometerData;
} // namespace hal

View File

@@ -9,25 +9,9 @@
#include "../PortsInternal.h"
#include "SPIDataInternal.h"
#include "mockdata/NotifyCallbackHelpers.h"
using namespace hal;
void InvokeCallback(
std::shared_ptr<SpiAutoReceiveDataListenerVector> currentVector,
const char* name, uint8_t* buffer, int32_t numToRead,
int32_t* outputCount) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // callback was removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, buffer, numToRead, outputCount);
}
}
namespace hal {
namespace init {
void InitializeSPIData() {
@@ -39,190 +23,53 @@ void InitializeSPIData() {
SPIData* hal::SimSPIData;
void SPIData::ResetData() {
m_initialized = false;
m_initializedCallbacks = nullptr;
m_readCallbacks = nullptr;
m_writeCallbacks = nullptr;
m_autoReceiveDataCallbacks = nullptr;
}
SPIData::SPIData() {}
SPIData::~SPIData() {}
int32_t SPIData::RegisterInitializedCallback(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeBoolean(GetInitialized());
callback("Initialized", param, &value);
}
return newUid;
}
void SPIData::CancelInitializedCallback(int32_t uid) {
m_initializedCallbacks = CancelCallback(m_initializedCallbacks, uid);
}
void SPIData::InvokeInitializedCallback(HAL_Value value) {
InvokeCallback(m_initializedCallbacks, "Initialized", &value);
}
HAL_Bool SPIData::GetInitialized() { return m_initialized; }
void SPIData::SetInitialized(HAL_Bool initialized) {
HAL_Bool oldValue = m_initialized.exchange(initialized);
if (oldValue != initialized) {
InvokeInitializedCallback(MakeBoolean(initialized));
}
}
int32_t SPIData::RegisterReadCallback(HAL_BufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_readCallbacks =
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
}
return newUid;
}
void SPIData::CancelReadCallback(int32_t uid) {
m_readCallbacks = CancelCallback(m_readCallbacks, uid);
}
int32_t SPIData::RegisterWriteCallback(HAL_ConstBufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_writeCallbacks =
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
}
return newUid;
}
void SPIData::CancelWriteCallback(int32_t uid) {
m_writeCallbacks = CancelCallback(m_writeCallbacks, uid);
}
int32_t SPIData::RegisterReadAutoReceivedDataCallback(
HAL_SpiReadAutoReceiveBufferCallback callback, void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_autoReceiveDataCallbacks = RegisterCallbackImpl(
m_autoReceiveDataCallbacks, "AutoReceive", callback, param, &newUid);
}
return newUid;
}
void SPIData::CancelReadAutoReceivedDataCallback(int32_t uid) {
m_autoReceiveDataCallbacks =
CancelCallbackImpl<SpiAutoReceiveDataListenerVector,
HAL_SpiReadAutoReceiveBufferCallback>(
m_autoReceiveDataCallbacks, uid);
initialized.Reset(false);
read.Reset();
write.Reset();
autoReceivedData.Reset();
}
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_readCallbacks, "Read", buffer, count);
read(buffer, count);
return count;
}
int32_t SPIData::Write(const uint8_t* dataToSend, int32_t sendSize) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", const_cast<uint8_t*>(dataToSend),
sendSize);
write(dataToSend, sendSize);
return sendSize;
}
int32_t SPIData::Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", dataToSend, size);
InvokeCallback(m_readCallbacks, "Read", dataReceived, size);
write(dataToSend, size);
read(dataReceived, size);
return size;
}
int32_t SPIData::ReadAutoReceivedData(uint8_t* buffer, int32_t numToRead,
double timeout, int32_t* status) {
int32_t outputCount = 0;
InvokeCallback(m_autoReceiveDataCallbacks, "AutoReceive",
const_cast<uint8_t*>(buffer), numToRead, &outputCount);
autoReceivedData(buffer, numToRead, &outputCount);
return outputCount;
}
extern "C" {
void HALSIM_ResetSPIData(int32_t index) { SimSPIData[index].ResetData(); }
int32_t HALSIM_RegisterSPIInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
return SimSPIData[index].RegisterInitializedCallback(callback, param,
initialNotify);
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
LOWERNAME)
void HALSIM_CancelSPIInitializedCallback(int32_t index, int32_t uid) {
SimSPIData[index].CancelInitializedCallback(uid);
}
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
HAL_Bool HALSIM_GetSPIInitialized(int32_t index) {
return SimSPIData[index].GetInitialized();
}
#undef DEFINE_CAPI
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, HALSIM, SPI##CAPINAME, SimSPIData, \
LOWERNAME)
void HALSIM_SetSPIInitialized(int32_t index, HAL_Bool initialized) {
SimSPIData[index].SetInitialized(initialized);
}
int32_t HALSIM_RegisterSPIReadCallback(int32_t index,
HAL_BufferCallback callback,
void* param) {
return SimSPIData[index].RegisterReadCallback(callback, param);
}
void HALSIM_CancelSPIReadCallback(int32_t index, int32_t uid) {
SimSPIData[index].CancelReadCallback(uid);
}
int32_t HALSIM_RegisterSPIWriteCallback(int32_t index,
HAL_ConstBufferCallback callback,
void* param) {
return SimSPIData[index].RegisterWriteCallback(callback, param);
}
void HALSIM_CancelSPIWriteCallback(int32_t index, int32_t uid) {
SimSPIData[index].CancelWriteCallback(uid);
}
int32_t HALSIM_RegisterSPIReadAutoReceivedDataCallback(
int32_t index, HAL_SpiReadAutoReceiveBufferCallback callback, void* param) {
return SimSPIData[index].RegisterReadAutoReceivedDataCallback(callback,
param);
}
void HALSIM_CancelSPIReadAutoReceivedDataCallback(int32_t index, int32_t uid) {
SimSPIData[index].CancelReadAutoReceivedDataCallback(uid);
}
DEFINE_CAPI(HAL_BufferCallback, Read, read)
DEFINE_CAPI(HAL_ConstBufferCallback, Write, write)
DEFINE_CAPI(HAL_SpiReadAutoReceiveBufferCallback, ReadAutoReceivedData,
autoReceivedData)
} // extern "C"

View File

@@ -7,61 +7,33 @@
#pragma once
#include <atomic>
#include <limits>
#include <memory>
#include <wpi/mutex.h>
#include "mockdata/NotifyListenerVector.h"
#include "mockdata/SPIData.h"
#include "mockdata/SimCallbackRegistry.h"
#include "mockdata/SimDataValue.h"
namespace hal {
typedef HalCallbackListenerVectorImpl<HAL_SpiReadAutoReceiveBufferCallback>
SpiAutoReceiveDataListenerVector;
class SPIData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Read)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Write)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(AutoReceive)
public:
SPIData();
~SPIData();
int32_t RegisterInitializedCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelInitializedCallback(int32_t uid);
void InvokeInitializedCallback(HAL_Value value);
HAL_Bool GetInitialized();
void SetInitialized(HAL_Bool initialized);
int32_t RegisterReadCallback(HAL_BufferCallback callback, void* param);
void CancelReadCallback(int32_t uid);
int32_t RegisterWriteCallback(HAL_ConstBufferCallback callback, void* param);
void CancelWriteCallback(int32_t uid);
int32_t RegisterReadAutoReceivedDataCallback(
HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
void CancelReadAutoReceivedDataCallback(int32_t uid);
int32_t Read(uint8_t* buffer, int32_t count);
int32_t Write(const uint8_t* dataToSend, int32_t sendSize);
int32_t Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size);
int32_t ReadAutoReceivedData(uint8_t* buffer, int32_t numToRead,
double timeout, int32_t* status);
void ResetData();
SimDataValue<HAL_Bool, MakeBoolean, GetInitializedName> initialized{false};
SimCallbackRegistry<HAL_BufferCallback, GetReadName> read;
SimCallbackRegistry<HAL_ConstBufferCallback, GetWriteName> write;
SimCallbackRegistry<HAL_SpiReadAutoReceiveBufferCallback, GetAutoReceiveName>
autoReceivedData;
private:
wpi::mutex m_registerMutex;
wpi::mutex m_dataMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
std::shared_ptr<SpiAutoReceiveDataListenerVector> m_autoReceiveDataCallbacks =
nullptr;
void ResetData();
};
extern SPIData* SimSPIData;
} // namespace hal

View File

@@ -11,7 +11,6 @@
#include <cmath>
#include <cstring>
#include <mockdata/NotifyCallbackHelpers.h>
#include <mockdata/SPIData.h>
#ifdef _WIN32
@@ -62,10 +61,9 @@ bool ADXRS450_SpiGyroWrapper::GetInitialized() const {
}
void ADXRS450_SpiGyroWrapper::ResetData() {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
m_angle = 0;
std::lock_guard<wpi::recursive_spinlock> lock(m_angle.GetMutex());
m_angle.Reset(0.0);
m_angleDiff = 0;
m_angleCallbacks = nullptr;
}
void ADXRS450_SpiGyroWrapper::HandleRead(uint8_t* buffer, uint32_t count) {
@@ -76,7 +74,7 @@ void ADXRS450_SpiGyroWrapper::HandleRead(uint8_t* buffer, uint32_t count) {
void ADXRS450_SpiGyroWrapper::HandleAutoReceiveData(uint8_t* buffer,
int32_t numToRead,
int32_t& outputCount) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
std::lock_guard<wpi::recursive_spinlock> lock(m_angle.GetMutex());
int32_t messagesToSend = std::abs(
m_angleDiff > 0 ? std::ceil(m_angleDiff / kMaxAngleDeltaPerMessage)
: std::floor(m_angleDiff / kMaxAngleDeltaPerMessage));
@@ -110,42 +108,9 @@ void ADXRS450_SpiGyroWrapper::HandleAutoReceiveData(uint8_t* buffer,
}
}
int32_t ADXRS450_SpiGyroWrapper::RegisterAngleCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_angleCallbacks =
RegisterCallback(m_angleCallbacks, "Angle", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetAngle());
callback("Angle", param, &value);
}
return newUid;
}
void ADXRS450_SpiGyroWrapper::CancelAngleCallback(int32_t uid) {
m_angleCallbacks = CancelCallback(m_angleCallbacks, uid);
}
void ADXRS450_SpiGyroWrapper::InvokeAngleCallback(HAL_Value value) {
InvokeCallback(m_angleCallbacks, "Angle", &value);
}
double ADXRS450_SpiGyroWrapper::GetAngle() {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
return m_angle;
}
void ADXRS450_SpiGyroWrapper::SetAngle(double angle) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
std::lock_guard<wpi::recursive_spinlock> lock(m_angle.GetMutex());
if (m_angle != angle) {
InvokeAngleCallback(MakeDouble(angle));
m_angleDiff += angle - m_angle;
m_angle = angle;
}

View File

@@ -7,123 +7,13 @@
#include "ThreeAxisAccelerometerData.h"
#include <mockdata/NotifyCallbackHelpers.h>
using namespace hal;
ThreeAxisAccelerometerData::ThreeAxisAccelerometerData() {}
ThreeAxisAccelerometerData::~ThreeAxisAccelerometerData() {}
void ThreeAxisAccelerometerData::ResetData() {
m_x = 0.0;
m_xCallbacks = nullptr;
m_y = 0.0;
m_yCallbacks = nullptr;
m_z = 0.0;
m_zCallbacks = nullptr;
}
int32_t ThreeAxisAccelerometerData::RegisterXCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_xCallbacks =
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetX());
callback("X", param, &value);
}
return newUid;
}
void ThreeAxisAccelerometerData::CancelXCallback(int32_t uid) {
m_xCallbacks = CancelCallback(m_xCallbacks, uid);
}
void ThreeAxisAccelerometerData::InvokeXCallback(HAL_Value value) {
InvokeCallback(m_xCallbacks, "X", &value);
}
double ThreeAxisAccelerometerData::GetX() { return m_x; }
void ThreeAxisAccelerometerData::SetX(double x) {
double oldValue = m_x.exchange(x);
if (oldValue != x) {
InvokeXCallback(MakeDouble(x));
}
}
int32_t ThreeAxisAccelerometerData::RegisterYCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_yCallbacks =
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetY());
callback("Y", param, &value);
}
return newUid;
}
void ThreeAxisAccelerometerData::CancelYCallback(int32_t uid) {
m_yCallbacks = CancelCallback(m_yCallbacks, uid);
}
void ThreeAxisAccelerometerData::InvokeYCallback(HAL_Value value) {
InvokeCallback(m_yCallbacks, "Y", &value);
}
double ThreeAxisAccelerometerData::GetY() { return m_y; }
void ThreeAxisAccelerometerData::SetY(double y) {
double oldValue = m_y.exchange(y);
if (oldValue != y) {
InvokeYCallback(MakeDouble(y));
}
}
int32_t ThreeAxisAccelerometerData::RegisterZCallback(
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zCallbacks =
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
}
if (initialNotify) {
// We know that the callback is not null because of earlier null check
HAL_Value value = MakeDouble(GetZ());
callback("Z", param, &value);
}
return newUid;
}
void ThreeAxisAccelerometerData::CancelZCallback(int32_t uid) {
m_zCallbacks = CancelCallback(m_zCallbacks, uid);
}
void ThreeAxisAccelerometerData::InvokeZCallback(HAL_Value value) {
InvokeCallback(m_zCallbacks, "Z", &value);
}
double ThreeAxisAccelerometerData::GetZ() { return m_z; }
void ThreeAxisAccelerometerData::SetZ(double z) {
double oldValue = m_z.exchange(z);
if (oldValue != z) {
InvokeZCallback(MakeDouble(z));
}
x.Reset(0.0);
y.Reset(0.0);
z.Reset(0.0);
}

View File

@@ -7,11 +7,7 @@
#pragma once
#include <atomic>
#include <memory>
#include <mockdata/NotifyListenerVector.h>
#include <wpi/mutex.h>
#include <mockdata/SimDataValue.h>
namespace hal {
class ADXRS450_SpiGyroWrapper {
@@ -25,25 +21,25 @@ class ADXRS450_SpiGyroWrapper {
void HandleAutoReceiveData(uint8_t* buffer, int32_t numToRead,
int32_t& outputCount);
virtual void ResetData();
int32_t RegisterAngleCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelAngleCallback(int32_t uid);
void InvokeAngleCallback(HAL_Value value);
double GetAngle();
HAL_Bool initialNotify) {
return m_angle.RegisterCallback(callback, param, initialNotify);
}
void CancelAngleCallback(int32_t uid) { m_angle.CancelCallback(uid); }
double GetAngle() { return m_angle; }
void SetAngle(double angle);
virtual void ResetData();
private:
int m_port;
int m_readCallbackId;
int m_autoReceiveReadCallbackId;
wpi::mutex m_registerMutex;
wpi::mutex m_dataMutex;
double m_angle = 0.0;
HAL_SIMDATAVALUE_DEFINE_NAME(Angle)
SimDataValue<double, MakeDouble, GetAngleName> m_angle{0.0};
double m_angleDiff = 0.0;
std::shared_ptr<NotifyListenerVector> m_angleCallbacks = nullptr;
static const double kAngleLsb;
// The maximum difference that can fit inside of the shifted and masked data

View File

@@ -7,50 +7,33 @@
#pragma once
#include <atomic>
#include <memory>
#include <mockdata/NotifyListenerVector.h>
#include <wpi/mutex.h>
#include <mockdata/SimDataValue.h>
namespace hal {
class ThreeAxisAccelerometerData {
HAL_SIMDATAVALUE_DEFINE_NAME(X);
HAL_SIMDATAVALUE_DEFINE_NAME(Y);
HAL_SIMDATAVALUE_DEFINE_NAME(Z);
public:
ThreeAxisAccelerometerData();
virtual ~ThreeAxisAccelerometerData();
virtual bool GetInitialized() const = 0;
int32_t RegisterXCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelXCallback(int32_t uid);
void InvokeXCallback(HAL_Value value);
double GetX();
void SetX(double x);
double GetX() { return x; }
void SetX(double x_) { x = x_; }
int32_t RegisterYCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelYCallback(int32_t uid);
void InvokeYCallback(HAL_Value value);
double GetY();
void SetY(double y);
double GetY() { return y; }
void SetY(double y_) { y = y_; }
int32_t RegisterZCallback(HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void CancelZCallback(int32_t uid);
void InvokeZCallback(HAL_Value value);
double GetZ();
void SetZ(double z);
double GetZ() { return z; }
void SetZ(double z_) { z = z_; }
SimDataValue<double, MakeDouble, GetXName> x{0.0};
SimDataValue<double, MakeDouble, GetYName> y{0.0};
SimDataValue<double, MakeDouble, GetZName> z{0.0};
virtual void ResetData();
protected:
wpi::mutex m_registerMutex;
std::atomic<double> m_x{0.0};
std::shared_ptr<NotifyListenerVector> m_xCallbacks = nullptr;
std::atomic<double> m_y{0.0};
std::shared_ptr<NotifyListenerVector> m_yCallbacks = nullptr;
std::atomic<double> m_z{0.0};
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
};
} // namespace hal

View File

@@ -14,35 +14,20 @@ namespace lowfi {
ADXLThreeAxisAccelerometerSim::ADXLThreeAxisAccelerometerSim(
hal::ThreeAxisAccelerometerData& accelerometerWrapper)
: m_accelerometerWrapper(accelerometerWrapper),
m_xWrapper(std::function<bool(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
&m_accelerometerWrapper)),
std::function<void(double)>(
std::bind(&hal::ThreeAxisAccelerometerData::SetX,
&m_accelerometerWrapper, std::placeholders::_1)),
std::function<double(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetX,
&m_accelerometerWrapper))),
m_xWrapper(
[data = &m_accelerometerWrapper] { return data->GetInitialized(); },
[data = &m_accelerometerWrapper](double x) { data->x = x; },
[data = &m_accelerometerWrapper] { return data->GetX(); }),
m_yWrapper(std::function<bool(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
&m_accelerometerWrapper)),
std::function<void(double)>(
std::bind(&hal::ThreeAxisAccelerometerData::SetY,
&m_accelerometerWrapper, std::placeholders::_1)),
std::function<double(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetY,
&m_accelerometerWrapper))),
m_yWrapper(
[data = &m_accelerometerWrapper] { return data->GetInitialized(); },
[data = &m_accelerometerWrapper](double y) { data->y = y; },
[data = &m_accelerometerWrapper] { return data->GetY(); }),
m_zWrapper(std::function<bool(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
&m_accelerometerWrapper)),
std::function<void(double)>(
std::bind(&hal::ThreeAxisAccelerometerData::SetZ,
&m_accelerometerWrapper, std::placeholders::_1)),
std::function<double(void)>(
std::bind(&hal::ThreeAxisAccelerometerData::GetZ,
&m_accelerometerWrapper))) {}
m_zWrapper(
[data = &m_accelerometerWrapper] { return data->GetInitialized(); },
[data = &m_accelerometerWrapper](double z) { data->z = z; },
[data = &m_accelerometerWrapper] { return data->GetZ(); }) {}
AccelerometerSim& ADXLThreeAxisAccelerometerSim::GetXWrapper() {
return m_xWrapper;