[sim] Add WebSocket extension (client/server) (#2589)

This allows access to HAL-level simulation data via a WebSocket connection.

The server additionally serves local files.

The following environment variables can be used for configuration:
HALSIMWS_USERROOT (server) - local directory to use for file serving for /user/ URIs, defaults to ./sim/user
HALSIMWS_SYSROOT (server) - local directory to use for file serving for all other URIs, defaults to ./sim
HALSIMWS_URI (client or server) - WebSocket URI, defaults to /wpilibws
HALSIMWS_PORT (client or server) - port number, defaults to 8080
HALSIMWS_HOST (client) - host to connect to, defaults to localhost

Co-authored-by: Zhiquan Yeo <zyeo8@bloomberg.net>
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: jpokornyiii <jpokornyiii@gmail.com>
This commit is contained in:
Zhiquan Yeo
2020-08-20 01:14:03 -04:00
committed by GitHub
parent e127bac7fd
commit 932bfcf374
51 changed files with 3696 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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 <iostream>
#include <thread>
#include <hal/DriverStation.h>
#include <hal/HALBase.h>
#include <hal/Main.h>
extern "C" int HALSIM_InitExtension(void);
int main() {
HAL_Initialize(500, 0);
HALSIM_InitExtension();
HAL_RunMain();
int cycleCount = 0;
while (cycleCount < 100) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
cycleCount++;
std::cout << "Count: " << cycleCount << std::endl;
}
std::cout << "DONE" << std::endl;
HAL_ExitMain();
}