Compare commits

...

46 Commits

Author SHA1 Message Date
Thad House
cd1dbb1e3a Adds a const buffer listener (#742)
Replaces need for const_cast in SPI and I2C functions
2017-11-17 10:01:49 -08:00
Peter Johnson
a20474bfc7 Update sensors to not use direct byte buffers. 2017-11-17 09:36:57 -08:00
Peter Johnson
479d0beb5a SerialPort: Use byte[] instead of ByteBuffer in JNI. 2017-11-17 09:36:57 -08:00
Peter Johnson
b93aa176d6 AnalogInput: Remove byte buffer usage. 2017-11-17 09:36:57 -08:00
Peter Johnson
9021b37fd2 I2C: Provide byte[] JNI interfaces.
This avoids a direct byte buffer allocation on every read/write/transaction
on the byte[] variants.

Changes HAL I2C interfaces to use const for dataToSend.
2017-11-17 09:36:57 -08:00
Peter Johnson
6307d41002 SPI: Provide byte[] JNI interfaces.
This avoids a direct byte buffer allocation on every read/write/transaction
for the byte[] variants.

Also change spiGetAccumulatorOutput() to directly set the AccumulatorResult
object, avoiding a ByteBuffer allocation.

Changes HAL SPI interfaces to use const for dataToSend.

Fixes #733.
2017-11-17 09:36:57 -08:00
Peter Johnson
df7c1389de Remove ni-libraries libi2c and libspi. 2017-11-16 23:01:28 -08:00
Peter Johnson
6accc31ee7 HAL: implement I2C and SPI directly instead of using i2clib and spilib.
This reduces library dependencies, improves error handling, and makes
future enhancements easier.
2017-11-16 23:01:28 -08:00
Thad House
f56ec10bcf Only return lower 32 bits of FPGA time (#741)
Works around an NI bug in image 10.
2017-11-16 20:52:50 -08:00
Tyler Veness
e5e6d6a193 Ran formatter based on styleguide#95 (#737) 2017-11-16 01:05:20 -08:00
Tyler Veness
c663d7cd16 Reflowed comments and removed commented out code (#735) 2017-11-16 00:33:51 -08:00
Tyler Veness
1e8d18b328 Upgrade Travis CI Python version to 3.5 (#740) 2017-11-16 00:19:16 -08:00
Peter Johnson
c2d95db3ab Fix PreferencesTest. (#739) 2017-11-15 23:56:17 -08:00
Thad House
dd7563376b Force load OpenCV and cscore libraries on program initialization (#716)
Fixes bugs where Mat's are initialized before anything cscore was
called.
2017-11-14 22:04:53 -08:00
Tyler Veness
14fcf3f2f0 Simplified PIDController integration logic (#645)
A clamp() helper function was written based on C++17's std::clamp().
2017-11-13 22:28:55 -08:00
Peter Johnson
020ee227d2 Move ctre headers to hal/src so they aren't user-visible. (#728)
Also removes ctre_frames.h entirely since it's not used.

Fixes #683.
2017-11-13 22:23:18 -08:00
Peter Johnson
4d559f3856 Use wpi::mutex instead of std::mutex. (#730)
This uses a priority-aware mutex on Linux platforms.

Fixes #729.
2017-11-13 09:51:48 -08:00
Thad House
35d68d2a34 Adds ability to simulate joysticks and event info (#727)
Thanks @pjreiniger for the initiali implementation and work on this.
2017-11-12 19:33:43 -08:00
Peter Johnson
7007725d9f SerialHelper: Check error_code to prevent infinite loop. (#725) 2017-11-11 22:13:59 -08:00
Tyler Veness
0c83cad70c Upgraded clang-format to 5.0 (#431) 2017-11-11 22:09:51 -08:00
sciencewhiz
0001047b8b Add NidecBrushless to WPILib.h (#724) 2017-11-11 16:35:43 -08:00
Thad House
c885251367 Fixes HALSim_Print build to be the standardized pattern (#721)
Now publishes in zips, and with proper artifacts.

The code files just moved, and no changes.
2017-11-10 19:26:33 -08:00
Tyler Veness
42096fac3f Ran formatter (#722) 2017-11-10 18:29:27 -08:00
sciencewhiz
6be9e69d13 Switch Command Templates to TimedRobot (#719) 2017-11-09 20:08:41 -08:00
Thad House
7bbd13d914 Adds match specific calls to Java and C++ (#720)
Uses caching, matching the joystick calls.
2017-11-09 19:59:29 -08:00
Thad House
2225c4fee2 Fixes warnings for casts in sim interrupt functions (#718) 2017-11-09 14:01:24 -08:00
Tyler Veness
7efab4c43a Replaced ternary operators with if statements (#346)
Instances of the ternary operator were replaced with if statements to make the code base more consistent.
2017-11-08 23:44:03 -08:00
Thad House
c8e44256ef Uses NI provided function for SetOccurDataRef rather then importing the symbol ourselves. (#714) 2017-11-08 23:41:16 -08:00
Peter Johnson
f3cd883c5c Add Nidec Brushless motor. (#705) 2017-11-08 23:40:01 -08:00
Thad House
f34c736fb2 Adds warning prints to native library builds (#710)
Can be disabled with -PskipWarningPrints
2017-11-08 23:14:21 -08:00
Tyler Veness
1276489961 Removed uses of deprecated functions (#709) 2017-11-08 21:29:29 -08:00
Tyler Veness
8b2e656bde Fixed Java velocity PID not calculating result when P = 0 (#717) 2017-11-08 21:28:09 -08:00
Thad House
6e9d1f55c6 Updates image to 2018 v10 image (#713) 2017-11-08 11:26:11 -08:00
Thad House
f4dce9e608 Fixes receive size in Java I2C (#715)
Allows underrun, which matches c++ behavior.

Fixes #711
2017-11-07 18:43:23 -08:00
Thad House
b9aabc71b0 Fixes publishing basenames for examples to make combiner script work. (#712) 2017-11-07 14:54:17 -08:00
Jaci R
0d54772362 Add IDEA plugin to root project (#707) 2017-11-05 19:57:53 -08:00
Tyler Veness
faf134a674 C++ examples no longer use deprecated APIs (#703) 2017-11-05 19:39:47 -08:00
Thad House
c24e755409 Fixes java example publishing and xml file (#706) 2017-11-04 10:09:41 -07:00
Thad House
bee9f1cb17 Adds header task to print out all headers (#704)
Will be used to create a generator for IDE's to get include paths.
2017-11-03 22:50:06 -07:00
Tyler Veness
45d48d6b5a Cleaned up C++ examples (#672) 2017-11-03 13:22:56 -07:00
Peter Johnson
6401aa1fde SerialHelper: Use llvm path functions instead of popen. (#702)
This avoids a fork that causes an out-of-memory error in Java.

Depends on wpilibsuite/wpiutil#43
2017-11-03 12:30:56 -07:00
Thad House
6af4940c22 Adds HAL calls for match data from DS (#691) 2017-11-01 21:58:44 -07:00
Sam Carlberg
237b2df82f Add .type metadata to preferences table (#701)
Allows shuffleboard to automatically discover the type, instead of inflexibly hardcoding it
2017-10-30 21:50:49 -07:00
Peter Johnson
a70687aaec Improve error reporting for the new TCP netconsole. (#700)
Fixes #695.
2017-10-30 21:50:14 -07:00
sciencewhiz
fbfe85568b Fix preferences test (#699) 2017-10-29 21:30:50 -07:00
Tyler Veness
595b1df380 Fixed minimum number of joystick axes (#696) 2017-10-29 17:21:50 -07:00
365 changed files with 4418 additions and 3287 deletions

View File

@@ -5,7 +5,7 @@ AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
@@ -32,12 +32,20 @@ BraceWrapping:
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
@@ -45,7 +53,11 @@ Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
@@ -53,9 +65,12 @@ IncludeCategories:
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -64,6 +79,7 @@ NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
@@ -73,7 +89,9 @@ PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false

2
.gitignore vendored
View File

@@ -12,6 +12,8 @@ test-reports
# IntelliJ
*.iml
*.ipr
*.iws
.idea/
# Created by http://www.gitignore.io

View File

@@ -1,19 +1,26 @@
sudo: false
sudo: true
dist: trusty
language: java
addons:
apt:
sources:
- deadsnakes
- ubuntu-toolchain-r-test
packages:
- g++-6
- python3
- python3-pip
- clang-format-3.8
- python3.5
before_install:
- sudo sh -c 'echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" > /etc/apt/sources.list.d/llvm.list'
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
- sudo apt-get update -q || true
- sudo apt-get install clang-format-5.0 -y
install:
- pip3 install --user wpiformat
- wget https://bootstrap.pypa.io/get-pip.py
- sudo python3.5 get-pip.py
- python3.5 -m pip install --user wpiformat
- mkdir -p $HOME/latest-gcc-symlinks # see travis-ci/travis-ci#3668
- ln -s /usr/bin/g++-6 $HOME/latest-gcc-symlinks/g++
- ln -s /usr/bin/gcc-6 $HOME/latest-gcc-symlinks/gcc
@@ -28,6 +35,6 @@ cache:
- $HOME/.gradle/wrapper/
script:
- wpiformat -y 2017 -clang 3.8
- python3.5 -m wpiformat -y 2017 -clang 5.0
- git --no-pager diff --exit-code HEAD # Ensure formatter made no changes
- ./gradlew --no-daemon --console=plain -PskipAthena :hal:halSimSharedLibrary :wpilibc:wpilibcSharedLibrary :wpilibj:wpilibJNISharedSharedLibrary :wpilibj:jar

View File

@@ -9,13 +9,14 @@ buildscript {
}
}
dependencies {
classpath 'gradle.plugin.edu.wpi.first:native-utils:1.2.12'
classpath 'gradle.plugin.edu.wpi.first:native-utils:1.3.0'
}
}
plugins {
id 'net.ltgt.errorprone' version '0.0.10'
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '2.0'
id 'idea'
}
ext.licenseFile = file("$rootDir/LICENSE.txt")

View File

@@ -8,7 +8,7 @@ def windowsLinkerArgs = [ '/DEBUG:FULL' ]
def windowsReleaseLinkerArgs = [ '/OPT:REF', '/OPT:ICF' ]
def linuxCompilerArgs = ['-std=c++1y', '-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g',
'-Wno-unused-parameter', '-fPIC', '-rdynamic', '-Wno-error=deprecated-declarations', '-pthread']
'-Wno-unused-parameter', '-fPIC', '-rdynamic', '-pthread']
def linuxLinkerArgs = ['-rdynamic', '-pthread']
def linuxReleaseCompilerArgs = ['-O2']
def linuxDebugCompilerArgs = ['-O0']

View File

@@ -202,6 +202,32 @@ model {
}
}
}
getHeaders(Task) {
def list = []
$.components.each {
if (it in NativeLibrarySpec && (it.name == 'halAthena' || it.name == 'halSim')) {
it.sources.each {
it.exportedHeaders.srcDirs.each {
list.add(it)
}
}
it.binaries.each {
it.libs.each {
it.includeRoots.each {
list.add(it)
}
}
}
}
}
list = list.unique(false)
doLast {
list.each {
print "WPIHEADER: "
println it
}
}
}
}
}

View File

@@ -7,9 +7,8 @@
#include "HAL/AnalogInput.h"
#include <mutex>
#include <FRC_NetworkCommunication/AICalibration.h>
#include <support/mutex.h>
#include "AnalogInternal.h"
#include "HAL/AnalogAccumulator.h"
@@ -230,7 +229,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
readSelect.Channel = port->channel;
readSelect.Averaged = false;
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
analogInputSystem->writeReadSelect(readSelect, status);
analogInputSystem->strobeLatchOutput(status);
return static_cast<int16_t>(analogInputSystem->readOutput(status));
@@ -261,7 +260,7 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
readSelect.Channel = port->channel;
readSelect.Averaged = true;
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
analogInputSystem->writeReadSelect(readSelect, status);
analogInputSystem->strobeLatchOutput(status);
return static_cast<int32_t>(analogInputSystem->readOutput(status));

View File

@@ -8,7 +8,8 @@
#include "AnalogInternal.h"
#include <atomic>
#include <mutex>
#include <support/mutex.h>
#include "HAL/AnalogInput.h"
#include "HAL/ChipObject.h"
@@ -16,7 +17,7 @@
namespace hal {
std::mutex analogRegisterWindowMutex;
wpi::mutex analogRegisterWindowMutex;
std::unique_ptr<tAI> analogInputSystem;
std::unique_ptr<tAO> analogOutputSystem;
@@ -35,7 +36,7 @@ bool analogSampleRateSet = false;
*/
void initializeAnalog(int32_t* status) {
if (analogSystemInitialized) return;
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
if (analogSystemInitialized) return;
analogInputSystem.reset(tAI::create(status));
analogOutputSystem.reset(tAO::create(status));

View File

@@ -10,7 +10,8 @@
#include <stdint.h>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/ChipObject.h"
#include "HAL/Ports.h"
@@ -27,7 +28,7 @@ static const uint32_t kAccumulatorChannels[] = {0, 1};
extern std::unique_ptr<tAI> analogInputSystem;
extern std::unique_ptr<tAO> analogOutputSystem;
extern std::mutex analogRegisterWindowMutex;
extern wpi::mutex analogRegisterWindowMutex;
extern bool analogSampleRateSet;
struct AnalogPort {

View File

@@ -17,7 +17,7 @@
using namespace hal;
// Create a mutex to protect changes to the digital output values
static std::mutex digitalDIOMutex;
static wpi::mutex digitalDIOMutex;
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>
@@ -54,7 +54,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
port->channel = static_cast<uint8_t>(channel);
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
@@ -115,7 +115,7 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
digitalChannelHandles.Free(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) return;
int32_t status = 0;
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Unset the SPI flag
int32_t bitToUnset = 1 << remapSPIChannel(port->channel);
@@ -205,7 +205,7 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double rawDutyCycle = 256.0 * dutyCycle;
if (rawDutyCycle > 255.5) rawDutyCycle = 255.5;
{
std::lock_guard<std::mutex> sync(digitalPwmMutex);
std::lock_guard<wpi::mutex> sync(digitalPwmMutex);
uint16_t pwmPeriodPower = digitalSystem->readPWMPeriodPower(status);
if (pwmPeriodPower < 4) {
// The resolution of the duty cycle drops close to the highest
@@ -265,7 +265,7 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
if (value != 0) value = 1;
}
{
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
tDIO::tDO currentDIO = digitalSystem->readDO(status);
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
@@ -437,7 +437,7 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
return;
}
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Channels 10-15 are SPI channels, so subtract our MXP channels
digitalSystem->writeFilterSelectHdr(port->channel - kNumDigitalMXPChannels,
@@ -465,7 +465,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
return 0;
}
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
// Channels 10-15 are SPI channels, so subtract our MXP channels
return digitalSystem->readFilterSelectHdr(
@@ -492,7 +492,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
initializeDigital(status);
if (*status != 0) return;
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
digitalSystem->writeFilterPeriodHdr(filterIndex, value, status);
if (*status == 0) {
digitalSystem->writeFilterPeriodMXP(filterIndex, value, status);
@@ -517,7 +517,7 @@ int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
uint32_t hdrPeriod = 0;
uint32_t mxpPeriod = 0;
{
std::lock_guard<std::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status);
if (*status == 0) {
mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status);

View File

@@ -8,10 +8,10 @@
#include "DigitalInternal.h"
#include <atomic>
#include <mutex>
#include <thread>
#include <FRC_NetworkCommunication/LoadOut.h>
#include <support/mutex.h>
#include "ConstantsInternal.h"
#include "HAL/AnalogTrigger.h"
@@ -23,7 +23,7 @@
namespace hal {
// Create a mutex to protect changes to the DO PWM config
std::mutex digitalPwmMutex;
wpi::mutex digitalPwmMutex;
std::unique_ptr<tDIO> digitalSystem;
std::unique_ptr<tRelay> relaySystem;
@@ -31,7 +31,7 @@ std::unique_ptr<tPWM> pwmSystem;
std::unique_ptr<tSPI> spiSystem;
static std::atomic<bool> digitalSystemsInitialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalChannels + kNumPWMHeaders>
@@ -44,7 +44,7 @@ void initializeDigital(int32_t* status) {
// Initial check, as if it's true initialization has finished
if (digitalSystemsInitialized) return;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (digitalSystemsInitialized) return;

View File

@@ -10,7 +10,8 @@
#include <stdint.h>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/AnalogTrigger.h"
#include "HAL/ChipObject.h"
@@ -59,7 +60,7 @@ constexpr int32_t kDefaultPwmStepsDown = 1000;
constexpr int32_t kPwmDisabled = 0;
// Create a mutex to protect changes to the DO PWM config
extern std::mutex digitalPwmMutex;
extern wpi::mutex digitalPwmMutex;
extern std::unique_ptr<tDIO> digitalSystem;
extern std::unique_ptr<tRelay> relaySystem;

View File

@@ -7,14 +7,15 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <mutex>
#include <FRC_NetworkCommunication/FRCComm.h>
#include <FRC_NetworkCommunication/NetCommRPCProxy_Occur.h>
#include <llvm/raw_ostream.h>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include "HAL/DriverStation.h"
@@ -26,25 +27,20 @@ struct HAL_JoystickAxesInt {
int16_t axes[HAL_kMaxJoystickAxes];
};
static std::mutex msgMutex;
static std::condition_variable newDSDataAvailableCond;
static std::mutex newDSDataAvailableMutex;
static wpi::mutex msgMutex;
static wpi::condition_variable newDSDataAvailableCond;
static wpi::mutex newDSDataAvailableMutex;
static int newDSDataAvailableCounter{0};
extern "C" {
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
int32_t waitMs) {
return setErrorData(errors, errorsLength, waitMs);
}
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
const char* details, const char* location,
const char* callStack, HAL_Bool printMsg) {
// Avoid flooding console by keeping track of previous 5 error
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;
std::lock_guard<std::mutex> lock(msgMutex);
std::lock_guard<wpi::mutex> lock(msgMutex);
static std::string prevMsg[KEEP_MSGS];
static std::chrono::time_point<std::chrono::steady_clock>
prevMsgTime[KEEP_MSGS];
@@ -230,6 +226,67 @@ double HAL_GetMatchTime(int32_t* status) {
return matchTime;
}
int HAL_GetMatchInfo(HAL_MatchInfo* info) {
uint16_t gameSpecificMessageSize = 0;
int status = FRC_NetworkCommunication_getMatchInfo(
nullptr, nullptr, nullptr, nullptr, nullptr, &gameSpecificMessageSize);
if (status < 0) {
info->eventName = nullptr;
info->gameSpecificMessage = nullptr;
return status;
}
info->eventName = static_cast<char*>(std::malloc(256));
gameSpecificMessageSize = ((gameSpecificMessageSize + 1023) / 1024) * 1024;
uint16_t originalGameSpecificSize = gameSpecificMessageSize;
uint8_t* gameSpecificMessage =
static_cast<uint8_t*>(std::malloc(gameSpecificMessageSize));
MatchType_t matchType = MatchType_t::kMatchType_none;
uint16_t matchNumber = 0;
uint8_t replayNumber = 0;
status = FRC_NetworkCommunication_getMatchInfo(
info->eventName, &matchType, &matchNumber, &replayNumber,
gameSpecificMessage, &gameSpecificMessageSize);
if (status < 0) {
std::free(info->eventName);
std::free(gameSpecificMessage);
info->eventName = nullptr;
info->gameSpecificMessage = nullptr;
return status;
}
if (gameSpecificMessageSize >= originalGameSpecificSize) {
// Data has updated between size and read calls. Retry.
// Unless large lag, this call will be right.
std::free(gameSpecificMessage);
gameSpecificMessageSize = ((gameSpecificMessageSize + 1023) / 1024) * 1024;
gameSpecificMessage =
static_cast<uint8_t*>(std::malloc(gameSpecificMessageSize));
int status = FRC_NetworkCommunication_getMatchInfo(
nullptr, nullptr, nullptr, nullptr, gameSpecificMessage,
&gameSpecificMessageSize);
if (status < 0) {
std::free(info->eventName);
std::free(gameSpecificMessage);
info->eventName = nullptr;
info->gameSpecificMessage = nullptr;
return status;
}
}
info->eventName[255] = '\0';
info->matchType = static_cast<HAL_MatchType>(matchType);
info->matchNumber = matchNumber;
info->replayNumber = replayNumber;
info->gameSpecificMessage = reinterpret_cast<char*>(gameSpecificMessage);
info->gameSpecificMessage[gameSpecificMessageSize] = '\0';
return status;
}
void HAL_FreeMatchInfo(HAL_MatchInfo* info) {
std::free(info->eventName);
std::free(info->gameSpecificMessage);
info->eventName = nullptr;
info->gameSpecificMessage = nullptr;
}
void HAL_ObserveUserProgramStarting(void) {
FRC_NetworkCommunication_observeUserProgramStarting();
}
@@ -258,7 +315,7 @@ bool HAL_IsNewControlData(void) {
thread_local int lastCount{-1};
int currentCount = 0;
{
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
currentCount = newDSDataAvailableCounter;
}
if (lastCount == currentCount) return false;
@@ -280,7 +337,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
auto timeoutTime =
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
int currentCount = newDSDataAvailableCounter;
while (newDSDataAvailableCounter == currentCount) {
if (timeout > 0) {
@@ -295,22 +352,17 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
return true;
}
// Internal NetComm function to set new packet callback
extern int NetCommRPCProxy_SetOccurFuncPointer(
int32_t (*occurFunc)(uint32_t refNum));
// Constant number to be used for our occur handle
constexpr int32_t refNumber = 42;
static int32_t newDataOccur(uint32_t refNum) {
static void newDataOccur(uint32_t refNum) {
// Since we could get other values, require our specific handle
// to signal our threads
if (refNum != refNumber) return 0;
std::lock_guard<std::mutex> lock(newDSDataAvailableMutex);
if (refNum != refNumber) return;
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
// Nofify all threads
newDSDataAvailableCounter++;
newDSDataAvailableCond.notify_all();
return 0;
}
/*
@@ -320,11 +372,11 @@ static int32_t newDataOccur(uint32_t refNum) {
*/
void HAL_InitializeDriverStation(void) {
static std::atomic_bool initialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;

View File

@@ -14,12 +14,12 @@
#include <atomic>
#include <cstdlib>
#include <fstream>
#include <mutex>
#include <thread>
#include <FRC_NetworkCommunication/FRCComm.h>
#include <FRC_NetworkCommunication/LoadOut.h>
#include <llvm/raw_ostream.h>
#include <support/mutex.h>
#include "HAL/ChipObject.h"
#include "HAL/DriverStation.h"
@@ -219,6 +219,9 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
}
// Because of a bug in FPGA image 10, just return the lower 32 bits of time.
return global->readLocalTime(status);
uint64_t upper1 = global->readLocalTimeUpper(status);
uint32_t lower = global->readLocalTime(status);
uint64_t upper2 = global->readLocalTimeUpper(status);
@@ -261,11 +264,11 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
void HAL_BaseInitialize(int32_t* status) {
static std::atomic_bool initialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;
// image 4; Fixes errors caused by multiple processes. Talk to NI about this
@@ -323,11 +326,11 @@ static bool killExistingProgram(int timeout, int mode) {
*/
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
static std::atomic_bool initialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return true;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return true;

View File

@@ -7,7 +7,13 @@
#include "HAL/I2C.h"
#include <i2clib/i2c-lib.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <cstring>
#include "DigitalInternal.h"
#include "HAL/DIO.h"
@@ -15,13 +21,13 @@
using namespace hal;
static std::mutex digitalI2COnBoardMutex;
static std::mutex digitalI2CMXPMutex;
static wpi::mutex digitalI2COnBoardMutex;
static wpi::mutex digitalI2CMXPMutex;
static uint8_t i2COnboardObjCount = 0;
static uint8_t i2CMXPObjCount = 0;
static uint8_t i2COnBoardHandle = 0;
static uint8_t i2CMXPHandle = 0;
static int i2COnBoardHandle = -1;
static int i2CMXPHandle = -1;
static HAL_DigitalHandle i2CMXPDigitalHandle1 = HAL_kInvalidHandle;
static HAL_DigitalHandle i2CMXPDigitalHandle2 = HAL_kInvalidHandle;
@@ -42,30 +48,37 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
return;
}
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
{
std::lock_guard<std::mutex> sync(lock);
if (port == 0) {
i2COnboardObjCount++;
if (i2COnBoardHandle > 0) return;
i2COnBoardHandle = i2clib_open("/dev/i2c-2");
} else if (port == 1) {
i2CMXPObjCount++;
if (i2CMXPHandle > 0) return;
if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort(
HAL_GetPort(24), false, status)) == HAL_kInvalidHandle) {
return;
}
if ((i2CMXPDigitalHandle2 = HAL_InitializeDIOPort(
HAL_GetPort(25), false, status)) == HAL_kInvalidHandle) {
HAL_FreeDIOPort(i2CMXPDigitalHandle1); // free the first port allocated
return;
}
digitalSystem->writeEnableMXPSpecialFunction(
digitalSystem->readEnableMXPSpecialFunction(status) | 0xC000, status);
i2CMXPHandle = i2clib_open("/dev/i2c-1");
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
i2COnboardObjCount++;
if (i2COnboardObjCount > 1) return;
int handle = open("/dev/i2c-2", O_RDWR);
if (handle < 0) {
std::printf("Failed to open onboard i2c bus: %s\n", std::strerror(errno));
return;
}
return;
i2COnBoardHandle = handle;
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
i2CMXPObjCount++;
if (i2CMXPObjCount > 1) return;
if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort(
HAL_GetPort(24), false, status)) == HAL_kInvalidHandle) {
return;
}
if ((i2CMXPDigitalHandle2 = HAL_InitializeDIOPort(
HAL_GetPort(25), false, status)) == HAL_kInvalidHandle) {
HAL_FreeDIOPort(i2CMXPDigitalHandle1); // free the first port allocated
return;
}
digitalSystem->writeEnableMXPSpecialFunction(
digitalSystem->readEnableMXPSpecialFunction(status) | 0xC000, status);
int handle = open("/dev/i2c-1", O_RDWR);
if (handle < 0) {
std::printf("Failed to open MXP i2c bus: %s\n", std::strerror(errno));
return;
}
i2CMXPHandle = handle;
}
}
@@ -82,22 +95,33 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize,
const uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize) {
if (port > 1) {
// Set port out of range error here
return -1;
}
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
struct i2c_msg msgs[2];
msgs[0].addr = deviceAddress;
msgs[0].flags = 0;
msgs[0].len = sendSize;
msgs[0].buf = const_cast<uint8_t*>(dataToSend);
msgs[1].addr = deviceAddress;
msgs[1].flags = I2C_M_RD;
msgs[1].len = receiveSize;
msgs[1].buf = dataReceived;
{
std::lock_guard<std::mutex> sync(lock);
return i2clib_writeread(
handle, deviceAddress, reinterpret_cast<const char*>(dataToSend),
static_cast<int32_t>(sendSize), reinterpret_cast<char*>(dataReceived),
static_cast<int32_t>(receiveSize));
struct i2c_rdwr_ioctl_data rdwr;
rdwr.msgs = msgs;
rdwr.nmsgs = 2;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -113,18 +137,28 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize) {
const uint8_t* dataToSend, int32_t sendSize) {
if (port > 1) {
// Set port out of range error here
return -1;
}
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
{
std::lock_guard<std::mutex> sync(lock);
return i2clib_write(handle, deviceAddress,
reinterpret_cast<const char*>(dataToSend), sendSize);
struct i2c_msg msg;
msg.addr = deviceAddress;
msg.flags = 0;
msg.len = sendSize;
msg.buf = const_cast<uint8_t*>(dataToSend);
struct i2c_rdwr_ioctl_data rdwr;
rdwr.msgs = &msg;
rdwr.nmsgs = 1;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -148,12 +182,22 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
return -1;
}
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
{
std::lock_guard<std::mutex> sync(lock);
return i2clib_read(handle, deviceAddress, reinterpret_cast<char*>(buffer),
static_cast<int32_t>(count));
struct i2c_msg msg;
msg.addr = deviceAddress;
msg.flags = I2C_M_RD;
msg.len = count;
msg.buf = buffer;
struct i2c_rdwr_ioctl_data rdwr;
rdwr.msgs = &msg;
rdwr.nmsgs = 1;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -162,20 +206,20 @@ void HAL_CloseI2C(HAL_I2CPort port) {
// Set port out of range error here
return;
}
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
{
std::lock_guard<std::mutex> sync(lock);
if ((port == 0 ? i2COnboardObjCount-- : i2CMXPObjCount--) == 0) {
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
i2clib_close(handle);
}
}
if (port == 1) {
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
if (i2COnboardObjCount-- == 0) {
close(i2COnBoardHandle);
}
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
if (i2CMXPObjCount-- == 0) {
close(i2CMXPHandle);
}
HAL_FreeDIOPort(i2CMXPDigitalHandle1);
HAL_FreeDIOPort(i2CMXPDigitalHandle2);
}
return;
}
} // extern "C"

View File

@@ -32,7 +32,7 @@ struct Interrupt {
class InterruptThread : public wpi::SafeThread {
public:
void Main() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<wpi::mutex> lock(m_mutex);
while (m_active) {
m_cond.wait(lock, [&] { return !m_active || m_notify; });
if (!m_active) break;
@@ -178,10 +178,10 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
}
/**
* Return the timestamp for the falling interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
* Return the timestamp for the falling interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interruptHandle);

View File

@@ -10,9 +10,9 @@
#include <atomic>
#include <cstdlib> // For std::atexit()
#include <memory>
#include <mutex>
#include <support/SafeThread.h>
#include <support/mutex.h>
#include "HAL/ChipObject.h"
#include "HAL/Errors.h"
@@ -25,8 +25,8 @@ using namespace hal;
static const int32_t kTimerInterruptNumber = 28;
static std::mutex notifierInterruptMutex;
static std::mutex notifierMutex;
static wpi::mutex notifierInterruptMutex;
static wpi::mutex notifierMutex;
static std::unique_ptr<tAlarm> notifierAlarm;
static std::unique_ptr<tInterruptManager> notifierManager;
static uint64_t closestTrigger = UINT64_MAX;
@@ -46,7 +46,7 @@ struct Notifier {
class NotifierThread : public wpi::SafeThread {
public:
void Main() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<wpi::mutex> lock(m_mutex);
while (m_active) {
m_cond.wait(lock, [&] { return !m_active || m_notify; });
if (!m_active) break;
@@ -126,7 +126,7 @@ void updateNotifierAlarmInternal(std::shared_ptr<Notifier> notifierPointer,
}
static void alarmCallback(uint32_t, void*) {
std::unique_lock<std::mutex> sync(notifierMutex);
std::unique_lock<wpi::mutex> sync(notifierMutex);
int32_t status = 0;
uint64_t currentTime = 0;
@@ -182,7 +182,7 @@ HAL_NotifierHandle HAL_InitializeNotifierNonThreadedUnsafe(
if (!notifierAtexitRegistered.test_and_set())
std::atexit(cleanupNotifierAtExit);
if (notifierRefCount.fetch_add(1) == 0) {
std::lock_guard<std::mutex> sync(notifierInterruptMutex);
std::lock_guard<wpi::mutex> sync(notifierInterruptMutex);
// create manager and alarm if not already created
if (!notifierManager) {
notifierManager = std::make_unique<tInterruptManager>(
@@ -193,7 +193,7 @@ HAL_NotifierHandle HAL_InitializeNotifierNonThreadedUnsafe(
if (!notifierAlarm) notifierAlarm.reset(tAlarm::create(status));
}
std::lock_guard<std::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> sync(notifierMutex);
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
HAL_NotifierHandle handle = notifierHandles.Allocate(notifier);
if (handle == HAL_kInvalidHandle) {
@@ -236,7 +236,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
{
std::lock_guard<std::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
@@ -254,7 +254,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
}
if (notifierRefCount.fetch_sub(1) == 1) {
std::lock_guard<std::mutex> sync(notifierInterruptMutex);
std::lock_guard<wpi::mutex> sync(notifierInterruptMutex);
// if this was the last notifier, clean up alarm and manager
if (notifierAlarm) {
notifierAlarm->writeEnable(false, status);
@@ -282,7 +282,7 @@ void* HAL_GetNotifierParam(HAL_NotifierHandle notifierHandle, int32_t* status) {
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
uint64_t triggerTime, int32_t* status) {
std::lock_guard<std::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
@@ -290,7 +290,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
}
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status) {
std::lock_guard<std::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
notifier->triggerTime = UINT64_MAX;

View File

@@ -19,24 +19,39 @@ using namespace hal;
static inline int32_t GetMaxPositivePwm(DigitalPort* port) {
return port->maxPwm;
}
static inline int32_t GetMinPositivePwm(DigitalPort* port) {
return port->eliminateDeadband ? port->deadbandMaxPwm : port->centerPwm + 1;
if (port->eliminateDeadband) {
return port->deadbandMaxPwm;
} else {
return port->centerPwm + 1;
}
}
static inline int32_t GetCenterPwm(DigitalPort* port) {
return port->centerPwm;
}
static inline int32_t GetMaxNegativePwm(DigitalPort* port) {
return port->eliminateDeadband ? port->deadbandMinPwm : port->centerPwm - 1;
if (port->eliminateDeadband) {
return port->deadbandMinPwm;
} else {
return port->centerPwm - 1;
}
}
static inline int32_t GetMinNegativePwm(DigitalPort* port) {
return port->minPwm;
}
static inline int32_t GetPositiveScaleFactor(DigitalPort* port) {
return GetMaxPositivePwm(port) - GetMinPositivePwm(port);
} ///< The scale for positive speeds.
static inline int32_t GetNegativeScaleFactor(DigitalPort* port) {
return GetMaxNegativePwm(port) - GetMinNegativePwm(port);
} ///< The scale for negative speeds.
static inline int32_t GetFullRangeScaleFactor(DigitalPort* port) {
return GetMaxPositivePwm(port) - GetMinNegativePwm(port);
} ///< The scale for positions.
@@ -458,6 +473,10 @@ int32_t HAL_GetPWMLoopTiming(int32_t* status) {
uint64_t HAL_GetPWMCycleStartTime(int32_t* status) {
initializeDigital(status);
if (*status != 0) return 0;
// Because of a bug in FPGA image 10, just return the lower 32 bits of cycle
// time.
return pwmSystem->readCycleStartTime(status);
uint64_t upper1 = pwmSystem->readCycleStartTimeUpper(status);
uint32_t lower = pwmSystem->readCycleStartTime(status);
uint64_t upper2 = pwmSystem->readCycleStartTimeUpper(status);

View File

@@ -27,7 +27,7 @@ static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
relayHandles;
// Create a mutex to protect changes to the relay values
static std::mutex digitalRelayMutex;
static wpi::mutex digitalRelayMutex;
extern "C" {
@@ -92,7 +92,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
*status = HAL_HANDLE_ERROR;
return;
}
std::lock_guard<std::mutex> sync(digitalRelayMutex);
std::lock_guard<wpi::mutex> sync(digitalRelayMutex);
uint8_t relays = 0;
if (port->fwd) {
relays = relaySystem->readValue_Forward(status);

View File

@@ -7,12 +7,17 @@
#include "HAL/SPI.h"
#include <fcntl.h>
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <array>
#include <atomic>
#include <mutex>
#include <cstring>
#include <llvm/raw_ostream.h>
#include <spilib/spi-lib.h>
#include <support/mutex.h>
#include "DigitalInternal.h"
#include "HAL/DIO.h"
@@ -32,9 +37,9 @@ static int32_t m_spiMXPHandle = 0;
static constexpr int32_t kSpiMaxHandles = 5;
// Indices 0-3 are for onboard CS0-CS2. Index 4 is for MXP.
static std::array<std::mutex, kSpiMaxHandles> spiHandleMutexes;
static std::array<std::mutex, kSpiMaxHandles> spiApiMutexes;
static std::array<std::mutex, kSpiMaxHandles> spiAccumulatorMutexes;
static std::array<wpi::mutex, kSpiMaxHandles> spiHandleMutexes;
static std::array<wpi::mutex, kSpiMaxHandles> spiApiMutexes;
static std::array<wpi::mutex, kSpiMaxHandles> spiAccumulatorMutexes;
// MXP SPI does not count towards this
std::atomic<int32_t> spiPortCount{0};
@@ -111,13 +116,21 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
return;
}
int handle;
if (HAL_GetSPIHandle(port) != 0) return;
switch (port) {
case 0:
CommonSPIPortInit(status);
if (*status != 0) return;
// CS0 is not a DIO port, so nothing to allocate
HAL_SetSPIHandle(HAL_SPI_kOnboardCS0, spilib_open("/dev/spidev0.0"));
handle = open("/dev/spidev0.0", O_RDWR);
if (handle < 0) {
std::printf("Failed to open SPI port %d: %s\n", port,
std::strerror(errno));
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS0, handle);
break;
case 1:
CommonSPIPortInit(status);
@@ -130,7 +143,15 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS1, spilib_open("/dev/spidev0.1"));
handle = open("/dev/spidev0.1", O_RDWR);
if (handle < 0) {
std::printf("Failed to open SPI port %d: %s\n", port,
std::strerror(errno));
CommonSPIPortFree();
HAL_FreeDIOPort(digitalHandles[0]);
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS1, handle);
break;
case 2:
CommonSPIPortInit(status);
@@ -143,7 +164,15 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS2, spilib_open("/dev/spidev0.2"));
handle = open("/dev/spidev0.2", O_RDWR);
if (handle < 0) {
std::printf("Failed to open SPI port %d: %s\n", port,
std::strerror(errno));
CommonSPIPortFree();
HAL_FreeDIOPort(digitalHandles[1]);
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS2, handle);
break;
case 3:
CommonSPIPortInit(status);
@@ -156,7 +185,15 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
CommonSPIPortFree();
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS3, spilib_open("/dev/spidev0.3"));
handle = open("/dev/spidev0.3", O_RDWR);
if (handle < 0) {
std::printf("Failed to open SPI port %d: %s\n", port,
std::strerror(errno));
CommonSPIPortFree();
HAL_FreeDIOPort(digitalHandles[2]);
return;
}
HAL_SetSPIHandle(HAL_SPI_kOnboardCS3, handle);
break;
case 4:
initializeDigital(status);
@@ -193,13 +230,22 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
}
digitalSystem->writeEnableMXPSpecialFunction(
digitalSystem->readEnableMXPSpecialFunction(status) | 0x00F0, status);
HAL_SetSPIHandle(HAL_SPI_kMXP, spilib_open("/dev/spidev1.0"));
handle = open("/dev/spidev1.0", O_RDWR);
if (handle < 0) {
std::printf("Failed to open SPI port %d: %s\n", port,
std::strerror(errno));
HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated
HAL_FreeDIOPort(digitalHandles[6]); // free the second port allocated
HAL_FreeDIOPort(digitalHandles[7]); // free the third port allocated
HAL_FreeDIOPort(digitalHandles[8]); // free the fourth port allocated
return;
}
HAL_SetSPIHandle(HAL_SPI_kMXP, handle);
break;
default:
*status = PARAMETER_OUT_OF_RANGE;
break;
}
return;
}
/**
@@ -214,16 +260,20 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
* @param size Number of bytes to transfer. [0..7]
* @return Number of bytes transferred, -1 for error
*/
int32_t HAL_TransactionSPI(HAL_SPIPort port, uint8_t* dataToSend,
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
if (port < 0 || port >= kSpiMaxHandles) {
return -1;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
return spilib_writeread(
HAL_GetSPIHandle(port), reinterpret_cast<const char*>(dataToSend),
reinterpret_cast<char*>(dataReceived), static_cast<int32_t>(size));
struct spi_ioc_transfer xfer;
std::memset(&xfer, 0, sizeof(xfer));
xfer.tx_buf = (__u64)dataToSend;
xfer.rx_buf = (__u64)dataReceived;
xfer.len = size;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
@@ -236,15 +286,19 @@ int32_t HAL_TransactionSPI(HAL_SPIPort port, uint8_t* dataToSend,
* @param sendSize The number of bytes to be written
* @return The number of bytes written. -1 for an error
*/
int32_t HAL_WriteSPI(HAL_SPIPort port, uint8_t* dataToSend, int32_t sendSize) {
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize) {
if (port < 0 || port >= kSpiMaxHandles) {
return -1;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
return spilib_write(HAL_GetSPIHandle(port),
reinterpret_cast<const char*>(dataToSend),
static_cast<int32_t>(sendSize));
struct spi_ioc_transfer xfer;
std::memset(&xfer, 0, sizeof(xfer));
xfer.tx_buf = (__u64)dataToSend;
xfer.len = sendSize;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
@@ -265,9 +319,13 @@ int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
return -1;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
return spilib_read(HAL_GetSPIHandle(port), reinterpret_cast<char*>(buffer),
static_cast<int32_t>(count));
struct spi_ioc_transfer xfer;
std::memset(&xfer, 0, sizeof(xfer));
xfer.rx_buf = (__u64)buffer;
xfer.len = count;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
@@ -284,8 +342,8 @@ void HAL_CloseSPI(HAL_SPIPort port) {
HAL_FreeSPIAccumulator(port, &status);
{
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
spilib_close(HAL_GetSPIHandle(port));
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
close(HAL_GetSPIHandle(port));
}
HAL_SetSPIHandle(port, 0);
@@ -326,8 +384,8 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
return;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
spilib_setspeed(HAL_GetSPIHandle(port), speed);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MAX_SPEED_HZ, &speed);
}
/**
@@ -346,9 +404,13 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
return;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
spilib_setopts(HAL_GetSPIHandle(port), msbFirst, sampleOnTrailing,
clkIdleHigh);
uint8_t mode = 0;
mode |= (!msbFirst ? 8 : 0);
mode |= (clkIdleHigh ? 2 : 0);
mode |= (sampleOnTrailing ? 1 : 0);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MODE, &mode);
}
/**
@@ -362,7 +424,7 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
spiSystem->readChipSelectActiveHigh_Hdr(status) | (1 << port), status);
@@ -382,7 +444,7 @@ void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
spiSystem->readChipSelectActiveHigh_Hdr(status) & ~(1 << port), status);
@@ -402,7 +464,7 @@ int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
return 0;
}
std::lock_guard<std::mutex> sync(spiHandleMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
switch (port) {
case 0:
return m_spiCS0Handle;
@@ -431,7 +493,7 @@ void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {
return;
}
std::lock_guard<std::mutex> sync(spiHandleMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
switch (port) {
case 0:
m_spiCS0Handle = handle;
@@ -462,13 +524,7 @@ static void spiAccumulatorProcess(uint64_t currentTime,
// perform SPI transaction
uint8_t resp_b[4];
{
std::lock_guard<std::mutex> sync(spiApiMutexes[accum->port]);
spilib_writeread(HAL_GetSPIHandle(accum->port),
reinterpret_cast<const char*>(accum->cmd),
reinterpret_cast<char*>(resp_b),
static_cast<int32_t>(accum->xferSize));
}
HAL_TransactionSPI(accum->port, accum->cmd, resp_b, accum->xferSize);
// convert from bytes
uint32_t resp = 0;
@@ -538,7 +594,7 @@ void HAL_InitSPIAccumulator(HAL_SPIPort port, int32_t period, int32_t cmd,
return;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
if (!spiAccumulators[port])
spiAccumulators[port] = std::make_unique<SPIAccumulator>();
SPIAccumulator* accum = spiAccumulators[port].get();
@@ -584,7 +640,7 @@ void HAL_FreeSPIAccumulator(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -604,7 +660,7 @@ void HAL_ResetSPIAccumulator(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -631,7 +687,7 @@ void HAL_SetSPIAccumulatorCenter(HAL_SPIPort port, int32_t center,
return;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -650,7 +706,7 @@ void HAL_SetSPIAccumulatorDeadband(HAL_SPIPort port, int32_t deadband,
return;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -668,7 +724,7 @@ int32_t HAL_GetSPIAccumulatorLastValue(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -688,7 +744,7 @@ int64_t HAL_GetSPIAccumulatorValue(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -711,7 +767,7 @@ int64_t HAL_GetSPIAccumulatorCount(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -754,7 +810,7 @@ void HAL_GetSPIAccumulatorOutput(HAL_SPIPort port, int64_t* value,
return;
}
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;

View File

@@ -11,6 +11,7 @@
#include <cstdio>
#include <cstring>
#include <llvm/FileSystem.h>
#include <llvm/StringRef.h>
#include "../visa/visa.h"
@@ -26,7 +27,7 @@ namespace hal {
std::string SerialHelper::m_usbNames[2]{"", ""};
std::mutex SerialHelper::m_nameMutex;
wpi::mutex SerialHelper::m_nameMutex;
SerialHelper::SerialHelper() {
viOpenDefaultRM(reinterpret_cast<ViSession*>(&m_resourceHandle));
@@ -178,9 +179,8 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
// Status might be positive, so reset it to 0
*status = 0;
// Storage buffers for Visa calls and system exec calls
// Storage buffer for Visa call
char osName[256];
char execBuffer[128];
// Loop through all returned VISA objects.
// Increment the internal VISA ptr every loop
@@ -214,45 +214,30 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
llvm::StringRef matchString = devNameRef.split(')').first;
if (matchString.equals(devNameRef)) continue;
// Run find using pipe to get a list of system accessors
llvm::SmallString<128> val(
"sh -c \"find /sys/devices/soc0 | grep amba | grep usb | grep ");
val += matchString;
val += "\"";
// Search directories to get a list of system accessors
std::error_code ec;
for (auto p = llvm::sys::fs::recursive_directory_iterator(
"/sys/devices/soc0", ec);
p != llvm::sys::fs::recursive_directory_iterator(); p.increment(ec)) {
if (ec) break;
llvm::StringRef path{p->path()};
if (path.find("amba") == llvm::StringRef::npos) continue;
if (path.find("usb") == llvm::StringRef::npos) continue;
if (path.find(matchString) == llvm::StringRef::npos) continue;
// Pipe code found on StackOverflow
// http://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c-using-posix
// Using std::string because this is guarenteed to be large
std::string output = "";
std::shared_ptr<std::FILE> pipe(popen(val.c_str(), "r"), pclose);
// Just check the next item on a pipe failure
if (!pipe) continue;
while (!feof(pipe.get())) {
if (std::fgets(execBuffer, 128, pipe.get()) != 0) output += execBuffer;
}
if (!output.empty()) {
llvm::SmallVector<llvm::StringRef, 16> pathSplitVec;
// Split output by line, grab first line, and split it into
// individual directories
llvm::StringRef{output}.split('\n').first.split(pathSplitVec, '/', -1,
false);
// Split path into individual directories
path.split(pathSplitVec, '/', -1, false);
// Find each individual item index
const char* usb1 = "usb1";
const char* tty = "tty";
int findusb = -1;
int findtty = -1;
int findregex = -1;
for (size_t i = 0; i < pathSplitVec.size(); i++) {
if (findusb == -1 && pathSplitVec[i].equals(usb1)) {
if (findusb == -1 && pathSplitVec[i].equals("usb1")) {
findusb = i;
}
if (findtty == -1 && pathSplitVec[i].equals(tty)) {
if (findtty == -1 && pathSplitVec[i].equals("tty")) {
findtty = i;
}
if (findregex == -1 && pathSplitVec[i].equals(matchString)) {
@@ -274,6 +259,7 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
m_visaResource.emplace_back(desc);
m_osResource.emplace_back(
llvm::StringRef{osName}.split("(").second.split(")").first);
break;
}
}
@@ -287,7 +273,7 @@ done:
int32_t SerialHelper::GetIndexForPort(HAL_SerialPort port, int32_t* status) {
// Hold lock whenever we're using the names array
std::lock_guard<std::mutex> lock(m_nameMutex);
std::lock_guard<wpi::mutex> lock(m_nameMutex);
std::string portString = m_usbNames[port - 2];

View File

@@ -1,6 +1,6 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "ctre/CtreCanNode.h"
#include "CtreCanNode.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include <string.h> // memset

View File

@@ -1,6 +1,6 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "ctre/PCM.h"
#include "PCM.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include <string.h> // memset
/* This can be a constant, as long as nobody needs to update solenoids within

View File

@@ -1,4 +1,4 @@
#include "ctre/PDP.h"
#include "PDP.h"
#include "FRC_NetworkCommunication/CANSessionMux.h" //CAN Comm
#include <string.h> // memset

View File

@@ -52,6 +52,4 @@ typedef enum {
CTR_BufferFull, //!< Caller attempted to insert data into a buffer that is full.
}CTR_Code;
#include "ctre_frames.h"
#endif /* CTRE_H */

View File

@@ -47,6 +47,13 @@ enum HAL_AllianceStationID : int32_t {
HAL_AllianceStationID_kBlue3,
};
enum HAL_MatchType {
HAL_kMatchType_none,
HAL_kMatchType_practice,
HAL_kMatchType_qualification,
HAL_kMatchType_elimination,
};
/* The maximum number of axes that will be stored in a single HALJoystickAxes
* struct. This is used for allocating buffers, not bounds checking, since
* there are usually less axes in practice.
@@ -79,11 +86,18 @@ struct HAL_JoystickDescriptor {
uint8_t povCount;
};
struct HAL_MatchInfo {
char* eventName;
HAL_MatchType matchType;
uint16_t matchNumber;
uint8_t replayNumber;
char* gameSpecificMessage;
};
#ifdef __cplusplus
extern "C" {
#endif
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
int32_t waitMs);
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
const char* details, const char* location,
const char* callStack, HAL_Bool printMsg);
@@ -105,6 +119,9 @@ int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble, int32_t rightRumble);
double HAL_GetMatchTime(int32_t* status);
int HAL_GetMatchInfo(HAL_MatchInfo* info);
void HAL_FreeMatchInfo(HAL_MatchInfo* info);
#ifndef HAL_USE_LABVIEW
void HAL_ReleaseDSMutex(void);

View File

@@ -17,10 +17,10 @@ extern "C" {
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status);
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize,
const uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize);
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize);
const uint8_t* dataToSend, int32_t sendSize);
int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
int32_t count);
void HAL_CloseI2C(HAL_I2CPort port);

View File

@@ -24,9 +24,10 @@ extern "C" {
#endif
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status);
int32_t HAL_TransactionSPI(HAL_SPIPort port, uint8_t* dataToSend,
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size);
int32_t HAL_WriteSPI(HAL_SPIPort port, uint8_t* dataToSend, int32_t sendSize);
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize);
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count);
void HAL_CloseSPI(HAL_SPIPort port);
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed);

View File

@@ -52,7 +52,9 @@ inline Log::Log() {}
inline llvm::raw_ostream& Log::Get(TLogLevel level) {
oss << "- " << NowTime();
oss << " " << ToString(level) << ": ";
oss << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
if (level > logDEBUG) {
oss << std::string(level - logDEBUG, '\t');
}
return oss;
}
@@ -94,7 +96,7 @@ typedef Log FILELog;
if (level > FILELog::ReportingLevel()) \
; \
else \
Log().Get(level)
Log().Get(level)
inline std::string NowTime() {
llvm::SmallString<128> buf;

View File

@@ -9,12 +9,12 @@
#include <stdint.h>
#include <mutex>
#include <string>
#include <vector>
#include <llvm/SmallString.h>
#include <llvm/SmallVector.h>
#include <support/mutex.h>
#include "HAL/SerialPort.h"
@@ -46,7 +46,7 @@ class SerialHelper {
int32_t m_resourceHandle;
static std::mutex m_nameMutex;
static wpi::mutex m_nameMutex;
static std::string m_usbNames[2];
};
} // namespace hal

View File

@@ -1,92 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
// Allows usage with std::lock_guard without including <mutex> separately
#include <mutex>
#if !defined(__linux__)
namespace hal {
// We do not want to use pthreads if in the simulator; however, in the
// simulator, we do not care about priority inversion.
typedef std::mutex priority_mutex;
typedef std::recursive_mutex priority_recursive_mutex;
} // namespace hal
#else // Covers rest of file.
#include <pthread.h>
namespace hal {
class priority_recursive_mutex {
public:
typedef pthread_mutex_t* native_handle_type;
constexpr priority_recursive_mutex() noexcept = default;
priority_recursive_mutex(const priority_recursive_mutex&) = delete;
priority_recursive_mutex& operator=(const priority_recursive_mutex&) = delete;
// Lock the mutex, blocking until it's available.
void lock();
// Unlock the mutex.
void unlock();
// Tries to lock the mutex.
bool try_lock() noexcept;
pthread_mutex_t* native_handle();
private:
// Do the equivalent of setting PTHREAD_PRIO_INHERIT and
// PTHREAD_MUTEX_RECURSIVE_NP.
#if __WORDSIZE == 64
pthread_mutex_t m_mutex = {
{0, 0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, 0, {0, 0}}};
#else
pthread_mutex_t m_mutex = {
{0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, {0}}};
#endif
};
class priority_mutex {
public:
typedef pthread_mutex_t* native_handle_type;
constexpr priority_mutex() noexcept = default;
priority_mutex(const priority_mutex&) = delete;
priority_mutex& operator=(const priority_mutex&) = delete;
// Lock the mutex, blocking until it's available.
void lock();
// Unlock the mutex.
void unlock();
// Tries to lock the mutex.
bool try_lock() noexcept;
pthread_mutex_t* native_handle();
private:
// Do the equivalent of setting PTHREAD_PRIO_INHERIT.
#if __WORDSIZE == 64
pthread_mutex_t m_mutex = {{0, 0, 0, 0, 0x20, 0, 0, {0, 0}}};
#else
pthread_mutex_t m_mutex = {{0, 0, 0, 0x20, 0, {0}}};
#endif
};
} // namespace hal
#endif // FRC_SIMULATOR
// For backwards compatibility
#ifndef NAMESPACED_PRIORITY
using hal::priority_mutex; // NOLINT
using hal::priority_recursive_mutex; // NOLINT
#endif

View File

@@ -11,7 +11,8 @@
#include <array>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/Errors.h"
#include "HAL/Types.h"
@@ -48,7 +49,7 @@ class DigitalHandleResource : public HandleBase {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<std::mutex, size> m_handleMutexes;
std::array<wpi::mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size>
@@ -59,7 +60,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -77,7 +78,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -90,14 +91,14 @@ void DigitalHandleResource<THandle, TStruct, size>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
template <typename THandle, typename TStruct, int16_t size>
void DigitalHandleResource<THandle, TStruct, size>::ResetHandles() {
for (int i = 0; i < size; i++) {
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -12,6 +12,8 @@
#include <memory>
#include <vector>
#include <support/mutex.h>
#include "HAL/Errors.h"
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
@@ -51,7 +53,7 @@ class IndexedClassedHandleResource : public HandleBase {
private:
std::array<std::shared_ptr<TStruct>[], size> m_structures;
std::array<std::mutex[], size> m_handleMutexes;
std::array<wpi::mutex[], size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -59,7 +61,7 @@ template <typename THandle, typename TStruct, int16_t size,
IndexedClassedHandleResource<THandle, TStruct, size,
enumValue>::IndexedClassedHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<std::mutex[]>(size);
m_handleMutexes = std::make_unique<wpi::mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size,
@@ -72,7 +74,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -84,14 +86,15 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
std::shared_ptr<TStruct> IndexedClassedHandleResource<
THandle, TStruct, size, enumValue>::Get(THandle handle) {
std::shared_ptr<TStruct>
IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
THandle handle) {
// get handle index, and fail early if index out of range or wrong handle
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -105,7 +108,7 @@ void IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -114,7 +117,7 @@ template <typename THandle, typename TStruct, int16_t size,
void IndexedClassedHandleResource<THandle, TStruct, size,
enumValue>::ResetHandles() {
for (int i = 0; i < size; i++) {
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -11,7 +11,8 @@
#include <array>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/Errors.h"
#include "HAL/Types.h"
@@ -49,7 +50,7 @@ class IndexedHandleResource : public HandleBase {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<std::mutex, size> m_handleMutexes;
std::array<wpi::mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -61,7 +62,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -80,7 +81,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -94,7 +95,7 @@ void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -102,7 +103,7 @@ template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
void IndexedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
for (int i = 0; i < size; i++) {
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -11,7 +11,8 @@
#include <array>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
@@ -48,8 +49,8 @@ class LimitedClassedHandleResource : public HandleBase {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<std::mutex, size> m_handleMutexes;
std::mutex m_allocateMutex;
std::array<wpi::mutex, size> m_handleMutexes;
wpi::mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -58,12 +59,12 @@ THandle
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
std::shared_ptr<TStruct> toSet) {
// globally lock to loop through indices
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
for (int16_t i = 0; i < size; i++) {
if (m_structures[i] == nullptr) {
// if a false index is found, grab its specific mutex
// and allocate it.
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i] = toSet;
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -73,14 +74,15 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
std::shared_ptr<TStruct> LimitedClassedHandleResource<
THandle, TStruct, size, enumValue>::Get(THandle handle) {
std::shared_ptr<TStruct>
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
THandle handle) {
// get handle index, and fail early if index out of range or wrong handle
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -94,8 +96,8 @@ void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<std::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -104,9 +106,9 @@ template <typename THandle, typename TStruct, int16_t size,
void LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::ResetHandles() {
{
std::lock_guard<std::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -11,7 +11,8 @@
#include <array>
#include <memory>
#include <mutex>
#include <support/mutex.h>
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
@@ -46,20 +47,20 @@ class LimitedHandleResource : public HandleBase {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<std::mutex, size> m_handleMutexes;
std::mutex m_allocateMutex;
std::array<wpi::mutex, size> m_handleMutexes;
wpi::mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
// globally lock to loop through indices
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
for (int16_t i = 0; i < size; i++) {
if (m_structures[i] == nullptr) {
// if a false index is found, grab its specific mutex
// and allocate it.
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i] = std::make_shared<TStruct>();
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -76,7 +77,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -90,8 +91,8 @@ void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<std::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -99,9 +100,9 @@ template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
{
std::lock_guard<std::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -10,9 +10,10 @@
#include <stdint.h>
#include <memory>
#include <mutex>
#include <vector>
#include <support/mutex.h>
#include "HAL/Types.h"
#include "HAL/handles/HandlesInternal.h"
@@ -48,13 +49,13 @@ class UnlimitedHandleResource : public HandleBase {
private:
std::vector<std::shared_ptr<TStruct>> m_structures;
std::mutex m_handleMutex;
wpi::mutex m_handleMutex;
};
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
std::shared_ptr<TStruct> structure) {
std::lock_guard<std::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> sync(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {
@@ -73,7 +74,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
std::lock_guard<std::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> sync(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
return nullptr;
return m_structures[index];
@@ -83,7 +84,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
std::lock_guard<std::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> sync(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size())) return;
m_structures[index].reset();
}
@@ -91,7 +92,7 @@ void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ResetHandles() {
{
std::lock_guard<std::mutex> lock(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
for (size_t i = 0; i < m_structures.size(); i++) {
m_structures[i].reset();
}

View File

@@ -7,6 +7,7 @@
#pragma once
#include "HAL/DriverStation.h"
#include "HAL/HAL.h"
#include "NotifyListener.h"
@@ -67,12 +68,24 @@ void HALSIM_CancelDriverStationMatchTimeCallback(int32_t uid);
double HALSIM_GetDriverStationMatchTime();
void HALSIM_SetDriverStationMatchTime(double matchTime);
void HALSIM_NotifyDriverStationNewData(void);
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes);
void HALSIM_SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs);
void HALSIM_SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons);
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
const HAL_JoystickDescriptor* descriptor);
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
int32_t* leftRumble, int32_t* rightRumble);
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info);
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_NotifyDriverStationNewData(void);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -30,7 +30,7 @@ int32_t HALSIM_RegisterI2CReadCallback(int32_t index,
void HALSIM_CancelI2CReadCallback(int32_t index, int32_t uid);
int32_t HALSIM_RegisterI2CWriteCallback(int32_t index,
HAL_BufferCallback callback,
HAL_ConstBufferCallback callback,
void* param);
void HALSIM_CancelI2CWriteCallback(int32_t index, int32_t uid);

View File

@@ -15,6 +15,10 @@ typedef void (*HAL_NotifyCallback)(const char* name, void* param,
typedef void (*HAL_BufferCallback)(const char* name, void* param,
unsigned char* buffer, unsigned int count);
typedef void (*HAL_ConstBufferCallback)(const char* name, void* param,
const unsigned char* buffer,
unsigned int count);
namespace hal {
template <typename CallbackFunction>

View File

@@ -8,7 +8,6 @@
#pragma once
#include <memory>
#include <mutex>
#include <queue>
#include <vector>
@@ -133,5 +132,7 @@ void HalCallbackListenerVectorImpl<ListenerType>::erase_impl(unsigned int uid) {
typedef HalCallbackListenerVectorImpl<HAL_NotifyCallback> NotifyListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_BufferCallback> BufferListenerVector;
typedef HalCallbackListenerVectorImpl<HAL_ConstBufferCallback>
ConstBufferListenerVector;
} // namespace hal

View File

@@ -30,7 +30,7 @@ int32_t HALSIM_RegisterSPIReadCallback(int32_t index,
void HALSIM_CancelSPIReadCallback(int32_t index, int32_t uid);
int32_t HALSIM_RegisterSPIWriteCallback(int32_t index,
HAL_BufferCallback callback,
HAL_ConstBufferCallback callback,
void* param);
void HALSIM_CancelSPIWriteCallback(int32_t index, int32_t uid);

View File

@@ -1,243 +0,0 @@
/**
* @file ctre_frames.h
* CAN Encoder/Decoder Structures for CTRE devices.
*/
#ifndef CTRE_FRAMES_H
#define CTRE_FRAMES_H
/** control */
typedef struct _TALON_Control_1_General_10ms_t {
unsigned TokenH:8;
unsigned TokenL:8;
unsigned DemandH:8;
unsigned DemandM:8;
unsigned DemandL:8;
unsigned ProfileSlotSelect:1;
unsigned FeedbackDeviceSelect:4;
unsigned OverrideLimitSwitchEn:3;
unsigned RevFeedbackSensor:1;
unsigned RevMotDuringCloseLoopEn:1;
unsigned OverrideBrakeType:2;
unsigned ModeSelect:4;
unsigned RampThrottle:8;
} TALON_Control_1_General_10ms_t ;
/* TALON_Control_2_Rates_OneShot_t removed since it has been deprecated */
typedef struct _TALON_Control_3_ClearFlags_OneShot_t {
unsigned ZeroFeedbackSensor:1;
unsigned ClearStickyFaults:1;
} TALON_Control_3_ClearFlags_OneShot_t ;
typedef struct _TALON_Control_5_General_10ms_t {
unsigned ThrottleBump_h3:3;
unsigned ReservedZero:5;
unsigned ThrottleBump_l8:8;
unsigned DemandH:8;
unsigned DemandM:8;
unsigned DemandL:8;
unsigned ProfileSlotSelect:1;
unsigned FeedbackDeviceSelect:4;
unsigned OverrideLimitSwitchEn:3;
unsigned RevFeedbackSensor:1;
unsigned RevMotDuringCloseLoopEn:1;
unsigned OverrideBrakeType:2;
unsigned ModeSelect:4;
unsigned RampThrottle:8;
} TALON_Control_5_General_10ms_t ;
typedef struct _TALON_Control_6_MotProfAddTrajPoint_t {
unsigned huffCode:2; //!< Compression coding
unsigned NextPt_VelOnly:1;
unsigned NextPt_IsLast:1;
unsigned reserved0:2;
unsigned NextPt_ZeroPosition:1;
unsigned NextPt_ProfileSlotSelect:1;
unsigned Idx:4;
unsigned reserved1:4;
unsigned restOfFrame0:8;
unsigned restOfFrame1:8;
unsigned restOfFrame2:8;
unsigned restOfFrame3:8;
unsigned restOfFrame4:8;
unsigned restOfFrame5:8;
} TALON_Control_6_MotProfAddTrajPoint_t;
typedef struct _TALON_Control_6_MotProfAddTrajPoint_huff0_t {
unsigned huffCode_expect_0:2; //!< Compression coding
unsigned NextPt_VelOnly:1;
unsigned NextPt_IsLast:1;
unsigned reserved0:2;
unsigned NextPt_ZeroPosition:1;
unsigned NextPt_ProfileSlotSelect:1;
unsigned Idx:4;
unsigned reserved1:4;
unsigned NextPt_DurationMs:8;
unsigned NextPt_VelocityH:8;
unsigned NextPt_VelocityL:8;
unsigned NextPt_PositionH:8;
unsigned NextPt_PositionM:8;
unsigned NextPt_PositionL:8;
} TALON_Control_6_MotProfAddTrajPoint_huff0_t;
typedef struct _TALON_Control_6_MotProfAddTrajPoint_huff1_t {
unsigned huffCode_expect_1:2; //!< Compression coding
unsigned NextPt_VelOnly:1;
unsigned NextPt_IsLast:1;
unsigned reserved0:2;
unsigned NextPt_ZeroPosition:1;
unsigned NextPt_ProfileSlotSelect:1;
unsigned Idx:4;
unsigned reserved1:4;
unsigned NextPt_DurationMs:8;
unsigned NextPt_SameVelocityH:8;
unsigned NextPt_SameVelocityL:8;
unsigned NextPt_DeltaPositionH:8;
unsigned NextPt_DeltaPositionL:8;
unsigned NextPt_Count:8;
} TALON_Control_6_MotProfAddTrajPoint_huff1_t;
/** status */
typedef struct _TALON_Status_1_General_10ms_t {
unsigned CloseLoopErrH:8;
unsigned CloseLoopErrM:8;
unsigned CloseLoopErrL:8;
unsigned AppliedThrottle_h3:3;
unsigned Fault_RevSoftLim:1;
unsigned Fault_ForSoftLim:1;
unsigned TokLocked:1;
unsigned LimitSwitchClosedRev:1;
unsigned LimitSwitchClosedFor:1;
unsigned AppliedThrottle_l8:8;
unsigned ModeSelect_h1:1;
unsigned FeedbackDeviceSelect:4;
unsigned LimitSwitchEn:3;
unsigned Fault_HardwareFailure:1;
unsigned Fault_RevLim:1;
unsigned Fault_ForLim:1;
unsigned Fault_UnderVoltage:1;
unsigned Fault_OverTemp:1;
unsigned ModeSelect_b3:3;
unsigned TokenSeed:8;
} TALON_Status_1_General_10ms_t ;
typedef struct _TALON_Status_2_Feedback_20ms_t {
unsigned SensorPositionH:8;
unsigned SensorPositionM:8;
unsigned SensorPositionL:8;
unsigned SensorVelocityH:8;
unsigned SensorVelocityL:8;
unsigned Current_h8:8;
unsigned StckyFault_RevSoftLim:1;
unsigned StckyFault_ForSoftLim:1;
unsigned StckyFault_RevLim:1;
unsigned StckyFault_ForLim:1;
unsigned StckyFault_UnderVoltage:1;
unsigned StckyFault_OverTemp:1;
unsigned Current_l2:2;
unsigned reserved:3;
unsigned Cmd5Allowed:1;
unsigned VelDiv4:1;
unsigned PosDiv8:1;
unsigned ProfileSlotSelect:1;
unsigned BrakeIsEnabled:1;
} TALON_Status_2_Feedback_20ms_t ;
typedef struct _TALON_Status_3_Enc_100ms_t {
unsigned EncPositionH:8;
unsigned EncPositionM:8;
unsigned EncPositionL:8;
unsigned EncVelH:8;
unsigned EncVelL:8;
unsigned EncIndexRiseEventsH:8;
unsigned EncIndexRiseEventsL:8;
unsigned reserved:3;
unsigned VelDiv4:1;
unsigned PosDiv8:1;
unsigned QuadIdxpin:1;
unsigned QuadBpin:1;
unsigned QuadApin:1;
} TALON_Status_3_Enc_100ms_t ;
typedef struct _TALON_Status_4_AinTempVbat_100ms_t {
unsigned AnalogInWithOvH:8;
unsigned AnalogInWithOvM:8;
unsigned AnalogInWithOvL:8;
unsigned AnalogInVelH:8;
unsigned AnalogInVelL:8;
unsigned Temp:8;
unsigned BatteryV:8;
unsigned reserved:6;
unsigned VelDiv4:1;
unsigned PosDiv8:1;
} TALON_Status_4_AinTempVbat_100ms_t ;
typedef struct _TALON_Status_5_Startup_OneShot_t {
unsigned ResetCountH:8;
unsigned ResetCountL:8;
unsigned ResetFlagsH:8;
unsigned ResetFlagsL:8;
unsigned FirmVersH:8;
unsigned FirmVersL:8;
} TALON_Status_5_Startup_OneShot_t ;
typedef struct _TALON_Status_6_Eol_t {
unsigned currentAdcUncal_h2:2;
unsigned reserved1:5;
unsigned SpiCsPin_GadgeteerPin6:1;
unsigned currentAdcUncal_l8:8;
unsigned tempAdcUncal_h2:2;
unsigned reserved2:6;
unsigned tempAdcUncal_l8:8;
unsigned vbatAdcUncal_h2:2;
unsigned reserved3:6;
unsigned vbatAdcUncal_l8:8;
unsigned analogAdcUncal_h2:2;
unsigned reserved4:6;
unsigned analogAdcUncal_l8:8;
} TALON_Status_6_Eol_t ;
typedef struct _TALON_Status_7_Debug_200ms_t {
unsigned TokenizationFails_h8:8;
unsigned TokenizationFails_l8:8;
unsigned LastFailedToken_h8:8;
unsigned LastFailedToken_l8:8;
unsigned TokenizationSucceses_h8:8;
unsigned TokenizationSucceses_l8:8;
} TALON_Status_7_Debug_200ms_t ;
typedef struct _TALON_Status_8_PulseWid_100ms_t {
unsigned PulseWidPositionH:8;
unsigned PulseWidPositionM:8;
unsigned PulseWidPositionL:8;
unsigned reserved:6;
unsigned VelDiv4:1;
unsigned PosDiv8:1;
unsigned PeriodUsM8:8;
unsigned PeriodUsL8:8;
unsigned PulseWidVelH:8;
unsigned PulseWidVelL:8;
} TALON_Status_8_PulseWid_100ms_t ;
typedef struct _TALON_Status_9_MotProfBuffer_100ms_t {
unsigned ActTraj_IsValid:1; //!< '1' if other ActTraj_* signals are valid. '0' if there is no active trajectory pt.
unsigned ActTraj_ProfileSlotSelect:1;
unsigned ActTraj_VelOnly:1;
unsigned ActTraj_IsLast:1;
unsigned OutputType:2;
unsigned HasUnderrun:1;
unsigned IsUnderrun:1;
unsigned NextID:4;
unsigned reserved1:3;
unsigned BufferIsFull:1;
unsigned Count:8;
unsigned ActTraj_VelocityH:8;
unsigned ActTraj_VelocityL:8;
unsigned ActTraj_PositionH:8;
unsigned ActTraj_PositionM:8;
unsigned ActTraj_PositionL:8;
} TALON_Status_9_MotProfBuffer_100ms_t ;
typedef struct _TALON_Param_Request_t {
unsigned ParamEnum:8;
} TALON_Param_Request_t ;
typedef struct _TALON_Param_Response_t {
unsigned ParamEnum:8;
unsigned ParamValueL:8;
unsigned ParamValueML:8;
unsigned ParamValueMH:8;
unsigned ParamValueH:8;
} TALON_Param_Response_t ;
#endif /* CTRE_FRAMES_H */

View File

@@ -1,34 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HAL/cpp/priority_mutex.h"
#if defined(__linux__)
using namespace hal;
void priority_recursive_mutex::lock() { pthread_mutex_lock(&m_mutex); }
void priority_recursive_mutex::unlock() { pthread_mutex_unlock(&m_mutex); }
bool priority_recursive_mutex::try_lock() noexcept {
return !pthread_mutex_trylock(&m_mutex);
}
pthread_mutex_t* priority_recursive_mutex::native_handle() { return &m_mutex; }
void priority_mutex::lock() { pthread_mutex_lock(&m_mutex); }
void priority_mutex::unlock() { pthread_mutex_unlock(&m_mutex); }
bool priority_mutex::try_lock() noexcept {
return !pthread_mutex_trylock(&m_mutex);
}
pthread_mutex_t* priority_mutex::native_handle() { return &m_mutex; }
#endif

View File

@@ -8,19 +8,19 @@
#include "HAL/handles/HandlesInternal.h"
#include <algorithm>
#include <mutex>
#include <llvm/SmallVector.h>
#include <support/mutex.h>
namespace hal {
static llvm::SmallVector<HandleBase*, 32> globalHandles;
static std::mutex& GetGlobalHandleMutex() {
static std::mutex globalHandleMutex;
static wpi::mutex& GetGlobalHandleMutex() {
static wpi::mutex globalHandleMutex;
return globalHandleMutex;
}
HandleBase::HandleBase() {
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
if (index == globalHandles.end()) {
globalHandles.push_back(this);
@@ -30,7 +30,7 @@ HandleBase::HandleBase() {
}
HandleBase::~HandleBase() {
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
if (index != globalHandles.end()) {
*index = nullptr;
@@ -45,7 +45,7 @@ void HandleBase::ResetHandles() {
}
void HandleBase::ResetGlobalHandles() {
std::unique_lock<std::mutex> lock(GetGlobalHandleMutex());
std::unique_lock<wpi::mutex> lock(GetGlobalHandleMutex());
for (auto&& i : globalHandles) {
if (i != nullptr) {
lock.unlock();

View File

@@ -168,4 +168,4 @@ int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
return 0;
}
}
} // extern "C"

View File

@@ -11,35 +11,32 @@
#include <pthread.h>
#endif
#include <condition_variable>
#include <cstdio>
#include <cstdlib>
#include <mutex>
#include <cstring>
#include <string>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include "MockData/DriverStationDataInternal.h"
#include "MockData/MockHooks.h"
static std::mutex msgMutex;
static std::condition_variable newDSDataAvailableCond;
static std::mutex newDSDataAvailableMutex;
static wpi::mutex msgMutex;
static wpi::condition_variable newDSDataAvailableCond;
static wpi::mutex newDSDataAvailableMutex;
static int newDSDataAvailableCounter{0};
using namespace hal;
extern "C" {
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
int32_t waitMs) {
return 0;
}
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
const char* details, const char* location,
const char* callStack, HAL_Bool printMsg) {
// Avoid flooding console by keeping track of previous 5 error
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;
std::lock_guard<std::mutex> lock(msgMutex);
std::lock_guard<wpi::mutex> lock(msgMutex);
static std::string prevMsg[KEEP_MSGS];
static std::chrono::time_point<std::chrono::steady_clock>
prevMsgTime[KEEP_MSGS];
@@ -103,15 +100,18 @@ HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
}
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
SimDriverStationData.GetJoystickAxes(joystickNum, axes);
return 0;
}
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
SimDriverStationData.GetJoystickPOVs(joystickNum, povs);
return 0;
}
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
HAL_JoystickButtons* buttons) {
SimDriverStationData.GetJoystickButtons(joystickNum, buttons);
return 0;
}
/**
@@ -127,16 +127,29 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
*/
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
HAL_JoystickDescriptor* desc) {
SimDriverStationData.GetJoystickDescriptor(joystickNum, desc);
return 0;
}
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) { return false; }
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) {
HAL_JoystickDescriptor desc;
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
return desc.isXbox;
}
int32_t HAL_GetJoystickType(int32_t joystickNum) { return 0; }
int32_t HAL_GetJoystickType(int32_t joystickNum) {
HAL_JoystickDescriptor desc;
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
return desc.type;
}
char* HAL_GetJoystickName(int32_t joystickNum) {
char* name = static_cast<char*>(std::malloc(1));
name[0] = '\0';
HAL_JoystickDescriptor desc;
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
size_t len = std::strlen(desc.name);
char* name = static_cast<char*>(std::malloc(len + 1));
std::strncpy(name, desc.name, len);
name[len] = '\0';
return name;
}
@@ -146,6 +159,8 @@ int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) { return 0; }
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble, int32_t rightRumble) {
SimDriverStationData.SetJoystickOutputs(joystickNum, outputs, leftRumble,
rightRumble);
return 0;
}
@@ -153,6 +168,15 @@ double HAL_GetMatchTime(int32_t* status) {
return SimDriverStationData.GetMatchTime();
}
int HAL_GetMatchInfo(HAL_MatchInfo* info) {
SimDriverStationData.GetMatchInfo(info);
return 0;
}
void HAL_FreeMatchInfo(HAL_MatchInfo* info) {
SimDriverStationData.FreeMatchInfo(info);
}
void HAL_ObserveUserProgramStarting(void) { HALSIM_SetProgramStarted(); }
void HAL_ObserveUserProgramDisabled(void) {
@@ -197,7 +221,7 @@ bool HAL_IsNewControlData(void) {
// worth the cycles to check.
int currentCount = 0;
{
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
currentCount = newDSDataAvailableCounter;
}
if (lastCount == currentCount) return false;
@@ -219,7 +243,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
auto timeoutTime =
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
int currentCount = newDSDataAvailableCounter;
while (newDSDataAvailableCounter == currentCount) {
if (timeout > 0) {
@@ -241,7 +265,7 @@ static int32_t newDataOccur(uint32_t refNum) {
// Since we could get other values, require our specific handle
// to signal our threads
if (refNum != refNumber) return 0;
std::lock_guard<std::mutex> lock(newDSDataAvailableMutex);
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
// Nofify all threads
newDSDataAvailableCounter++;
newDSDataAvailableCond.notify_all();
@@ -255,11 +279,11 @@ static int32_t newDataOccur(uint32_t refNum) {
*/
void HAL_InitializeDriverStation(void) {
static std::atomic_bool initialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;

View File

@@ -323,4 +323,4 @@ HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
return encoder->encodingType;
}
}
} // extern "C"

View File

@@ -198,11 +198,11 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
static std::atomic_bool initialized{false};
static std::mutex initializeMutex;
static wpi::mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return true;
std::lock_guard<std::mutex> lock(initializeMutex);
std::lock_guard<wpi::mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return true;

View File

@@ -16,14 +16,14 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
SimI2CData[port].SetInitialized(true);
}
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize,
const uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize) {
SimI2CData[port].Write(deviceAddress, dataToSend, sendSize);
SimI2CData[port].Read(deviceAddress, dataReceived, receiveSize);
return 0;
}
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataToSend, int32_t sendSize) {
const uint8_t* dataToSend, int32_t sendSize) {
SimI2CData[port].Write(deviceAddress, dataToSend, sendSize);
return 0;
}

View File

@@ -7,9 +7,10 @@
#include "HAL/Interrupts.h"
#include <condition_variable>
#include <memory>
#include <support/condition_variable.h>
#include "AnalogInternal.h"
#include "DigitalInternal.h"
#include "ErrorsInternal.h"
@@ -53,7 +54,7 @@ struct Interrupt {
struct SynchronousWaitData {
HAL_InterruptHandle interruptHandle;
std::condition_variable waitCond;
wpi::condition_variable waitCond;
HAL_Bool waitPredicate;
};
} // namespace
@@ -97,8 +98,8 @@ void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status) {
static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
const struct HAL_Value* value) {
// void* is a SynchronousWaitDataHandle.
// convert to intptr_t first, then to handle
intptr_t handleTmp = reinterpret_cast<intptr_t>(param);
// convert to uintptr_t first, then to handle
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SynchronousWaitDataHandle handle =
static_cast<SynchronousWaitDataHandle>(handleTmp);
auto interruptData = synchronousInterruptHandles.Get(handle);
@@ -130,8 +131,8 @@ static double GetAnalogTriggerValue(HAL_Handle triggerHandle,
static void ProcessInterruptAnalogSynchronous(const char* name, void* param,
const struct HAL_Value* value) {
// void* is a SynchronousWaitDataHandle.
// convert to intptr_t first, then to handle
intptr_t handleTmp = reinterpret_cast<intptr_t>(param);
// convert to uintptr_t first, then to handle
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SynchronousWaitDataHandle handle =
static_cast<SynchronousWaitDataHandle>(handleTmp);
auto interruptData = synchronousInterruptHandles.Get(handle);
@@ -186,12 +187,12 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
interrupt->previousState = SimDIOData[digitalIndex].GetValue();
int32_t uid = SimDIOData[digitalIndex].RegisterValueCallback(
&ProcessInterruptDigitalSynchronous, reinterpret_cast<void*>(dataHandle),
false);
&ProcessInterruptDigitalSynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(dataHandle)), false);
bool timedOut = false;
std::mutex waitMutex;
wpi::mutex waitMutex;
#if defined(_MSC_VER) && _MSC_VER < 1900
auto timeoutTime = std::chrono::steady_clock::now() +
@@ -203,7 +204,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
#endif
{
std::unique_lock<std::mutex> lock(waitMutex);
std::unique_lock<wpi::mutex> lock(waitMutex);
while (!data->waitPredicate) {
if (data->waitCond.wait_until(lock, timeoutTime) ==
std::cv_status::timeout) {
@@ -256,12 +257,12 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
if (status != 0) return WaitResult::Timeout;
int32_t uid = SimAnalogInData[analogIndex].RegisterVoltageCallback(
&ProcessInterruptAnalogSynchronous, reinterpret_cast<void*>(dataHandle),
false);
&ProcessInterruptAnalogSynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(dataHandle)), false);
bool timedOut = false;
std::mutex waitMutex;
wpi::mutex waitMutex;
#if defined(_MSC_VER) && _MSC_VER < 1900
auto timeoutTime = std::chrono::steady_clock::now() +
@@ -273,7 +274,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
#endif
{
std::unique_lock<std::mutex> lock(waitMutex);
std::unique_lock<wpi::mutex> lock(waitMutex);
while (!data->waitPredicate) {
if (data->waitCond.wait_until(lock, timeoutTime) ==
std::cv_status::timeout) {
@@ -327,8 +328,8 @@ int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
static void ProcessInterruptDigitalAsynchronous(const char* name, void* param,
const struct HAL_Value* value) {
// void* is a HAL handle
// convert to intptr_t first, then to handle
intptr_t handleTmp = reinterpret_cast<intptr_t>(param);
// convert to uintptr_t first, then to handle
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
auto interrupt = interruptHandles.Get(handle);
if (interrupt == nullptr) return;
@@ -360,7 +361,7 @@ static void ProcessInterruptAnalogAsynchronous(const char* name, void* param,
const struct HAL_Value* value) {
// void* is a HAL handle
// convert to intptr_t first, then to handle
intptr_t handleTmp = reinterpret_cast<intptr_t>(param);
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
auto interrupt = interruptHandles.Get(handle);
if (interrupt == nullptr) return;
@@ -400,8 +401,8 @@ static void EnableInterruptsDigital(HAL_InterruptHandle handle,
interrupt->previousState = SimDIOData[digitalIndex].GetValue();
int32_t uid = SimDIOData[digitalIndex].RegisterValueCallback(
&ProcessInterruptDigitalAsynchronous, reinterpret_cast<void*>(handle),
false);
&ProcessInterruptDigitalAsynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(handle)), false);
interrupt->callbackId = uid;
}
@@ -418,8 +419,8 @@ static void EnableInterruptsAnalog(HAL_InterruptHandle handle,
if (status != 0) return;
int32_t uid = SimAnalogInData[analogIndex].RegisterVoltageCallback(
&ProcessInterruptAnalogAsynchronous, reinterpret_cast<void*>(handle),
false);
&ProcessInterruptAnalogAsynchronous,
reinterpret_cast<void*>(static_cast<uintptr_t>(handle)), false);
interrupt->callbackId = uid;
}
@@ -552,4 +553,4 @@ void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
interrupt->fireOnDown = fallingEdge;
interrupt->fireOnUp = risingEdge;
}
}
} // extern "C"

View File

@@ -32,7 +32,7 @@ int32_t AccelerometerData::RegisterActiveCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_activeCallbacks =
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
}
@@ -68,7 +68,7 @@ int32_t AccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rangeCallbacks =
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
}
@@ -104,7 +104,7 @@ int32_t AccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_xCallbacks =
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
}
@@ -140,7 +140,7 @@ int32_t AccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_yCallbacks =
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
}
@@ -176,7 +176,7 @@ int32_t AccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zCallbacks =
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/AccelerometerData.h"
#include "MockData/NotifyListenerVector.h"
@@ -54,7 +56,7 @@ class AccelerometerData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_active{false};
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
std::atomic<HAL_AccelerometerRange> m_range{

View File

@@ -28,7 +28,7 @@ int32_t AnalogGyroData::RegisterAngleCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_angleCallbacks =
RegisterCallback(m_angleCallbacks, "Angle", callback, param, &newUid);
}
@@ -64,7 +64,7 @@ int32_t AnalogGyroData::RegisterRateCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rateCallbacks =
RegisterCallback(m_rateCallbacks, "Rate", callback, param, &newUid);
}
@@ -100,7 +100,7 @@ int32_t AnalogGyroData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/AnalogGyroData.h"
#include "MockData/NotifyListenerVector.h"
@@ -40,7 +42,7 @@ class AnalogGyroData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<double> m_angle{0.0};
std::shared_ptr<NotifyListenerVector> m_angleCallbacks = nullptr;
std::atomic<double> m_rate{0.0};

View File

@@ -40,7 +40,7 @@ int32_t AnalogInData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -76,7 +76,7 @@ int32_t AnalogInData::RegisterAverageBitsCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_averageBitsCallbacks = RegisterCallback(
m_averageBitsCallbacks, "AverageBits", callback, param, &newUid);
}
@@ -111,7 +111,7 @@ int32_t AnalogInData::RegisterOversampleBitsCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_oversampleBitsCallbacks = RegisterCallback(
m_oversampleBitsCallbacks, "OversampleBits", callback, param, &newUid);
}
@@ -147,7 +147,7 @@ int32_t AnalogInData::RegisterVoltageCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
@@ -182,7 +182,7 @@ int32_t AnalogInData::RegisterAccumulatorInitializedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorInitializedCallbacks =
RegisterCallback(m_accumulatorInitializedCallbacks,
"AccumulatorInitialized", callback, param, &newUid);
@@ -222,7 +222,7 @@ int32_t AnalogInData::RegisterAccumulatorValueCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorValueCallbacks =
RegisterCallback(m_accumulatorValueCallbacks, "AccumulatorValue",
callback, param, &newUid);
@@ -259,7 +259,7 @@ int32_t AnalogInData::RegisterAccumulatorCountCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorCountCallbacks =
RegisterCallback(m_accumulatorCountCallbacks, "AccumulatorCount",
callback, param, &newUid);
@@ -296,7 +296,7 @@ int32_t AnalogInData::RegisterAccumulatorCenterCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorCenterCallbacks =
RegisterCallback(m_accumulatorCenterCallbacks, "AccumulatorCenter",
callback, param, &newUid);
@@ -333,7 +333,7 @@ int32_t AnalogInData::RegisterAccumulatorDeadbandCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_accumulatorDeadbandCallbacks =
RegisterCallback(m_accumulatorDeadbandCallbacks, "AccumulatorDeadband",
callback, param, &newUid);

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/AnalogInData.h"
#include "MockData/NotifyListenerVector.h"
@@ -85,7 +87,7 @@ class AnalogInData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_averageBits{7};

View File

@@ -26,7 +26,7 @@ int32_t AnalogOutData::RegisterVoltageCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
@@ -62,7 +62,7 @@ int32_t AnalogOutData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/AnalogOutData.h"
#include "MockData/NotifyListenerVector.h"
@@ -33,7 +35,7 @@ class AnalogOutData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<double> m_voltage{0.0};
std::shared_ptr<NotifyListenerVector> m_voltageCallbacks = nullptr;
std::atomic<HAL_Bool> m_initialized{0};

View File

@@ -29,7 +29,7 @@ int32_t AnalogTriggerData::RegisterInitializedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -64,7 +64,7 @@ int32_t AnalogTriggerData::RegisterTriggerLowerBoundCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerLowerBoundCallbacks =
RegisterCallback(m_triggerLowerBoundCallbacks, "TriggerLowerBound",
callback, param, &newUid);
@@ -101,7 +101,7 @@ int32_t AnalogTriggerData::RegisterTriggerUpperBoundCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerUpperBoundCallbacks =
RegisterCallback(m_triggerUpperBoundCallbacks, "TriggerUpperBound",
callback, param, &newUid);
@@ -138,7 +138,7 @@ int32_t AnalogTriggerData::RegisterTriggerModeCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_triggerModeCallbacks = RegisterCallback(
m_triggerModeCallbacks, "TriggerMode", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/AnalogTriggerData.h"
#include "MockData/NotifyListenerVector.h"
@@ -49,7 +51,7 @@ class AnalogTriggerData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{0};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_triggerLowerBound{0};

View File

@@ -32,7 +32,7 @@ int32_t DIOData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -67,7 +67,7 @@ int32_t DIOData::RegisterValueCallback(HAL_NotifyCallback callback, void* param,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_valueCallbacks =
RegisterCallback(m_valueCallbacks, "Value", callback, param, &newUid);
}
@@ -103,7 +103,7 @@ int32_t DIOData::RegisterPulseLengthCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pulseLengthCallbacks = RegisterCallback(
m_pulseLengthCallbacks, "PulseLength", callback, param, &newUid);
}
@@ -138,7 +138,7 @@ int32_t DIOData::RegisterIsInputCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_isInputCallbacks = RegisterCallback(m_isInputCallbacks, "IsInput",
callback, param, &newUid);
}
@@ -174,7 +174,7 @@ int32_t DIOData::RegisterFilterIndexCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_filterIndexCallbacks = RegisterCallback(
m_filterIndexCallbacks, "FilterIndex", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/DIOData.h"
#include "MockData/NotifyListenerVector.h"
@@ -54,7 +56,7 @@ class DIOData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<HAL_Bool> m_value{true};

View File

@@ -28,7 +28,7 @@ int32_t DigitalPWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -64,7 +64,7 @@ int32_t DigitalPWMData::RegisterDutyCycleCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_dutyCycleCallbacks = RegisterCallback(m_dutyCycleCallbacks, "DutyCycle",
callback, param, &newUid);
}
@@ -100,7 +100,7 @@ int32_t DigitalPWMData::RegisterPinCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pinCallbacks =
RegisterCallback(m_pinCallbacks, "Pin", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/DigitalPWMData.h"
#include "MockData/NotifyListenerVector.h"
@@ -40,7 +42,7 @@ class DigitalPWMData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_dutyCycle{false};

View File

@@ -5,13 +5,35 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cstdlib>
#include <cstring>
#include <string>
#include "DriverStationDataInternal.h"
#include "HAL/cpp/make_unique.h"
#include "NotifyCallbackHelpers.h"
namespace hal {
struct JoystickOutputStore {
int64_t outputs = 0;
int32_t leftRumble = 0;
int32_t rightRumble = 0;
};
struct MatchInfoDataStore {
std::string eventName;
std::string gameSpecificMessage;
int32_t replayNumber = 0;
int32_t matchNumber = 0;
HAL_MatchType matchType = HAL_MatchType::HAL_kMatchType_none;
};
} // namespace hal
using namespace hal;
DriverStationData hal::SimDriverStationData;
DriverStationData::DriverStationData() { ResetData(); }
void DriverStationData::ResetData() {
m_enabled = false;
m_enabledCallbacks = nullptr;
@@ -25,6 +47,29 @@ void DriverStationData::ResetData() {
m_fmsAttachedCallbacks = nullptr;
m_dsAttached = false;
m_dsAttachedCallbacks = nullptr;
{
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickAxes = std::make_unique<HAL_JoystickAxes[]>(6);
m_joystickPOVs = std::make_unique<HAL_JoystickPOVs[]>(6);
m_joystickButtons = std::make_unique<HAL_JoystickButtons[]>(6);
m_joystickOutputs = std::make_unique<JoystickOutputStore[]>(6);
m_joystickDescriptor = std::make_unique<HAL_JoystickDescriptor[]>(6);
for (int i = 0; i < 6; i++) {
m_joystickAxes[i].count = 0;
m_joystickPOVs[i].count = 0;
m_joystickButtons[i].count = 0;
m_joystickDescriptor[i].isXbox = 0;
m_joystickDescriptor[i].type = -1;
m_joystickDescriptor[i].name[0] = '\0';
}
}
{
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
m_matchInfo = std::make_unique<MatchInfoDataStore>();
}
}
int32_t DriverStationData::RegisterEnabledCallback(HAL_NotifyCallback callback,
@@ -34,7 +79,7 @@ int32_t DriverStationData::RegisterEnabledCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_enabledCallbacks = RegisterCallback(m_enabledCallbacks, "Enabled",
callback, param, &newUid);
}
@@ -69,7 +114,7 @@ int32_t DriverStationData::RegisterAutonomousCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_autonomousCallbacks = RegisterCallback(
m_autonomousCallbacks, "Autonomous", callback, param, &newUid);
}
@@ -105,7 +150,7 @@ int32_t DriverStationData::RegisterTestCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_testCallbacks =
RegisterCallback(m_testCallbacks, "Test", callback, param, &newUid);
}
@@ -141,7 +186,7 @@ int32_t DriverStationData::RegisterEStopCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_eStopCallbacks =
RegisterCallback(m_eStopCallbacks, "EStop", callback, param, &newUid);
}
@@ -176,7 +221,7 @@ int32_t DriverStationData::RegisterFmsAttachedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_fmsAttachedCallbacks = RegisterCallback(
m_fmsAttachedCallbacks, "FmsAttached", callback, param, &newUid);
}
@@ -211,7 +256,7 @@ int32_t DriverStationData::RegisterDsAttachedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_dsAttachedCallbacks = RegisterCallback(
m_dsAttachedCallbacks, "DsAttached", callback, param, &newUid);
}
@@ -246,7 +291,7 @@ int32_t DriverStationData::RegisterAllianceStationIdCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_allianceStationIdCallbacks =
RegisterCallback(m_allianceStationIdCallbacks, "AllianceStationId",
callback, param, &newUid);
@@ -287,7 +332,7 @@ int32_t DriverStationData::RegisterMatchTimeCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_matchTimeCallbacks = RegisterCallback(m_matchTimeCallbacks, "MatchTime",
callback, param, &newUid);
}
@@ -316,6 +361,97 @@ void DriverStationData::SetMatchTime(double matchTime) {
}
}
void DriverStationData::GetJoystickAxes(int32_t joystickNum,
HAL_JoystickAxes* axes) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
*axes = m_joystickAxes[joystickNum];
}
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
HAL_JoystickPOVs* povs) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
*povs = m_joystickPOVs[joystickNum];
}
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
HAL_JoystickButtons* buttons) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
*buttons = m_joystickButtons[joystickNum];
}
void DriverStationData::GetJoystickDescriptor(
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
*descriptor = m_joystickDescriptor[joystickNum];
// Always ensure name is null terminated
descriptor->name[255] = '\0';
}
void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
int64_t* outputs,
int32_t* leftRumble,
int32_t* rightRumble) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
*leftRumble = m_joystickOutputs[joystickNum].leftRumble;
*outputs = m_joystickOutputs[joystickNum].outputs;
*rightRumble = m_joystickOutputs[joystickNum].rightRumble;
}
void DriverStationData::GetMatchInfo(HAL_MatchInfo* info) {
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
auto eventLen = m_matchInfo->eventName.size();
info->eventName = static_cast<char*>(std::malloc(eventLen + 1));
std::memcpy(info->eventName, m_matchInfo->eventName.c_str(), eventLen);
auto gameLen = m_matchInfo->gameSpecificMessage.size();
info->gameSpecificMessage = static_cast<char*>(std::malloc(gameLen + 1));
std::memcpy(info->gameSpecificMessage,
m_matchInfo->gameSpecificMessage.c_str(), gameLen);
info->gameSpecificMessage[gameLen] = '\0';
info->eventName[eventLen] = '\0';
info->matchNumber = m_matchInfo->matchNumber;
info->replayNumber = m_matchInfo->replayNumber;
info->matchType = m_matchInfo->matchType;
}
void DriverStationData::FreeMatchInfo(const HAL_MatchInfo* info) {
std::free(info->eventName);
std::free(info->gameSpecificMessage);
}
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
const HAL_JoystickAxes* axes) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickAxes[joystickNum] = *axes;
}
void DriverStationData::SetJoystickPOVs(int32_t joystickNum,
const HAL_JoystickPOVs* povs) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickPOVs[joystickNum] = *povs;
}
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickButtons[joystickNum] = *buttons;
}
void DriverStationData::SetJoystickDescriptor(
int32_t joystickNum, const HAL_JoystickDescriptor* descriptor) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickDescriptor[joystickNum] = *descriptor;
}
void DriverStationData::SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble,
int32_t rightRumble) {
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
m_joystickOutputs[joystickNum].leftRumble = leftRumble;
m_joystickOutputs[joystickNum].outputs = outputs;
m_joystickOutputs[joystickNum].rightRumble = rightRumble;
}
void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
m_matchInfo->eventName = info->eventName;
m_matchInfo->gameSpecificMessage = info->gameSpecificMessage;
m_matchInfo->matchNumber = info->matchNumber;
m_matchInfo->matchType = info->matchType;
m_matchInfo->replayNumber = info->replayNumber;
}
void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
extern "C" {
@@ -445,6 +581,33 @@ void HALSIM_SetDriverStationMatchTime(double matchTime) {
SimDriverStationData.SetMatchTime(matchTime);
}
void HALSIM_SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes) {
SimDriverStationData.SetJoystickAxes(joystickNum, axes);
}
void HALSIM_SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs) {
SimDriverStationData.SetJoystickPOVs(joystickNum, povs);
}
void HALSIM_SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons) {
SimDriverStationData.SetJoystickButtons(joystickNum, buttons);
}
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
const HAL_JoystickDescriptor* descriptor) {
SimDriverStationData.SetJoystickDescriptor(joystickNum, descriptor);
}
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
int32_t* leftRumble, int32_t* rightRumble) {
SimDriverStationData.GetJoystickOutputs(joystickNum, outputs, leftRumble,
rightRumble);
}
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {
SimDriverStationData.SetMatchInfo(info);
}
void HALSIM_NotifyDriverStationNewData(void) {
SimDriverStationData.NotifyNewData();
}

View File

@@ -7,15 +7,22 @@
#pragma once
#include <array>
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/DriverStationData.h"
#include "MockData/NotifyListenerVector.h"
namespace hal {
struct JoystickOutputStore;
struct MatchInfoDataStore;
class DriverStationData {
public:
DriverStationData();
void ResetData();
int32_t RegisterEnabledCallback(HAL_NotifyCallback callback, void* param,
@@ -75,10 +82,30 @@ class DriverStationData {
double GetMatchTime();
void SetMatchTime(double matchTime);
void GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
void GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
void GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons* buttons);
void GetJoystickDescriptor(int32_t joystickNum,
HAL_JoystickDescriptor* descriptor);
void GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
int32_t* leftRumble, int32_t* rightRumble);
void GetMatchInfo(HAL_MatchInfo* info);
void FreeMatchInfo(const HAL_MatchInfo* info);
void SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes);
void SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs);
void SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons);
void SetJoystickDescriptor(int32_t joystickNum,
const HAL_JoystickDescriptor* descriptor);
void SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble, int32_t rightRumble);
void SetMatchInfo(const HAL_MatchInfo* info);
void NotifyNewData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_enabled{false};
std::shared_ptr<NotifyListenerVector> m_enabledCallbacks = nullptr;
std::atomic<HAL_Bool> m_autonomous{false};
@@ -96,6 +123,17 @@ class DriverStationData {
std::shared_ptr<NotifyListenerVector> m_allianceStationIdCallbacks = nullptr;
std::atomic<double> m_matchTime{0.0};
std::shared_ptr<NotifyListenerVector> m_matchTimeCallbacks = nullptr;
wpi::mutex m_joystickDataMutex;
wpi::mutex m_matchInfoMutex;
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
std::unique_ptr<JoystickOutputStore[]> m_joystickOutputs;
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
std::unique_ptr<MatchInfoDataStore> m_matchInfo;
};
extern DriverStationData SimDriverStationData;
} // namespace hal

View File

@@ -38,7 +38,7 @@ int32_t EncoderData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -74,7 +74,7 @@ int32_t EncoderData::RegisterCountCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_countCallbacks =
RegisterCallback(m_countCallbacks, "Count", callback, param, &newUid);
}
@@ -110,7 +110,7 @@ int32_t EncoderData::RegisterPeriodCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_periodCallbacks =
RegisterCallback(m_periodCallbacks, "Period", callback, param, &newUid);
}
@@ -146,7 +146,7 @@ int32_t EncoderData::RegisterResetCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_resetCallbacks =
RegisterCallback(m_resetCallbacks, "Reset", callback, param, &newUid);
}
@@ -182,7 +182,7 @@ int32_t EncoderData::RegisterMaxPeriodCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_maxPeriodCallbacks = RegisterCallback(m_maxPeriodCallbacks, "MaxPeriod",
callback, param, &newUid);
}
@@ -218,7 +218,7 @@ int32_t EncoderData::RegisterDirectionCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_directionCallbacks = RegisterCallback(m_directionCallbacks, "Direction",
callback, param, &newUid);
}
@@ -253,7 +253,7 @@ int32_t EncoderData::RegisterReverseDirectionCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_reverseDirectionCallbacks =
RegisterCallback(m_reverseDirectionCallbacks, "ReverseDirection",
callback, param, &newUid);
@@ -290,7 +290,7 @@ int32_t EncoderData::RegisterSamplesToAverageCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_samplesToAverageCallbacks =
RegisterCallback(m_samplesToAverageCallbacks, "SamplesToAverage",
callback, param, &newUid);

View File

@@ -11,6 +11,8 @@
#include <limits>
#include <memory>
#include <support/mutex.h>
#include "MockData/EncoderData.h"
#include "MockData/NotifyListenerVector.h"
@@ -76,7 +78,7 @@ class EncoderData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_count{0};

View File

@@ -34,7 +34,7 @@ int32_t I2CData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -69,7 +69,7 @@ int32_t I2CData::RegisterReadCallback(HAL_BufferCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_readCallbacks =
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
}
@@ -80,13 +80,13 @@ void I2CData::CancelReadCallback(int32_t uid) {
m_readCallbacks = CancelCallback(m_readCallbacks, uid);
}
int32_t I2CData::RegisterWriteCallback(HAL_BufferCallback callback,
int32_t I2CData::RegisterWriteCallback(HAL_ConstBufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_writeCallbacks =
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
}
@@ -97,13 +97,14 @@ void I2CData::CancelWriteCallback(int32_t uid) {
m_writeCallbacks = CancelCallback(m_writeCallbacks, uid);
}
void I2CData::Write(int32_t deviceAddress, uint8_t* dataToSend,
void I2CData::Write(int32_t deviceAddress, const uint8_t* dataToSend,
int32_t sendSize) {
std::lock_guard<std::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", dataToSend, sendSize);
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", const_cast<uint8_t*>(dataToSend),
sendSize);
}
void I2CData::Read(int32_t deviceAddress, uint8_t* buffer, int32_t count) {
std::lock_guard<std::mutex> lock(m_dataMutex);
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_readCallbacks, "Read", buffer, count);
}
@@ -140,7 +141,7 @@ void HALSIM_CancelI2CReadCallback(int32_t index, int32_t uid) {
}
int32_t HALSIM_RegisterI2CWriteCallback(int32_t index,
HAL_BufferCallback callback,
HAL_ConstBufferCallback callback,
void* param) {
return SimI2CData[index].RegisterWriteCallback(callback, param);
}

View File

@@ -11,6 +11,8 @@
#include <limits>
#include <memory>
#include <support/mutex.h>
#include "MockData/I2CData.h"
#include "MockData/NotifyListenerVector.h"
@@ -30,21 +32,22 @@ class I2CData {
int32_t RegisterReadCallback(HAL_BufferCallback callback, void* param);
void CancelReadCallback(int32_t uid);
int32_t RegisterWriteCallback(HAL_BufferCallback callback, void* param);
int32_t RegisterWriteCallback(HAL_ConstBufferCallback callback, void* param);
void CancelWriteCallback(int32_t uid);
void Write(int32_t deviceAddress, uint8_t* dataToSend, int32_t sendSize);
void Write(int32_t deviceAddress, const uint8_t* dataToSend,
int32_t sendSize);
void Read(int32_t deviceAddress, uint8_t* buffer, int32_t count);
void ResetData();
private:
std::mutex m_registerMutex;
std::mutex m_dataMutex;
wpi::mutex m_registerMutex;
wpi::mutex m_dataMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_writeCallbacks = nullptr;
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
};
extern I2CData SimI2CData[];
} // namespace hal

View File

@@ -83,3 +83,30 @@ void InvokeCallback(std::shared_ptr<BufferListenerVector> currentVector,
listener.callback(name, listener.param, buffer, count);
}
}
std::shared_ptr<ConstBufferListenerVector> RegisterCallback(
std::shared_ptr<ConstBufferListenerVector> currentVector, const char* name,
HAL_ConstBufferCallback callback, void* param, int32_t* newUid) {
return RegisterCallbackImpl<ConstBufferListenerVector,
HAL_ConstBufferCallback>(currentVector, name,
callback, param, newUid);
}
std::shared_ptr<ConstBufferListenerVector> CancelCallback(
std::shared_ptr<ConstBufferListenerVector> currentVector, int32_t uid) {
return CancelCallbackImpl<ConstBufferListenerVector, HAL_ConstBufferCallback>(
currentVector, uid);
}
void InvokeCallback(std::shared_ptr<ConstBufferListenerVector> currentVector,
const char* name, const uint8_t* buffer, int32_t count) {
// Return if no callbacks are assigned
if (currentVector == nullptr) return;
// Get a copy of the shared_ptr, then iterate and callback listeners
auto newCallbacks = currentVector;
for (size_t i = 0; i < newCallbacks->size(); ++i) {
if (!(*newCallbacks)[i]) continue; // removed
auto listener = (*newCallbacks)[i];
listener.callback(name, listener.param, buffer, count);
}
}

View File

@@ -30,3 +30,15 @@ std::shared_ptr<hal::BufferListenerVector> CancelCallback(
void InvokeCallback(std::shared_ptr<hal::BufferListenerVector> currentVector,
const char* name, uint8_t* buffer, int32_t count);
std::shared_ptr<hal::ConstBufferListenerVector> RegisterCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
const char* name, HAL_ConstBufferCallback callback, void* param,
int32_t* newUid);
std::shared_ptr<hal::ConstBufferListenerVector> CancelCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector, int32_t uid);
void InvokeCallback(
std::shared_ptr<hal::ConstBufferListenerVector> currentVector,
const char* name, const uint8_t* buffer, int32_t count);

