Skip to content

Commit

Permalink
Merge pull request #50 from DeepBlueRobotics/update-package-name
Browse files Browse the repository at this point in the history
Move `org.team199` to `org.carlmontrobotics` (#49)
  • Loading branch information
CoolSpy3 authored Jun 27, 2024
2 parents 20c853c + 573e965 commit aa8450d
Show file tree
Hide file tree
Showing 28 changed files with 94 additions and 87 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# WPIWebSockets
This API provides a Java interface to the [WPILib HALSim WebSockets API](https://github.com/wpilibsuite/allwpilib/blob/master/simulation/halsim_ws_core/doc/hardware_ws_api.md) which mirrors the standard simulation API.
# Building the API
To build the API, navigate to the root directory of this repository and run `./gradlew build`. This will use Gradle to build the API with Java 8. Note that the simulated device files (org.team199.wpiws.devices.*) are auto-generated using the [AsyncAPI Generator](https://github.com/asyncapi/generator) and [an extended version](./wpilib-ws.yaml) of [WPILib's machine readable WebSocket specification](https://github.com/wpilibsuite/allwpilib/blob/master/simulation/halsim_ws_core/doc/wpilib-ws.yaml). The AsyncAPI template used to generate these files is located at [./asyncapi-template](./asyncapi-template). These files are auto-generated during the `WPIWebSockets:build` task, however, they can be manually regenerated by running `./gradlew generateDeviceFiles`.
To build the API, navigate to the root directory of this repository and run `./gradlew build`. This will use Gradle to build the API with Java 8. Note that the simulated device files (org.carlmontrobotics.wpiws.devices.*) are auto-generated using the [AsyncAPI Generator](https://github.com/asyncapi/generator) and [an extended version](./wpilib-ws.yaml) of [WPILib's machine readable WebSocket specification](https://github.com/wpilibsuite/allwpilib/blob/master/simulation/halsim_ws_core/doc/wpilib-ws.yaml). The AsyncAPI template used to generate these files is located at [./asyncapi-template](./asyncapi-template). These files are auto-generated during the `WPIWebSockets:build` task, however, they can be manually regenerated by running `./gradlew generateDeviceFiles`.
# Using the API
Connecting to the running HALSim client and server instances can be accomplished by using the `connectHALSim` and `startHALSimServer` methods of [`org.team199.wpiws.connection.WSConnection`](./src/main/java/org/team199/wpiws/connection/WSConnection.java). Code for connecting to simulated devices can be found in the `org.team199.wpiws.devices` package. These classes can be initialized by providing the constructor with the device id with which it should associate itself. The instance will then provide getter, setter, and callback methods for all of the values exposed by the WebSocket API. (ex. `new PWMSim("5").setSpeed(5)`, `new DIOSim("0").getValue()`). Note: `static` methods apply globaly to the device type.
Connecting to the running HALSim client and server instances can be accomplished by using the `connectHALSim` and `startHALSimServer` methods of [`org.carlmontrobotics.wpiws.connection.WSConnection`](./src/main/java/org/carlmontrobotics/wpiws/connection/WSConnection.java). Code for connecting to simulated devices can be found in the `org.carlmontrobotics.wpiws.devices` package. These classes can be initialized by providing the constructor with the device id with which it should associate itself. The instance will then provide getter, setter, and callback methods for all of the values exposed by the WebSocket API. (ex. `new PWMSim("5").setSpeed(5)`, `new DIOSim("0").getValue()`). Note: `static` methods apply globaly to the device type.

For a more complete example, see [DeepBlueRobotics/DeepBlueSim](https://github.com/DeepBlueRobotics/DeepBlueSim) which uses this API to provide an interface to a [Webots](https://cyberbotics.com/) robot simulator.
16 changes: 8 additions & 8 deletions asyncapi-template/partials/SimDeviceSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// IT IS AUTOMATICALLY GENERATED BY THE 'generateDeviceFiles' GRADLE TASK
// FROM THE TEMPLATE FILE 'asyncapi-template/partials/SimDeviceSim.java'.
// EDIT THAT FILE INSTEAD.
package org.team199.wpiws.devices;
package org.carlmontrobotics.wpiws.devices;

import java.math.BigDecimal;
import java.util.Arrays;
Expand All @@ -17,12 +17,12 @@
import java.util.function.Function;
import java.util.function.Predicate;

import org.team199.wpiws.Pair;
import org.team199.wpiws.StateDevice;
import org.team199.wpiws.connection.ConnectionProcessor;
import org.team199.wpiws.connection.WSValue;
import org.team199.wpiws.interfaces.SimDeviceCallback;
import org.team199.wpiws.interfaces.ObjectCallback;
import org.carlmontrobotics.wpiws.Pair;
import org.carlmontrobotics.wpiws.StateDevice;
import org.carlmontrobotics.wpiws.connection.ConnectionProcessor;
import org.carlmontrobotics.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.interfaces.SimDeviceCallback;
import org.carlmontrobotics.wpiws.interfaces.ObjectCallback;

/**
* Represents a miscellaneous simulated device
Expand Down Expand Up @@ -252,7 +252,7 @@ public static void cancelDeviceCreatedCallback(Pair<String, SimDeviceCallback> c
}

/**
* An implementation of {@link org.team199.wpiws.interfaces.DeviceMessageProcessor} which processes WPI HALSim messages for SimDeviceSims
* An implementation of {@link org.carlmontrobotics.wpiws.interfaces.DeviceMessageProcessor} which processes WPI HALSim messages for SimDeviceSims
* @param device the device identifier of the device sending the message
* @param data the data associated with the message
*/
Expand Down
14 changes: 7 additions & 7 deletions asyncapi-template/template/$$schema$$.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// IT IS AUTOMATICALLY GENERATED BY THE 'generateDeviceFiles' GRADLE TASK
// FROM THE TEMPLATE FILE 'asyncapi-template/template/$$schema$$.java'.
// EDIT THAT FILE INSTEAD.
package org.team199.wpiws.devices;
package org.carlmontrobotics.wpiws.devices;

import java.util.List;
{% if hasId -%}
Expand All @@ -32,12 +32,12 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import org.team199.wpiws.StateDevice;
import org.team199.wpiws.connection.ConnectionProcessor;
import org.team199.wpiws.connection.WSValue;
import org.team199.wpiws.interfaces.*;
import org.carlmontrobotics.wpiws.StateDevice;
import org.carlmontrobotics.wpiws.connection.ConnectionProcessor;
import org.carlmontrobotics.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.interfaces.*;
{%- if (props | usesCustomTypes(name)) %}
import org.team199.wpiws.types.*;
import org.carlmontrobotics.wpiws.types.*;
{%- endif %}

/**
Expand Down Expand Up @@ -254,7 +254,7 @@ protected State generateState() {
{% endfor -%}

/**
* An implementation of {@link org.team199.wpiws.interfaces.DeviceMessageProcessor} which processes WPI HALSim messages for {{ name }}Sims
* An implementation of {@link org.carlmontrobotics.wpiws.interfaces.DeviceMessageProcessor} which processes WPI HALSim messages for {{ name }}Sims
* @param device the device identifier of the device sending the message
* @param type the type of the device sending the message
* @param data the data associated with the message
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ task generateDeviceFiles(type: NpxTask) {
workingDir = buildDir // Because templateDir can't be under it
command = '@asyncapi/[email protected]'
args = ['--force-write',
'-o', "${outputDir}/org/team199/wpiws/devices",
'-o', "${outputDir}/org/carlmontrobotics/wpiws/devices",
"https://raw.githubusercontent.com/DeepBlueRobotics/allwpilib/c1fc86033a4b5ebda451de657fc2546eb3f431fb/simulation/halsim_ws_core/doc/wpilib-ws.yaml",
file(archiveTemplate.archiveFile).toURI()]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws;
package org.carlmontrobotics.wpiws;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws;
package org.carlmontrobotics.wpiws;

import java.math.BigDecimal;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;

import org.team199.wpiws.devices.AccelerometerSim;
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;
import org.team199.wpiws.devices.DutyCycleSim;
import org.team199.wpiws.devices.EncoderSim;
import org.team199.wpiws.devices.GyroSim;
import org.team199.wpiws.devices.HALSim;
import org.team199.wpiws.devices.JoystickSim;
import org.team199.wpiws.devices.PCMSim;
import org.team199.wpiws.devices.PWMSim;
import org.team199.wpiws.devices.RelaySim;
import org.team199.wpiws.devices.RoboRIOSim;
import org.team199.wpiws.devices.SimDeviceSim;
import org.team199.wpiws.devices.SolenoidSim;
import org.team199.wpiws.devices.dPWMSim;
import org.team199.wpiws.interfaces.DeviceMessageProcessor;
import org.carlmontrobotics.wpiws.devices.AccelerometerSim;
import org.carlmontrobotics.wpiws.devices.AddressableLEDSim;
import org.carlmontrobotics.wpiws.devices.AnalogInputSim;
import org.carlmontrobotics.wpiws.devices.AnalogOutputSim;
import org.carlmontrobotics.wpiws.devices.CANAccelerometerSim;
import org.carlmontrobotics.wpiws.devices.CANAnalogInputSim;
import org.carlmontrobotics.wpiws.devices.CANDIOSim;
import org.carlmontrobotics.wpiws.devices.CANDutyCycleSim;
import org.carlmontrobotics.wpiws.devices.CANEncoderSim;
import org.carlmontrobotics.wpiws.devices.CANGyroSim;
import org.carlmontrobotics.wpiws.devices.CANMotorSim;
import org.carlmontrobotics.wpiws.devices.DIOSim;
import org.carlmontrobotics.wpiws.devices.DriverStationSim;
import org.carlmontrobotics.wpiws.devices.DutyCycleSim;
import org.carlmontrobotics.wpiws.devices.EncoderSim;
import org.carlmontrobotics.wpiws.devices.GyroSim;
import org.carlmontrobotics.wpiws.devices.HALSim;
import org.carlmontrobotics.wpiws.devices.JoystickSim;
import org.carlmontrobotics.wpiws.devices.PCMSim;
import org.carlmontrobotics.wpiws.devices.PWMSim;
import org.carlmontrobotics.wpiws.devices.RelaySim;
import org.carlmontrobotics.wpiws.devices.RoboRIOSim;
import org.carlmontrobotics.wpiws.devices.SimDeviceSim;
import org.carlmontrobotics.wpiws.devices.SolenoidSim;
import org.carlmontrobotics.wpiws.devices.dPWMSim;
import org.carlmontrobotics.wpiws.interfaces.DeviceMessageProcessor;

/**
* Manages a list of {@link DeviceMessageProcessor} objects which handle messages for different device types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;

/**
* Represents a Runnable which is being run in another {@link Thread}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;

import java.net.ConnectException;
import java.net.InetSocketAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Manages low level interfacing with WebSockets and basic WPI HALSim protocol processing and formatting
*/
package org.team199.wpiws.connection;
package org.carlmontrobotics.wpiws.connection;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which accepts a boolean value as data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

import java.util.List;

import org.team199.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.connection.WSValue;

/**
* Represents a function which processes WPI HALSim messages for a specific device type
* @see org.team199.wpiws.connection.MessageProcessor
* @see org.carlmontrobotics.wpiws.connection.MessageProcessor
*/
@FunctionalInterface
public interface DeviceMessageProcessor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which accepts a double value as data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a function which is equivalent to {@link java.util.function.Consumer} with the ability to throw an {@link Exception}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which accepts a integer value as data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which accepts a long value as data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which accepts an object type as data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a device callback which only accepts the name of a device
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* All required {@link java.lang.FunctionalInterface} interfaces used in this API
*/
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Code to interface with the WebSockets API of WPILib
*/
package org.team199.wpiws;
package org.carlmontrobotics.wpiws;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.types;
package org.carlmontrobotics.wpiws.types;

import com.github.cliftonlabs.json_simple.JsonObject;
import com.github.cliftonlabs.json_simple.Jsonable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.team199.wpiws;
package org.carlmontrobotics.wpiws;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.team199.wpiws.connection.MessageProcessor;
import org.team199.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.connection.MessageProcessor;
import org.carlmontrobotics.wpiws.connection.WSValue;

/**
* Provides various utility functions for other test classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.devices;
package org.carlmontrobotics.wpiws.devices;

import static org.junit.Assert.*;
import static org.junit.Assume.*;
Expand All @@ -15,6 +15,20 @@
import java.util.function.Function;
import java.util.function.Supplier;

import org.carlmontrobotics.wpiws.Pair;
import org.carlmontrobotics.wpiws.TestUtils;
import org.carlmontrobotics.wpiws.connection.ConnectionProcessor;
import org.carlmontrobotics.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.devices.AccelerometerSim;
import org.carlmontrobotics.wpiws.devices.AddressableLEDSim;
import org.carlmontrobotics.wpiws.devices.AnalogInputSim;
import org.carlmontrobotics.wpiws.devices.DIOSim;
import org.carlmontrobotics.wpiws.devices.DriverStationSim;
import org.carlmontrobotics.wpiws.devices.JoystickSim;
import org.carlmontrobotics.wpiws.interfaces.BooleanCallback;
import org.carlmontrobotics.wpiws.interfaces.ObjectCallback;
import org.carlmontrobotics.wpiws.interfaces.TriFunction;
import org.carlmontrobotics.wpiws.types.LEDColor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
Expand All @@ -25,14 +39,6 @@
import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
import org.mockito.MockedStatic;
import org.team199.wpiws.Pair;
import org.team199.wpiws.TestUtils;
import org.team199.wpiws.connection.ConnectionProcessor;
import org.team199.wpiws.connection.WSValue;
import org.team199.wpiws.interfaces.BooleanCallback;
import org.team199.wpiws.interfaces.ObjectCallback;
import org.team199.wpiws.interfaces.TriFunction;
import org.team199.wpiws.types.LEDColor;

import com.github.cliftonlabs.json_simple.JsonArray;
import com.github.cliftonlabs.json_simple.JsonException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.devices;
package org.carlmontrobotics.wpiws.devices;

import static org.junit.Assert.*;
import static org.junit.Assume.*;
Expand All @@ -8,6 +8,14 @@
import java.util.ArrayList;
import java.util.Arrays;

import org.carlmontrobotics.wpiws.Pair;
import org.carlmontrobotics.wpiws.TestUtils;
import org.carlmontrobotics.wpiws.connection.ConnectionProcessor;
import org.carlmontrobotics.wpiws.connection.WSValue;
import org.carlmontrobotics.wpiws.devices.SimDeviceSim;
import org.carlmontrobotics.wpiws.interfaces.ObjectCallback;
import org.carlmontrobotics.wpiws.interfaces.SimDeviceCallback;
import org.carlmontrobotics.wpiws.interfaces.TriConsumer;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
Expand All @@ -18,13 +26,6 @@
import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
import org.mockito.MockedStatic;
import org.team199.wpiws.Pair;
import org.team199.wpiws.TestUtils;
import org.team199.wpiws.connection.ConnectionProcessor;
import org.team199.wpiws.connection.WSValue;
import org.team199.wpiws.interfaces.ObjectCallback;
import org.team199.wpiws.interfaces.SimDeviceCallback;
import org.team199.wpiws.interfaces.TriConsumer;

@RunWith(Enclosed.class)
public class SimDeviceSimTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a function that accepts three arguments and does not return a value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.team199.wpiws.interfaces;
package org.carlmontrobotics.wpiws.interfaces;

/**
* Represents a function that accepts three arguments and returns a value.
Expand Down

0 comments on commit aa8450d

Please sign in to comment.