Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit - RM code
  • Loading branch information
theterg committed Sep 23, 2011
0 parents commit 60bd00f
Show file tree
Hide file tree
Showing 701 changed files with 49,782 additions and 0 deletions.
8 changes: 8 additions & 0 deletions XBeeAPITest/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="com.buglabs.dragonfly.jdt.BugClasspathContainerInitializer"/>
<classpathentry kind="output" path=""/>
</classpath>
29 changes: 29 additions & 0 deletions XBeeAPITest/.project
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>XBeeAPITest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.buglabs.dragonfly.BugApplicationNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions XBeeAPITest/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
#Wed Sep 21 17:39:04 EDT 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.6
23 changes: 23 additions & 0 deletions XBeeAPITest/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: XBeeAPITest
Bundle-Activator: xbeeapitest.Activator
Bundle-SymbolicName: XBeeAPITest
Bundle-Version: 1.0.0
Bundle-Vendor: terg
Bug-Bundle-Type: Application
BUG-API-Version: 2.0.2
Import-Package: com.buglabs.application,
com.buglabs.util,
com.rapplogic.xbee,
com.rapplogic.xbee.api,
com.rapplogic.xbee.api.wpan,
com.rapplogic.xbee.api.zigbee,
com.rapplogic.xbee.examples,
com.rapplogic.xbee.examples.wpan,
com.rapplogic.xbee.examples.zigbee,
com.rapplogic.xbee.test,
com.rapplogic.xbee.util,
org.osgi.framework,
org.osgi.service.log,
org.osgi.util.tracker
Binary file added XBeeAPITest/xbeeapitest/Activator.class
Binary file not shown.
50 changes: 50 additions & 0 deletions XBeeAPITest/xbeeapitest/Activator.java
@@ -0,0 +1,50 @@
/**
* Generated by Dragonfly SDK.
*/
package xbeeapitest;


import org.osgi.service.log.LogService;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;

import com.buglabs.application.ServiceTrackerHelper;


/**
* BundleActivator for XBeeAPITest. The OSGi entry point to the application.
*
*/
public class Activator implements BundleActivator {
/**
* OSGi services the application depends on.
*/
private static final String [] services = {
LogService.class.getName(),
};
private ServiceTracker serviceTracker;

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
//Begin tracking services, and when all services are available, create thread and call ManagedRunnable.run().
serviceTracker = ServiceTrackerHelper.openServiceTracker(context, services, new XBeeAPITestApplication());

}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {

//Will cause the ManagedRunnable.shutdown() to be called.
serviceTracker.close();
}


}
Binary file not shown.
Binary file not shown.
120 changes: 120 additions & 0 deletions XBeeAPITest/xbeeapitest/XBeeAPITestApplication.java
@@ -0,0 +1,120 @@
package xbeeapitest;

import java.util.Map;
import java.util.Properties;

import org.osgi.service.log.LogService;