View File

@@ -38,7 +38,7 @@ int32_t PCMData::RegisterSolenoidInitializedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_solenoidInitializedCallbacks[channel] =
RegisterCallback(m_solenoidInitializedCallbacks[channel],
"SolenoidInitialized", callback, param, &newUid);
@@ -84,7 +84,7 @@ int32_t PCMData::RegisterSolenoidOutputCallback(int32_t channel,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_solenoidOutputCallbacks[channel] =
RegisterCallback(m_solenoidOutputCallbacks[channel], "SolenoidOutput",
callback, param, &newUid);
@@ -123,7 +123,7 @@ int32_t PCMData::RegisterCompressorInitializedCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorInitializedCallbacks =
RegisterCallback(m_compressorInitializedCallbacks,
"CompressorInitialized", callback, param, &newUid);
@@ -162,7 +162,7 @@ int32_t PCMData::RegisterCompressorOnCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorOnCallbacks = RegisterCallback(
m_compressorOnCallbacks, "CompressorOn", callback, param, &newUid);
}
@@ -198,7 +198,7 @@ int32_t PCMData::RegisterClosedLoopEnabledCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_closedLoopEnabledCallbacks =
RegisterCallback(m_closedLoopEnabledCallbacks, "ClosedLoopEnabled",
callback, param, &newUid);
@@ -236,7 +236,7 @@ int32_t PCMData::RegisterPressureSwitchCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_pressureSwitchCallbacks = RegisterCallback(
m_pressureSwitchCallbacks, "PressureSwitch", callback, param, &newUid);
}
@@ -272,7 +272,7 @@ int32_t PCMData::RegisterCompressorCurrentCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_compressorCurrentCallbacks =
RegisterCallback(m_compressorCurrentCallbacks, "CompressorCurrent",
callback, param, &newUid);

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "../PortsInternal.h"
#include "MockData/NotifyListenerVector.h"
#include "MockData/PCMData.h"
@@ -75,7 +77,7 @@ class PCMData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_solenoidInitialized[kNumSolenoidChannels];
std::shared_ptr<NotifyListenerVector>
m_solenoidInitializedCallbacks[kNumSolenoidChannels];

