SunSPOT API V5.0


com.sun.spot.io.j2me.radiogram
Class RadiogramConnImpl

java.lang.Object
  extended by com.sun.squawk.io.ConnectionBase
      extended by com.sun.spot.peripheral.RadioConnectionBase
          extended by com.sun.spot.io.j2me.radiogram.RadiogramConnImpl
All Implemented Interfaces:
RadiogramConnection, IMultipleHopConnection, IRadioControl, ITimeoutableConnection, Connection, DatagramConnection

public class RadiogramConnImpl
extends RadioConnectionBase
implements RadiogramConnection

This class provides the "radiogram" protocol for accessing the SPOT radio using datagrams. It is an implementor of RadiostreamConnection

See Also:
RadiostreamConnection

Field Summary
 
Fields inherited from class com.sun.spot.peripheral.RadioConnectionBase
DEFAULT_TIMEOUT
 
Constructor Summary
RadiogramConnImpl()
          DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)
RadiogramConnImpl(String addr, byte portNo, boolean isServer, boolean timeouts)
          DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)
 
Method Summary
 void close()
          Close
 byte getLocalPort()
          Answer the port number for this connection
 long getMacAddress()
           
 int getMaxBroadcastHops()
          returns the maximum number of mesh hops broadcasts sent on this connection will traverse
 int getMaximumLength()
          Get the maximum length a datagram can be.
 int getNominalLength()
          Get the nominal length of a datagram.
static IRadioPolicyManager getRadioPolicyManager()
           
 boolean isBroadcast()
           
 boolean isPointToPoint()
           
 boolean isServer()
           
 Datagram newDatagram(byte[] buf, int size)
          Create a new datagram object.
 Datagram newDatagram(byte[] buf, int size, String addr)
          Make a new datagram object.
 Datagram newDatagram(int size)
          Create a new datagram object.
 Datagram newDatagram(int size, String addr)
          Create a new datagram object.
 Connection open(String arg0, String arg1, int arg2, boolean arg3)
          Open a connection to a target.
 boolean packetsAvailable()
          determines whether there are radiograms that can be read from this connection
 void receive(Datagram dgram)
          Receive a datagram.
 IncomingData receivePacket()
           
 void send(Datagram dgram)
          Send a datagram.
 void setMaxBroadcastHops(int hops)
          change the number of mesh hops a broadcast packet may take
static void setProtocolManager(IRadiogramProtocolManager protocolManager)
           
 void setRadioPolicy(RadioPolicy policy)
          Set the radio policy for this connection
static void setRadioPolicyManager(IRadioPolicyManager manager)
           
 
Methods inherited from class com.sun.spot.peripheral.RadioConnectionBase
getTimeout, setTimeout
 
Methods inherited from class com.sun.squawk.io.ConnectionBase
openDataInputStream, openDataOutputStream, openInputStream, openOutputStream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.peripheral.ITimeoutableConnection
getTimeout, setTimeout
 

Constructor Detail

RadiogramConnImpl

public RadiogramConnImpl(String addr,
                         byte portNo,
                         boolean isServer,
                         boolean timeouts)
DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)


RadiogramConnImpl

public RadiogramConnImpl()
DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)

Method Detail

setProtocolManager

public static void setProtocolManager(IRadiogramProtocolManager protocolManager)

getRadioPolicyManager

public static IRadioPolicyManager getRadioPolicyManager()

setRadioPolicyManager

public static void setRadioPolicyManager(IRadioPolicyManager manager)

close

public void close()
           throws IOException
Description copied from class: ConnectionBase
Close

Specified by:
close in interface Connection
Overrides:
close in class ConnectionBase
Throws:
IOException - If an I/O error occurs

getMaximumLength

public int getMaximumLength()
Description copied from interface: DatagramConnection
Get the maximum length a datagram can be. Maximum length determines the maximum size of the datagram that can be created using the newDatagram method, and the maximum size of the datagram that can be sent or received.

Specified by:
getMaximumLength in interface DatagramConnection
Returns:
The maximum length of a datagram.

getNominalLength

