org.discotools.io.aprs.tnc
Class TncProtocol

java.lang.Object
  extended by org.discotools.io.AbstractProtocol<T>
      extended by org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>
          extended by org.discotools.io.aprs.tnc.TncProtocol
All Implemented Interfaces:
org.discotools.io.Protocol<AprsPacket>

public final class TncProtocol
extends org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>

This class implements the terminal mode protocol.

Author:
Kenneth Gulbrandsøy - 13. May 2012

Field Summary
static String A_BATCH
          TNC batch action: Executes a TncDialect batch.
static String A_CANCEL
          TNC batch cancel action: Cancels current TncDialect batch.
static String A_CLOSE
          AbstractConnection.close() action: The connection has been closed, which forces the protocol to S_IDLE state.
static String A_CONTINUE
          TNC continue batch action: returns FSM to batch state.
static String A_DONE
          TNC command done action: Completes current TncDialect command.
static String A_END
          TNC batch end action: Ends current TncDialect batch.
static String A_EXECUTE
          TNC command execute action: Executes a TncDialect command.
static String A_NEXT
          TNC next batch step action: Executes a TncDialect command.
static String A_OPEN
          SerialConnection#open(org.discotools.io.IProtocol) action: The connection has been open, which forces the protocol to S_OPEN state.
static String S_BATCH
          TNC batch state: The protocol is executing a TncDialect batch.
static String S_COMMAND
          TNC command state: The protocol is executing a TncDialect command.
static String S_IDLE
          TNC idle state: SerialConnection is closed.
static String S_OPEN
          TNC open state: SerialConnection is open.
static String S_STEP
          TNC batch step state: The protocol is executing a batch step.
 
Fields inherited from class org.discotools.io.fsm.FsmProtocol
common, parser, S_COMMON
 
Fields inherited from class org.discotools.io.AbstractProtocol
DEFAULT_SIZE, head, isOpen, rb, size, tail, tb
 
Constructor Summary
TncProtocol(TncDialect dialect)
          Dialect constructor
TncProtocol(TncDialect dialect, AprsCache cache)
          Cache constructor
 
Method Summary
 boolean addListener(org.discotools.fsm.event.FsmListener listener)
          Add FsmListener to TNC finite state machine instance
protected  org.discotools.fsm.Fsm createFsm(org.discotools.io.fsm.FsmProtocolState idle)
          Create TNC FSM instance.
protected  org.discotools.io.fsm.FsmProtocolState createState(String name, boolean isParseable)
           
 boolean execute(org.discotools.io.Connection<AprsPacket> connection, String sentence, Object... params)
          Execute given sentence.
 AprsCache getCache()
           
 TncState getState()
           
protected  void internalClose(org.discotools.io.Connection<AprsPacket> connection)
           
protected  boolean internalOpen(org.discotools.io.Connection<AprsPacket> connection, Map<String,? extends Object> options)
           
 boolean removeListener(org.discotools.fsm.event.FsmListener listener)
          Remove FsmListener from Terminal Finite State Machine instance
 
Methods inherited from class org.discotools.io.fsm.FsmProtocol
getCurrentState, getFsm, getParser, handle, internalParse, merge, setFsm, toState
 
Methods inherited from class org.discotools.io.AbstractProtocol
addListener, assertClose, assertOpen, close, fireOnReceive, fireOnTransmit, getListeners, internalReceive, internalTransmit, isHead, isOpen, isTail, open, open, receive, receive, receive, receive, receive, removeListener, toBytes, toBytes, toString, transmit, transmit, transmit, transmit, transmit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A_CLOSE

public static final String A_CLOSE
AbstractConnection.close() action: The connection has been closed, which forces the protocol to S_IDLE state.

See Also:
Constant Field Values

S_IDLE

public static final String S_IDLE
TNC idle state: SerialConnection is closed.

See Also:
Constant Field Values

A_OPEN

public static final String A_OPEN
SerialConnection#open(org.discotools.io.IProtocol) action: The connection has been open, which forces the protocol to S_OPEN state.

