SerialPort
Class SPDMessage

java.lang.Object
  extended bySerialPort.SPDMessage

public class SPDMessage
extends java.lang.Object

This class contains a message sent to and received from the serial port server, spd. Its methods are used for assembling, unpacking and retrieving the message.

This class is not normally accessible to the calling program. It is used internally by the SerialPort class and no references to SPDMessage objects are returned to the caller.

Messages consist of a command field and a value field: Both fields must be present, but the value field may be empty. Messages sent to the server use the command field to request an action to be taken with parameters sent in the value field. Messages received from the server are always a response to the previous command. Here the command field indicates whether the value is a valid response to the request or an error response.

The environ jar file must be in the classpath for this class to compile and at run time.

 SerialPort - serial connections for Java
 Copyright (C) 2005  Martin C Gregorie
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 

Contact Martin Gregorie at martin@gregorie.org.
Read the GNU General Public License.


Constructor Summary
SPDMessage(int debug)
          Construct an empty message object and set the debugging level.
SPDMessage(java.lang.String msg, int debug)
          Construct an SPDMessage object from a received message.
 
Method Summary
 void buildMessage(java.lang.String cmd, java.lang.String val)
          Assemble a message from its components.
 java.lang.String getCommand()
          Retrieve the command field.
 java.lang.String getMessage()
          Retrieve the message.
 java.lang.String getValue()
          Retrieve the value field.
 int length()
          Retrieve the message length.
 int unpackMessage()
          Unpack a message, extracting the command and value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPDMessage

public SPDMessage(java.lang.String msg,
                  int debug)
Construct an SPDMessage object from a received message. Set the debugging level. unpackMessage() must be invoked before any other methods if this constructor is used.


SPDMessage

public SPDMessage(int debug)
Construct an empty message object and set the debugging level. buildMessage() must be invoked before any other methods if this constructor is used.

Method Detail

buildMessage

public void buildMessage(java.lang.String cmd,
                         java.lang.String val)
Assemble a message from its components.


unpackMessage

public int unpackMessage()
Unpack a message, extracting the command and value. The length of the value is returned. Use getCommand() and getValue() to retrieve the message components.


getMessage

public java.lang.String getMessage()
Retrieve the message. This method is used to extract a message for sending to the server.


getCommand

public java.lang.String getCommand()
Retrieve the command field.


getValue

public java.lang.String getValue()
Retrieve the value field.


length

public int length()
Retrieve the message length.