Permalink
Browse files

Added parseable() function in preparation for adding protocol detection

  • Loading branch information...
1 parent b81c352 commit c334a3546c7b063a1375e7111777782ac7d6a862 @theterg theterg committed Sep 27, 2011
@@ -45,5 +45,9 @@ public String toString(Map<String, Object> data) {
public String toString(){
return toString(last);
}
+ @Override
+ public boolean parseable(XBeeResponse res) {
+ return false;
+ }
}
@@ -43,5 +43,18 @@ public String toString(Map<String, Object> data) {
+"): "+data.get("Range");
return ret;
}
+
+ @Override
+ public boolean parseable(XBeeResponse res){
+ if (res.getApiId() != ApiId.RX_16_RESPONSE)
+ return false;
+ RxResponse pkt = (RxResponse) res;
+ String data = ByteUtils.toString(pkt.getData());
+ data = data.replaceAll("\n", "");
+ data = data.replaceAll("\r", "");
+ if ((data.charAt(0) == 'R')&&(data.length() == 4))
+ return true;
+ return false;
+ }
}
@@ -31,5 +31,12 @@ public PIRMotion(int[] address, XBeeController con) {
public String toString(Map<String, Object> data) {
return "Motion detected from "+Integer.toHexString(((int[])data.get("address"))[1]);
}
+
+ @Override
+ public boolean parseable(XBeeResponse res){
+ if (res.getApiId() == ApiId.RX_16_IO_RESPONSE)
+ return true;
+ return false;
+ }
}
@@ -53,5 +53,12 @@ public void write(String data){
con.getXBee().sendAsynchronous(request);
} catch (XBeeException e) {}
}
+
+ @Override
+ public boolean parseable(XBeeResponse res){
+ if (!((res.getApiId() == ApiId.RX_16_RESPONSE)||(res.getApiId() == ApiId.RX_64_RESPONSE)))
+ return false;
+ return true;
+ }
}
@@ -57,5 +57,29 @@ public String toString(Map<String, Object> data) {
ret += "Light: "+data.get("Light")+"\r\n";
return ret;
}
+
+ @Override
+ public boolean parseable(XBeeResponse res){
+ if (res.getApiId() != ApiId.RX_16_RESPONSE)
+ return false;
+ RxResponse pkt = (RxResponse) res;
+ String data = ByteUtils.toString(pkt.getData());
+ data = data.replaceAll("\n", "");
+ data = data.replaceAll("\r", "");
+ if (data.charAt(0) != '$')
+ return false;
+ data = data.substring(2,data.length()-2);
+ String[] values = data.split(",");
+ if (values.length != 10)
+ return false;
+ if (values[9] != "*")
+ return false;
+ int[] floats = {0,2,3,4,5,7,8};
+ for (int idx:floats){
+ if (!values[idx].contains("."))
+ return false;
+ }
+ return true;
+ }
}
@@ -10,4 +10,5 @@
public Map<String, Object> lastSample();
public XBeeAddress getAddr();
public String toString(Map<String, Object> data);
+ public boolean parseable(XBeeResponse res);
};

0 comments on commit c334a35

Please sign in to comment.