-
Notifications
You must be signed in to change notification settings - Fork 12
Extending the Framework
In general, the framework consists of the following components:
- Sensors - provide data to the pipeline (only output)
- Transformers - modify data within the pipeline (input + output)
- Consumers - take data from the pipeline and perform an external action (only input)
To create your own components you can follow the steps below.
The first step is to integrate a new sensor is to create a new Java class that extends the abstract Sensor
class.
import hcm.ssj.core.Sensor;
public class MySensor extends Sensor
{
}
Afterwards, implement the abstract connect()
, disconnect()
and getOptions()
methods. The basic structure should look like this:
import hcm.ssj.core.Log;
import hcm.ssj.core.SSJFatalException;
import hcm.ssj.core.Sensor;
import hcm.ssj.core.option.Option;
import hcm.ssj.core.option.OptionList;
public class MySensor extends Sensor
{
public class Options extends OptionList
{
// Specify your options here
public final Option<String> myStringOption = new Option<>("myStringOption", "default value", String.class, "option description");
public final Option<Boolean> myBooleanOption = new Option<>("myBooleanOption", true, Boolean.class, "option description");
public final Option<Float> myFloatOption = new Option<>("myFloatOption", 1.0f, Float.class, "option description");
public final Option<Integer> myIntOption = new Option<>("myIntOption", 1, Integer.class, "option description");
private Options()
{
addOptions();
}
}
public final Options options = new Options();
public MySensor()
{
// Set custom name for your sensor component (shows up in SSJ Creator)
_name = "MySensor";
}
@Override
public OptionList getOptions()
{
return options;
}
@Override
protected boolean connect() throws SSJFatalException
{
boolean connected = false;
// Example for accessing your options
if (options.myBooleanOption.get())
{
// Example for using the integrated logger
Log.i("String option value: " + options.myStringOption.get());
}
// Establish connection to your sensor here
// Return true if connected successfully
connected = true;
return connected;
}
@Override
protected void disconnect() throws SSJFatalException
{
// Disconnect from your sensor here and perform cleanup
}
}
In addition to the Sensor
component which handles the connection to the sensor, at least one SensorChannel
component needs to be created that is responsible for providing the sensor data to the pipeline. It is also common that a sensor can have multiple channels (e.g., if you want to integrate a wearable device that provides the heart rate and accelerometer data via bluetooth, then you would create a sensor component that handles the bluetooth connection and two sensor channels - one that provides the heart rate and another one for the accelerometer data).
To create a sensor channel component simply create a new Java class and extend the abstract SensorChannel
class.
import hcm.ssj.core.SensorChannel;
public class MySensorChannel extends SensorChannel
{
}