org.discotools.io.aprs.tnc
Class TncDialect

java.lang.Object
  extended by org.discotools.io.aprs.tnc.TncDialect

public class TncDialect
extends Object

TNC terminal mode dialect declaration class.

Terminal mode allows clients to communicate with the TNC using “english-like” command strings.

Following sentences are required:

  1. S_HEAD - Packet header sequence

Author:
kengu - 8. mai 2012

Field Summary
static String A_DELIMITER
          DELIMITER argument in a dialect understood by target TNC (TERMINAL mode only).
static String A_OFF
          OFF argument in a dialect understood by target TNC.
static String A_ON
          ON argument in a dialect understood by target TNC.
static String B_RESET
          RESET command batch in a dialect understood by target TNC.
static String B_SETUP
          SETUP command batch in a dialect understood by target TNC.
static String C_BAUD
          BAUD command in a dialect understood by target TNC (TERMINAL mode only).
static String C_COMMENT
          COMMENT command in a dialect understood by target TNC (TERMINAL mode only).
static String C_COMPRESS
          COMPRESS command in a dialect understood by target TNC (TERMINAL mode only).
static String C_DISPLAY
          DISPLAY command in a dialect understood by target TNC (TERMINAL mode only).
static String C_MODE
          MODE command in a dialect understood by target TNC (TERMINAL mode only).
static String C_MYCALL
          MYCALL command in a dialect understood by target TNC (TERMINAL mode only).
static String C_POSITION
          POSITION command in a dialect understood by target TNC (TERMINAL mode only).
static String C_STATUS
          STATUS command in a dialect understood by target TNC (TERMINAL mode only).
static String C_SYMBOL
          SYMBOL command in a dialect understood by target TNC (TERMINAL mode only).
static String C_TIMESTAMP
          TIMESTAMP command in a dialect understood by target TNC (TERMINAL mode only).
static String C_VELOCITY
          VELOCITY command in a dialect understood by target TNC (TERMINAL mode only).
static String C_VERSION
          VERSION command in a dialect understood by target TNC (TERMINAL mode only).
static String D_DELIMITER
          Default delimiter.
static String D_OFF
          Default OFF argument value.
static String D_ON
          Default ON argument value.
static String D_TIMEOUT
          Default timeout (in milliseconds).
static String K_ENTER
          ENTER key in a dialect understood by target TNC (TERMINAL mode only).
static String R_BAUD
          TNC response to C_BAUD.
static String R_COMMENT
          TNC response to C_COMMENT.
static String R_COMPRESS
          TNC response to C_COMPRESS.
static String R_DISPLAY
          TNC response to C_DISPLAY.
static String R_MODE
          TNC response to C_MODE.
static String R_MYCALL
          TNC response to C_MYCALL.
static String R_POSITION
          TNC response to C_POSITION.
static String R_RESET
          TNC response to B_RESET.
static String R_SETUP
          TNC responses to B_SETUP.
static String R_STATUS
          TNC response to C_STATUS.
static String R_SYMBOL
          TNC response to C_SYMBOL.
static String R_TERMINAL
          Command prompt text returned by TNC in TERMINAL mode as a response to K_ENTER without any command text.
static String R_TIMESTAMP
          TNC response to C_TIMESTAMP.
static String R_VELOCITY
          TNC response to C_VELOCITY.
static String R_VERSION
          TNC response to C_VERSION.
static Set<String> REQUIRED
          Set of required sentences.
static String S_HEAD
          Characters which mark the start of a TNC terminal mode sentence.
static String S_TAIL
          Characters which mark the end of a TNC terminal mode sentence.
static String S_TIMEOUT
          TNC terminal mode sentence timeout (in milliseconds).
 
Constructor Summary
TncDialect(InputStream dialect)
          Construct dialect from InputStream The stream is kept open after this construction
TncDialect(Properties dialect)
          Construct dialect from Properties Given properties are copied (dialects are immutable)
TncDialect(String file)
          Construct dialect from file.
TncDialect(URL url)
          Construct dialect from URL.
 
