SunSPOT API V3.0


com.sun.spot.io.j2me.radiostream
Class RadioInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.sun.spot.io.j2me.radiostream.RadioInputStream
All Implemented Interfaces:
IRadioControl

public class RadioInputStream
extends InputStream
implements IRadioControl

Helper class for "radiostream:" connections. This class provides an InputStream over the data received from another Spot. It also provides a small set of accessors to get information about the quality of the link. You should NOT normally instantiate this class directly, but rather via the GCF framework: see the first reference below for more details.

See Also:
RadiostreamConnection

Constructor Summary
RadioInputStream(IRadiostreamProtocolManager dispatcher, ConnectionID cid, long timeout, RadioPolicy initialPolicy, IRadioPolicyManager radioPolicyManager)
          Construct a RadioInputStream
 
Method Summary
 int available()
          Return the number of bytes available to be read from the stream without blocking.
 void close()
          Closes this input stream and releases any system resources associated with the stream.
 int getCorr()
          CORR measures the average correlation value of the first 4 bytes of the packet header.
 int getLinkQuality()
          Link Quality Indication (LQI) is a characterization of the quality of a received packet.
 byte getLocalPort()
          Answer the port number for this connection
 int getRssi()
          RSSI (received signal strength indicator) measures the strength (power) of the signal for the packet.
 long getTimeout()
          returns the time, in milliseconds, this connection will wait for data before throwing a timeout exception
 int read()
          Reads the next byte of data from the input stream.
 void setRadioPolicy(RadioPolicy selection)
          Set the radio policy for this connection
 void setTimeout(long time)
          change the timeout associated with this input stream
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RadioInputStream

public RadioInputStream(IRadiostreamProtocolManager dispatcher,
                        ConnectionID cid,
                        long timeout,
                        RadioPolicy initialPolicy,
                        IRadioPolicyManager radioPolicyManager)
Construct a RadioInputStream

Parameters:
initialPolicy - radio policy assoicated with this connection
radioPolicyManager - the RadioPolicyManager associated with this inputstream
dispatcher - the PortBasedProtocolManager that will dispatch radio packets
cid - the ConnectionID object being used
timeout - the timeout to use when waiting for input
Method Detail

read

public int read()
         throws IOException
Description copied from class: InputStream
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

A subclass must provide an implementation of this method.

Specified by:
read in class InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.

available

public int available()
              throws IOException
Return the number of bytes available to be read from the stream without blocking. Returns the number of bytes available in the current underlying radio packet - more packets might be coming but we just don't know.

Overrides:
available in class InputStream
Returns:
the number of bytes available right now
Throws:
IOException

getLinkQuality

public int getLinkQuality()
Link Quality Indication (LQI) is a characterization of the quality of a received packet. Its value is computed from the CORR, correlation value. The LQI ranges from 0 (bad) to 255 (good).

Returns:
linkQuality - range 0 to 0xFF
See Also:
RadioPacket.getLinkQuality()

getCorr

public int getCorr()
CORR measures the average correlation value of the first 4 bytes of the packet header. A correlation value of ~110 indicates a maximum quality packet while a value of ~50 is typically the lowest quality packet detectable by the SPOT's receiver.

Returns:
- correlation value
See Also:
RadioPacket.getCorr()

getRssi

public int getRssi()
RSSI (received signal strength indicator) measures the strength (power) of the signal for the packet. It ranges from +60 (strong) to -60 (weak). To convert it to decibels relative to 1 mW (= 0 dBm) subtract 45 from it, e.g. for an RSSI of -20 the RF input power is approximately -65 dBm.

Returns:
- RSSI value
See Also:
RadioPacket.getRssi()

close

public void close()
           throws IOException
Description copied from class: InputStream
Closes this input stream and releases any system resources associated with the stream.

The close method of InputStream does nothing.

Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occurs.

setRadioPolicy

public void setRadioPolicy(RadioPolicy selection)
Description copied from interface: IRadioControl
Set the radio policy for this connection

Specified by:
setRadioPolicy in interface IRadioControl
Parameters:
selection - the policy required

getLocalPort

public byte getLocalPort()
Description copied from interface: IRadioControl
Answer the port number for this connection

Specified by:
getLocalPort in interface IRadioControl
Returns:
the port number

setTimeout

public void setTimeout(long time)
change the timeout associated with this input stream

Parameters:
time - time, in milliseconds, to wait for data on this input stream

getTimeout

public long getTimeout()
returns the time, in milliseconds, this connection will wait for data before throwing a timeout exception

Returns:
input timeout, in milliseconds

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.