View File

@@ -32,7 +32,7 @@ int32_t PDPData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -68,7 +68,7 @@ int32_t PDPData::RegisterTemperatureCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_temperatureCallbacks = RegisterCallback(
m_temperatureCallbacks, "Temperature", callback, param, &newUid);
}
@@ -103,7 +103,7 @@ int32_t PDPData::RegisterVoltageCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
callback, param, &newUid);
}
@@ -139,7 +139,7 @@ int32_t PDPData::RegisterCurrentCallback(int32_t channel,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_currentCallbacks[channel] = RegisterCallback(
m_currentCallbacks[channel], "Current", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "../PortsInternal.h"
#include "MockData/NotifyListenerVector.h"
#include "MockData/PDPData.h"
@@ -48,7 +50,7 @@ class PDPData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<double> m_temperature{0.0};

View File

@@ -34,7 +34,7 @@ int32_t PWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -69,7 +69,7 @@ int32_t PWMData::RegisterRawValueCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rawValueCallbacks = RegisterCallback(m_rawValueCallbacks, "RawValue",
callback, param, &newUid);
}
@@ -104,7 +104,7 @@ int32_t PWMData::RegisterSpeedCallback(HAL_NotifyCallback callback, void* param,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_speedCallbacks =
RegisterCallback(m_speedCallbacks, "Speed", callback, param, &newUid);
}
@@ -139,7 +139,7 @@ int32_t PWMData::RegisterPositionCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_positionCallbacks = RegisterCallback(m_positionCallbacks, "Position",
callback, param, &newUid);
}
@@ -175,7 +175,7 @@ int32_t PWMData::RegisterPeriodScaleCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_periodScaleCallbacks = RegisterCallback(
m_periodScaleCallbacks, "PeriodScale", callback, param, &newUid);
}
@@ -211,7 +211,7 @@ int32_t PWMData::RegisterZeroLatchCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zeroLatchCallbacks = RegisterCallback(m_zeroLatchCallbacks, "ZeroLatch",
callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/NotifyListenerVector.h"
#include "MockData/PWMData.h"
@@ -61,7 +63,7 @@ class PWMData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::atomic<int32_t> m_rawValue{0};

View File

@@ -29,7 +29,7 @@ int32_t RelayData::RegisterInitializedForwardCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedForwardCallbacks =
RegisterCallback(m_initializedForwardCallbacks, "InitializedForward",
callback, param, &newUid);
@@ -66,7 +66,7 @@ int32_t RelayData::RegisterInitializedReverseCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedReverseCallbacks =
RegisterCallback(m_initializedReverseCallbacks, "InitializedReverse",
callback, param, &newUid);
@@ -104,7 +104,7 @@ int32_t RelayData::RegisterForwardCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_forwardCallbacks = RegisterCallback(m_forwardCallbacks, "Forward",
callback, param, &newUid);
}
@@ -140,7 +140,7 @@ int32_t RelayData::RegisterReverseCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_reverseCallbacks = RegisterCallback(m_reverseCallbacks, "Reverse",
callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/NotifyListenerVector.h"
#include "MockData/RelayData.h"
@@ -49,7 +51,7 @@ class RelayData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_initializedForward{false};
std::shared_ptr<NotifyListenerVector> m_initializedForwardCallbacks = nullptr;
std::atomic<HAL_Bool> m_initializedReverse{false};

View File

@@ -52,7 +52,7 @@ int32_t RoboRioData::RegisterFPGAButtonCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_fPGAButtonCallbacks = RegisterCallback(
m_fPGAButtonCallbacks, "FPGAButton", callback, param, &newUid);
}
@@ -88,7 +88,7 @@ int32_t RoboRioData::RegisterVInVoltageCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_vInVoltageCallbacks = RegisterCallback(
m_vInVoltageCallbacks, "VInVoltage", callback, param, &newUid);
}
@@ -124,7 +124,7 @@ int32_t RoboRioData::RegisterVInCurrentCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_vInCurrentCallbacks = RegisterCallback(
m_vInCurrentCallbacks, "VInCurrent", callback, param, &newUid);
}
@@ -160,7 +160,7 @@ int32_t RoboRioData::RegisterUserVoltage6VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage6VCallbacks = RegisterCallback(
m_userVoltage6VCallbacks, "UserVoltage6V", callback, param, &newUid);
}
@@ -196,7 +196,7 @@ int32_t RoboRioData::RegisterUserCurrent6VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent6VCallbacks = RegisterCallback(
m_userCurrent6VCallbacks, "UserCurrent6V", callback, param, &newUid);
}
@@ -232,7 +232,7 @@ int32_t RoboRioData::RegisterUserActive6VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive6VCallbacks = RegisterCallback(
m_userActive6VCallbacks, "UserActive6V", callback, param, &newUid);
}
@@ -268,7 +268,7 @@ int32_t RoboRioData::RegisterUserVoltage5VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage5VCallbacks = RegisterCallback(
m_userVoltage5VCallbacks, "UserVoltage5V", callback, param, &newUid);
}
@@ -304,7 +304,7 @@ int32_t RoboRioData::RegisterUserCurrent5VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent5VCallbacks = RegisterCallback(
m_userCurrent5VCallbacks, "UserCurrent5V", callback, param, &newUid);
}
@@ -340,7 +340,7 @@ int32_t RoboRioData::RegisterUserActive5VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive5VCallbacks = RegisterCallback(
m_userActive5VCallbacks, "UserActive5V", callback, param, &newUid);
}
@@ -376,7 +376,7 @@ int32_t RoboRioData::RegisterUserVoltage3V3Callback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userVoltage3V3Callbacks = RegisterCallback(
m_userVoltage3V3Callbacks, "UserVoltage3V3", callback, param, &newUid);
}
@@ -412,7 +412,7 @@ int32_t RoboRioData::RegisterUserCurrent3V3Callback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userCurrent3V3Callbacks = RegisterCallback(
m_userCurrent3V3Callbacks, "UserCurrent3V3", callback, param, &newUid);
}
@@ -448,7 +448,7 @@ int32_t RoboRioData::RegisterUserActive3V3Callback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userActive3V3Callbacks = RegisterCallback(
m_userActive3V3Callbacks, "UserActive3V3", callback, param, &newUid);
}
@@ -484,7 +484,7 @@ int32_t RoboRioData::RegisterUserFaults6VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults6VCallbacks = RegisterCallback(
m_userFaults6VCallbacks, "UserFaults6V", callback, param, &newUid);
}
@@ -520,7 +520,7 @@ int32_t RoboRioData::RegisterUserFaults5VCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults5VCallbacks = RegisterCallback(
m_userFaults5VCallbacks, "UserFaults5V", callback, param, &newUid);
}
@@ -556,7 +556,7 @@ int32_t RoboRioData::RegisterUserFaults3V3Callback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_userFaults3V3Callbacks = RegisterCallback(
m_userFaults3V3Callbacks, "UserFaults3V3", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/NotifyListenerVector.h"
#include "MockData/RoboRioData.h"
@@ -124,7 +126,7 @@ class RoboRioData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_fPGAButton{false};
std::shared_ptr<NotifyListenerVector> m_fPGAButtonCallbacks = nullptr;
std::atomic<double> m_vInVoltage{0.0};

View File

@@ -31,7 +31,7 @@ int32_t SPIAccelerometerData::RegisterActiveCallback(
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_activeCallbacks =
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
}
@@ -67,7 +67,7 @@ int32_t SPIAccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_rangeCallbacks =
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
}
@@ -103,7 +103,7 @@ int32_t SPIAccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_xCallbacks =
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
}
@@ -139,7 +139,7 @@ int32_t SPIAccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_yCallbacks =
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
}
@@ -175,7 +175,7 @@ int32_t SPIAccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_zCallbacks =
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
}

