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.
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
#include "frc/simulation/SimDeviceSim.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <hal/SimDevice.h>
|
|
|
|
|
#include <hal/simulation/SimDeviceData.h>
|
2021-02-13 08:17:13 +02:00
|
|
|
#include <wpi/SmallString.h>
|
|
|
|
|
#include <wpi/raw_ostream.h>
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
|
|
|
|
SimDeviceSim::SimDeviceSim(const char* name)
|
|
|
|
|
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
|
|
|
|
|
|
2021-02-13 08:17:13 +02:00
|
|
|
SimDeviceSim::SimDeviceSim(const char* name, int index) {
|
|
|
|
|
wpi::SmallString<128> fullname;
|
|
|
|
|
wpi::raw_svector_ostream os(fullname);
|
|
|
|
|
os << name << '[' << index << ']';
|
|
|
|
|
|
|
|
|
|
m_handle = HALSIM_GetSimDeviceHandle(fullname.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimDeviceSim::SimDeviceSim(const char* name, int index, int channel) {
|
|
|
|
|
wpi::SmallString<128> fullname;
|
|
|
|
|
wpi::raw_svector_ostream os(fullname);
|
|
|
|
|
os << name << '[' << index << ',' << channel << ']';
|
|
|
|
|
|
|
|
|
|
m_handle = HALSIM_GetSimDeviceHandle(fullname.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimValue SimDeviceSim::GetValue(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
hal::SimInt SimDeviceSim::GetInt(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hal::SimLong SimDeviceSim::GetLong(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
hal::SimDouble SimDeviceSim::GetDouble(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hal::SimEnum SimDeviceSim::GetEnum(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hal::SimBoolean SimDeviceSim::GetBoolean(const char* name) const {
|
|
|
|
|
return HALSIM_GetSimValueHandle(m_handle, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> SimDeviceSim::GetEnumOptions(hal::SimEnum val) {
|
|
|
|
|
int32_t numOptions;
|
|
|
|
|
const char** options = HALSIM_GetSimValueEnumOptions(val, &numOptions);
|
|
|
|
|
std::vector<std::string> rv;
|
|
|
|
|
rv.reserve(numOptions);
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int32_t i = 0; i < numOptions; ++i) {
|
|
|
|
|
rv.emplace_back(options[i]);
|
|
|
|
|
}
|
2020-07-15 23:48:09 -07:00
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void SimDeviceSim::ResetData() {
|
|
|
|
|
HALSIM_ResetSimDeviceData();
|
|
|
|
|
}
|