lejos.pc.charting
Class LoggerProtocolManager

java.lang.Object
  extended by lejos.pc.charting.LoggerProtocolManager

public class LoggerProtocolManager
extends java.lang.Object

This class provides the communications protocol manager for receiving and processing messages from the lejos.util.NXTDataLogger class. It uses an event model for notifications of the events specified in LoggerListener.

Author:
Kirk P. Thompson
See Also:
LoggerComms, LoggerListener, lejos.util.NXTDataLogger

Constructor Summary
LoggerProtocolManager(java.io.InputStream is, java.io.OutputStream os)
          Create a LoggerProtocolManager instance.
 
Method Summary
 void addLoggerListener(LoggerListener listener)
          Register a LoggerListener so data can be managed and acted upon when it is received from the NXT.
static java.lang.String parseLogData(DataItem[] logDataItems)
          Parse an array of DataItems and return a formatted string suitable for logging
 boolean removeLoggerListener(LoggerListener listener)
          Remove a logger listener.
 void startListen()
          Start listening for and processing logging data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggerProtocolManager

public LoggerProtocolManager(java.io.InputStream is,
                             java.io.OutputStream os)
                      throws java.io.IOException
Create a LoggerProtocolManager instance.

You must register a LoggerListener to receive logging events. The connection must already be established and the passed InputStream and OutputStream are valid or IOException is thrown.

Parameters:
is - The established connection's InputStream from the NXT
Throws:
java.io.IOException - If the passed input or output stream is null
See Also:
LoggerComms, startListen(), addLoggerListener(lejos.pc.charting.LoggerListener)
Method Detail

addLoggerListener

public void addLoggerListener(LoggerListener listener)
Register a LoggerListener so data can be managed and acted upon when it is received from the NXT.

Parameters:
listener - The LoggerListener instance to register
See Also:
LoggerListener, removeLoggerListener(lejos.pc.charting.LoggerListener)

removeLoggerListener

public boolean removeLoggerListener(LoggerListener listener)
Remove a logger listener.

Parameters:
listener - The LoggerListener instance to de-register
Returns:
true if passed listener was removed. false if passed listener was not registered to begin with.
See Also:
LoggerListener, addLoggerListener(lejos.pc.charting.LoggerListener)

startListen

public void startListen()
                 throws java.io.IOException
Start listening for and processing logging data. After the NXT closes the connection (i.e. on EOF or other IOException), the dataInputStreamEOF() method is invoked on registered LoggerListeners, the logging session ends, and this instance is no longer connected. A new instance must be created to log again.

Throws:
java.io.IOException - if connection has not been established
See Also:
LoggerListener

parseLogData

public static java.lang.String parseLogData(DataItem[] logDataItems)
Parse an array of DataItems and return a formatted string suitable for logging

Parameters:
logDataItems -
Returns:
A formatted string representation of the DataItems
See Also:
DataItem