import com.buglabs.application.ServiceTrackerHelper.ManagedRunnable;
import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.AtCommand;
import com.rapplogic.xbee.api.AtCommandResponse;
import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeAddress;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.wpan.RxBaseResponse;
import com.rapplogic.xbee.api.wpan.RxResponse;
import com.rapplogic.xbee.api.wpan.RxResponseIoSample;
import com.rapplogic.xbee.util.ByteUtils;
/**
* This class represents the running application when all service dependencies are fulfilled.
*
* The run() method will be called with a map containing all the services specified in ServiceTrackerHelper.openServiceTracker().
* The application will run in a separate thread than the caller of start() in the Activator. See
* ManagedInlineRunnable for a thread-less application.
*
* By default, the application will only be started when all service dependencies are fulfilled. For
* finer grained service binding logic, see ServiceTrackerHelper.openServiceTracker(BundleContext context, String[] services, Filter filter, ServiceTrackerCustomizer customizer)
*/
public class XBeeAPITestApplication implements ManagedRunnable {
private LogService ls;
private XBee xb;

@Override
public void run(Map<Object, Object> services) {
ls = (LogService) services.get(LogService.class.getName());
ilog("Start, connecting");
System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyUSB0");
xb = new XBee();
try {
xb.open("/dev/ttyUSB0",9600);
dlog("Opened, requesting data");
AtCommandResponse res = (AtCommandResponse) xb.sendSynchronous(new AtCommand("MY"), 10000);
if (res.isOk()){
ilog("Addr of attached XBee: "+ByteUtils.toBase16(res.getValue()));
}
} catch (XBeeException e) {
e.printStackTrace();
shutdown();
return;
}
xb.addPacketListener(new PacketParser());
}

@Override
public void shutdown() {
ilog("Stop.");
xb.close();
}

private class PacketParser implements PacketListener{

@Override
public void processResponse(XBeeResponse res) {
//If the incoming data is a serial data packet
if (res.getApiId() == ApiId.RX_16_RESPONSE){
RxResponse pkt = (RxResponse) res;
String data = ByteUtils.toString(pkt.getData());
//dlog("Incoming data "+pkt.getSourceAddress().getAddress()[1]+": "+data);
if (pkt.getSourceAddress().getAddress()[1] == 1){
//Data from the Sonar mote
if (data.charAt(0) == 'R'){
ilog("Range: "+data.substring(1)+"(cm)");
} else {
dlog("Sonar data: "+data);
}
} else if (pkt.getSourceAddress().getAddress()[1] == 2){
//Serial data from the Motion mote (must be in serial mode)
if (data.contains("M")){
ilog("Motion detected!");
} else {
dlog("Motion data: "+data);
}
} else if (pkt.getSourceAddress().getAddress()[1] == 3){
//Data from the weatherboard
if (data.charAt(0) == '$'){
data = data.substring(2,data.length()-2);
String[] values = data.split(",");
ilog("Temperature: "+values[0]+" (F)");
ilog("Humidity: "+values[1]+" (%)");
ilog("Dewpoint: "+values[2]+" (F)");
ilog("Pressure: "+values[3]+" (in/hg)");
ilog("Light: "+values[4]+" (%)");
ilog("Wind Speed: "+values[5]+" (mph)");
ilog("Wind Direction: "+values[6]+" (deg)");
ilog("Rainfall: "+values[7]+" (in)");
ilog("Battery: "+values[8]+" (V)");
} else {
dlog("Weatherboard info: "+data);
}
} else {
dlog("Data from "+pkt.getSourceAddress().getAddress()[1]+": "+data);
}
} else if (res.getApiId() == ApiId.RX_16_IO_RESPONSE){
//If incoming data is an IO packet
//Assume this was from a Motion module
RxResponseIoSample pkt = (RxResponseIoSample) res;
ilog("Motion detected: "+ByteUtils.toBase16(pkt.getSamples()[0].getDioMsb())+","+ByteUtils.toBase16(pkt.getSamples()[0].getDioLsb()));
}
}

}

//Wrappers for the log service (to standardize logged messages)
void ilog(String message){ ls.log(ls.LOG_INFO, "["+this.getClass().getSimpleName()+"] "+message); }
void dlog(String message){ ls.log(ls.LOG_DEBUG, "["+this.getClass().getSimpleName()+"] "+message); }
void elog(String message){ ls.log(ls.LOG_ERROR, "["+this.getClass().getSimpleName()+"] "+message); }
void wlog(String message){ ls.log(ls.LOG_WARNING, "["+this.getClass().getSimpleName()+"] "+message); }
}
8 changes: 8 additions & 0 deletions log4jlib_osgi/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="com.buglabs.dragonfly.jdt.BugClasspathContainerInitializer"/>
<classpathentry kind="output" path=""/>
</classpath>
29 changes: 29 additions & 0 deletions log4jlib_osgi/.project
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>log4jlib_osgi</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.buglabs.dragonfly.BugApplicationNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions log4jlib_osgi/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
#Wed Oct 27 14:43:26 EDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.6
10 changes: 10 additions & 0 deletions log4jlib_osgi/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
Manifest-Version: 1.0
Export-Package: org.apache.log4j
Bug-Bundle-Type: Application
Bundle-Vendor: jconnolly
Bundle-Version: 1.0.0
BUG-API-Version: 1.4.4
Bundle-Name: log4jlib_osgi
Import-Package: org.osgi.framework
Bundle-SymbolicName: log4jlib_osgi

Binary file added log4jlib_osgi/org/apache/log4j/Appender.class
Binary file not shown.

0 comments on commit 60bd00f

Please sign in to comment.