wonderly.jeaprs.io.aprs
Class TNCStream

java.lang.Object
  |
  +--wonderly.jeaprs.aprs.APRSStreamHandler
        |
        +--wonderly.jeaprs.io.aprs.TNCStream
All Implemented Interfaces:
APRSEventGenerator, APRSInput, APRSIOModule, APRSOutput, IOModule, TNC

public class TNCStream
extends APRSStreamHandler
implements TNC

This class provides access to a Serial Port connected TNC stream. The device is initialized by a 'tnc.init' file (or kiss.init/kissoff.init) in the current directory of the process (System.getProperty("user.dir"), or by default commands which may work for many generic TNCs.

Version:
1.0
Author:
Gregg Wonderly - The information contained in this document is Copyright 2001-2003, Gregg Wonderly, all rights reserved.

Field Summary
static int C_FLAG
           
static int END_FLAG
           
static int FEND
           
static int FESC
           
protected  wonderly.jeaprs.io.TNCInitialization fileAccess
           
static int FLAG_MASK
           
protected  boolean hardwareFlow
           
static int R1_FLAG
           
static int R2_FLAG
           
static int SSID_MASK
           
static int TFEND
           
static int TFESC
           
 
Fields inherited from interface wonderly.jeaprs.TNC
TNC_TYPE_EHF, TNC_TYPE_HF, TNC_TYPE_NET, TNC_TYPE_UHF, TNC_TYPE_VHF
 
Constructor Summary
TNCStream()
           
 
Method Summary
 void close()
          Close the stream when done
 void flush()
           
 int getBaudRate()
           
 java.lang.String getCommPort()
           
 int getDataBits()
           
 java.io.InputStream getInputStream()
          Returns the input stream for the TNC.
protected  java.io.BufferedReader getKissModeOff()
          Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()
protected  java.io.BufferedReader getKissModeOn()
          Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()
 java.io.OutputStream getOutputStream()
          Returns the output stream for the TNC
 int getParity()
           
 int getStopBits()
           
protected  java.io.BufferedReader getTNCInit()
          Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()
protected  java.io.BufferedReader getTNCReset()
          Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()
 int getTNCType()
          Returns what type this TNC was configured for (TNC_TYPE_*).
 void initialize(wonderly.jeaprs.ui.JeAPRSUI ui)
          Set everything up, open ports etc
 void initTNC()
          Call this method to send the default initialization data to the TNC
 void initTNC(wonderly.jeaprs.io.TNCInitialization init)
          Call this method to initialize the TNC using the passed TNCInitialization instance instead of the default file based initialization.
 boolean isHardwareFlow()
           
 boolean isInitialized()
          Tracks whether initTNC has been called
 boolean isKiss()
           
 void lockTNC(boolean how)
          Causes this object to block/release access to the TNC stream
 void openStream(java.lang.String port)
           
 byte[] readPacket()
          Reads a packet from the TNC.
 void setBaudRate(int v)
           
 void setDataBits(int v)
           
 void setHardwareFlow(boolean how)
           
 void setKiss(boolean how)
          sets the use of KISS mode based on the passed parameter
 void setParity(int v)
           
 void setStopBits(int v)
           
 void setTNCType(int type)
          Sets what type this TNC should be recognized as providing (TNC_TYPE_*).
 void waitReady()
          Waits until the TNC stream is ready to be used
 void write(wonderly.jeaprs.ByteString callstr, wonderly.jeaprs.ByteString toCall, wonderly.jeaprs.ByteString pathstr, byte[] arr)
          Write the data in arr to the TNC 'device'.
 void write(wonderly.jeaprs.ByteString callstr, wonderly.jeaprs.ByteString toCall, wonderly.jeaprs.ByteString pathstr, wonderly.jeaprs.ByteString strstr)
          Write the data in strstr to the TNC 'device' followed by a <CR>.
 
Methods inherited from class wonderly.jeaprs.aprs.APRSStreamHandler
addAPRSEventListener, addAPRSStatusListener, addStreamListener, getAPRSEventListeners, getAPRSStatusListeners, getDebugging, getModuleId, processAPRSPacket, processTNCStream, removeAPRSEventListener, removeAPRSStatusListener, removeStreamListener, sendBadPacket, sendEOFStatus, setDebugging, setModuleId, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wonderly.jeaprs.io.IOModule
getModuleId, setModuleId
 

Field Detail

FEND

public static final int FEND
See Also:
Constant Field Values

FESC

public static final int FESC
See Also:
Constant Field Values

TFEND

public static final int TFEND
See Also:
Constant Field Values

TFESC

public static final int TFESC
See Also:
Constant Field Values

C_FLAG

public static final int C_FLAG
See Also:
Constant Field Values

R2_FLAG

public static final int R2_FLAG
See Also:
Constant Field Values

R1_FLAG

public static final int R1_FLAG
See Also:
Constant Field Values

END_FLAG

public static final int END_FLAG
See Also:
Constant Field Values

FLAG_MASK

public static final int FLAG_MASK
See Also:
Constant Field Values

SSID_MASK

public static final int SSID_MASK
See Also:
Constant Field Values

hardwareFlow

protected boolean hardwareFlow

fileAccess

protected wonderly.jeaprs.io.TNCInitialization fileAccess
Constructor Detail

TNCStream

public TNCStream()
Method Detail

getCommPort

public java.lang.String getCommPort()

setHardwareFlow

public void setHardwareFlow(boolean how)

isHardwareFlow

public boolean isHardwareFlow()

close

public void close()
Description copied from interface: APRSInput
Close the stream when done

Specified by:
close in interface APRSInput

setTNCType

public void setTNCType(int type)
Description copied from interface: TNC
Sets what type this TNC should be recognized as providing (TNC_TYPE_*).

Specified by:
setTNCType in interface TNC

getTNCType

public int getTNCType()
Description copied from interface: TNC
Returns what type this TNC was configured for (TNC_TYPE_*).

Specified by:
getTNCType in interface TNC

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface TNC
java.io.IOException

isKiss

public boolean isKiss()
Specified by:
isKiss in interface TNC
Returns:
true if this TNC is in KISS mode

setKiss

public void setKiss(boolean how)
Description copied from interface: TNC
sets the use of KISS mode based on the passed parameter

Specified by:
setKiss in interface TNC

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: TNC
Returns the input stream for the TNC.

Specified by:
getInputStream in interface TNC

lockTNC

public void lockTNC(boolean how)
Description copied from interface: TNC
Causes this object to block/release access to the TNC stream

Specified by:
lockTNC in interface TNC

isInitialized

public boolean isInitialized()
Description copied from interface: TNC
Tracks whether initTNC has been called

Specified by:
isInitialized in interface TNC

waitReady

public void waitReady()
Description copied from interface: TNC
Waits until the TNC stream is ready to be used

Specified by:
waitReady in interface TNC

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: TNC
Returns the output stream for the TNC

Specified by:
getOutputStream in interface TNC

setStopBits

public void setStopBits(int v)

setBaudRate

public void setBaudRate(int v)

setDataBits

public void setDataBits(int v)

setParity

public void setParity(int v)

getStopBits

public int getStopBits()

getBaudRate

public int getBaudRate()

getDataBits

public int getDataBits()

getParity

public int getParity()

initialize

public void initialize(wonderly.jeaprs.ui.JeAPRSUI ui)
                throws java.io.IOException
Description copied from interface: TNC
Set everything up, open ports etc

Specified by:
initialize in interface TNC
java.io.IOException

openStream

public void openStream(java.lang.String port)
                throws java.io.IOException,
                       javax.comm.NoSuchPortException,
                       javax.comm.PortInUseException,
                       javax.comm.UnsupportedCommOperationException
java.io.IOException
javax.comm.NoSuchPortException
javax.comm.PortInUseException
javax.comm.UnsupportedCommOperationException

write

public void write(wonderly.jeaprs.ByteString callstr,
                  wonderly.jeaprs.ByteString toCall,
                  wonderly.jeaprs.ByteString pathstr,
                  wonderly.jeaprs.ByteString strstr)
           throws java.io.IOException
Description copied from interface: APRSOutput
Write the data in strstr to the TNC 'device' followed by a <CR>. If kissMode is 'true', then callstr, toCall and pathstr are all used to formulate a KISS mode packet, otherwise they are ignored.

Specified by:
write in interface APRSOutput
Parameters:
toCall - the to call/unproto field.
java.io.IOException

write

public void write(wonderly.jeaprs.ByteString callstr,
                  wonderly.jeaprs.ByteString toCall,
                  wonderly.jeaprs.ByteString pathstr,
                  byte[] arr)
           throws java.io.IOException
Description copied from interface: APRSOutput
Write the data in arr to the TNC 'device'. If kissMode is 'true', then callstr, toCall and pathstr are all used to formulate a KISS mode packet, otherwise they are ignored.

Specified by:
write in interface APRSOutput
Parameters:
toCall - the to call/unproto field.
arr - the contents of the packet.
java.io.IOException

getKissModeOn

protected java.io.BufferedReader getKissModeOn()
                                        throws java.io.IOException
Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()

java.io.IOException

getTNCInit

protected java.io.BufferedReader getTNCInit()
                                     throws java.io.IOException
Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()

java.io.IOException

getKissModeOff

protected java.io.BufferedReader getKissModeOff()
                                         throws java.io.IOException
Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()

java.io.IOException

getTNCReset

protected java.io.BufferedReader getTNCReset()
                                      throws java.io.IOException
Convert InputStream from TNCInitialization (via fileAccess) to BufferedReader()

java.io.IOException

readPacket

public byte[] readPacket()
                  throws java.io.IOException
Description copied from interface: APRSInput
Reads a packet from the TNC. Normally, an APRSStreamHandler is using this stream and will be calling this method and then dispatching the packet to the listeners of that APRSStreamHandler.

Specified by:
readPacket in interface APRSInput
java.io.IOException
See Also:
APRSStreamHandler, wonderly.jeaprs.aprs.APRSEventListener, APRSStatusListener

initTNC

public void initTNC(wonderly.jeaprs.io.TNCInitialization init)
Call this method to initialize the TNC using the passed TNCInitialization instance instead of the default file based initialization.


initTNC

public void initTNC()
Call this method to send the default initialization data to the TNC

Specified by:
initTNC in interface TNC