Method Summary
 String[] batch(String sentence, Object... args)
          Lookup command batch
 String command(String sentence, boolean isOn)
          Lookup command on the format: COMMAND ON | OFF
 String command(String sentence, Object... args)
          Lookup command on the format: COMMAND [arg1...
 String get(String sentence)
          Lookup given dialect sentence (see public constants).
 String get(String sentence, String use)
          Lookup given dialect sentence (see public constants).
 String getCOMMENT(String comment)
          Lookup C_COMMENT command.
 String getCOMPRESS(boolean isOn)
          Lookup C_COMPRESS command.
 String getDELIMITER()
          Lookup A_DELIMITER argument value.
 String getENTER()
          Lookup K_ENTER key.
 byte[] getHEAD()
          Lookup sentence S_HEAD (terminator).
 String getOFF()
          Lookup A_OFF argument value.
 String getON()
          Lookup A_ON argument value.
 String getPOSITION(String argument)
          Lookup C_POSITION command.
 String getRESET()
          Lookup B_RESET command
 String getSETUP()
          Lookup B_SETUP command batch
 byte[] getTAIL()
          Lookup sentence S_TAIL (terminator).
 String getTERMINAL()
          Lookup R_TERMINAL response value.
 String getTIMEOUT()
          Lookup sentence S_TIMEOUT value.
 boolean isBatch(String sentence)
          Check if given string is a supported command.
 boolean isCommand(String sentence)
          Check if given string is a supported command.
 boolean isResponse(String command, String response)
          Check if given payload is response to given command.
 boolean isTerminal(String response)
          Check if given string is a R_TERMINAL response.
protected  void prepare()
           
 boolean supports(String sentence)
          Check if TNC supports (understand) given sentence
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

S_HEAD

public static final String S_HEAD
Characters which mark the start of a TNC terminal mode sentence.

NOTE: You can specify any Unicode character with a \uXXXX escape sequence. Use this to encode non-printable ASCII characters.

See Also:
Constant Field Values

S_TAIL

public static final String S_TAIL
Characters which mark the end of a TNC terminal mode sentence.

NOTE: You can specify any Unicode character with a \uXXXX escape sequence. Use this to encode non-printable ASCII characters.

See Also:
Constant Field Values

S_TIMEOUT

public static final String S_TIMEOUT
TNC terminal mode sentence timeout (in milliseconds).

Used by TncProtocol to determine command response timeout. Default value is "1000".

See Also:
#D_TIMEOUT}., Constant Field Values

A_ON

public static final String A_ON
ON argument in a dialect understood by target TNC.

Default value is "ON".

See Also:
Constant Field Values

A_OFF

public static final String A_OFF
OFF argument in a dialect understood by target TNC.

Default value is "OFF".

See Also:
Constant Field Values

A_DELIMITER

public static final String A_DELIMITER
DELIMITER argument in a dialect understood by target TNC (TERMINAL mode only).

This key delimit each commands in a command batch. Default: ';'

See Also:
TncDialect#B_SETUP} - Setup command batch, TncDialect#B_RESET} - Reset command batch, Constant Field Values

D_ON

public static final String D_ON
Default ON argument value.

See Also:
Constant Field Values

D_OFF

public static final String D_OFF
Default OFF argument value.

See Also:
Constant Field Values

D_DELIMITER

public static final String D_DELIMITER
Default delimiter.

See Also:
Constant Field Values

D_TIMEOUT

public static final String D_TIMEOUT
Default timeout (in milliseconds).

See Also:
Constant Field Values

K_ENTER

public static final String K_ENTER
ENTER key in a dialect understood by target TNC (TERMINAL mode only).

This key instructs the TNC to run previously transmitted command.

See Also:
Constant Field Values

R_TERMINAL

public static final String R_TERMINAL
Command prompt text returned by TNC in TERMINAL mode as a response to K_ENTER without any command text.

String comparison is case-insensitive and regexp is supported.

The framework use this to:

  • detect a TNC in TERMINAL mode
  • determine if a serial connection is down
  • See Also:
    Constant Field Values

    B_SETUP

    public static final String B_SETUP
    SETUP command batch in a dialect understood by target TNC.

    This batch is typically executed by the TncProtocol immediately after a serial connection is established. It is usually a series of commands which enters the TNC into the communication mode implemented by the protocol.

    Each response must be delimited by the D_DELIMITER character.

    For example, a Tracker2 TNC is in terminal mode on port A, but the protocol requested is KISS. The protocol performs a B_SETUP lookup which returns the following commands:

     ABAUD 9600
     AMODE KISS 
     
    which forces the TNC into KISS mode.

    This command batch is accompanied by B_RESET, which is typically executed just before the connection is closed. The general idea here is to leave the TNC in the same state as it was before before #C_SETUP was performed.

    Although this command batch is usually executed in pairs with B_RESET, it could be performed at any point by the client code or the framework if necessary.


    R_SETUP

    public static final String R_SETUP
    TNC responses to B_SETUP.

    Each response must be delimited by the D_DELIMITER character.

    String comparison is case-insensitive and regexp is supported.


    B_RESET

    public static final String B_RESET
    RESET command batch in a dialect understood by target TNC.

    This command is typically executed by the protocol just before the serial connection is closed. The general idea here is to leave the TNC in the same state as it was before before #C_SETUP was performed.

    Each response must be delimited by the D_DELIMITER character.

    Although this command batch is usually executed in pairs with B_SETUP, it could be performed at any point by the client code or the framework if necessary.


    R_RESET

    public static final String R_RESET
    TNC response to B_RESET.

    String comparison is case-insensitive and regexp is supported.


    C_BAUD

    public static final String C_BAUD
    BAUD command in a dialect understood by target TNC (TERMINAL mode only).

    Sets baud rate for serial port.  Default is 4800 baud.


    R_BAUD

    public static final String R_BAUD
    TNC response to C_BAUD.

    String comparison is case-insensitive and regexp is supported.


    C_MODE

    public static final String C_MODE
    MODE command in a dialect understood by target TNC (TERMINAL mode only).

    Sets mode for primary serial port.


    R_MODE

    public static final String R_MODE
    TNC response to C_MODE.

    String comparison is case-insensitive and regexp is supported.


    C_MYCALL

    public static final String C_MYCALL
    MYCALL command in a dialect understood by target TNC (TERMINAL mode only).

    Sets the TNC's callsign and optional SSID: <xxxxxx-nn>


    R_MYCALL

    public static final String R_MYCALL
    TNC response to C_MYCALL.

    String comparison is case-insensitive and regexp is supported.


    C_COMMENT

    public static final String C_COMMENT
    COMMENT command in a dialect understood by target TNC (TERMINAL mode only).

    Sets beacon text / comment string.


    R_COMMENT

    public static final String R_COMMENT
    TNC response to C_COMMENT.

    String comparison is case-insensitive and regexp is supported.


    C_COMPRESS

    public static final String C_COMPRESS
    COMPRESS command in a dialect understood by target TNC (TERMINAL mode only).

    Enables Base91 compressed format for position transmissions.


    R_COMPRESS

    public static final String R_COMPRESS
    TNC response to C_COMPRESS.

    String comparison is case-insensitive and regexp is supported.


    C_POSITION

    public static final String C_POSITION
    POSITION command in a dialect understood by target TNC (TERMINAL mode only).

    Sets fixed position or enable GPS: <hhmm.mmx hhhmm.mmx> | GPS


    R_POSITION

    public static final String R_POSITION
    TNC response to C_POSITION.

    String comparison is case-insensitive and regexp is supported.


    C_STATUS

    public static final String C_STATUS
    STATUS command in a dialect understood by target TNC (TERMINAL mode only).

    Status packets are sent every n transmissions, or if set to 0, status text is sent as part of the position packet.


    R_STATUS

    public static final String R_STATUS
    TNC response to C_STATUS.

    String comparison is case-insensitive and regexp is supported.


    C_SYMBOL

    public static final String C_SYMBOL
    SYMBOL command in a dialect understood by target TNC (TERMINAL mode only).

    APRS symbol character, optionally preceded by symbol table or overlay identifier.


    R_SYMBOL

    public static final String R_SYMBOL
    TNC response to C_SYMBOL.

    String comparison is case-insensitive and regexp is supported.


    C_TIMESTAMP

    public static final String C_TIMESTAMP
    TIMESTAMP command in a dialect understood by target TNC (TERMINAL mode only).

    Report time information in the position packet.


    R_TIMESTAMP

    public static final String R_TIMESTAMP
    TNC response to C_TIMESTAMP.

    String comparison is case-insensitive and regexp is supported.


    C_VELOCITY

    public static final String C_VELOCITY
    VELOCITY command in a dialect understood by target TNC (TERMINAL mode only).

    Enables transmission of velocity (course and speed) information in the position packet.


    R_VELOCITY

    public static final String R_VELOCITY
    TNC response to C_VELOCITY.

    String comparison is case-insensitive and regexp is supported.


    C_DISPLAY

    public static final String C_DISPLAY
    DISPLAY command in a dialect understood by target TNC (TERMINAL mode only).

    Lists all configuration parameters.


    R_DISPLAY

    public static final String R_DISPLAY
    TNC response to C_DISPLAY.

    String comparison is case-insensitive and regexp is supported.


    C_VERSION

    public static final String C_VERSION
    VERSION command in a dialect understood by target TNC (TERMINAL mode only).

    Displays firmware version number.


    R_VERSION

    public static final String R_VERSION
    TNC response to C_VERSION.

    String comparison is case-insensitive and regexp is supported.


    REQUIRED

    public static final Set<String> REQUIRED
    Set of required sentences.

    Constructor Detail

    TncDialect

    public TncDialect(String file)
               throws IOException
    Construct dialect from file.

    Parameters:
    dialect - - InputStream instance
    Throws:
    IOException

    TncDialect

    public TncDialect(URL url)
               throws IOException
    Construct dialect from URL.

    Parameters:
    dialect - - InputStream instance
    Throws:
    IOException
    See Also:
    ClassLoader#getSystemResource(String)}

    TncDialect

    public TncDialect(InputStream dialect)
               throws IOException
    Construct dialect from InputStream

    The stream is kept open after this construction

    Parameters:
    dialect - - InputStream instance
    Throws:
    IOException
    See Also:
    ClassLoader#getSystemResource(String)}

    TncDialect

    public TncDialect(Properties dialect)
    Construct dialect from Properties

    Given properties are copied (dialects are immutable)

    Parameters:
    dialect - - Properties instance
    Method Detail

    supports

    public boolean supports(String sentence)
    Check if TNC supports (understand) given sentence

    Parameters:
    sentence - - see public constants.

    isCommand

    public boolean isCommand(String sentence)
    Check if given string is a supported command.

    Parameters:
    sentence - - sentence part of dialect

    isBatch

    public boolean isBatch(String sentence)
    Check if given string is a supported command.

    Parameters:
    sentence - - sentence part of dialect

    isTerminal

    public boolean isTerminal(String response)
    Check if given string is a R_TERMINAL response.

    Parameters:
    response - - received payload

    isResponse

    public boolean isResponse(String command,
                              String response)
    Check if given payload is response to given command.

    Parameters:
    response - - received payload

    get

    public String get(String sentence)
    Lookup given dialect sentence (see public constants).


    get

    public String get(String sentence,
                      String use)
    Lookup given dialect sentence (see public constants).


    command

    public String command(String sentence,
                          boolean isOn)
    Lookup command on the format: COMMAND ON | OFF

    Parameters:
    sentence - - command sentence
    isOn - - if true, ON is used, OFF otherwise
    Returns:
    a command in a dialect understood by the TNC

    command

    public String command(String sentence,
                          Object... args)
    Lookup command on the format: COMMAND [arg1...[arg2...]]

    Parameters:
    sentence - - command sentence
    args - - optional array
    Returns:
    a command in a dialect understood by the TNC

    batch

    public String[] batch(String sentence,
                          Object... args)
    Lookup command batch

    Parameters:
    sentence - - command sentence
    args - - optional array
    Returns:
    a command in a dialect understood by the TNC

    getHEAD

    public byte[] getHEAD()
    Lookup sentence S_HEAD (terminator).


    getTAIL

    public byte[] getTAIL()
    Lookup sentence S_TAIL (terminator).


    getENTER

    public String getENTER()
    Lookup K_ENTER key.


    getDELIMITER

    public String getDELIMITER()
    Lookup A_DELIMITER argument value.


    getTIMEOUT

    public String getTIMEOUT()
    Lookup sentence S_TIMEOUT value.


    getON

    public String getON()
    Lookup A_ON argument value.


    getOFF

    public String getOFF()
    Lookup A_OFF argument value.


    getTERMINAL

    public String getTERMINAL()
    Lookup R_TERMINAL response value.


    getCOMMENT

    public String getCOMMENT(String comment)
    Lookup C_COMMENT command.


    getCOMPRESS

    public String getCOMPRESS(boolean isOn)
    Lookup C_COMPRESS command.


    getPOSITION

    public String getPOSITION(String argument)
    Lookup C_POSITION command.


    getSETUP

    public String getSETUP()
    Lookup B_SETUP command batch


    getRESET

    public String getRESET()
    Lookup B_RESET command


    toString

    public String toString()
    Overrides:
    toString in class Object

    prepare

    protected void prepare()
                    throws IllegalArgumentException
    Throws:
    IllegalArgumentException


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