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

org.sunspotworld.demo.util
Class PacketReceiver

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

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

Simple helper class to monitor a radiogram connection and redirect packets to handlers that have registered an interest in that packet type. The contents of the first byte of the packet determines its type.

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

Author:
arshan & Ron Goldman
Date: August 1, 2007
See Also:
PacketHandler, PacketTransmitter, IService

Field Summary
 
Fields inherited from interface com.sun.spot.service.IService
PAUSED, PAUSING, RESUMING, RUNNING, STARTING, STOPPED, STOPPING
 
Constructor Summary
PacketReceiver(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn)
          Creates a new instance of a PacketReceiver.
 
Method Summary
 boolean getEnabled()
          Return whether service is started automatically on reboot.
 java.lang.String getServiceName()
          Return service name
 int getStatus()
          Return current service status.
 boolean isRunning()
          Return if service is currently running.
 boolean pause()
          Pause the service, and return whether successful.
 void registerHandler(PacketHandler handler, byte type)
          Register a handler for some packet type.
 boolean resume()
          Resume the service, and return whether successful.
 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 packet receiver service running.
 boolean stop()
          Stop packet receiver service if running.
 void unregisterHandler(PacketHandler handler)
          Unregister a handler from all packet types.
 void unregisterHandler(PacketHandler handler, byte type)
          Unregister a handler for some packet type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketReceiver

public PacketReceiver(com.sun.spot.io.j2me.radiogram.RadiogramConnection conn)
Creates a new instance of a PacketReceiver.

Parameters:
conn - the radiogram connection to receive packets from
Method Detail

registerHandler

public void registerHandler(PacketHandler handler,
                            byte type)
Register a handler for some packet type. Packets of this type will be passed to the class via its handlePacket() callback method.

Parameters:
handler - the class to register
type - the command to dispatch to this handler

unregisterHandler

public void unregisterHandler(PacketHandler handler,
                              byte type)
Unregister a handler for some packet type.

Parameters:
handler - the class to unregister
type - the command to not dispatch to this handler

unregisterHandler

public void unregisterHandler(PacketHandler handler)
Unregister a handler from all packet types.

Parameters:
handler - the class to unregister

stop

public boolean stop()
Stop packet receiver service if running.

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

start

public boolean start()
Start packet receiver 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.