View File

@@ -10,6 +10,8 @@
#include <atomic>
#include <memory>
#include <support/mutex.h>
#include "MockData/NotifyListenerVector.h"
#include "MockData/SPIAccelerometerData.h"
@@ -54,7 +56,7 @@ class SPIAccelerometerData {
virtual void ResetData();
private:
std::mutex m_registerMutex;
wpi::mutex m_registerMutex;
std::atomic<HAL_Bool> m_active{false};
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
std::atomic<int32_t> m_range{0};

View File

@@ -35,7 +35,7 @@ int32_t SPIData::RegisterInitializedCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_initializedCallbacks = RegisterCallback(
m_initializedCallbacks, "Initialized", callback, param, &newUid);
}
@@ -70,7 +70,7 @@ int32_t SPIData::RegisterReadCallback(HAL_BufferCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_readCallbacks =
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
}
@@ -82,13 +82,13 @@ void SPIData::CancelReadCallback(int32_t uid) {
m_readCallbacks = CancelCallback(m_readCallbacks, uid);
}
int32_t SPIData::RegisterWriteCallback(HAL_BufferCallback callback,
int32_t SPIData::RegisterWriteCallback(HAL_ConstBufferCallback callback,
void* param) {
// Must return -1 on a null callback for error handling
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_writeCallbacks =
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
}
@@ -107,7 +107,7 @@ int32_t SPIData::RegisterResetAccumulatorCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_resetAccumulatorCallback =
RegisterCallback(m_resetAccumulatorCallback, "ResetAccumulator",
callback, param, &newUid);
@@ -131,7 +131,7 @@ int32_t SPIData::RegisterAccumulatorCallback(HAL_NotifyCallback callback,
if (callback == nullptr) return -1;
int32_t newUid = 0;
{
std::lock_guard<std::mutex> lock(m_registerMutex);
std::lock_guard<wpi::mutex> lock(m_registerMutex);
m_setAccumulatorCallback = RegisterCallback(
m_setAccumulatorCallback, "SetAccumulator", callback, param, &newUid);
}
@@ -161,22 +161,23 @@ void SPIData::SetAccumulatorValue(int64_t value) {
int64_t SPIData::GetAccumulatorValue() { return m_accumulatorValue; }
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
std::lock_guard<std::mutex> lock(m_dataMutex);
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_readCallbacks, "Read", buffer, count);
return count;
}
int32_t SPIData::Write(uint8_t* dataToSend, int32_t sendSize) {
std::lock_guard<std::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", dataToSend, sendSize);
int32_t SPIData::Write(const uint8_t* dataToSend, int32_t sendSize) {
std::lock_guard<wpi::mutex> lock(m_dataMutex);
InvokeCallback(m_writeCallbacks, "Write", const_cast<uint8_t*>(dataToSend),
sendSize);
return sendSize;
}
int32_t SPIData::Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
int32_t SPIData::Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size) {
std::lock_guard<std::mutex> lock(m_dataMutex);
std::lock_guard<wpi::mutex> lock(m_dataMutex);
return size;
}
@@ -218,7 +219,7 @@ void HALSIM_CancelSPIReadCallback(int32_t index, int32_t uid) {
}
int32_t HALSIM_RegisterSPIWriteCallback(int32_t index,
HAL_BufferCallback callback,
HAL_ConstBufferCallback callback,
void* param) {
return SimSPIData[index].RegisterWriteCallback(callback, param);
}

View File

@@ -11,6 +11,8 @@
#include <limits>
#include <memory>
#include <support/mutex.h>
#include "MockData/NotifyListenerVector.h"
#include "MockData/SPIData.h"
@@ -30,7 +32,7 @@ class SPIData {
int32_t RegisterReadCallback(HAL_BufferCallback callback, void* param);
void CancelReadCallback(int32_t uid);
int32_t RegisterWriteCallback(HAL_BufferCallback callback, void* param);
int32_t RegisterWriteCallback(HAL_ConstBufferCallback callback, void* param);
void CancelWriteCallback(int32_t uid);
int32_t RegisterResetAccumulatorCallback(HAL_NotifyCallback callback,
@@ -45,20 +47,21 @@ class SPIData {
int64_t GetAccumulatorValue();
int32_t Read(uint8_t* buffer, int32_t count);
int32_t Write(uint8_t* dataToSend, int32_t sendSize);
int32_t Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int32_t size);
int32_t Write(const uint8_t* dataToSend, int32_t sendSize);
int32_t Transaction(const uint8_t* dataToSend, uint8_t* dataReceived,
int32_t size);
void ResetAccumulator();
void ResetData();
private:
std::mutex m_registerMutex;
std::mutex m_dataMutex;
wpi::mutex m_registerMutex;
wpi::mutex m_dataMutex;
std::atomic<HAL_Bool> m_initialized{false};
std::atomic<int64_t> m_accumulatorValue{false};
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
std::shared_ptr<BufferListenerVector> m_writeCallbacks = nullptr;
std::shared_ptr<ConstBufferListenerVector> m_writeCallbacks = nullptr;
std::shared_ptr<NotifyListenerVector> m_resetAccumulatorCallback = nullptr;
std::shared_ptr<NotifyListenerVector> m_setAccumulatorCallback = nullptr;
};

View File

@@ -23,7 +23,7 @@ class NotifierThread : public wpi::SafeThread {
public:
void Main() {
int32_t status = 0;
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<wpi::mutex> lock(m_mutex);
while (m_active) {
startNotifierLoop:
double waitTime = m_waitTime * 1e-6;

View File

@@ -348,4 +348,4 @@ int32_t HAL_GetPWMLoopTiming(int32_t* status) { return kExpectedLoopTiming; }
* @return The pwm cycle start time.
*/
uint64_t HAL_GetPWMCycleStartTime(int32_t* status) { return 0; }
}
} // extern "C"

View File

@@ -106,4 +106,4 @@ HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
else
return SimRelayData[port->channel].GetReverse();
}
}
} // extern "C"

