SunSPOT API V5.0


com.sun.spot.peripheral.ota
Class OTACommandServer

java.lang.Object
  extended by com.sun.spot.peripheral.ota.OTACommandServer
All Implemented Interfaces:
IOTACommandServer, ISpotAdminConstants, IService, Runnable

public class OTACommandServer
extends Object
implements Runnable, ISpotAdminConstants, IOTACommandServer

This class monitors radiogram communications on port number 8 and establishes a new OTA session to handle commands. These commands allow flashing the Spot's config page and/or applications remotely, retrieving the config page contents, and restarting the Spot.

Applications should not need to create an OTACommandServer explicitly. OTA is enabled or disabled for a SPOT using the ant command line facility.
To get access to the OTACommandServer use Spot.getInstance().getOTACommandServer()
See IOTACommandServerListener if you want to run an application in a separate thread concurrently with OTACommandServer, and you need to respond (for example, suspending) when flash operations start.


Field Summary
 
Fields inherited from interface com.sun.spot.peripheral.ota.ISpotAdminConstants
ABORT_REQUEST, ADMIN_FLASH_OPERATION_FLOW_CONTROL_QUANTUM, BLINK_CMD, BOOTLOADER_CMD_ATTENTION, BOOTLOADER_CMD_HEADER, CHILD_ISOLATE_ECHO_PORT, CLOSEDOWN, DELETE_PUBLIC_KEY_CMD, ERROR_COMMAND_VERIFICATION_FAILED, ERROR_GENERAL, ERROR_UNKNOWN_COMMAND, FLASH_APP_CMD, FLASH_LIB_CMD, GET_ALL_APPS_STATUS_CMD, GET_APP_STATUS_CMD, GET_AVAILABLE_SUITES_CMD, GET_CONFIG_PAGE_CMD, GET_CONFIG_PAGE_LEN_CMD, GET_FILE_INFO_CMD, GET_FILE_LIST_CMD, GET_MEMORY_STATS_CMD, GET_POWER_STATS_CMD, GET_RADIO_INFO_CMD, GET_ROUTE_CMD, GET_SLEEP_INFO_CMD, GET_SPOT_PROPERTY_CMD, GET_SUITE_MANIFEST_CMD, GET_SYSTEM_PROPERTIES, LOCAL_OTA_COMMAND_SERVER_IDENTIFICATION_STRING, MASTER_ISOLATE_ECHO_PORT, MIGRATE_APP_CMD, PAUSE_APP_CMD, RECEIVE_APP_CMD, REMOTE_FLASH_OPERATION_FLOW_CONTROL_QUANTUM, REMOTE_GET_PHYS_NBRS_CMD, REMOTE_OTA_COMMAND_SERVER_IDENTIFICATION_STRING, RESUME_APP_CMD, RESYNC_CMD, SET_PUBLIC_KEY_CMD, SET_RADIO_INFO_CMD, SET_STARTUP_CMD, SET_SYSTEM_PROPERTIES, SET_TIME_CMD, START_APP_CMD, START_REMOTE_PRINTING_CMD, START_VM_CMD, STOP_APP_CMD, STOP_REMOTE_PRINTING_CMD, UNDEPLOY_CMD
 
Fields inherited from interface com.sun.spot.peripheral.ota.IOTACommandServer
BASIC_HELLO_TYPE, DEFAULT_DATAGRAM_PORT, DEFAULT_DATAGRAM_PROTOCOL, DEFAULT_STREAM_PORT, DEFAULT_STREAM_PROTOCOL, ESPOT_SUBTYPE, GENERIC_HOST_APP_SUBTYPE, HARDWARE_MAJOR_REV_ESPOT, HELLO_CMD, HELLO_COMMAND_MAJOR_VERSION, HELLO_COMMAND_MINOR_VERSION, HOST_APP_TYPE, PHYSICAL_NEIGHBORS_HELLO_TYPE, SHARED_BASESTATION_SUBTYPE, SPOT_TYPE, START_OTA_SESSION_CMD, VIRTUAL_ESPOT_SUBTYPE
 
Fields inherited from interface com.sun.spot.service.IService
PAUSED, PAUSING, READY, RESUMING, RUNNING, STARTING, STOPPED, STOPPING
 
Method Summary
 void addListener(IOTACommandServerListener sml)
          Attach a listener to be notified of the start and stop of flash operations.
 String getBaseStationAddress()
          Answer the IEEE address of the sender of the last command received.
 boolean getEnabled()
          Return whether service is started automatically on reboot.
