mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
Removes statics from hal sim (#825)
Based off of #824, the equivelent in sim.
This commit is contained in:
committed by
Peter Johnson
parent
8bd48d6c34
commit
d2e7a90f41
@@ -12,7 +12,6 @@
|
|||||||
#include <llvm/SmallVector.h>
|
#include <llvm/SmallVector.h>
|
||||||
#include <support/mutex.h>
|
#include <support/mutex.h>
|
||||||
|
|
||||||
#ifdef __FRC_ROBORIO__
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
static llvm::SmallVector<HandleBase*, 32>* globalHandles;
|
static llvm::SmallVector<HandleBase*, 32>* globalHandles;
|
||||||
static wpi::mutex globalHandleMutex;
|
static wpi::mutex globalHandleMutex;
|
||||||
@@ -95,90 +94,3 @@ HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
#else
|
|
||||||
namespace hal {
|
|
||||||
static llvm::SmallVector<HandleBase*, 32>& GetGlobalHandles() {
|
|
||||||
static llvm::SmallVector<HandleBase*, 32> globalHandles;
|
|
||||||
return globalHandles;
|
|
||||||
}
|
|
||||||
static wpi::mutex& GetGlobalHandleMutex() {
|
|
||||||
static wpi::mutex globalHandleMutex;
|
|
||||||
return globalHandleMutex;
|
|
||||||
}
|
|
||||||
HandleBase::HandleBase() {
|
|
||||||
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
|
|
||||||
auto& globalHandles = GetGlobalHandles();
|
|
||||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
|
||||||
if (index == globalHandles.end()) {
|
|
||||||
globalHandles.push_back(this);
|
|
||||||
} else {
|
|
||||||
*index = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HandleBase::~HandleBase() {
|
|
||||||
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
|
|
||||||
auto& globalHandles = GetGlobalHandles();
|
|
||||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
|
||||||
if (index != globalHandles.end()) {
|
|
||||||
*index = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void HandleBase::ResetHandles() {
|
|
||||||
m_version++;
|
|
||||||
if (m_version > 255) {
|
|
||||||
m_version = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void HandleBase::ResetGlobalHandles() {
|
|
||||||
std::unique_lock<wpi::mutex> lock(GetGlobalHandleMutex());
|
|
||||||
auto& globalHandles = GetGlobalHandles();
|
|
||||||
for (auto&& i : globalHandles) {
|
|
||||||
if (i != nullptr) {
|
|
||||||
lock.unlock();
|
|
||||||
i->ResetHandles();
|
|
||||||
lock.lock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
|
|
||||||
// set last 8 bits, then shift to first 8 bits
|
|
||||||
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
|
|
||||||
handle = handle << 24;
|
|
||||||
// shift module and add to 3rd set of 8 bits
|
|
||||||
int32_t temp = module;
|
|
||||||
temp = (temp << 8) & 0xff00;
|
|
||||||
handle += temp;
|
|
||||||
// add channel to last 8 bits
|
|
||||||
handle += channel;
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
HAL_PortHandle createPortHandleForSPI(uint8_t channel) {
|
|
||||||
// set last 8 bits, then shift to first 8 bits
|
|
||||||
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
|
|
||||||
handle = handle << 16;
|
|
||||||
// set second set up bits to 1
|
|
||||||
int32_t temp = 1;
|
|
||||||
temp = (temp << 8) & 0xff00;
|
|
||||||
handle += temp;
|
|
||||||
// shift to last set of bits
|
|
||||||
handle = handle << 8;
|
|
||||||
// add channel to last 8 bits
|
|
||||||
handle += channel;
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
|
|
||||||
int16_t version) {
|
|
||||||
if (index < 0) return HAL_kInvalidHandle;
|
|
||||||
uint8_t hType = static_cast<uint8_t>(handleType);
|
|
||||||
if (hType == 0 || hType > 127) return HAL_kInvalidHandle;
|
|
||||||
// set last 8 bits, then shift to first 8 bits
|
|
||||||
HAL_Handle handle = hType;
|
|
||||||
handle = handle << 8;
|
|
||||||
handle += static_cast<uint8_t>(version);
|
|
||||||
handle = handle << 16;
|
|
||||||
// add index to set last 16 bits
|
|
||||||
handle += index;
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
} // namespace hal
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAccelerometer() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HAL_SetAccelerometerActive(HAL_Bool active) {
|
void HAL_SetAccelerometerActive(HAL_Bool active) {
|
||||||
SimAccelerometerData[0].SetActive(active);
|
SimAccelerometerData[0].SetActive(active);
|
||||||
|
|||||||
@@ -12,10 +12,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogAccumulator() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
|
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -27,7 +33,7 @@ HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -42,7 +48,7 @@ void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -54,7 +60,7 @@ void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t center, int32_t* status) {
|
int32_t center, int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -64,7 +70,7 @@ void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t deadband, int32_t* status) {
|
int32_t deadband, int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -74,7 +80,7 @@ void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
|
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -84,7 +90,7 @@ int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
|
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -94,7 +100,7 @@ int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int64_t* value, int64_t* count, int32_t* status) {
|
int64_t* value, int64_t* count, int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,8 +26,18 @@ struct AnalogGyro {
|
|||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
|
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
|
||||||
HAL_HandleEnum::AnalogGyro>
|
HAL_HandleEnum::AnalogGyro>* analogGyroHandles;
|
||||||
analogGyroHandles;
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogGyro() {
|
||||||
|
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
|
||||||
|
HAL_HandleEnum::AnalogGyro>
|
||||||
|
agH;
|
||||||
|
analogGyroHandles = &agH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
|
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
|
||||||
@@ -42,13 +52,13 @@ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
|
|||||||
// handle known to be correct, so no need to type check
|
// handle known to be correct, so no need to type check
|
||||||
int16_t channel = getHandleIndex(analogHandle);
|
int16_t channel = getHandleIndex(analogHandle);
|
||||||
|
|
||||||
auto handle = analogGyroHandles.Allocate(channel, status);
|
auto handle = analogGyroHandles->Allocate(channel, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
// Initialize port structure
|
// Initialize port structure
|
||||||
auto gyro = analogGyroHandles.Get(handle);
|
auto gyro = analogGyroHandles->Get(handle);
|
||||||
if (gyro == nullptr) { // would only error on thread issue
|
if (gyro == nullptr) { // would only error on thread issue
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -67,8 +77,8 @@ void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
|
void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
|
||||||
auto gyro = analogGyroHandles.Get(handle);
|
auto gyro = analogGyroHandles->Get(handle);
|
||||||
analogGyroHandles.Free(handle);
|
analogGyroHandles->Free(handle);
|
||||||
if (gyro == nullptr) return;
|
if (gyro == nullptr) return;
|
||||||
SimAnalogGyroData[gyro->index].SetInitialized(false);
|
SimAnalogGyroData[gyro->index].SetInitialized(false);
|
||||||
}
|
}
|
||||||
@@ -86,7 +96,7 @@ void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||||
auto gyro = analogGyroHandles.Get(handle);
|
auto gyro = analogGyroHandles->Get(handle);
|
||||||
if (gyro == nullptr) {
|
if (gyro == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -106,7 +116,7 @@ void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
|
double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
|
||||||
auto gyro = analogGyroHandles.Get(handle);
|
auto gyro = analogGyroHandles->Get(handle);
|
||||||
if (gyro == nullptr) {
|
if (gyro == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -116,7 +126,7 @@ double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
|
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
|
||||||
auto gyro = analogGyroHandles.Get(handle);
|
auto gyro = analogGyroHandles->Get(handle);
|
||||||
if (gyro == nullptr) {
|
if (gyro == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogInput() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
|
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
@@ -23,13 +29,13 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
|
|||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_AnalogInputHandle handle = analogInputHandles.Allocate(channel, status);
|
HAL_AnalogInputHandle handle = analogInputHandles->Allocate(channel, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
// Initialize port structure
|
// Initialize port structure
|
||||||
auto analog_port = analogInputHandles.Get(handle);
|
auto analog_port = analogInputHandles->Get(handle);
|
||||||
if (analog_port == nullptr) { // would only error on thread issue
|
if (analog_port == nullptr) { // would only error on thread issue
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -48,9 +54,9 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
|
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
// no status, so no need to check for a proper free.
|
// no status, so no need to check for a proper free.
|
||||||
analogInputHandles.Free(analogPortHandle);
|
analogInputHandles->Free(analogPortHandle);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
SimAnalogInData[port->channel].SetInitialized(false);
|
SimAnalogInData[port->channel].SetInitialized(false);
|
||||||
SimAnalogInData[port->channel].SetAccumulatorInitialized(false);
|
SimAnalogInData[port->channel].SetAccumulatorInitialized(false);
|
||||||
@@ -68,7 +74,7 @@ void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
|
|||||||
double HAL_GetAnalogSampleRate(int32_t* status) { return kDefaultSampleRate; }
|
double HAL_GetAnalogSampleRate(int32_t* status) { return kDefaultSampleRate; }
|
||||||
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t bits, int32_t* status) {
|
int32_t bits, int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -78,7 +84,7 @@ void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -88,7 +94,7 @@ int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t bits, int32_t* status) {
|
int32_t bits, int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +104,7 @@ void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -108,7 +114,7 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -140,7 +146,7 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
@@ -150,7 +156,7 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
|||||||
}
|
}
|
||||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogInputHandles.Get(analogPortHandle);
|
auto port = analogInputHandles->Get(analogPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|||||||
@@ -12,6 +12,16 @@
|
|||||||
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort, kNumAnalogInputs,
|
IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort, kNumAnalogInputs,
|
||||||
HAL_HandleEnum::AnalogInput>
|
HAL_HandleEnum::AnalogInput>* analogInputHandles;
|
||||||
analogInputHandles;
|
} // namespace hal
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogInternal() {
|
||||||
|
static IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
|
||||||
|
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>
|
||||||
|
aiH;
|
||||||
|
analogInputHandles = &aiH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock
|
|||||||
constexpr int32_t kDefaultOversampleBits = 0;
|
constexpr int32_t kDefaultOversampleBits = 0;
|
||||||
constexpr int32_t kDefaultAverageBits = 7;
|
constexpr int32_t kDefaultAverageBits = 7;
|
||||||
constexpr double kDefaultSampleRate = 50000.0;
|
constexpr double kDefaultSampleRate = 50000.0;
|
||||||
static const uint32_t kAccumulatorChannels[] = {0, 1};
|
static constexpr uint32_t kAccumulatorChannels[] = {0, 1};
|
||||||
|
|
||||||
struct AnalogPort {
|
struct AnalogPort {
|
||||||
uint8_t channel;
|
uint8_t channel;
|
||||||
@@ -28,7 +28,7 @@ struct AnalogPort {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
|
extern IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
|
||||||
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>
|
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
|
||||||
analogInputHandles;
|
analogInputHandles;
|
||||||
|
|
||||||
int32_t GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
|
int32_t GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
|
||||||
|
|||||||
@@ -22,9 +22,20 @@ struct AnalogOutput {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
|
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
|
||||||
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>
|
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>*
|
||||||
analogOutputHandles;
|
analogOutputHandles;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogOutput() {
|
||||||
|
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
|
||||||
|
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>
|
||||||
|
aoH;
|
||||||
|
analogOutputHandles = &aoH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
|
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
@@ -34,12 +45,13 @@ HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
|
|||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_AnalogOutputHandle handle = analogOutputHandles.Allocate(channel, status);
|
HAL_AnalogOutputHandle handle =
|
||||||
|
analogOutputHandles->Allocate(channel, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
auto port = analogOutputHandles.Get(handle);
|
auto port = analogOutputHandles->Get(handle);
|
||||||
if (port == nullptr) { // would only error on thread issue
|
if (port == nullptr) { // would only error on thread issue
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -54,9 +66,9 @@ HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
|
|||||||
|
|
||||||
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
|
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
|
||||||
// no status, so no need to check for a proper free.
|
// no status, so no need to check for a proper free.
|
||||||
auto port = analogOutputHandles.Get(analogOutputHandle);
|
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
analogOutputHandles.Free(analogOutputHandle);
|
analogOutputHandles->Free(analogOutputHandle);
|
||||||
SimAnalogOutData[port->channel].SetInitialized(false);
|
SimAnalogOutData[port->channel].SetInitialized(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +78,7 @@ HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
|
|||||||
|
|
||||||
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
||||||
double voltage, int32_t* status) {
|
double voltage, int32_t* status) {
|
||||||
auto port = analogOutputHandles.Get(analogOutputHandle);
|
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -77,7 +89,7 @@ void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
|||||||
|
|
||||||
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = analogOutputHandles.Get(analogOutputHandle);
|
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|||||||
@@ -27,23 +27,54 @@ struct AnalogTrigger {
|
|||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
|
static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
|
||||||
kNumAnalogTriggers, HAL_HandleEnum::AnalogTrigger>
|
kNumAnalogTriggers, HAL_HandleEnum::AnalogTrigger>*
|
||||||
analogTriggerHandles;
|
analogTriggerHandles;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogTrigger() {
|
||||||
|
static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
|
||||||
|
kNumAnalogTriggers,
|
||||||
|
HAL_HandleEnum::AnalogTrigger>
|
||||||
|
atH;
|
||||||
|
analogTriggerHandles = &atH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
int32_t hal::GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
|
||||||
|
int32_t* status) {
|
||||||
|
auto trigger = analogTriggerHandles->Get(handle);
|
||||||
|
if (trigger == nullptr) {
|
||||||
|
*status = HAL_HANDLE_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto analog_port = analogInputHandles->Get(trigger->analogHandle);
|
||||||
|
if (analog_port == nullptr) {
|
||||||
|
*status = HAL_HANDLE_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return analog_port->channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||||
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status) {
|
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status) {
|
||||||
// ensure we are given a valid and active AnalogInput handle
|
// ensure we are given a valid and active AnalogInput handle
|
||||||
auto analog_port = analogInputHandles.Get(portHandle);
|
auto analog_port = analogInputHandles->Get(portHandle);
|
||||||
if (analog_port == nullptr) {
|
if (analog_port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
HAL_AnalogTriggerHandle handle = analogTriggerHandles.Allocate();
|
HAL_AnalogTriggerHandle handle = analogTriggerHandles->Allocate();
|
||||||
if (handle == HAL_kInvalidHandle) {
|
if (handle == HAL_kInvalidHandle) {
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
auto trigger = analogTriggerHandles.Get(handle);
|
auto trigger = analogTriggerHandles->Get(handle);
|
||||||
if (trigger == nullptr) { // would only occur on thread issue
|
if (trigger == nullptr) { // would only occur on thread issue
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -61,8 +92,8 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
|||||||
|
|
||||||
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
analogTriggerHandles.Free(analogTriggerHandle);
|
analogTriggerHandles->Free(analogTriggerHandle);
|
||||||
if (trigger == nullptr) return;
|
if (trigger == nullptr) return;
|
||||||
SimAnalogTriggerData[trigger->index].SetInitialized(false);
|
SimAnalogTriggerData[trigger->index].SetInitialized(false);
|
||||||
// caller owns the analog input handle.
|
// caller owns the analog input handle.
|
||||||
@@ -78,27 +109,10 @@ static double GetAnalogValueToVoltage(
|
|||||||
return voltage;
|
return voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t hal::GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
|
|
||||||
int32_t* status) {
|
|
||||||
auto trigger = analogTriggerHandles.Get(handle);
|
|
||||||
if (trigger == nullptr) {
|
|
||||||
*status = HAL_HANDLE_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto analog_port = analogInputHandles.Get(trigger->analogHandle);
|
|
||||||
if (analog_port == nullptr) {
|
|
||||||
*status = HAL_HANDLE_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return analog_port->channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||||
int32_t lower, int32_t upper,
|
int32_t lower, int32_t upper,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -120,7 +134,7 @@ void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
|||||||
void HAL_SetAnalogTriggerLimitsVoltage(
|
void HAL_SetAnalogTriggerLimitsVoltage(
|
||||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -134,7 +148,7 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
|||||||
}
|
}
|
||||||
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||||
HAL_Bool useAveragedValue, int32_t* status) {
|
HAL_Bool useAveragedValue, int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -153,7 +167,7 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
|||||||
}
|
}
|
||||||
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||||
HAL_Bool useFilteredValue, int32_t* status) {
|
HAL_Bool useFilteredValue, int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -172,7 +186,7 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) {
|
static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) {
|
||||||
auto analogIn = analogInputHandles.Get(trigger->analogHandle);
|
auto analogIn = analogInputHandles->Get(trigger->analogHandle);
|
||||||
if (analogIn == nullptr) {
|
if (analogIn == nullptr) {
|
||||||
// Returning HAL Handle Error, but going to ignore lower down
|
// Returning HAL Handle Error, but going to ignore lower down
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
@@ -184,7 +198,7 @@ static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) {
|
|||||||
|
|
||||||
HAL_Bool HAL_GetAnalogTriggerInWindow(
|
HAL_Bool HAL_GetAnalogTriggerInWindow(
|
||||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -204,7 +218,7 @@ HAL_Bool HAL_GetAnalogTriggerInWindow(
|
|||||||
}
|
}
|
||||||
HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
||||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
||||||
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
|
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||||
if (trigger == nullptr) {
|
if (trigger == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -242,3 +256,4 @@ HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // extern "C"
|
||||||
|
|||||||
@@ -11,41 +11,45 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
CanData hal::SimCanData;
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeCAN() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data,
|
void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data,
|
||||||
uint8_t dataSize, int32_t periodMs, int32_t* status) {
|
uint8_t dataSize, int32_t periodMs, int32_t* status) {
|
||||||
SimCanData.SendMessage(messageID, data, dataSize, periodMs, status);
|
SimCanData->SendMessage(messageID, data, dataSize, periodMs, status);
|
||||||
}
|
}
|
||||||
void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
|
void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
|
||||||
uint8_t* data, uint8_t* dataSize,
|
uint8_t* data, uint8_t* dataSize,
|
||||||
uint32_t* timeStamp, int32_t* status) {
|
uint32_t* timeStamp, int32_t* status) {
|
||||||
SimCanData.ReceiveMessage(messageID, messageIDMask, data, dataSize, timeStamp,
|
SimCanData->ReceiveMessage(messageID, messageIDMask, data, dataSize,
|
||||||
status);
|
timeStamp, status);
|
||||||
}
|
}
|
||||||
void HAL_CAN_OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
|
void HAL_CAN_OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
|
||||||
uint32_t messageIDMask, uint32_t maxMessages,
|
uint32_t messageIDMask, uint32_t maxMessages,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
SimCanData.OpenStreamSession(sessionHandle, messageID, messageIDMask,
|
SimCanData->OpenStreamSession(sessionHandle, messageID, messageIDMask,
|
||||||
maxMessages, status);
|
maxMessages, status);
|
||||||
}
|
}
|
||||||
void HAL_CAN_CloseStreamSession(uint32_t sessionHandle) {
|
void HAL_CAN_CloseStreamSession(uint32_t sessionHandle) {
|
||||||
SimCanData.CloseStreamSession(sessionHandle);
|
SimCanData->CloseStreamSession(sessionHandle);
|
||||||
}
|
}
|
||||||
void HAL_CAN_ReadStreamSession(uint32_t sessionHandle,
|
void HAL_CAN_ReadStreamSession(uint32_t sessionHandle,
|
||||||
struct HAL_CANStreamMessage* messages,
|
struct HAL_CANStreamMessage* messages,
|
||||||
uint32_t messagesToRead, uint32_t* messagesRead,
|
uint32_t messagesToRead, uint32_t* messagesRead,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
SimCanData.ReadStreamSession(sessionHandle, messages, messagesToRead,
|
SimCanData->ReadStreamSession(sessionHandle, messages, messagesToRead,
|
||||||
messagesRead, status);
|
messagesRead, status);
|
||||||
}
|
}
|
||||||
void HAL_CAN_GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount,
|
void HAL_CAN_GetCANStatus(float* percentBusUtilization, uint32_t* busOffCount,
|
||||||
uint32_t* txFullCount, uint32_t* receiveErrorCount,
|
uint32_t* txFullCount, uint32_t* receiveErrorCount,
|
||||||
uint32_t* transmitErrorCount, int32_t* status) {
|
uint32_t* transmitErrorCount, int32_t* status) {
|
||||||
SimCanData.GetCANStatus(percentBusUtilization, busOffCount, txFullCount,
|
SimCanData->GetCANStatus(percentBusUtilization, busOffCount, txFullCount,
|
||||||
receiveErrorCount, transmitErrorCount, status);
|
receiveErrorCount, transmitErrorCount, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeCompressor() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status) {
|
HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status) {
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeConstants() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int32_t HAL_GetSystemClockTicksPerMicrosecond(void) {
|
int32_t HAL_GetSystemClockTicksPerMicrosecond(void) {
|
||||||
return kSystemClockTicksPerMicrosecond;
|
return kSystemClockTicksPerMicrosecond;
|
||||||
|
|||||||
@@ -16,8 +16,18 @@
|
|||||||
namespace hal {
|
namespace hal {
|
||||||
|
|
||||||
LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
|
LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
|
||||||
HAL_HandleEnum::Counter>
|
HAL_HandleEnum::Counter>* counterHandles;
|
||||||
counterHandles;
|
} // namespace hal
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeCounter() {
|
||||||
|
static LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
|
||||||
|
HAL_HandleEnum::Counter>
|
||||||
|
cH;
|
||||||
|
counterHandles = &cH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ struct Counter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
|
extern LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
|
||||||
HAL_HandleEnum::Counter>
|
HAL_HandleEnum::Counter>* counterHandles;
|
||||||
counterHandles;
|
|
||||||
|
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -19,9 +19,21 @@
|
|||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
|
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
|
||||||
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>
|
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>*
|
||||||
digitalPWMHandles;
|
digitalPWMHandles;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeDIO() {
|
||||||
|
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
|
||||||
|
kNumDigitalPWMOutputs,
|
||||||
|
HAL_HandleEnum::DigitalPWM>
|
||||||
|
dpH;
|
||||||
|
digitalPWMHandles = &dpH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,12 +50,12 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto handle =
|
auto handle =
|
||||||
digitalChannelHandles.Allocate(channel, HAL_HandleEnum::DIO, status);
|
digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
auto port = digitalChannelHandles.Get(handle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) { // would only occur on thread issue.
|
if (port == nullptr) { // would only occur on thread issue.
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -63,9 +75,9 @@ HAL_Bool HAL_CheckDIOChannel(int32_t channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
// no status, so no need to check for a proper free.
|
// no status, so no need to check for a proper free.
|
||||||
digitalChannelHandles.Free(dioPortHandle, HAL_HandleEnum::DIO);
|
digitalChannelHandles->Free(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
SimDIOData[port->channel].SetInitialized(true);
|
SimDIOData[port->channel].SetInitialized(true);
|
||||||
}
|
}
|
||||||
@@ -77,13 +89,13 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
|||||||
* @return PWM Generator handle
|
* @return PWM Generator handle
|
||||||
*/
|
*/
|
||||||
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
|
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
|
||||||
auto handle = digitalPWMHandles.Allocate();
|
auto handle = digitalPWMHandles->Allocate();
|
||||||
if (handle == HAL_kInvalidHandle) {
|
if (handle == HAL_kInvalidHandle) {
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto id = digitalPWMHandles.Get(handle);
|
auto id = digitalPWMHandles->Get(handle);
|
||||||
if (id == nullptr) { // would only occur on thread issue.
|
if (id == nullptr) { // would only occur on thread issue.
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -102,8 +114,8 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
|
|||||||
* allocateDigitalPWM()
|
* allocateDigitalPWM()
|
||||||
*/
|
*/
|
||||||
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
|
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
|
||||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
auto port = digitalPWMHandles->Get(pwmGenerator);
|
||||||
digitalPWMHandles.Free(pwmGenerator);
|
digitalPWMHandles->Free(pwmGenerator);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
int32_t id = *port;
|
int32_t id = *port;
|
||||||
SimDigitalPWMData[id].SetInitialized(false);
|
SimDigitalPWMData[id].SetInitialized(false);
|
||||||
@@ -137,7 +149,7 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
|
|||||||
*/
|
*/
|
||||||
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||||
double dutyCycle, int32_t* status) {
|
double dutyCycle, int32_t* status) {
|
||||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
auto port = digitalPWMHandles->Get(pwmGenerator);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -156,7 +168,7 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
|||||||
*/
|
*/
|
||||||
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
||||||
int32_t channel, int32_t* status) {
|
int32_t channel, int32_t* status) {
|
||||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
auto port = digitalPWMHandles->Get(pwmGenerator);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -175,7 +187,7 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
|||||||
*/
|
*/
|
||||||
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -194,7 +206,7 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
|||||||
* @return The state of the specified channel
|
* @return The state of the specified channel
|
||||||
*/
|
*/
|
||||||
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -213,7 +225,7 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
|||||||
* @return The direction of the specified channel
|
* @return The direction of the specified channel
|
||||||
*/
|
*/
|
||||||
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -234,7 +246,7 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
|||||||
*/
|
*/
|
||||||
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
|
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -248,7 +260,7 @@ void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
|
|||||||
* @return A pulse is in progress
|
* @return A pulse is in progress
|
||||||
*/
|
*/
|
||||||
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -276,7 +288,7 @@ HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
|
|||||||
*/
|
*/
|
||||||
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
|
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -294,7 +306,7 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
|
|||||||
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
|
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
|
||||||
*/
|
*/
|
||||||
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
|
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -15,12 +15,19 @@
|
|||||||
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
|
|
||||||
bool digitalSystemsInitialized = false;
|
|
||||||
|
|
||||||
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
||||||
kNumDigitalChannels + kNumPWMHeaders>
|
kNumDigitalChannels + kNumPWMHeaders>*
|
||||||
digitalChannelHandles;
|
digitalChannelHandles;
|
||||||
|
|
||||||
|
namespace init {
|
||||||
|
void InitializeDigitalInternal() {
|
||||||
|
static DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
||||||
|
kNumDigitalChannels + kNumPWMHeaders>
|
||||||
|
dcH;
|
||||||
|
digitalChannelHandles = &dcH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map DIO channel numbers from their physical number (10 to 26) to their
|
* Map DIO channel numbers from their physical number (10 to 26) to their
|
||||||
* position in the bit field.
|
* position in the bit field.
|
||||||
@@ -69,7 +76,7 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t GetDigitalInputChannel(HAL_DigitalHandle handle, int32_t* status) {
|
int32_t GetDigitalInputChannel(HAL_DigitalHandle handle, int32_t* status) {
|
||||||
auto digital = digitalChannelHandles.Get(handle, HAL_HandleEnum::DIO);
|
auto digital = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
|
||||||
if (digital == nullptr) {
|
if (digital == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ struct DigitalPort {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
||||||
kNumDigitalChannels + kNumPWMHeaders>
|
kNumDigitalChannels + kNumPWMHeaders>*
|
||||||
digitalChannelHandles;
|
digitalChannelHandles;
|
||||||
|
|
||||||
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
||||||
|
|||||||
@@ -23,10 +23,19 @@
|
|||||||
#include "MockData/MockHooks.h"
|
#include "MockData/MockHooks.h"
|
||||||
|
|
||||||
static wpi::mutex msgMutex;
|
static wpi::mutex msgMutex;
|
||||||
static wpi::condition_variable newDSDataAvailableCond;
|
static wpi::condition_variable* newDSDataAvailableCond;
|
||||||
static wpi::mutex newDSDataAvailableMutex;
|
static wpi::mutex newDSDataAvailableMutex;
|
||||||
static int newDSDataAvailableCounter{0};
|
static int newDSDataAvailableCounter{0};
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeDriverStation() {
|
||||||
|
static wpi::condition_variable nddaC;
|
||||||
|
newDSDataAvailableCond = &nddaC;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -85,33 +94,33 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||||
controlWord->enabled = SimDriverStationData.GetEnabled();
|
controlWord->enabled = SimDriverStationData->GetEnabled();
|
||||||
controlWord->autonomous = SimDriverStationData.GetAutonomous();
|
controlWord->autonomous = SimDriverStationData->GetAutonomous();
|
||||||
controlWord->test = SimDriverStationData.GetTest();
|
controlWord->test = SimDriverStationData->GetTest();
|
||||||
controlWord->eStop = SimDriverStationData.GetEStop();
|
controlWord->eStop = SimDriverStationData->GetEStop();
|
||||||
controlWord->fmsAttached = SimDriverStationData.GetFmsAttached();
|
controlWord->fmsAttached = SimDriverStationData->GetFmsAttached();
|
||||||
controlWord->dsAttached = SimDriverStationData.GetDsAttached();
|
controlWord->dsAttached = SimDriverStationData->GetDsAttached();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
|
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
|
||||||
*status = 0;
|
*status = 0;
|
||||||
return SimDriverStationData.GetAllianceStationId();
|
return SimDriverStationData->GetAllianceStationId();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
|
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
|
||||||
SimDriverStationData.GetJoystickAxes(joystickNum, axes);
|
SimDriverStationData->GetJoystickAxes(joystickNum, axes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
|
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
|
||||||
SimDriverStationData.GetJoystickPOVs(joystickNum, povs);
|
SimDriverStationData->GetJoystickPOVs(joystickNum, povs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||||
HAL_JoystickButtons* buttons) {
|
HAL_JoystickButtons* buttons) {
|
||||||
SimDriverStationData.GetJoystickButtons(joystickNum, buttons);
|
SimDriverStationData->GetJoystickButtons(joystickNum, buttons);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -127,25 +136,25 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
|||||||
*/
|
*/
|
||||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||||
HAL_JoystickDescriptor* desc) {
|
HAL_JoystickDescriptor* desc) {
|
||||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, desc);
|
SimDriverStationData->GetJoystickDescriptor(joystickNum, desc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) {
|
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) {
|
||||||
HAL_JoystickDescriptor desc;
|
HAL_JoystickDescriptor desc;
|
||||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||||
return desc.isXbox;
|
return desc.isXbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
||||||
HAL_JoystickDescriptor desc;
|
HAL_JoystickDescriptor desc;
|
||||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||||
return desc.type;
|
return desc.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* HAL_GetJoystickName(int32_t joystickNum) {
|
char* HAL_GetJoystickName(int32_t joystickNum) {
|
||||||
HAL_JoystickDescriptor desc;
|
HAL_JoystickDescriptor desc;
|
||||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||||
size_t len = std::strlen(desc.name);
|
size_t len = std::strlen(desc.name);
|
||||||
char* name = static_cast<char*>(std::malloc(len + 1));
|
char* name = static_cast<char*>(std::malloc(len + 1));
|
||||||
std::strncpy(name, desc.name, len);
|
std::strncpy(name, desc.name, len);
|
||||||
@@ -159,22 +168,22 @@ int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) { return 0; }
|
|||||||
|
|
||||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||||
int32_t leftRumble, int32_t rightRumble) {
|
int32_t leftRumble, int32_t rightRumble) {
|
||||||
SimDriverStationData.SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
SimDriverStationData->SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||||
rightRumble);
|
rightRumble);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double HAL_GetMatchTime(int32_t* status) {
|
double HAL_GetMatchTime(int32_t* status) {
|
||||||
return SimDriverStationData.GetMatchTime();
|
return SimDriverStationData->GetMatchTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
int HAL_GetMatchInfo(HAL_MatchInfo* info) {
|
int HAL_GetMatchInfo(HAL_MatchInfo* info) {
|
||||||
SimDriverStationData.GetMatchInfo(info);
|
SimDriverStationData->GetMatchInfo(info);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_FreeMatchInfo(HAL_MatchInfo* info) {
|
void HAL_FreeMatchInfo(HAL_MatchInfo* info) {
|
||||||
SimDriverStationData.FreeMatchInfo(info);
|
SimDriverStationData->FreeMatchInfo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_ObserveUserProgramStarting(void) { HALSIM_SetProgramStarted(); }
|
void HAL_ObserveUserProgramStarting(void) { HALSIM_SetProgramStarted(); }
|
||||||
@@ -249,12 +258,12 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
|||||||
int currentCount = newDSDataAvailableCounter;
|
int currentCount = newDSDataAvailableCounter;
|
||||||
while (newDSDataAvailableCounter == currentCount) {
|
while (newDSDataAvailableCounter == currentCount) {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
auto timedOut = newDSDataAvailableCond.wait_until(lock, timeoutTime);
|
auto timedOut = newDSDataAvailableCond->wait_until(lock, timeoutTime);
|
||||||
if (timedOut == std::cv_status::timeout) {
|
if (timedOut == std::cv_status::timeout) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newDSDataAvailableCond.wait(lock);
|
newDSDataAvailableCond->wait(lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -270,7 +279,7 @@ static int32_t newDataOccur(uint32_t refNum) {
|
|||||||
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
|
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||||
// Nofify all threads
|
// Nofify all threads
|
||||||
newDSDataAvailableCounter++;
|
newDSDataAvailableCounter++;
|
||||||
newDSDataAvailableCond.notify_all();
|
newDSDataAvailableCond->notify_all();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +298,7 @@ void HAL_InitializeDriverStation(void) {
|
|||||||
// Second check in case another thread was waiting
|
// Second check in case another thread was waiting
|
||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
|
|
||||||
SimDriverStationData.ResetData();
|
SimDriverStationData->ResetData();
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,26 @@ struct Empty {};
|
|||||||
|
|
||||||
static LimitedHandleResource<HAL_EncoderHandle, Encoder,
|
static LimitedHandleResource<HAL_EncoderHandle, Encoder,
|
||||||
kNumEncoders + kNumCounters,
|
kNumEncoders + kNumCounters,
|
||||||
HAL_HandleEnum::Encoder>
|
HAL_HandleEnum::Encoder>* encoderHandles;
|
||||||
encoderHandles;
|
|
||||||
|
|
||||||
static LimitedHandleResource<HAL_FPGAEncoderHandle, Empty, kNumEncoders,
|
static LimitedHandleResource<HAL_FPGAEncoderHandle, Empty, kNumEncoders,
|
||||||
HAL_HandleEnum::FPGAEncoder>
|
HAL_HandleEnum::FPGAEncoder>* fpgaEncoderHandles;
|
||||||
fpgaEncoderHandles;
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeEncoder() {
|
||||||
|
static LimitedHandleResource<HAL_FPGAEncoderHandle, Empty, kNumEncoders,
|
||||||
|
HAL_HandleEnum::FPGAEncoder>
|
||||||
|
feH;
|
||||||
|
fpgaEncoderHandles = &feH;
|
||||||
|
static LimitedHandleResource<HAL_EncoderHandle, Encoder,
|
||||||
|
kNumEncoders + kNumCounters,
|
||||||
|
HAL_HandleEnum::Encoder>
|
||||||
|
eH;
|
||||||
|
encoderHandles = &eH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_EncoderHandle HAL_InitializeEncoder(
|
HAL_EncoderHandle HAL_InitializeEncoder(
|
||||||
@@ -45,21 +59,21 @@ HAL_EncoderHandle HAL_InitializeEncoder(
|
|||||||
HAL_Handle nativeHandle = HAL_kInvalidHandle;
|
HAL_Handle nativeHandle = HAL_kInvalidHandle;
|
||||||
if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||||
// k4x, allocate encoder
|
// k4x, allocate encoder
|
||||||
nativeHandle = fpgaEncoderHandles.Allocate();
|
nativeHandle = fpgaEncoderHandles->Allocate();
|
||||||
} else {
|
} else {
|
||||||
// k2x or k1x, allocate counter
|
// k2x or k1x, allocate counter
|
||||||
nativeHandle = counterHandles.Allocate();
|
nativeHandle = counterHandles->Allocate();
|
||||||
}
|
}
|
||||||
if (nativeHandle == HAL_kInvalidHandle) {
|
if (nativeHandle == HAL_kInvalidHandle) {
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
auto handle = encoderHandles.Allocate();
|
auto handle = encoderHandles->Allocate();
|
||||||
if (handle == HAL_kInvalidHandle) {
|
if (handle == HAL_kInvalidHandle) {
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
auto encoder = encoderHandles.Get(handle);
|
auto encoder = encoderHandles->Get(handle);
|
||||||
if (encoder == nullptr) { // would only occur on thread issue
|
if (encoder == nullptr) { // would only occur on thread issue
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -75,13 +89,13 @@ HAL_EncoderHandle HAL_InitializeEncoder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
encoderHandles.Free(encoderHandle);
|
encoderHandles->Free(encoderHandle);
|
||||||
if (encoder == nullptr) return;
|
if (encoder == nullptr) return;
|
||||||
if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::FPGAEncoder)) {
|
if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::FPGAEncoder)) {
|
||||||
fpgaEncoderHandles.Free(encoder->nativeHandle);
|
fpgaEncoderHandles->Free(encoder->nativeHandle);
|
||||||
} else if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::Counter)) {
|
} else if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::Counter)) {
|
||||||
counterHandles.Free(encoder->nativeHandle);
|
counterHandles->Free(encoder->nativeHandle);
|
||||||
}
|
}
|
||||||
SimEncoderData[encoder->index].SetInitialized(false);
|
SimEncoderData[encoder->index].SetInitialized(false);
|
||||||
}
|
}
|
||||||
@@ -113,7 +127,7 @@ static inline double DecodingScaleFactor(Encoder* encoder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -122,7 +136,7 @@ int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
|||||||
return SimEncoderData[encoder->index].GetCount();
|
return SimEncoderData[encoder->index].GetCount();
|
||||||
}
|
}
|
||||||
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -133,7 +147,7 @@ int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
|
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -142,7 +156,7 @@ int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
|
|||||||
return EncodingScaleFactor(encoder.get());
|
return EncodingScaleFactor(encoder.get());
|
||||||
}
|
}
|
||||||
void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -153,7 +167,7 @@ void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
|||||||
SimEncoderData[encoder->index].SetReset(true);
|
SimEncoderData[encoder->index].SetReset(true);
|
||||||
}
|
}
|
||||||
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -163,7 +177,7 @@ double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
|
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -173,7 +187,7 @@ void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
|
|||||||
}
|
}
|
||||||
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
|
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -184,7 +198,7 @@ HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
|
|||||||
}
|
}
|
||||||
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
|
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -194,7 +208,7 @@ HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
|
|||||||
}
|
}
|
||||||
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
|
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -203,7 +217,7 @@ double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
|
|||||||
return SimEncoderData[encoder->index].GetCount() * encoder->distancePerPulse;
|
return SimEncoderData[encoder->index].GetCount() * encoder->distancePerPulse;
|
||||||
}
|
}
|
||||||
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -213,7 +227,7 @@ double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
|
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -229,7 +243,7 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
|
|||||||
}
|
}
|
||||||
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
||||||
double distancePerPulse, int32_t* status) {
|
double distancePerPulse, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -244,7 +258,7 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
|||||||
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
|
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
|
||||||
HAL_Bool reverseDirection,
|
HAL_Bool reverseDirection,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -254,7 +268,7 @@ void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
|
|||||||
}
|
}
|
||||||
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
|
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t samplesToAverage, int32_t* status) {
|
int32_t samplesToAverage, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -264,7 +278,7 @@ void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
|
|||||||
}
|
}
|
||||||
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
|
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -282,7 +296,7 @@ void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
|
|||||||
|
|
||||||
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
|
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -293,7 +307,7 @@ int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
|
|||||||
|
|
||||||
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
|
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
@@ -304,7 +318,7 @@ double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
|
|||||||
|
|
||||||
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
@@ -315,7 +329,7 @@ double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
|||||||
|
|
||||||
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
|
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
|
||||||
HAL_EncoderHandle encoderHandle, int32_t* status) {
|
HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||||
auto encoder = encoderHandles.Get(encoderHandle);
|
auto encoder = encoderHandles->Get(encoderHandle);
|
||||||
if (encoder == nullptr) {
|
if (encoder == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_Encoder_k4X; // default to k4x
|
return HAL_Encoder_k4X; // default to k4x
|
||||||
|
|||||||
@@ -33,6 +33,12 @@
|
|||||||
#define DLCLOSE dlclose
|
#define DLCLOSE dlclose
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeExtensions() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
int HAL_LoadOneExtension(const char* library) {
|
int HAL_LoadOneExtension(const char* library) {
|
||||||
|
|||||||
@@ -14,11 +14,66 @@
|
|||||||
#include "HAL/Errors.h"
|
#include "HAL/Errors.h"
|
||||||
#include "HAL/Extensions.h"
|
#include "HAL/Extensions.h"
|
||||||
#include "HAL/handles/HandlesInternal.h"
|
#include "HAL/handles/HandlesInternal.h"
|
||||||
|
#include "HALInitializer.h"
|
||||||
#include "MockData/RoboRioDataInternal.h"
|
#include "MockData/RoboRioDataInternal.h"
|
||||||
#include "MockHooksInternal.h"
|
#include "MockHooksInternal.h"
|
||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeHAL() {
|
||||||
|
InitializeHandlesInternal();
|
||||||
|
InitializeAccelerometerData();
|
||||||
|
InitializeAnalogGyroData();
|
||||||
|
InitializeAnalogInData();
|
||||||
|
InitializeAnalogOutData();
|
||||||
|
InitializeAnalogTriggerData();
|
||||||
|
InitializeCanData();
|
||||||
|
InitializeDigitalPWMData();
|
||||||
|
InitializeDIOData();
|
||||||
|
InitializeDriverStationData();
|
||||||
|
InitializeEncoderData();
|
||||||
|
InitializeI2CData();
|
||||||
|
InitializePCMData();
|
||||||
|
InitializePDPData();
|
||||||
|
InitializePWMData();
|
||||||
|
InitializeRelayData();
|
||||||
|
InitializeRoboRioData();
|
||||||
|
InitializeSPIAccelerometerData();
|
||||||
|
InitializeSPIData();
|
||||||
|
InitializeAccelerometer();
|
||||||
|
InitializeAnalogAccumulator();
|
||||||
|
InitializeAnalogGyro();
|
||||||
|
InitializeAnalogInput();
|
||||||
|
InitializeAnalogInternal();
|
||||||
|
InitializeAnalogOutput();
|
||||||
|
InitializeCAN();
|
||||||
|
InitializeCompressor();
|
||||||
|
InitializeConstants();
|
||||||
|
InitializeCounter();
|
||||||
|
InitializeDigitalInternal();
|
||||||
|
InitializeDIO();
|
||||||
|
InitializeDriverStation();
|
||||||
|
InitializeExtensions();
|
||||||
|
InitializeI2C();
|
||||||
|
InitializeInterrupts();
|
||||||
|
InitializeMockHooks();
|
||||||
|
InitializeNotifier();
|
||||||
|
InitializeOSSerialPort();
|
||||||
|
InitializePDP();
|
||||||
|
InitializePorts();
|
||||||
|
InitializePower();
|
||||||
|
InitializePWM();
|
||||||
|
InitializeRelay();
|
||||||
|
InitializeSerialPort();
|
||||||
|
InitializeSolenoid();
|
||||||
|
InitializeSPI();
|
||||||
|
InitializeThreads();
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
HAL_PortHandle HAL_GetPort(int32_t channel) {
|
HAL_PortHandle HAL_GetPort(int32_t channel) {
|
||||||
@@ -206,6 +261,8 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
|||||||
// Second check in case another thread was waiting
|
// Second check in case another thread was waiting
|
||||||
if (initialized) return true;
|
if (initialized) return true;
|
||||||
|
|
||||||
|
hal::init::InitializeHAL();
|
||||||
|
|
||||||
llvm::outs().SetUnbuffered();
|
llvm::outs().SetUnbuffered();
|
||||||
if (HAL_LoadExtensions() < 0) return false;
|
if (HAL_LoadExtensions() < 0) return false;
|
||||||
hal::RestartTiming();
|
hal::RestartTiming();
|
||||||
|
|||||||
@@ -9,7 +9,54 @@
|
|||||||
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
namespace init {
|
namespace init {
|
||||||
extern void InitializeHAL();
|
|
||||||
extern void InitializeHandlesInternal();
|
extern void InitializeHandlesInternal();
|
||||||
|
extern void InitializeAccelerometerData();
|
||||||
|
extern void InitializeAnalogGyroData();
|
||||||
|
extern void InitializeAnalogInData();
|
||||||
|
extern void InitializeAnalogOutData();
|
||||||
|
extern void InitializeAnalogTriggerData();
|
||||||
|
extern void InitializeCanData();
|
||||||
|
extern void InitializeDigitalPWMData();
|
||||||
|
extern void InitializeDIOData();
|
||||||
|
extern void InitializeDriverStationData();
|
||||||
|
extern void InitializeEncoderData();
|
||||||
|
extern void InitializeI2CData();
|
||||||
|
extern void InitializePCMData();
|
||||||
|
extern void InitializePDPData();
|
||||||
|
extern void InitializePWMData();
|
||||||
|
extern void InitializeRelayData();
|
||||||
|
extern void InitializeRoboRioData();
|
||||||
|
extern void InitializeSPIAccelerometerData();
|
||||||
|
extern void InitializeSPIData();
|
||||||
|
extern void InitializeAccelerometer();
|
||||||
|
extern void InitializeAnalogAccumulator();
|
||||||
|
extern void InitializeAnalogGyro();
|
||||||
|
extern void InitializeAnalogInput();
|
||||||
|
extern void InitializeAnalogInternal();
|
||||||
|
extern void InitializeAnalogOutput();
|
||||||
|
extern void InitializeCAN();
|
||||||
|
extern void InitializeCompressor();
|
||||||
|
extern void InitializeConstants();
|
||||||
|
extern void InitializeCounter();
|
||||||
|
extern void InitializeDigitalInternal();
|
||||||
|
extern void InitializeDIO();
|
||||||
|
extern void InitializeDriverStation();
|
||||||
|
extern void InitializeExtensions();
|
||||||
|
extern void InitializeHAL();
|
||||||
|
extern void InitializeI2C();
|
||||||
|
extern void InitializeInterrupts();
|
||||||
|
extern void InitializeMockHooks();
|
||||||
|
extern void InitializeNotifier();
|
||||||
|
extern void InitializeOSSerialPort();
|
||||||
|
extern void InitializePDP();
|
||||||
|
extern void InitializePorts();
|
||||||
|
extern void InitializePower();
|
||||||
|
extern void InitializePWM();
|
||||||
|
extern void InitializeRelay();
|
||||||
|
extern void InitializeSerialPort();
|
||||||
|
extern void InitializeSolenoid();
|
||||||
|
extern void InitializeSPI();
|
||||||
|
extern void InitializeThreads();
|
||||||
|
|
||||||
} // namespace init
|
} // namespace init
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeI2C() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||||
SimI2CData[port].SetInitialized(true);
|
SimI2CData[port].SetInitialized(true);
|
||||||
|
|||||||
@@ -60,23 +60,37 @@ struct SynchronousWaitData {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||||
HAL_HandleEnum::Interrupt>
|
HAL_HandleEnum::Interrupt>* interruptHandles;
|
||||||
interruptHandles;
|
|
||||||
|
|
||||||
typedef HAL_Handle SynchronousWaitDataHandle;
|
typedef HAL_Handle SynchronousWaitDataHandle;
|
||||||
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
|
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
|
||||||
HAL_HandleEnum::Vendor>
|
HAL_HandleEnum::Vendor>*
|
||||||
synchronousInterruptHandles;
|
synchronousInterruptHandles;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeInterrupts() {
|
||||||
|
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||||
|
HAL_HandleEnum::Interrupt>
|
||||||
|
iH;
|
||||||
|
interruptHandles = &iH;
|
||||||
|
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
|
||||||
|
HAL_HandleEnum::Vendor>
|
||||||
|
siH;
|
||||||
|
synchronousInterruptHandles = &siH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
HAL_InterruptHandle handle = interruptHandles.Allocate();
|
HAL_InterruptHandle handle = interruptHandles->Allocate();
|
||||||
if (handle == HAL_kInvalidHandle) {
|
if (handle == HAL_kInvalidHandle) {
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
auto anInterrupt = interruptHandles.Get(handle);
|
auto anInterrupt = interruptHandles->Get(handle);
|
||||||
if (anInterrupt == nullptr) { // would only occur on thread issue.
|
if (anInterrupt == nullptr) { // would only occur on thread issue.
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -91,8 +105,8 @@ HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
|||||||
}
|
}
|
||||||
void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status) {
|
void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status) {
|
||||||
HAL_DisableInterrupts(interruptHandle, status);
|
HAL_DisableInterrupts(interruptHandle, status);
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
interruptHandles.Free(interruptHandle);
|
interruptHandles->Free(interruptHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
||||||
@@ -102,9 +116,9 @@ static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
|||||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||||
SynchronousWaitDataHandle handle =
|
SynchronousWaitDataHandle handle =
|
||||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||||
auto interruptData = synchronousInterruptHandles.Get(handle);
|
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||||
if (interruptData == nullptr) return;
|
if (interruptData == nullptr) return;
|
||||||
auto interrupt = interruptHandles.Get(interruptData->interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||||
if (interrupt == nullptr) return;
|
if (interrupt == nullptr) return;
|
||||||
// Have a valid interrupt
|
// Have a valid interrupt
|
||||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||||
@@ -135,9 +149,9 @@ static void ProcessInterruptAnalogSynchronous(const char* name, void* param,
|
|||||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||||
SynchronousWaitDataHandle handle =
|
SynchronousWaitDataHandle handle =
|
||||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||||
auto interruptData = synchronousInterruptHandles.Get(handle);
|
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||||
if (interruptData == nullptr) return;
|
if (interruptData == nullptr) return;
|
||||||
auto interrupt = interruptHandles.Get(interruptData->interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||||
if (interrupt == nullptr) return;
|
if (interrupt == nullptr) return;
|
||||||
// Have a valid interrupt
|
// Have a valid interrupt
|
||||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||||
@@ -168,13 +182,13 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
|||||||
bool ignorePrevious) {
|
bool ignorePrevious) {
|
||||||
auto data = std::make_shared<SynchronousWaitData>();
|
auto data = std::make_shared<SynchronousWaitData>();
|
||||||
|
|
||||||
auto dataHandle = synchronousInterruptHandles.Allocate(data);
|
auto dataHandle = synchronousInterruptHandles->Allocate(data);
|
||||||
if (dataHandle == HAL_kInvalidHandle) {
|
if (dataHandle == HAL_kInvalidHandle) {
|
||||||
// Error allocating data
|
// Error allocating data
|
||||||
return WaitResult::Timeout;
|
return WaitResult::Timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto data = synchronousInterruptHandles.Get(dataHandle);
|
// auto data = synchronousInterruptHandles->Get(dataHandle);
|
||||||
data->waitPredicate = false;
|
data->waitPredicate = false;
|
||||||
data->interruptHandle = handle;
|
data->interruptHandle = handle;
|
||||||
|
|
||||||
@@ -216,7 +230,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
|||||||
|
|
||||||
// Cancel our callback
|
// Cancel our callback
|
||||||
SimDIOData[digitalIndex].CancelValueCallback(uid);
|
SimDIOData[digitalIndex].CancelValueCallback(uid);
|
||||||
synchronousInterruptHandles.Free(dataHandle);
|
synchronousInterruptHandles->Free(dataHandle);
|
||||||
|
|
||||||
// Check for what to return
|
// Check for what to return
|
||||||
if (timedOut) return WaitResult::Timeout;
|
if (timedOut) return WaitResult::Timeout;
|
||||||
@@ -236,7 +250,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
|||||||
bool ignorePrevious) {
|
bool ignorePrevious) {
|
||||||
auto data = std::make_shared<SynchronousWaitData>();
|
auto data = std::make_shared<SynchronousWaitData>();
|
||||||
|
|
||||||
auto dataHandle = synchronousInterruptHandles.Allocate(data);
|
auto dataHandle = synchronousInterruptHandles->Allocate(data);
|
||||||
if (dataHandle == HAL_kInvalidHandle) {
|
if (dataHandle == HAL_kInvalidHandle) {
|
||||||
// Error allocating data
|
// Error allocating data
|
||||||
return WaitResult::Timeout;
|
return WaitResult::Timeout;
|
||||||
@@ -286,7 +300,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
|||||||
|
|
||||||
// Cancel our callback
|
// Cancel our callback
|
||||||
SimAnalogInData[analogIndex].CancelVoltageCallback(uid);
|
SimAnalogInData[analogIndex].CancelVoltageCallback(uid);
|
||||||
synchronousInterruptHandles.Free(dataHandle);
|
synchronousInterruptHandles->Free(dataHandle);
|
||||||
|
|
||||||
// Check for what to return
|
// Check for what to return
|
||||||
if (timedOut) return WaitResult::Timeout;
|
if (timedOut) return WaitResult::Timeout;
|
||||||
@@ -304,7 +318,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
|||||||
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
|
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
|
||||||
double timeout, HAL_Bool ignorePrevious,
|
double timeout, HAL_Bool ignorePrevious,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return WaitResult::Timeout;
|
return WaitResult::Timeout;
|
||||||
@@ -331,7 +345,7 @@ static void ProcessInterruptDigitalAsynchronous(const char* name, void* param,
|
|||||||
// convert to uintptr_t first, then to handle
|
// convert to uintptr_t first, then to handle
|
||||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||||
auto interrupt = interruptHandles.Get(handle);
|
auto interrupt = interruptHandles->Get(handle);
|
||||||
if (interrupt == nullptr) return;
|
if (interrupt == nullptr) return;
|
||||||
// Have a valid interrupt
|
// Have a valid interrupt
|
||||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||||
@@ -363,7 +377,7 @@ static void ProcessInterruptAnalogAsynchronous(const char* name, void* param,
|
|||||||
// convert to intptr_t first, then to handle
|
// convert to intptr_t first, then to handle
|
||||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||||
auto interrupt = interruptHandles.Get(handle);
|
auto interrupt = interruptHandles->Get(handle);
|
||||||
if (interrupt == nullptr) return;
|
if (interrupt == nullptr) return;
|
||||||
// Have a valid interrupt
|
// Have a valid interrupt
|
||||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||||
@@ -426,7 +440,7 @@ static void EnableInterruptsAnalog(HAL_InterruptHandle handle,
|
|||||||
|
|
||||||
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -452,7 +466,7 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
|||||||
}
|
}
|
||||||
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -479,7 +493,7 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
|||||||
}
|
}
|
||||||
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -489,7 +503,7 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
|||||||
}
|
}
|
||||||
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
|
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -501,7 +515,7 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
|
|||||||
HAL_Handle digitalSourceHandle,
|
HAL_Handle digitalSourceHandle,
|
||||||
HAL_AnalogTriggerType analogTriggerType,
|
HAL_AnalogTriggerType analogTriggerType,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -525,7 +539,7 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
|
|||||||
void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle,
|
void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle,
|
||||||
HAL_InterruptHandlerFunction handler,
|
HAL_InterruptHandlerFunction handler,
|
||||||
void* param, int32_t* status) {
|
void* param, int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -544,7 +558,7 @@ void HAL_AttachInterruptHandlerThreaded(HAL_InterruptHandle interruptHandle,
|
|||||||
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
||||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto interrupt = interruptHandles.Get(interruptHandle);
|
auto interrupt = interruptHandles->Get(interruptHandle);
|
||||||
if (interrupt == nullptr) {
|
if (interrupt == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
AccelerometerData hal::SimAccelerometerData[1];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAccelerometerData() {
|
||||||
|
static AccelerometerData sad[1];
|
||||||
|
::hal::SimAccelerometerData = sad;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
AccelerometerData* hal::SimAccelerometerData;
|
||||||
void AccelerometerData::ResetData() {
|
void AccelerometerData::ResetData() {
|
||||||
m_active = false;
|
m_active = false;
|
||||||
m_activeCallbacks = nullptr;
|
m_activeCallbacks = nullptr;
|
||||||
|
|||||||
@@ -69,5 +69,5 @@ class AccelerometerData {
|
|||||||
std::atomic<double> m_z{0.0};
|
std::atomic<double> m_z{0.0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern AccelerometerData SimAccelerometerData[];
|
extern AccelerometerData* SimAccelerometerData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
AnalogGyroData hal::SimAnalogGyroData[kNumAccumulators];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogGyroData() {
|
||||||
|
static AnalogGyroData agd[kNumAccumulators];
|
||||||
|
::hal::SimAnalogGyroData = agd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
AnalogGyroData* hal::SimAnalogGyroData;
|
||||||
void AnalogGyroData::ResetData() {
|
void AnalogGyroData::ResetData() {
|
||||||
m_angle = 0.0;
|
m_angle = 0.0;
|
||||||
m_angleCallbacks = nullptr;
|
m_angleCallbacks = nullptr;
|
||||||
|
|||||||
@@ -50,5 +50,5 @@ class AnalogGyroData {
|
|||||||
std::atomic<HAL_Bool> m_initialized{false};
|
std::atomic<HAL_Bool> m_initialized{false};
|
||||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern AnalogGyroData SimAnalogGyroData[];
|
extern AnalogGyroData* SimAnalogGyroData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
AnalogInData hal::SimAnalogInData[kNumAnalogInputs];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogInData() {
|
||||||
|
static AnalogInData sind[kNumAnalogInputs];
|
||||||
|
::hal::SimAnalogInData = sind;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
AnalogInData* hal::SimAnalogInData;
|
||||||
void AnalogInData::ResetData() {
|
void AnalogInData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -109,5 +109,5 @@ class AnalogInData {
|
|||||||
std::shared_ptr<NotifyListenerVector> m_accumulatorDeadbandCallbacks =
|
std::shared_ptr<NotifyListenerVector> m_accumulatorDeadbandCallbacks =
|
||||||
nullptr;
|
nullptr;
|
||||||
};
|
};
|
||||||
extern AnalogInData SimAnalogInData[];
|
extern AnalogInData* SimAnalogInData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
AnalogOutData hal::SimAnalogOutData[kNumAnalogOutputs];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogOutData() {
|
||||||
|
static AnalogOutData siod[kNumAnalogOutputs];
|
||||||
|
::hal::SimAnalogOutData = siod;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
AnalogOutData* hal::SimAnalogOutData;
|
||||||
void AnalogOutData::ResetData() {
|
void AnalogOutData::ResetData() {
|
||||||
m_voltage = 0.0;
|
m_voltage = 0.0;
|
||||||
m_voltageCallbacks = nullptr;
|
m_voltageCallbacks = nullptr;
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ class AnalogOutData {
|
|||||||
std::atomic<HAL_Bool> m_initialized{0};
|
std::atomic<HAL_Bool> m_initialized{0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern AnalogOutData SimAnalogOutData[];
|
extern AnalogOutData* SimAnalogOutData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
AnalogTriggerData hal::SimAnalogTriggerData[kNumAnalogTriggers];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeAnalogTriggerData() {
|
||||||
|
static AnalogTriggerData satd[kNumAnalogTriggers];
|
||||||
|
::hal::SimAnalogTriggerData = satd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
AnalogTriggerData* hal::SimAnalogTriggerData;
|
||||||
void AnalogTriggerData::ResetData() {
|
void AnalogTriggerData::ResetData() {
|
||||||
m_initialized = 0;
|
m_initialized = 0;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -62,5 +62,5 @@ class AnalogTriggerData {
|
|||||||
static_cast<HALSIM_AnalogTriggerMode>(0)};
|
static_cast<HALSIM_AnalogTriggerMode>(0)};
|
||||||
std::shared_ptr<NotifyListenerVector> m_triggerModeCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_triggerModeCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern AnalogTriggerData SimAnalogTriggerData[];
|
extern AnalogTriggerData* SimAnalogTriggerData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,6 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
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,
|
void InvokeCallback(std::shared_ptr<CanSendMessageListenerVector> currentVector,
|
||||||
const char* name, uint32_t messageID, const uint8_t* data,
|
const char* name, uint32_t messageID, const uint8_t* data,
|
||||||
uint8_t dataSize, int32_t periodMs, int32_t* status) {
|
uint8_t dataSize, int32_t periodMs, int32_t* status) {
|
||||||
@@ -233,54 +243,54 @@ void CanData::CancelGetCANStatusCallback(int32_t uid) {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void HALSIM_ResetCanData(void) { SimCanData.ResetData(); }
|
void HALSIM_ResetCanData(void) { SimCanData->ResetData(); }
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanSendMessageCallback(
|
int32_t HALSIM_RegisterCanSendMessageCallback(
|
||||||
HAL_CAN_SendMessageCallback callback, void* param) {
|
HAL_CAN_SendMessageCallback callback, void* param) {
|
||||||
return SimCanData.RegisterSendMessageCallback(callback, param);
|
return SimCanData->RegisterSendMessageCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanSendMessageCallback(int32_t uid) {
|
void HALSIM_CancelCanSendMessageCallback(int32_t uid) {
|
||||||
SimCanData.CancelSendMessageCallback(uid);
|
SimCanData->CancelSendMessageCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanReceiveMessageCallback(
|
int32_t HALSIM_RegisterCanReceiveMessageCallback(
|
||||||
HAL_CAN_ReceiveMessageCallback callback, void* param) {
|
HAL_CAN_ReceiveMessageCallback callback, void* param) {
|
||||||
return SimCanData.RegisterReceiveMessageCallback(callback, param);
|
return SimCanData->RegisterReceiveMessageCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanReceiveMessageCallback(int32_t uid) {
|
void HALSIM_CancelCanReceiveMessageCallback(int32_t uid) {
|
||||||
SimCanData.CancelReceiveMessageCallback(uid);
|
SimCanData->CancelReceiveMessageCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanOpenStreamCallback(
|
int32_t HALSIM_RegisterCanOpenStreamCallback(
|
||||||
HAL_CAN_OpenStreamSessionCallback callback, void* param) {
|
HAL_CAN_OpenStreamSessionCallback callback, void* param) {
|
||||||
return SimCanData.RegisterOpenStreamCallback(callback, param);
|
return SimCanData->RegisterOpenStreamCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanOpenStreamCallback(int32_t uid) {
|
void HALSIM_CancelCanOpenStreamCallback(int32_t uid) {
|
||||||
SimCanData.CancelOpenStreamCallback(uid);
|
SimCanData->CancelOpenStreamCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanCloseStreamCallback(
|
int32_t HALSIM_RegisterCanCloseStreamCallback(
|
||||||
HAL_CAN_CloseStreamSessionCallback callback, void* param) {
|
HAL_CAN_CloseStreamSessionCallback callback, void* param) {
|
||||||
return SimCanData.RegisterCloseStreamCallback(callback, param);
|
return SimCanData->RegisterCloseStreamCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanCloseStreamCallback(int32_t uid) {
|
void HALSIM_CancelCanCloseStreamCallback(int32_t uid) {
|
||||||
SimCanData.CancelCloseStreamCallback(uid);
|
SimCanData->CancelCloseStreamCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanReadStreamCallback(
|
int32_t HALSIM_RegisterCanReadStreamCallback(
|
||||||
HAL_CAN_ReadStreamSessionCallback callback, void* param) {
|
HAL_CAN_ReadStreamSessionCallback callback, void* param) {
|
||||||
return SimCanData.RegisterReadStreamCallback(callback, param);
|
return SimCanData->RegisterReadStreamCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanReadStreamCallback(int32_t uid) {
|
void HALSIM_CancelCanReadStreamCallback(int32_t uid) {
|
||||||
SimCanData.CancelReadStreamCallback(uid);
|
SimCanData->CancelReadStreamCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterCanGetCANStatusCallback(
|
int32_t HALSIM_RegisterCanGetCANStatusCallback(
|
||||||
HAL_CAN_GetCANStatusCallback callback, void* param) {
|
HAL_CAN_GetCANStatusCallback callback, void* param) {
|
||||||
return SimCanData.RegisterGetCANStatusCallback(callback, param);
|
return SimCanData->RegisterGetCANStatusCallback(callback, param);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelCanGetCANStatusCallback(int32_t uid) {
|
void HALSIM_CancelCanGetCANStatusCallback(int32_t uid) {
|
||||||
SimCanData.CancelGetCANStatusCallback(uid);
|
SimCanData->CancelGetCANStatusCallback(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -106,6 +106,6 @@ class CanData {
|
|||||||
std::shared_ptr<CanGetCANStatusListenerVector> m_getCanStatusCallback;
|
std::shared_ptr<CanGetCANStatusListenerVector> m_getCanStatusCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CanData SimCanData;
|
extern CanData* SimCanData;
|
||||||
|
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
DIOData hal::SimDIOData[kNumDigitalChannels];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeDIOData() {
|
||||||
|
static DIOData sdd[kNumDigitalChannels];
|
||||||
|
::hal::SimDIOData = sdd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
DIOData* hal::SimDIOData;
|
||||||
void DIOData::ResetData() {
|
void DIOData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -68,5 +68,5 @@ class DIOData {
|
|||||||
std::atomic<int32_t> m_filterIndex{-1};
|
std::atomic<int32_t> m_filterIndex{-1};
|
||||||
std::shared_ptr<NotifyListenerVector> m_filterIndexCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_filterIndexCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern DIOData SimDIOData[];
|
extern DIOData* SimDIOData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
DigitalPWMData hal::SimDigitalPWMData[kNumDigitalPWMOutputs];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeDigitalPWMData() {
|
||||||
|
static DigitalPWMData sdpd[kNumDigitalPWMOutputs];
|
||||||
|
::hal::SimDigitalPWMData = sdpd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
DigitalPWMData* hal::SimDigitalPWMData;
|
||||||
void DigitalPWMData::ResetData() {
|
void DigitalPWMData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -50,5 +50,5 @@ class DigitalPWMData {
|
|||||||
std::atomic<int32_t> m_pin{0};
|
std::atomic<int32_t> m_pin{0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_pinCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_pinCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern DigitalPWMData SimDigitalPWMData[];
|
extern DigitalPWMData* SimDigitalPWMData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -30,7 +30,16 @@ struct MatchInfoDataStore {
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
DriverStationData hal::SimDriverStationData;
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeDriverStationData() {
|
||||||
|
static DriverStationData dsd;
|
||||||
|
::hal::SimDriverStationData = &dsd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
DriverStationData* hal::SimDriverStationData;
|
||||||
|
|
||||||
DriverStationData::DriverStationData() { ResetData(); }
|
DriverStationData::DriverStationData() { ResetData(); }
|
||||||
|
|
||||||
@@ -455,178 +464,178 @@ void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
|
|||||||
void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
|
void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HALSIM_ResetDriverStationData(void) { SimDriverStationData.ResetData(); }
|
void HALSIM_ResetDriverStationData(void) { SimDriverStationData->ResetData(); }
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationEnabledCallback(HAL_NotifyCallback callback,
|
int32_t HALSIM_RegisterDriverStationEnabledCallback(HAL_NotifyCallback callback,
|
||||||
void* param,
|
void* param,
|
||||||
HAL_Bool initialNotify) {
|
HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterEnabledCallback(callback, param,
|
return SimDriverStationData->RegisterEnabledCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationEnabledCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationEnabledCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelEnabledCallback(uid);
|
SimDriverStationData->CancelEnabledCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationEnabled(void) {
|
HAL_Bool HALSIM_GetDriverStationEnabled(void) {
|
||||||
return SimDriverStationData.GetEnabled();
|
return SimDriverStationData->GetEnabled();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationEnabled(HAL_Bool enabled) {
|
void HALSIM_SetDriverStationEnabled(HAL_Bool enabled) {
|
||||||
SimDriverStationData.SetEnabled(enabled);
|
SimDriverStationData->SetEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationAutonomousCallback(
|
int32_t HALSIM_RegisterDriverStationAutonomousCallback(
|
||||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterAutonomousCallback(callback, param,
|
return SimDriverStationData->RegisterAutonomousCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationAutonomousCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationAutonomousCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelAutonomousCallback(uid);
|
SimDriverStationData->CancelAutonomousCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationAutonomous(void) {
|
HAL_Bool HALSIM_GetDriverStationAutonomous(void) {
|
||||||
return SimDriverStationData.GetAutonomous();
|
return SimDriverStationData->GetAutonomous();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationAutonomous(HAL_Bool autonomous) {
|
void HALSIM_SetDriverStationAutonomous(HAL_Bool autonomous) {
|
||||||
SimDriverStationData.SetAutonomous(autonomous);
|
SimDriverStationData->SetAutonomous(autonomous);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationTestCallback(HAL_NotifyCallback callback,
|
int32_t HALSIM_RegisterDriverStationTestCallback(HAL_NotifyCallback callback,
|
||||||
void* param,
|
void* param,
|
||||||
HAL_Bool initialNotify) {
|
HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterTestCallback(callback, param,
|
return SimDriverStationData->RegisterTestCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationTestCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationTestCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelTestCallback(uid);
|
SimDriverStationData->CancelTestCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationTest(void) {
|
HAL_Bool HALSIM_GetDriverStationTest(void) {
|
||||||
return SimDriverStationData.GetTest();
|
return SimDriverStationData->GetTest();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationTest(HAL_Bool test) {
|
void HALSIM_SetDriverStationTest(HAL_Bool test) {
|
||||||
SimDriverStationData.SetTest(test);
|
SimDriverStationData->SetTest(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationEStopCallback(HAL_NotifyCallback callback,
|
int32_t HALSIM_RegisterDriverStationEStopCallback(HAL_NotifyCallback callback,
|
||||||
void* param,
|
void* param,
|
||||||
HAL_Bool initialNotify) {
|
HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterEStopCallback(callback, param,
|
return SimDriverStationData->RegisterEStopCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationEStopCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationEStopCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelEStopCallback(uid);
|
SimDriverStationData->CancelEStopCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationEStop(void) {
|
HAL_Bool HALSIM_GetDriverStationEStop(void) {
|
||||||
return SimDriverStationData.GetEStop();
|
return SimDriverStationData->GetEStop();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationEStop(HAL_Bool eStop) {
|
void HALSIM_SetDriverStationEStop(HAL_Bool eStop) {
|
||||||
SimDriverStationData.SetEStop(eStop);
|
SimDriverStationData->SetEStop(eStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationFmsAttachedCallback(
|
int32_t HALSIM_RegisterDriverStationFmsAttachedCallback(
|
||||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterFmsAttachedCallback(callback, param,
|
return SimDriverStationData->RegisterFmsAttachedCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationFmsAttachedCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationFmsAttachedCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelFmsAttachedCallback(uid);
|
SimDriverStationData->CancelFmsAttachedCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationFmsAttached(void) {
|
HAL_Bool HALSIM_GetDriverStationFmsAttached(void) {
|
||||||
return SimDriverStationData.GetFmsAttached();
|
return SimDriverStationData->GetFmsAttached();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationFmsAttached(HAL_Bool fmsAttached) {
|
void HALSIM_SetDriverStationFmsAttached(HAL_Bool fmsAttached) {
|
||||||
SimDriverStationData.SetFmsAttached(fmsAttached);
|
SimDriverStationData->SetFmsAttached(fmsAttached);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationDsAttachedCallback(
|
int32_t HALSIM_RegisterDriverStationDsAttachedCallback(
|
||||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterDsAttachedCallback(callback, param,
|
return SimDriverStationData->RegisterDsAttachedCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationDsAttachedCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationDsAttachedCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelDsAttachedCallback(uid);
|
SimDriverStationData->CancelDsAttachedCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_Bool HALSIM_GetDriverStationDsAttached(void) {
|
HAL_Bool HALSIM_GetDriverStationDsAttached(void) {
|
||||||
return SimDriverStationData.GetDsAttached();
|
return SimDriverStationData->GetDsAttached();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationDsAttached(HAL_Bool dsAttached) {
|
void HALSIM_SetDriverStationDsAttached(HAL_Bool dsAttached) {
|
||||||
SimDriverStationData.SetDsAttached(dsAttached);
|
SimDriverStationData->SetDsAttached(dsAttached);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationAllianceStationIdCallback(
|
int32_t HALSIM_RegisterDriverStationAllianceStationIdCallback(
|
||||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterAllianceStationIdCallback(callback, param,
|
return SimDriverStationData->RegisterAllianceStationIdCallback(
|
||||||
initialNotify);
|
callback, param, initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationAllianceStationIdCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationAllianceStationIdCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelAllianceStationIdCallback(uid);
|
SimDriverStationData->CancelAllianceStationIdCallback(uid);
|
||||||
}
|
}
|
||||||
HAL_AllianceStationID HALSIM_GetDriverStationAllianceStationId(void) {
|
HAL_AllianceStationID HALSIM_GetDriverStationAllianceStationId(void) {
|
||||||
return SimDriverStationData.GetAllianceStationId();
|
return SimDriverStationData->GetAllianceStationId();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationAllianceStationId(
|
void HALSIM_SetDriverStationAllianceStationId(
|
||||||
HAL_AllianceStationID allianceStationId) {
|
HAL_AllianceStationID allianceStationId) {
|
||||||
SimDriverStationData.SetAllianceStationId(allianceStationId);
|
SimDriverStationData->SetAllianceStationId(allianceStationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HALSIM_RegisterDriverStationMatchTimeCallback(
|
int32_t HALSIM_RegisterDriverStationMatchTimeCallback(
|
||||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) {
|
||||||
return SimDriverStationData.RegisterMatchTimeCallback(callback, param,
|
return SimDriverStationData->RegisterMatchTimeCallback(callback, param,
|
||||||
initialNotify);
|
initialNotify);
|
||||||
}
|
}
|
||||||
void HALSIM_CancelDriverStationMatchTimeCallback(int32_t uid) {
|
void HALSIM_CancelDriverStationMatchTimeCallback(int32_t uid) {
|
||||||
SimDriverStationData.CancelMatchTimeCallback(uid);
|
SimDriverStationData->CancelMatchTimeCallback(uid);
|
||||||
}
|
}
|
||||||
double HALSIM_GetDriverStationMatchTime(void) {
|
double HALSIM_GetDriverStationMatchTime(void) {
|
||||||
return SimDriverStationData.GetMatchTime();
|
return SimDriverStationData->GetMatchTime();
|
||||||
}
|
}
|
||||||
void HALSIM_SetDriverStationMatchTime(double matchTime) {
|
void HALSIM_SetDriverStationMatchTime(double matchTime) {
|
||||||
SimDriverStationData.SetMatchTime(matchTime);
|
SimDriverStationData->SetMatchTime(matchTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes) {
|
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes) {
|
||||||
SimDriverStationData.SetJoystickAxes(joystickNum, axes);
|
SimDriverStationData->SetJoystickAxes(joystickNum, axes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs) {
|
void HALSIM_SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs) {
|
||||||
SimDriverStationData.SetJoystickPOVs(joystickNum, povs);
|
SimDriverStationData->SetJoystickPOVs(joystickNum, povs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_SetJoystickButtons(int32_t joystickNum,
|
void HALSIM_SetJoystickButtons(int32_t joystickNum,
|
||||||
const HAL_JoystickButtons* buttons) {
|
const HAL_JoystickButtons* buttons) {
|
||||||
SimDriverStationData.SetJoystickButtons(joystickNum, buttons);
|
SimDriverStationData->SetJoystickButtons(joystickNum, buttons);
|
||||||
}
|
}
|
||||||
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
|
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
|
||||||
const HAL_JoystickDescriptor* descriptor) {
|
const HAL_JoystickDescriptor* descriptor) {
|
||||||
SimDriverStationData.SetJoystickDescriptor(joystickNum, descriptor);
|
SimDriverStationData->SetJoystickDescriptor(joystickNum, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||||
int32_t* leftRumble, int32_t* rightRumble) {
|
int32_t* leftRumble, int32_t* rightRumble) {
|
||||||
SimDriverStationData.GetJoystickOutputs(joystickNum, outputs, leftRumble,
|
SimDriverStationData->GetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||||
rightRumble);
|
rightRumble);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {
|
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {
|
||||||
SimDriverStationData.SetMatchInfo(info);
|
SimDriverStationData->SetMatchInfo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_NotifyDriverStationNewData(void) {
|
void HALSIM_NotifyDriverStationNewData(void) {
|
||||||
SimDriverStationData.NotifyNewData();
|
SimDriverStationData->NotifyNewData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
|
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
|
||||||
void* param,
|
void* param,
|
||||||
HAL_Bool initialNotify) {
|
HAL_Bool initialNotify) {
|
||||||
SimDriverStationData.RegisterEnabledCallback(callback, param, initialNotify);
|
SimDriverStationData->RegisterEnabledCallback(callback, param, initialNotify);
|
||||||
SimDriverStationData.RegisterAutonomousCallback(callback, param,
|
SimDriverStationData->RegisterAutonomousCallback(callback, param,
|
||||||
initialNotify);
|
|
||||||
SimDriverStationData.RegisterTestCallback(callback, param, initialNotify);
|
|
||||||
SimDriverStationData.RegisterEStopCallback(callback, param, initialNotify);
|
|
||||||
SimDriverStationData.RegisterFmsAttachedCallback(callback, param,
|
|
||||||
initialNotify);
|
initialNotify);
|
||||||
SimDriverStationData.RegisterDsAttachedCallback(callback, param,
|
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);
|
initialNotify);
|
||||||
SimDriverStationData.RegisterAllianceStationIdCallback(callback, param,
|
|
||||||
initialNotify);
|
|
||||||
SimDriverStationData.RegisterMatchTimeCallback(callback, param,
|
|
||||||
initialNotify);
|
|
||||||
}
|
}
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -135,5 +135,5 @@ class DriverStationData {
|
|||||||
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
|
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
|
||||||
std::unique_ptr<MatchInfoDataStore> m_matchInfo;
|
std::unique_ptr<MatchInfoDataStore> m_matchInfo;
|
||||||
};
|
};
|
||||||
extern DriverStationData SimDriverStationData;
|
extern DriverStationData* SimDriverStationData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
EncoderData hal::SimEncoderData[kNumEncoders];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeEncoderData() {
|
||||||
|
static EncoderData sed[kNumEncoders];
|
||||||
|
::hal::SimEncoderData = sed;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
EncoderData* hal::SimEncoderData;
|
||||||
void EncoderData::ResetData() {
|
void EncoderData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -96,5 +96,5 @@ class EncoderData {
|
|||||||
std::atomic<int32_t> m_samplesToAverage{0};
|
std::atomic<int32_t> m_samplesToAverage{0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_samplesToAverageCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_samplesToAverageCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern EncoderData SimEncoderData[];
|
extern EncoderData* SimEncoderData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -13,7 +13,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
I2CData hal::SimI2CData[2];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeI2CData() {
|
||||||
|
static I2CData sid[2];
|
||||||
|
::hal::SimI2CData = sid;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
I2CData* hal::SimI2CData;
|
||||||
|
|
||||||
void I2CData::ResetData() {
|
void I2CData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
|
|||||||
@@ -49,5 +49,5 @@ class I2CData {
|
|||||||
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
|
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
|
||||||
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
|
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern I2CData SimI2CData[];
|
extern I2CData* SimI2CData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
PCMData hal::SimPCMData[kNumPCMModules];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePCMData() {
|
||||||
|
static PCMData spd[kNumPCMModules];
|
||||||
|
::hal::SimPCMData = spd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
PCMData* hal::SimPCMData;
|
||||||
void PCMData::ResetData() {
|
void PCMData::ResetData() {
|
||||||
for (int i = 0; i < kNumSolenoidChannels; i++) {
|
for (int i = 0; i < kNumSolenoidChannels; i++) {
|
||||||
m_solenoidInitialized[i] = false;
|
m_solenoidInitialized[i] = false;
|
||||||
|
|||||||
@@ -96,5 +96,5 @@ class PCMData {
|
|||||||
std::atomic<double> m_compressorCurrent{0.0};
|
std::atomic<double> m_compressorCurrent{0.0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_compressorCurrentCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_compressorCurrentCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern PCMData SimPCMData[];
|
extern PCMData* SimPCMData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
PDPData hal::SimPDPData[kNumPDPModules];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePDPData() {
|
||||||
|
static PDPData spd[kNumPDPModules];
|
||||||
|
::hal::SimPDPData = spd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
PDPData* hal::SimPDPData;
|
||||||
void PDPData::ResetData() {
|
void PDPData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -60,5 +60,5 @@ class PDPData {
|
|||||||
std::atomic<double> m_current[kNumPDPChannels];
|
std::atomic<double> m_current[kNumPDPChannels];
|
||||||
std::shared_ptr<NotifyListenerVector> m_currentCallbacks[kNumPDPChannels];
|
std::shared_ptr<NotifyListenerVector> m_currentCallbacks[kNumPDPChannels];
|
||||||
};
|
};
|
||||||
extern PDPData SimPDPData[];
|
extern PDPData* SimPDPData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
PWMData hal::SimPWMData[kNumPWMChannels];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePWMData() {
|
||||||
|
static PWMData spd[kNumPWMChannels];
|
||||||
|
::hal::SimPWMData = spd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
PWMData* hal::SimPWMData;
|
||||||
void PWMData::ResetData() {
|
void PWMData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_initializedCallbacks = nullptr;
|
m_initializedCallbacks = nullptr;
|
||||||
|
|||||||
@@ -77,5 +77,5 @@ class PWMData {
|
|||||||
std::atomic<HAL_Bool> m_zeroLatch{false};
|
std::atomic<HAL_Bool> m_zeroLatch{false};
|
||||||
std::shared_ptr<NotifyListenerVector> m_zeroLatchCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_zeroLatchCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern PWMData SimPWMData[];
|
extern PWMData* SimPWMData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
RelayData hal::SimRelayData[kNumRelayHeaders];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeRelayData() {
|
||||||
|
static RelayData srd[kNumRelayHeaders];
|
||||||
|
::hal::SimRelayData = srd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
RelayData* hal::SimRelayData;
|
||||||
void RelayData::ResetData() {
|
void RelayData::ResetData() {
|
||||||
m_initializedForward = false;
|
m_initializedForward = false;
|
||||||
m_initializedForwardCallbacks = nullptr;
|
m_initializedForwardCallbacks = nullptr;
|
||||||
|
|||||||
@@ -61,5 +61,5 @@ class RelayData {
|
|||||||
std::atomic<HAL_Bool> m_reverse{false};
|
std::atomic<HAL_Bool> m_reverse{false};
|
||||||
std::shared_ptr<NotifyListenerVector> m_reverseCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_reverseCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern RelayData SimRelayData[];
|
extern RelayData* SimRelayData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
RoboRioData hal::SimRoboRioData[1];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeRoboRioData() {
|
||||||
|
static RoboRioData srrd[1];
|
||||||
|
::hal::SimRoboRioData = srrd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
RoboRioData* hal::SimRoboRioData;
|
||||||
void RoboRioData::ResetData() {
|
void RoboRioData::ResetData() {
|
||||||
m_fPGAButton = false;
|
m_fPGAButton = false;
|
||||||
m_fPGAButtonCallbacks = nullptr;
|
m_fPGAButtonCallbacks = nullptr;
|
||||||
|
|||||||
@@ -158,5 +158,5 @@ class RoboRioData {
|
|||||||
std::atomic<int32_t> m_userFaults3V3{0};
|
std::atomic<int32_t> m_userFaults3V3{0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_userFaults3V3Callbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_userFaults3V3Callbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern RoboRioData SimRoboRioData[];
|
extern RoboRioData* SimRoboRioData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -11,7 +11,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
SPIAccelerometerData hal::SimSPIAccelerometerData[5];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeSPIAccelerometerData() {
|
||||||
|
static SPIAccelerometerData ssad[5];
|
||||||
|
::hal::SimSPIAccelerometerData = ssad;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
SPIAccelerometerData* hal::SimSPIAccelerometerData;
|
||||||
void SPIAccelerometerData::ResetData() {
|
void SPIAccelerometerData::ResetData() {
|
||||||
m_active = false;
|
m_active = false;
|
||||||
m_activeCallbacks = nullptr;
|
m_activeCallbacks = nullptr;
|
||||||
|
|||||||
@@ -68,5 +68,5 @@ class SPIAccelerometerData {
|
|||||||
std::atomic<double> m_z{0.0};
|
std::atomic<double> m_z{0.0};
|
||||||
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
|
||||||
};
|
};
|
||||||
extern SPIAccelerometerData SimSPIAccelerometerData[];
|
extern SPIAccelerometerData* SimSPIAccelerometerData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -13,8 +13,16 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
SPIData hal::SimSPIData[5];
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeSPIData() {
|
||||||
|
static SPIData ssd[5];
|
||||||
|
::hal::SimSPIData = ssd;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
|
SPIData* hal::SimSPIData;
|
||||||
void SPIData::ResetData() {
|
void SPIData::ResetData() {
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
m_accumulatorValue = 0;
|
m_accumulatorValue = 0;
|
||||||
|
|||||||
@@ -65,5 +65,5 @@ class SPIData {
|
|||||||
std::shared_ptr<NotifyListenerVector> m_resetAccumulatorCallback = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_resetAccumulatorCallback = nullptr;
|
||||||
std::shared_ptr<NotifyListenerVector> m_setAccumulatorCallback = nullptr;
|
std::shared_ptr<NotifyListenerVector> m_setAccumulatorCallback = nullptr;
|
||||||
};
|
};
|
||||||
extern SPIData SimSPIData[];
|
extern SPIData* SimSPIData;
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ static std::atomic<bool> programStarted{false};
|
|||||||
|
|
||||||
static std::atomic<uint64_t> programStartTime{0};
|
static std::atomic<uint64_t> programStartTime{0};
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeMockHooks() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
void RestartTiming() { programStartTime = wpi::Now(); }
|
void RestartTiming() { programStartTime = wpi::Now(); }
|
||||||
|
|
||||||
|
|||||||
@@ -47,13 +47,22 @@ class NotifierHandleContainer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static NotifierHandleContainer notifierHandles;
|
static NotifierHandleContainer* notifierHandles;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeNotifier() {
|
||||||
|
static NotifierHandleContainer nH;
|
||||||
|
notifierHandles = &nH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||||
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
|
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
|
||||||
HAL_NotifierHandle handle = notifierHandles.Allocate(notifier);
|
HAL_NotifierHandle handle = notifierHandles->Allocate(notifier);
|
||||||
if (handle == HAL_kInvalidHandle) {
|
if (handle == HAL_kInvalidHandle) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -62,7 +71,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||||
auto notifier = notifierHandles.Get(notifierHandle);
|
auto notifier = notifierHandles->Get(notifierHandle);
|
||||||
if (!notifier) return;
|
if (!notifier) return;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -74,7 +83,7 @@ void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||||
auto notifier = notifierHandles.Free(notifierHandle);
|
auto notifier = notifierHandles->Free(notifierHandle);
|
||||||
if (!notifier) return;
|
if (!notifier) return;
|
||||||
|
|
||||||
// Just in case HAL_StopNotifier() wasn't called...
|
// Just in case HAL_StopNotifier() wasn't called...
|
||||||
@@ -88,7 +97,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
|||||||
|
|
||||||
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||||
uint64_t triggerTime, int32_t* status) {
|
uint64_t triggerTime, int32_t* status) {
|
||||||
auto notifier = notifierHandles.Get(notifierHandle);
|
auto notifier = notifierHandles->Get(notifierHandle);
|
||||||
if (!notifier) return;
|
if (!notifier) return;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -104,7 +113,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
|||||||
|
|
||||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto notifier = notifierHandles.Get(notifierHandle);
|
auto notifier = notifierHandles->Get(notifierHandle);
|
||||||
if (!notifier) return;
|
if (!notifier) return;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -115,7 +124,7 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
|||||||
|
|
||||||
uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto notifier = notifierHandles.Get(notifierHandle);
|
auto notifier = notifierHandles->Get(notifierHandle);
|
||||||
if (!notifier) return 0;
|
if (!notifier) return 0;
|
||||||
|
|
||||||
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
#include "HAL/SerialPort.h"
|
#include "HAL/SerialPort.h"
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeOSSerialPort() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HAL_InitializeOSSerialPort(HAL_SerialPort port, int32_t* status) {}
|
void HAL_InitializeOSSerialPort(HAL_SerialPort port, int32_t* status) {}
|
||||||
void HAL_SetOSSerialBaudRate(HAL_SerialPort port, int32_t baud,
|
void HAL_SetOSSerialBaudRate(HAL_SerialPort port, int32_t baud,
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePDP() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HAL_InitializePDP(int32_t module, int32_t* status) {
|
void HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||||
SimPDPData[module].SetInitialized(true);
|
SimPDPData[module].SetInitialized(true);
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePWM() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
||||||
@@ -36,12 +42,12 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto handle =
|
auto handle =
|
||||||
digitalChannelHandles.Allocate(channel, HAL_HandleEnum::PWM, status);
|
digitalChannelHandles->Allocate(channel, HAL_HandleEnum::PWM, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
auto port = digitalChannelHandles.Get(handle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) { // would only occur on thread issue.
|
if (port == nullptr) { // would only occur on thread issue.
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -54,7 +60,7 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -62,7 +68,7 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
|
|
||||||
SimPWMData[port->channel].SetInitialized(false);
|
SimPWMData[port->channel].SetInitialized(false);
|
||||||
|
|
||||||
digitalChannelHandles.Free(pwmPortHandle, HAL_HandleEnum::PWM);
|
digitalChannelHandles->Free(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Bool HAL_CheckPWMChannel(int32_t channel) {
|
HAL_Bool HAL_CheckPWMChannel(int32_t channel) {
|
||||||
@@ -72,7 +78,7 @@ HAL_Bool HAL_CheckPWMChannel(int32_t channel) {
|
|||||||
void HAL_SetPWMConfig(HAL_DigitalHandle pwmPortHandle, double max,
|
void HAL_SetPWMConfig(HAL_DigitalHandle pwmPortHandle, double max,
|
||||||
double deadbandMax, double center, double deadbandMin,
|
double deadbandMax, double center, double deadbandMin,
|
||||||
double min, int32_t* status) {
|
double min, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -106,7 +112,7 @@ void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t maxPwm,
|
|||||||
int32_t deadbandMaxPwm, int32_t centerPwm,
|
int32_t deadbandMaxPwm, int32_t centerPwm,
|
||||||
int32_t deadbandMinPwm, int32_t minPwm,
|
int32_t deadbandMinPwm, int32_t minPwm,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -123,7 +129,7 @@ void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t* maxPwm,
|
|||||||
int32_t* deadbandMaxPwm, int32_t* centerPwm,
|
int32_t* deadbandMaxPwm, int32_t* centerPwm,
|
||||||
int32_t* deadbandMinPwm, int32_t* minPwm,
|
int32_t* deadbandMinPwm, int32_t* minPwm,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -137,7 +143,7 @@ void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t* maxPwm,
|
|||||||
|
|
||||||
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
||||||
HAL_Bool eliminateDeadband, int32_t* status) {
|
HAL_Bool eliminateDeadband, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -147,7 +153,7 @@ void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
|||||||
|
|
||||||
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -165,7 +171,7 @@ HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
|
|||||||
*/
|
*/
|
||||||
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
|
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -185,7 +191,7 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
|
|||||||
*/
|
*/
|
||||||
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
|
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -215,7 +221,7 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
|
|||||||
*/
|
*/
|
||||||
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
|
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -235,7 +241,7 @@ void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -252,7 +258,7 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
* @return The raw PWM value.
|
* @return The raw PWM value.
|
||||||
*/
|
*/
|
||||||
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -268,7 +274,7 @@ int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
* @return The scaled PWM value.
|
* @return The scaled PWM value.
|
||||||
*/
|
*/
|
||||||
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -291,7 +297,7 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
* @return The scaled PWM value.
|
* @return The scaled PWM value.
|
||||||
*/
|
*/
|
||||||
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -308,7 +314,7 @@ double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -326,7 +332,7 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
|
|||||||
*/
|
*/
|
||||||
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
|
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePorts() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int32_t HAL_GetNumAccumulators(void) { return kNumAccumulators; }
|
int32_t HAL_GetNumAccumulators(void) { return kNumAccumulators; }
|
||||||
int32_t HAL_GetNumAnalogTriggers(void) { return kNumAnalogTriggers; }
|
int32_t HAL_GetNumAnalogTriggers(void) { return kNumAnalogTriggers; }
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializePower() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
// TODO: Fix the naming in here
|
// TODO: Fix the naming in here
|
||||||
extern "C" {
|
extern "C" {
|
||||||
double HAL_GetVinVoltage(int32_t* status) {
|
double HAL_GetVinVoltage(int32_t* status) {
|
||||||
|
|||||||
@@ -21,8 +21,18 @@ struct Relay {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
||||||
HAL_HandleEnum::Relay>
|
HAL_HandleEnum::Relay>* relayHandles;
|
||||||
relayHandles;
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeRelay() {
|
||||||
|
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
||||||
|
HAL_HandleEnum::Relay>
|
||||||
|
rH;
|
||||||
|
relayHandles = &rH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
||||||
@@ -37,12 +47,12 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
|||||||
|
|
||||||
if (!fwd) channel += kNumRelayHeaders; // add 4 to reverse channels
|
if (!fwd) channel += kNumRelayHeaders; // add 4 to reverse channels
|
||||||
|
|
||||||
auto handle = relayHandles.Allocate(channel, status);
|
auto handle = relayHandles->Allocate(channel, status);
|
||||||
|
|
||||||
if (*status != 0)
|
if (*status != 0)
|
||||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||||
|
|
||||||
auto port = relayHandles.Get(handle);
|
auto port = relayHandles->Get(handle);
|
||||||
if (port == nullptr) { // would only occur on thread issue.
|
if (port == nullptr) { // would only occur on thread issue.
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -66,8 +76,8 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
|
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
|
||||||
auto port = relayHandles.Get(relayPortHandle);
|
auto port = relayHandles->Get(relayPortHandle);
|
||||||
relayHandles.Free(relayPortHandle);
|
relayHandles->Free(relayPortHandle);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
if (port->fwd)
|
if (port->fwd)
|
||||||
SimRelayData[port->channel].SetInitializedForward(false);
|
SimRelayData[port->channel].SetInitializedForward(false);
|
||||||
@@ -84,7 +94,7 @@ HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
|
|||||||
|
|
||||||
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = relayHandles.Get(relayPortHandle);
|
auto port = relayHandles->Get(relayPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
@@ -96,7 +106,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
|||||||
}
|
}
|
||||||
|
|
||||||
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
|
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
|
||||||
auto port = relayHandles.Get(relayPortHandle);
|
auto port = relayHandles->Get(relayPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
using namespace hal;
|
using namespace hal;
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeSPI() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||||
SimSPIData[port].SetInitialized(true);
|
SimSPIData[port].SetInitialized(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
#include "HAL/SerialPort.h"
|
#include "HAL/SerialPort.h"
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeSerialPort() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void HAL_InitializeSerialPort(HAL_SerialPort port, int32_t* status) {}
|
void HAL_InitializeSerialPort(HAL_SerialPort port, int32_t* status) {}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,19 @@ using namespace hal;
|
|||||||
|
|
||||||
static IndexedHandleResource<HAL_SolenoidHandle, Solenoid,
|
static IndexedHandleResource<HAL_SolenoidHandle, Solenoid,
|
||||||
kNumPCMModules * kNumSolenoidChannels,
|
kNumPCMModules * kNumSolenoidChannels,
|
||||||
HAL_HandleEnum::Solenoid>
|
HAL_HandleEnum::Solenoid>* solenoidHandles;
|
||||||
solenoidHandles;
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeSolenoid() {
|
||||||
|
static IndexedHandleResource<HAL_SolenoidHandle, Solenoid,
|
||||||
|
kNumPCMModules * kNumSolenoidChannels,
|
||||||
|
HAL_HandleEnum::Solenoid>
|
||||||
|
sH;
|
||||||
|
solenoidHandles = &sH;
|
||||||
|
}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
|
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
|
||||||
@@ -47,13 +58,13 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
|
|||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto handle =
|
auto handle = solenoidHandles->Allocate(
|
||||||
solenoidHandles.Allocate(module * kNumSolenoidChannels + channel, status);
|
module * kNumSolenoidChannels + channel, status);
|
||||||
if (handle == HAL_kInvalidHandle) { // out of resources
|
if (handle == HAL_kInvalidHandle) { // out of resources
|
||||||
*status = NO_AVAILABLE_RESOURCES;
|
*status = NO_AVAILABLE_RESOURCES;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
}
|
}
|
||||||
auto solenoidPort = solenoidHandles.Get(handle);
|
auto solenoidPort = solenoidHandles->Get(handle);
|
||||||
if (solenoidPort == nullptr) { // would only occur on thread issues
|
if (solenoidPort == nullptr) { // would only occur on thread issues
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return HAL_kInvalidHandle;
|
return HAL_kInvalidHandle;
|
||||||
@@ -66,9 +77,9 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle) {
|
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle) {
|
||||||
auto port = solenoidHandles.Get(solenoidPortHandle);
|
auto port = solenoidHandles->Get(solenoidPortHandle);
|
||||||
if (port == nullptr) return;
|
if (port == nullptr) return;
|
||||||
solenoidHandles.Free(solenoidPortHandle);
|
solenoidHandles->Free(solenoidPortHandle);
|
||||||
HALSIM_SetPCMSolenoidInitialized(port->module, port->channel, false);
|
HALSIM_SetPCMSolenoidInitialized(port->module, port->channel, false);
|
||||||
}
|
}
|
||||||
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
|
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
|
||||||
@@ -80,7 +91,7 @@ HAL_Bool HAL_CheckSolenoidChannel(int32_t channel) {
|
|||||||
}
|
}
|
||||||
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle,
|
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = solenoidHandles.Get(solenoidPortHandle);
|
auto port = solenoidHandles->Get(solenoidPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
@@ -99,7 +110,7 @@ int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status) {
|
|||||||
}
|
}
|
||||||
void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
|
void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
auto port = solenoidHandles.Get(solenoidPortHandle);
|
auto port = solenoidHandles->Get(solenoidPortHandle);
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
*status = HAL_HANDLE_ERROR;
|
*status = HAL_HANDLE_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
#include "HAL/Threads.h"
|
#include "HAL/Threads.h"
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace init {
|
||||||
|
void InitializeThreads() {}
|
||||||
|
} // namespace init
|
||||||
|
} // namespace hal
|
||||||
|
|
||||||
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
|
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
|
||||||
int32_t* status) {
|
int32_t* status) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
/* the project. */
|
/* the project. */
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "HAL/HAL.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
HAL_Initialize(500, 0);
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
int ret = RUN_ALL_TESTS();
|
int ret = RUN_ALL_TESTS();
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -5,9 +5,12 @@
|
|||||||
/* the project. */
|
/* the project. */
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <HAL/HAL.h>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
HAL_Initialize(500, 0);
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
int ret = RUN_ALL_TESTS();
|
int ret = RUN_ALL_TESTS();
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.google.common.base.Stopwatch;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import edu.wpi.first.wpilibj.hal.HAL;
|
||||||
import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
|
import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +26,7 @@ public final class UnitTestUtility {
|
|||||||
* Sets up the base system WPILib so that it does not rely on hardware.
|
* Sets up the base system WPILib so that it does not rely on hardware.
|
||||||
*/
|
*/
|
||||||
public static void setupMockBase() {
|
public static void setupMockBase() {
|
||||||
|
HAL.initialize(500, 0);
|
||||||
try {
|
try {
|
||||||
// Check to see if this has been setup
|
// Check to see if this has been setup
|
||||||
Timer.getFPGATimestamp();
|
Timer.getFPGATimestamp();
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ package edu.wpi.first.wpilibj.can;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import edu.wpi.first.wpilibj.hal.HAL;
|
||||||
|
|
||||||
public class CANStatusTest {
|
public class CANStatusTest {
|
||||||
@Test
|
@Test
|
||||||
public void canStatusGetDoesntThrow() {
|
public void canStatusGetDoesntThrow() {
|
||||||
|
HAL.initialize(500, 0);
|
||||||
CANStatus status = new CANStatus();
|
CANStatus status = new CANStatus();
|
||||||
CANJNI.GetCANStatus(status);
|
CANJNI.GetCANStatus(status);
|
||||||
// Nothing we can assert, so just make sure it didn't throw.
|
// Nothing we can assert, so just make sure it didn't throw.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class JNITest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jniHalLinkTest() {
|
public void jniHalLinkTest() {
|
||||||
|
HAL.initialize(500, 0);
|
||||||
// Test to verify that the JNI test link works correctly.
|
// Test to verify that the JNI test link works correctly.
|
||||||
HALUtil.getHALRuntimeType();
|
HALUtil.getHALRuntimeType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.junit.Test;
|
|||||||
public class MatchInfoDataTest {
|
public class MatchInfoDataTest {
|
||||||
@Test
|
@Test
|
||||||
public void matchInfoDataDoesNotThrow() {
|
public void matchInfoDataDoesNotThrow() {
|
||||||
|
HAL.initialize(500, 0);
|
||||||
MatchInfoData data = new MatchInfoData();
|
MatchInfoData data = new MatchInfoData();
|
||||||
HAL.getMatchInfo(data);
|
HAL.getMatchInfo(data);
|
||||||
// Nothing we can assert, so just make sure it didn't throw.
|
// Nothing we can assert, so just make sure it didn't throw.
|
||||||
|
|||||||
Reference in New Issue
Block a user