Permalink
Browse files

Protocol guessing works, but BUG found: removeAll hangs if more than …

…1 protocol was discovered... Demo Application was updated to not use hard coded addresses.
  • Loading branch information...
1 parent 009d4ab commit 7169405aa681ec00b8307a226ab8818e87b53ea5 @theterg theterg committed Sep 27, 2011
@@ -7,11 +7,11 @@ Bundle-Version: 1.0.0
Bundle-Vendor: theterg
Bundle-Description: The Remote Monitoring demo - using com.buglabs.xbee
Bug-Bundle-Type: Application
-BUG-API-Version: 2.0.2
Import-Package: com.buglabs.application,
com.buglabs.util,
com.buglabs.xbee,
com.buglabs.xbee.protocol,
org.osgi.framework,
org.osgi.service.log,
org.osgi.util.tracker
+BUG-API-Version: 2.0.2
@@ -38,23 +38,18 @@
@Override
public void dataRecieved(Map<String, Object> data) {
- /*if ((XBeeProtocol)data.get("protocol") == motion){
- ilog("Motion detected!");
- ilog((String)xbc.getResponse(RANGE_ADDRESS).get("Range"));
- ilog((String)xbc.getResponse(WEATHER_ADDRESS).get("Temperature"));
- }*/
- if ((XBeeProtocol)data.get("protocol") == weather){
+ if ((Class)data.get("class") == SparkfunWeatherboard.class){
ilog("Weather data from "+Integer.toHexString(((int[])data.get("address"))[1]));
ilog("Temperature: "+data.get("Temperature"));
ilog("Humidity: "+data.get("Humidity"));
ilog("Dewpoint: "+data.get("Dewpoint"));
ilog("Pressure: "+data.get("Pressure"));
ilog("Light: "+data.get("Light"));
- } else if ((XBeeProtocol)data.get("protocol") == range){
+ } else if ((Class)data.get("class") == MaxbotixRangefinder.class){
String range = (String) data.get("Range");
ilog("Range from "+Integer.toHexString(((int[])data.get("address"))[1])
+": "+range);
- } else if ((XBeeProtocol)data.get("protocol") == motion){
+ } else if ((Class)data.get("class") == PIRMotion.class){
ilog("Motion detected from "+Integer.toHexString(((int[])data.get("address"))[1]));
} else {
ilog("Unknown data: "+Arrays.toString((int[])data.get("raw")));
@@ -66,16 +61,16 @@ public void run(Map<Object, Object> services) {
xbc = (XBeeController) services.get(XBeeController.class.getName());
ls = (LogService) services.get(LogService.class.getName());
ilog("start");
- weather = new SparkfunWeatherboard(WEATHER_ADDRESS, xbc);
- range = new MaxbotixRangefinder(RANGE_ADDRESS, xbc);
- motion = new PIRMotion(MOTION_ADDRESS , xbc);
+ xbc.addPredictive(SparkfunWeatherboard.class);
+ xbc.addPredictive(MaxbotixRangefinder.class);
+ xbc.addPredictive(PIRMotion.class);
}
@Override
public void shutdown() {
- xbc.removeListener(WEATHER_ADDRESS);
- xbc.removeListener(RANGE_ADDRESS);
- xbc.removeListener(MOTION_ADDRESS);
+ xbc.removeAll(SparkfunWeatherboard.class);
+ xbc.removeAll(MaxbotixRangefinder.class);
+ xbc.removeAll(PIRMotion.class);
ilog("Stop");
}
@@ -122,6 +122,7 @@ public void processResponse(XBeeResponse res) {
//so we shouldn't report unparseable data.
if (ret != null){
ret.put("protocol", protocols.get(pkt.getSourceAddress()));
+ ret.put("class", protocols.get(pkt.getSourceAddress()).getClass());
ret.put("address", pkt.getSourceAddress().getAddress());
}
return ret;
@@ -135,6 +136,7 @@ public void processResponse(XBeeResponse res) {
if (ret != null){
dlog("prediction success: "+protocols.get(pkt.getSourceAddress()).getClass().getName());
ret.put("protocol", protocols.get(pkt.getSourceAddress()));
+ ret.put("class", protocols.get(pkt.getSourceAddress()).getClass());
ret.put("address", pkt.getSourceAddress().getAddress());
}
return ret;
@@ -217,9 +219,12 @@ public void addPredictive(Class proto) {
@Override
public void removeAll(Class proto) {
- expectedProtocols.remove(proto);
+ dlog("removing "+proto.getName()+" from list...");
+ boolean success = expectedProtocols.remove(proto);
+ dlog("..."+success);
for (Map.Entry<XBeeAddress, XBeeProtocol> entry : protocols.entrySet()){
if (entry.getValue().getClass() == proto){
+ dlog("removing protocol at "+ByteUtils.toBase16(entry.getKey().getAddress()));
protocols.remove(entry.getKey());
}
}
@@ -13,6 +13,8 @@
import com.rapplogic.xbee.util.ByteUtils;
public class MaxbotixRangefinder extends BaseXBeeProtocol {
+ public MaxbotixRangefinder(){
+ }
public MaxbotixRangefinder(int[] address, XBeeController con) {
super(address, con);
@@ -12,6 +12,9 @@
import com.rapplogic.xbee.api.wpan.RxResponseIoSample;
public class PIRMotion extends BaseXBeeProtocol {
+ public PIRMotion(){
+ }
+
public PIRMotion(int[] address, XBeeController con) {
super(address, con);
}
@@ -17,6 +17,8 @@
import com.rapplogic.xbee.util.ByteUtils;
public class SerialDevice extends BaseXBeeProtocol {
+ public SerialDevice(){
+ }
public SerialDevice(int[] address, XBeeController con) {
super(address, con);
@@ -13,6 +13,8 @@
import com.rapplogic.xbee.util.ByteUtils;
public class SparkfunWeatherboard extends BaseXBeeProtocol {
+ public SparkfunWeatherboard(){
+ }
public SparkfunWeatherboard(int[] address, XBeeController con) {
super(address, con);
@@ -68,12 +70,14 @@ public boolean parseable(XBeeResponse res){
data = data.replaceAll("\r", "");
if (data.charAt(0) != '$')
return false;
- data = data.substring(2,data.length()-2);
+ data = data.substring(2);
String[] values = data.split(",");
- if (values.length != 10)
+ if (values.length != 10){
return false;
- if (values[9] != "*")
+ }
+ if (!values[9].contains("*")){
return false;
+ }
int[] floats = {0,2,3,4,5,7,8};
for (int idx:floats){
if (!values[idx].contains("."))

0 comments on commit 7169405

Please sign in to comment.