static IOTACommandServer getInstance()
           
 String getServiceName()
          Return the name of this service.
 int getStatus()
          Return the current status of this service.
 byte getSubType()
          Get the device subtype for the Hello command.
 boolean isRunning()
          Return whether the service is currently running.
 boolean isSuspended()
           
static void main(String[] args)
          Startup the OTACommandServer on a SPOT listening for OTA connections.
 boolean pause()
          Pause the service, and return whether successful.
 boolean resume()
          Resume the service, and return whether successful.
 void run()
          Should not be invoked from user code - call start() instead.
 void setEnabled(boolean enable)
          Enable/disable whether service is started automatically.
 void setServiceName(String who)
          Assign a name to this service.
 void setSubType(byte subtype)
          Set the device subtype for the Hello command.
 void setSuspended(boolean suspended)
           
 boolean start()
          Start the service, and return whether successful.
 boolean stop()
          Stop the service, and return whether successful.
 Date timeOfLastMessageFromHost()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)
Startup the OTACommandServer on a SPOT listening for OTA connections.

Parameters:
args - ignored

getInstance

public static IOTACommandServer getInstance()
Returns:
Answer the singleton instance of this class
Throws:
IOException

addListener

public void addListener(IOTACommandServerListener sml)
Attach a listener to be notified of the start and stop of flash operations.

Specified by:
addListener in interface IOTACommandServer
Parameters:
sml - the listener

getBaseStationAddress

public String getBaseStationAddress()
Answer the IEEE address of the sender of the last command received.

Specified by:
getBaseStationAddress in interface IOTACommandServer
Returns:
-- the address

isSuspended

public boolean isSuspended()
Specified by:
isSuspended in interface IOTACommandServer
Returns:
Returns true if the server has been suspended by software.

setSuspended

public void setSuspended(boolean suspended)
Specified by:
setSuspended in interface IOTACommandServer
Parameters:
suspended - Suspends or resumes the server (it is initially running).

timeOfLastMessageFromHost

public Date timeOfLastMessageFromHost()
Specified by:
timeOfLastMessageFromHost in interface IOTACommandServer
Returns:
The time when the server last received a message from the host

setSubType

public void setSubType(byte subtype)
Set the device subtype for the Hello command.

Specified by:
setSubType in interface IOTACommandServer
Parameters:
subtype - specify the type of SPOT this is

getSubType

public byte getSubType()
Get the device subtype for the Hello command.

Specified by:
getSubType in interface IOTACommandServer
Returns:
the type of SPOT this is

run

public void run()
Should not be invoked from user code - call start() instead.

Specified by:
run in interface Runnable
See Also:
Runnable.run()

start

public boolean start()
Start the service, and return whether successful. Sets up its radio connections and then spawns a thread to respond to remote requests.

Specified by:
start in interface IService
Returns:
true if the service was successfully started

stop

public boolean stop()
Stop the service, and return whether successful. Stops all running threads. Closes any open IO connections.

Specified by:
stop in interface IService
Returns:
true if the service was successfully stopped

pause

public boolean pause()
Pause the service, and return whether successful. Preserve any current state, but do not handle new requests. Any running threads should block or sleep. Any open IO connections may be kept open. If there is no particular state associated with this service then pause() can be implemented by calling stop().

Specified by:
pause in interface IService
Returns:
true if the service was successfully paused

resume

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

Specified by:
resume in interface IService
Returns:
true if the service was successfully resumed

getStatus

public int getStatus()
Return the current status of this service.

Specified by:
getStatus in interface IService
Returns:
the current status of this service, e.g. STOPPED, STARTING, RUNNING, PAUSED, STOPPING, etc.

isRunning

public boolean isRunning()
Return whether the service is currently running.

Specified by:
isRunning in interface IService
Returns:
true if the service is currently running

getServiceName

public String getServiceName()
Return the name of this service.

Specified by:
getServiceName in interface IService
Returns:
the name of this service

setServiceName

public void setServiceName(String who)
Assign a name to this service. For some fixed services this may not apply and any new name will just be ignored.

Specified by:
setServiceName in interface IService
Parameters:
who - the name for this service

getEnabled

public boolean getEnabled()
Return whether service is started automatically on reboot. This may not apply to some services and for those services it will always return false.

Specified by:
getEnabled in interface IService
Returns:
true if the service is started automatically on reboot

setEnabled

public void setEnabled(boolean enable)
Enable/disable whether service is started automatically. This may not apply to some services and calls to setEnabled() may be ignored.

Specified by:
setEnabled in interface IService
Parameters:
enable - true if the service should be started automatically on reboot

SunSPOT API V5.0


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