[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

@@ -94,12 +94,13 @@ public class ADXL345_I2C implements Accelerometer, Sendable, AutoCloseable {
m_i2c = new I2C(port, deviceAddress);
// simulation
m_simDevice = SimDevice.create("ADXL345_I2C", port.value, deviceAddress);
m_simDevice = SimDevice.create("Accel:ADXL345_I2C", port.value, deviceAddress);
if (m_simDevice != null) {
m_simRange = m_simDevice.createEnum("Range", true, new String[] {"2G", "4G", "8G", "16G"}, 0);
m_simX = m_simDevice.createDouble("X Accel", false, 0.0);
m_simY = m_simDevice.createDouble("Y Accel", false, 0.0);
m_simZ = m_simDevice.createDouble("Z Accel", false, 0.0);
m_simRange = m_simDevice.createEnumDouble("range", SimDevice.Direction.kOutput,
new String[] {"2G", "4G", "8G", "16G"}, new double[] {2.0, 4.0, 8.0, 16.0}, 0);
m_simX = m_simDevice.createDouble("x", SimDevice.Direction.kInput, 0.0);
m_simY = m_simDevice.createDouble("y", SimDevice.Direction.kInput, 0.0);
m_simZ = m_simDevice.createDouble("z", SimDevice.Direction.kInput, 0.0);
}
// Turn on the measurements

View File

@@ -85,12 +85,13 @@ public class ADXL345_SPI implements Accelerometer, Sendable, AutoCloseable {
public ADXL345_SPI(SPI.Port port, Range range) {
m_spi = new SPI(port);
// simulation
m_simDevice = SimDevice.create("ADXL345_SPI", port.value);
m_simDevice = SimDevice.create("Accel:ADXL345_SPI", port.value);
if (m_simDevice != null) {
m_simRange = m_simDevice.createEnum("Range", true, new String[] {"2G", "4G", "8G", "16G"}, 0);
m_simX = m_simDevice.createDouble("X Accel", false, 0.0);
m_simY = m_simDevice.createDouble("Y Accel", false, 0.0);
m_simZ = m_simDevice.createDouble("Z Accel", false, 0.0);
m_simRange = m_simDevice.createEnumDouble("range", SimDevice.Direction.kOutput,
new String[] {"2G", "4G", "8G", "16G"}, new double[] {2.0, 4.0, 8.0, 16.0}, 0);
m_simX = m_simDevice.createDouble("x", SimDevice.Direction.kInput, 0.0);
m_simY = m_simDevice.createDouble("y", SimDevice.Direction.kInput, 0.0);
m_simZ = m_simDevice.createDouble("z", SimDevice.Direction.kInput, 0.0);
}
init(range);
SendableRegistry.addLW(this, "ADXL345_SPI", port.value);

View File

@@ -93,12 +93,13 @@ public class ADXL362 implements Accelerometer, Sendable, AutoCloseable {
m_spi = new SPI(port);
// simulation
m_simDevice = SimDevice.create("ADXL362", port.value);
m_simDevice = SimDevice.create("Accel:ADXL362", port.value);
if (m_simDevice != null) {
m_simRange = m_simDevice.createEnum("Range", true, new String[] {"2G", "4G", "8G", "16G"}, 0);
m_simX = m_simDevice.createDouble("X Accel", false, 0.0);
m_simY = m_simDevice.createDouble("Y Accel", false, 0.0);
m_simZ = m_simDevice.createDouble("Z Accel", false, 0.0);
m_simRange = m_simDevice.createEnumDouble("range", SimDevice.Direction.kOutput,
new String[] {"2G", "4G", "8G", "16G"}, new double[] {2.0, 4.0, 8.0, 16.0}, 0);
m_simX = m_simDevice.createDouble("x", SimDevice.Direction.kInput, 0.0);
m_simY = m_simDevice.createDouble("y", SimDevice.Direction.kInput, 0.0);
m_simZ = m_simDevice.createDouble("z", SimDevice.Direction.kInput, 0.0);
}
m_spi.setClockRate(3000000);

View File

@@ -69,11 +69,11 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, Sendable
m_port = port;
// simulation
m_simDevice = SimDevice.create("ADXRS450_Gyro", port.value);
m_simDevice = SimDevice.create("Gyro:ADXRS450", port.value);
if (m_simDevice != null) {
m_simConnected = m_simDevice.createBoolean("Connected", false, true);
m_simAngle = m_simDevice.createDouble("Angle", false, 0.0);
m_simRate = m_simDevice.createDouble("Rate", false, 0.0);
m_simConnected = m_simDevice.createBoolean("connected", SimDevice.Direction.kInput, true);
m_simAngle = m_simDevice.createDouble("angle", SimDevice.Direction.kInput, 0.0);
m_simRate = m_simDevice.createDouble("rate", SimDevice.Direction.kInput, 0.0);
}
m_spi.setClockRate(3000000);

View File

@@ -32,7 +32,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
protected SimDevice m_simDevice;
protected SimDouble m_simPosition;
protected SimDouble m_simDistancePerRotation;
protected SimBoolean m_simIsConnected;
/**
@@ -69,12 +68,11 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
}
private void init() {
m_simDevice = SimDevice.create("DutyCycleEncoder", m_dutyCycle.getFPGAIndex());
m_simDevice = SimDevice.create("DutyCycle:DutyCycleEncoder", m_dutyCycle.getSourceChannel());
if (m_simDevice != null) {
m_simPosition = m_simDevice.createDouble("Position", false, 0.0);
m_simDistancePerRotation = m_simDevice.createDouble("DistancePerRotation", false, 1.0);
m_simIsConnected = m_simDevice.createBoolean("Connected", false, true);
m_simPosition = m_simDevice.createDouble("position", SimDevice.Direction.kInput, 0.0);
m_simIsConnected = m_simDevice.createBoolean("connected", SimDevice.Direction.kInput, true);
} else {
m_counter = new Counter();
m_analogTrigger = new AnalogTrigger(m_dutyCycle);
@@ -142,10 +140,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
*/
public void setDistancePerRotation(double distancePerRotation) {
m_distancePerRotation = distancePerRotation;
if (m_simDistancePerRotation != null) {
m_simDistancePerRotation.set(distancePerRotation);
}
}
/**