See Also:
Constant Field Values

S_OPEN

public static final String S_OPEN
TNC open state: SerialConnection is open.

See Also:
Constant Field Values

A_BATCH

public static final String A_BATCH
TNC batch action: Executes a TncDialect batch.

See Also:
Constant Field Values

S_BATCH

public static final String S_BATCH
TNC batch state: The protocol is executing a TncDialect batch.

See Also:
Constant Field Values

A_NEXT

public static final String A_NEXT
TNC next batch step action: Executes a TncDialect command.

See Also:
Constant Field Values

S_STEP

public static final String S_STEP
TNC batch step state: The protocol is executing a batch step.

See Also:
Constant Field Values

A_EXECUTE

public static final String A_EXECUTE
TNC command execute action: Executes a TncDialect command.

See Also:
Constant Field Values

S_COMMAND

public static final String S_COMMAND
TNC command state: The protocol is executing a TncDialect command.

See Also:
Constant Field Values

A_DONE

public static final String A_DONE
TNC command done action: Completes current TncDialect command.

See Also:
Constant Field Values

A_CONTINUE

public static final String A_CONTINUE
TNC continue batch action: returns FSM to batch state.

See Also:
Constant Field Values

A_CANCEL

public static final String A_CANCEL
TNC batch cancel action: Cancels current TncDialect batch.

See Also:
Constant Field Values

A_END

public static final String A_END
TNC batch end action: Ends current TncDialect batch.

See Also:
Constant Field Values
Constructor Detail

TncProtocol

public TncProtocol(TncDialect dialect)
Dialect constructor


TncProtocol

public TncProtocol(TncDialect dialect,
                   AprsCache cache)
Cache constructor

Method Detail

getCache

public AprsCache getCache()

getState

public TncState getState()

execute

public boolean execute(org.discotools.io.Connection<AprsPacket> connection,
                       String sentence,
                       Object... params)
                throws org.discotools.fsm.FsmException
Execute given sentence.

NOTE: Execution is only possible when getState() is S_OPEN.

Parameters:
connection -
sentence -
params -
Returns:
true if passed to TNC, false otherwise.
Throws:
org.discotools.fsm.FsmException

addListener

public boolean addListener(org.discotools.fsm.event.FsmListener listener)
Add FsmListener to TNC finite state machine instance

Overrides:
addListener in class org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>
Parameters:
listener -
Returns:
true if added.

removeListener

public boolean removeListener(org.discotools.fsm.event.FsmListener listener)
Remove FsmListener from Terminal Finite State Machine instance

Overrides:
removeListener in class org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>
Parameters:
listener -
Returns:
true if added.

createState

protected org.discotools.io.fsm.FsmProtocolState createState(String name,
                                                             boolean isParseable)
Overrides:
createState in class org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>

createFsm

protected org.discotools.fsm.Fsm createFsm(org.discotools.io.fsm.FsmProtocolState idle)
Create TNC FSM instance.

NOTE: Following parseable states share receive and transmit buffers.

  1. S_IDLE
  2. S_OPEN
  3. S_BATCH
  4. S_STEP
  5. S_COMMAND
which enables this protocol to parse payload into AprsPacket regardless of protocol state, except in S_IDLE.

Overrides:
createFsm in class org.discotools.io.fsm.FsmProtocol<AprsPacket,TncParser>

internalOpen

protected boolean internalOpen(org.discotools.io.Connection<AprsPacket> connection,
                               Map<String,? extends Object> options)
                        throws IOException
Overrides:
internalOpen in class org.discotools.io.AbstractProtocol<AprsPacket>
Throws:
IOException

internalClose

protected void internalClose(org.discotools.io.Connection<AprsPacket> connection)
                      throws IOException
Overrides:
internalClose in class org.discotools.io.AbstractProtocol<AprsPacket>
Throws:
IOException


Copyright © 2012-2013 DISCO Foundation. All Rights Reserved.