mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Move CameraServer and WPILib headers into their own folder
The old headers were moved into folders because doing so avoids polluting the system include directories. Folder names were also normalized to lowercase.
This commit is contained in:
committed by
Peter Johnson
parent
31ced30c1e
commit
d89b7dd412
334
hal/src/main/native/sim/mockdata/AccelerometerData.cpp
Normal file
334
hal/src/main/native/sim/mockdata/AccelerometerData.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "AccelerometerDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAccelerometerData() {
|
||||
static AccelerometerData sad[1];
|
||||
::hal::SimAccelerometerData = sad;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelAccelerometerActiveCallback(int32_t index, int32_t uid) {
|
||||
SimAccelerometerData[index].CancelActiveCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
73
hal/src/main/native/sim/mockdata/AccelerometerDataInternal.h
Normal file
73
hal/src/main/native/sim/mockdata/AccelerometerDataInternal.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/AccelerometerData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class AccelerometerData {
|
||||
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);
|
||||
|
||||
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
|
||||
215
hal/src/main/native/sim/mockdata/AnalogGyroData.cpp
Normal file
215
hal/src/main/native/sim/mockdata/AnalogGyroData.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "AnalogGyroDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAnalogGyroData() {
|
||||
static AnalogGyroData agd[kNumAccumulators];
|
||||
::hal::SimAnalogGyroData = agd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelAnalogGyroAngleCallback(int32_t index, int32_t uid) {
|
||||
SimAnalogGyroData[index].CancelAngleCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
54
hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h
Normal file
54
hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/AnalogGyroData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class AnalogGyroData {
|
||||
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);
|
||||
|
||||
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
|
||||
585
hal/src/main/native/sim/mockdata/AnalogInData.cpp
Normal file
585
hal/src/main/native/sim/mockdata/AnalogInData.cpp
Normal file
@@ -0,0 +1,585 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "AnalogInDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAnalogInData() {
|
||||
static AnalogInData sind[kNumAnalogInputs];
|
||||
::hal::SimAnalogInData = sind;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelAnalogInInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimAnalogInData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
113
hal/src/main/native/sim/mockdata/AnalogInDataInternal.h
Normal file
113
hal/src/main/native/sim/mockdata/AnalogInDataInternal.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/AnalogInData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class AnalogInData {
|
||||
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);
|
||||
|
||||
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
|
||||
156
hal/src/main/native/sim/mockdata/AnalogOutData.cpp
Normal file
156
hal/src/main/native/sim/mockdata/AnalogOutData.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "AnalogOutDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAnalogOutData() {
|
||||
static AnalogOutData siod[kNumAnalogOutputs];
|
||||
::hal::SimAnalogOutData = siod;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelAnalogOutVoltageCallback(int32_t index, int32_t uid) {
|
||||
SimAnalogOutData[index].CancelVoltageCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
45
hal/src/main/native/sim/mockdata/AnalogOutDataInternal.h
Normal file
45
hal/src/main/native/sim/mockdata/AnalogOutDataInternal.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/AnalogOutData.h"
|
||||
#include "mockdata/NotifyListenerVector.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);
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
280
hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp
Normal file
280
hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "AnalogTriggerDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAnalogTriggerData() {
|
||||
static AnalogTriggerData satd[kNumAnalogTriggers];
|
||||
::hal::SimAnalogTriggerData = satd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelAnalogTriggerInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimAnalogTriggerData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
66
hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h
Normal file
66
hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/AnalogTriggerData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class AnalogTriggerData {
|
||||
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);
|
||||
|
||||
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
|
||||
296
hal/src/main/native/sim/mockdata/CanDataInternal.cpp
Normal file
296
hal/src/main/native/sim/mockdata/CanDataInternal.cpp
Normal file
@@ -0,0 +1,296 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "CanDataInternal.h"
|
||||
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeCanData() {
|
||||
static CanData scd;
|
||||
::hal::SimCanData = &scd;
|
||||
}
|
||||
} // namespace init
|
||||
} // 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
111
hal/src/main/native/sim/mockdata/CanDataInternal.h
Normal file
111
hal/src/main/native/sim/mockdata/CanDataInternal.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/CanData.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
#include "mockdata/NotifyListenerVector.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 {
|
||||
public:
|
||||
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;
|
||||
|
||||
} // namespace hal
|
||||
324
hal/src/main/native/sim/mockdata/DIOData.cpp
Normal file
324
hal/src/main/native/sim/mockdata/DIOData.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "DIODataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDIOData() {
|
||||
static DIOData sdd[kNumDigitalChannels];
|
||||
::hal::SimDIOData = sdd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelDIOInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimDIOData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
72
hal/src/main/native/sim/mockdata/DIODataInternal.h
Normal file
72
hal/src/main/native/sim/mockdata/DIODataInternal.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/DIOData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class DIOData {
|
||||
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);
|
||||
|
||||
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
|
||||
215
hal/src/main/native/sim/mockdata/DigitalPWMData.cpp
Normal file
215
hal/src/main/native/sim/mockdata/DigitalPWMData.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "DigitalPWMDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDigitalPWMData() {
|
||||
static DigitalPWMData sdpd[kNumDigitalPWMOutputs];
|
||||
::hal::SimDigitalPWMData = sdpd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelDigitalPWMInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimDigitalPWMData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
54
hal/src/main/native/sim/mockdata/DigitalPWMDataInternal.h
Normal file
54
hal/src/main/native/sim/mockdata/DigitalPWMDataInternal.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/DigitalPWMData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class DigitalPWMData {
|
||||
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);
|
||||
|
||||
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
|
||||
615
hal/src/main/native/sim/mockdata/DriverStationData.cpp
Normal file
615
hal/src/main/native/sim/mockdata/DriverStationData.cpp
Normal file
@@ -0,0 +1,615 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "DriverStationDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
namespace hal {
|
||||
struct JoystickOutputStore {
|
||||
int64_t outputs = 0;
|
||||
int32_t leftRumble = 0;
|
||||
int32_t rightRumble = 0;
|
||||
};
|
||||
} // namespace hal
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDriverStationData() {
|
||||
static DriverStationData dsd;
|
||||
::hal::SimDriverStationData = &dsd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> 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);
|
||||
m_joystickOutputs = std::make_unique<JoystickOutputStore[]>(6);
|
||||
m_joystickDescriptor = std::make_unique<HAL_JoystickDescriptor[]>(6);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
m_joystickAxes[i].count = 0;
|
||||
m_joystickPOVs[i].count = 0;
|
||||
m_joystickButtons[i].count = 0;
|
||||
m_joystickDescriptor[i].isXbox = 0;
|
||||
m_joystickDescriptor[i].type = -1;
|
||||
m_joystickDescriptor[i].name[0] = '\0';
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<wpi::mutex> 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);
|
||||
*axes = m_joystickAxes[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
|
||||
HAL_JoystickPOVs* povs) {
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*povs = m_joystickPOVs[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*buttons = m_joystickButtons[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickDescriptor(
|
||||
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*descriptor = m_joystickDescriptor[joystickNum];
|
||||
// Always ensure name is null terminated
|
||||
descriptor->name[255] = '\0';
|
||||
}
|
||||
void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
|
||||
int64_t* outputs,
|
||||
int32_t* leftRumble,
|
||||
int32_t* rightRumble) {
|
||||
std::lock_guard<wpi::mutex> 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);
|
||||
*info = *m_matchInfo;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
|
||||
const HAL_JoystickAxes* axes) {
|
||||
std::lock_guard<wpi::mutex> 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);
|
||||
m_joystickPOVs[joystickNum] = *povs;
|
||||
}
|
||||
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<wpi::mutex> 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);
|
||||
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);
|
||||
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);
|
||||
*m_matchInfo = *info;
|
||||
*(std::end(m_matchInfo->eventName) - 1) = '\0';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes) {
|
||||
SimDriverStationData->SetJoystickAxes(joystickNum, axes);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs) {
|
||||
SimDriverStationData->SetJoystickPOVs(joystickNum, povs);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons) {
|
||||
SimDriverStationData->SetJoystickButtons(joystickNum, buttons);
|
||||
}
|
||||
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor) {
|
||||
SimDriverStationData->SetJoystickDescriptor(joystickNum, descriptor);
|
||||
}
|
||||
|
||||
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble) {
|
||||
SimDriverStationData->GetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
}
|
||||
|
||||
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {
|
||||
SimDriverStationData->SetMatchInfo(info);
|
||||
}
|
||||
|
||||
void HALSIM_NotifyDriverStationNewData(void) {
|
||||
SimDriverStationData->NotifyNewData();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
138
hal/src/main/native/sim/mockdata/DriverStationDataInternal.h
Normal file
138
hal/src/main/native/sim/mockdata/DriverStationDataInternal.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/DriverStationData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
struct JoystickOutputStore;
|
||||
|
||||
class DriverStationData {
|
||||
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);
|
||||
void GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* descriptor);
|
||||
void GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble);
|
||||
void GetMatchInfo(HAL_MatchInfo* info);
|
||||
void FreeMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
void SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes);
|
||||
void SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs);
|
||||
void SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons);
|
||||
void SetJoystickDescriptor(int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor);
|
||||
void SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
void SetMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
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;
|
||||
|
||||
wpi::mutex m_joystickDataMutex;
|
||||
wpi::mutex m_matchInfoMutex;
|
||||
|
||||
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
|
||||
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
|
||||
std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
|
||||
|
||||
std::unique_ptr<JoystickOutputStore[]> m_joystickOutputs;
|
||||
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
|
||||
std::unique_ptr<HAL_MatchInfo> m_matchInfo;
|
||||
};
|
||||
extern DriverStationData* SimDriverStationData;
|
||||
} // namespace hal
|
||||
585
hal/src/main/native/sim/mockdata/EncoderData.cpp
Normal file
585
hal/src/main/native/sim/mockdata/EncoderData.cpp
Normal file
@@ -0,0 +1,585 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "EncoderDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeEncoderData() {
|
||||
static EncoderData sed[kNumEncoders];
|
||||
::hal::SimEncoderData = sed;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void HALSIM_ResetEncoderData(int32_t index) {
|
||||
SimEncoderData[index].ResetData();
|
||||
}
|
||||
|
||||
int16_t HALSIM_GetDigitalChannelA(int32_t index) {
|
||||
return SimEncoderData[index].GetDigitalChannelA();
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterEncoderInitializedCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimEncoderData[index].RegisterInitializedCallback(callback, param,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
void HALSIM_CancelEncoderInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimEncoderData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
113
hal/src/main/native/sim/mockdata/EncoderDataInternal.h
Normal file
113
hal/src/main/native/sim/mockdata/EncoderDataInternal.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/EncoderData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class EncoderData {
|
||||
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);
|
||||
|
||||
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
|
||||
27
hal/src/main/native/sim/mockdata/HALValueInternal.h
Normal file
27
hal/src/main/native/sim/mockdata/HALValueInternal.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "mockdata/HALValue.h"
|
||||
#include "mockdata/wpi/StringRef.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
class Value;
|
||||
|
||||
void ConvertToC(const Value& in, HAL_Value* out);
|
||||
std::shared_ptr<Value> ConvertFromC(const HAL_Value& value);
|
||||
void ConvertToC(wpi::StringRef in, HALString* out);
|
||||
inline wpi::StringRef ConvertFromC(const HALString& str) {
|
||||
return wpi::StringRef(str.str, str.len);
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
161
hal/src/main/native/sim/mockdata/I2CData.cpp
Normal file
161
hal/src/main/native/sim/mockdata/I2CData.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <iostream>
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "I2CDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeI2CData() {
|
||||
static I2CData sid[2];
|
||||
::hal::SimI2CData = sid;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelI2CInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimI2CData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
HAL_Bool HALSIM_GetI2CInitialized(int32_t index) {
|
||||
return SimI2CData[index].GetInitialized();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
53
hal/src/main/native/sim/mockdata/I2CDataInternal.h
Normal file
53
hal/src/main/native/sim/mockdata/I2CDataInternal.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/I2CData.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class I2CData {
|
||||
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();
|
||||
|
||||
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;
|
||||
};
|
||||
extern I2CData* SimI2CData;
|
||||
} // namespace hal
|
||||
89
hal/src/main/native/sim/mockdata/NotifyCallbackHelpers.cpp
Normal file
89
hal/src/main/native/sim/mockdata/NotifyCallbackHelpers.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
486
hal/src/main/native/sim/mockdata/PCMData.cpp
Normal file
486
hal/src/main/native/sim/mockdata/PCMData.cpp
Normal file
@@ -0,0 +1,486 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "PCMDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializePCMData() {
|
||||
static PCMData spd[kNumPCMModules];
|
||||
::hal::SimPCMData = spd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelPCMSolenoidInitializedCallback(int32_t index, int32_t channel,
|
||||
int32_t uid) {
|
||||
SimPCMData[index].CancelSolenoidInitializedCallback(channel, uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
100
hal/src/main/native/sim/mockdata/PCMDataInternal.h
Normal file
100
hal/src/main/native/sim/mockdata/PCMDataInternal.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/PCMData.h"
|
||||
|
||||
namespace hal {
|
||||
class PCMData {
|
||||
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);
|
||||
|
||||
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
|
||||
271
hal/src/main/native/sim/mockdata/PDPData.cpp
Normal file
271
hal/src/main/native/sim/mockdata/PDPData.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "PDPDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializePDPData() {
|
||||
static PDPData spd[kNumPDPModules];
|
||||
::hal::SimPDPData = spd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelPDPInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimPDPData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
64
hal/src/main/native/sim/mockdata/PDPDataInternal.h
Normal file
64
hal/src/main/native/sim/mockdata/PDPDataInternal.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/PDPData.h"
|
||||
|
||||
namespace hal {
|
||||
class PDPData {
|
||||
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);
|
||||
|
||||
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
|
||||
383
hal/src/main/native/sim/mockdata/PWMData.cpp
Normal file
383
hal/src/main/native/sim/mockdata/PWMData.cpp
Normal file
@@ -0,0 +1,383 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "PWMDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializePWMData() {
|
||||
static PWMData spd[kNumPWMChannels];
|
||||
::hal::SimPWMData = spd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelPWMInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimPWMData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
81
hal/src/main/native/sim/mockdata/PWMDataInternal.h
Normal file
81
hal/src/main/native/sim/mockdata/PWMDataInternal.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/PWMData.h"
|
||||
|
||||
namespace hal {
|
||||
class PWMData {
|
||||
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);
|
||||
|
||||
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
|
||||
274
hal/src/main/native/sim/mockdata/RelayData.cpp
Normal file
274
hal/src/main/native/sim/mockdata/RelayData.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "RelayDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeRelayData() {
|
||||
static RelayData srd[kNumRelayHeaders];
|
||||
::hal::SimRelayData = srd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelRelayInitializedForwardCallback(int32_t index, int32_t uid) {
|
||||
SimRelayData[index].CancelInitializedForwardCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
65
hal/src/main/native/sim/mockdata/RelayDataInternal.h
Normal file
65
hal/src/main/native/sim/mockdata/RelayDataInternal.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/RelayData.h"
|
||||
|
||||
namespace hal {
|
||||
class RelayData {
|
||||
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);
|
||||
|
||||
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
|
||||
934
hal/src/main/native/sim/mockdata/RoboRioData.cpp
Normal file
934
hal/src/main/native/sim/mockdata/RoboRioData.cpp
Normal file
@@ -0,0 +1,934 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "RoboRioDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeRoboRioData() {
|
||||
static RoboRioData srrd[1];
|
||||
::hal::SimRoboRioData = srrd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelRoboRioFPGAButtonCallback(int32_t index, int32_t uid) {
|
||||
SimRoboRioData[index].CancelFPGAButtonCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
162
hal/src/main/native/sim/mockdata/RoboRioDataInternal.h
Normal file
162
hal/src/main/native/sim/mockdata/RoboRioDataInternal.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/RoboRioData.h"
|
||||
|
||||
namespace hal {
|
||||
class RoboRioData {
|
||||
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);
|
||||
|
||||
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
|
||||
334
hal/src/main/native/sim/mockdata/SPIAccelerometerData.cpp
Normal file
334
hal/src/main/native/sim/mockdata/SPIAccelerometerData.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "../PortsInternal.h"
|
||||
#include "SPIAccelerometerDataInternal.h"
|
||||
#include "mockdata/NotifyCallbackHelpers.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeSPIAccelerometerData() {
|
||||
static SPIAccelerometerData ssad[5];
|
||||
::hal::SimSPIAccelerometerData = ssad;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelSPIAccelerometerActiveCallback(int32_t index, int32_t uid) {
|
||||
SimSPIAccelerometerData[index].CancelActiveCallback(uid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,72 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/SPIAccelerometerData.h"
|
||||
|
||||
namespace hal {
|
||||
class SPIAccelerometerData {
|
||||
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);
|
||||
|
||||
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
|
||||
228
hal/src/main/native/sim/mockdata/SPIData.cpp
Normal file
228
hal/src/main/native/sim/mockdata/SPIData.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <iostream>
|
||||
|
||||
#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() {
|
||||
static SPIData ssd[5];
|
||||
::hal::SimSPIData = ssd;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
InvokeCallback(m_readCallbacks, "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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void HALSIM_CancelSPIInitializedCallback(int32_t index, int32_t uid) {
|
||||
SimSPIData[index].CancelInitializedCallback(uid);
|
||||
}
|
||||
|
||||
HAL_Bool HALSIM_GetSPIInitialized(int32_t index) {
|
||||
return SimSPIData[index].GetInitialized();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
67
hal/src/main/native/sim/mockdata/SPIDataInternal.h
Normal file
67
hal/src/main/native/sim/mockdata/SPIDataInternal.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "mockdata/NotifyListenerVector.h"
|
||||
#include "mockdata/SPIData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
typedef HalCallbackListenerVectorImpl<HAL_SpiReadAutoReceiveBufferCallback>
|
||||
SpiAutoReceiveDataListenerVector;
|
||||
|
||||
class SPIData {
|
||||
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();
|
||||
|
||||
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;
|
||||
};
|
||||
extern SPIData* SimSPIData;
|
||||
} // namespace hal
|
||||
Reference in New Issue
Block a user