[hal] Consistently use .hpp for C++ header content

Some headers were renamed, but others were split.
This commit is contained in:
Peter Johnson
2026-01-04 00:41:53 -08:00
parent ab45819f6f
commit a7f71c9434
309 changed files with 1762 additions and 1744 deletions

View File

@@ -2,7 +2,7 @@
// 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 "wpi/hal/UsageReporting.h"
#include "wpi/hal/UsageReporting.hpp"
#include <fmt/format.h>

View File

@@ -2,7 +2,7 @@
// 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 "wpi/hal/cpp/fpga_clock.h"
#include "wpi/hal/cpp/fpga_clock.hpp"
#include <cstdio>
#include <limits>

View File

@@ -2,7 +2,7 @@
// 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 "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include <algorithm>

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_AddressableLEDJNI.h"
#include "wpi/hal/AddressableLED.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -7,7 +7,7 @@
#include <cassert>
#include <cstdio>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_AlertJNI.h"
#include "wpi/hal/Alert.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -6,11 +6,11 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_AnalogJNI.h"
#include "wpi/hal/AnalogInput.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_CANAPIJNI.h"
#include "wpi/hal/CAN.h"
#include "wpi/hal/CANAPI.h"

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_can_CANJNI.h"
#include "wpi/hal/CAN.h"
#include "wpi/hal/Errors.h"

View File

@@ -4,11 +4,11 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_CTREPCMJNI.h"
#include "wpi/hal/CTREPCM.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_ConstantsJNI.h"
#include "wpi/hal/Constants.h"

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_CounterJNI.h"
#include "wpi/hal/Counter.h"
#include "wpi/hal/Errors.h"

View File

@@ -6,12 +6,12 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_DIOJNI.h"
#include "wpi/hal/DIO.h"
#include "wpi/hal/PWM.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -10,7 +10,7 @@
#include <fmt/format.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_DriverStationJNI.h"
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/HALBase.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_DutyCycleJNI.h"
#include "wpi/hal/DutyCycle.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_EncoderJNI.h"
#include "wpi/hal/Encoder.h"
#include "wpi/hal/Errors.h"

View File

@@ -15,7 +15,7 @@
#include <fmt/format.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_HAL.h"
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/Main.h"

View File

@@ -2,7 +2,7 @@
// 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"
#include "HALUtil.hpp"
#include <jni.h>

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_I2CJNI.h"
#include "wpi/hal/I2C.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -8,7 +8,7 @@
#include <fmt/format.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_IMUJNI.h"
#include "wpi/hal/IMU.h"

View File

@@ -7,7 +7,7 @@
#include <cassert>
#include <cstdio>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_NotifierJNI.h"
#include "wpi/hal/Notifier.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -6,12 +6,12 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_PWMJNI.h"
#include "wpi/hal/DIO.h"
#include "wpi/hal/PWM.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_PortsJNI.h"
#include "wpi/hal/Ports.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_PowerDistributionJNI.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/PowerDistribution.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_PowerJNI.h"
#include "wpi/hal/Power.h"

View File

@@ -4,11 +4,11 @@
#include <jni.h>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_REVPHJNI.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/REVPH.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/jni_util.hpp"
static_assert(

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_SerialPortJNI.h"
#include "wpi/hal/SerialPort.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -7,9 +7,9 @@
#include <string>
#include <vector>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_SimDeviceJNI.h"
#include "wpi/hal/SimDevice.h"
#include "wpi/hal/SimDevice.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::util::java;

View File

@@ -6,7 +6,7 @@
#include <cassert>
#include "HALUtil.h"
#include "HALUtil.hpp"
#include "org_wpilib_hardware_hal_ThreadsJNI.h"
#include "wpi/hal/Threads.h"

View File

@@ -6,8 +6,8 @@
#include <memory>
#include "CallbackStore.h"
#include "ConstBufferCallbackStore.h"
#include "CallbackStore.hpp"
#include "ConstBufferCallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_AddressableLEDDataJNI.h"
#include "wpi/hal/simulation/AddressableLEDData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_AnalogInDataJNI.h"
#include "wpi/hal/simulation/AnalogInData.h"

View File

@@ -2,16 +2,16 @@
// 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 "BufferCallbackStore.hpp"
#include <jni.h>
#include <cstdio>
#include <memory>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,10 +6,10 @@
#include <jni.h>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/NotifyListener.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_CTREPCMDataJNI.h"
#include "wpi/hal/simulation/CTREPCMData.h"

View File

@@ -2,17 +2,17 @@
// 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 "CallbackStore.hpp"
#include <jni.h>
#include <cstdio>
#include <memory>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,10 +6,10 @@
#include <jni.h>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/NotifyListener.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -2,16 +2,16 @@
// 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 "ConstBufferCallbackStore.hpp"
#include <jni.h>
#include <cstdio>
#include <memory>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,10 +6,10 @@
#include <jni.h>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/NotifyListener.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_DIODataJNI.h"
#include "wpi/hal/simulation/DIOData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_DigitalPWMDataJNI.h"
#include "wpi/hal/simulation/DigitalPWMData.h"

View File

@@ -4,10 +4,10 @@
#include <jni.h>
#include "../HALUtil.h"
#include "CallbackStore.h"
#include "OpModeOptionsCallbackStore.h"
#include "SimulatorJNI.h"
#include "../HALUtil.hpp"
#include "CallbackStore.hpp"
#include "OpModeOptionsCallbackStore.hpp"
#include "SimulatorJNI.hpp"
#include "org_wpilib_hardware_hal_simulation_DriverStationDataJNI.h"
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/hal/simulation/MockHooks.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_DutyCycleDataJNI.h"
#include "wpi/hal/simulation/DutyCycleData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_EncoderDataJNI.h"
#include "wpi/hal/simulation/EncoderData.h"

View File

@@ -4,9 +4,9 @@
#include <jni.h>
#include "BufferCallbackStore.h"
#include "CallbackStore.h"
#include "ConstBufferCallbackStore.h"
#include "BufferCallbackStore.hpp"
#include "CallbackStore.hpp"
#include "ConstBufferCallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_I2CDataJNI.h"
#include "wpi/hal/simulation/I2CData.h"

View File

@@ -2,17 +2,17 @@
// 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 "OpModeOptionsCallbackStore.h"
#include "OpModeOptionsCallbackStore.hpp"
#include <jni.h>
#include <cstdio>
#include <memory>
#include "../HALUtil.h"
#include "SimulatorJNI.h"
#include "../HALUtil.hpp"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::hal;

View File

@@ -6,7 +6,7 @@
#include <jni.h>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "wpi/hal/Types.h"
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_PWMDataJNI.h"
#include "wpi/hal/simulation/PWMData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_PowerDistributionDataJNI.h"
#include "wpi/hal/simulation/PowerDistributionData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_REVPHDataJNI.h"
#include "wpi/hal/simulation/REVPHData.h"

View File

@@ -4,7 +4,7 @@
#include <jni.h>
#include "CallbackStore.h"
#include "CallbackStore.hpp"
#include "org_wpilib_hardware_hal_simulation_RoboRioDataJNI.h"
#include "wpi/hal/simulation/RoboRioData.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -2,7 +2,7 @@
// 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 "SimDeviceDataJNI.hpp"
#include <jni.h>
@@ -12,9 +12,9 @@
#include <utility>
#include <vector>
#include "SimulatorJNI.h"
#include "SimulatorJNI.hpp"
#include "org_wpilib_hardware_hal_simulation_SimDeviceDataJNI.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/SimDeviceData.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -2,17 +2,17 @@
// 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"
#include "SimulatorJNI.hpp"
#include "AlertDataJNI.hpp"
#include "BufferCallbackStore.h"
#include "CallbackStore.h"
#include "ConstBufferCallbackStore.h"
#include "OpModeOptionsCallbackStore.h"
#include "SimDeviceDataJNI.h"
#include "BufferCallbackStore.hpp"
#include "CallbackStore.hpp"
#include "ConstBufferCallbackStore.hpp"
#include "OpModeOptionsCallbackStore.hpp"
#include "SimDeviceDataJNI.hpp"
#include "org_wpilib_hardware_hal_simulation_SimulatorJNI.h"
#include "wpi/hal/HAL.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/simulation/MockHooks.h"
#include "wpi/util/jni_util.hpp"

View File

@@ -305,19 +305,5 @@ void HAL_ObserveUserProgram(HAL_ControlWord word);
#ifdef __cplusplus
} // extern "C"
namespace wpi::hal {
inline ControlWord GetControlWord() {
HAL_ControlWord word;
HAL_GetControlWord(&word);
return ControlWord{word};
}
inline ControlWord GetUncachedControlWord() {
HAL_ControlWord word;
HAL_GetUncachedControlWord(&word);
return ControlWord{word};
}
} // namespace wpi::hal
#endif
/** @} */