View File

@@ -14,11 +14,12 @@ using namespace hal;
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
SimSPIData[port].SetInitialized(true);
}
int32_t HAL_TransactionSPI(HAL_SPIPort port, uint8_t* dataToSend,
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
return SimSPIData[port].Transaction(dataToSend, dataReceived, size);
}
int32_t HAL_WriteSPI(HAL_SPIPort port, uint8_t* dataToSend, int32_t sendSize) {
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize) {
return SimSPIData[port].Write(dataToSend, sendSize);
}
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {

View File

@@ -0,0 +1,139 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2017 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cstring>
#include "HAL/HAL.h"
#include "HAL/Solenoid.h"
#include "MockData/DriverStationData.h"
#include "gtest/gtest.h"
namespace hal {
TEST(DriverStationTests, JoystickTests) {
HAL_JoystickAxes axes;
HAL_JoystickPOVs povs;
HAL_JoystickButtons buttons;
// Check default values before anything has been set
for (int joystickNum = 0; joystickNum < 6; ++joystickNum) {
HAL_GetJoystickAxes(joystickNum, &axes);
HAL_GetJoystickPOVs(joystickNum, &povs);
HAL_GetJoystickButtons(joystickNum, &buttons);
EXPECT_EQ(0, axes.count);
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
EXPECT_EQ(0, axes.axes[i]);
}
EXPECT_EQ(0, povs.count);
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
EXPECT_EQ(0, povs.povs[i]);
}
EXPECT_EQ(0, buttons.count);
EXPECT_EQ(0u, buttons.buttons);
}
HAL_JoystickAxes set_axes;
std::memset(&set_axes, 0, sizeof(HAL_JoystickAxes));
HAL_JoystickPOVs set_povs;
std::memset(&set_povs, 0, sizeof(HAL_JoystickPOVs));
HAL_JoystickButtons set_buttons;
std::memset(&set_buttons, 0, sizeof(HAL_JoystickButtons));
// Set values
int joystickUnderTest = 4;
set_axes.count = 5;
for (int i = 0; i < set_axes.count; ++i) {
set_axes.axes[i] = i * .125;
}
set_povs.count = 3;
for (int i = 0; i < set_povs.count; ++i) {
set_povs.povs[i] = i * 15 + 12;
}
set_buttons.count = 8;
set_buttons.buttons = 0xDEADBEEF;
HALSIM_SetJoystickAxes(joystickUnderTest, &set_axes);
HALSIM_SetJoystickPOVs(joystickUnderTest, &set_povs);
HALSIM_SetJoystickButtons(joystickUnderTest, &set_buttons);
// Check the set values
HAL_GetJoystickAxes(joystickUnderTest, &axes);
HAL_GetJoystickPOVs(joystickUnderTest, &povs);
HAL_GetJoystickButtons(joystickUnderTest, &buttons);
EXPECT_EQ(5, axes.count);
EXPECT_NEAR(0.000, axes.axes[0], 0.000001);
EXPECT_NEAR(0.125, axes.axes[1], 0.000001);
EXPECT_NEAR(0.250, axes.axes[2], 0.000001);
EXPECT_NEAR(0.375, axes.axes[3], 0.000001);
EXPECT_NEAR(0.500, axes.axes[4], 0.000001);
EXPECT_NEAR(0, axes.axes[5], 0.000001); // Should not have been set, still 0
EXPECT_NEAR(0, axes.axes[6], 0.000001); // Should not have been set, still 0
EXPECT_EQ(3, povs.count);
EXPECT_EQ(12, povs.povs[0]);
EXPECT_EQ(27, povs.povs[1]);
EXPECT_EQ(42, povs.povs[2]);
EXPECT_EQ(0, povs.povs[3]); // Should not have been set, still 0
EXPECT_EQ(0, povs.povs[4]); // Should not have been set, still 0
EXPECT_EQ(0, povs.povs[5]); // Should not have been set, still 0
EXPECT_EQ(0, povs.povs[6]); // Should not have been set, still 0
EXPECT_EQ(8, buttons.count);
EXPECT_EQ(0xDEADBEEFu, buttons.buttons);
// Reset
HALSIM_ResetDriverStationData();
for (int joystickNum = 0; joystickNum < 6; ++joystickNum) {
HAL_GetJoystickAxes(joystickNum, &axes);
HAL_GetJoystickPOVs(joystickNum, &povs);
HAL_GetJoystickButtons(joystickNum, &buttons);
EXPECT_EQ(0, axes.count);
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
EXPECT_EQ(0, axes.axes[i]);
}
EXPECT_EQ(0, povs.count);
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
EXPECT_EQ(0, povs.povs[i]);
}
EXPECT_EQ(0, buttons.count);
EXPECT_EQ(0u, buttons.buttons);
}
}
TEST(DriverStationTests, EventInfoTest) {
std::string eventName = "UnitTest";
std::string gameData = "Insert game specific info here :D";
HAL_MatchInfo info;
info.eventName = const_cast<char*>(eventName.c_str());
info.gameSpecificMessage = const_cast<char*>(gameData.c_str());
info.matchNumber = 5;
info.matchType = HAL_MatchType::HAL_kMatchType_qualification;
info.replayNumber = 42;
HALSIM_SetMatchInfo(&info);
HAL_MatchInfo dataBack;
HAL_GetMatchInfo(&dataBack);
EXPECT_STREQ(eventName.c_str(), dataBack.eventName);
EXPECT_STREQ(gameData.c_str(), dataBack.gameSpecificMessage);
EXPECT_EQ(5, dataBack.matchNumber);
EXPECT_EQ(HAL_MatchType::HAL_kMatchType_qualification, dataBack.matchType);
EXPECT_EQ(42, dataBack.replayNumber);
HAL_FreeMatchInfo(&dataBack);
}
} // namespace hal

