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

org.sunspotworld.demo
Class TelemetryMain

java.lang.Object
  extended by javax.microedition.midlet.MIDlet
      extended by org.sunspotworld.demo.util.Spotlet
          extended by org.sunspotworld.demo.TelemetryMain
All Implemented Interfaces:
com.sun.spot.peripheral.ota.IOTACommandServerListener, com.sun.spot.util.IBootloaderListenerCallback, PacketTypes, LocateServiceListener, PacketHandler

public class TelemetryMain
extends Spotlet
implements LocateServiceListener, PacketHandler, PacketTypes

Sample application that sends a stream of accelerometer telemetry information back from the SPOT to a host application.

This class establishes a radio connection with the host application. The AccelMonitor class takes care of all accelerometer-related commands, and sends the host a telemetry stream of accelerometer readings.

To simplify our work we make use of a number of utility helper classes:

The host commands and replies are defined in the PacketTypes class.

The SPOT uses the LEDs to display its status as follows:

LED 0:

LED 1:

Author:
Ron Goldman
Date: May 8, 2006, revised: August 1, 2007
See Also:
LocateService, LocateServiceListener, PacketHandler, PacketReceiver, PacketTransmitter, PacketTypes, Spotlet

Field Summary
 
Fields inherited from interface org.sunspotworld.demo.PacketTypes
ACCEL_2G_DATA_REPLY, ACCEL_6G_DATA_REPLY, BLINK_LEDS_REQ, BROADCAST_PORT, CALIBRATE_ACCEL_REPLY, CALIBRATE_ACCEL_REQ, CONNECTED_PORT, DISPLAY_SERVER_AVAIL_REPLY, DISPLAY_SERVER_QUITTING, DISPLAY_SERVER_RESTART, GET_ACCEL_INFO_REPLY, GET_ACCEL_INFO_REQ, GET_ACCEL_INFO2_REPLY, LOCATE_DISPLAY_SERVER_REQ, MESSAGE_REPLY, PING_REPLY, PING_REQ, SEND_ACCEL_DATA_REQ, SET_ACCEL_SCALE_REPLY, SET_ACCEL_SCALE_REQ, STOP_ACCEL_DATA_REQ
 
Constructor Summary
TelemetryMain()
           
 
Method Summary
 void closeConnection()
          Called to declare that the connection to the host is no longer present.
 void handlePacket(byte type, com.sun.spot.io.j2me.radiogram.Radiogram pkt)
          Callback from PacketReceiver when a new command is received from the host.
 void initialize()
          Initialize any needed variables.
 void queueMessage(java.lang.String msg)
          Add a message to the queue to be sent to the host at a later time.
 void reinitialize()
          Reinitialize any needed variables after an error.
 void run()
          Main application run loop.
 void serviceLocated(long serviceAddress)
          Callback from LocateService when the host display service has been contacted.
 
Methods inherited from class org.sunspotworld.demo.util.Spotlet
cleanup, destroyApp, firstRun, getCurrentRunTime, getLastError, getLastRunTime, getNumberRetries, getNumberRuns, getTimeBetweenRetries, getTotalRunTime, pause, pauseApp, postFlash, preFlash, prepareToExit, quit, setBlinkLEDs, setListenForBootloader, setNumberRetries, setTimeBetweenRetries, startApp
 
Methods inherited from class javax.microedition.midlet.MIDlet
getAppProperty, notifyDestroyed, notifyPaused, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelemetryMain

public TelemetryMain()
Method Detail

initialize

public void initialize()
Initialize any needed variables. Called by Spotlet.

Overrides:
initialize in class Spotlet

reinitialize

public void reinitialize()
Reinitialize any needed variables after an error. Called by Spotlet.

Overrides:
reinitialize in class Spotlet

run

public void run()
Main application run loop. Called by Spotlet.

Specified by:
run in class Spotlet

serviceLocated

public void serviceLocated(long serviceAddress)
Callback from LocateService when the host display service has been contacted. This routine will setup both PacketReceiver & PacketTransmitter services to handle communications with the host service. Registers which commands this class handles.

Specified by:
serviceLocated in interface LocateServiceListener
Parameters:
serviceAddress - the IEEE address of the host display service

closeConnection

public void closeConnection()
Called to declare that the connection to the host is no longer present.


handlePacket

public void handlePacket(byte type,
                         com.sun.spot.io.j2me.radiogram.Radiogram pkt)
Callback from PacketReceiver when a new command is received from the host. Note that commands associated with the accelerometer are dispatched directly to the AccelMonitor class's handlePacket() method.

Specified by:
handlePacket in interface PacketHandler
Parameters:
type - the command
pkt - the radiogram with any other required information

queueMessage

public void queueMessage(java.lang.String msg)
Add a message to the queue to be sent to the host at a later time. Messages will be sent after the next Ping request arrives.

Parameters:
msg - the String to be sent

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

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