mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[sim] Move Sim classes from HAL to wpilibc/j (#2549)
Also move some things in HAL for consistency. WAS: C++: - C APIs: #include "mockdata/AccelerometerData.h" - User side class: #include "simulation/AccelerometerSim.h" Java: - JNI APIs: hal.sim.mockdata.AccelerometerData (and a few classes in hal.sim) - User side classes: hal.sim.AccelerometerSim IS: C++: - C APIs: #include "hal/simulation/AccelerometerData.h" - C++ class: #include "frc/simulation/AccelerometerSim.h" Java: - JNI APIs: hal.simulation.AccelerometerData - User side class: wpilibj.simulation.AccelerometerSim
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/CANAPI.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "mockdata/CanData.h"
|
||||
#include "hal/simulation/CanData.h"
|
||||
|
||||
namespace hal {
|
||||
struct CANTestStore {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/AnalogInput.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/AnalogInData.h"
|
||||
#include "hal/simulation/AnalogInData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/AnalogOutput.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/AnalogOutData.h"
|
||||
#include "hal/simulation/AnalogOutData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/DIO.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/DIOData.h"
|
||||
#include "hal/simulation/DIOData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Solenoid.h"
|
||||
#include "mockdata/DriverStationData.h"
|
||||
#include "hal/simulation/DriverStationData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/I2C.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/I2CData.h"
|
||||
#include "hal/simulation/I2CData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Solenoid.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PCMData.h"
|
||||
#include "hal/simulation/PCMData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/PDP.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PDPData.h"
|
||||
#include "hal/simulation/PDPData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/PWM.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PWMData.h"
|
||||
#include "hal/simulation/PWMData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Relay.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/RelayData.h"
|
||||
#include "hal/simulation/RelayData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-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. */
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/SPI.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/SPIData.h"
|
||||
#include "hal/simulation/SPIData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/Accelerometer.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "simulation/AccelerometerSim.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
namespace hal {
|
||||
|
||||
TEST(AcclerometerSimTests, TestActiveCallback) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AccelerometerSim sim{0};
|
||||
|
||||
sim.ResetData();
|
||||
|
||||
bool wasTriggered = false;
|
||||
bool lastValue = false;
|
||||
|
||||
auto cb = sim.RegisterActiveCallback(
|
||||
[&](wpi::StringRef name, const HAL_Value* value) {
|
||||
wasTriggered = true;
|
||||
lastValue = value->data.v_boolean;
|
||||
},
|
||||
false);
|
||||
|
||||
EXPECT_FALSE(wasTriggered);
|
||||
|
||||
HAL_SetAccelerometerActive(true);
|
||||
|
||||
EXPECT_TRUE(wasTriggered);
|
||||
EXPECT_TRUE(lastValue);
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
@@ -1,40 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/SimDevice.h"
|
||||
#include "simulation/SimDeviceSim.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
namespace hal {
|
||||
|
||||
TEST(SimDeviceSimTests, TestBasic) {
|
||||
SimDevice dev{"test"};
|
||||
SimBoolean devBool = dev.CreateBoolean("bool", false, false);
|
||||
|
||||
SimDeviceSim sim{"test"};
|
||||
SimBoolean simBool = sim.GetBoolean("bool");
|
||||
EXPECT_FALSE(simBool.Get());
|
||||
simBool.Set(true);
|
||||
EXPECT_TRUE(devBool.Get());
|
||||
}
|
||||
|
||||
TEST(SimDeviceSimTests, TestEnumerateDevices) {
|
||||
SimDevice dev{"test"};
|
||||
|
||||
bool foundit = false;
|
||||
SimDeviceSim::EnumerateDevices(
|
||||
"te", [&](const char* name, HAL_SimDeviceHandle handle) {
|
||||
if (wpi::StringRef(name) == "test") foundit = true;
|
||||
});
|
||||
EXPECT_TRUE(foundit);
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
@@ -1,49 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "simulation/AccelerometerSim.h"
|
||||
#include "simulation/AnalogGyroSim.h"
|
||||
#include "simulation/AnalogInSim.h"
|
||||
#include "simulation/AnalogOutSim.h"
|
||||
#include "simulation/AnalogTriggerSim.h"
|
||||
#include "simulation/DIOSim.h"
|
||||
#include "simulation/DigitalPWMSim.h"
|
||||
#include "simulation/DriverStationSim.h"
|
||||
#include "simulation/EncoderSim.h"
|
||||
#include "simulation/PCMSim.h"
|
||||
#include "simulation/PDPSim.h"
|
||||
#include "simulation/PWMSim.h"
|
||||
#include "simulation/RelaySim.h"
|
||||
#include "simulation/RoboRioSim.h"
|
||||
#include "simulation/SPIAccelerometerSim.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
namespace hal {
|
||||
|
||||
TEST(SimInitializationTests, TestAllInitialize) {
|
||||
HAL_Initialize(500, 0);
|
||||
AccelerometerSim acsim{0};
|
||||
AnalogGyroSim agsim{0};
|
||||
AnalogInSim aisim{0};
|
||||
AnalogOutSim aosim{0};
|
||||
AnalogTriggerSim atsim{0};
|
||||
DigitalPWMSim dpsim{0};
|
||||
DIOSim diosim{0};
|
||||
DriverStationSim dssim;
|
||||
(void)dssim;
|
||||
EncoderSim esim{0};
|
||||
PCMSim pcmsim{0};
|
||||
PDPSim pdpsim{0};
|
||||
PWMSim pwmsim{0};
|
||||
RelaySim rsim{0};
|
||||
RoboRioSim rrsim{0};
|
||||
SPIAccelerometerSim sasim{0};
|
||||
}
|
||||
} // namespace hal
|
||||
Reference in New Issue
Block a user