Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WebSockets Spec #47

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion asyncapi-template/filters/DeviceFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ function formatName(type) {
case "AI":
return "AnalogInput";
case "AO":
return "AnalogOutput"
return "AnalogOutput";
case "CANAccel":
return "CANAccelerometer";
case "CANAIn":
return "CANAnalogInput";
case "CTREPCM":
return "PCM";
default:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ task generateDeviceFiles(type: NpxTask) {
command = '@asyncapi/[email protected]'
args = ['--force-write',
'-o', "${outputDir}/org/team199/wpiws/devices",
"https://raw.githubusercontent.com/wpilibsuite/allwpilib/3b8d8a367b49bea28d5423dca53f913c13ff6936/simulation/halsim_ws_core/doc/wpilib-ws.yaml",
"https://raw.githubusercontent.com/DeepBlueRobotics/allwpilib/c1fc86033a4b5ebda451de657fc2546eb3f431fb/simulation/halsim_ws_core/doc/wpilib-ws.yaml",
file(archiveTemplate.archiveFile).toURI()]

// Define the inputs and outputs of this task so that gradle only runs it
Expand Down
42 changes: 16 additions & 26 deletions src/main/java/org/team199/wpiws/connection/MessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import org.team199.wpiws.devices.AddressableLEDSim;
import org.team199.wpiws.devices.AnalogInputSim;
import org.team199.wpiws.devices.AnalogOutputSim;
import org.team199.wpiws.devices.CANAccelerometerSim;
import org.team199.wpiws.devices.CANAnalogInputSim;
import org.team199.wpiws.devices.CANDIOSim;
import org.team199.wpiws.devices.CANDutyCycleSim;
import org.team199.wpiws.devices.CANEncoderSim;
import org.team199.wpiws.devices.CANGyroSim;
import org.team199.wpiws.devices.CANMotorSim;
import org.team199.wpiws.devices.DIOSim;
import org.team199.wpiws.devices.DriverStationSim;
Expand Down Expand Up @@ -57,11 +62,11 @@ public final class MessageProcessor {
registerProcessor("SimDevice", SimDeviceSim::processMessage);
registerProcessor("CANMotor", CANMotorSim::processMessage);
registerProcessor("CANEncoder", CANEncoderSim::processMessage);
registerProcessor("CANDutyCycle", DutyCycleSim::processMessage);
registerProcessor("CANAccel", AccelerometerSim::processMessage);
registerProcessor("CANAIn", AnalogInputSim::processMessage);
registerProcessor("CANDIO", DIOSim::processMessage);
registerProcessor("CANGyro", GyroSim::processMessage);
registerProcessor("CANDutyCycle", CANDutyCycleSim::processMessage);
registerProcessor("CANAccel", CANAccelerometerSim::processMessage);
registerProcessor("CANAIn", CANAnalogInputSim::processMessage);
registerProcessor("CANDIO", CANDIOSim::processMessage);
registerProcessor("CANGyro", CANGyroSim::processMessage);

}

Expand All @@ -88,29 +93,14 @@ public static void registerProcessor(String type, DeviceMessageProcessor process
* @param data the values of that device which have been modified
*/
public static void process(String device, String type, List<WSValue> data) {
// Per the spec, some message with a type of SimDevice have a data
// format that is identical to hardware devices. In particular a
// SimDevice message with device=DutyCyle:Name has the same data format
// as a DutyCycle message, and a SimDevice message with
// device=CAN{Gyro,AI,Accel,DIO,DutyCycle}:Name has the same data format
// as a {Gyro,AI,Accel,DIO,DutyCycle} message. The
// CAN{Gyro,AI,Accel,DIO,DutyCycle} processors are registered as aliases
// for the the their non CAN counterparts. CANMotor and CANEncoder have
// their own processors because there is no Motor processor and the
// CANEncoder data format is different from the Encoder data format.
String dataType = type;
if (type.equals("SimDevice")) {
String[] deviceParts = device.split(":");
if (deviceParts.length > 1) {
dataType = deviceParts[0];
}
}

// Use the data type to find the appropriate processor. Fallback on SimDevice if the parsing above returned an invalid type.
DeviceMessageProcessor processor = processors.getOrDefault(dataType, type.equals("SimDevice") ? processors.get("SimDevice") : null);
DeviceMessageProcessor processor = processors.get(type);
if(processor == null) {
if(unknownTypes.add(dataType)) {
System.err.println("No processor found for device with data type: \"" + dataType + "\". Messages with this data type will be ignored.");
if (unknownTypes.add(type)) {
System.err.println(
"No processor found for device with data type: \""
+ type
+ "\". Messages with this data type will be ignored.");
}
return;
}
Expand Down