import java.util.List;
import java.util.LinkedList;
+import java.util.HashMap;
import java.util.Collection;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
private Task task;
private IBeaconManager ibeacon;
+ private String uuid;
+ private HashMap<Integer,LatLon> locations;
/* Public methods */
public Beacon(Task task) {
- this.task = task;
IBeaconManager.LOG_DEBUG = true;
+
+ // Setup object
+ this.uuid = "iBeaconNav";
+ this.task = task;
+
+ // Initialize iBeacons
+ this.locations = new HashMap<Integer,LatLon>();
+ this.addIBeacon(1, 1, 34.0722, -118.4441);
+ this.addIBeacon(1, 2, 34.0722, -118.4441);
+ this.addIBeacon(1, 3, 34.0722, -118.4441);
+ this.addIBeacon(1, 5, 34.0722, -118.4441);
+ this.addIBeacon(1, 5, 34.0722, -118.4441);
}
public void connect() {
//this.ibeacon.setBackgroundMode(this, true);
}
+ /* Private methods */
+ private void addIBeacon(int major, int minor, double lat, double lon) {
+ IBeacon ib = new IBeacon(this.uuid, major, minor);
+ LatLon loc = new LatLon(lat, lon);
+ this.locations.put(ib.getMinor(), loc);
+ }
+
/* IBeaconConsumer Methods
* Pass most of these off to Task,
* I don't even know why they're here */
/* RangeNotifier Methods */
@Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
- Util.debug("Task: didRangeBeaconsInRegion");
+ Util.debug("Task: didRangeBeaconsInRegion - " + iBeacons.size() + " beacons");
+ for (IBeacon ib : iBeacons) {
+ if (this.locations.containsKey(ib.getMinor())) {
+ LatLon loc = this.locations.get(ib.getMinor());
+ float[] data = new float[4];
+ data[0] = CMD.Data.BEACON.ordinal();
+ data[1] = (float)loc.lat;
+ data[2] = (float)loc.lon;
+ data[3] = (float)ib.getAccuracy();
+ this.task.tellMain(CMD.Response.SHOWDATA, data);
+ } else {
+ Util.debug("Unknown beacon:" +
+ " " + ib.getProximityUuid() +
+ ":" + ib.getMajor() +
+ ":" + ib.getMinor() +
+ " @ " + ib.getAccuracy());
+ }
+ }
}
/* MonitorNotifier Methods */
public void didDetermineStateForRegion(int state, Region region) {
Util.debug("Task: didDetermineStateForRegion");
}
+
+ /* Location class */
+ class LatLon {
+ public double lat = 0;
+ public double lon = 0;
+
+ public LatLon(double lat, double lon) {
+ this.lat = lat;
+ this.lon = lon;
+ }
+ }
}