diff --git a/asyncapi-template/filters/DeviceFilter.js b/asyncapi-template/filters/DeviceFilter.js index ec66fc1..5d37bcd 100644 --- a/asyncapi-template/filters/DeviceFilter.js +++ b/asyncapi-template/filters/DeviceFilter.js @@ -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: diff --git a/build.gradle b/build.gradle index 2ae0adc..8977099 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ task generateDeviceFiles(type: NpxTask) { command = '@asyncapi/generator@1.17.25' 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/5e85b83d920d78a1ec6b1e1919ddcbeece7d25e1/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 diff --git a/src/main/java/org/team199/wpiws/connection/MessageProcessor.java b/src/main/java/org/team199/wpiws/connection/MessageProcessor.java index a5fb5b2..7954f6b 100644 --- a/src/main/java/org/team199/wpiws/connection/MessageProcessor.java +++ b/src/main/java/org/team199/wpiws/connection/MessageProcessor.java @@ -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; @@ -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); } @@ -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 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; }