Sun SPOT Telemetry Demo -- Host side
v1.1

org.sunspotworld.demo
Class AccelerometerListener

java.lang.Object
  extended by java.lang.Thread
      extended by org.sunspotworld.demo.AccelerometerListener
All Implemented Interfaces:
java.lang.Runnable, PacketTypes

public class AccelerometerListener
extends java.lang.Thread
implements PacketTypes

Simple example class to locate a remote service (on a SPOT), to connect to it and send it a variety of commands. In this case to set or calibrate the SPOT's accelerometer and to return a stream of accelerometer telemetry information.

Author:
Ron Goldman
Date: May 2, 2006

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
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
AccelerometerListener()
          Create a new AccelerometerListener to connect to the remote SPOT over the radio.
 
Method Summary
 void clear()
          Routine to reset after old data has been cleared from the GUI display.
 void doBlink()
          Send a request to the remote SPOT to blink its LEDs.
 void doCalibrate()
          Send a request to the remote SPOT to calibrate the accelerometer.
 void doGetScale()
          Send a request to the remote SPOT to report on which accelerometer scale it is using.
 void doPing()
          Send a request to the remote SPOT to report on radio signal strength.
 void doQuit()
          Stop running.
 void doSendData(boolean sendIt, GraphView gView)
          Send a request to the remote SPOT to start or stop sending accelerometer readings.
 void doSetScale(int val)
          Send a request to the remote SPOT to set which accelerometer scale it will use.
 boolean is2GScale()
          Report which scale is the accelerometer is using.
 void reconnect()
          Send a request to the remote SPOT to report on radio signal strength.
 void run()
          Main runtime loop to connect to a remote SPOT.
 void setGUI(TelemetryFrame fr)
          Specify the GUI window that shows whether connected to a remote SPOT.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AccelerometerListener

public AccelerometerListener()
Create a new AccelerometerListener to connect to the remote SPOT over the radio.

Method Detail

is2GScale

public boolean is2GScale()
Report which scale is the accelerometer is using.

Returns:
true if using 2G scale, false for 6G scale

setGUI

public void setGUI(TelemetryFrame fr)
Specify the GUI window that shows whether connected to a remote SPOT.

Parameters:
fr - the TelemetryFrame GUI that will be used to display the connection status to the remote SPOT

doGetScale

public void doGetScale()
Send a request to the remote SPOT to report on which accelerometer scale it is using.


doSetScale

public void doSetScale(int val)
Send a request to the remote SPOT to set which accelerometer scale it will use.

Parameters:
val - the scale to use: 2 or 6

doCalibrate

public void doCalibrate()
Send a request to the remote SPOT to calibrate the accelerometer.


doSendData

public void doSendData(boolean sendIt,
                       GraphView gView)
Send a request to the remote SPOT to start or stop sending accelerometer readings.

Parameters:
sendIt - true to start sending, false to stop
gView - the GraphView display to pass the data to

doPing

public void doPing()
Send a request to the remote SPOT to report on radio signal strength.


doBlink

public void doBlink()
Send a request to the remote SPOT to blink its LEDs.


doQuit

public void doQuit()
Stop running. Also notify the remote SPOT that we are no longer listening to it.


reconnect

public void reconnect()
Send a request to the remote SPOT to report on radio signal strength.


clear

public void clear()
Routine to reset after old data has been cleared from the GUI display.


run

public void run()
Main runtime loop to connect to a remote SPOT. Do not call directly. Call start() instead.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

Sun SPOT Telemetry Demo -- Host side
v1.1

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