[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

@@ -126,15 +126,16 @@ class SimPrefixCallbackRegistry {
class SimDeviceData {
private:
struct Value {
Value(const char* name_, bool readonly_, const HAL_Value& value_)
: name{name_}, readonly{readonly_}, value{value_} {}
Value(const char* name_, int32_t direction_, const HAL_Value& value_)
: name{name_}, direction{direction_}, value{value_} {}
HAL_SimValueHandle handle{0};
std::string name;
bool readonly;
int32_t direction;
HAL_Value value;
std::vector<std::string> enumOptions;
std::vector<const char*> cstrEnumOptions;
std::vector<double> enumOptionValues;
impl::SimUnnamedCallbackRegistry<HALSIM_SimValueCallback> changed;
};
@@ -168,8 +169,9 @@ class SimDeviceData {
HAL_SimDeviceHandle CreateDevice(const char* name);
void FreeDevice(HAL_SimDeviceHandle handle);
HAL_SimValueHandle CreateValue(HAL_SimDeviceHandle device, const char* name,
bool readonly, int32_t numOptions,
int32_t direction, int32_t numOptions,
const char** options,
const double* optionValues,
const HAL_Value& initialValue);
HAL_Value GetValue(HAL_SimValueHandle handle);
void SetValue(HAL_SimValueHandle handle, const HAL_Value& value);
@@ -212,6 +214,9 @@ class SimDeviceData {
const char** GetValueEnumOptions(HAL_SimValueHandle handle,
int32_t* numOptions);
const double* GetValueEnumDoubleValues(HAL_SimValueHandle handle,
int32_t* numOptions);
void ResetData();
};
extern SimDeviceData* SimSimDeviceData;