[sim] Various WebSockets fixes and enhancements (#2952)

This is a breaking change to the WebSockets layer to align it with
recent specification documentation work.

To support this, HAL SimValue changed readonly to a direction enum.
This allows specifying bidirectional in addition to input and output.

The SimValue change is specifically designed to avoid API and ABI breakage.
This is completely transparent in C++; in Java a new callback class was added,
and the old readonly functions have been marked deprecated.

A new SimValue creation function for enums allows specifying double values
for each enum value, not just strings.  This allows mapping enum values to
doubles in the WebSockets layer.

A ":" in the SimDevice name now maps it to different WebSocket types (e.g.
"Accel:Name" becomes type "Accel", device "Name").  The type is hidden
in the GUI.

Other WebSockets changes:
* Implemented match_time and game_data
* Added joystick rumble data
* Added builtin accelerometer support
* SimValue enums are mapped to string and double value on WS interface
* Added WebSockets protocol specification
* Added READMEs
This commit is contained in:
Peter Johnson
2020-12-23 15:54:11 -08:00
committed by GitHub
parent 699bbe21a4
commit 10b396b4c2
38 changed files with 1264 additions and 187 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2019-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. */
@@ -33,19 +33,29 @@ void HAL_FreeSimDevice(HAL_SimDeviceHandle handle) {
}
HAL_SimValueHandle HAL_CreateSimValue(HAL_SimDeviceHandle device,
const char* name, HAL_Bool readonly,
const char* name, int32_t direction,
const struct HAL_Value* initialValue) {
return SimSimDeviceData->CreateValue(device, name, readonly, 0, nullptr,
*initialValue);
return SimSimDeviceData->CreateValue(device, name, direction, 0, nullptr,
nullptr, *initialValue);
}
HAL_SimValueHandle HAL_CreateSimValueEnum(HAL_SimDeviceHandle device,
const char* name, HAL_Bool readonly,
const char* name, int32_t direction,
int32_t numOptions,
const char** options,
int32_t initialValue) {
return SimSimDeviceData->CreateValue(device, name, readonly, numOptions,
options, HAL_MakeEnum(initialValue));
return SimSimDeviceData->CreateValue(device, name, direction, numOptions,
options, nullptr,
HAL_MakeEnum(initialValue));
}
HAL_SimValueHandle HAL_CreateSimValueEnumDouble(
HAL_SimDeviceHandle device, const char* name, int32_t direction,
int32_t numOptions, const char** options, const double* optionValues,
int32_t initialValue) {
return SimSimDeviceData->CreateValue(device, name, direction, numOptions,
options, optionValues,
HAL_MakeEnum(initialValue));
}
void HAL_GetSimValue(HAL_SimValueHandle handle, struct HAL_Value* value) {