|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openuat.sensors.AsciiLineReaderBase
public abstract class AsciiLineReaderBase
This is a base class for reading from sensors that are represented by simple files and output ASCII lines, with one line for each sample. It handles registering of sinks and sending sample events to them as well as managing a background thread for sampling the values. The parseLine method must be implemented by derived classes, which is expected to call the emitSample method to send out the samples to all registered sinks.
| Field Summary | |
|---|---|
protected int |
maxNumLines
The maximum number of data lines to read from the device - depends on the sensor. |
protected java.io.InputStream |
port
This represent the file to read from and is opened in the constructor. |
| Constructor Summary | |
|---|---|
protected |
AsciiLineReaderBase(java.io.InputStream stream,
int maxNumLines)
Initializes the reader base object. |
protected |
AsciiLineReaderBase(int maxNumLines)
Initializes the reader base object. |
protected |
AsciiLineReaderBase(java.lang.String filename,
int maxNumLines)
Initializes the reader base object. |
| Method Summary | |
|---|---|
void |
addSink(int[] lines,
SamplesSink[] sink)
Registers a sink, which will receive all new values as they are sampled. |
void |
dispose()
This causes the reader to be shut down properly by calling stop() and making sure that all ressources are freed properly when this object is garbage collected. |
protected void |
emitSample(double[] sample)
This method should be called by the parseLine method to send samples to all registered listeners. |
int |
getMaxNumLines()
Returns the maximum number of lines that can be sampled. |
protected abstract void |
parseLine(java.lang.String line)
|
boolean |
removeSink(int[] lines,
SamplesSink[] sink)
Removes a previously registered sink. |
void |
simulateSampling()
Simulate sampling by reading all available lines from the spcified file. |
void |
start()
Starts a new background thread to read from the file and create sample values as the lines are read. |
void |
stop()
Stops the background thread, if started previously. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int maxNumLines
protected java.io.InputStream port
AsciiLineReaderBase(String, int)| Constructor Detail |
|---|
protected AsciiLineReaderBase(java.lang.String filename,
int maxNumLines)
throws java.io.FileNotFoundException
filename - The log to read from. This may either be a normal log file
when simulation is intended or it can be a FIFO/pipe to read
online data.maxNumLines - The maximum number of data lines to read from the device -
depends on the sensor.
java.io.FileNotFoundException - When filename does not exist or can not be opened.
protected AsciiLineReaderBase(java.io.InputStream stream,
int maxNumLines)
stream - Specifies the InputStream to read from.maxNumLines - The maximum number of data lines to read from the device -
depends on the sensor.and should only be used
in special cases.protected AsciiLineReaderBase(int maxNumLines)
| Method Detail |
|---|
public void addSink(int[] lines,
SamplesSink[] sink)
throws java.lang.IllegalArgumentException
sink - The time series to fill. This array must have the same number of
elements as the number of lines specified to the constructor.lines - The set of lines on the device to read. Must be an integer
array with a minimum length of 1 and a maximum length specified to
the constructor, containing the indices of the lines to read. These
indices are counted from 0 to maxNumLines-1. E.g. for a parallel
port (see ParallelPortPWMReader), this corresponds to data lines
DATA0 to DATA7. E.g. for a 3D accelerometer (see WiTiltRawReader),
this corresponds to 0=X, 1=Y, 2=Z.
java.lang.IllegalArgumentException
public boolean removeSink(int[] lines,
SamplesSink[] sink)
sink - The time series to stop filling.lines - The set of lines with which this sink has been registered.
addSink(int[], SamplesSink[])public void start()
public void stop()
public void simulateSampling()
throws java.io.IOException
java.io.IOExceptionpublic void dispose()
public int getMaxNumLines()
protected void emitSample(double[] sample)
sample - The current sample.protected abstract void parseLine(java.lang.String line)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||