2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2019-12-02 23:27:33 -08:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/SimDevice.h>
|
|
|
|
|
#include <hal/simulation/SimDeviceData.h>
|
|
|
|
|
|
2019-12-02 23:27:33 -08:00
|
|
|
namespace frc {
|
|
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control the simulation side of a SimDevice.
|
|
|
|
|
*/
|
2019-12-02 23:27:33 -08:00
|
|
|
class SimDeviceSim {
|
|
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs a SimDeviceSim.
|
|
|
|
|
*
|
|
|
|
|
* @param name name of the SimDevice
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit SimDeviceSim(const char* name);
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimValue GetValue(const char* name) const;
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimDouble GetDouble(const char* name) const;
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimEnum GetEnum(const char* name) const;
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimBoolean GetBoolean(const char* name) const;
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
static std::vector<std::string> GetEnumOptions(hal::SimEnum val);
|
2019-12-02 23:27:33 -08:00
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
|
void EnumerateValues(F callback) const {
|
|
|
|
|
return HALSIM_EnumerateSimValues(
|
|
|
|
|
m_handle, &callback,
|
|
|
|
|
[](const char* name, void* param, HAL_SimValueHandle handle,
|
|
|
|
|
HAL_Bool readonly, const struct HAL_Value* value) {
|
|
|
|
|
std::invoke(*static_cast<F*>(param), name, handle, readonly, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator HAL_SimDeviceHandle() const { return m_handle; }
|
|
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
|
static void EnumerateDevices(const char* prefix, F callback) {
|
|
|
|
|
return HALSIM_EnumerateSimDevices(
|
|
|
|
|
prefix, &callback,
|
|
|
|
|
[](const char* name, void* param, HAL_SimDeviceHandle handle) {
|
|
|
|
|
std::invoke(*static_cast<F*>(param), name, handle);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
static void ResetData();
|
2019-12-02 23:27:33 -08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
HAL_SimDeviceHandle m_handle;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|