edu.nau.cs.scu
Class SignalInterpreter

java.lang.Object
  extended by edu.nau.cs.scu.SignalInterpreter

public class SignalInterpreter
extends java.lang.Object

This class provides the methods for sending and receiving signals over a serial port. Calling enumeratePorts() will initialize the communications drivers. The comm port can be set using setPort(CommPortIdentifier). When the port is set, the communication is still not started. Communication can be started using enableCommunication(). Communications can be stopped using disableCommunication().

Author:
Sam Mallon

Field Summary
static int COMM_PORT_TIMEOUT
          This constant defines how long the communications driver should wait (in milliseconds) when trying to open a port.
 
Method Summary
static byte calculateChecksum(byte[] command)
          This method calculates the checksum of a command byte packet.
 void disableCommunication()
          This will stop communications on the current port.
 boolean enableCommunication()
          This is the method used to start communications on a port which was previously selected using setPort(CommPortIdentifier).
 javax.comm.CommPortIdentifier[] enumeratePorts()
          The first call to this method will initialize the serial communications drivers.
 void forceCommunicationBreak(boolean forceBreak)
          This method is used to force a break in communication.
static SignalInterpreter getInstance()
          This method is used to retrieve the singleton instance of the SignalInterpreter
 boolean isCommunicating()
          This returns whether the SignalInterpreter currently has open communications on a serial port.
 void setPort(javax.comm.CommPortIdentifier port)
          Sets the port for future communication.
 void setSerialConfig(SerialConfiguration sc)
          Set the baud rate and serial communication configuration.
 boolean write(byte[] response)
          This method is used to write information to to the serial port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMM_PORT_TIMEOUT

public static final int COMM_PORT_TIMEOUT
This constant defines how long the communications driver should wait (in milliseconds) when trying to open a port.

See Also:
Constant Field Values
Method Detail

getInstance

public static SignalInterpreter getInstance()
This method is used to retrieve the singleton instance of the SignalInterpreter

Returns:
SignalInterpreter

calculateChecksum

public static byte calculateChecksum(byte[] command)
This method calculates the checksum of a command byte packet. This checksum calculation is specific to Commands. It will not work on Status packets.

Parameters:
command - The byte packet to calculate the checksum for
Returns:
The checksum of the command packet.

enableCommunication

public boolean enableCommunication()
                            throws javax.comm.PortInUseException,
                                   javax.comm.UnsupportedCommOperationException,
                                   java.io.IOException,
                                   java.lang.NoClassDefFoundError
This is the method used to start communications on a port which was previously selected using setPort(CommPortIdentifier). If no port has been previously selected, this method will fail.

Returns:
A boolean indicating if starting communications was successful.
Throws:
javax.comm.PortInUseException - If the port is currently being used by another application. Establishing communications failed
javax.comm.UnsupportedCommOperationException - If setting the port baud rate and configuration fails. Communications will still be operational, but may not operate correctly
java.io.IOException - If there was a problem opening the port. Establishing communications failed.
java.lang.NoClassDefFoundError - If the serial communications driver is not loaded.

write

public boolean write(byte[] response)
This method is used to write information to to the serial port. It is used primarily by the ResponseGenerator to send status responses to the MEU. This method has a special behavior when a break in serial communication is being forced. It will not write the packet to the stream, but will still return true as if it succeeded in writing the packet.

Parameters:
response - The byte packet to write to the serial stream.
Returns:
Whether the write was successful

forceCommunicationBreak

public void forceCommunicationBreak(boolean forceBreak)
This method is used to force a break in communication. Packets will still be read from the serial port and communications will remain active, but the packets will be ignored.

Parameters:
forceBreak - If true, a break will be forced in communication

disableCommunication

public void disableCommunication()
This will stop communications on the current port. No further activity will occur until enableCommunication() is called again.


isCommunicating

public boolean isCommunicating()
This returns whether the SignalInterpreter currently has open communications on a serial port.

Returns:
Whether the SignalInterpreter is communicating

setPort

public void setPort(javax.comm.CommPortIdentifier port)
Sets the port for future communication. Communications will be stopped on the current port, and communications will not be started on the new port until enableCommunication() is called again.

Parameters:
port - The port to communicate on.

setSerialConfig

public void setSerialConfig(SerialConfiguration sc)
                     throws javax.comm.UnsupportedCommOperationException
Set the baud rate and serial communication configuration. Will change the configuration for current and all future communications.

Parameters:
sc - The SerialConfiguration enumeration detailing the settings
Throws:
javax.comm.UnsupportedCommOperationException - If the chosen baud rate and settings are not supported. Communications are still running, but may operate in unpredictable ways.

enumeratePorts

public javax.comm.CommPortIdentifier[] enumeratePorts()
                                               throws java.lang.NoClassDefFoundError
The first call to this method will initialize the serial communications drivers. It lists all of the available serial ports in the system.

Returns:
An array of the available serial ports in the system.
Throws:
java.lang.NoClassDefFoundError - If the serial communications drivers are not loaded in the system