import java.io.*; import java.net.*; /** * This class provides location awareness to the granularity of a room * inside a building based on the reception of 802.11 broadcasts and the * corresponding detection of ultrasound. This class is intended to be used * by an application running on a mobile device. If the mobile device moves * close to a desktop running the ServerBeacon class/application, it will * know that it is in the same room as the desktop based on the information * provided by this MobileClient class. *

* An application using this class needs to provide a reference to a * LocationTracker object in the MobileClient class's constructor so that * the MobileClient class can signal the LocationTracker object when a room * change has occurred. *

* The MobileClient class implements both an UltrasoundUpdateListener * and a DatagramUpdateListener so that it can be informed of ultrasound * detections and datagram receptions. * * @author Tony Offer * @author Chris Palistrant * @version 1.0 */ public class MobileClient implements UltrasoundUpdateListener, DatagramUpdateListener { // Reference to the object/application that instantiated this MobileClient protected LocationTracker notifyApp = null; // Reference to the UltrasoundListenr used throughout this class protected UltrasoundListener usl; // This string identifies the current room in which this // MobileClient object perceives itself to exist. private String room = null; private static final long RECORD = 2000; /** * This is the only constructor for this class. It takes a reference * to a LocationTracker object so that the MobileClient class * can notify the object when a room change has occurred. No other * constructor is provided because the MobileClient class must have * access to a roomChanged() method. * * @param extApp Reference to the LocationTracker object that * will receive room change notifications. */ public MobileClient(LocationTracker extApp) { notifyApp = extApp; // Start a datagram listener thread that will notify this class of updates. // Create a new UltrasoundListener that will be used to //usl = new UltrasoundListener(this, false); // No debugging info usl = new UltrasoundListener(this, true); new DatagramListener(this).start(); } /** * Callback method for the UltrasoundListener thread that receives * notifications of newly received ultrasound detections. This * method attempts to correlate the time of the received ultrasound * detection with the time of one of the previously received * datagram transmissions in order to make a determination of room * location. * * @param timeDetected The time (in milliseconds since January 1, * 1970) at which the ultrasound was * received. */ public void ultrasoundDetected(long timeDetected) { /*** TESTING ***/ System.out.println("US Detected: " + //new java.util.Date(timeDetected)); timeDetected); } /** * Callback method for the DatagramListener thread that receives * notifications of newly received datagram messages. This method * stores the received datagram message and the time at which it was * received for later correlation with ultrasound detections. If an * ultrasound detection is later correlated with the datagram * message received by this callback method, then the received * datagram message describes the current room location. * * @param timeDetected The time (in milliseconds since January 1, * 1970) at which the datagram message was * received. * @param message The string that was transmitted in the datagram. */ public void datagramDetected(String message, long timeDetected) { /*** TESTING ***/ System.out.println("\"" + message + "\" Received: " + //new java.util.Date(timeDetected)); timeDetected); // A datagram was detected so, the line should be analyzed for an // appropriate period of time. usl.record(RECORD); } }