View File

@@ -5,7 +5,7 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include "WPILib.h"
#include "IterativeRobot.h"
class MyRobot : public IterativeRobot {
/**

View File

@@ -4,6 +4,6 @@
#ifndef __RoboRIO_FRC_ChipObject_Aliases_h__
#define __RoboRIO_FRC_ChipObject_Aliases_h__
#define nRoboRIO_FPGANamespace nFRC_2018_18_0_4
#define nRoboRIO_FPGANamespace nFRC_2018_18_0_5
#endif // __RoboRIO_FRC_ChipObject_Aliases_h__

View File

@@ -1,15 +1,15 @@
// Copyright (c) National Instruments 2008. All Rights Reserved.
// Do Not Edit... this file is generated!
#ifndef __nFRC_2018_18_0_4_nInterfaceGlobals_h__
#define __nFRC_2018_18_0_4_nInterfaceGlobals_h__
#ifndef __nFRC_2018_18_0_5_nInterfaceGlobals_h__
#define __nFRC_2018_18_0_5_nInterfaceGlobals_h__
namespace nFPGA
{
namespace nFRC_2018_18_0_4
namespace nFRC_2018_18_0_5
{
extern unsigned int g_currentTargetClass;
}
}
#endif // __nFRC_2018_18_0_4_nInterfaceGlobals_h__
#endif // __nFRC_2018_18_0_5_nInterfaceGlobals_h__

View File

@@ -1,15 +1,15 @@
// Copyright (c) National Instruments 2008. All Rights Reserved.
// Do Not Edit... this file is generated!
#ifndef __nFRC_2018_18_0_4_AI_h__
#define __nFRC_2018_18_0_4_AI_h__
#ifndef __nFRC_2018_18_0_5_AI_h__
#define __nFRC_2018_18_0_5_AI_h__
#include "../tSystem.h"
#include "../tSystemInterface.h"
namespace nFPGA
{
namespace nFRC_2018_18_0_4
namespace nFRC_2018_18_0_5
{
class tAI
@@ -141,4 +141,4 @@ private:
}
}
#endif // __nFRC_2018_18_0_4_AI_h__
#endif // __nFRC_2018_18_0_5_AI_h__

View File

@@ -1,15 +1,15 @@
// Copyright (c) National Instruments 2008. All Rights Reserved.
// Do Not Edit... this file is generated!
#ifndef __nFRC_2018_18_0_4_AO_h__
#define __nFRC_2018_18_0_4_AO_h__
#ifndef __nFRC_2018_18_0_5_AO_h__
#define __nFRC_2018_18_0_5_AO_h__
#include "../tSystem.h"
#include "../tSystemInterface.h"
namespace nFPGA
{
namespace nFRC_2018_18_0_4
namespace nFRC_2018_18_0_5
{
class tAO
@@ -48,4 +48,4 @@ private:
}
}
#endif // __nFRC_2018_18_0_4_AO_h__
#endif // __nFRC_2018_18_0_5_AO_h__

Some files were not shown because too many files have changed in this diff Show More