public int getNominalLength()
Description copied from interface: DatagramConnection
Get the nominal length of a datagram. Nominal length refers to the size of the datagram that is stored into the data buffer. Nominal length may be equal or less than the maximum length of the datagram.

Specified by:
getNominalLength in interface DatagramConnection
Returns:
The nominal length of a datagram.

send

public void send(Datagram dgram)
          throws NoAckException,
                 ChannelBusyException,
                 NoRouteException,
                 NoMeshLayerAckException
Description copied from interface: DatagramConnection
Send a datagram. The Datagram object includes the information indicating the data to be sent, its length, and the address of the receiver. The method sends length bytes starting at the current offset of the Datagram object, where length and offset are internal state variables of the Datagram object.

Specified by:
send in interface DatagramConnection
Parameters:
dgram - A datagram.
Throws:
NoAckException
ChannelBusyException
NoRouteException
NoMeshLayerAckException

receive

public void receive(Datagram dgram)
             throws IOException
Description copied from interface: DatagramConnection
Receive a datagram. When this method returns, the internal buffer in the Datagram object is filled with the data received, starting at the location determined by the offset state variable, and the data is ready to be read using the methods of the DataInput interface.

This method blocks until a datagram is received. The internal length state variable in the Datagram object contains the length of the received datagram. If the received data is longer than the length of the internal buffer minus offset, data is truncated.

This method does not change the internal read/write state variable of the Datagram object. Use method Datagram.reset to change the pointer before reading if necessary.

Specified by:
receive in interface DatagramConnection
Parameters:
dgram - A datagram.
Throws:
IOException - If an I/O error occurs.

newDatagram

public Datagram newDatagram(int size)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
size - The size of the buffer needed for the datagram
Returns:
A new datagram

newDatagram

public Datagram newDatagram(int size,
                            String addr)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
size - The size of the buffer needed for the datagram
addr - The I/O address to which the datagram will be sent
Returns:
A new datagram

newDatagram

public Datagram newDatagram(byte[] buf,
                            int size)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
buf - The buffer to be used for the datagram
size - The size of the buffer needed for the datagram
Returns:
A new datagram

newDatagram

public Datagram newDatagram(byte[] buf,
                            int size,
                            String addr)
Description copied from interface: DatagramConnection
Make a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
buf - The buffer to be used for the datagram
size - The size of the buffer needed for the datagram
addr - The I/O address to which the datagram will be sent
Returns:
A new datagram

isBroadcast

public boolean isBroadcast()

isPointToPoint

public boolean isPointToPoint()

isServer

public boolean isServer()

getMacAddress

public long getMacAddress()

setRadioPolicy

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

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

open

public Connection open(String arg0,
                       String arg1,
                       int arg2,
                       boolean arg3)
                throws IOException
Description copied from class: ConnectionBase
Open a connection to a target.

Specified by:
open in class ConnectionBase
Parameters:
arg0 - The URL protocol
arg1 - The URL for the connection
arg2 - The access mode
arg3 - A flag to indicate that the caller wants timeout exceptions
Returns:
A new Connection object
Throws:
IOException - If some other kind of I/O error occurs.

receivePacket

public IncomingData receivePacket()

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

packetsAvailable

public boolean packetsAvailable()
Description copied from interface: RadiogramConnection
determines whether there are radiograms that can be read from this connection

Specified by:
packetsAvailable in interface RadiogramConnection
Returns:
true if there are packets that can be read from the connection

setMaxBroadcastHops

public void setMaxBroadcastHops(int hops)
Description copied from interface: IMultipleHopConnection
change the number of mesh hops a broadcast packet may take

Specified by:
setMaxBroadcastHops in interface IMultipleHopConnection
Parameters:
hops - the new number of mesh hops a packet will traverse

getMaxBroadcastHops

public int getMaxBroadcastHops()
Description copied from interface: IMultipleHopConnection
returns the maximum number of mesh hops broadcasts sent on this connection will traverse

Specified by:
getMaxBroadcastHops in interface IMultipleHopConnection
Returns:
the number of mesh hops a packet will traverse

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.