Squashed 'third_party/allwpilib/' changes from 66b57f032..e473a00f9
e473a00f9 [wpiutil] Base64: Add unsigned span/vector variants (#3702)
52f2d580e [wpiutil] raw_uv_ostream: Add reset() (#3701)
d7b1e3576 [wpiutil] WebSocket: move std::function (#3700)
93799fbe9 [examples] Fix description of TrapezoidProfileSubsystem (#3699)
b84644740 [wpimath] Document pose estimator states, inputs, and outputs (#3698)
2dc35c139 [wpimath] Fix classpaths for JNI class loads (#3697)
2cb171f6f [docs] Set Doxygen extract_all to true and fix Doxygen failures (#3695)
a939cd9c8 [wpimath] Print uncontrollable/unobservable models in LQR and KF (#3694)
d5270d113 [wpimath] Clean up C++ StateSpaceUtil tests (#3692)
b20903960 [wpimath] Remove redundant discretization tests from StateSpaceUtilTest (#3689)
c0cb545b4 [wpilibc] Add deprecated Doxygen attribute to SpeedController (#3691)
35c9f66a7 [wpilib] Rename PneumaticsHub to PneumaticHub (#3686)
796d03d10 [wpiutil] Remove unused LLVM header (#3688)
8723caf78 [wpilibj] Make Java TrapezoidProfile.Constraints an immutable class (#3687)
187f50a34 [wpimath] Catch incorrect parameters to state-space models earlier (#3680)
8d04606c4 Replace instances of frc-characterization with SysId (NFC) (#3681)
b82d4f6e5 [hal, cscore, ntcore] Use WPI common handle type base
87e34967e [wpiutil] Add synchronization primitives
e32499c54 [wpiutil] Add ParallelTcpConnector (#3655)
aa0b49228 [wpilib] Remove redundant "quick turn" docs for curvature drive (NFC) (#3674)
57301a7f9 [hal] REVPH: Start closed-loop compressor control on init (#3673)
d1842ea8f [wpilib] Improve interrupt docs (NFC) (#3679)
558151061 [wpiutil] Add DsClient (#3654)
181723e57 Replace `.to<double>()` and `.template to<double>()` with `.value()` (#3667)
6bc1db44b [commands] Add pointer overload of AddRequirements (artf6003) (#3669)
737b57ed5 [wpimath] Update to drake v0.35.0 (#3665)
4d287d1ae [build] Upgrade WPIJREArtifact to JRE 2022-11.0.12u5 (#3666)
f26eb5ada [hal] Fix another typo (get -> gets) (NFC) (#3663)
94ed275ba [hal] Fix misspelling (numer -> number) (NFC) (#3662)
ac2f44da3 [wpiutil] uv: use move for std::function (#3653)
75fa1fbfb [wpiutil] json::serializer: Optimize construction (#3647)
5e689faea [wpiutil] Import MessagePack implementation (mpack) (#3650)
649a50b40 [wpiutil] Add LEB128 byte-by-byte reader (#3652)
e94397a97 [wpiutil] Move json_serializer.h to public headers (#3646)
4ec58724d [wpiutil] uv::Tcp: Clarify SetNoDelay documentation (#3649)
8cb294aa4 [wpiutil] WebSocket: Make Shutdown() public (#3651)
2b3a9a52b [wpiutil] json: Fix map iterator key() for std::string_view (#3645)
138cbb94b [wpiutil] uv::Async: Add direct call for no-parameter specialization (#3648)
e56d6dea8 [ci] Update testbench pool image to ubuntu-latest (#3643)
43f30e44e [build] Enable comments in doxygen source files (#3644)
9e6db17ef [build] Enable doxygen preprocessor expansion of WPI_DEPRECATED (#3642)
0e631ad2f Add WPILib version to issue template (#3641)
6229d8d2f [build] Docs: set case_sense_names to false (#3392)
4647d09b5 [docs] Fix Doxygen warnings, add CI docs lint job (#3639)
4ad3a5402 [hal] Fix PWM allocation channel (#3637)
05e5feac4 [docs] Fix brownout docs (NFC) (#3638)
67df469c5 [examples] Remove old command-based templates and examples (#3263)
689e9ccfb [hal, wpilib] Add brownout voltage configuration (#3632)
9cd4bc407 [docs] Add useLocal to avoid using installer artifacts (#3634)
61996c2bb [cscore] Fix Java direct callback notifications (#3631)
6d3dd99eb [build] Update to newest native-utils (#3633)
f0b484892 [wpiutil] Fix StringMap iterator equality check (#3629)
8352cbb7a Update development build instructions for 2022 (#3616)
6da08b71d [examples] Fix Intermediate Vision Java Example description (#3628)
5d99059bf [wpiutil] Remove optional.h (#3627)
fa41b106a [glass, wpiutil] Add missing format args (#3626)
4e3fd7d42 [build] Enable Zc:__cplusplus for Windows (#3625)
791d8354d [build] Suppress deprecation/removal warnings for old commands (#3618)
10f19e6fc [hal, wpilib] Add REV PneumaticsHub (#3600)
4c61a1305 [ntcore] Revert to per-element copy for toNative() (#3621)
7b3f62244 [wpiutil] SendableRegistry: Print exception stacktrace (#3620)
d347928e4 [hal] Use better error for when console out is enabled while attempting to use onboard serial port (#3622)
cc31079a1 [hal] Use setcap instead of setuid for setting thread priorities (#3613)
4676648b7 [wpimath] Upgrade to Drake v0.34.0 (#3607)
c7594c911 [build] Allow building wpilibc in cmake without cscore and opencv (#3605)
173cb7359 [wpilib] Add TimesliceRobot (#3502)
af295879f [hal] Set error status for I2C port out of range (#3603)
95dd20a15 [build] Enable spotbugs (#3601)
b65fce86b [wpilib] Remove Timer lock in wpilibj and update docs (#3602)
3b8d3bbcb Remove unused and add missing deprecated.h includes (#3599)
f9e976467 [examples] Rename DriveTrain classes to Drivetrain (#3594)
118a27be2 [wpilib] Add Timer tests (#3595)
59c89428e [wpilib] Deprecate Timer::HasPeriodPassed() (#3598)
202ca5e78 Force C++17 in .clang-format (#3597)
d6f185d8e Rename tests for consistency (#3592)
54ca474db [ci] Enable asan and tsan in CI for tests that pass (#3591)
1ca383b23 Add Debouncer (#3590)
179fde3a7 [build] Update to 2022 native utils and gradle 7 (#3588)
50198ffcf [examples] Add Mechanism2d visualization to Elevator Sim (#3587)
a446c2559 [examples] Synchronize C++ and Java Mechanism2d examples (#3589)
a7fb83103 [ci] clang-tidy: Generate compilation commands DB with Gradle (#3585)
4f5e0c9f8 [examples] Update ArmSimulation example to use Mechanism2d (#3572)
8164b91dc [CI] Print CMake test output on failure (#3583)
4d5fca27e [wpilib] Impove Mechanism2D documentation (NFC) (#3584)
fe59e4b9f Make C++ test names more consistent (#3586)
5c8868549 [wpilibc] Fix C++ MechanisimRoot2D to use same NT entries as Java/Glass (#3582)
9359431ba [wpimath] Clean up Eigen usage
72716f51c [wpimath] Upgrade to Eigen 3.4
382deef75 [wpimath] Explicitly export wpimath symbols
161e21173 [ntcore] Match standard handle layout, only allow 16 instances (#3577)
263a24811 [wpimath] Use jinja for codegen (#3574)
725251d29 [wpilib] Increase tolerances of DifferentialDriveSimTest (#3581)
4dff87301 [wpimath] Make LinearFilter::Factorial() constexpr (#3579)
60ede67ab [hal, wpilib] Switch PCM to be a single object that is allowed to be duplicated (#3475)
906bfc846 [build] Add CMake build support for sanitizers (#3576)
0d4f08ad9 [hal] Simplify string copy of joystick name (#3575)
a52bf87b7 [wpiutil] Add Java function package (#3570)
40c7645d6 [wpiutil] UidVector: Return old object from erase() (#3571)
5b886a23f [wpiutil] jni_util: Add size, operator[] to JArrayRef (#3569)
65797caa7 [sim] Fix halsim_ds_socket stringop overflow warning from GCC 10 (#3568)
66abb3988 [hal] Update runtime enum to allow selecting roborio 2 (#3565)
95a12e0ee [hal] UidSetter: Don't revert euid if its already current value (#3566)
27951442b [wpimath] Use external Eigen headers only (#3564)
c42e053ae [docs] Update to doxygen 1.9.2 (#3562)
e7048c8c8 [docs] Disable doxygen linking for common words that are also classes (#3563)
d8e0b6c97 [wpilibj] Fix java async interrupts (#3559)
5e6c34c61 Update to 2022 roborio image (#3537)
828f073eb [wpiutil] Fix uv::Buffer memory leaks caught by asan (#3555)
2dd5701ac [cscore] Fix mutex use-after-free in cscore test (#3557)
531439198 [ntcore] Fix NetworkTables memory leaks caught by asan (#3556)
3d9a4d585 [wpilibc] Fix AnalogTriggerOutput memory leak reported by asan (#3554)
54eda5928 [wpiutil] Ignore ubsan vptr upcast warning in SendableHelper moves (#3553)
5a4f75c9f [wpilib] Replace Speed controller comments with motor controller (NFC) (#3551)
7810f665f [wpiutil] Fix bug in uleb128 (#3540)
697e2dd33 [wpilib] Fix errant jaguar reference in comments (NFC) (#3550)
936c64ff5 [docs] Enable -linksource for javadocs (#3549)
1ea654954 [build] Upgrade CMake build to googletest 1.11.0 (#3548)
32d9949e4 [wpimath] Move controller tests to wpimath (#3541)
01ba56a8a [hal] Replace strncpy with memcpy (#3539)
e109c4251 [build] Rename makeSim flag to forceGazebo to better describe what it does (#3535)
e4c709164 [docs] Use a doxygen theme and add logo (#3533)
960b6e589 [wpimath] Fix Javadoc warning (#3532)
82eef8d5e [hal] Remove over current fault HAL functions from REV PDH (#3526)
aa3848b2c [wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)
3b5d0d141 [wpimath] Add LinearFilter::BackwardFiniteDifference() (#3528)
c8fc715fe [wpimath] Upgrade drake files to v0.33.0 (#3531)
e5fe3a8e1 [build] Treat javadoc warnings as errors in CI and fix warnings (#3530)
e0c6cd3dc [wpimath] Add an operator for composing two Transform2ds (#3527)
2edd510ab [sim] Add sim wrappers for sensors that use SimDevice (#3517)
2b3e2ebc1 [hal] Fix HAL Notifier thread priority setting (#3522)
ab4cb5932 [gitignore] Update gitignore to ignore bazel / clion files (#3524)
57c8615af [build] Generate spotless patch on failure (#3523)
b90317321 Replace std::cout and std::cerr with fmt::print() (#3519)
10cc8b89c [hal] [wpilib] Add initial support for the REV PDH (#3503)
5d9ae3cdb [hal] Set HAL Notifier thread as RT by default (#3482)
192d251ee [wpilibcIntegrationTests] Properly disable DMA integration tests (#3514)
031962608 [wpilib] Add PS4Controller, remove Hand from GenericHID/XboxController (#3345)
25f6f478a [wpilib] Rename DriverStation::IsOperatorControl() to IsTeleop() (#3505)
e80f09f84 [wpilibj] Add unit tests (#3501)
c159f91f0 [wpilib] Only read DS control word once in IterativeRobotBase (#3504)
eb790a74d Add rio development docs documenting myRobot deploy tasks (#3508)
e47451f5a [wpimath] Replace auto with Eigen types (#3511)
252b8c83b Remove Java formatting from build task in CI (#3507)
09666ff29 Shorten Gazebo CI build (#3506)
baf2e501d Update myRobot to use 2021 java (#3509)
5ac60f0a2 [wpilib] Remove IterativeRobotBase mode init prints (#3500)
fb2ee8ec3 [wpilib] Add TimedRobot functions for running code on mode exit (#3499)
94e0db796 [wpilibc] Add more unit tests (#3494)
b25324695 [wpilibj] Add units to parameter names (NFC) (#3497)
1ac73a247 [hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
2014115bc [examples] frisbeebot: Fix typo and reflow comments (NFC) (#3498)
4a944dc39 [examples] Consistently use 0 for controller port (#3496)
3838cc4ec Use unicode characters in docs equations (#3487)
85748f2e6 [examples] Add C++ TankDrive example (#3493)
d7b8aa56d [wpilibj] Rename DriverStation In[Mode] functions to follow style guide (#3488)
16e096cf8 [build] Fix CMake Windows CI (#3490)
50af74c38 [wpimath] Clean up NumericalIntegration and add Discretization tests (#3489)
bfc209b12 Automate fmt update (#3486)
e7f9331e4 [build] Update to Doxygen 1.9.1 (#3008)
ab8e8aa2a [wpimath] Update drake with upstream (#3484)
1ef826d1d [wpimath] Fix IOException path in WPIMath JNI (#3485)
52bddaa97 [wpimath] Disable iostream support for units and enable fmtlib (#3481)
e4dc3908b [wpiutil] Upgrade to fmtlib 8.0.1 (#3483)
1daadb812 [wpimath] Implement Dormand-Prince integration method (#3476)
9c2723391 [cscore] Add [[nodiscard]] to GrabFrame functions (#3479)
7a8796414 [wpilib] Add Notifier integration tests (#3480)
f8f13c536 [wpilibcExamples] Prefix decimal numbers with 0 (#3478)
1adb69c0f [ntcore] Use "NetworkTables" instead of "Network Tables" in NT specs (#3477)
5f5830b96 Upload wpiformat diff if one exists (#3474)
9fb4f35bb [wpimath] Add tests for DARE overload with Q, R, and N matrices (#3472)
c002e6f92 Run wpiformat (#3473)
c154e5262 [wpilib] Make solenoids exclusive use, PCM act like old sendable compressor (#3464)
6ddef1cca [hal] JNI setDIO: use a boolean and not a short (#3469)
9d68d9582 Remove extra newlines after open curly braces (NFC) (#3471)
a4233e1a1 [wpimath] Add script for updating Drake (#3470)
39373c6d2 Update README.md for new GCC version requirement (#3467)
d29acc90a [wpigui] Add option to reset UI on exit (#3463)
a371235b0 [ntcore] Fix dangling pointer in logger (#3465)
53b4891a5 [wpilibcintegrationtests] Fix deprecated Preferences usage (#3461)
646ded912 [wpimath] Remove incorrect discretization in pose estimators (#3460)
ea0b8f48e Fix some deprecation warnings due to fmtlib upgrade (#3459)
2067d7e30 [wpilibjexamples] Add wpimathjni, wpiutiljni to library path (#3455)
866571ab4 [wpiutil] Upgrade to fmtlib 8.0.0 (#3457)
4e1fa0308 [build] Skip PDB copy on windows build servers (#3458)
b45572167 [build] Change CI back to 18.04 docker images (#3456)
57a160f1b [wpilibc] Fix LiveWindow deprecation warning in RobotBase skeleton template (#3454)
29ae8640d [HLT] Implement duty cycle cross connect tests (#3453)
ee6377e54 [HLT] Add relay and analog cross connects (#3452)
b0f1ae7ea [build] CMake: Build the HAL even if WITH_CSCORE=OFF (#3449)
7aae2b72d Replace std::to_string() with fmt::format() (#3451)
73fcbbd74 [HLT] Add relay digital cross connect tests (#3450)
e7bedde83 [HLT] Add PWM tests that use DMA as the back end (#3447)
7253edb1e [wpilibc] Timer: Fix deprecated warning (#3446)
efa28125c [wpilibc] Add message to RobotBase on how to read stacktrace (#3444)
9832fcfe1 [hal] Fix DIO direction getter (#3445)
49c71f9f2 [wpilibj] Clarify robot quit message (#3364)
791770cf6 [wpimath] Move controller from wpilibj to wpimath (#3439)
9ce9188ff [wpimath] Add ReportWarning to MathShared (#3441)
362066a9b [wpilib] Deprecate getInstance() in favor of static functions (#3440)
26ff9371d Initial commit of cross connect integration test project (#3434)
4a36f86c8 [hal] Add support for DMA to Java (#3158)
85144e47f [commands] Unbreak build (#3438)
b417d961e Split Sendable into NT and non-NT portions (#3432)
ef4ea84cb [commands] Change grouping decorator impl to flatten nested group structures (#3335)
b422665a3 [examples] Invert right side of drive subsystems (#3437)
186dadf14 [hal] Error if attempting to set DIO output on an input port (#3436)
04e64db94 Remove redundant C++ lambda parentheses (NFC) (#3433)
f60994ad2 [wpiutil] Rename Java package to edu.wpi.first.util (#3431)
cfa1ca96f [wpilibc] Make ShuffleboardValue non-copyable (#3430)
4d9ff7643 Fix documentation warnings generated by JavaDoc (NFC) (#3428)
9e1b7e046 [build] Fix clang-tidy and clang-format (#3429)
a77c6ff3a [build] Upgrade clang-format and clang-tidy (NFC) (#3422)
099fde97d [wpilib] Improve PDP comments (NFC) (#3427)
f8fc2463e [wpilibc, wpiutil] Clean up includes (NFC) (#3426)
e246b7884 [wpimath] Clean up member initialization in feedforward classes (#3425)
c1e128bd5 Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
8284075ee Run "Lint and Format" CI job on push as well as pull request (#3412)
f7db09a12 [wpimath] Move C++ filters into filter folder to match Java (#3417)
f9c3d54bd [wpimath] Reset error covariance in pose estimator ResetPosition() (#3418)
0773f4033 [hal] Ensure HAL status variables are initialized to zero (#3421)
d068fb321 [build] Upgrade CI to use 20.04 docker images (#3420)
8d054c940 [wpiutil] Remove STLExtras.h
80f1d7921 [wpiutil] Split function_ref to a separate header
64f541325 Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)
2abbbd9e7 [build] clang-tidy: Remove bugprone-exception-escape (#3415)
a5c471af7 [wpimath] Add LQR template specialization for 2x2 system
edd2f0232 [wpimath] Add DARE solver for Q, R, and N with LQR ctor overloads
b2c3b2dd8 Use std::string_view and fmtlib across all libraries (#3402)
4f1cecb8e [wpiutil] Remove Path.h (#3413)
b336eac34 [build] Publish halsim_ws_core to Maven
2a09f6fa4 [build] Also build sim modules as static libraries
0e702eb79 [hal] Add a unified PCM object (#3331)
dea841103 [wpimath] Add fmtlib formatter overloads for Eigen::Matrix and units (#3409)
82856cf81 [wpiutil] Improve wpi::circular_buffer iterators (#3410)
8aecda03e [wpilib] Fix a documentation typo (#3408)
5c817082a [wpilib] Remove InterruptableSensorBase and replace with interrupt classes (#2410)
15c521a7f [wpimath] Fix drivetrain system identification (#3406)
989de4a1b [build] Force all linker warnings to be fatal for rio builds (#3407)
d9eeb45b0 [wpilibc] Add units to Ultrasonic class API (#3403)
fe570e000 [wpiutil] Replace llvm filesystem with C++17 filesystem (#3401)
01dc0249d [wpimath] Move SlewRateLimiter from wpilib to wpimath (#3399)
93523d572 [wpilibc] Clean up integration tests (#3400)
4f7a4464d [wpiutil] Rewrite StringExtras for std::string_view (#3394)
e09293a15 [wpilibc] Transition C++ classes to units::second_t (#3396)
827b17a52 [build] Create run tasks for Glass and OutlineViewer (#3397)
a61037996 [wpiutil] Avoid MSVC warning on span include (#3393)
4e2c3051b [wpilibc] Use std::string_view instead of Twine (#3380)
50915cb7e [wpilibc] MotorSafety::GetDescription(): Return std::string (#3390)
f4e2d26d5 [wpilibc] Move NullDeleter from frc/Base.h to wpi/NullDeleter.h (#3387)
cb0051ae6 [wpilibc] SimDeviceSim: use fmtlib (#3389)
a238cec12 [wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)
393bf23c0 [ntcore, cscore, wpiutil] Standardize template impl files on .inc extension (NFC) (#3124)
e7d9ba135 [sim] Disable flaky web server integration tests (#3388)
0a0003c11 [wpilibjExamples] Fix name of Java swerve drive pose estimator example (#3382)
7e1b27554 [wpilibc] Use default copies and moves when possible (#3381)
fb2a56e2d [wpilibc] Remove START_ROBOT_CLASS macro (#3384)
84218bfb4 [wpilibc] Remove frc namespace shim (#3385)
dd7824340 [wpilibc] Remove C++ compiler version static asserts (#3386)
484cf9c0e [wpimath] Suppress the -Wmaybe-uninitialized warning in Eigen (#3378)
a04d1b4f9 [wpilibc] DriverStation: Remove ReportError and ReportWarning
831c10bdf [wpilibc] Errors: Use fmtlib
87603e400 [wpiutil] Import fmtlib (#3375)
442621672 [wpiutil] Add ArrayRef/std::span/wpi::span implicit conversions
bc15b953b [wpiutil] Add std::span implementation
6d20b1204 [wpiutil] StringRef, Twine, raw_ostream: Add std::string_view support (#3373)
2385c2a43 [wpilibc] Remove Utility.h (#3376)
87384ea68 [wpilib] Fix PIDController continuous range error calculations (#3170)
04dae799a [wpimath] Add SimpleMotorFeedforward::Calculate(velocity, nextVelocity) overload (#3183)
0768c3903 [wpilib] DifferentialDrive: Remove right side inversion (#3340)
8dd8d4d2d [wpimath] Fix redundant nested math package introduced by #3316 (#3368)
49b06beed [examples] Add Field2d to RamseteController example (#3371)
4c562a445 [wpimath] Fix typo in comment of update_eigen.py (#3369)
fdbbf1188 [wpimath] Add script for updating Eigen
f1e64b349 [wpimath] Move Eigen unsupported folder into eigeninclude
224f3a05c [sim] Fix build error when building with GCC 11.1 (#3361)
ff56d6861 [wpilibj] Fix SpeedController deprecated warnings (#3360)
1873fbefb [examples] Fix Swerve and Mecanum examples (#3359)
80b479e50 [examples] Fix SwerveBot example to use unique encoder ports (#3358)
1f7c9adee [wpilibjExamples] Fix pose estimator examples (#3356)
9ebc3b058 [outlineviewer] Change default size to 600x400 (#3353)
e21b443a4 [build] Gradle: Make C++ examples runnable (#3348)
da590120c [wpilibj] Add MotorController.setVoltage default (#3347)
561d53885 [build] Update opencv to 4.5.2, imgui/implot to latest (#3344)
44ad67ca8 [wpilibj] Preferences: Add missing Deprecated annotation (#3343)
3fe8fc75a [wpilibc] Revert "Return reference from GetInstance" (#3342)
3cc2da332 Merge branch '2022'
a3cd90dd7 [wpimath] Fix classpath used by generate_numbers.py (#3339)
d6cfdd3ba [wpilib] Preferences: Deprecate Put* in favor of Set* (#3337)
ba08baabb [wpimath] Update Drake DARE solver to v0.29.0 (#3336)
497b712f6 [wpilib] Make IterativeRobotBase::m_period private with getter
f00dfed7a [wpilib] Remove IterativeRobot base class
3c0846168 [hal] Use last error reporting instead of PARAMETER_OUT_OF_RANGE (#3328)
5ef2b4fdc [wpilibj] Fix @deprecated warning for SerialPort constructor (#3329)
23d2326d1 [hal] Report previous allocation location for indexed resource duplicates (#3322)
e338f9f19 [build] Fix wpilibc runCpp task (#3327)
c8ff626fe [wpimath] Move Java classes to edu.wpi.first.math (#3316)
4e424d51f [wpilibj] DifferentialDrivetrainSim: Rename constants to match the style guide (#3312)
6b50323b0 [cscore] Use Lock2DSize if possible for Windows USB cameras (#3326)
65c148536 [wpilibc] Fix "control reaches end of non-void function" warning (#3324)
f99f62bee [wpiutil] uv Handle: Use malloc/free instead of new/delete (#3325)
365f5449c [wpimath] Fix MecanumDriveKinematics (#3266)
ff52f207c [glass, wpilib] Rewrite Mechanism2d (#3281)
ee0eed143 [wpimath] Add DCMotor factory function for Romi motors (#3319)
512738072 [hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)
ced654880 [glass, outlineviewer] Update Mac icons to macOS 11 style (#3313)
936d3b9f8 [templates] Add Java template for educational robot (#3309)
6e31230ad [examples] Fix odometry update in SwerveControllerCommand example (#3310)
05ebe9318 Merge branch 'main' into 2022
aaf24e255 [wpilib] Fix initial heading behavior in HolonomicDriveController (#3290)
8d961dfd2 [wpilibc] Remove ErrorBase (#3306)
659b37ef9 [wpiutil] StackTrace: Include offset on Linux (#3305)
0abf6c904 [wpilib] Move motor controllers to motorcontrol package (#3302)
4630191fa [wpiutil] circular_buffer: Use value initialization instead of passing zero (#3303)
b7b178f49 [wpilib] Remove Potentiometer interface
687066af3 [wpilib] Remove GyroBase
6b168ab0c [wpilib] Remove PIDController, PIDOutput, PIDSource
948625de9 [wpimath] Document conversion from filter cutoff frequency to time constant (#3299)
3848eb8b1 [wpilibc] Fix flywhel -> flywheel typo in FlywheelSim (#3298)
3abe0b9d4 [cscore] Move java package to edu.wpi.first.cscore (#3294)
d7fabe81f [wpilib] Remove RobotDrive (#3295)
1dc81669c [wpilib] Remove GearTooth (#3293)
01d0e1260 [wpilib] Revert move of RomiGyro into main wpilibc/j (#3296)
397e569aa [ntcore] Remove "using wpi" from nt namespace
79267f9e6 [ntcore] Remove NetworkTable -> nt::NetworkTable shim
48ebe5736 [ntcore] Remove deprecated Java interfaces and classes
c2064c78b [ntcore] Remove deprecated ITable interfaces
36608a283 [ntcore] Remove deprecated C++ APIs
a1c87e1e1 [glass] LogView: Add "copy to clipboard" button (#3274)
fa7240a50 [wpimath] Fix typo in quintic spline basis matrix
ffb4d38e2 [wpimath] Add derivation for spline basis matrices
f57c188f2 [wpilib] Add AnalogEncoder(int) ctor (#3273)
8471c4fb2 [wpilib] FieldObject2d: Add setTrajectory() method (#3277)
c97acd18e [glass] Field2d enhancements (#3234)
ffb590bfc [wpilib] Fix Compressor sendable properties (#3269)
6137f98eb [hal] Rename SimValueCallback2 to SimValueCallback (#3212)
a6f653969 [hal] Move registerSimPeriodic functions to HAL package (#3211)
10c038d9b [glass] Plot: Fix window creation after removal (#3264)
2d2eaa3ef [wpigui] Ensure window will be initially visible (#3256)
4d28b1f0c [wpimath] Use JNI for trajectory serialization (#3257)
3de800a60 [wpimath] TrajectoryUtil.h: Comment formatting (NFC) (#3262)
eff592377 [glass] Plot: Don't overwrite series ID (#3260)
a79faace1 [wpilibc] Return reference from GetInstance (#3247)
9550777b9 [wpilib] PWMSpeedController: Use PWM by composition (#3248)
c8521a3c3 [glass] Plot: Set reasonable default window size (#3261)
d71eb2cf3 [glass] Plot: Show full source name as tooltip and in popup (#3255)
160fb740f [hal] Use std::lround() instead of adding 0.5 and truncating (#3012)
48e9f3951 [wpilibj] Remove wpilibj package CameraServer (#3213)
8afa596fd [wpilib] Remove deprecated Sendable functions and SendableBase (#3210)
d3e45c297 [wpimath] Make C++ geometry classes immutable (#3249)
2c98939c1 [glass] StringChooser: Don't call SameLine() at end
a18a7409f [glass] NTStringChooser: Clear value of deleted entries
2f19cf452 [glass] NetworkTablesHelper: listen to delete events
da96707dc Merge branch 'main' into 2022
c3a8bdc24 [build] Fix clang-tidy action (#3246)
21624ef27 Add ImGui OutlineViewer (#3220)
1032c9b91 [wpiutil] Unbreak wpi::Format on Windows (#3242)
2e07902d7 [glass] NTField2D: Fix name lookup (#3233)
6e23e1840 [wpilibc] Remove WPILib.h (#3235)
3e22e4506 [wpilib] Make KoP drivetrain simulation weight 60 lbs (#3228)
79d1bd6c8 [glass] NetworkTablesSetting: Allow disable of server option (#3227)
fe341a16f [examples] Use more logical elevator setpoints in GearsBot (#3198)
62abf46b3 [glass] NetworkTablesSettings: Don't block GUI (#3226)
a95a5e0d9 [glass] Move NetworkTablesSettings to libglassnt (#3224)
d6f6ceaba [build] Run Spotless formatter (NFC) (#3221)
0922f8af5 [commands] CommandScheduler.requiring(): Note return can be null (NFC) (#2934)
6812302ff [examples] Make DriveDistanceOffboard example work in sim (#3199)
f3f86b8e7 [wpimath] Add pose estimator overload for vision + std dev measurement (#3200)
1a2680b9e [wpilibj] Change CommandBase.withName() to return CommandBase (#3209)
435bbb6a8 [command] RamseteCommand: Output 0 if interrupted (#3216)
3cf44e0a5 [hal] Add function for changing HAL Notifier thread priority (#3218)
40b367513 [wpimath] Units.java: Add kg-lb conversions (#3203)
9f563d584 [glass] NT: Fix return value in StringToDoubleArray (#3208)
af4adf537 [glass] Auto-size plots to fit window (#3193)
2560146da [sim] GUI: Add option to show prefix in Other Devices (#3186)
eae3a6397 gitignore: Ignore .cache directory (#3196)
959611420 [wpilib] Require non-zero positive value for PIDController.period (#3175)
9522f2e8c [wpimath] Add methods to concatenate trajectories (#3139)
e42a0b6cf [wpimath] Rotation2d comment formatting (NFC) (#3162)
d1c7032de [wpimath] Fix order of setting gyro offset in pose estimators (#3176)
d241bc81a [sim] Add DoubleSolenoidSim and SolenoidSim classes (#3177)
cb7f39afa [wpilibc] Add RobotController::GetBatteryVoltage() to C++ (#3179)
99b5ad9eb [wpilibj] Fix warnings that are not unused variables or deprecation (#3161)
c14b23775 [build] Fixup doxygen generated include dirs to match what users would need (#3154)
d447c7dc3 [sim] Add SimDeviceSim ctor overloads (#3134)
247420c9c [build] Remove jcenter repo (#3157)
04b112e00 [build] Include debug info in plugin published artifacts (#3149)
be0ce9900 [examples] Use PWMSparkMax instead of PWMVictorSPX (#3156)
69e8d0b65 [wpilib] Move RomiGyro into main wpilibc/j (#3143)
94e685e1b [wpimath] Add custom residual support to EKF (#3148)
5899f3dd2 [sim] GUI: Make keyboard settings loading more robust (#3167)
f82aa1d56 [wpilib] Fix HolonomicDriveController atReference() behavior (#3163)
fe5c2cf4b [wpimath] Remove ControllerUtil.java (#3169)
43d40c6e9 [wpiutil] Suppress unchecked cast in CombinedRuntimeLoader (#3155)
3d44d8f79 [wpimath] Fix argument order in UKF docs (NFC) (#3147)
ba6fe8ff2 [cscore] Add USB camera change event (#3123)
533725888 [build] Tweak OpenCV cmake search paths to work better on Linux (#3144)
29bf9d6ef [cscore] Add polled support to listener
483beb636 [ntcore] Move CallbackManager to wpiutil
fdaec7759 [examples] Instantiate m_ramseteController in example (#3142)
8494a5761 Rename default branch to main (#3140)
45590eea2 [wpigui] Hardcode window scale to 1 on macOS (#3135)
834a64920 [build] Publish libglass and libglassnt to Maven (#3127)
2c2ccb361 [wpimath] Fix Rotation2d equality operator (#3128)
fb5c8c39a [wpigui] clang-tidy: readability-braces-around-statements
f7d39193a [wpigui] Fix copyright in pfd and wpigui_metal.mm
aec796b21 [ntcore] Fix conditional jump on uninitialized value (#3125)
fb13bb239 [sim] GUI: Add right click popup for keyboard joystick settings (#3119)
c517ec677 [build] Update thirdparty-imgui to 1.79-2 (#3118)
e8cbf2a71 [wpimath] Fix typo in SwerveDrivePoseEstimator doc (NFC) (#3112)
e9c86df46 [wpimath] Add tests for swerve module optimization (#3100)
6ba8c289c [examples] Remove negative of ArcadeDrive(fwd, ..) in the C++ Getting Started Example (#3102)
3f1672e89 [hal] Add SimDevice createInt() and createLong() (#3110)
15be5cbf1 [examples] Fix segfault in GearsBot C++ example (#3111)
4cf0e5e6d Add quick links to API documentation in README (#3082)
6b1898f12 Fix RT priority docs (NFC) (#3098)
b3426e9c0 [wpimath] Fix missing whitespace in pose estimator doc (#3097)
38c1a1f3e [examples] Fix feildRelative -> fieldRelative typo in XControllerCommand examples (#3104)
4488e25f1 [glass] Shorten SmartDashboard window names (#3096)
cfdb3058e [wpilibj] Update SimDeviceSimTest (#3095)
64adff5fe [examples] Fix typo in ArcadeDrive constructor parameter name (#3092)
6efc58e3d [build] Fix issues with build on windows, deprecations, and native utils (#3090)
f393989a5 [wpimath, wpiutil] Add wpi::array for compile time size checking (#3087)
d6ed20c1e [build] Set macOS deployment target to 10.14 (#3088)
7c524014c [hal] Add [[nodiscard]] to HAL_WaitForNotifierAlarm() (#3085)
406d055f0 [wpilib] Fixup wouldHitLowerLimit in elevator and arm simulation classes. (#3076)
04a90b5dd [examples] Don't continually set setpoint in PotentiometerPID Examples (#3084)
8c5bfa013 [sim] GUI: Add max value setting for keyboard joysticks (#3083)
bc80c5535 [hal] Add SimValue reset() function (#3064)
9c3b51ca0 [wpilib] Document simulation APIs (#3079)
26584ff14 [wpimath] Add model description to LinearSystemId Javadocs (#3080)
42c3d5286 [examples] Sync Java and C++ trajectories in sim example (#3081)
64e72f710 [wpilibc] Add missing function RoboRioSim::ResetData (#3073)
e95503798 [wpimath] Add optimize() to SwerveModuleState (#3065)
fb99910c2 [hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066)
e620bd4d3 [doc] Add machine-readable websocket specification (#3059)
a44e761d9 [glass] Add support for plot Y axis labels
ea1974d57 [wpigui] Update imgui and implot to latest
85a0bd43c [wpimath] Add RKF45 integration (#3047)
278e0f126 [glass] Use .controllable to set widgets' read-only state (#3035)
d8652cfd4 [wpimath] Make Java DCMotor API consistent with C++ and fix motor calcs (#3046)
377b7065a [build] Add toggleOffOn to Java spotless (#3053)
1e9c79c58 [sim] Use plant output to retrieve simulated position (#3043)
78147aa34 [sim] GUI: Fix Keyboard Joystick (#3052)
cd4a2265b [ntcore] Fix NetworkTableEntry::GetRaw() (#3051)
767ac1de1 [build] Use deploy key for doc publish (#3048)
d762215d1 [build] Add publish documentation script (#3040)
1fd09593c [examples] Add missing TestInit method to GettingStarted Example (#3039)
e45a0f6ce [examples] Add RomiGyro to the Romi Reference example (#3037)
94f852572 Update imaging link and fix typo (#3038)
d73cf64e5 [examples] Update RomiReference to match motor directions (#3036)
f945462ba Bump copyright year to 2021 (#3033)
b05946175 [wpimath] Catch Drake JNI exceptions and rethrow them (#3032)
62f0f8190 [wpimath] Deduplicate angle modulus functions (#2998)
bf8c0da4b [glass] Add "About" popup with version number (#3031)
dfdd6b389 [build] Increase Gradle heap size in Gazebo build (#3028)
f5e0fc3e9 Finish clang-tidy cleanups (#3003)
d741101fe [sim] Revert accidental commit of WSProvider_PDP.h (#3027)
e1620799c [examples] Add C++ RomiReference example (#2969)
749c7adb1 [command] Fix use-after-free in CommandScheduler (#3024)
921a73391 [sim] Add WS providers for AddressableLED, PCM, and Solenoid (#3026)
26d0004fe [build] Split Actions into different yml files (#3025)
948af6d5b [wpilib] PWMSpeedController.get(): Apply Inversion (#3016)
670a187a3 [wpilibc] SuppliedValueWidget.h: Forward declare ShuffleboardContainer (#3021)
be9f72502 [ntcore] NetworkTableValue: Use std::forward instead of std::move (#3022)
daf3f4cb1 [cscore] cscore_raw_cv.h: Fix error in PutFrame() (#3019)
5acda4cc7 [wpimath] ElevatorFeedforward.h: Add time.h include
8452af606 [wpimath] units/radiation.h: Add mass.h include
630d44952 [hal] ErrorsInternal.h: Add stdint.h include
7372cf7d9 [cscore] Windows NetworkUtil.cpp: Add missing include
b7e46c558 Include .h from .inc/.inl files (NFC) (#3017)
bf8f8710e [examples] Update Romi template and example (#2996)
6ffe5b775 [glass] Ensure NetworkTableTree parent context menu has an id (#3015)
be0805b85 [build] Update to WPILibVersioningPlugin 4.1.0 (#3014)
65b2359b2 [build] Add spotless for other files (#3007)
8651aa73e [examples] Enable NT Flush in Field2d examples (#3013)
78b542737 [build] Add Gazebo build to Actions CI (#3004)
fccf86532 [sim] DriverStationGui: Fix two bugs (#3010)
185741760 [sim] WSProvider_Joystick: Fix off-by-1 in incoming buttons (#3011)
ee7114a58 [glass] Add drive class widgets (#2975)
00fa91d0d [glass] Use ImGui style for gyro widget colors (#3009)
b7a25bfc3 ThirdPartyNotices: Add portable file dialogs license (#3005)
a2e46b9a1 [glass] modernize-use-nullptr (NFC) (#3006)
a751fa22d [build] Apply spotless for java formatting (#1768)
e563a0b7d [wpimath] Make LinearSystemLoop move-constructible and move-assignable (#2967)
49085ca94 [glass] Add context menus to remove and add NetworkTables values (#2979)
560a850a2 [glass] Add NetworkTables Log window (#2997)
66782e231 [sim] Create Left/Right drivetrain current accessors (#3001)
b60eb1544 clang-tidy: bugprone-virtual-near-miss
cbe59fa3b clang-tidy: google-explicit-constructor
c97c6dc06 clang-tidy: google-readability-casting (NFC)
32fa97d68 clang-tidy: modernize-use-nullptr (NFC)
aee460326 clang-tidy: modernize-pass-by-value
29c7da5f1 clang-tidy: modernize-make-unique
6131f4e32 clang-tidy: modernize-concat-nested-namespaces (NFC)
67e03e625 clang-tidy: modernize-use-equals-default
b124f9101 clang-tidy: modernize-use-default-member-init
d11a3a638 clang-tidy: modernize-use-override (NFC)
4cc0706b0 clang-tidy: modernize-use-using (NFC)
885f5a978 [wpilibc] Speed up ScopedTracerTest (#2999)
60b596457 [wpilibj] Fix typos (NFC) (#3000)
6e1919414 [build] Bring naming checkstyle rules up to date with Google Style guide (#1781)
8c8ec5e63 [wpilibj] Suppress unchecked cast warnings (#2995)
b8413ddd5 [wpiutil] Add noexcept to timestamp static functions (#2994)
5d976b6e1 [glass] Load NetworkTableView settings on first draw (#2993)
2b4317452 Replace NOLINT(runtime/explicit) comments with NOLINT (NFC) (#2992)
1c3011ba4 [glass] Fix handling of "/" NetworkTables key (#2991)
574a42f3b [hal] Fix UnsafeManipulateDIO status check (#2987)
9005cd59e [wpilib] Clamp input voltage in sim classes (#2955)
dd494d4ab [glass] NetworkTablesModel::Update(): Avoid use-after-move (#2988)
7cca469a1 [wpimath] NormalizeAngle: Make inline, remove unnamed namespace (#2986)
2aed432b4 Add braces to C++ single-line loops and conditionals (NFC) (#2973)
0291a3ff5 [wpiutil] StringRef: Add noexcept to several constructors (#2984)
5d7315280 [wpimath] Update UnitsTest.cpp copyright (#2985)
254931b9a [wpimath] Remove LinearSystem from LinearSystemLoop (#2968)
aa89744c9 Update OtherVersions.md to include wpimath info (#2983)
1cda3f5ad [glass] Fix styleguide (#2976)
8f1f64ffb Remove year from file copyright message (NFC) (#2972)
2bc0a7795 [examples] Fix wpiformat warning about utility include (#2971)
4204da6ad [glass] Add application icon
7ac39b10f [wpigui] Add icon support
6b567e006 [wpimath] Add support for varying vision standard deviations in pose estimators (#2956)
df299d6ed [wpimath] Add UnscentedKalmanFilter::Correct() overload (#2966)
4e34f0523 [examples] Use ADXRS450_GyroSim class in simulation example (#2964)
9962f6fd7 [wpilib] Give Field2d a default Sendable name (#2953)
f9d492f4b [sim] GUI: Show "Other Devices" window by default (#2961)
a8bb2ef1c [sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
240c629cd [sim] Try to guess "Map Gamepad" setting (#2960)
952567dd3 [wpilibc] Add missing move constructors and assignment operators (#2959)
10b396b4c [sim] Various WebSockets fixes and enhancements (#2952)
699bbe21a [examples] Fix comments in Gearsbot to match implementation (NFC) (#2957)
27b67deca [glass] Add more widgets (#2947)
581b7ec55 [wpilib] Add option to flush NetworkTables every iterative loop
acfbb1a44 [ntcore] DispatcherBase::Flush: Use wpi::Now()
d85a6d8fe [ntcore] Reduce limit on flush and update rate to 5 ms
20fbb5c63 [sim] Fix stringop truncation warning from GCC 10 (#2945)
1051a06a7 [glass] Show NT timestamps in seconds (#2944)
98dfc2620 [glass] Fix plots (#2943)
1ba0a2ced [sim] GUI: Add keyboard virtual joystick support (#2940)
4afb13f98 [examples] Replace M_PI with wpi::math::pi (#2938)
b27d33675 [examples] Enhance Romi templates (#2931)
00b9ae77f [sim] Change default WS port number to 3300 (#2932)
65219f309 [examples] Update Field2d position in periodic() (#2928)
f78d1d434 [sim] Process WS Encoder reset internally (#2927)
941edca59 [hal] Add Java SimDeviceDataJNI.getSimDeviceName (#2924)
a699435ed [wpilibj] Fix FlywheelSim argument order in constructor (#2922)
66d641718 [examples] Add tasks to run Java examples (#2920)
558e37c41 [examples] Add simple differential drive simulation example (#2918)
4f40d991e [glass] Switch name of Glass back to glass (#2919)
549af9900 [build] Update native-utils to 2021.0.6 (#2914)
b33693009 [glass] Change basename of glass to Glass (#2915)
c9a0edfb8 [glass] Package macOS application bundle
2c5668af4 [wpigui] Add platform-specific preferences save
751dea32a [wpilibc] Try to work around ABI break introduced in #2901 (#2917)
cd8f4bfb1 [build] Package up msvc runtime into maven artifact (#2913)
a6cfcc686 [wpilibc] Move SendableChooser Doxygen comments to header (NFC) (#2911)
b8c4f603d [wpimath] Upgrade to Eigen 3.3.9 (#2910)
0075e4b39 [wpilibj] Fix NPE in Field2d (#2909)
125af556c [simulation] Fix halsim_gui ntcore and wpiutil deps (#2908)
963ad5c25 [wpilib] Add noise to Differential Drive simulator (#2903)
387f56cb7 [examples] Add Romi reference Java example and templates (#2905)
b3deda38c [examples] Zero motors on disabledInit() in sim physics examples (#2906)
2a5ca7745 [glass] Add glass: an application for display of robot data
727940d84 [wpilib] Move Field2d to SmartDashboard
8cd42478e [wpilib] SendableBuilder: Make GetTable() visible
c11d34b26 [command] Use addCommands in command group templates (#2900)
339d7445b [sim] Add HAL hooks for simulationPeriodic (#2881)
d16f05f2c [wpilib] Fix SmartDashboard update order (#2896)
5427b32a4 [wpiutil] unique_function: Restrict implicit conversion (#2899)
f73701239 [ntcore] Add missing SetDefault initializer_list functions (#2898)
f5a6fc070 [sim] Add initialized flag for all solenoids on a PCM (#2897)
bdf5ba91a [wpilibj] Fix typo in ElevatorSim (#2895)
bc8f33877 [wpilib] Add pose estimators (#2867)
3413bfc06 [wpilib] PIDController: Recompute the error in AtSetpoint() (#2822)
2056f0ce0 [wpilib] Fix bugs in Hatchbot examples (#2893)
5eb8cfd69 [wpilibc] Fix MatchDataSender (#2892)
e6a425448 [build] Delete test folders after tests execute (#2891)
d478ad00d [imgui] Allow usage of imgui_stdlib (#2889)
53eda861d [build] Add unit-testing infrastructure to examples (#2863)
cc1d86ba6 [sim] Add title to simulator GUI window (#2888)
f0528f00e [build] CMake: Use project-specific binary and source dirs (#2886)
5cd2ad124 [wpilibc] Add Color::operator!= (#2887)
6c00e7a90 [build] CI CMake: build with GUI enabled (#2884)
53170bbb5 Update roboRIO toolchain installation instructions (#2883)
467258e05 [sim] GUI: Add option to not zero disconnected joysticks (#2876)
129be23c9 Clarify JDK installation instructions in readme (#2882)
8e9290e86 [build] Add separate CMake setting for wpimath (#2885)
7cf5bebf8 [wpilibj] Cache NT writes from DriverStation (#2780)
f7f9087fb [command] Fix timing issue in RamseteCommand (#2871)
256e7904f [wpilibj] SimDeviceSim: Fix sim value changed callback (#2880)
c8ea1b6c3 [wpilib] Add function to adjust LQR controller gain for pure time delay (#2878)
2816b06c0 [sim] HAL_GetControlWord: Fully zero output (#2873)
4c695ea08 Add toolchain installation instructions to README (#2875)
a14d51806 [wpimath] DCMotor: fix doc typo (NFC) (#2868)
017097791 [build] CMake: build sim extensions as shared libs (#2866)
f61726b5a [build] Fix cmake-config files (#2865)
fc27fdac5 [wpilibc] Cache NT values from driver station (#2768)
47c59859e [sim] Make SimDevice callbacks synchronous (#2861)
6e76ab9c0 [build] Turn on WITH_GUI for Windows cmake CI
5f78b7670 [build] Set GLFW_INSTALL to OFF
5e0808c84 [wpigui] Fix Windows cmake build
508f05a47 [imgui] Fix typo in Windows CMake target sources
Change-Id: I1737b45965f31803a96676bedc7dc40e337aa321
git-subtree-dir: third_party/allwpilib
git-subtree-split: e473a00f9785f9949e5ced30901baeaf426d2fc9
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/hal/src/main/native/cpp/ErrorHandling.cpp b/hal/src/main/native/cpp/ErrorHandling.cpp
new file mode 100644
index 0000000..ad1b40b
--- /dev/null
+++ b/hal/src/main/native/cpp/ErrorHandling.cpp
@@ -0,0 +1,60 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <fmt/format.h>
+#include <wpi/SmallString.h>
+
+#include "hal/Errors.h"
+#include "hal/HALBase.h"
+
+namespace {
+struct LastErrorStorage {
+ int32_t status;
+ wpi::SmallString<512> message;
+};
+} // namespace
+
+static LastErrorStorage& GetThreadLastError() {
+ thread_local LastErrorStorage lastError;
+ return lastError;
+}
+
+namespace hal {
+void SetLastError(int32_t* status, std::string_view value) {
+ LastErrorStorage& lastError = GetThreadLastError();
+ lastError.message = value;
+ lastError.status = *status;
+ *status = HAL_USE_LAST_ERROR;
+}
+
+void SetLastErrorIndexOutOfRange(int32_t* status, std::string_view message,
+ int32_t minimum, int32_t maximum,
+ int32_t requested) {
+ SetLastError(
+ status,
+ fmt::format("{}\n Status: {}\n Minimum: {} Maximum: {} Requested: {}",
+ message, *status, minimum, maximum, requested));
+}
+
+void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message,
+ int32_t channel,
+ std::string_view previousAllocation) {
+ hal::SetLastError(status,
+ fmt::format("{} {} previously allocated.\n"
+ "Location of the previous allocation:\n{}\n"
+ "Location of the current allocation:",
+ message, channel, previousAllocation));
+}
+} // namespace hal
+
+extern "C" {
+const char* HAL_GetLastError(int32_t* status) {
+ if (*status == HAL_USE_LAST_ERROR) {
+ LastErrorStorage& lastError = GetThreadLastError();
+ *status = lastError.status;
+ return lastError.message.c_str();
+ }
+ return HAL_GetErrorMessage(*status);
+}
+} // extern "C"
diff --git a/hal/src/main/native/cpp/Main.cpp b/hal/src/main/native/cpp/Main.cpp
index a37c2b0..a43a108 100644
--- a/hal/src/main/native/cpp/Main.cpp
+++ b/hal/src/main/native/cpp/Main.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "hal/Main.h"
@@ -36,14 +33,12 @@
mainObj->gExitCv.notify_all();
}
-namespace hal {
-namespace init {
+namespace hal::init {
void InitializeMain() {
static MainObj mO;
mainObj = &mO;
}
-} // namespace init
-} // namespace hal
+} // namespace hal::init
extern "C" {
@@ -55,10 +50,16 @@
gExitFunc = exitFunc;
}
-HAL_Bool HAL_HasMain(void) { return gHasMain; }
+HAL_Bool HAL_HasMain(void) {
+ return gHasMain;
+}
-void HAL_RunMain(void) { gMainFunc(gMainParam); }
+void HAL_RunMain(void) {
+ gMainFunc(gMainParam);
+}
-void HAL_ExitMain(void) { gExitFunc(gMainParam); }
+void HAL_ExitMain(void) {
+ gExitFunc(gMainParam);
+}
} // extern "C"
diff --git a/hal/src/main/native/cpp/cpp/fpga_clock.cpp b/hal/src/main/native/cpp/cpp/fpga_clock.cpp
index ae65ee7..550596a 100644
--- a/hal/src/main/native/cpp/cpp/fpga_clock.cpp
+++ b/hal/src/main/native/cpp/cpp/fpga_clock.cpp
@@ -1,15 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "hal/cpp/fpga_clock.h"
+#include <cstdio>
#include <limits>
-#include <wpi/raw_ostream.h>
+#include <fmt/format.h>
#include "hal/HALBase.h"
@@ -22,11 +20,12 @@
int32_t status = 0;
uint64_t currentTime = HAL_GetFPGATime(&status);
if (status != 0) {
- wpi::errs()
- << "Call to HAL_GetFPGATime failed in fpga_clock::now() with status "
- << status
- << ". Initialization might have failed. Time will not be correct\n";
- wpi::errs().flush();
+ fmt::print(
+ stderr,
+ "Call to HAL_GetFPGATime failed in fpga_clock::now() with status {}. "
+ "Initialization might have failed. Time will not be correct\n",
+ status);
+ std::fflush(stderr);
return epoch();
}
return time_point(std::chrono::microseconds(currentTime));
diff --git a/hal/src/main/native/cpp/handles/HandlesInternal.cpp b/hal/src/main/native/cpp/handles/HandlesInternal.cpp
index 5e66ce1..80dca71 100644
--- a/hal/src/main/native/cpp/handles/HandlesInternal.cpp
+++ b/hal/src/main/native/cpp/handles/HandlesInternal.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "hal/handles/HandlesInternal.h"
@@ -80,9 +77,13 @@
}
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
int16_t version) {
- if (index < 0) return HAL_kInvalidHandle;
+ if (index < 0) {
+ return HAL_kInvalidHandle;
+ }
uint8_t hType = static_cast<uint8_t>(handleType);
- if (hType == 0 || hType > 127) return HAL_kInvalidHandle;
+ if (hType == 0 || hType > 127) {
+ return HAL_kInvalidHandle;
+ }
// set last 8 bits, then shift to first 8 bits
HAL_Handle handle = hType;
handle = handle << 8;
diff --git a/hal/src/main/native/cpp/jni/AccelerometerJNI.cpp b/hal/src/main/native/cpp/jni/AccelerometerJNI.cpp
index 6d0d256..d2c107e 100644
--- a/hal/src/main/native/cpp/jni/AccelerometerJNI.cpp
+++ b/hal/src/main/native/cpp/jni/AccelerometerJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
index 3d74b24..75da176 100644
--- a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
+++ b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp b/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp
index c06e513..154301f 100644
--- a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp
+++ b/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
+#include <wpi/jni_util.h>
+
#include "HALUtil.h"
#include "edu_wpi_first_hal_AnalogGyroJNI.h"
#include "hal/AnalogGyro.h"
@@ -27,8 +26,9 @@
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
- HAL_GyroHandle handle =
- HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id, &status);
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ HAL_GyroHandle handle = HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id,
+ stack.c_str(), &status);
// Analog input does range checking, so we don't need to do so.
CheckStatusForceThrow(env, status);
return (jint)handle;
diff --git a/hal/src/main/native/cpp/jni/AnalogJNI.cpp b/hal/src/main/native/cpp/jni/AnalogJNI.cpp
index 8b920ac..a2cccb6 100644
--- a/hal/src/main/native/cpp/jni/AnalogJNI.cpp
+++ b/hal/src/main/native/cpp/jni/AnalogJNI.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
+#include <wpi/jni_util.h>
+
#include "HALUtil.h"
#include "edu_wpi_first_hal_AnalogJNI.h"
#include "hal/AnalogAccumulator.h"
@@ -32,9 +31,10 @@
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
- auto analog = HAL_InitializeAnalogInputPort((HAL_PortHandle)id, &status);
- CheckStatusRange(env, status, 0, HAL_GetNumAnalogInputs(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto analog =
+ HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
return (jint)analog;
}
@@ -60,10 +60,10 @@
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
- HAL_AnalogOutputHandle analog =
- HAL_InitializeAnalogOutputPort((HAL_PortHandle)id, &status);
- CheckStatusRange(env, status, 0, HAL_GetNumAnalogOutputs(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ HAL_AnalogOutputHandle analog = HAL_InitializeAnalogOutputPort(
+ (HAL_PortHandle)id, stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
return (jlong)analog;
}
@@ -298,6 +298,22 @@
/*
* Class: edu_wpi_first_hal_AnalogJNI
+ * Method: getAnalogValueToVolts
+ * Signature: (II)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_AnalogJNI_getAnalogValueToVolts
+ (JNIEnv* env, jclass, jint id, jint rawValue)
+{
+ int32_t status = 0;
+ jdouble returnValue =
+ HAL_GetAnalogValueToVolts((HAL_AnalogInputHandle)id, rawValue, &status);
+ CheckStatus(env, status);
+ return returnValue;
+}
+
+/*
+ * Class: edu_wpi_first_hal_AnalogJNI
* Method: getAnalogVoltage
* Signature: (I)D
*/
diff --git a/hal/src/main/native/cpp/jni/CANAPIJNI.cpp b/hal/src/main/native/cpp/jni/CANAPIJNI.cpp
index f42cc2f..106167a 100644
--- a/hal/src/main/native/cpp/jni/CANAPIJNI.cpp
+++ b/hal/src/main/native/cpp/jni/CANAPIJNI.cpp
@@ -1,17 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
-#include <wpi/SmallString.h>
#include <wpi/jni_util.h>
-#include <wpi/raw_ostream.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_CANAPIJNI.h"
@@ -197,11 +192,15 @@
if (!CheckStatus(env, status)) {
return false;
}
- if (dataLength > 8) dataLength = 8;
+ if (dataLength > 8) {
+ dataLength = 8;
+ }
jbyteArray toSetArray = SetCANDataObject(env, data, dataLength, timestamp);
auto javaLen = env->GetArrayLength(toSetArray);
- if (javaLen < dataLength) dataLength = javaLen;
+ if (javaLen < dataLength) {
+ dataLength = javaLen;
+ }
env->SetByteArrayRegion(toSetArray, 0, dataLength,
reinterpret_cast<jbyte*>(dataTemp));
return true;
@@ -229,11 +228,15 @@
if (!CheckStatus(env, status)) {
return false;
}
- if (dataLength > 8) dataLength = 8;
+ if (dataLength > 8) {
+ dataLength = 8;
+ }
jbyteArray toSetArray = SetCANDataObject(env, data, dataLength, timestamp);
auto javaLen = env->GetArrayLength(toSetArray);
- if (javaLen < dataLength) dataLength = javaLen;
+ if (javaLen < dataLength) {
+ dataLength = javaLen;
+ }
env->SetByteArrayRegion(toSetArray, 0, dataLength,
reinterpret_cast<jbyte*>(dataTemp));
return true;
@@ -262,11 +265,15 @@
if (!CheckStatus(env, status)) {
return false;
}
- if (dataLength > 8) dataLength = 8;
+ if (dataLength > 8) {
+ dataLength = 8;
+ }
jbyteArray toSetArray = SetCANDataObject(env, data, dataLength, timestamp);
auto javaLen = env->GetArrayLength(toSetArray);
- if (javaLen < dataLength) dataLength = javaLen;
+ if (javaLen < dataLength) {
+ dataLength = javaLen;
+ }
env->SetByteArrayRegion(toSetArray, 0, dataLength,
reinterpret_cast<jbyte*>(dataTemp));
return true;
diff --git a/hal/src/main/native/cpp/jni/CANJNI.cpp b/hal/src/main/native/cpp/jni/CANJNI.cpp
index 42b484b..968f656 100644
--- a/hal/src/main/native/cpp/jni/CANJNI.cpp
+++ b/hal/src/main/native/cpp/jni/CANJNI.cpp
@@ -1,17 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
-#include <wpi/SmallString.h>
#include <wpi/jni_util.h>
-#include <wpi/raw_ostream.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_can_CANJNI.h"
@@ -64,19 +59,21 @@
HAL_CAN_ReceiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize,
timeStampPtr, &status);
- if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr;
+ if (!CheckCANStatus(env, status, *messageIDPtr)) {
+ return nullptr;
+ }
return MakeJByteArray(env,
- wpi::StringRef{reinterpret_cast<const char*>(buffer),
- static_cast<size_t>(dataSize)});
+ std::string_view{reinterpret_cast<const char*>(buffer),
+ static_cast<size_t>(dataSize)});
}
/*
* Class: edu_wpi_first_hal_can_CANJNI
- * Method: GetCANStatus
+ * Method: getCANStatus
* Signature: (Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_can_CANJNI_GetCANStatus
+Java_edu_wpi_first_hal_can_CANJNI_getCANStatus
(JNIEnv* env, jclass, jobject canStatus)
{
float percentBusUtilization = 0;
@@ -88,7 +85,9 @@
HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount,
&receiveErrorCount, &transmitErrorCount, &status);
- if (!CheckStatus(env, status)) return;
+ if (!CheckStatus(env, status)) {
+ return;
+ }
SetCanStatusObject(env, canStatus, percentBusUtilization, busOffCount,
txFullCount, receiveErrorCount, transmitErrorCount);
diff --git a/hal/src/main/native/cpp/jni/CTREPCMJNI.cpp b/hal/src/main/native/cpp/jni/CTREPCMJNI.cpp
new file mode 100644
index 0000000..4d22f66
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/CTREPCMJNI.cpp
@@ -0,0 +1,340 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include <wpi/jni_util.h>
+
+#include "HALUtil.h"
+#include "edu_wpi_first_hal_CTREPCMJNI.h"
+#include "hal/CTREPCM.h"
+#include "hal/Ports.h"
+#include "hal/handles/HandlesInternal.h"
+
+using namespace hal;
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: initialize
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_initialize
+ (JNIEnv* env, jclass, jint module)
+{
+ int32_t status = 0;
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto handle = HAL_InitializeCTREPCM(module, stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
+ return handle;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: free
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_free
+ (JNIEnv* env, jclass, jint handle)
+{
+ HAL_FreeCTREPCM(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: checkSolenoidChannel
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_checkSolenoidChannel
+ (JNIEnv*, jclass, jint channel)
+{
+ return HAL_CheckCTREPCMSolenoidChannel(channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressor
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressor
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressor(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: setClosedLoopControl
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_setClosedLoopControl
+ (JNIEnv* env, jclass, jint handle, jboolean enabled)
+{
+ int32_t status = 0;
+ HAL_SetCTREPCMClosedLoopControl(handle, enabled, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getClosedLoopControl
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getClosedLoopControl
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMClosedLoopControl(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getPressureSwitch
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getPressureSwitch
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMPressureSwitch(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorCurrent
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorCurrent
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressorCurrent(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorCurrentTooHighFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorCurrentTooHighFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressorCurrentTooHighFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorCurrentTooHighStickyFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorCurrentTooHighStickyFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result =
+ HAL_GetCTREPCMCompressorCurrentTooHighStickyFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorShortedFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorShortedFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressorShortedFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorShortedStickyFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorShortedStickyFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressorShortedStickyFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorNotConnectedFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorNotConnectedFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMCompressorNotConnectedFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getCompressorNotConnectedStickyFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getCompressorNotConnectedStickyFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result =
+ HAL_GetCTREPCMCompressorNotConnectedStickyFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getSolenoids
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getSolenoids
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMSolenoids(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: setSolenoids
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_setSolenoids
+ (JNIEnv* env, jclass, jint handle, jint mask, jint value)
+{
+ int32_t status = 0;
+ HAL_SetCTREPCMSolenoids(handle, mask, value, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getSolenoidDisabledList
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getSolenoidDisabledList
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMSolenoidDisabledList(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getSolenoidVoltageFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getSolenoidVoltageFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMSolenoidVoltageFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: getSolenoidVoltageStickyFault
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_getSolenoidVoltageStickyFault
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetCTREPCMSolenoidVoltageStickyFault(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: clearAllStickyFaults
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_clearAllStickyFaults
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_ClearAllCTREPCMStickyFaults(handle, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: fireOneShot
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_fireOneShot
+ (JNIEnv* env, jclass, jint handle, jint index)
+{
+ int32_t status = 0;
+ HAL_FireCTREPCMOneShot(handle, index, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_CTREPCMJNI
+ * Method: setOneShotDuration
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_CTREPCMJNI_setOneShotDuration
+ (JNIEnv* env, jclass, jint handle, jint index, jint durMs)
+{
+ int32_t status = 0;
+ HAL_SetCTREPCMOneShotDuration(handle, index, durMs, &status);
+ CheckStatus(env, status, false);
+}
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/CompressorJNI.cpp b/hal/src/main/native/cpp/jni/CompressorJNI.cpp
deleted file mode 100644
index c214c60..0000000
--- a/hal/src/main/native/cpp/jni/CompressorJNI.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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 "HALUtil.h"
-#include "edu_wpi_first_hal_CompressorJNI.h"
-#include "hal/Compressor.h"
-#include "hal/Ports.h"
-#include "hal/Solenoid.h"
-
-using namespace hal;
-
-extern "C" {
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: initializeCompressor
- * Signature: (B)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_initializeCompressor
- (JNIEnv* env, jclass, jbyte module)
-{
- int32_t status = 0;
- auto handle = HAL_InitializeCompressor(module, &status);
- CheckStatusRange(env, status, 0, HAL_GetNumPCMModules(), module);
-
- return (jint)handle;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: checkCompressorModule
- * Signature: (B)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_checkCompressorModule
- (JNIEnv* env, jclass, jbyte module)
-{
- return HAL_CheckCompressorModule(module);
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressor
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressor
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressor((HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: setCompressorClosedLoopControl
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_setCompressorClosedLoopControl
- (JNIEnv* env, jclass, jint compressorHandle, jboolean value)
-{
- int32_t status = 0;
- HAL_SetCompressorClosedLoopControl((HAL_CompressorHandle)compressorHandle,
- value, &status);
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorClosedLoopControl
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorClosedLoopControl
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorClosedLoopControl(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorPressureSwitch
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorPressureSwitch
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorPressureSwitch(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorCurrent
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorCurrent
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- double val =
- HAL_GetCompressorCurrent((HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorCurrentTooHighFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorCurrentTooHighFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorCurrentTooHighFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorCurrentTooHighStickyFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorCurrentTooHighStickyFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorShortedStickyFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorShortedStickyFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorShortedStickyFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorShortedFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorShortedFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorShortedFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorNotConnectedStickyFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorNotConnectedStickyFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorNotConnectedStickyFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: getCompressorNotConnectedFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_getCompressorNotConnectedFault
- (JNIEnv* env, jclass, jint compressorHandle)
-{
- int32_t status = 0;
- bool val = HAL_GetCompressorNotConnectedFault(
- (HAL_CompressorHandle)compressorHandle, &status);
- CheckStatus(env, status);
- return val;
-}
-/*
- * Class: edu_wpi_first_hal_CompressorJNI
- * Method: clearAllPCMStickyFaults
- * Signature: (B)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_CompressorJNI_clearAllPCMStickyFaults
- (JNIEnv* env, jclass, jbyte module)
-{
- int32_t status = 0;
- HAL_ClearAllPCMStickyFaults(static_cast<int32_t>(module), &status);
- CheckStatus(env, status);
-}
-
-} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/ConstantsJNI.cpp b/hal/src/main/native/cpp/jni/ConstantsJNI.cpp
index 9c4aa63..600b7f7 100644
--- a/hal/src/main/native/cpp/jni/ConstantsJNI.cpp
+++ b/hal/src/main/native/cpp/jni/ConstantsJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/CounterJNI.cpp b/hal/src/main/native/cpp/jni/CounterJNI.cpp
index 06cbceb..0565d5b 100644
--- a/hal/src/main/native/cpp/jni/CounterJNI.cpp
+++ b/hal/src/main/native/cpp/jni/CounterJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -122,12 +119,6 @@
HAL_SetCounterDownSource((HAL_CounterHandle)id,
(HAL_Handle)digitalSourceHandle,
(HAL_AnalogTriggerType)analogTriggerType, &status);
- if (status == PARAMETER_OUT_OF_RANGE) {
- ThrowIllegalArgumentException(env,
- "Counter only supports DownSource in "
- "TwoPulse and ExternalDirection modes.");
- return;
- }
CheckStatus(env, status);
}
@@ -243,10 +234,6 @@
{
int32_t status = 0;
HAL_SetCounterSamplesToAverage((HAL_CounterHandle)id, value, &status);
- if (status == PARAMETER_OUT_OF_RANGE) {
- ThrowBoundaryException(env, value, 1, 127);
- return;
- }
CheckStatus(env, status);
}
diff --git a/hal/src/main/native/cpp/jni/DIOJNI.cpp b/hal/src/main/native/cpp/jni/DIOJNI.cpp
index 428dd99..5cd6c2e 100644
--- a/hal/src/main/native/cpp/jni/DIOJNI.cpp
+++ b/hal/src/main/native/cpp/jni/DIOJNI.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
+#include <wpi/jni_util.h>
+
#include "HALUtil.h"
#include "edu_wpi_first_hal_DIOJNI.h"
#include "hal/DIO.h"
@@ -30,10 +29,10 @@
(JNIEnv* env, jclass, jint id, jboolean input)
{
int32_t status = 0;
- auto dio = HAL_InitializeDIOPort((HAL_PortHandle)id,
- static_cast<uint8_t>(input), &status);
- CheckStatusRange(env, status, 0, HAL_GetNumDigitalChannels(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto dio = HAL_InitializeDIOPort(
+ (HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
return (jint)dio;
}
@@ -76,11 +75,11 @@
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: setDIO
- * Signature: (IS)V
+ * Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDIO
- (JNIEnv* env, jclass, jint id, jshort value)
+ (JNIEnv* env, jclass, jint id, jboolean value)
{
int32_t status = 0;
HAL_SetDIO((HAL_DigitalHandle)id, value, &status);
diff --git a/hal/src/main/native/cpp/jni/DMAJNI.cpp b/hal/src/main/native/cpp/jni/DMAJNI.cpp
new file mode 100644
index 0000000..3e95c7b
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/DMAJNI.cpp
@@ -0,0 +1,416 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <algorithm>
+#include <cstring>
+
+#include "HALUtil.h"
+#include "edu_wpi_first_hal_DMAJNI.h"
+#include "hal/DMA.h"
+#include "hal/handles/HandlesInternal.h"
+
+using namespace hal;
+
+namespace hal {
+bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
+ HAL_FPGAEncoderHandle* fpgaEncoderHandle,
+ HAL_CounterHandle* counterHandle);
+} // namespace hal
+
+extern "C" {
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: initialize
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_DMAJNI_initialize
+ (JNIEnv* env, jclass)
+{
+ int32_t status = 0;
+ auto handle = HAL_InitializeDMA(&status);
+ CheckStatusForceThrow(env, status);
+ return handle;
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: free
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_free
+ (JNIEnv* env, jclass, jint handle)
+{
+ HAL_FreeDMA(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: setPause
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_setPause
+ (JNIEnv* env, jclass, jint handle, jboolean pause)
+{
+ int32_t status = 0;
+ HAL_SetDMAPause(handle, pause, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: setTimedTrigger
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_setTimedTrigger
+ (JNIEnv* env, jclass, jint handle, jdouble seconds)
+{
+ int32_t status = 0;
+ HAL_SetDMATimedTrigger(handle, seconds, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: setTimedTriggerCycles
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_setTimedTriggerCycles
+ (JNIEnv* env, jclass, jint handle, jint cycles)
+{
+ int32_t status = 0;
+ HAL_SetDMATimedTriggerCycles(handle, static_cast<uint32_t>(cycles), &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addEncoder
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addEncoder
+ (JNIEnv* env, jclass, jint handle, jint encoderHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMAEncoder(handle, encoderHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addEncoderPeriod
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addEncoderPeriod
+ (JNIEnv* env, jclass, jint handle, jint encoderHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMAEncoderPeriod(handle, encoderHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addCounter
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addCounter
+ (JNIEnv* env, jclass, jint handle, jint counterHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMACounter(handle, counterHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addCounterPeriod
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addCounterPeriod
+ (JNIEnv* env, jclass, jint handle, jint counterHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMACounterPeriod(handle, counterHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addDutyCycle
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addDutyCycle
+ (JNIEnv* env, jclass, jint handle, jint dutyCycleHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMADutyCycle(handle, dutyCycleHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addDigitalSource
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addDigitalSource
+ (JNIEnv* env, jclass, jint handle, jint digitalSourceHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMADigitalSource(handle, digitalSourceHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addAnalogInput
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addAnalogInput
+ (JNIEnv* env, jclass, jint handle, jint analogInputHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMAAnalogInput(handle, analogInputHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addAveragedAnalogInput
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addAveragedAnalogInput
+ (JNIEnv* env, jclass, jint handle, jint analogInputHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMAAveragedAnalogInput(handle, analogInputHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: addAnalogAccumulator
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_addAnalogAccumulator
+ (JNIEnv* env, jclass, jint handle, jint analogInputHandle)
+{
+ int32_t status = 0;
+ HAL_AddDMAAnalogAccumulator(handle, analogInputHandle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: setExternalTrigger
+ * Signature: (IIIZZ)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_DMAJNI_setExternalTrigger
+ (JNIEnv* env, jclass, jint handle, jint digitalSourceHandle,
+ jint analogTriggerType, jboolean rising, jboolean falling)
+{
+ int32_t status = 0;
+ int32_t idx = HAL_SetDMAExternalTrigger(
+ handle, digitalSourceHandle,
+ static_cast<HAL_AnalogTriggerType>(analogTriggerType), rising, falling,
+ &status);
+ CheckStatus(env, status);
+ return idx;
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: clearSensors
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_clearSensors
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_ClearDMASensors(handle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: clearExternalTriggers
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_clearExternalTriggers
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_ClearDMAExternalTriggers(handle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: startDMA
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_startDMA
+ (JNIEnv* env, jclass, jint handle, jint queueDepth)
+{
+ int32_t status = 0;
+ HAL_StartDMA(handle, queueDepth, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: stopDMA
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_DMAJNI_stopDMA
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_StopDMA(handle, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: readDMA
+ * Signature: (ID[I[I)J
+ */
+JNIEXPORT jlong JNICALL
+Java_edu_wpi_first_hal_DMAJNI_readDMA
+ (JNIEnv* env, jclass, jint handle, jdouble timeoutSeconds, jintArray buf,
+ jintArray store)
+{
+ int32_t status = 0;
+ HAL_DMASample dmaSample;
+ std::memset(&dmaSample, 0, sizeof(dmaSample));
+ int32_t remaining = 0;
+ HAL_DMAReadStatus readStatus =
+ HAL_ReadDMA(handle, &dmaSample, timeoutSeconds, &remaining, &status);
+ CheckStatus(env, status);
+
+ static_assert(sizeof(uint32_t) == sizeof(jint), "Java ints must be 32 bits");
+
+ env->SetIntArrayRegion(buf, 0, dmaSample.captureSize,
+ reinterpret_cast<jint*>(dmaSample.readBuffer));
+
+ int32_t* nativeArr =
+ static_cast<int32_t*>(env->GetPrimitiveArrayCritical(store, nullptr));
+
+ std::copy_n(
+ dmaSample.channelOffsets,
+ sizeof(dmaSample.channelOffsets) / sizeof(dmaSample.channelOffsets[0]),
+ nativeArr);
+ nativeArr[22] = static_cast<int32_t>(dmaSample.captureSize);
+ nativeArr[23] = static_cast<int32_t>(dmaSample.triggerChannels);
+ nativeArr[24] = remaining;
+ nativeArr[25] = readStatus;
+
+ env->ReleasePrimitiveArrayCritical(store, nativeArr, JNI_ABORT);
+
+ return dmaSample.timeStamp;
+}
+
+// TODO sync these up
+enum DMAOffsetConstants {
+ kEnable_AI0_Low = 0,
+ kEnable_AI0_High = 1,
+ kEnable_AIAveraged0_Low = 2,
+ kEnable_AIAveraged0_High = 3,
+ kEnable_AI1_Low = 4,
+ kEnable_AI1_High = 5,
+ kEnable_AIAveraged1_Low = 6,
+ kEnable_AIAveraged1_High = 7,
+ kEnable_Accumulator0 = 8,
+ kEnable_Accumulator1 = 9,
+ kEnable_DI = 10,
+ kEnable_AnalogTriggers = 11,
+ kEnable_Counters_Low = 12,
+ kEnable_Counters_High = 13,
+ kEnable_CounterTimers_Low = 14,
+ kEnable_CounterTimers_High = 15,
+ kEnable_Encoders_Low = 16,
+ kEnable_Encoders_High = 17,
+ kEnable_EncoderTimers_Low = 18,
+ kEnable_EncoderTimers_High = 19,
+ kEnable_DutyCycle_Low = 20,
+ kEnable_DutyCycle_High = 21,
+};
+
+/*
+ * Class: edu_wpi_first_hal_DMAJNI
+ * Method: getSensorReadData
+ * Signature: (I)Ljava/lang/Object;
+ */
+JNIEXPORT jobject JNICALL
+Java_edu_wpi_first_hal_DMAJNI_getSensorReadData
+ (JNIEnv* env, jclass, jint handle)
+{
+ HAL_Handle halHandle = static_cast<HAL_Handle>(handle);
+
+ // Check for encoder/counter handle
+ HAL_FPGAEncoderHandle fpgaEncoderHandle = 0;
+ HAL_CounterHandle counterHandle = 0;
+ bool validEncoderHandle =
+ hal::GetEncoderBaseHandle(halHandle, &fpgaEncoderHandle, &counterHandle);
+
+ if (validEncoderHandle) {
+ if (counterHandle != HAL_kInvalidHandle) {
+ int32_t cindex = getHandleIndex(counterHandle);
+ if (cindex < 4) {
+ return CreateDMABaseStore(env, kEnable_Counters_Low, cindex);
+ } else {
+ return CreateDMABaseStore(env, kEnable_Counters_High, cindex - 4);
+ }
+ } else {
+ int32_t cindex = getHandleIndex(fpgaEncoderHandle);
+ if (cindex < 4) {
+ return CreateDMABaseStore(env, kEnable_Encoders_Low, cindex);
+ } else {
+ return CreateDMABaseStore(env, kEnable_Encoders_High, cindex - 4);
+ }
+ }
+ }
+
+ HAL_HandleEnum handleType = getHandleType(halHandle);
+ int32_t index = getHandleIndex(halHandle);
+ if (handleType == HAL_HandleEnum::DIO) {
+ return CreateDMABaseStore(env, kEnable_DI, index);
+ } else if (handleType == HAL_HandleEnum::AnalogTrigger) {
+ return CreateDMABaseStore(env, kEnable_AnalogTriggers, index);
+ } else if (handleType == HAL_HandleEnum::AnalogInput) {
+ if (index < 4) {
+ return CreateDMABaseStore(env, kEnable_AI0_Low, index);
+ } else {
+ return CreateDMABaseStore(env, kEnable_AI0_High, index - 4);
+ }
+ } else if (handleType == HAL_HandleEnum::DutyCycle) {
+ if (index < 4) {
+ return CreateDMABaseStore(env, kEnable_DutyCycle_Low, index);
+ } else {
+ return CreateDMABaseStore(env, kEnable_DutyCycle_High, index - 4);
+ }
+ } else {
+ return nullptr;
+ }
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/DigitalGlitchFilterJNI.cpp b/hal/src/main/native/cpp/jni/DigitalGlitchFilterJNI.cpp
index cfb504d..762f7fb 100644
--- a/hal/src/main/native/cpp/jni/DigitalGlitchFilterJNI.cpp
+++ b/hal/src/main/native/cpp/jni/DigitalGlitchFilterJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp b/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
index b191374..96cc27b 100644
--- a/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
+++ b/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/EncoderJNI.cpp b/hal/src/main/native/cpp/jni/EncoderJNI.cpp
index 11686a6..f93e064 100644
--- a/hal/src/main/native/cpp/jni/EncoderJNI.cpp
+++ b/hal/src/main/native/cpp/jni/EncoderJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -270,10 +267,6 @@
{
int32_t status = 0;
HAL_SetEncoderSamplesToAverage((HAL_EncoderHandle)id, value, &status);
- if (status == PARAMETER_OUT_OF_RANGE) {
- ThrowBoundaryException(env, value, 1, 127);
- return;
- }
CheckStatus(env, status);
}
diff --git a/hal/src/main/native/cpp/jni/HAL.cpp b/hal/src/main/native/cpp/jni/HAL.cpp
index 3d736bf..4e26032 100644
--- a/hal/src/main/native/cpp/jni/HAL.cpp
+++ b/hal/src/main/native/cpp/jni/HAL.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "hal/HAL.h"
@@ -12,6 +9,7 @@
#include <cassert>
#include <cstring>
+#include <fmt/format.h>
#include <wpi/jni_util.h>
#include "HALUtil.h"
@@ -86,6 +84,30 @@
/*
* Class: edu_wpi_first_hal_HAL
+ * Method: simPeriodicBeforeNative
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_HAL_simPeriodicBeforeNative
+ (JNIEnv*, jclass)
+{
+ HAL_SimPeriodicBefore();
+}
+
+/*
+ * Class: edu_wpi_first_hal_HAL
+ * Method: simPeriodicAfterNative
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_HAL_simPeriodicAfterNative
+ (JNIEnv*, jclass)
+{
+ HAL_SimPeriodicAfter();
+}
+
+/*
+ * Class: edu_wpi_first_hal_HAL
* Method: observeUserProgramStarting
* Signature: ()V
*/
@@ -172,7 +194,6 @@
static_assert(sizeof(HAL_ControlWord) == sizeof(jint),
"Java int must match the size of control word");
HAL_ControlWord controlWord;
- std::memset(&controlWord, 0, sizeof(HAL_ControlWord));
HAL_GetControlWord(&controlWord);
jint retVal = 0;
std::memcpy(&retVal, &controlWord, sizeof(HAL_ControlWord));
@@ -207,13 +228,11 @@
jsize javaSize = env->GetArrayLength(axesArray);
if (axes.count > javaSize) {
- wpi::SmallString<128> errStr;
- wpi::raw_svector_ostream oss{errStr};
- oss << "Native array size larger then passed in java array size "
- << "Native Size: " << static_cast<int>(axes.count)
- << " Java Size: " << static_cast<int>(javaSize);
-
- ThrowIllegalArgumentException(env, errStr.str());
+ ThrowIllegalArgumentException(
+ env,
+ fmt::format("Native array size larger then passed in java array "
+ "size\nNative Size: {} Java Size: {}",
+ static_cast<int>(axes.count), static_cast<int>(javaSize)));
return 0;
}
@@ -236,13 +255,11 @@
jsize javaSize = env->GetArrayLength(povsArray);
if (povs.count > javaSize) {
- wpi::SmallString<128> errStr;
- wpi::raw_svector_ostream oss{errStr};
- oss << "Native array size larger then passed in java array size "
- << "Native Size: " << static_cast<int>(povs.count)
- << " Java Size: " << static_cast<int>(javaSize);
-
- ThrowIllegalArgumentException(env, errStr.str());
+ ThrowIllegalArgumentException(
+ env,
+ fmt::format("Native array size larger then passed in java array "
+ "size\nNative Size: {} Java Size: {}",
+ static_cast<int>(povs.count), static_cast<int>(javaSize)));
return 0;
}
diff --git a/hal/src/main/native/cpp/jni/HALUtil.cpp b/hal/src/main/native/cpp/jni/HALUtil.cpp
index 2938f45..1070085 100644
--- a/hal/src/main/native/cpp/jni/HALUtil.cpp
+++ b/hal/src/main/native/cpp/jni/HALUtil.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "HALUtil.h"
@@ -15,9 +12,8 @@
#include <cstring>
#include <string>
-#include <wpi/SmallString.h>
+#include <fmt/format.h>
#include <wpi/jni_util.h>
-#include <wpi/raw_ostream.h>
#include "edu_wpi_first_hal_HALUtil.h"
#include "hal/CAN.h"
@@ -34,6 +30,12 @@
#define kRIOStatusFeatureNotSupported (kRioStatusOffset - 193)
#define kRIOStatusResourceNotInitialized -52010
+static_assert(edu_wpi_first_hal_HALUtil_RUNTIME_ROBORIO == HAL_Runtime_RoboRIO);
+static_assert(edu_wpi_first_hal_HALUtil_RUNTIME_ROBORIO2 ==
+ HAL_Runtime_RoboRIO2);
+static_assert(edu_wpi_first_hal_HALUtil_RUNTIME_SIMULATION ==
+ HAL_Runtime_Simulation);
+
static JavaVM* jvm = nullptr;
static JException illegalArgExCls;
static JException boundaryExCls;
@@ -50,6 +52,7 @@
static JClass accumulatorResultCls;
static JClass canDataCls;
static JClass halValueCls;
+static JClass baseStoreCls;
static const JClassInit classes[] = {
{"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls},
@@ -57,7 +60,8 @@
{"edu/wpi/first/hal/MatchInfoData", &matchInfoDataCls},
{"edu/wpi/first/hal/AccumulatorResult", &accumulatorResultCls},
{"edu/wpi/first/hal/CANData", &canDataCls},
- {"edu/wpi/first/hal/HALValue", &halValueCls}};
+ {"edu/wpi/first/hal/HALValue", &halValueCls},
+ {"edu/wpi/first/hal/DMAJNISample$BaseStore", &baseStoreCls}};
static const JExceptionInit exceptions[] = {
{"java/lang/IllegalArgumentException", &illegalArgExCls},
@@ -75,7 +79,7 @@
namespace hal {
-void ThrowUncleanStatusException(JNIEnv* env, wpi::StringRef msg,
+void ThrowUncleanStatusException(JNIEnv* env, std::string_view msg,
int32_t status) {
static jmethodID func =
env->GetMethodID(uncleanStatusExCls, "<init>", "(ILjava/lang/String;)V");
@@ -86,63 +90,64 @@
env->Throw(static_cast<jthrowable>(exception));
}
-void ThrowAllocationException(JNIEnv* env, int32_t minRange, int32_t maxRange,
- int32_t requestedValue, int32_t status) {
- const char* message = HAL_GetErrorMessage(status);
- wpi::SmallString<1024> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << " Code: " << status << ". " << message
- << ", Minimum Value: " << minRange << ", Maximum Value: " << maxRange
- << ", Requested Value: " << requestedValue;
- env->ThrowNew(allocationExCls, buf.c_str());
- allocationExCls.Throw(env, buf.c_str());
+void ThrowAllocationException(JNIEnv* env, const char* lastError,
+ int32_t status) {
+ allocationExCls.Throw(env,
+ fmt::format("Code: {}\n{}", status, lastError).c_str());
}
void ThrowHalHandleException(JNIEnv* env, int32_t status) {
- const char* message = HAL_GetErrorMessage(status);
- wpi::SmallString<1024> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << " Code: " << status << ". " << message;
- halHandleExCls.Throw(env, buf.c_str());
+ const char* message = HAL_GetLastError(&status);
+ halHandleExCls.Throw(env,
+ fmt::format(" Code: {}. {}", status, message).c_str());
}
void ReportError(JNIEnv* env, int32_t status, bool doThrow) {
- if (status == 0) return;
+ if (status == 0) {
+ return;
+ }
+ const char* message = HAL_GetLastError(&status);
if (status == HAL_HANDLE_ERROR) {
ThrowHalHandleException(env, status);
+ return;
}
- const char* message = HAL_GetErrorMessage(status);
if (doThrow && status < 0) {
- wpi::SmallString<1024> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << " Code: " << status << ". " << message;
- ThrowUncleanStatusException(env, buf.c_str(), status);
+ ThrowUncleanStatusException(
+ env, fmt::format(" Code: {}. {}", status, message).c_str(), status);
} else {
std::string func;
auto stack = GetJavaStackTrace(env, &func, "edu.wpi.first");
- HAL_SendError(1, status, 0, message, func.c_str(), stack.c_str(), 1);
+ // Make a copy of message for safety, calling back into the HAL might
+ // invalidate the string.
+ std::string lastMessage{message};
+ HAL_SendError(1, status, 0, lastMessage.c_str(), func.c_str(),
+ stack.c_str(), 1);
}
}
void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange,
int32_t requestedValue) {
- if (status == 0) return;
+ if (status == 0) {
+ return;
+ }
+ const char* lastError = HAL_GetLastError(&status);
if (status == NO_AVAILABLE_RESOURCES || status == RESOURCE_IS_ALLOCATED ||
status == RESOURCE_OUT_OF_RANGE) {
- ThrowAllocationException(env, minRange, maxRange, requestedValue, status);
+ ThrowAllocationException(env, lastError, status);
+ return;
}
if (status == HAL_HANDLE_ERROR) {
ThrowHalHandleException(env, status);
+ return;
}
- const char* message = HAL_GetErrorMessage(status);
- wpi::SmallString<1024> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << " Code: " << status << ". " << message;
- ThrowUncleanStatusException(env, buf.c_str(), status);
+ ThrowUncleanStatusException(
+ env, fmt::format(" Code: {}. {}", status, lastError).c_str(), status);
}
void ReportCANError(JNIEnv* env, int32_t status, int message_id) {
- if (status >= 0) return;
+ if (status >= 0) {
+ return;
+ }
switch (status) {
case kRioStatusSuccess:
// Everything is ok... don't throw.
@@ -150,9 +155,10 @@
case HAL_ERR_CANSessionMux_InvalidBuffer:
case kRIOStatusBufferInvalidSize: {
static jmethodID invalidBufConstruct = nullptr;
- if (!invalidBufConstruct)
+ if (!invalidBufConstruct) {
invalidBufConstruct =
env->GetMethodID(canInvalidBufferExCls, "<init>", "()V");
+ }
jobject exception =
env->NewObject(canInvalidBufferExCls, invalidBufConstruct);
env->Throw(static_cast<jthrowable>(exception));
@@ -161,9 +167,10 @@
case HAL_ERR_CANSessionMux_MessageNotFound:
case kRIOStatusOperationTimedOut: {
static jmethodID messageNotFoundConstruct = nullptr;
- if (!messageNotFoundConstruct)
+ if (!messageNotFoundConstruct) {
messageNotFoundConstruct =
env->GetMethodID(canMessageNotFoundExCls, "<init>", "()V");
+ }
jobject exception =
env->NewObject(canMessageNotFoundExCls, messageNotFoundConstruct);
env->Throw(static_cast<jthrowable>(exception));
@@ -171,48 +178,47 @@
}
case HAL_ERR_CANSessionMux_NotAllowed:
case kRIOStatusFeatureNotSupported: {
- wpi::SmallString<100> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << "MessageID = " << message_id;
- canMessageNotAllowedExCls.Throw(env, buf.c_str());
+ canMessageNotAllowedExCls.Throw(
+ env, fmt::format("MessageID = {}", message_id).c_str());
break;
}
case HAL_ERR_CANSessionMux_NotInitialized:
case kRIOStatusResourceNotInitialized: {
static jmethodID notInitConstruct = nullptr;
- if (!notInitConstruct)
+ if (!notInitConstruct) {
notInitConstruct =
env->GetMethodID(canNotInitializedExCls, "<init>", "()V");
+ }
jobject exception =
env->NewObject(canNotInitializedExCls, notInitConstruct);
env->Throw(static_cast<jthrowable>(exception));
break;
}
default: {
- wpi::SmallString<100> buf;
- wpi::raw_svector_ostream oss(buf);
- oss << "Fatal status code detected: " << status;
- uncleanStatusExCls.Throw(env, buf.c_str());
+ uncleanStatusExCls.Throw(
+ env, fmt::format("Fatal status code detected: {}", status).c_str());
break;
}
}
}
-void ThrowIllegalArgumentException(JNIEnv* env, wpi::StringRef msg) {
+void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) {
illegalArgExCls.Throw(env, msg);
}
void ThrowBoundaryException(JNIEnv* env, double value, double lower,
double upper) {
static jmethodID getMessage = nullptr;
- if (!getMessage)
+ if (!getMessage) {
getMessage = env->GetStaticMethodID(boundaryExCls, "getMessage",
"(DDD)Ljava/lang/String;");
+ }
static jmethodID constructor = nullptr;
- if (!constructor)
+ if (!constructor) {
constructor =
env->GetMethodID(boundaryExCls, "<init>", "(Ljava/lang/String;)V");
+ }
jobject msg = env->CallStaticObjectMethod(
boundaryExCls, getMessage, static_cast<jdouble>(value),
@@ -226,9 +232,10 @@
int32_t deadbandMinPwm, int32_t minPwm) {
static jmethodID constructor =
env->GetMethodID(pwmConfigDataResultCls, "<init>", "(IIIII)V");
- return env->NewObject(pwmConfigDataResultCls, constructor, (jint)maxPwm,
- (jint)deadbandMaxPwm, (jint)centerPwm,
- (jint)deadbandMinPwm, (jint)minPwm);
+ return env->NewObject(
+ pwmConfigDataResultCls, constructor, static_cast<jint>(maxPwm),
+ static_cast<jint>(deadbandMaxPwm), static_cast<jint>(centerPwm),
+ static_cast<jint>(deadbandMinPwm), static_cast<jint>(minPwm));
}
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
@@ -237,9 +244,11 @@
uint32_t transmitErrorCount) {
static jmethodID func =
env->GetMethodID(canStatusCls, "setStatus", "(DIIII)V");
- env->CallVoidMethod(canStatus, func, (jdouble)percentBusUtilization,
- (jint)busOffCount, (jint)txFullCount,
- (jint)receiveErrorCount, (jint)transmitErrorCount);
+ env->CallVoidMethod(
+ canStatus, func, static_cast<jdouble>(percentBusUtilization),
+ static_cast<jint>(busOffCount), static_cast<jint>(txFullCount),
+ static_cast<jint>(receiveErrorCount),
+ static_cast<jint>(transmitErrorCount));
}
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
@@ -250,11 +259,12 @@
env->CallVoidMethod(
matchStatus, func, MakeJString(env, matchInfo.eventName),
- MakeJString(env, wpi::StringRef{reinterpret_cast<const char*>(
- matchInfo.gameSpecificMessage),
- matchInfo.gameSpecificMessageSize}),
- (jint)matchInfo.matchNumber, (jint)matchInfo.replayNumber,
- (jint)matchInfo.matchType);
+ MakeJString(env,
+ {reinterpret_cast<const char*>(matchInfo.gameSpecificMessage),
+ matchInfo.gameSpecificMessageSize}),
+ static_cast<jint>(matchInfo.matchNumber),
+ static_cast<jint>(matchInfo.replayNumber),
+ static_cast<jint>(matchInfo.matchType));
}
void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult,
@@ -262,15 +272,16 @@
static jmethodID func =
env->GetMethodID(accumulatorResultCls, "set", "(JJ)V");
- env->CallVoidMethod(accumulatorResult, func, (jlong)value, (jlong)count);
+ env->CallVoidMethod(accumulatorResult, func, static_cast<jlong>(value),
+ static_cast<jlong>(count));
}
jbyteArray SetCANDataObject(JNIEnv* env, jobject canData, int32_t length,
uint64_t timestamp) {
static jmethodID func = env->GetMethodID(canDataCls, "setData", "(IJ)[B");
- jbyteArray retVal = static_cast<jbyteArray>(
- env->CallObjectMethod(canData, func, (jint)length, (jlong)timestamp));
+ jbyteArray retVal = static_cast<jbyteArray>(env->CallObjectMethod(
+ canData, func, static_cast<jint>(length), static_cast<jlong>(timestamp)));
return retVal;
}
@@ -298,11 +309,18 @@
default:
break;
}
- return env->CallStaticObjectMethod(halValueCls, fromNative, (jint)value.type,
- value1, value2);
+ return env->CallStaticObjectMethod(
+ halValueCls, fromNative, static_cast<jint>(value.type), value1, value2);
}
-JavaVM* GetJVM() { return jvm; }
+jobject CreateDMABaseStore(JNIEnv* env, jint valueType, jint index) {
+ static jmethodID ctor = env->GetMethodID(baseStoreCls, "<init>", "(II)V");
+ return env->NewObject(baseStoreCls, ctor, valueType, index);
+}
+
+JavaVM* GetJVM() {
+ return jvm;
+}
namespace sim {
jint SimOnLoad(JavaVM* vm, void* reserved);
@@ -322,17 +340,22 @@
jvm = vm;
JNIEnv* env;
- if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
+ }
for (auto& c : classes) {
*c.cls = JClass(env, c.name);
- if (!*c.cls) return JNI_ERR;
+ if (!*c.cls) {
+ return JNI_ERR;
+ }
}
for (auto& c : exceptions) {
*c.cls = JException(env, c.name);
- if (!*c.cls) return JNI_ERR;
+ if (!*c.cls) {
+ return JNI_ERR;
+ }
}
return sim::SimOnLoad(vm, reserved);
@@ -342,8 +365,9 @@
sim::SimOnUnload(vm, reserved);
JNIEnv* env;
- if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return;
+ }
// Delete global references
for (auto& c : classes) {
diff --git a/hal/src/main/native/cpp/jni/HALUtil.h b/hal/src/main/native/cpp/jni/HALUtil.h
index 0a192da..2afe595 100644
--- a/hal/src/main/native/cpp/jni/HALUtil.h
+++ b/hal/src/main/native/cpp/jni/HALUtil.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#ifndef HAL_HAL_SRC_MAIN_NATIVE_CPP_JNI_HALUTIL_H_
#define HAL_HAL_SRC_MAIN_NATIVE_CPP_JNI_HALUTIL_H_
@@ -11,7 +8,7 @@
#include <jni.h>
#include <stdint.h>
-#include <wpi/StringRef.h>
+#include <string_view>
struct HAL_MatchInfo;
struct HAL_Value;
@@ -24,29 +21,37 @@
int32_t requestedValue);
inline bool CheckStatus(JNIEnv* env, int32_t status, bool doThrow = true) {
- if (status != 0) ReportError(env, status, doThrow);
+ if (status != 0) {
+ ReportError(env, status, doThrow);
+ }
return status == 0;
}
inline bool CheckStatusRange(JNIEnv* env, int32_t status, int32_t minRange,
int32_t maxRange, int32_t requestedValue) {
- if (status != 0) ThrowError(env, status, minRange, maxRange, requestedValue);
+ if (status != 0) {
+ ThrowError(env, status, minRange, maxRange, requestedValue);
+ }
return status == 0;
}
inline bool CheckStatusForceThrow(JNIEnv* env, int32_t status) {
- if (status != 0) ThrowError(env, status, 0, 0, 0);
+ if (status != 0) {
+ ThrowError(env, status, 0, 0, 0);
+ }
return status == 0;
}
void ReportCANError(JNIEnv* env, int32_t status, int32_t message_id);
inline bool CheckCANStatus(JNIEnv* env, int32_t status, int32_t message_id) {
- if (status != 0) ReportCANError(env, status, message_id);
+ if (status != 0) {
+ ReportCANError(env, status, message_id);
+ }
return status == 0;
}
-void ThrowIllegalArgumentException(JNIEnv* env, wpi::StringRef msg);
+void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg);
void ThrowBoundaryException(JNIEnv* env, double value, double lower,
double upper);
@@ -70,6 +75,8 @@
jobject CreateHALValue(JNIEnv* env, const HAL_Value& value);
+jobject CreateDMABaseStore(JNIEnv* env, jint valueType, jint index);
+
JavaVM* GetJVM();
} // namespace hal
diff --git a/hal/src/main/native/cpp/jni/I2CJNI.cpp b/hal/src/main/native/cpp/jni/I2CJNI.cpp
index de27df6..b605b95 100644
--- a/hal/src/main/native/cpp/jni/I2CJNI.cpp
+++ b/hal/src/main/native/cpp/jni/I2CJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -45,7 +42,7 @@
jbyte sendSize, jobject dataReceived, jbyte receiveSize)
{
uint8_t* dataToSendPtr = nullptr;
- if (dataToSend != 0) {
+ if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
@@ -91,7 +88,7 @@
{
uint8_t* dataToSendPtr = nullptr;
- if (dataToSend != 0) {
+ if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
diff --git a/hal/src/main/native/cpp/jni/InterruptJNI.cpp b/hal/src/main/native/cpp/jni/InterruptJNI.cpp
index d18ef27..ed56ce5 100644
--- a/hal/src/main/native/cpp/jni/InterruptJNI.cpp
+++ b/hal/src/main/native/cpp/jni/InterruptJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -20,108 +17,19 @@
using namespace hal;
-// Thread where callbacks are actually performed.
-//
-// JNI's AttachCurrentThread() creates a Java Thread object on every
-// invocation, which is both time inefficient and causes issues with Eclipse
-// (which tries to keep a thread list up-to-date and thus gets swamped).
-//
-// Instead, this class attaches just once. When a hardware notification
-// occurs, a condition variable wakes up this thread and this thread actually
-// makes the call into Java.
-//
-// We don't want to use a FIFO here. If the user code takes too long to
-// process, we will just ignore the redundant wakeup.
-class InterruptThreadJNI : public wpi::SafeThread {
- public:
- void Main();
-
- bool m_notify = false;
- uint32_t m_mask = 0;
- jobject m_func = nullptr;
- jmethodID m_mid;
- jobject m_param = nullptr;
-};
-
-class InterruptJNI : public wpi::SafeThreadOwner<InterruptThreadJNI> {
- public:
- void SetFunc(JNIEnv* env, jobject func, jmethodID mid, jobject param);
-
- void Notify(uint32_t mask) {
- auto thr = GetThread();
- if (!thr) return;
- thr->m_notify = true;
- thr->m_mask = mask;
- thr->m_cond.notify_one();
- }
-};
-
-void InterruptJNI::SetFunc(JNIEnv* env, jobject func, jmethodID mid,
- jobject param) {
- auto thr = GetThread();
- if (!thr) return;
- // free global references
- if (thr->m_func) env->DeleteGlobalRef(thr->m_func);
- if (thr->m_param) env->DeleteGlobalRef(thr->m_param);
- // create global references
- thr->m_func = env->NewGlobalRef(func);
- thr->m_param = param ? env->NewGlobalRef(param) : nullptr;
- thr->m_mid = mid;
-}
-
-void InterruptThreadJNI::Main() {
- JNIEnv* env;
- JavaVMAttachArgs args;
- args.version = JNI_VERSION_1_2;
- args.name = const_cast<char*>("Interrupt");
- args.group = nullptr;
- jint rs = GetJVM()->AttachCurrentThreadAsDaemon(
- reinterpret_cast<void**>(&env), &args);
- if (rs != JNI_OK) return;
-
- std::unique_lock lock(m_mutex);
- while (m_active) {
- m_cond.wait(lock, [&] { return !m_active || m_notify; });
- if (!m_active) break;
- m_notify = false;
- if (!m_func) continue;
- jobject func = m_func;
- jmethodID mid = m_mid;
- uint32_t mask = m_mask;
- jobject param = m_param;
- lock.unlock(); // don't hold mutex during callback execution
- env->CallVoidMethod(func, mid, static_cast<jint>(mask), param);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- env->ExceptionClear();
- }
- lock.lock();
- }
-
- // free global references
- if (m_func) env->DeleteGlobalRef(m_func);
- if (m_param) env->DeleteGlobalRef(m_param);
-
- GetJVM()->DetachCurrentThread();
-}
-
-void interruptHandler(uint32_t mask, void* param) {
- static_cast<InterruptJNI*>(param)->Notify(mask);
-}
-
extern "C" {
/*
* Class: edu_wpi_first_hal_InterruptJNI
* Method: initializeInterrupts
- * Signature: (Z)I
+ * Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_InterruptJNI_initializeInterrupts
- (JNIEnv* env, jclass, jboolean watcher)
+ (JNIEnv* env, jclass)
{
int32_t status = 0;
- HAL_InterruptHandle interrupt = HAL_InitializeInterrupts(watcher, &status);
+ HAL_InterruptHandle interrupt = HAL_InitializeInterrupts(&status);
CheckStatusForceThrow(env, status);
return (jint)interrupt;
@@ -136,14 +44,7 @@
Java_edu_wpi_first_hal_InterruptJNI_cleanInterrupts
(JNIEnv* env, jclass, jint interruptHandle)
{
- int32_t status = 0;
- auto param =
- HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle, &status);
- if (param) {
- delete static_cast<InterruptJNI*>(param);
- }
-
- // ignore status, as an invalid handle just needs to be ignored.
+ HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle);
}
/*
@@ -166,36 +67,6 @@
/*
* Class: edu_wpi_first_hal_InterruptJNI
- * Method: enableInterrupts
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_InterruptJNI_enableInterrupts
- (JNIEnv* env, jclass, jint interruptHandle)
-{
- int32_t status = 0;
- HAL_EnableInterrupts((HAL_InterruptHandle)interruptHandle, &status);
-
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_InterruptJNI
- * Method: disableInterrupts
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_InterruptJNI_disableInterrupts
- (JNIEnv* env, jclass, jint interruptHandle)
-{
- int32_t status = 0;
- HAL_DisableInterrupts((HAL_InterruptHandle)interruptHandle, &status);
-
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_InterruptJNI
* Method: readInterruptRisingTimestamp
* Signature: (I)J
*/
@@ -248,37 +119,6 @@
/*
* Class: edu_wpi_first_hal_InterruptJNI
- * Method: attachInterruptHandler
- * Signature: (ILjava/lang/Object;Ljava/lang/Object;)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_InterruptJNI_attachInterruptHandler
- (JNIEnv* env, jclass, jint interruptHandle, jobject handler, jobject param)
-{
- jclass cls = env->GetObjectClass(handler);
- if (cls == 0) {
- assert(false);
- return;
- }
- jmethodID mid = env->GetMethodID(cls, "apply", "(ILjava/lang/Object;)V");
- if (mid == 0) {
- assert(false);
- return;
- }
-
- InterruptJNI* intr = new InterruptJNI;
- intr->Start();
- intr->SetFunc(env, handler, mid, param);
-
- int32_t status = 0;
- HAL_AttachInterruptHandler((HAL_InterruptHandle)interruptHandle,
- interruptHandler, intr, &status);
-
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_InterruptJNI
* Method: setInterruptUpSourceEdge
* Signature: (IZZ)V
*/
diff --git a/hal/src/main/native/cpp/jni/NotifierJNI.cpp b/hal/src/main/native/cpp/jni/NotifierJNI.cpp
index ed0b324..4e7069e 100644
--- a/hal/src/main/native/cpp/jni/NotifierJNI.cpp
+++ b/hal/src/main/native/cpp/jni/NotifierJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -41,6 +38,19 @@
/*
* Class: edu_wpi_first_hal_NotifierJNI
+ * Method: setHALThreadPriority
+ * Signature: (ZI)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_NotifierJNI_setHALThreadPriority
+ (JNIEnv* env, jclass, jboolean realTime, jint priority)
+{
+ int32_t status = 0;
+ return HAL_SetNotifierThreadPriority(realTime, priority, &status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_NotifierJNI
* Method: setNotifierName
* Signature: (ILjava/lang/String;)V
*/
diff --git a/hal/src/main/native/cpp/jni/PDPJNI.cpp b/hal/src/main/native/cpp/jni/PDPJNI.cpp
deleted file mode 100644
index bb28fdf..0000000
--- a/hal/src/main/native/cpp/jni/PDPJNI.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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 "HALUtil.h"
-#include "edu_wpi_first_hal_PDPJNI.h"
-#include "hal/PDP.h"
-#include "hal/Ports.h"
-
-using namespace hal;
-
-extern "C" {
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: initializePDP
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_PDPJNI_initializePDP
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- auto handle = HAL_InitializePDP(module, &status);
- CheckStatusRange(env, status, 0, HAL_GetNumPDPModules(), module);
- return static_cast<jint>(handle);
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: checkPDPChannel
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_PDPJNI_checkPDPChannel
- (JNIEnv* env, jclass, jint channel)
-{
- return HAL_CheckPDPChannel(channel);
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: checkPDPModule
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_PDPJNI_checkPDPModule
- (JNIEnv* env, jclass, jint module)
-{
- return HAL_CheckPDPModule(module);
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPTemperature
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPTemperature
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- double temperature = HAL_GetPDPTemperature(handle, &status);
- CheckStatus(env, status, false);
- return temperature;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPVoltage
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPVoltage
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- double voltage = HAL_GetPDPVoltage(handle, &status);
- CheckStatus(env, status, false);
- return voltage;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPChannelCurrent
- * Signature: (BI)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPChannelCurrent
- (JNIEnv* env, jclass, jbyte channel, jint handle)
-{
- int32_t status = 0;
- double current = HAL_GetPDPChannelCurrent(handle, channel, &status);
- CheckStatus(env, status, false);
- return current;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPAllCurrents
- * Signature: (I[D)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPAllCurrents
- (JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
-{
- double storage[16];
- int32_t status = 0;
- HAL_GetPDPAllChannelCurrents(handle, storage, &status);
- if (!CheckStatus(env, status, false)) {
- return;
- }
-
- env->SetDoubleArrayRegion(jarr, 0, 16, storage);
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPTotalCurrent
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPTotalCurrent
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- double current = HAL_GetPDPTotalCurrent(handle, &status);
- CheckStatus(env, status, false);
- return current;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPTotalPower
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPTotalPower
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- double power = HAL_GetPDPTotalPower(handle, &status);
- CheckStatus(env, status, false);
- return power;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: getPDPTotalEnergy
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_PDPJNI_getPDPTotalEnergy
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- double energy = HAL_GetPDPTotalEnergy(handle, &status);
- CheckStatus(env, status, false);
- return energy;
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: resetPDPTotalEnergy
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_PDPJNI_resetPDPTotalEnergy
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- HAL_ResetPDPTotalEnergy(handle, &status);
- CheckStatus(env, status, false);
-}
-
-/*
- * Class: edu_wpi_first_hal_PDPJNI
- * Method: clearPDPStickyFaults
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_PDPJNI_clearPDPStickyFaults
- (JNIEnv* env, jclass, jint handle)
-{
- int32_t status = 0;
- HAL_ClearPDPStickyFaults(handle, &status);
- CheckStatus(env, status, false);
-}
-
-} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/PWMJNI.cpp b/hal/src/main/native/cpp/jni/PWMJNI.cpp
index 085cd0c..e83f11b 100644
--- a/hal/src/main/native/cpp/jni/PWMJNI.cpp
+++ b/hal/src/main/native/cpp/jni/PWMJNI.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
+#include <wpi/jni_util.h>
+
#include "HALUtil.h"
#include "edu_wpi_first_hal_PWMJNI.h"
#include "hal/DIO.h"
@@ -30,9 +29,9 @@
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
- auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, &status);
- CheckStatusRange(env, status, 0, HAL_GetNumPWMChannels(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
return (jint)pwm;
}
diff --git a/hal/src/main/native/cpp/jni/PortsJNI.cpp b/hal/src/main/native/cpp/jni/PortsJNI.cpp
index 65fabd4..9757f44 100644
--- a/hal/src/main/native/cpp/jni/PortsJNI.cpp
+++ b/hal/src/main/native/cpp/jni/PortsJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -200,53 +197,105 @@
/*
* Class: edu_wpi_first_hal_PortsJNI
- * Method: getNumPCMModules
+ * Method: getNumCTREPCMModules
* Signature: ()I
*/
JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_PortsJNI_getNumPCMModules
+Java_edu_wpi_first_hal_PortsJNI_getNumCTREPCMModules
(JNIEnv* env, jclass)
{
- jint value = HAL_GetNumPCMModules();
+ jint value = HAL_GetNumCTREPCMModules();
return value;
}
/*
* Class: edu_wpi_first_hal_PortsJNI
- * Method: getNumSolenoidChannels
+ * Method: getNumCTRESolenoidChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_PortsJNI_getNumSolenoidChannels
+Java_edu_wpi_first_hal_PortsJNI_getNumCTRESolenoidChannels
(JNIEnv* env, jclass)
{
- jint value = HAL_GetNumSolenoidChannels();
+ jint value = HAL_GetNumCTRESolenoidChannels();
return value;
}
/*
* Class: edu_wpi_first_hal_PortsJNI
- * Method: getNumPDPModules
+ * Method: getNumCTREPDPModules
* Signature: ()I
*/
JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_PortsJNI_getNumPDPModules
+Java_edu_wpi_first_hal_PortsJNI_getNumCTREPDPModules
(JNIEnv* env, jclass)
{
- jint value = HAL_GetNumPDPModules();
+ jint value = HAL_GetNumCTREPDPModules();
return value;
}
/*
* Class: edu_wpi_first_hal_PortsJNI
- * Method: getNumPDPChannels
+ * Method: getNumCTREPDPChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_PortsJNI_getNumPDPChannels
+Java_edu_wpi_first_hal_PortsJNI_getNumCTREPDPChannels
(JNIEnv* env, jclass)
{
- jint value = HAL_GetNumPDPChannels();
+ jint value = HAL_GetNumCTREPDPChannels();
+ return value;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PortsJNI
+ * Method: getNumREVPDHModules
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PortsJNI_getNumREVPDHModules
+ (JNIEnv* env, jclass)
+{
+ jint value = HAL_GetNumREVPDHModules();
+ return value;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PortsJNI
+ * Method: getNumREVPDHChannels
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PortsJNI_getNumREVPDHChannels
+ (JNIEnv* env, jclass)
+{
+ jint value = HAL_GetNumREVPDHChannels();
+ return value;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PortsJNI
+ * Method: getNumREVPHModules
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PortsJNI_getNumREVPHModules
+ (JNIEnv* env, jclass)
+{
+ jint value = HAL_GetNumREVPHModules();
+ return value;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PortsJNI
+ * Method: getNumREVPHChannels
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PortsJNI_getNumREVPHChannels
+ (JNIEnv* env, jclass)
+{
+ jint value = HAL_GetNumREVPHChannels();
return value;
}
} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/PowerDistributionJNI.cpp b/hal/src/main/native/cpp/jni/PowerDistributionJNI.cpp
new file mode 100644
index 0000000..b608458
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/PowerDistributionJNI.cpp
@@ -0,0 +1,295 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include <wpi/jni_util.h>
+
+#include "HALUtil.h"
+#include "edu_wpi_first_hal_PowerDistributionJNI.h"
+#include "hal/Ports.h"
+#include "hal/PowerDistribution.h"
+
+using namespace hal;
+
+static_assert(edu_wpi_first_hal_PowerDistributionJNI_AUTOMATIC_TYPE ==
+ HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic);
+static_assert(edu_wpi_first_hal_PowerDistributionJNI_CTRE_TYPE ==
+ HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE);
+static_assert(edu_wpi_first_hal_PowerDistributionJNI_REV_TYPE ==
+ HAL_PowerDistributionType::HAL_PowerDistributionType_kRev);
+static_assert(edu_wpi_first_hal_PowerDistributionJNI_DEFAULT_MODULE ==
+ HAL_DEFAULT_POWER_DISTRIBUTION_MODULE);
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: initialize
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_initialize
+ (JNIEnv* env, jclass, jint module, jint type)
+{
+ int32_t status = 0;
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto handle = HAL_InitializePowerDistribution(
+ module, static_cast<HAL_PowerDistributionType>(type), stack.c_str(),
+ &status);
+ CheckStatusForceThrow(env, status);
+ return static_cast<jint>(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: free
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_free
+ (JNIEnv*, jclass, jint handle)
+{
+ HAL_CleanPowerDistribution(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getModuleNumber
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getModuleNumber
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetPowerDistributionModuleNumber(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: checkChannel
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_checkChannel
+ (JNIEnv* env, jclass, jint handle, jint channel)
+{
+ return HAL_CheckPowerDistributionChannel(handle, channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: checkModule
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_checkModule
+ (JNIEnv* env, jclass, jint module, jint type)
+{
+ return HAL_CheckPowerDistributionModule(
+ module, static_cast<HAL_PowerDistributionType>(type));
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getType
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getType
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetPowerDistributionType(handle, &status);
+ CheckStatus(env, status);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getNumChannels
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getNumChannels
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetPowerDistributionNumChannels(handle, &status);
+ CheckStatus(env, status);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getTemperature
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getTemperature
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ double temperature = HAL_GetPowerDistributionTemperature(handle, &status);
+ CheckStatus(env, status, false);
+ return temperature;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getVoltage
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getVoltage
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ double voltage = HAL_GetPowerDistributionVoltage(handle, &status);
+ CheckStatus(env, status, false);
+ return voltage;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getChannelCurrent
+ * Signature: (II)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getChannelCurrent
+ (JNIEnv* env, jclass, jint handle, jint channel)
+{
+ int32_t status = 0;
+ double current =
+ HAL_GetPowerDistributionChannelCurrent(handle, channel, &status);
+ CheckStatus(env, status, false);
+ return current;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getAllCurrents
+ * Signature: (I[D)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getAllCurrents
+ (JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
+{
+ double storage[16];
+ int32_t status = 0;
+ // TODO fix me
+ HAL_GetPowerDistributionAllChannelCurrents(handle, storage, 16, &status);
+ if (!CheckStatus(env, status, false)) {
+ return;
+ }
+
+ env->SetDoubleArrayRegion(jarr, 0, 16, storage);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getTotalCurrent
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalCurrent
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ double current = HAL_GetPowerDistributionTotalCurrent(handle, &status);
+ CheckStatus(env, status, false);
+ return current;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getTotalPower
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalPower
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ double power = HAL_GetPowerDistributionTotalPower(handle, &status);
+ CheckStatus(env, status, false);
+ return power;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getTotalEnergy
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalEnergy
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ double energy = HAL_GetPowerDistributionTotalEnergy(handle, &status);
+ CheckStatus(env, status, false);
+ return energy;
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: resetTotalEnergy
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_resetTotalEnergy
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_ResetPowerDistributionTotalEnergy(handle, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: clearStickyFaults
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_clearStickyFaults
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ HAL_ClearPowerDistributionStickyFaults(handle, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: setSwitchableChannel
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_setSwitchableChannel
+ (JNIEnv* env, jclass, jint handle, jboolean enabled)
+{
+ int32_t status = 0;
+ HAL_SetPowerDistributionSwitchableChannel(handle, enabled, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerDistributionJNI
+ * Method: getSwitchableChannel
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_PowerDistributionJNI_getSwitchableChannel
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto state = HAL_GetPowerDistributionSwitchableChannel(handle, &status);
+ CheckStatus(env, status, false);
+ return state;
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/PowerJNI.cpp b/hal/src/main/native/cpp/jni/PowerJNI.cpp
index 6fc42b4..92b174d 100644
--- a/hal/src/main/native/cpp/jni/PowerJNI.cpp
+++ b/hal/src/main/native/cpp/jni/PowerJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -225,4 +222,33 @@
return val;
}
+/*
+ * Class: edu_wpi_first_hal_PowerJNI
+ * Method: setBrownoutVoltage
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_PowerJNI_setBrownoutVoltage
+ (JNIEnv* env, jclass, jdouble brownoutVoltage)
+{
+ int32_t status = 0;
+ HAL_SetBrownoutVoltage(brownoutVoltage, &status);
+ CheckStatus(env, status);
+}
+
+/*
+ * Class: edu_wpi_first_hal_PowerJNI
+ * Method: getBrownoutVoltage
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_PowerJNI_getBrownoutVoltage
+ (JNIEnv* env, jclass)
+{
+ int32_t status = 0;
+ double val = HAL_GetBrownoutVoltage(&status);
+ CheckStatus(env, status);
+ return val;
+}
+
} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/REVPHJNI.cpp b/hal/src/main/native/cpp/jni/REVPHJNI.cpp
new file mode 100644
index 0000000..3e99430
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/REVPHJNI.cpp
@@ -0,0 +1,191 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include <wpi/jni_util.h>
+
+#include "HALUtil.h"
+#include "edu_wpi_first_hal_REVPHJNI.h"
+#include "hal/Ports.h"
+#include "hal/REVPH.h"
+#include "hal/handles/HandlesInternal.h"
+
+using namespace hal;
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: initialize
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_initialize
+ (JNIEnv* env, jclass, jint module)
+{
+ int32_t status = 0;
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
+ auto handle = HAL_InitializeREVPH(module, stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
+ return handle;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: free
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_free
+ (JNIEnv* env, jclass, jint handle)
+{
+ HAL_FreeREVPH(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: checkSolenoidChannel
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_checkSolenoidChannel
+ (JNIEnv*, jclass, jint channel)
+{
+ return HAL_CheckREVPHSolenoidChannel(channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getCompressor
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getCompressor
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHCompressor(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: setClosedLoopControl
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControl
+ (JNIEnv* env, jclass, jint handle, jboolean enabled)
+{
+ int32_t status = 0;
+ HAL_SetREVPHClosedLoopControl(handle, enabled, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getClosedLoopControl
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getClosedLoopControl
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHClosedLoopControl(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getPressureSwitch
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getPressureSwitch
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHPressureSwitch(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getAnalogPressure
+ * Signature: (II)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getAnalogPressure
+ (JNIEnv* env, jclass, jint handle, jint channel)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHAnalogPressure(handle, channel, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getCompressorCurrent
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getCompressorCurrent
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHCompressorCurrent(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: getSolenoids
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_getSolenoids
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t status = 0;
+ auto result = HAL_GetREVPHSolenoids(handle, &status);
+ CheckStatus(env, status, false);
+ return result;
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: setSolenoids
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_setSolenoids
+ (JNIEnv* env, jclass, jint handle, jint mask, jint value)
+{
+ int32_t status = 0;
+ HAL_SetREVPHSolenoids(handle, mask, value, &status);
+ CheckStatus(env, status, false);
+}
+
+/*
+ * Class: edu_wpi_first_hal_REVPHJNI
+ * Method: fireOneShot
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_REVPHJNI_fireOneShot
+ (JNIEnv* env, jclass, jint handle, jint index, jint durMs)
+{
+ int32_t status = 0;
+ HAL_FireREVPHOneShot(handle, index, durMs, &status);
+ CheckStatus(env, status, false);
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/RelayJNI.cpp b/hal/src/main/native/cpp/jni/RelayJNI.cpp
index ce43307..9e31a9d 100644
--- a/hal/src/main/native/cpp/jni/RelayJNI.cpp
+++ b/hal/src/main/native/cpp/jni/RelayJNI.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include <cassert>
+#include <wpi/jni_util.h>
+
#include "HALUtil.h"
#include "edu_wpi_first_hal_RelayJNI.h"
#include "hal/Ports.h"
@@ -29,10 +28,10 @@
(JNIEnv* env, jclass, jint id, jboolean fwd)
{
int32_t status = 0;
+ auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
HAL_RelayHandle handle = HAL_InitializeRelayPort(
- (HAL_PortHandle)id, static_cast<uint8_t>(fwd), &status);
- CheckStatusRange(env, status, 0, HAL_GetNumRelayChannels(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
+ (HAL_PortHandle)id, static_cast<uint8_t>(fwd), stack.c_str(), &status);
+ CheckStatusForceThrow(env, status);
return (jint)handle;
}
diff --git a/hal/src/main/native/cpp/jni/SPIJNI.cpp b/hal/src/main/native/cpp/jni/SPIJNI.cpp
index d7709e2..67ef56d 100644
--- a/hal/src/main/native/cpp/jni/SPIJNI.cpp
+++ b/hal/src/main/native/cpp/jni/SPIJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -45,7 +42,7 @@
jbyte size)
{
uint8_t* dataToSendPtr = nullptr;
- if (dataToSend != 0) {
+ if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
@@ -88,7 +85,7 @@
(JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size)
{
uint8_t* dataToSendPtr = nullptr;
- if (dataToSend != 0) {
+ if (dataToSend != nullptr) {
dataToSendPtr =
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
}
@@ -370,7 +367,9 @@
jint retval =
HAL_ReadSPIAutoReceivedData(static_cast<HAL_SPIPort>(port),
recvBuf.data(), numToRead, timeout, &status);
- if (!CheckStatus(env, status)) return retval;
+ if (!CheckStatus(env, status)) {
+ return retval;
+ }
if (numToRead > 0) {
env->SetIntArrayRegion(buffer, 0, numToRead,
reinterpret_cast<const jint*>(recvBuf.data()));
diff --git a/hal/src/main/native/cpp/jni/SerialPortJNI.cpp b/hal/src/main/native/cpp/jni/SerialPortJNI.cpp
index 13f1f99..e7f81aa 100644
--- a/hal/src/main/native/cpp/jni/SerialPortJNI.cpp
+++ b/hal/src/main/native/cpp/jni/SerialPortJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/SimDeviceJNI.cpp b/hal/src/main/native/cpp/jni/SimDeviceJNI.cpp
index b69a8bb..f681e71 100644
--- a/hal/src/main/native/cpp/jni/SimDeviceJNI.cpp
+++ b/hal/src/main/native/cpp/jni/SimDeviceJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -69,25 +66,25 @@
/*
* Class: edu_wpi_first_hal_SimDeviceJNI
* Method: createSimValueNative
- * Signature: (ILjava/lang/String;ZIJD)I
+ * Signature: (ILjava/lang/String;IIJD)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SimDeviceJNI_createSimValueNative
- (JNIEnv* env, jclass, jint device, jstring name, jboolean readonly, jint type,
+ (JNIEnv* env, jclass, jint device, jstring name, jint direction, jint type,
jlong value1, jdouble value2)
{
- return HAL_CreateSimValue(device, JStringRef{env, name}.c_str(), readonly,
+ return HAL_CreateSimValue(device, JStringRef{env, name}.c_str(), direction,
ValueFromJava(type, value1, value2));
}
/*
* Class: edu_wpi_first_hal_SimDeviceJNI
* Method: createSimValueEnum
- * Signature: (ILjava/lang/String;Z[Ljava/lang/Object;I)I
+ * Signature: (ILjava/lang/String;I[Ljava/lang/Object;I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_SimDeviceJNI_createSimValueEnum
- (JNIEnv* env, jclass, jint device, jstring name, jboolean readonly,
+ (JNIEnv* env, jclass, jint device, jstring name, jint direction,
jobjectArray options, jint initialValue)
{
size_t len = env->GetArrayLength(options);
@@ -96,13 +93,52 @@
for (size_t i = 0; i < len; ++i) {
JLocal<jstring> elem{
env, static_cast<jstring>(env->GetObjectArrayElement(options, i))};
- if (!elem) return 0;
- arr.push_back(JStringRef{env, elem}.str());
+ if (!elem) {
+ return 0;
+ }
+ arr.emplace_back(JStringRef{env, elem}.str());
}
wpi::SmallVector<const char*, 8> carr;
- for (auto&& val : arr) carr.push_back(val.c_str());
- return HAL_CreateSimValueEnum(device, JStringRef{env, name}.c_str(), readonly,
- len, carr.data(), initialValue);
+ for (auto&& val : arr) {
+ carr.push_back(val.c_str());
+ }
+ return HAL_CreateSimValueEnum(device, JStringRef{env, name}.c_str(),
+ direction, len, carr.data(), initialValue);
+}
+
+/*
+ * Class: edu_wpi_first_hal_SimDeviceJNI
+ * Method: createSimValueEnumDouble
+ * Signature: (ILjava/lang/String;I[Ljava/lang/Object;[DI)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_SimDeviceJNI_createSimValueEnumDouble
+ (JNIEnv* env, jclass, jint device, jstring name, jint direction,
+ jobjectArray options, jdoubleArray optionValues, jint initialValue)
+{
+ size_t len = env->GetArrayLength(options);
+ size_t len2 = env->GetArrayLength(optionValues);
+ if (len != len2) {
+ return 0;
+ }
+ std::vector<std::string> arr;
+ arr.reserve(len);
+ for (size_t i = 0; i < len; ++i) {
+ JLocal<jstring> elem{
+ env, static_cast<jstring>(env->GetObjectArrayElement(options, i))};
+ if (!elem) {
+ return 0;
+ }
+ arr.emplace_back(JStringRef{env, elem}.str());
+ }
+
+ wpi::SmallVector<const char*, 8> carr;
+ for (auto&& val : arr) {
+ carr.push_back(val.c_str());
+ }
+ return HAL_CreateSimValueEnumDouble(
+ device, JStringRef{env, name}.c_str(), direction, len, carr.data(),
+ JDoubleArrayRef{env, optionValues}.array().data(), initialValue);
}
/*
@@ -119,6 +155,30 @@
/*
* Class: edu_wpi_first_hal_SimDeviceJNI
+ * Method: getSimValueInt
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_SimDeviceJNI_getSimValueInt
+ (JNIEnv*, jclass, jint handle)
+{
+ return HAL_GetSimValueInt(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_SimDeviceJNI
+ * Method: getSimValueLong
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL
+Java_edu_wpi_first_hal_SimDeviceJNI_getSimValueLong
+ (JNIEnv*, jclass, jint handle)
+{
+ return HAL_GetSimValueLong(handle);
+}
+
+/*
+ * Class: edu_wpi_first_hal_SimDeviceJNI
* Method: getSimValueDouble
* Signature: (I)D
*/
@@ -165,4 +225,16 @@
HAL_SetSimValue(handle, ValueFromJava(type, value1, value2));
}
+/*
+ * Class: edu_wpi_first_hal_SimDeviceJNI
+ * Method: resetSimValue
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_SimDeviceJNI_resetSimValue
+ (JNIEnv*, jclass, jint handle)
+{
+ HAL_ResetSimValue(handle);
+}
+
} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/SolenoidJNI.cpp b/hal/src/main/native/cpp/jni/SolenoidJNI.cpp
deleted file mode 100644
index 4877db3..0000000
--- a/hal/src/main/native/cpp/jni/SolenoidJNI.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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 <jni.h>
-
-#include "HALUtil.h"
-#include "edu_wpi_first_hal_SolenoidJNI.h"
-#include "hal/Ports.h"
-#include "hal/Solenoid.h"
-#include "hal/handles/HandlesInternal.h"
-
-using namespace hal;
-
-extern "C" {
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: initializeSolenoidPort
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_initializeSolenoidPort
- (JNIEnv* env, jclass, jint id)
-{
- int32_t status = 0;
- HAL_SolenoidHandle handle =
- HAL_InitializeSolenoidPort((HAL_PortHandle)id, &status);
-
- // Use solenoid channels, as we have to pick one.
- CheckStatusRange(env, status, 0, HAL_GetNumSolenoidChannels(),
- hal::getPortHandleChannel((HAL_PortHandle)id));
- return (jint)handle;
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: checkSolenoidChannel
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_checkSolenoidChannel
- (JNIEnv* env, jclass, jint channel)
-{
- return HAL_CheckSolenoidChannel(channel);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: checkSolenoidModule
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_checkSolenoidModule
- (JNIEnv* env, jclass, jint module)
-{
- return HAL_CheckSolenoidModule(module);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: freeSolenoidPort
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_freeSolenoidPort
- (JNIEnv* env, jclass, jint id)
-{
- HAL_FreeSolenoidPort((HAL_SolenoidHandle)id);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: setSolenoid
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_setSolenoid
- (JNIEnv* env, jclass, jint solenoid_port, jboolean value)
-{
- int32_t status = 0;
- HAL_SetSolenoid((HAL_SolenoidHandle)solenoid_port, value, &status);
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: getSolenoid
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_getSolenoid
- (JNIEnv* env, jclass, jint solenoid_port)
-{
- int32_t status = 0;
- jboolean val = HAL_GetSolenoid((HAL_SolenoidHandle)solenoid_port, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: getAllSolenoids
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_getAllSolenoids
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- jint val = HAL_GetAllSolenoids(module, &status);
- CheckStatus(env, status);
- return val;
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: getPCMSolenoidBlackList
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_getPCMSolenoidBlackList
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- jint val = HAL_GetPCMSolenoidBlackList(module, &status);
- CheckStatus(env, status);
- return val;
-}
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: getPCMSolenoidVoltageStickyFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_getPCMSolenoidVoltageStickyFault
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- bool val = HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
- CheckStatus(env, status);
- return val;
-}
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: getPCMSolenoidVoltageFault
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_getPCMSolenoidVoltageFault
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- bool val = HAL_GetPCMSolenoidVoltageFault(module, &status);
- CheckStatus(env, status);
- return val;
-}
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: clearAllPCMStickyFaults
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_clearAllPCMStickyFaults
- (JNIEnv* env, jclass, jint module)
-{
- int32_t status = 0;
- HAL_ClearAllPCMStickyFaults(module, &status);
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: setOneShotDuration
- * Signature: (IJ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_setOneShotDuration
- (JNIEnv* env, jclass, jint solenoid_port, jlong durationMS)
-{
- int32_t status = 0;
- HAL_SetOneShotDuration((HAL_SolenoidHandle)solenoid_port, durationMS,
- &status);
- CheckStatus(env, status);
-}
-
-/*
- * Class: edu_wpi_first_hal_SolenoidJNI
- * Method: fireOneShot
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_SolenoidJNI_fireOneShot
- (JNIEnv* env, jclass, jint solenoid_port)
-{
- int32_t status = 0;
- HAL_FireOneShot((HAL_SolenoidHandle)solenoid_port, &status);
- CheckStatus(env, status);
-}
-} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/ThreadsJNI.cpp b/hal/src/main/native/cpp/jni/ThreadsJNI.cpp
index a26a4bf..94f00c5 100644
--- a/hal/src/main/native/cpp/jni/ThreadsJNI.cpp
+++ b/hal/src/main/native/cpp/jni/ThreadsJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -29,7 +26,7 @@
HAL_Bool isRT = false;
auto ret = HAL_GetCurrentThreadPriority(&isRT, &status);
CheckStatus(env, status);
- return (jint)ret;
+ return static_cast<jint>(ret);
}
/*
@@ -45,7 +42,7 @@
HAL_Bool isRT = false;
HAL_GetCurrentThreadPriority(&isRT, &status);
CheckStatus(env, status);
- return (jboolean)isRT;
+ return static_cast<jboolean>(isRT);
}
/*
@@ -59,9 +56,9 @@
{
int32_t status = 0;
auto ret = HAL_SetCurrentThreadPriority(
- (HAL_Bool)realTime, static_cast<int32_t>(priority), &status);
- CheckStatus(env, status);
- return (jboolean)ret;
+ static_cast<HAL_Bool>(realTime), static_cast<int32_t>(priority), &status);
+ CheckStatus(env, status, false);
+ return static_cast<jboolean>(ret);
}
} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/AccelerometerDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AccelerometerDataJNI.cpp
index 21d93fe..bc0b499 100644
--- a/hal/src/main/native/cpp/jni/simulation/AccelerometerDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AccelerometerDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp
index 8ac59ec..e888bd3 100644
--- a/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AddressableLEDDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -260,7 +257,7 @@
std::make_unique<HAL_AddressableLEDData[]>(HAL_kAddressableLEDMaxLength);
int32_t length = HALSIM_GetAddressableLEDData(index, data.get());
return MakeJByteArray(
- env, wpi::ArrayRef(reinterpret_cast<jbyte*>(data.get()), length * 4));
+ env, wpi::span(reinterpret_cast<jbyte*>(data.get()), length * 4));
}
/*
diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp
index ed867cd..6a916f5 100644
--- a/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp
index 0266a76..336c0f4 100644
--- a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogOutDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogOutDataJNI.cpp
index 06f5be6..ce74fad 100644
--- a/hal/src/main/native/cpp/jni/simulation/AnalogOutDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AnalogOutDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp
index be92c6d..f7a5147 100644
--- a/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp
index 6751e03..265b363 100644
--- a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "BufferCallbackStore.h"
#include <jni.h>
+#include <cstdio>
+
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
@@ -25,16 +24,14 @@
hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
-namespace hal {
-namespace sim {
+namespace hal::sim {
void InitializeBufferStore() {
static hal::UnlimitedHandleResource<SIM_JniHandle, BufferCallbackStore,
hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
void BufferCallbackStore::create(JNIEnv* env, jobject obj) {
m_call = JGlobal<jobject>(env, obj);
@@ -51,21 +48,21 @@
didAttachThread = true;
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
// Failed to attach, log and return
- wpi::outs() << "Failed to attach\n";
- wpi::outs().flush();
+ std::puts("Failed to attach");
+ std::fflush(stdout);
return;
}
} else if (tryGetEnv == JNI_EVERSION) {
- wpi::outs() << "Invalid JVM Version requested\n";
- wpi::outs().flush();
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
}
- auto toCallbackArr =
- MakeJByteArray(env, wpi::StringRef{reinterpret_cast<const char*>(buffer),
- static_cast<size_t>(length)});
+ auto toCallbackArr = MakeJByteArray(
+ env, std::string_view{reinterpret_cast<const char*>(buffer),
+ static_cast<size_t>(length)});
env->CallVoidMethod(m_call, sim::GetBufferCallback(), MakeJString(env, name),
- toCallbackArr, (jint)length);
+ toCallbackArr, static_cast<jint>(length));
jbyte* fromCallbackArr = reinterpret_cast<jbyte*>(
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));
@@ -85,7 +82,9 @@
}
}
-void BufferCallbackStore::free(JNIEnv* env) { m_call.free(env); }
+void BufferCallbackStore::free(JNIEnv* env) {
+ m_call.free(env);
+}
SIM_JniHandle sim::AllocateBufferCallback(
JNIEnv* env, jint index, jobject callback,
@@ -108,7 +107,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
data->performCallback(name, buffer, length);
};
diff --git a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.h b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.h
index 8e746d2..73cf957 100644
--- a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.h
+++ b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -17,8 +14,7 @@
#include "hal/handles/UnlimitedHandleResource.h"
#include "hal/simulation/NotifyListener.h"
-namespace hal {
-namespace sim {
+namespace hal::sim {
class BufferCallbackStore {
public:
void create(JNIEnv* env, jobject obj);
@@ -34,14 +30,13 @@
void InitializeBufferStore();
-typedef int32_t (*RegisterBufferCallbackFunc)(int32_t index,
- HAL_BufferCallback callback,
- void* param);
-typedef void (*FreeBufferCallbackFunc)(int32_t index, int32_t uid);
+using RegisterBufferCallbackFunc = int32_t (*)(int32_t index,
+ HAL_BufferCallback callback,
+ void* param);
+using FreeBufferCallbackFunc = void (*)(int32_t index, int32_t uid);
SIM_JniHandle AllocateBufferCallback(JNIEnv* env, jint index, jobject callback,
RegisterBufferCallbackFunc createCallback);
void FreeBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
FreeBufferCallbackFunc freeCallback);
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
diff --git a/hal/src/main/native/cpp/jni/simulation/CTREPCMDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/CTREPCMDataJNI.cpp
new file mode 100644
index 0000000..416478c
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/simulation/CTREPCMDataJNI.cpp
@@ -0,0 +1,368 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include "CallbackStore.h"
+#include "edu_wpi_first_hal_simulation_CTREPCMDataJNI.h"
+#include "hal/simulation/CTREPCMData.h"
+
+using namespace hal;
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerInitializedCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerInitializedCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelInitializedCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelInitializedCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelCTREPCMInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getInitialized
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getInitialized
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetCTREPCMInitialized(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setInitialized
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setInitialized
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetCTREPCMInitialized(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerSolenoidOutputCallback
+ * Signature: (IILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerSolenoidOutputCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
+ jboolean initialNotify)
+{
+ return sim::AllocateChannelCallback(
+ env, index, channel, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMSolenoidOutputCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelSolenoidOutputCallback
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelSolenoidOutputCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jint handle)
+{
+ return sim::FreeChannelCallback(env, handle, index, channel,
+ &HALSIM_CancelCTREPCMSolenoidOutputCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getSolenoidOutput
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getSolenoidOutput
+ (JNIEnv*, jclass, jint index, jint channel)
+{
+ return HALSIM_GetCTREPCMSolenoidOutput(index, channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setSolenoidOutput
+ * Signature: (IIZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setSolenoidOutput
+ (JNIEnv*, jclass, jint index, jint channel, jboolean value)
+{
+ HALSIM_SetCTREPCMSolenoidOutput(index, channel, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerCompressorOnCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerCompressorOnCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMCompressorOnCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelCompressorOnCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelCompressorOnCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelCTREPCMCompressorOnCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getCompressorOn
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getCompressorOn
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetCTREPCMCompressorOn(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setCompressorOn
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setCompressorOn
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetCTREPCMCompressorOn(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerClosedLoopEnabledCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerClosedLoopEnabledCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMClosedLoopEnabledCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelClosedLoopEnabledCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelClosedLoopEnabledCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelCTREPCMClosedLoopEnabledCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getClosedLoopEnabled
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getClosedLoopEnabled
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetCTREPCMClosedLoopEnabled(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setClosedLoopEnabled
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setClosedLoopEnabled
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetCTREPCMClosedLoopEnabled(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerPressureSwitchCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerPressureSwitchCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMPressureSwitchCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelPressureSwitchCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelPressureSwitchCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelCTREPCMPressureSwitchCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getPressureSwitch
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getPressureSwitch
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetCTREPCMPressureSwitch(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setPressureSwitch
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setPressureSwitch
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetCTREPCMPressureSwitch(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerCompressorCurrentCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerCompressorCurrentCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ &HALSIM_RegisterCTREPCMCompressorCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: cancelCompressorCurrentCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_cancelCompressorCurrentCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelCTREPCMCompressorCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: getCompressorCurrent
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_getCompressorCurrent
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetCTREPCMCompressorCurrent(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: setCompressorCurrent
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_setCompressorCurrent
+ (JNIEnv*, jclass, jint index, jdouble value)
+{
+ HALSIM_SetCTREPCMCompressorCurrent(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerAllNonSolenoidCallbacks
+ * Signature: (ILjava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerAllNonSolenoidCallbacks
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ [](int32_t index, HAL_NotifyCallback cb, void* param, HAL_Bool in) {
+ HALSIM_RegisterCTREPCMAllNonSolenoidCallbacks(index, cb, param, in);
+ return 0;
+ });
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: registerAllSolenoidCallbacks
+ * Signature: (IILjava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_registerAllSolenoidCallbacks
+ (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
+ jboolean initialNotify)
+{
+ sim::AllocateChannelCallback(
+ env, index, channel, callback, initialNotify,
+ [](int32_t index, int32_t channel, HAL_NotifyCallback cb, void* param,
+ HAL_Bool in) {
+ HALSIM_RegisterCTREPCMAllSolenoidCallbacks(index, channel, cb, param,
+ in);
+ return 0;
+ });
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_CTREPCMDataJNI
+ * Method: resetData
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_CTREPCMDataJNI_resetData
+ (JNIEnv*, jclass, jint index)
+{
+ HALSIM_ResetCTREPCMData(index);
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp
index 5ce046d..f57dfb3 100644
--- a/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CallbackStore.h"
#include <jni.h>
+#include <cstdio>
+
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
@@ -25,16 +24,14 @@
hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
-namespace hal {
-namespace sim {
+namespace hal::sim {
void InitializeStore() {
static hal::UnlimitedHandleResource<SIM_JniHandle, CallbackStore,
hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
void CallbackStore::create(JNIEnv* env, jobject obj) {
m_call = JGlobal<jobject>(env, obj);
@@ -50,18 +47,39 @@
didAttachThread = true;
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
// Failed to attach, log and return
- wpi::outs() << "Failed to attach\n";
- wpi::outs().flush();
+ std::puts("Failed to attach");
+ std::fflush(stdout);
return;
}
} else if (tryGetEnv == JNI_EVERSION) {
- wpi::outs() << "Invalid JVM Version requested\n";
- wpi::outs().flush();
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
+ }
+
+ int64_t longValue = 0;
+
+ switch (value->type) {
+ case HAL_BOOLEAN:
+ longValue = value->data.v_boolean;
+ break;
+ case HAL_ENUM:
+ longValue = value->data.v_enum;
+ break;
+ case HAL_INT:
+ longValue = value->data.v_int;
+ break;
+ case HAL_LONG:
+ longValue = value->data.v_long;
+ break;
+ case HAL_DOUBLE:
+ case HAL_UNASSIGNED:
+ break;
}
env->CallVoidMethod(m_call, sim::GetNotifyCallback(), MakeJString(env, name),
- (jint)value->type, (jlong)value->data.v_long,
- (jdouble)value->data.v_double);
+ static_cast<jint>(value->type),
+ static_cast<jlong>(longValue),
+ static_cast<jdouble>(value->data.v_double));
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
@@ -72,7 +90,9 @@
}
}
-void CallbackStore::free(JNIEnv* env) { m_call.free(env); }
+void CallbackStore::free(JNIEnv* env) {
+ m_call.free(env);
+}
SIM_JniHandle sim::AllocateCallback(JNIEnv* env, jint index, jobject callback,
jboolean initialNotify,
@@ -95,7 +115,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
data->performCallback(name, value);
};
@@ -135,7 +157,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
data->performCallback(name, value);
};
@@ -177,7 +201,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
data->performCallback(name, value);
};
diff --git a/hal/src/main/native/cpp/jni/simulation/CallbackStore.h b/hal/src/main/native/cpp/jni/simulation/CallbackStore.h
index 0ba44d3..59e1018 100644
--- a/hal/src/main/native/cpp/jni/simulation/CallbackStore.h
+++ b/hal/src/main/native/cpp/jni/simulation/CallbackStore.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -17,8 +14,7 @@
#include "hal/handles/UnlimitedHandleResource.h"
#include "hal/simulation/NotifyListener.h"
-namespace hal {
-namespace sim {
+namespace hal::sim {
class CallbackStore {
public:
void create(JNIEnv* env, jobject obj);
@@ -34,20 +30,20 @@
void InitializeStore();
-typedef int32_t (*RegisterCallbackFunc)(int32_t index,
- HAL_NotifyCallback callback,
- void* param, HAL_Bool initialNotify);
-typedef void (*FreeCallbackFunc)(int32_t index, int32_t uid);
-typedef int32_t (*RegisterChannelCallbackFunc)(int32_t index, int32_t channel,
- HAL_NotifyCallback callback,
- void* param,
- HAL_Bool initialNotify);
-typedef void (*FreeChannelCallbackFunc)(int32_t index, int32_t channel,
- int32_t uid);
-typedef int32_t (*RegisterCallbackNoIndexFunc)(HAL_NotifyCallback callback,
- void* param,
- HAL_Bool initialNotify);
-typedef void (*FreeCallbackNoIndexFunc)(int32_t uid);
+using RegisterCallbackFunc = int32_t (*)(int32_t index,
+ HAL_NotifyCallback callback,
+ void* param, HAL_Bool initialNotify);
+using FreeCallbackFunc = void (*)(int32_t index, int32_t uid);
+using RegisterChannelCallbackFunc = int32_t (*)(int32_t index, int32_t channel,
+ HAL_NotifyCallback callback,
+ void* param,
+ HAL_Bool initialNotify);
+using FreeChannelCallbackFunc = void (*)(int32_t index, int32_t channel,
+ int32_t uid);
+using RegisterCallbackNoIndexFunc = int32_t (*)(HAL_NotifyCallback callback,
+ void* param,
+ HAL_Bool initialNotify);
+using FreeCallbackNoIndexFunc = void (*)(int32_t uid);
SIM_JniHandle AllocateCallback(JNIEnv* env, jint index, jobject callback,
jboolean initialNotify,
@@ -64,5 +60,4 @@
jint channel, FreeChannelCallbackFunc freeCallback);
void FreeCallbackNoIndex(JNIEnv* env, SIM_JniHandle handle,
FreeCallbackNoIndexFunc freeCallback);
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
diff --git a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp
index b9c9808..cba0a5b 100644
--- a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ConstBufferCallbackStore.h"
#include <jni.h>
+#include <cstdio>
+
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
@@ -25,16 +24,14 @@
hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
-namespace hal {
-namespace sim {
+namespace hal::sim {
void InitializeConstBufferStore() {
static hal::UnlimitedHandleResource<SIM_JniHandle, ConstBufferCallbackStore,
hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
void ConstBufferCallbackStore::create(JNIEnv* env, jobject obj) {
m_call = JGlobal<jobject>(env, obj);
@@ -52,21 +49,22 @@
didAttachThread = true;
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
// Failed to attach, log and return
- wpi::outs() << "Failed to attach\n";
- wpi::outs().flush();
+ std::puts("Failed to attach");
+ std::fflush(stdout);
return;
}
} else if (tryGetEnv == JNI_EVERSION) {
- wpi::outs() << "Invalid JVM Version requested\n";
- wpi::outs().flush();
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
}
- auto toCallbackArr =
- MakeJByteArray(env, wpi::StringRef{reinterpret_cast<const char*>(buffer),
- static_cast<size_t>(length)});
+ auto toCallbackArr = MakeJByteArray(
+ env, std::string_view{reinterpret_cast<const char*>(buffer),
+ static_cast<size_t>(length)});
env->CallVoidMethod(m_call, sim::GetConstBufferCallback(),
- MakeJString(env, name), toCallbackArr, (jint)length);
+ MakeJString(env, name), toCallbackArr,
+ static_cast<jint>(length));
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
@@ -77,7 +75,9 @@
}
}
-void ConstBufferCallbackStore::free(JNIEnv* env) { m_call.free(env); }
+void ConstBufferCallbackStore::free(JNIEnv* env) {
+ m_call.free(env);
+}
SIM_JniHandle sim::AllocateConstBufferCallback(
JNIEnv* env, jint index, jobject callback,
@@ -100,7 +100,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
data->performCallback(name, buffer, length);
};
diff --git a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.h b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.h
index b69eccf..0998d3c 100644
--- a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.h
+++ b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -17,8 +14,7 @@
#include "hal/handles/UnlimitedHandleResource.h"
#include "hal/simulation/NotifyListener.h"
-namespace hal {
-namespace sim {
+namespace hal::sim {
class ConstBufferCallbackStore {
public:
void create(JNIEnv* env, jobject obj);
@@ -35,14 +31,13 @@
void InitializeConstBufferStore();
-typedef int32_t (*RegisterConstBufferCallbackFunc)(
- int32_t index, HAL_ConstBufferCallback callback, void* param);
-typedef void (*FreeConstBufferCallbackFunc)(int32_t index, int32_t uid);
+using RegisterConstBufferCallbackFunc =
+ int32_t (*)(int32_t index, HAL_ConstBufferCallback callback, void* param);
+using FreeConstBufferCallbackFunc = void (*)(int32_t index, int32_t uid);
SIM_JniHandle AllocateConstBufferCallback(
JNIEnv* env, jint index, jobject callback,
RegisterConstBufferCallbackFunc createCallback);
void FreeConstBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
FreeConstBufferCallbackFunc freeCallback);
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
diff --git a/hal/src/main/native/cpp/jni/simulation/DIODataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/DIODataJNI.cpp
index f757558..e81ad77 100644
--- a/hal/src/main/native/cpp/jni/simulation/DIODataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/DIODataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/DigitalPWMDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/DigitalPWMDataJNI.cpp
index ea6bee2..3ba3931 100644
--- a/hal/src/main/native/cpp/jni/simulation/DigitalPWMDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/DigitalPWMDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp
index 7868e43..acecacb 100644
--- a/hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp
index 054fa67..9cda86d 100644
--- a/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/DutyCycleDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/EncoderDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/EncoderDataJNI.cpp
index b97e0fe..69549a1 100644
--- a/hal/src/main/native/cpp/jni/simulation/EncoderDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/EncoderDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/I2CDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/I2CDataJNI.cpp
index e4c2259..c023754 100644
--- a/hal/src/main/native/cpp/jni/simulation/I2CDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/I2CDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/NotifierDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/NotifierDataJNI.cpp
index 845c164..15b02d7 100644
--- a/hal/src/main/native/cpp/jni/simulation/NotifierDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/NotifierDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "edu_wpi_first_hal_simulation_NotifierDataJNI.h"
#include "hal/simulation/NotifierData.h"
diff --git a/hal/src/main/native/cpp/jni/simulation/PCMDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/PCMDataJNI.cpp
deleted file mode 100644
index cfcd2c0..0000000
--- a/hal/src/main/native/cpp/jni/simulation/PCMDataJNI.cpp
+++ /dev/null
@@ -1,421 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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 <jni.h>
-
-#include "CallbackStore.h"
-#include "edu_wpi_first_hal_simulation_PCMDataJNI.h"
-#include "hal/simulation/PCMData.h"
-
-using namespace hal;
-
-extern "C" {
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerSolenoidInitializedCallback
- * Signature: (IILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerSolenoidInitializedCallback
- (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
- jboolean initialNotify)
-{
- return sim::AllocateChannelCallback(
- env, index, channel, callback, initialNotify,
- &HALSIM_RegisterPCMSolenoidInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelSolenoidInitializedCallback
- * Signature: (III)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelSolenoidInitializedCallback
- (JNIEnv* env, jclass, jint index, jint channel, jint handle)
-{
- return sim::FreeChannelCallback(env, handle, index, channel,
- &HALSIM_CancelPCMSolenoidInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getSolenoidInitialized
- * Signature: (II)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getSolenoidInitialized
- (JNIEnv*, jclass, jint index, jint channel)
-{
- return HALSIM_GetPCMSolenoidInitialized(index, channel);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setSolenoidInitialized
- * Signature: (IIZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setSolenoidInitialized
- (JNIEnv*, jclass, jint index, jint channel, jboolean value)
-{
- HALSIM_SetPCMSolenoidInitialized(index, channel, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerSolenoidOutputCallback
- * Signature: (IILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerSolenoidOutputCallback
- (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
- jboolean initialNotify)
-{
- return sim::AllocateChannelCallback(
- env, index, channel, callback, initialNotify,
- &HALSIM_RegisterPCMSolenoidOutputCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelSolenoidOutputCallback
- * Signature: (III)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelSolenoidOutputCallback
- (JNIEnv* env, jclass, jint index, jint channel, jint handle)
-{
- return sim::FreeChannelCallback(env, handle, index, channel,
- &HALSIM_CancelPCMSolenoidOutputCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getSolenoidOutput
- * Signature: (II)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getSolenoidOutput
- (JNIEnv*, jclass, jint index, jint channel)
-{
- return HALSIM_GetPCMSolenoidOutput(index, channel);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setSolenoidOutput
- * Signature: (IIZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setSolenoidOutput
- (JNIEnv*, jclass, jint index, jint channel, jboolean value)
-{
- HALSIM_SetPCMSolenoidOutput(index, channel, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerCompressorInitializedCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerCompressorInitializedCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(
- env, index, callback, initialNotify,
- &HALSIM_RegisterPCMCompressorInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelCompressorInitializedCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelCompressorInitializedCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPCMCompressorInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getCompressorInitialized
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getCompressorInitialized
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPCMCompressorInitialized(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setCompressorInitialized
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setCompressorInitialized
- (JNIEnv*, jclass, jint index, jboolean value)
-{
- HALSIM_SetPCMCompressorInitialized(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerCompressorOnCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerCompressorOnCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPCMCompressorOnCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelCompressorOnCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelCompressorOnCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPCMCompressorOnCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getCompressorOn
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getCompressorOn
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPCMCompressorOn(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setCompressorOn
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setCompressorOn
- (JNIEnv*, jclass, jint index, jboolean value)
-{
- HALSIM_SetPCMCompressorOn(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerClosedLoopEnabledCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerClosedLoopEnabledCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPCMClosedLoopEnabledCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelClosedLoopEnabledCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelClosedLoopEnabledCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPCMClosedLoopEnabledCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getClosedLoopEnabled
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getClosedLoopEnabled
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPCMClosedLoopEnabled(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setClosedLoopEnabled
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setClosedLoopEnabled
- (JNIEnv*, jclass, jint index, jboolean value)
-{
- HALSIM_SetPCMClosedLoopEnabled(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerPressureSwitchCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerPressureSwitchCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPCMPressureSwitchCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelPressureSwitchCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelPressureSwitchCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPCMPressureSwitchCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getPressureSwitch
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getPressureSwitch
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPCMPressureSwitch(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setPressureSwitch
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setPressureSwitch
- (JNIEnv*, jclass, jint index, jboolean value)
-{
- HALSIM_SetPCMPressureSwitch(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerCompressorCurrentCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerCompressorCurrentCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPCMCompressorCurrentCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: cancelCompressorCurrentCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_cancelCompressorCurrentCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPCMCompressorCurrentCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: getCompressorCurrent
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_getCompressorCurrent
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPCMCompressorCurrent(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: setCompressorCurrent
- * Signature: (ID)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_setCompressorCurrent
- (JNIEnv*, jclass, jint index, jdouble value)
-{
- HALSIM_SetPCMCompressorCurrent(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerAllNonSolenoidCallbacks
- * Signature: (ILjava/lang/Object;Z)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerAllNonSolenoidCallbacks
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- sim::AllocateCallback(
- env, index, callback, initialNotify,
- [](int32_t index, HAL_NotifyCallback cb, void* param, HAL_Bool in) {
- HALSIM_RegisterPCMAllNonSolenoidCallbacks(index, cb, param, in);
- return 0;
- });
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: registerAllSolenoidCallbacks
- * Signature: (IILjava/lang/Object;Z)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_registerAllSolenoidCallbacks
- (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
- jboolean initialNotify)
-{
- sim::AllocateChannelCallback(
- env, index, channel, callback, initialNotify,
- [](int32_t index, int32_t channel, HAL_NotifyCallback cb, void* param,
- HAL_Bool in) {
- HALSIM_RegisterPCMAllSolenoidCallbacks(index, channel, cb, param, in);
- return 0;
- });
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PCMDataJNI
- * Method: resetData
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PCMDataJNI_resetData
- (JNIEnv*, jclass, jint index)
-{
- HALSIM_ResetPCMData(index);
-}
-
-} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/PDPDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/PDPDataJNI.cpp
deleted file mode 100644
index 2ce6cbd..0000000
--- a/hal/src/main/native/cpp/jni/simulation/PDPDataJNI.cpp
+++ /dev/null
@@ -1,232 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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 <jni.h>
-
-#include "CallbackStore.h"
-#include "edu_wpi_first_hal_simulation_PDPDataJNI.h"
-#include "hal/simulation/PDPData.h"
-
-using namespace hal;
-
-extern "C" {
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: registerInitializedCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerInitializedCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPDPInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: cancelInitializedCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelInitializedCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPDPInitializedCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: getInitialized
- * Signature: (I)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_getInitialized
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPDPInitialized(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: setInitialized
- * Signature: (IZ)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_setInitialized
- (JNIEnv*, jclass, jint index, jboolean value)
-{
- HALSIM_SetPDPInitialized(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: registerTemperatureCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerTemperatureCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPDPTemperatureCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: cancelTemperatureCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelTemperatureCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPDPTemperatureCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: getTemperature
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_getTemperature
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPDPTemperature(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: setTemperature
- * Signature: (ID)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_setTemperature
- (JNIEnv*, jclass, jint index, jdouble value)
-{
- HALSIM_SetPDPTemperature(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: registerVoltageCallback
- * Signature: (ILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerVoltageCallback
- (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
-{
- return sim::AllocateCallback(env, index, callback, initialNotify,
- &HALSIM_RegisterPDPVoltageCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: cancelVoltageCallback
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelVoltageCallback
- (JNIEnv* env, jclass, jint index, jint handle)
-{
- return sim::FreeCallback(env, handle, index,
- &HALSIM_CancelPDPVoltageCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: getVoltage
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_getVoltage
- (JNIEnv*, jclass, jint index)
-{
- return HALSIM_GetPDPVoltage(index);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: setVoltage
- * Signature: (ID)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_setVoltage
- (JNIEnv*, jclass, jint index, jdouble value)
-{
- HALSIM_SetPDPVoltage(index, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: registerCurrentCallback
- * Signature: (IILjava/lang/Object;Z)I
- */
-JNIEXPORT jint JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerCurrentCallback
- (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
- jboolean initialNotify)
-{
- return sim::AllocateChannelCallback(env, index, channel, callback,
- initialNotify,
- &HALSIM_RegisterPDPCurrentCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: cancelCurrentCallback
- * Signature: (III)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelCurrentCallback
- (JNIEnv* env, jclass, jint index, jint channel, jint handle)
-{
- return sim::FreeChannelCallback(env, handle, index, channel,
- &HALSIM_CancelPDPCurrentCallback);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: getCurrent
- * Signature: (II)D
- */
-JNIEXPORT jdouble JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_getCurrent
- (JNIEnv*, jclass, jint index, jint channel)
-{
- return HALSIM_GetPDPCurrent(index, channel);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: setCurrent
- * Signature: (IID)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_setCurrent
- (JNIEnv*, jclass, jint index, jint channel, jdouble value)
-{
- HALSIM_SetPDPCurrent(index, channel, value);
-}
-
-/*
- * Class: edu_wpi_first_hal_simulation_PDPDataJNI
- * Method: resetData
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_simulation_PDPDataJNI_resetData
- (JNIEnv*, jclass, jint index)
-{
- HALSIM_ResetPDPData(index);
-}
-
-} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/PWMDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/PWMDataJNI.cpp
index 03e61ef..31c79a7 100644
--- a/hal/src/main/native/cpp/jni/simulation/PWMDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/PWMDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/PowerDistributionDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/PowerDistributionDataJNI.cpp
new file mode 100644
index 0000000..517dc09
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/simulation/PowerDistributionDataJNI.cpp
@@ -0,0 +1,233 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include "CallbackStore.h"
+#include "edu_wpi_first_hal_simulation_PowerDistributionDataJNI.h"
+#include "hal/simulation/PowerDistributionData.h"
+
+using namespace hal;
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: registerInitializedCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerInitializedCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ &HALSIM_RegisterPowerDistributionInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: cancelInitializedCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelInitializedCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelPowerDistributionInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: getInitialized
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getInitialized
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetPowerDistributionInitialized(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: setInitialized
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setInitialized
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetPowerDistributionInitialized(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: registerTemperatureCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerTemperatureCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ &HALSIM_RegisterPowerDistributionTemperatureCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: cancelTemperatureCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelTemperatureCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelPowerDistributionTemperatureCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: getTemperature
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getTemperature
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetPowerDistributionTemperature(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: setTemperature
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setTemperature
+ (JNIEnv*, jclass, jint index, jdouble value)
+{
+ HALSIM_SetPowerDistributionTemperature(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: registerVoltageCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerVoltageCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ &HALSIM_RegisterPowerDistributionVoltageCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: cancelVoltageCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelVoltageCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelPowerDistributionVoltageCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: getVoltage
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getVoltage
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetPowerDistributionVoltage(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: setVoltage
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setVoltage
+ (JNIEnv*, jclass, jint index, jdouble value)
+{
+ HALSIM_SetPowerDistributionVoltage(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: registerCurrentCallback
+ * Signature: (IILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerCurrentCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
+ jboolean initialNotify)
+{
+ return sim::AllocateChannelCallback(
+ env, index, channel, callback, initialNotify,
+ &HALSIM_RegisterPowerDistributionCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: cancelCurrentCallback
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelCurrentCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jint handle)
+{
+ return sim::FreeChannelCallback(
+ env, handle, index, channel,
+ &HALSIM_CancelPowerDistributionCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: getCurrent
+ * Signature: (II)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getCurrent
+ (JNIEnv*, jclass, jint index, jint channel)
+{
+ return HALSIM_GetPowerDistributionCurrent(index, channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: setCurrent
+ * Signature: (IID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setCurrent
+ (JNIEnv*, jclass, jint index, jint channel, jdouble value)
+{
+ HALSIM_SetPowerDistributionCurrent(index, channel, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
+ * Method: resetData
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_resetData
+ (JNIEnv*, jclass, jint index)
+{
+ HALSIM_ResetPowerDistributionData(index);
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/REVPHDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/REVPHDataJNI.cpp
new file mode 100644
index 0000000..da473de
--- /dev/null
+++ b/hal/src/main/native/cpp/jni/simulation/REVPHDataJNI.cpp
@@ -0,0 +1,365 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <jni.h>
+
+#include "CallbackStore.h"
+#include "edu_wpi_first_hal_simulation_REVPHDataJNI.h"
+#include "hal/simulation/REVPHData.h"
+
+using namespace hal;
+
+extern "C" {
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerInitializedCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerInitializedCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterREVPHInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelInitializedCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelInitializedCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelREVPHInitializedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getInitialized
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getInitialized
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetREVPHInitialized(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setInitialized
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setInitialized
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetREVPHInitialized(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerSolenoidOutputCallback
+ * Signature: (IILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerSolenoidOutputCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
+ jboolean initialNotify)
+{
+ return sim::AllocateChannelCallback(
+ env, index, channel, callback, initialNotify,
+ &HALSIM_RegisterREVPHSolenoidOutputCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelSolenoidOutputCallback
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelSolenoidOutputCallback
+ (JNIEnv* env, jclass, jint index, jint channel, jint handle)
+{
+ return sim::FreeChannelCallback(env, handle, index, channel,
+ &HALSIM_CancelREVPHSolenoidOutputCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getSolenoidOutput
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getSolenoidOutput
+ (JNIEnv*, jclass, jint index, jint channel)
+{
+ return HALSIM_GetREVPHSolenoidOutput(index, channel);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setSolenoidOutput
+ * Signature: (IIZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setSolenoidOutput
+ (JNIEnv*, jclass, jint index, jint channel, jboolean value)
+{
+ HALSIM_SetREVPHSolenoidOutput(index, channel, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerCompressorOnCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerCompressorOnCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterREVPHCompressorOnCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelCompressorOnCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelCompressorOnCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelREVPHCompressorOnCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getCompressorOn
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getCompressorOn
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetREVPHCompressorOn(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setCompressorOn
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setCompressorOn
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetREVPHCompressorOn(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerClosedLoopEnabledCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerClosedLoopEnabledCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterREVPHClosedLoopEnabledCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelClosedLoopEnabledCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelClosedLoopEnabledCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelREVPHClosedLoopEnabledCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getClosedLoopEnabled
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getClosedLoopEnabled
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetREVPHClosedLoopEnabled(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setClosedLoopEnabled
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setClosedLoopEnabled
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetREVPHClosedLoopEnabled(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerPressureSwitchCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerPressureSwitchCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterREVPHPressureSwitchCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelPressureSwitchCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelPressureSwitchCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelREVPHPressureSwitchCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getPressureSwitch
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getPressureSwitch
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetREVPHPressureSwitch(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setPressureSwitch
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setPressureSwitch
+ (JNIEnv*, jclass, jint index, jboolean value)
+{
+ HALSIM_SetREVPHPressureSwitch(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerCompressorCurrentCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerCompressorCurrentCallback
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallback(env, index, callback, initialNotify,
+ &HALSIM_RegisterREVPHCompressorCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: cancelCompressorCurrentCallback
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelCompressorCurrentCallback
+ (JNIEnv* env, jclass, jint index, jint handle)
+{
+ return sim::FreeCallback(env, handle, index,
+ &HALSIM_CancelREVPHCompressorCurrentCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: getCompressorCurrent
+ * Signature: (I)D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getCompressorCurrent
+ (JNIEnv*, jclass, jint index)
+{
+ return HALSIM_GetREVPHCompressorCurrent(index);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: setCompressorCurrent
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setCompressorCurrent
+ (JNIEnv*, jclass, jint index, jdouble value)
+{
+ HALSIM_SetREVPHCompressorCurrent(index, value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerAllNonSolenoidCallbacks
+ * Signature: (ILjava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerAllNonSolenoidCallbacks
+ (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
+{
+ sim::AllocateCallback(
+ env, index, callback, initialNotify,
+ [](int32_t index, HAL_NotifyCallback cb, void* param, HAL_Bool in) {
+ HALSIM_RegisterREVPHAllNonSolenoidCallbacks(index, cb, param, in);
+ return 0;
+ });
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: registerAllSolenoidCallbacks
+ * Signature: (IILjava/lang/Object;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerAllSolenoidCallbacks
+ (JNIEnv* env, jclass, jint index, jint channel, jobject callback,
+ jboolean initialNotify)
+{
+ sim::AllocateChannelCallback(
+ env, index, channel, callback, initialNotify,
+ [](int32_t index, int32_t channel, HAL_NotifyCallback cb, void* param,
+ HAL_Bool in) {
+ HALSIM_RegisterREVPHAllSolenoidCallbacks(index, channel, cb, param, in);
+ return 0;
+ });
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_REVPHDataJNI
+ * Method: resetData
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_REVPHDataJNI_resetData
+ (JNIEnv*, jclass, jint index)
+{
+ HALSIM_ResetREVPHData(index);
+}
+
+} // extern "C"
diff --git a/hal/src/main/native/cpp/jni/simulation/RelayDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/RelayDataJNI.cpp
index 7abe7cb..7a59327 100644
--- a/hal/src/main/native/cpp/jni/simulation/RelayDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/RelayDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/RoboRioDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/RoboRioDataJNI.cpp
index 1ff6044..03bb0c5 100644
--- a/hal/src/main/native/cpp/jni/simulation/RoboRioDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/RoboRioDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
@@ -779,6 +776,57 @@
/*
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
+ * Method: registerBrownoutVoltageCallback
+ * Signature: (Ljava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_registerBrownoutVoltageCallback
+ (JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
+{
+ return sim::AllocateCallbackNoIndex(
+ env, callback, initialNotify,
+ &HALSIM_RegisterRoboRioBrownoutVoltageCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
+ * Method: cancelBrownoutVoltageCallback
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_cancelBrownoutVoltageCallback
+ (JNIEnv* env, jclass, jint handle)
+{
+ return sim::FreeCallbackNoIndex(env, handle,
+ &HALSIM_CancelRoboRioBrownoutVoltageCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
+ * Method: getBrownoutVoltage
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL
+Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_getBrownoutVoltage
+ (JNIEnv*, jclass)
+{
+ return HALSIM_GetRoboRioBrownoutVoltage();
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
+ * Method: setBrownoutVoltage
+ * Signature: (D)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_setBrownoutVoltage
+ (JNIEnv*, jclass, jdouble value)
+{
+ HALSIM_SetRoboRioBrownoutVoltage(value);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
* Method: resetData
* Signature: ()V
*/
diff --git a/hal/src/main/native/cpp/jni/simulation/SPIAccelerometerDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SPIAccelerometerDataJNI.cpp
index fe0c410..51bb320 100644
--- a/hal/src/main/native/cpp/jni/simulation/SPIAccelerometerDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/SPIAccelerometerDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/SPIDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SPIDataJNI.cpp
index 3709984..977f25b 100644
--- a/hal/src/main/native/cpp/jni/simulation/SPIDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/SPIDataJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp
index 0b43d24..60ce0f7 100644
--- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp
@@ -1,23 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "SimDeviceDataJNI.h"
#include <jni.h>
-#include <functional>
-#include <string>
+#include <cstdio>
#include <utility>
-#include <wpi/UidVector.h>
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
#include "edu_wpi_first_hal_simulation_SimDeviceDataJNI.h"
+#include "hal/SimDevice.h"
+#include "hal/handles/UnlimitedHandleResource.h"
#include "hal/simulation/SimDeviceData.h"
using namespace hal;
@@ -39,23 +36,18 @@
HAL_SimValueHandle handle;
jobject MakeJava(JNIEnv* env) const;
- void CallJava(JNIEnv* env, jobject callobj) const;
};
struct ValueInfo {
- ValueInfo(const char* name_, HAL_SimValueHandle handle_, bool readonly_,
+ ValueInfo(const char* name_, HAL_SimValueHandle handle_, int32_t direction_,
const HAL_Value& value_)
- : name{name_}, handle{handle_}, readonly{readonly_}, value{value_} {}
+ : name{name_}, handle{handle_}, direction{direction_}, value{value_} {}
std::string name;
HAL_SimValueHandle handle;
- bool readonly;
+ int32_t direction;
HAL_Value value;
jobject MakeJava(JNIEnv* env) const;
- void CallJava(JNIEnv* env, jobject callobj) const;
-
- private:
- std::pair<jlong, jdouble> ToValue12() const;
};
} // namespace
@@ -64,15 +56,10 @@
static jmethodID func =
env->GetMethodID(simDeviceInfoCls, "<init>", "(Ljava/lang/String;I)V");
return env->NewObject(simDeviceInfoCls, func, MakeJString(env, name),
- (jint)handle);
+ static_cast<jint>(handle));
}
-void DeviceInfo::CallJava(JNIEnv* env, jobject callobj) const {
- env->CallVoidMethod(callobj, simDeviceCallbackCallback,
- MakeJString(env, name), (jint)handle);
-}
-
-std::pair<jlong, jdouble> ValueInfo::ToValue12() const {
+static std::pair<jlong, jdouble> ToValue12(const HAL_Value& value) {
jlong value1 = 0;
jdouble value2 = 0.0;
switch (value.type) {
@@ -99,194 +86,268 @@
jobject ValueInfo::MakeJava(JNIEnv* env) const {
static jmethodID func =
- env->GetMethodID(simValueInfoCls, "<init>", "(Ljava/lang/String;IZIJD)V");
- auto [value1, value2] = ToValue12();
+ env->GetMethodID(simValueInfoCls, "<init>", "(Ljava/lang/String;IIIJD)V");
+ auto [value1, value2] = ToValue12(value);
return env->NewObject(simValueInfoCls, func, MakeJString(env, name),
- (jint)handle, (jboolean)readonly, (jint)value.type,
- value1, value2);
-}
-
-void ValueInfo::CallJava(JNIEnv* env, jobject callobj) const {
- auto [value1, value2] = ToValue12();
- env->CallVoidMethod(callobj, simValueCallbackCallback, MakeJString(env, name),
- (jint)handle, (jboolean)readonly, (jint)value.type,
- value1, value2);
+ static_cast<jint>(handle), static_cast<jint>(direction),
+ static_cast<jint>(value.type), value1, value2);
}
namespace {
-class CallbackStore {
+class DeviceCallbackStore {
public:
- explicit CallbackStore(JNIEnv* env, jobject obj) : m_call{env, obj} {}
- ~CallbackStore() {
- if (m_cancelCallback) m_cancelCallback();
- }
-
- void SetCancel(std::function<void()> cancelCallback) {
- m_cancelCallback = std::move(cancelCallback);
- }
- void Free(JNIEnv* env) { m_call.free(env); }
- jobject Get() const { return m_call; }
+ void create(JNIEnv* env, jobject obj) { m_call = JGlobal<jobject>(env, obj); }
+ void performCallback(const char* name, HAL_SimDeviceHandle handle);
+ void free(JNIEnv* env) { m_call.free(env); }
+ void setCallbackId(int32_t id) { callbackId = id; }
+ int32_t getCallbackId() { return callbackId; }
private:
wpi::java::JGlobal<jobject> m_call;
- std::function<void()> m_cancelCallback;
+ int32_t callbackId;
};
-class CallbackThreadJNI : public wpi::SafeThread {
+class ValueCallbackStore {
public:
- void Main();
-
- using DeviceCalls =
- std::vector<std::pair<std::weak_ptr<CallbackStore>, DeviceInfo>>;
- DeviceCalls m_deviceCalls;
- using ValueCalls =
- std::vector<std::pair<std::weak_ptr<CallbackStore>, ValueInfo>>;
- ValueCalls m_valueCalls;
-
- wpi::UidVector<std::shared_ptr<CallbackStore>, 4> m_callbacks;
-};
-
-class CallbackJNI {
- public:
- static CallbackJNI& GetInstance() {
- static CallbackJNI inst;
- return inst;
- }
- void SendDevice(int32_t callback, DeviceInfo info);
- void SendValue(int32_t callback, ValueInfo info);
-
- std::pair<int32_t, std::shared_ptr<CallbackStore>> AllocateCallback(
- JNIEnv* env, jobject obj);
-
- void FreeCallback(JNIEnv* env, int32_t uid);
+ void create(JNIEnv* env, jobject obj) { m_call = JGlobal<jobject>(env, obj); }
+ void performCallback(const char* name, HAL_SimValueHandle handle,
+ int32_t direction, const HAL_Value& value);
+ void free(JNIEnv* env) { m_call.free(env); }
+ void setCallbackId(int32_t id) { m_callbackId = id; }
+ int32_t getCallbackId() { return m_callbackId; }
private:
- CallbackJNI() { m_owner.Start(); }
-
- wpi::SafeThreadOwner<CallbackThreadJNI> m_owner;
+ wpi::java::JGlobal<jobject> m_call;
+ int32_t m_callbackId;
};
} // namespace
-void CallbackThreadJNI::Main() {
+void DeviceCallbackStore::performCallback(const char* name,
+ HAL_SimDeviceHandle handle) {
JNIEnv* env;
- JavaVMAttachArgs args;
- args.version = JNI_VERSION_1_2;
- args.name = const_cast<char*>("SimDeviceCallback");
- args.group = nullptr;
- jint rs = sim::GetJVM()->AttachCurrentThreadAsDaemon(
- reinterpret_cast<void**>(&env), &args);
- if (rs != JNI_OK) return;
-
- DeviceCalls deviceCalls;
- ValueCalls valueCalls;
-
- std::unique_lock lock(m_mutex);
- while (m_active) {
- m_cond.wait(lock, [&] { return !m_active; });
- if (!m_active) break;
-
- deviceCalls.swap(m_deviceCalls);
- valueCalls.swap(m_valueCalls);
-
- lock.unlock(); // don't hold mutex during callback execution
-
- for (auto&& call : deviceCalls) {
- if (auto store = call.first.lock()) {
- if (jobject callobj = store->Get()) {
- call.second.CallJava(env, callobj);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- env->ExceptionClear();
- }
- }
- }
+ JavaVM* vm = sim::GetJVM();
+ bool didAttachThread = false;
+ int tryGetEnv = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
+ if (tryGetEnv == JNI_EDETACHED) {
+ // Thread not attached
+ didAttachThread = true;
+ if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
+ // Failed to attach, log and return
+ std::puts("Failed to attach");
+ std::fflush(stdout);
+ return;
}
-
- for (auto&& call : valueCalls) {
- if (auto store = call.first.lock()) {
- if (jobject callobj = store->Get()) {
- call.second.CallJava(env, callobj);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- env->ExceptionClear();
- }
- }
- }
- }
-
- deviceCalls.clear();
- valueCalls.clear();
-
- lock.lock();
+ } else if (tryGetEnv == JNI_EVERSION) {
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
}
- // free global references
- for (auto&& callback : m_callbacks) callback->Free(env);
+ env->CallVoidMethod(m_call, simDeviceCallbackCallback, MakeJString(env, name),
+ static_cast<jint>(handle));
- sim::GetJVM()->DetachCurrentThread();
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ if (didAttachThread) {
+ vm->DetachCurrentThread();
+ }
}
-void CallbackJNI::SendDevice(int32_t callback, DeviceInfo info) {
- auto thr = m_owner.GetThread();
- if (!thr) return;
- thr->m_deviceCalls.emplace_back(thr->m_callbacks[callback], std::move(info));
- thr->m_cond.notify_one();
+void ValueCallbackStore::performCallback(const char* name,
+ HAL_SimValueHandle handle,
+ int32_t direction,
+ const HAL_Value& value) {
+ JNIEnv* env;
+ JavaVM* vm = sim::GetJVM();
+ bool didAttachThread = false;
+ int tryGetEnv = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
+ if (tryGetEnv == JNI_EDETACHED) {
+ // Thread not attached
+ didAttachThread = true;
+ if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
+ // Failed to attach, log and return
+ std::puts("Failed to attach");
+ std::fflush(stdout);
+ return;
+ }
+ } else if (tryGetEnv == JNI_EVERSION) {
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
+ }
+
+ auto [value1, value2] = ToValue12(value);
+ env->CallVoidMethod(m_call, simValueCallbackCallback, MakeJString(env, name),
+ static_cast<jint>(handle), static_cast<jint>(direction),
+ static_cast<jint>(value.type), value1, value2);
+
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ if (didAttachThread) {
+ vm->DetachCurrentThread();
+ }
}
-void CallbackJNI::SendValue(int32_t callback, ValueInfo info) {
- auto thr = m_owner.GetThread();
- if (!thr) return;
- thr->m_valueCalls.emplace_back(thr->m_callbacks[callback], std::move(info));
- thr->m_cond.notify_one();
+static hal::UnlimitedHandleResource<SIM_JniHandle, DeviceCallbackStore,
+ hal::HAL_HandleEnum::SimulationJni>*
+ deviceCallbackHandles;
+
+namespace {
+using RegisterDeviceCallbackFunc =
+ int32_t (*)(const char* prefix, void* param,
+ HALSIM_SimDeviceCallback callback, HAL_Bool initialNotify);
+using FreeDeviceCallbackFunc = void (*)(int32_t uid);
+} // namespace
+
+static SIM_JniHandle AllocateDeviceCallback(
+ JNIEnv* env, const char* prefix, jobject callback, jboolean initialNotify,
+ RegisterDeviceCallbackFunc createCallback) {
+ auto callbackStore = std::make_shared<DeviceCallbackStore>();
+
+ auto handle = deviceCallbackHandles->Allocate(callbackStore);
+
+ if (handle == HAL_kInvalidHandle) {
+ return -1;
+ }
+
+ uintptr_t handleAsPtr = static_cast<uintptr_t>(handle);
+ void* handleAsVoidPtr = reinterpret_cast<void*>(handleAsPtr);
+
+ callbackStore->create(env, callback);
+
+ auto callbackFunc = [](const char* name, void* param,
+ HAL_SimDeviceHandle handle) {
+ uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
+ SIM_JniHandle jnihandle = static_cast<SIM_JniHandle>(handleTmp);
+ auto data = deviceCallbackHandles->Get(jnihandle);
+ if (!data) {
+ return;
+ }
+
+ data->performCallback(name, handle);
+ };
+
+ auto id =
+ createCallback(prefix, handleAsVoidPtr, callbackFunc, initialNotify);
+
+ callbackStore->setCallbackId(id);
+
+ return handle;
}
-std::pair<int32_t, std::shared_ptr<CallbackStore>>
-CallbackJNI::AllocateCallback(JNIEnv* env, jobject obj) {
- auto thr = m_owner.GetThread();
- if (!thr) return std::pair(0, nullptr);
- auto store = std::make_shared<CallbackStore>(env, obj);
- return std::pair(thr->m_callbacks.emplace_back(store) + 1, store);
+static void FreeDeviceCallback(JNIEnv* env, SIM_JniHandle handle,
+ FreeDeviceCallbackFunc freeCallback) {
+ auto callback = deviceCallbackHandles->Free(handle);
+ freeCallback(callback->getCallbackId());
+ callback->free(env);
}
-void CallbackJNI::FreeCallback(JNIEnv* env, int32_t uid) {
- auto thr = m_owner.GetThread();
- if (!thr) return;
- if (uid <= 0 || static_cast<uint32_t>(uid) >= thr->m_callbacks.size()) return;
- --uid;
- auto store = std::move(thr->m_callbacks[uid]);
- thr->m_callbacks.erase(uid);
- store->Free(env);
+static hal::UnlimitedHandleResource<SIM_JniHandle, ValueCallbackStore,
+ hal::HAL_HandleEnum::SimulationJni>*
+ valueCallbackHandles;
+
+namespace {
+using FreeValueCallbackFunc = void (*)(int32_t uid);
+} // namespace
+
+template <typename THandle>
+static SIM_JniHandle AllocateValueCallback(
+ JNIEnv* env, THandle h, jobject callback, jboolean initialNotify,
+ int32_t (*createCallback)(THandle handle, void* param,
+ HALSIM_SimValueCallback callback,
+ HAL_Bool initialNotify)) {
+ auto callbackStore = std::make_shared<ValueCallbackStore>();
+
+ auto handle = valueCallbackHandles->Allocate(callbackStore);
+
+ if (handle == HAL_kInvalidHandle) {
+ return -1;
+ }
+
+ uintptr_t handleAsPtr = static_cast<uintptr_t>(handle);
+ void* handleAsVoidPtr = reinterpret_cast<void*>(handleAsPtr);
+
+ callbackStore->create(env, callback);
+
+ auto callbackFunc = [](const char* name, void* param,
+ HAL_SimValueHandle handle, int32_t direction,
+ const HAL_Value* value) {
+ uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
+ SIM_JniHandle jnihandle = static_cast<SIM_JniHandle>(handleTmp);
+ auto data = valueCallbackHandles->Get(jnihandle);
+ if (!data) {
+ return;
+ }
+
+ data->performCallback(name, handle, direction, *value);
+ };
+
+ auto id = createCallback(h, handleAsVoidPtr, callbackFunc, initialNotify);
+
+ callbackStore->setCallbackId(id);
+
+ return handle;
}
-namespace hal {
-namespace sim {
+static void FreeValueCallback(JNIEnv* env, SIM_JniHandle handle,
+ FreeValueCallbackFunc freeCallback) {
+ auto callback = valueCallbackHandles->Free(handle);
+ freeCallback(callback->getCallbackId());
+ callback->free(env);
+}
+
+namespace hal::sim {
bool InitializeSimDeviceDataJNI(JNIEnv* env) {
simDeviceInfoCls = JClass(
env, "edu/wpi/first/hal/simulation/SimDeviceDataJNI$SimDeviceInfo");
- if (!simDeviceInfoCls) return false;
+ if (!simDeviceInfoCls) {
+ return false;
+ }
simValueInfoCls =
JClass(env, "edu/wpi/first/hal/simulation/SimDeviceDataJNI$SimValueInfo");
- if (!simValueInfoCls) return false;
+ if (!simValueInfoCls) {
+ return false;
+ }
simDeviceCallbackCls =
JClass(env, "edu/wpi/first/hal/simulation/SimDeviceCallback");
- if (!simDeviceCallbackCls) return false;
+ if (!simDeviceCallbackCls) {
+ return false;
+ }
simDeviceCallbackCallback = env->GetMethodID(simDeviceCallbackCls, "callback",
"(Ljava/lang/String;I)V");
- if (!simDeviceCallbackCallback) return false;
+ if (!simDeviceCallbackCallback) {
+ return false;
+ }
simValueCallbackCls =
JClass(env, "edu/wpi/first/hal/simulation/SimValueCallback");
- if (!simValueCallbackCls) return false;
+ if (!simValueCallbackCls) {
+ return false;
+ }
simValueCallbackCallback = env->GetMethodID(
- simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IZIJD)V");
- if (!simValueCallbackCallback) return false;
+ simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IIIJD)V");
+ if (!simValueCallbackCallback) {
+ return false;
+ }
+
+ static hal::UnlimitedHandleResource<SIM_JniHandle, DeviceCallbackStore,
+ hal::HAL_HandleEnum::SimulationJni>
+ cbDevice;
+ deviceCallbackHandles = &cbDevice;
+
+ static hal::UnlimitedHandleResource<SIM_JniHandle, ValueCallbackStore,
+ hal::HAL_HandleEnum::SimulationJni>
+ cbValue;
+ valueCallbackHandles = &cbValue;
return true;
}
@@ -298,8 +359,7 @@
simValueCallbackCls.free(env);
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
extern "C" {
@@ -337,18 +397,9 @@
(JNIEnv* env, jclass, jstring prefix, jobject callback,
jboolean initialNotify)
{
- auto [uid, store] =
- CallbackJNI::GetInstance().AllocateCallback(env, callback);
- int32_t cuid = HALSIM_RegisterSimDeviceCreatedCallback(
- JStringRef{env, prefix}.c_str(),
- reinterpret_cast<void*>(static_cast<intptr_t>(uid)),
- [](const char* name, void* param, HAL_SimDeviceHandle handle) {
- int32_t uid = reinterpret_cast<intptr_t>(param);
- CallbackJNI::GetInstance().SendDevice(uid, DeviceInfo{name, handle});
- },
- initialNotify);
- store->SetCancel([cuid] { HALSIM_CancelSimDeviceCreatedCallback(cuid); });
- return uid;
+ return AllocateDeviceCallback(env, JStringRef{env, prefix}.c_str(), callback,
+ initialNotify,
+ &HALSIM_RegisterSimDeviceCreatedCallback);
}
/*
@@ -360,29 +411,22 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_cancelSimDeviceCreatedCallback
(JNIEnv* env, jclass, jint uid)
{
- CallbackJNI::GetInstance().FreeCallback(env, uid);
+ FreeDeviceCallback(env, uid, &HALSIM_CancelSimDeviceCreatedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
* Method: registerSimDeviceFreedCallback
- * Signature: (Ljava/lang/String;Ljava/lang/Object;)I
+ * Signature: (Ljava/lang/String;Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimDeviceFreedCallback
- (JNIEnv* env, jclass, jstring prefix, jobject callback)
+ (JNIEnv* env, jclass, jstring prefix, jobject callback,
+ jboolean initialNotify)
{
- auto [uid, store] =
- CallbackJNI::GetInstance().AllocateCallback(env, callback);
- int32_t cuid = HALSIM_RegisterSimDeviceFreedCallback(
- JStringRef{env, prefix}.c_str(),
- reinterpret_cast<void*>(static_cast<intptr_t>(uid)),
- [](const char* name, void* param, HAL_SimDeviceHandle handle) {
- int32_t uid = reinterpret_cast<intptr_t>(param);
- CallbackJNI::GetInstance().SendDevice(uid, DeviceInfo{name, handle});
- });
- store->SetCancel([cuid] { HALSIM_CancelSimDeviceFreedCallback(cuid); });
- return uid;
+ return AllocateDeviceCallback(env, JStringRef{env, prefix}.c_str(), callback,
+ initialNotify,
+ &HALSIM_RegisterSimDeviceFreedCallback);
}
/*
@@ -394,7 +438,7 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_cancelSimDeviceFreedCallback
(JNIEnv* env, jclass, jint uid)
{
- CallbackJNI::GetInstance().FreeCallback(env, uid);
+ FreeDeviceCallback(env, uid, &HALSIM_CancelSimDeviceFreedCallback);
}
/*
@@ -411,6 +455,18 @@
/*
* Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
+ * Method: getSimDeviceName
+ * Signature: (I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_getSimDeviceName
+ (JNIEnv* env, jclass, jint handle)
+{
+ return MakeJString(env, HALSIM_GetSimDeviceName(handle));
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
* Method: getSimValueDeviceHandle
* Signature: (I)I
*/
@@ -443,7 +499,9 @@
size_t numElems = arr.size();
jobjectArray jarr =
env->NewObjectArray(arr.size(), simDeviceInfoCls, nullptr);
- if (!jarr) return nullptr;
+ if (!jarr) {
+ return nullptr;
+ }
for (size_t i = 0; i < numElems; ++i) {
JLocal<jobject> elem{env, arr[i].MakeJava(env)};
env->SetObjectArrayElement(jarr, i, elem.obj());
@@ -460,19 +518,9 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueCreatedCallback
(JNIEnv* env, jclass, jint device, jobject callback, jboolean initialNotify)
{
- auto [uid, store] =
- CallbackJNI::GetInstance().AllocateCallback(env, callback);
- int32_t cuid = HALSIM_RegisterSimValueCreatedCallback(
- device, reinterpret_cast<void*>(static_cast<intptr_t>(uid)),
- [](const char* name, void* param, HAL_SimValueHandle handle,
- HAL_Bool readonly, const HAL_Value* value) {
- int32_t uid = reinterpret_cast<intptr_t>(param);
- CallbackJNI::GetInstance().SendValue(
- uid, ValueInfo{name, handle, static_cast<bool>(readonly), *value});
- },
- initialNotify);
- store->SetCancel([cuid] { HALSIM_CancelSimValueCreatedCallback(cuid); });
- return uid;
+ return AllocateValueCallback(env, static_cast<HAL_SimDeviceHandle>(device),
+ callback, initialNotify,
+ &HALSIM_RegisterSimValueCreatedCallback);
}
/*
@@ -484,7 +532,7 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_cancelSimValueCreatedCallback
(JNIEnv* env, jclass, jint uid)
{
- CallbackJNI::GetInstance().FreeCallback(env, uid);
+ FreeValueCallback(env, uid, &HALSIM_CancelSimValueCreatedCallback);
}
/*
@@ -496,19 +544,9 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueChangedCallback
(JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify)
{
- auto [uid, store] =
- CallbackJNI::GetInstance().AllocateCallback(env, callback);
- int32_t cuid = HALSIM_RegisterSimValueChangedCallback(
- handle, reinterpret_cast<void*>(static_cast<intptr_t>(uid)),
- [](const char* name, void* param, HAL_SimValueHandle handle,
- HAL_Bool readonly, const HAL_Value* value) {
- int32_t uid = reinterpret_cast<intptr_t>(param);
- CallbackJNI::GetInstance().SendValue(
- uid, ValueInfo{name, handle, static_cast<bool>(readonly), *value});
- },
- initialNotify);
- store->SetCancel([cuid] { HALSIM_CancelSimValueChangedCallback(cuid); });
- return uid;
+ return AllocateValueCallback(env, static_cast<HAL_SimValueHandle>(handle),
+ callback, initialNotify,
+ &HALSIM_RegisterSimValueChangedCallback);
}
/*
@@ -520,7 +558,33 @@
Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_cancelSimValueChangedCallback
(JNIEnv* env, jclass, jint uid)
{
- CallbackJNI::GetInstance().FreeCallback(env, uid);
+ FreeValueCallback(env, uid, &HALSIM_CancelSimValueChangedCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
+ * Method: registerSimValueResetCallback
+ * Signature: (ILjava/lang/Object;Z)I
+ */
+JNIEXPORT jint JNICALL
+Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueResetCallback
+ (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify)
+{
+ return AllocateValueCallback(env, static_cast<HAL_SimValueHandle>(handle),
+ callback, initialNotify,
+ &HALSIM_RegisterSimValueResetCallback);
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
+ * Method: cancelSimValueResetCallback
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL
+Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_cancelSimValueResetCallback
+ (JNIEnv* env, jclass, jint uid)
+{
+ FreeValueCallback(env, uid, &HALSIM_CancelSimValueResetCallback);
}
/*
@@ -557,7 +621,9 @@
// convert to java
size_t numElems = arr.size();
jobjectArray jarr = env->NewObjectArray(arr.size(), simValueInfoCls, nullptr);
- if (!jarr) return nullptr;
+ if (!jarr) {
+ return nullptr;
+ }
for (size_t i = 0; i < numElems; ++i) {
JLocal<jobject> elem{env, arr[i].MakeJava(env)};
env->SetObjectArrayElement(jarr, i, elem.obj());
@@ -575,11 +641,15 @@
(JNIEnv* env, jclass, jint handle)
{
static JClass stringCls{env, "java/lang/String"};
- if (!stringCls) return nullptr;
+ if (!stringCls) {
+ return nullptr;
+ }
int32_t numElems = 0;
const char** elems = HALSIM_GetSimValueEnumOptions(handle, &numElems);
jobjectArray jarr = env->NewObjectArray(numElems, stringCls, nullptr);
- if (!jarr) return nullptr;
+ if (!jarr) {
+ return nullptr;
+ }
for (int32_t i = 0; i < numElems; ++i) {
JLocal<jstring> elem{env, MakeJString(env, elems[i])};
env->SetObjectArrayElement(jarr, i, elem.obj());
@@ -589,6 +659,20 @@
/*
* Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
+ * Method: getSimValueEnumDoubleValues
+ * Signature: (I)[D
+ */
+JNIEXPORT jdoubleArray JNICALL
+Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_getSimValueEnumDoubleValues
+ (JNIEnv* env, jclass, jint handle)
+{
+ int32_t numElems = 0;
+ const double* elems = HALSIM_GetSimValueEnumDoubleValues(handle, &numElems);
+ return MakeJDoubleArray(env, wpi::span(elems, numElems));
+}
+
+/*
+ * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI
* Method: resetSimDeviceData
* Signature: ()V
*/
diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.h b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.h
index 44fc27f..08c47b9 100644
--- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.h
+++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.h
@@ -1,17 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <jni.h>
-namespace hal {
-namespace sim {
+namespace hal::sim {
bool InitializeSimDeviceDataJNI(JNIEnv* env);
void FreeSimDeviceDataJNI(JNIEnv* env);
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
diff --git a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.cpp
index b6336e8..859c7f5 100644
--- a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "SimulatorJNI.h"
@@ -31,61 +28,80 @@
static jmethodID constBufferCallbackCallback;
static jmethodID spiReadAutoReceiveBufferCallbackCallback;
-namespace hal {
-namespace sim {
+namespace hal::sim {
jint SimOnLoad(JavaVM* vm, void* reserved) {
jvm = vm;
JNIEnv* env;
- if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
+ }
notifyCallbackCls =
JClass(env, "edu/wpi/first/hal/simulation/NotifyCallback");
- if (!notifyCallbackCls) return JNI_ERR;
+ if (!notifyCallbackCls) {
+ return JNI_ERR;
+ }
notifyCallbackCallback = env->GetMethodID(notifyCallbackCls, "callbackNative",
"(Ljava/lang/String;IJD)V");
- if (!notifyCallbackCallback) return JNI_ERR;
+ if (!notifyCallbackCallback) {
+ return JNI_ERR;
+ }
bufferCallbackCls =
JClass(env, "edu/wpi/first/hal/simulation/BufferCallback");
- if (!bufferCallbackCls) return JNI_ERR;
+ if (!bufferCallbackCls) {
+ return JNI_ERR;
+ }
bufferCallbackCallback = env->GetMethodID(bufferCallbackCls, "callback",
"(Ljava/lang/String;[BI)V");
- if (!bufferCallbackCallback) return JNI_ERR;
+ if (!bufferCallbackCallback) {
+ return JNI_ERR;
+ }
constBufferCallbackCls =
JClass(env, "edu/wpi/first/hal/simulation/ConstBufferCallback");
- if (!constBufferCallbackCls) return JNI_ERR;
+ if (!constBufferCallbackCls) {
+ return JNI_ERR;
+ }
constBufferCallbackCallback = env->GetMethodID(
constBufferCallbackCls, "callback", "(Ljava/lang/String;[BI)V");
- if (!constBufferCallbackCallback) return JNI_ERR;
+ if (!constBufferCallbackCallback) {
+ return JNI_ERR;
+ }
spiReadAutoReceiveBufferCallbackCls = JClass(
env, "edu/wpi/first/hal/simulation/SpiReadAutoReceiveBufferCallback");
- if (!spiReadAutoReceiveBufferCallbackCls) return JNI_ERR;
+ if (!spiReadAutoReceiveBufferCallbackCls) {
+ return JNI_ERR;
+ }
spiReadAutoReceiveBufferCallbackCallback =
env->GetMethodID(spiReadAutoReceiveBufferCallbackCls, "callback",
"(Ljava/lang/String;[II)I");
- if (!spiReadAutoReceiveBufferCallbackCallback) return JNI_ERR;
+ if (!spiReadAutoReceiveBufferCallbackCallback) {
+ return JNI_ERR;
+ }
InitializeStore();
InitializeBufferStore();
InitializeConstBufferStore();
InitializeSpiBufferStore();
- if (!InitializeSimDeviceDataJNI(env)) return JNI_ERR;
+ if (!InitializeSimDeviceDataJNI(env)) {
+ return JNI_ERR;
+ }
return JNI_VERSION_1_6;
}
void SimOnUnload(JavaVM* vm, void* reserved) {
JNIEnv* env;
- if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return;
+ }
notifyCallbackCls.free(env);
bufferCallbackCls.free(env);
@@ -95,19 +111,26 @@
jvm = nullptr;
}
-JavaVM* GetJVM() { return jvm; }
+JavaVM* GetJVM() {
+ return jvm;
+}
-jmethodID GetNotifyCallback() { return notifyCallbackCallback; }
+jmethodID GetNotifyCallback() {
+ return notifyCallbackCallback;
+}
-jmethodID GetBufferCallback() { return bufferCallbackCallback; }
+jmethodID GetBufferCallback() {
+ return bufferCallbackCallback;
+}
-jmethodID GetConstBufferCallback() { return constBufferCallbackCallback; }
+jmethodID GetConstBufferCallback() {
+ return constBufferCallbackCallback;
+}
jmethodID GetSpiReadAutoReceiveBufferCallback() {
return spiReadAutoReceiveBufferCallbackCallback;
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
extern "C" {
/*
diff --git a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h
index d6710e8..3e71acd 100644
--- a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h
+++ b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h
@@ -1,24 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include "hal/Types.h"
#include "jni.h"
-typedef HAL_Handle SIM_JniHandle;
+using SIM_JniHandle = HAL_Handle; // NOLINT
-namespace hal {
-namespace sim {
+namespace hal::sim {
JavaVM* GetJVM();
jmethodID GetNotifyCallback();
jmethodID GetBufferCallback();
jmethodID GetConstBufferCallback();
jmethodID GetSpiReadAutoReceiveBufferCallback();
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
diff --git a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp
index 5432840..c20f607 100644
--- a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp
+++ b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.cpp
@@ -1,14 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "SpiReadAutoReceiveBufferCallbackStore.h"
#include <jni.h>
+#include <cstdio>
+
#include <wpi/jni_util.h>
#include "SimulatorJNI.h"
@@ -25,8 +24,7 @@
SIM_JniHandle, SpiReadAutoReceiveBufferCallbackStore,
hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
-namespace hal {
-namespace sim {
+namespace hal::sim {
void InitializeSpiBufferStore() {
static hal::UnlimitedHandleResource<SIM_JniHandle,
SpiReadAutoReceiveBufferCallbackStore,
@@ -34,8 +32,7 @@
cb;
callbackHandles = &cb;
}
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim
void SpiReadAutoReceiveBufferCallbackStore::create(JNIEnv* env, jobject obj) {
m_call = JGlobal<jobject>(env, obj);
@@ -52,21 +49,21 @@
didAttachThread = true;
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
// Failed to attach, log and return
- wpi::outs() << "Failed to attach\n";
- wpi::outs().flush();
+ std::puts("Failed to attach");
+ std::fflush(stdout);
return -1;
}
} else if (tryGetEnv == JNI_EVERSION) {
- wpi::outs() << "Invalid JVM Version requested\n";
- wpi::outs().flush();
+ std::puts("Invalid JVM Version requested");
+ std::fflush(stdout);
}
auto toCallbackArr = MakeJIntArray(
- env, wpi::ArrayRef<uint32_t>{buffer, static_cast<size_t>(numToRead)});
+ env, wpi::span<const uint32_t>{buffer, static_cast<size_t>(numToRead)});
jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
MakeJString(env, name), toCallbackArr,
- (jint)numToRead);
+ static_cast<jint>(numToRead));
jint* fromCallbackArr = reinterpret_cast<jint*>(
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));
@@ -113,7 +110,9 @@
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
auto data = callbackHandles->Get(handle);
- if (!data) return;
+ if (!data) {
+ return;
+ }
*outputCount = data->performCallback(name, buffer, numToRead);
};
diff --git a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.h b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.h
index 6a457de..18e8a44 100644
--- a/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.h
+++ b/hal/src/main/native/cpp/jni/simulation/SpiReadAutoReceiveBufferCallbackStore.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -18,8 +15,7 @@
#include "hal/simulation/NotifyListener.h"
#include "hal/simulation/SPIData.h"
-namespace hal {
-namespace sim {
+namespace hal::sim {
class SpiReadAutoReceiveBufferCallbackStore {
public:
void create(JNIEnv* env, jobject obj);
@@ -36,14 +32,13 @@
void InitializeSpiBufferStore();
-typedef int32_t (*RegisterSpiBufferCallbackFunc)(
+using RegisterSpiBufferCallbackFunc = int32_t (*)(
int32_t index, HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
-typedef void (*FreeSpiBufferCallbackFunc)(int32_t index, int32_t uid);
+using FreeSpiBufferCallbackFunc = void (*)(int32_t index, int32_t uid);
SIM_JniHandle AllocateSpiBufferCallback(
JNIEnv* env, jint index, jobject callback,
RegisterSpiBufferCallbackFunc createCallback);
void FreeSpiBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
FreeSpiBufferCallbackFunc freeCallback);
-} // namespace sim
-} // namespace hal
+} // namespace hal::sim