mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
|
|
/*----------------------------------------------------------------------------*/
|
||
|
|
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||
|
|
/* the project. */
|
||
|
|
/*----------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
#include <WSProviderContainer.h>
|
||
|
|
#include <WSProvider_Analog.h>
|
||
|
|
#include <WSProvider_DIO.h>
|
||
|
|
#include <WSProvider_DriverStation.h>
|
||
|
|
#include <WSProvider_Encoder.h>
|
||
|
|
#include <WSProvider_Joystick.h>
|
||
|
|
#include <WSProvider_PWM.h>
|
||
|
|
#include <WSProvider_Relay.h>
|
||
|
|
#include <WSProvider_RoboRIO.h>
|
||
|
|
#include <WSProvider_SimDevice.h>
|
||
|
|
#include <WSProvider_dPWM.h>
|
||
|
|
#include <hal/Main.h>
|
||
|
|
#include <wpi/raw_ostream.h>
|
||
|
|
|
||
|
|
#include "HALSimWSServer.h"
|
||
|
|
|
||
|
|
using namespace std::placeholders;
|
||
|
|
using namespace wpilibws;
|
||
|
|
|
||
|
|
// Currently, robots never terminate, so we keep static objects that are
|
||
|
|
// never properly released or cleaned up.
|
||
|
|
static ProviderContainer providers;
|
||
|
|
static HALSimWSProviderSimDevices simDevices(providers);
|
||
|
|
|
||
|
|
extern "C" {
|
||
|
|
#if defined(WIN32) || defined(_WIN32)
|
||
|
|
__declspec(dllexport)
|
||
|
|
#endif
|
||
|
|
int HALSIM_InitExtension(void) {
|
||
|
|
wpi::outs() << "Websocket Simulator Initializing.\n";
|
||
|
|
auto hsw = std::make_shared<HALSimWeb>(providers, simDevices);
|
||
|
|
HALSimWeb::SetInstance(hsw);
|
||
|
|
|
||
|
|
if (!hsw->Initialize()) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
WSRegisterFunc registerFunc = [&](auto key, auto provider) {
|
||
|
|
providers.Add(key, provider);
|
||
|
|
};
|
||
|
|
|
||
|
|
HALSimWSProviderAnalogIn::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderAnalogOut::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderDIO::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderDigitalPWM::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderDriverStation::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderEncoder::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderJoystick::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderPWM::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderRelay::Initialize(registerFunc);
|
||
|
|
HALSimWSProviderRoboRIO::Initialize(registerFunc);
|
||
|
|
|
||
|
|
simDevices.Initialize(hsw->GetLoop());
|
||
|
|
|
||
|
|
HAL_SetMain(nullptr, HALSimWeb::Main, HALSimWeb::Exit);
|
||
|
|
|
||
|
|
wpi::outs() << "Websocket Simulator Initialized!\n";
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
} // extern "C"
|