View File

@@ -0,0 +1,22 @@
// 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 "wpi/hal/DriverStation.h"
#include "wpi/hal/DriverStationTypes.hpp"
namespace wpi::hal {
inline ControlWord GetControlWord() {
HAL_ControlWord word;
HAL_GetControlWord(&word);
return ControlWord{word};
}
inline ControlWord GetUncachedControlWord() {
HAL_ControlWord word;
HAL_GetUncachedControlWord(&word);
return ControlWord{word};
}
} // namespace wpi::hal

View File

@@ -9,10 +9,6 @@
#include "wpi/hal/Types.h"
#include "wpi/util/string.h"
#ifdef __cplusplus
#include "wpi/util/struct/Struct.hpp"
#endif // __cplusplus
/**
* @defgroup hal_driverstation Driver Station Functions
* @ingroup hal_capi
@@ -190,7 +186,7 @@ typedef struct HAL_OpModeOption HAL_OpModeOption;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#endif
inline HAL_ControlWord HAL_MakeControlWord(int64_t opModeHash,
HAL_RobotMode robotMode,
@@ -277,235 +273,6 @@ inline int64_t HAL_OpMode_GetHash(int64_t id) {
}
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif
/** @} */
#ifdef __cplusplus
namespace wpi::hal {
/**
* The overall robot mode (not including enabled state).
*/
enum class RobotMode {
/// Unknown.
UNKNOWN = HAL_ROBOTMODE_UNKNOWN,
/// Autonomous.
AUTONOMOUS = HAL_ROBOTMODE_AUTONOMOUS,
/// Qualification.
TELEOPERATED = HAL_ROBOTMODE_TELEOPERATED,
/// Elimination.
TEST = HAL_ROBOTMODE_TEST
};
/**
* A wrapper around Driver Station control word.
*/
class ControlWord {
public:
/**
* Default constructor.
*/
ControlWord() = default;
/**
* Constructs from state values.
*
* @param opModeHash opmode hash
* @param robotMode robot mode
* @param enabled enabled
* @param eStop emergency stopped
* @param fmsAttached FMS attached
* @param dsAttached DS attached
*/
ControlWord(int64_t opModeHash, RobotMode robotMode, bool enabled, bool eStop,
bool fmsAttached, bool dsAttached)
: m_word{HAL_MakeControlWord(opModeHash,
static_cast<HAL_RobotMode>(robotMode),
enabled, eStop, fmsAttached, dsAttached)} {}
/**
* Constructs from the native HAL value.
*
* @param word value
*/
explicit ControlWord(HAL_ControlWord word) : m_word{word} {}
ControlWord(const ControlWord&) = default;
ControlWord& operator=(const ControlWord&) = default;
/**
* Updates from state values.
*
* @param opModeHash opmode hash
* @param robotMode robot mode
* @param enabled enabled
* @param eStop emergency stopped
* @param fmsAttached FMS attached
* @param dsAttached DS attached
*/
void Update(int64_t opModeHash, RobotMode robotMode, bool enabled, bool eStop,
bool fmsAttached, bool dsAttached) {
m_word =
HAL_MakeControlWord(opModeHash, static_cast<HAL_RobotMode>(robotMode),
enabled, eStop, fmsAttached, dsAttached);
}
/**
* Updates from the native HAL value.
*
* @param word value
*/
void Update(HAL_ControlWord word) { m_word = word; }
/**
* Check if the DS has enabled the robot.
*
* @return True if the robot is enabled and the DS is connected
*/
bool IsEnabled() const { return HAL_ControlWord_IsEnabled(m_word); }
/**
* Gets the current robot mode.
*
* <p>Note that this does not indicate whether the robot is enabled or
* disabled.
*
* @return robot mode
*/
RobotMode GetRobotMode() const {
return static_cast<RobotMode>(HAL_ControlWord_GetRobotMode(m_word));
}
/**
* Gets the current opmode ID.
*
* @return opmode
*/
int64_t GetOpModeId() const { return HAL_ControlWord_GetOpModeId(m_word); }
/**
* Sets the opmode ID.
*
* @param id opmode ID
*/
void SetOpModeId(int64_t id) { HAL_ControlWord_SetOpModeId(&m_word, id); }
/**
* Check if the robot is e-stopped.
*
* @return True if the robot is e-stopped
*/
bool IsEStopped() const { return HAL_ControlWord_IsEStopped(m_word); }
/**
* Is the driver station attached to a Field Management System?
*
* @return True if the robot is competing on a field being controlled by a
* Field Management System
*/
bool IsFMSAttached() const { return HAL_ControlWord_IsFMSAttached(m_word); }
/**
* Check if the DS is attached.
*
* @return True if the DS is connected to the robot
*/
bool IsDSAttached() const { return HAL_ControlWord_IsDSAttached(m_word); }
/**
* Check if the DS is commanding autonomous mode.
*
* @return True if the robot is being commanded to be in autonomous mode
*/
bool IsAutonomous() const { return GetRobotMode() == RobotMode::AUTONOMOUS; }
/**
* Check if the DS is commanding autonomous mode and if it has enabled the
* robot.
*
* @return True if the robot is being commanded to be in autonomous mode and
* enabled.
*/
bool IsAutonomousEnabled() const {
return IsAutonomous() && IsEnabled() && IsDSAttached();
}
/**
* Check if the DS is commanding teleop mode.
*
* @return True if the robot is being commanded to be in teleop mode
*/
bool IsTeleop() const { return GetRobotMode() == RobotMode::TELEOPERATED; }
/**
* Check if the DS is commanding teleop mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in teleop mode and
* enabled.
*/
bool IsTeleopEnabled() const {
return IsTeleop() && IsEnabled() && IsDSAttached();
}
/**
* Check if the DS is commanding test mode.
*
* @return True if the robot is being commanded to be in test mode
*/
bool IsTest() const { return GetRobotMode() == RobotMode::TEST; }
/**
* Check if the DS is commanding test mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in test mode and
* enabled.
*/
bool IsTestEnabled() const {
return IsTest() && IsEnabled() && IsDSAttached();
}
/**
* Get the HAL raw value.
*
* @return Control word value
*/
HAL_ControlWord GetValue() const { return m_word; }
private:
HAL_ControlWord m_word{.value = 0};
};
inline bool operator==(const ControlWord& lhs, const ControlWord& rhs) {
return lhs.GetValue().value == rhs.GetValue().value;
}
inline bool operator!=(const ControlWord& lhs, const ControlWord& rhs) {
return !(lhs == rhs);
}
} // namespace wpi::hal
template <>
struct wpi::util::Struct<wpi::hal::ControlWord> {
static constexpr std::string_view GetTypeName() { return "ControlWord"; }
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() {
return "uint64 opModeHash:56;"
"enum{unknown=0,autonomous=1,teleoperated=2,test=3}"
"uint64 robotMode:2;"
"bool enabled:1;bool eStop:1;bool fmsAttached:1;bool dsAttached:1;";
}
static inline wpi::hal::ControlWord Unpack(std::span<const uint8_t> data) {
return wpi::hal::ControlWord{
{.value = wpi::util::UnpackStruct<int64_t>(data)}};
}
static inline void Pack(std::span<uint8_t> data,
wpi::hal::ControlWord value) {
wpi::util::PackStruct(data, value.GetValue().value);
}
};
static_assert(wpi::util::StructSerializable<wpi::hal::ControlWord>);
#endif // __cplusplus

