Sun SPOT Telemetry Demo -- SPOT-side
v1.1

org.sunspotworld.demo.util
Class PacketTransmitter

java.lang.Object
  extended by org.sunspotworld.demo.util.PacketTransmitter
All Implemented Interfaces:
com.sun.spot.service.IService

public class PacketTransmitter
extends java.lang.Object
implements com.sun.spot.service.IService

Simple transmit loop to pull packets off of a xmitQueue and send them. After the packet is sent it is put on a freeQueue.

Classes wanting to send a packet should get one by calling newDataPacket(), passing in the packet type as an argument.

Implements the com.sun.spot.service.IService interface.

Author:
Ron Goldman
Date: August 1, 2007
See Also:
PacketReceiver, IService

Field Summary
static int SINGLE_PACKET_PAYLOAD_SIZE
          Number of bytes of data that will fit in a single packet, not including the header
 
Fields inherited from interface com.sun.spot.service.IService
PAUSED, PAUSING, RESUMING, RUNNING, STARTING, STOPPED, STOPPING
 
Constructor Summary
PacketTransmitter(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn)
          Create a new transmit loop thread.
PacketTransmitter(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn, int payloadSize)
          Create a new transmit loop thread and use (multi-packet) datagrams.
 
Method Summary
 void free(javax.microedition.io.Datagram dg)
          Routine to put a data packet onto the free list.
 boolean getEnabled()
          Return whether service is started automatically on reboot.
 java.lang.String getServiceName()
          Return service name
 int getStatus()
          Return current service status.
 void immediateSend(javax.microedition.io.Datagram dg)
          Routine to immediately send a data packet.
 boolean isRunning()
          Return if service is currently running.
 com.sun.spot.io.j2me.radiogram.Radiogram newDataPacket(byte type)
          Get a free data packet and write its header.
 boolean pause()
          Pause the service, and return whether successful.
 boolean resume()
          Resume the service, and return whether successful.
 void send(javax.microedition.io.Datagram dg)
          Routine to queue a data packet for later sending.
 void setEnabled(boolean enable)
          Enable/disable whether service is started automatically.
 void setServiceName(java.lang.String who)
          Assign a name to this service.
 boolean start()
          Start service running.
 boolean stop()
          Stop service running.
 void writeHeader(com.sun.spot.io.j2me.radiogram.Radiogram rdg, byte type)
          Write the common header into a Radiogram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLE_PACKET_PAYLOAD_SIZE

public static final int SINGLE_PACKET_PAYLOAD_SIZE
Number of bytes of data that will fit in a single packet, not including the header

See Also:
Constant Field Values
Constructor Detail

PacketTransmitter

public PacketTransmitter(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn)
Create a new transmit loop thread.

Parameters:
conn - the RadiogramConnection to send packets over

PacketTransmitter

public PacketTransmitter(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn,
                         int payloadSize)
Create a new transmit loop thread and use (multi-packet) datagrams.

Parameters:
conn - the RadiogramConnection to send packets over
payloadSize - how big do outgoing packets need to be
Method Detail

writeHeader

public void writeHeader(com.sun.spot.io.j2me.radiogram.Radiogram rdg,
                        byte type)
Write the common header into a Radiogram.

Parameters:
rdg - the Radiogram to write the header info into
type - the type of data packet to send

newDataPacket

public com.sun.spot.io.j2me.radiogram.Radiogram newDataPacket(byte type)
Get a free data packet and write its header.

Parameters:
type - the type of data packet to send
Returns:
the data packet with its header setup

free

public void free(javax.microedition.io.Datagram dg)
Routine to put a data packet onto the free list.

Parameters:
dg - the Datagram to free

send

public void send(javax.microedition.io.Datagram dg)
Routine to queue a data packet for later sending.

Parameters:
dg - the Datagram to send

immediateSend

public void immediateSend(javax.microedition.io.Datagram dg)
                   throws java.io.IOException
Routine to immediately send a data packet. Used by senders who need to know when the packet was actually sent or who want to reuse the Datagram.

Parameters:
dg - the Datagram to send
Throws:
java.io.IOException

stop

public boolean stop()
Stop service running.

Specified by:
stop in interface com.sun.spot.service.IService
Returns:
true if will stop service

start

public boolean start()
Start service running.

Specified by:
start in interface com.sun.spot.service.IService
Returns:
true if will start service

pause

public boolean pause()
Pause the service, and return whether successful. Since there is no particular state associated with this service then pause() can be implemented by calling stop().

Specified by:
pause in interface com.sun.spot.service.IService
Returns:
true if the service was successfully paused

resume

public boolean resume()
Resume the service, and return whether successful. Since there was no particular state associated with this service then resume() can be implemented by calling start().

Specified by:
resume in interface com.sun.spot.service.IService
Returns:
true if the service was successfully resumed

getServiceName

public java.lang.String getServiceName()
Return service name

Specified by:
getServiceName in interface com.sun.spot.service.IService
Returns:
the name of this service

setServiceName

public void setServiceName(java.lang.String who)
Assign a name to this service.

Specified by:
setServiceName in interface com.sun.spot.service.IService
Parameters:
who - the new name for this service

isRunning

public boolean isRunning()
Return if service is currently running.

Specified by:
isRunning in interface com.sun.spot.service.IService
Returns:
true if currently running

getStatus

public int getStatus()
Return current service status.

Specified by:
getStatus in interface com.sun.spot.service.IService
Returns:
current service status: STOPPED, STARTING, RUNNING, or STOPPING.

getEnabled

public boolean getEnabled()
Return whether service is started automatically on reboot.

Specified by:
getEnabled in interface com.sun.spot.service.IService
Returns:
false as this service is never started automatically on reboot

setEnabled

public void setEnabled(boolean enable)
Enable/disable whether service is started automatically. Noop for us.

Specified by:
setEnabled in interface com.sun.spot.service.IService
Parameters:
enable - ignored

Sun SPOT Telemetry Demo -- SPOT-side
v1.1

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