View File

@@ -0,0 +1,235 @@
// 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 "wpi/hal/DriverStationTypes.h"
#include "wpi/util/struct/Struct.hpp"
namespace wpi::hal {
/**
* The overall robot mode (not including enabled state).
*/
enum class RobotMode {
/// Unknown.
UNKNOWN = HAL_ROBOTMODE_UNKNOWN,
/// Autonomous.
AUTONOMOUS = HAL_ROBOTMODE_AUTONOMOUS,
/// Teleoperated.
TELEOPERATED = HAL_ROBOTMODE_TELEOPERATED,
/// Test.
TEST = HAL_ROBOTMODE_TEST
};
/**
* A wrapper around Driver Station control word.
*/
class ControlWord {
public:
/**
* Default constructor.
*/
ControlWord() = default;
/**
* Constructs from state values.
*
* @param opModeHash opmode hash
* @param robotMode robot mode
* @param enabled enabled
* @param eStop emergency stopped
* @param fmsAttached FMS attached
* @param dsAttached DS attached
*/
ControlWord(int64_t opModeHash, RobotMode robotMode, bool enabled, bool eStop,
bool fmsAttached, bool dsAttached)
: m_word{HAL_MakeControlWord(opModeHash,
static_cast<HAL_RobotMode>(robotMode),
enabled, eStop, fmsAttached, dsAttached)} {}
/**
* Constructs from the native HAL value.
*
* @param word value
*/
explicit ControlWord(HAL_ControlWord word) : m_word{word} {}
ControlWord(const ControlWord&) = default;
ControlWord& operator=(const ControlWord&) = default;
/**
* Updates from state values.
*
* @param opModeHash opmode hash
* @param robotMode robot mode
* @param enabled enabled
* @param eStop emergency stopped
* @param fmsAttached FMS attached
* @param dsAttached DS attached
*/
void Update(int64_t opModeHash, RobotMode robotMode, bool enabled, bool eStop,
bool fmsAttached, bool dsAttached) {
m_word =
HAL_MakeControlWord(opModeHash, static_cast<HAL_RobotMode>(robotMode),
enabled, eStop, fmsAttached, dsAttached);
}
/**
* Updates from the native HAL value.
*
* @param word value
*/
void Update(HAL_ControlWord word) { m_word = word; }
/**
* Check if the DS has enabled the robot.
*
* @return True if the robot is enabled and the DS is connected
*/
bool IsEnabled() const { return HAL_ControlWord_IsEnabled(m_word); }
/**
* Gets the current robot mode.
*
* <p>Note that this does not indicate whether the robot is enabled or
* disabled.
*
* @return robot mode
*/
RobotMode GetRobotMode() const {
return static_cast<RobotMode>(HAL_ControlWord_GetRobotMode(m_word));
}
/**
* Gets the current opmode ID.
*
* @return opmode
*/
int64_t GetOpModeId() const { return HAL_ControlWord_GetOpModeId(m_word); }
/**
* Sets the opmode ID.
*
* @param id opmode ID
*/
void SetOpModeId(int64_t id) { HAL_ControlWord_SetOpModeId(&m_word, id); }
/**
* Check if the robot is e-stopped.
*
* @return True if the robot is e-stopped
*/
bool IsEStopped() const { return HAL_ControlWord_IsEStopped(m_word); }
/**
* Is the driver station attached to a Field Management System?
*
* @return True if the robot is competing on a field being controlled by a
* Field Management System
*/
bool IsFMSAttached() const { return HAL_ControlWord_IsFMSAttached(m_word); }
/**
* Check if the DS is attached.
*
* @return True if the DS is connected to the robot
*/
bool IsDSAttached() const { return HAL_ControlWord_IsDSAttached(m_word); }
/**
* Check if the DS is commanding autonomous mode.
*
* @return True if the robot is being commanded to be in autonomous mode
*/
bool IsAutonomous() const { return GetRobotMode() == RobotMode::AUTONOMOUS; }
/**
* Check if the DS is commanding autonomous mode and if it has enabled the
* robot.
*
* @return True if the robot is being commanded to be in autonomous mode and
* enabled.
*/
bool IsAutonomousEnabled() const {
return IsAutonomous() && IsEnabled() && IsDSAttached();
}
/**
* Check if the DS is commanding teleop mode.
*
* @return True if the robot is being commanded to be in teleop mode
*/
bool IsTeleop() const { return GetRobotMode() == RobotMode::TELEOPERATED; }
/**
* Check if the DS is commanding teleop mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in teleop mode and
* enabled.
*/
bool IsTeleopEnabled() const {
return IsTeleop() && IsEnabled() && IsDSAttached();
}
/**
* Check if the DS is commanding test mode.
*
* @return True if the robot is being commanded to be in test mode
*/
bool IsTest() const { return GetRobotMode() == RobotMode::TEST; }
/**
* Check if the DS is commanding test mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in test mode and
* enabled.
*/
bool IsTestEnabled() const {
return IsTest() && IsEnabled() && IsDSAttached();
}
/**
* Get the HAL raw value.
*
* @return Control word value
*/
HAL_ControlWord GetValue() const { return m_word; }
private:
HAL_ControlWord m_word{.value = 0};
};
inline bool operator==(const ControlWord& lhs, const ControlWord& rhs) {
return lhs.GetValue().value == rhs.GetValue().value;
}
inline bool operator!=(const ControlWord& lhs, const ControlWord& rhs) {
return !(lhs == rhs);
}
} // namespace wpi::hal
template <>
struct wpi::util::Struct<wpi::hal::ControlWord> {
static constexpr std::string_view GetTypeName() { return "ControlWord"; }
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() {
return "uint64 opModeHash:56;"
"enum{unknown=0,autonomous=1,teleoperated=2,test=3}"
"uint64 robotMode:2;"
"bool enabled:1;bool eStop:1;bool fmsAttached:1;bool dsAttached:1;";
}
static inline wpi::hal::ControlWord Unpack(std::span<const uint8_t> data) {
return wpi::hal::ControlWord{
{.value = wpi::util::UnpackStruct<int64_t>(data)}};
}
static inline void Pack(std::span<uint8_t> data,
wpi::hal::ControlWord value) {
wpi::util::PackStruct(data, value.GetValue().value);
}
};
static_assert(wpi::util::StructSerializable<wpi::hal::ControlWord>);

View File

@@ -6,10 +6,6 @@
#include <stdint.h>
#ifdef __cplusplus
#include <string_view>
#endif
#include "wpi/hal/Types.h"
#include "wpi/util/string.h"
@@ -134,18 +130,3 @@ int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle,
} // extern "C"
#endif
/** @} */
#ifdef __cplusplus
/**
* Sets the name of a notifier.
*
* @param[in] notifierHandle the notifier handle
* @param[in] name name
* @param[out] status Error status variable. 0 on success.
*/
inline void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle,
std::string_view name, int32_t* status) {
WPI_String nameStr = wpi::util::make_string(name);
HAL_SetNotifierName(notifierHandle, &nameStr, status);
}
#endif

View File

@@ -0,0 +1,22 @@
// 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 <string_view>
#include "wpi/hal/Notifier.h"
/**
* Sets the name of a notifier.
*
* @param[in] notifierHandle the notifier handle
* @param[in] name name
* @param[out] status Error status variable. 0 on success.
*/
inline void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle,
std::string_view name, int32_t* status) {
WPI_String nameStr = wpi::util::make_string(name);
HAL_SetNotifierName(notifierHandle, &nameStr, status);
}

View File

@@ -6,12 +6,6 @@
#include <stdint.h>
#ifdef __cplusplus
#include <initializer_list>
#include <span>
#include <string>
#endif
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
@@ -92,17 +86,6 @@ HAL_SimValueHandle HAL_CreateSimValue(HAL_SimDeviceHandle device,
const char* name, int32_t direction,
const struct HAL_Value* initialValue);
#ifdef __cplusplus
extern "C++" {
inline HAL_SimValueHandle HAL_CreateSimValue(HAL_SimDeviceHandle device,
const char* name,
int32_t direction,
const HAL_Value& initialValue) {
return HAL_CreateSimValue(device, name, direction, &initialValue);
}
} // extern "C++"
#endif
/**
* Creates an int value on a simulated device.
*
@@ -235,16 +218,6 @@ inline HAL_SimValueHandle HAL_CreateSimValueBoolean(HAL_SimDeviceHandle device,
*/
void HAL_GetSimValue(HAL_SimValueHandle handle, struct HAL_Value* value);
#ifdef __cplusplus
extern "C++" {
inline HAL_Value HAL_GetSimValue(HAL_SimValueHandle handle) {
HAL_Value v;
HAL_GetSimValue(handle, &v);
return v;
}
} // extern "C++"
#endif
/**
* Gets a simulated value (int).
*
@@ -313,14 +286,6 @@ inline HAL_Bool HAL_GetSimValueBoolean(HAL_SimValueHandle handle) {
*/
void HAL_SetSimValue(HAL_SimValueHandle handle, const struct HAL_Value* value);
#ifdef __cplusplus
extern "C++" {
inline void HAL_SetSimValue(HAL_SimValueHandle handle, const HAL_Value& value) {
HAL_SetSimValue(handle, &value);
}
} // extern "C++"
#endif
/**
* Sets a simulated value (int).
*
@@ -392,557 +357,3 @@ void HAL_ResetSimValue(HAL_SimValueHandle handle);
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
namespace wpi::hal {
/**
* C++ wrapper around a HAL simulator value handle.
*/
class SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimValue() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValue().
*
* @param val simulated value handle
*/
/*implicit*/ SimValue(HAL_SimValueHandle val) // NOLINT
: m_handle(val) {}
/**
* Determine if handle is empty. Should be used to optimize out code paths
* that are taken/not taken in simulation.
*
* @return False if handle is empty, true if handle is valid.
*/
explicit operator bool() const { return m_handle != HAL_kInvalidHandle; }
/**
* Get the internal device handle.
*
* @return internal handle
*/
operator HAL_SimValueHandle() const { return m_handle; } // NOLINT
/**
* Gets the simulated value.
*
* @return The current value
*/
HAL_Value GetValue() const { return HAL_GetSimValue(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void SetValue(const HAL_Value& value) { HAL_SetSimValue(m_handle, value); }
protected:
HAL_SimValueHandle m_handle = HAL_kInvalidHandle;
};
/**
* C++ wrapper around a HAL simulator int value handle.
*/
class SimInt : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimInt() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueInt().
*
* @param val simulated value handle
*/
/*implicit*/ SimInt(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int32_t Get() const { return HAL_GetSimValueInt(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int32_t value) { HAL_SetSimValueInt(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator long value handle.
*/
class SimLong : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimLong() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueLong().
*
* @param val simulated value handle
*/
/*implicit*/ SimLong(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int64_t Get() const { return HAL_GetSimValueLong(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int64_t value) { HAL_SetSimValueLong(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator double value handle.
*/
class SimDouble : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimDouble() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueDouble().
*
* @param val simulated value handle
*/
/*implicit*/ SimDouble(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
double Get() const { return HAL_GetSimValueDouble(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(double value) { HAL_SetSimValueDouble(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator enum value handle.
*/
class SimEnum : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimEnum() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueEnum().
*
* @param val simulated value handle
*/
/*implicit*/ SimEnum(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int32_t Get() const { return HAL_GetSimValueEnum(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int32_t value) { HAL_SetSimValueEnum(m_handle, value); }
};
/**
* C++ wrapper around a HAL simulator boolean value handle.
*/
class SimBoolean : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimBoolean() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueBoolean().
*
* @param val simulated value handle
*/
/*implicit*/ SimBoolean(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
bool Get() const { return HAL_GetSimValueBoolean(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(bool value) { HAL_SetSimValueBoolean(m_handle, value); }
};
/**
* A move-only C++ wrapper around a HAL simulator device handle.
*/
class SimDevice {
public:
/**
* Direction of a simulated value (from the perspective of user code).
*/
enum Direction {
kInput = HAL_SimValueInput,
kOutput = HAL_SimValueOutput,
kBidir = HAL_SimValueBidir
};
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimDevice() = default;
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. If multiple instances of the same device are desired,
* recommend appending the instance/unique identifier in brackets to the base
* name, e.g. "device[1]".
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
*/
explicit SimDevice(const char* name) : m_handle(HAL_CreateSimDevice(name)) {}
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. This is a convenience method that appends index in
* brackets to the device name, e.g. passing index=1 results in "device[1]"
* for the device name.
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
* @param index device index number to append to name
*/
SimDevice(const char* name, int index);
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. This is a convenience method that appends index and
* channel in brackets to the device name, e.g. passing index=1 and channel=2
* results in "device[1,2]" for the device name.
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
* @param index device index number to append to name
* @param channel device channel number to append to name
*/
SimDevice(const char* name, int index, int channel);
~SimDevice() {
if (m_handle != HAL_kInvalidHandle) {
HAL_FreeSimDevice(m_handle);
}
}
SimDevice(const SimDevice&) = delete;
SimDevice& operator=(const SimDevice&) = delete;
SimDevice(SimDevice&& rhs) : m_handle(rhs.m_handle) {
rhs.m_handle = HAL_kInvalidHandle;
}
SimDevice& operator=(SimDevice&& rhs) {
m_handle = rhs.m_handle;
rhs.m_handle = HAL_kInvalidHandle;
return *this;
}
/**
* Determine if handle is empty. Should be used to optimize out code paths
* that are taken/not taken in simulation.
*
* @return False if handle is empty, true if handle is valid.
*/
explicit operator bool() const { return m_handle != HAL_kInvalidHandle; }
/**
* Get the internal device handle.
*
* @return internal handle
*/
operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT
/**
* Get the name of the simulated device.
*
* @return name
*/
std::string GetName() const {
return std::string(HAL_GetSimDeviceName(m_handle));
}
/**
* Creates a value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated value object
*/
SimValue CreateValue(const char* name, int32_t direction,
const HAL_Value& initialValue) {
return HAL_CreateSimValue(m_handle, name, direction, &initialValue);
}
/**
* Creates an int value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimInt CreateInt(const char* name, int32_t direction, int32_t initialValue) {
return HAL_CreateSimValueInt(m_handle, name, direction, initialValue);
}
/**
* Creates a long value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimLong CreateLong(const char* name, int32_t direction,
int64_t initialValue) {
return HAL_CreateSimValueLong(m_handle, name, direction, initialValue);
}
/**
* Creates a double value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimDouble CreateDouble(const char* name, int32_t direction,
double initialValue) {
return HAL_CreateSimValueDouble(m_handle, name, direction, initialValue);
}
/**
* Creates an enumerated value on the simulated device.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnum(const char* name, int32_t direction,
std::initializer_list<const char*> options,
int32_t initialValue) {
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
const_cast<const char**>(options.begin()),
initialValue);
}
/**
* Creates an enumerated value on the simulated device.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnum(const char* name, int32_t direction,
std::span<const char* const> options,
int32_t initialValue) {
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
const_cast<const char**>(options.data()),
initialValue);
}
/**
* Creates an enumerated value on the simulated device with double values.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param optionValues array of option values (must be the same size as
* options)
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnumDouble(const char* name, int32_t direction,
std::initializer_list<const char*> options,
std::initializer_list<double> optionValues,
int32_t initialValue) {
if (options.size() != optionValues.size()) {
return {};
}
return HAL_CreateSimValueEnumDouble(
m_handle, name, direction, options.size(),
const_cast<const char**>(options.begin()), optionValues.begin(),
initialValue);
}
/**
* Creates an enumerated value on the simulated device with double values.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param optionValues array of option values (must be the same size as
* options)
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnumDouble(const char* name, int32_t direction,
std::span<const char* const> options,
std::span<const double> optionValues,
int32_t initialValue) {
if (options.size() != optionValues.size()) {
return {};
}
return HAL_CreateSimValueEnumDouble(
m_handle, name, direction, options.size(),
const_cast<const char**>(options.data()), optionValues.data(),
initialValue);
}
/**
* Creates a boolean value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated boolean value object
*/
SimBoolean CreateBoolean(const char* name, int32_t direction,
bool initialValue) {
return HAL_CreateSimValueBoolean(m_handle, name, direction, initialValue);
}
protected:
HAL_SimDeviceHandle m_handle = HAL_kInvalidHandle;
};
} // namespace wpi::hal
#endif // __cplusplus

View File

@@ -0,0 +1,580 @@
// 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 <initializer_list>
#include <span>
#include <string>
#include "wpi/hal/SimDevice.h"
inline HAL_SimValueHandle HAL_CreateSimValue(HAL_SimDeviceHandle device,
const char* name,
int32_t direction,
const HAL_Value& initialValue) {
return HAL_CreateSimValue(device, name, direction, &initialValue);
}
inline HAL_Value HAL_GetSimValue(HAL_SimValueHandle handle) {
HAL_Value v;
HAL_GetSimValue(handle, &v);
return v;
}
inline void HAL_SetSimValue(HAL_SimValueHandle handle, const HAL_Value& value) {
HAL_SetSimValue(handle, &value);
}
namespace wpi::hal {
/**
* C++ wrapper around a HAL simulator value handle.
*/
class SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimValue() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValue().
*
* @param val simulated value handle
*/
/*implicit*/ SimValue(HAL_SimValueHandle val) // NOLINT
: m_handle(val) {}
/**
* Determine if handle is empty. Should be used to optimize out code paths
* that are taken/not taken in simulation.
*
* @return False if handle is empty, true if handle is valid.
*/
explicit operator bool() const { return m_handle != HAL_kInvalidHandle; }
/**
* Get the internal device handle.
*
* @return internal handle
*/
operator HAL_SimValueHandle() const { return m_handle; } // NOLINT
/**
* Gets the simulated value.
*
* @return The current value
*/
HAL_Value GetValue() const { return HAL_GetSimValue(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void SetValue(const HAL_Value& value) { HAL_SetSimValue(m_handle, value); }
protected:
HAL_SimValueHandle m_handle = HAL_kInvalidHandle;
};
/**
* C++ wrapper around a HAL simulator int value handle.
*/
class SimInt : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimInt() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueInt().
*
* @param val simulated value handle
*/
/*implicit*/ SimInt(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int32_t Get() const { return HAL_GetSimValueInt(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int32_t value) { HAL_SetSimValueInt(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator long value handle.
*/
class SimLong : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimLong() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueLong().
*
* @param val simulated value handle
*/
/*implicit*/ SimLong(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int64_t Get() const { return HAL_GetSimValueLong(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int64_t value) { HAL_SetSimValueLong(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator double value handle.
*/
class SimDouble : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimDouble() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueDouble().
*
* @param val simulated value handle
*/
/*implicit*/ SimDouble(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
double Get() const { return HAL_GetSimValueDouble(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(double value) { HAL_SetSimValueDouble(m_handle, value); }
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting
* incremental sensor values like encoder counts or gyro accumulated angle
* to ensure correct behavior in a distributed system (e.g. WebSockets).
*/
void Reset() { HAL_ResetSimValue(m_handle); }
};
/**
* C++ wrapper around a HAL simulator enum value handle.
*/
class SimEnum : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimEnum() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueEnum().
*
* @param val simulated value handle
*/
/*implicit*/ SimEnum(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
int32_t Get() const { return HAL_GetSimValueEnum(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(int32_t value) { HAL_SetSimValueEnum(m_handle, value); }
};
/**
* C++ wrapper around a HAL simulator boolean value handle.
*/
class SimBoolean : public SimValue {
public:
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimBoolean() = default;
/**
* Wraps a simulated value handle as returned by HAL_CreateSimValueBoolean().
*
* @param val simulated value handle
*/
/*implicit*/ SimBoolean(HAL_SimValueHandle val) // NOLINT
: SimValue(val) {}
/**
* Gets the simulated value.
*
* @return The current value
*/
bool Get() const { return HAL_GetSimValueBoolean(m_handle); }
/**
* Sets the simulated value.
*
* @param value the value to set
*/
void Set(bool value) { HAL_SetSimValueBoolean(m_handle, value); }
};
/**
* A move-only C++ wrapper around a HAL simulator device handle.
*/
class SimDevice {
public:
/**
* Direction of a simulated value (from the perspective of user code).
*/
enum Direction {
kInput = HAL_SimValueInput,
kOutput = HAL_SimValueOutput,
kBidir = HAL_SimValueBidir
};
/**
* Default constructor that results in an "empty" object that is false in
* a boolean context.
*/
SimDevice() = default;
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. If multiple instances of the same device are desired,
* recommend appending the instance/unique identifier in brackets to the base
* name, e.g. "device[1]".
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
*/
explicit SimDevice(const char* name) : m_handle(HAL_CreateSimDevice(name)) {}
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. This is a convenience method that appends index in
* brackets to the device name, e.g. passing index=1 results in "device[1]"
* for the device name.
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
* @param index device index number to append to name
*/
SimDevice(const char* name, int index);
/**
* Creates a simulated device.
*
* The device name must be unique. Returns null if the device name
* already exists. This is a convenience method that appends index and
* channel in brackets to the device name, e.g. passing index=1 and channel=2
* results in "device[1,2]" for the device name.
*
* Using a device name of the form "Type:Name" will create a WebSockets node
* with a type value of "Type" and a device value of "Name"
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name device name
* @param index device index number to append to name
* @param channel device channel number to append to name
*/
SimDevice(const char* name, int index, int channel);
~SimDevice() {
if (m_handle != HAL_kInvalidHandle) {
HAL_FreeSimDevice(m_handle);
}
}
SimDevice(const SimDevice&) = delete;
SimDevice& operator=(const SimDevice&) = delete;
SimDevice(SimDevice&& rhs) : m_handle(rhs.m_handle) {
rhs.m_handle = HAL_kInvalidHandle;
}
SimDevice& operator=(SimDevice&& rhs) {
m_handle = rhs.m_handle;
rhs.m_handle = HAL_kInvalidHandle;
return *this;
}
/**
* Determine if handle is empty. Should be used to optimize out code paths
* that are taken/not taken in simulation.
*
* @return False if handle is empty, true if handle is valid.
*/
explicit operator bool() const { return m_handle != HAL_kInvalidHandle; }
/**
* Get the internal device handle.
*
* @return internal handle
*/
operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT
/**
* Get the name of the simulated device.
*
* @return name
*/
std::string GetName() const {
return std::string(HAL_GetSimDeviceName(m_handle));
}
/**
* Creates a value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated value object
*/
SimValue CreateValue(const char* name, int32_t direction,
const HAL_Value& initialValue) {
return HAL_CreateSimValue(m_handle, name, direction, &initialValue);
}
/**
* Creates an int value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimInt CreateInt(const char* name, int32_t direction, int32_t initialValue) {
return HAL_CreateSimValueInt(m_handle, name, direction, initialValue);
}
/**
* Creates a long value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimLong CreateLong(const char* name, int32_t direction,
int64_t initialValue) {
return HAL_CreateSimValueLong(m_handle, name, direction, initialValue);
}
/**
* Creates a double value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated double value object
*/
SimDouble CreateDouble(const char* name, int32_t direction,
double initialValue) {
return HAL_CreateSimValueDouble(m_handle, name, direction, initialValue);
}
/**
* Creates an enumerated value on the simulated device.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnum(const char* name, int32_t direction,
std::initializer_list<const char*> options,
int32_t initialValue) {
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
const_cast<const char**>(options.begin()),
initialValue);
}
/**
* Creates an enumerated value on the simulated device.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnum(const char* name, int32_t direction,
std::span<const char* const> options,
int32_t initialValue) {
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
const_cast<const char**>(options.data()),
initialValue);
}
/**
* Creates an enumerated value on the simulated device with double values.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param optionValues array of option values (must be the same size as
* options)
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnumDouble(const char* name, int32_t direction,
std::initializer_list<const char*> options,
std::initializer_list<double> optionValues,
int32_t initialValue) {
if (options.size() != optionValues.size()) {
return {};
}
return HAL_CreateSimValueEnumDouble(
m_handle, name, direction, options.size(),
const_cast<const char**>(options.begin()), optionValues.begin(),
initialValue);
}
/**
* Creates an enumerated value on the simulated device with double values.
*
* Enumerated values are always in the range 0 to numOptions-1.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param options array of option descriptions
* @param optionValues array of option values (must be the same size as
* options)
* @param initialValue initial value (selection)
* @return simulated enum value object
*/
SimEnum CreateEnumDouble(const char* name, int32_t direction,
std::span<const char* const> options,
std::span<const double> optionValues,
int32_t initialValue) {
if (options.size() != optionValues.size()) {
return {};
}
return HAL_CreateSimValueEnumDouble(
m_handle, name, direction, options.size(),
const_cast<const char**>(options.data()), optionValues.data(),
initialValue);
}
/**
* Creates a boolean value on the simulated device.
*
* If not in simulation, results in an "empty" object that evaluates to false
* in a boolean context.
*
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated boolean value object
*/
SimBoolean CreateBoolean(const char* name, int32_t direction,
bool initialValue) {
return HAL_CreateSimValueBoolean(m_handle, name, direction, initialValue);
}
protected:
HAL_SimDeviceHandle m_handle = HAL_kInvalidHandle;
};
} // namespace wpi::hal

View File

@@ -89,75 +89,4 @@ typedef int32_t HAL_Bool;
#define HAL_ENUM(name) HAL_ENUM_WITH_UNDERLYING_TYPE(name, int32_t)
#ifdef __cplusplus
namespace wpi::hal {
/**
* A move-only C++ wrapper around a HAL handle.
* Will free the handle if FreeFunction is provided
*/
template <typename CType, void (*FreeFunction)(CType) = nullptr,
int32_t CInvalid = HAL_kInvalidHandle>
class Handle {
public:
Handle() = default;
/*implicit*/ Handle(CType val) : m_handle(val) {} // NOLINT
Handle(const Handle&) = delete;
Handle& operator=(const Handle&) = delete;
Handle(Handle&& rhs) : m_handle(rhs.m_handle) { rhs.m_handle = CInvalid; }
Handle& operator=(Handle&& rhs) {
if (this != &rhs) {
// FIXME: GCC gives the false positive "the address of <GetDefault> will never
// be NULL" because it doesn't realize the default template parameter can make
// GetDefault nullptr. Fixed in GCC 13.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105885
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
#endif // __GNUC__
if constexpr (FreeFunction != nullptr) {
#if __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
if (m_handle != CInvalid) {
FreeFunction(m_handle);
}
}
}
m_handle = rhs.m_handle;
rhs.m_handle = CInvalid;
return *this;
}
~Handle() {
// FIXME: GCC gives the false positive "the address of <GetDefault> will never
// be NULL" because it doesn't realize the default template parameter can make
// GetDefault nullptr. Fixed in GCC 13.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105885
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
#endif // __GNUC__
if constexpr (FreeFunction != nullptr) {
#if __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
if (m_handle != CInvalid) {
FreeFunction(m_handle);
}
}
}
operator CType() const { return m_handle; } // NOLINT
private:
CType m_handle = CInvalid;
};
} // namespace wpi::hal
#endif
/** @} */

View File

@@ -0,0 +1,77 @@
// 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 "wpi/hal/Types.h"
namespace wpi::hal {
/**
* A move-only C++ wrapper around a HAL handle.
* Will free the handle if FreeFunction is provided
*/
template <typename CType, void (*FreeFunction)(CType) = nullptr,
int32_t CInvalid = HAL_kInvalidHandle>
class Handle {
public:
Handle() = default;
/*implicit*/ Handle(CType val) : m_handle(val) {} // NOLINT
Handle(const Handle&) = delete;
Handle& operator=(const Handle&) = delete;
Handle(Handle&& rhs) : m_handle(rhs.m_handle) { rhs.m_handle = CInvalid; }
Handle& operator=(Handle&& rhs) {
if (this != &rhs) {
// FIXME: GCC gives the false positive "the address of <GetDefault> will never
// be NULL" because it doesn't realize the default template parameter can make
// GetDefault nullptr. Fixed in GCC 13.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105885
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
#endif // __GNUC__
if constexpr (FreeFunction != nullptr) {
#if __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
if (m_handle != CInvalid) {
FreeFunction(m_handle);
}
}
}
m_handle = rhs.m_handle;
rhs.m_handle = CInvalid;
return *this;
}
~Handle() {
// FIXME: GCC gives the false positive "the address of <GetDefault> will never
// be NULL" because it doesn't realize the default template parameter can make
// GetDefault nullptr. Fixed in GCC 13.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105885
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
#endif // __GNUC__
if constexpr (FreeFunction != nullptr) {
#if __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
if (m_handle != CInvalid) {
FreeFunction(m_handle);
}
}
}
operator CType() const { return m_handle; } // NOLINT
private:
CType m_handle = CInvalid;
};
} // namespace wpi::hal

View File

@@ -6,10 +6,6 @@
#include <stdint.h>
#ifdef __cplusplus
#include <string_view>
#endif
#include "wpi/util/string.h"
#ifdef __cplusplus
@@ -31,32 +27,3 @@ void HAL_ReportUsage(const struct WPI_String* resource,
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
/**
* Reports usage of a resource of interest. Repeated calls for the same
* resource name replace the previous report.
*
* @param resource the used resource name; convention is to suffix with
* "[instanceNum]" for multiple instances of the same
* resource
* @param data arbitrary associated data string
*/
inline void HAL_ReportUsage(std::string_view resource, std::string_view data) {
WPI_String resourceStr = wpi::util::make_string(resource);
WPI_String dataStr = wpi::util::make_string(data);
HAL_ReportUsage(&resourceStr, &dataStr);
}
/**
* Reports usage of a resource of interest. Repeated calls for the same
* resource name replace the previous report.
*
* @param resource the used resource name
* @param instanceNumber an index that identifies the resource instance
* @param data arbitrary associated data string
*/
void HAL_ReportUsage(std::string_view resource, int instanceNumber,
std::string_view data);
#endif

View File

@@ -0,0 +1,35 @@
// 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 <string_view>
#include "wpi/hal/UsageReporting.h"
/**
* Reports usage of a resource of interest. Repeated calls for the same
* resource name replace the previous report.
*
* @param resource the used resource name; convention is to suffix with
* "[instanceNum]" for multiple instances of the same
* resource
* @param data arbitrary associated data string
*/
inline void HAL_ReportUsage(std::string_view resource, std::string_view data) {
WPI_String resourceStr = wpi::util::make_string(resource);
WPI_String dataStr = wpi::util::make_string(data);
HAL_ReportUsage(&resourceStr, &dataStr);
}
/**
* Reports usage of a resource of interest. Repeated calls for the same
* resource name replace the previous report.
*
* @param resource the used resource name
* @param instanceNumber an index that identifies the resource instance
* @param data arbitrary associated data string
*/
void HAL_ReportUsage(std::string_view resource, int instanceNumber,
std::string_view data);

View File

@@ -11,7 +11,7 @@
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -8,11 +8,10 @@
#include <array>
#include <memory>
#include <vector>
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -11,7 +11,7 @@
#include "wpi/hal/Errors.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -10,7 +10,7 @@
#include <memory>
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -9,8 +9,8 @@
#include <array>
#include <memory>
#include "HandlesInternal.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -11,7 +11,7 @@
#include <vector>
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::hal {

View File

@@ -5,8 +5,6 @@
#pragma once
#include "wpi/hal/Types.h"
#include "wpi/hal/Value.h"
#include "wpi/hal/simulation/NotifyListener.h"
typedef void (*HAL_CAN_SendMessageCallback)(
const char* name, void* param, int32_t busId, uint32_t messageId,

View File

@@ -47,16 +47,4 @@ void HALSIM_CancelAllSimPeriodicCallbacks(void);
#ifdef __cplusplus
} // extern "C"
namespace wpi::hal::sim {
inline void SetProgramState(const ControlWord& controlWord) {
HALSIM_SetProgramState(controlWord.GetValue());
}
inline ControlWord GetProgramState() {
HAL_ControlWord word;
HALSIM_GetProgramState(&word);
return ControlWord{word};
}
} // namespace wpi::hal::sim
#endif // __cplusplus
#endif

View File

@@ -0,0 +1,20 @@
// 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 "wpi/hal/DriverStationTypes.hpp"
#include "wpi/hal/simulation/MockHooks.h"
namespace wpi::hal::sim {
inline void SetProgramState(const ControlWord& controlWord) {
HALSIM_SetProgramState(controlWord.GetValue());
}
inline ControlWord GetProgramState() {
HAL_ControlWord word;
HALSIM_GetProgramState(&word);
return ControlWord{word};
}
} // namespace wpi::hal::sim

View File

@@ -15,23 +15,3 @@ typedef void (*HAL_BufferCallback)(const char* name, void* param,
typedef void (*HAL_ConstBufferCallback)(const char* name, void* param,
const unsigned char* buffer,
unsigned int count);
#ifdef __cplusplus
namespace wpi::hal {
template <typename CallbackFunction>
struct HalCallbackListener {
HalCallbackListener() = default;
HalCallbackListener(void* param_, CallbackFunction callback_)
: callback(callback_), param(param_) {}
explicit operator bool() const { return callback != nullptr; }
CallbackFunction callback = nullptr;
void* param = nullptr;
};
} // namespace wpi::hal
#endif

View File

@@ -0,0 +1,23 @@
// 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 "wpi/hal/simulation/NotifyListener.h"
namespace wpi::hal {
template <typename CallbackFunction>
struct HalCallbackListener {
HalCallbackListener() = default;
HalCallbackListener(void* param_, CallbackFunction callback_)
: callback(callback_), param(param_) {}
explicit operator bool() const { return callback != nullptr; }
CallbackFunction callback = nullptr;
void* param = nullptr;
};
} // namespace wpi::hal

View File

@@ -7,7 +7,7 @@
#include <memory>
#include <utility>
#include "wpi/hal/simulation/NotifyListener.h"
#include "wpi/hal/simulation/NotifyListener.hpp"
#include "wpi/util/Compiler.hpp"
#include "wpi/util/UidVector.hpp"
#include "wpi/util/spinlock.hpp"

View File

@@ -4,12 +4,11 @@
#pragma once
#include <memory>
#include <mutex>
#include "wpi/hal/simulation/NotifyListener.h"
#include "wpi/hal/simulation/SimCallbackRegistry.h"
#include "wpi/hal/simulation/SimCallbackRegistry.hpp"
#include "wpi/util/Compiler.hpp"
#include "wpi/util/UidVector.hpp"
#include "wpi/util/spinlock.hpp"
namespace wpi::hal {

View File

@@ -6,14 +6,13 @@
#include <fmt/format.h>
#include "DigitalInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/AddressableLEDDataInternal.h"
#include "DigitalInternal.hpp"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/AddressableLEDDataInternal.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/IndexedHandleResource.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
using namespace wpi::hal;

View File

@@ -9,11 +9,11 @@
#include <memory>
#include <string>
#include "HALInitializer.h"
#include "HALInitializer.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/HALBase.h"
#include "wpi/hal/Types.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/hal/simulation/AlertData.h"
#include "wpi/util/mutex.hpp"
#include "wpi/util/string.h"

View File

@@ -4,12 +4,11 @@
#include "wpi/hal/AnalogInput.h"
#include "AnalogInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/AnalogInDataInternal.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "AnalogInternal.hpp"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/AnalogInDataInternal.hpp"
using namespace wpi::hal;

View File

@@ -2,10 +2,10 @@
// 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 "AnalogInternal.h"
#include "AnalogInternal.hpp"
#include "PortsInternal.h"
#include "wpi/hal/handles/IndexedHandleResource.h"
#include "PortsInternal.hpp"
#include "wpi/hal/handles/IndexedHandleResource.hpp"
namespace wpi::hal {
IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort,

View File

@@ -8,9 +8,9 @@
#include <string>
#include "PortsInternal.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/IndexedHandleResource.h"
#include "PortsInternal.hpp"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/IndexedHandleResource.hpp"
namespace wpi::hal {
constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock

View File

@@ -4,7 +4,7 @@
#include "wpi/hal/CAN.h"
#include "mockdata/CanDataInternal.h"
#include "mockdata/CanDataInternal.hpp"
using namespace wpi::hal;

View File

@@ -7,11 +7,11 @@
#include <ctime>
#include <memory>
#include "HALInitializer.h"
#include "PortsInternal.h"
#include "HALInitializer.hpp"
#include "PortsInternal.hpp"
#include "wpi/hal/CAN.h"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/UnlimitedHandleResource.h"
#include "wpi/hal/handles/UnlimitedHandleResource.hpp"
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/mutex.hpp"
#include "wpi/util/timestamp.h"

View File

@@ -6,12 +6,12 @@
#include <string>
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/CTREPCMDataInternal.h"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/CTREPCMDataInternal.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/IndexedHandleResource.h"
#include "wpi/hal/handles/IndexedHandleResource.hpp"
using namespace wpi::hal;

View File

@@ -4,7 +4,7 @@
#include "wpi/hal/Constants.h"
#include "ConstantsInternal.h"
#include "ConstantsInternal.hpp"
using namespace wpi::hal;

View File

@@ -4,11 +4,11 @@
#include "wpi/hal/Counter.h"
#include "CounterInternal.h"
#include "HALInitializer.h"
#include "PortsInternal.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/LimitedHandleResource.h"
#include "CounterInternal.hpp"
#include "HALInitializer.hpp"
#include "PortsInternal.hpp"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/LimitedHandleResource.hpp"
namespace wpi::hal {

View File

@@ -4,9 +4,9 @@
#pragma once
#include "PortsInternal.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/LimitedHandleResource.h"
#include "PortsInternal.hpp"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/LimitedHandleResource.hpp"
namespace wpi::hal {

View File

@@ -4,14 +4,14 @@
#include "wpi/hal/DIO.h"
#include "DigitalInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/DIODataInternal.h"
#include "mockdata/DigitalPWMDataInternal.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/LimitedHandleResource.h"
#include "DigitalInternal.hpp"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/DIODataInternal.hpp"
#include "mockdata/DigitalPWMDataInternal.hpp"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/LimitedHandleResource.hpp"
using namespace wpi::hal;

View File

@@ -2,12 +2,12 @@
// 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 "DigitalInternal.h"
#include "DigitalInternal.hpp"
#include "PortsInternal.h"
#include "PortsInternal.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/DigitalHandleResource.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/DigitalHandleResource.hpp"
#include "wpi/hal/handles/HandlesInternal.hpp"
namespace wpi::hal {

View File

@@ -8,8 +8,8 @@
#include <string>
#include "PortsInternal.h"
#include "wpi/hal/handles/DigitalHandleResource.h"
#include "PortsInternal.hpp"
#include "wpi/hal/handles/DigitalHandleResource.hpp"
namespace wpi::hal {
/**

View File

@@ -16,11 +16,11 @@
#include <fmt/format.h>
#include "HALInitializer.h"
#include "mockdata/DriverStationDataInternal.h"
#include "HALInitializer.hpp"
#include "mockdata/DriverStationDataInternal.hpp"
#include "wpi/hal/DriverStationTypes.h"
#include "wpi/hal/Errors.h"
#include "wpi/hal/cpp/fpga_clock.h"
#include "wpi/hal/cpp/fpga_clock.hpp"
#include "wpi/hal/simulation/MockHooks.h"
#include "wpi/util/EventVector.hpp"
#include "wpi/util/mutex.hpp"

View File

@@ -6,13 +6,13 @@
#include <string>
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/DutyCycleDataInternal.h"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/DutyCycleDataInternal.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/IndexedHandleResource.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/IndexedHandleResource.hpp"
using namespace wpi::hal;

View File

@@ -6,14 +6,14 @@
#include <limits>
#include "CounterInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "mockdata/EncoderDataInternal.h"
#include "CounterInternal.hpp"
#include "HALInitializer.hpp"
#include "HALInternal.hpp"
#include "PortsInternal.hpp"
#include "mockdata/EncoderDataInternal.hpp"
#include "wpi/hal/Errors.h"
#include "wpi/hal/handles/HandlesInternal.h"
#include "wpi/hal/handles/LimitedHandleResource.h"
#include "wpi/hal/handles/HandlesInternal.hpp"
#include "wpi/hal/handles/LimitedHandleResource.hpp"
using namespace wpi::hal;

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