Permalink
Browse files

Arrow Telematics Solution Code

Written by jconnolly
Code shipped with Telematics Solution kit for Arrow
  • Loading branch information...
1 parent 08b5841 commit 8be3dcac3f0ee4a940115b208cc23a3526f09644 mgrundy committed Nov 1, 2011
@@ -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>
View
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ArrowTelematicsSolution</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>
@@ -0,0 +1,7 @@
+#Mon Oct 17 14:20:14 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
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bug-Bundle-Type: Application
+Bundle-Vendor: John Connolly
+Bundle-Version: 1.0.0
+BUG-API-Version: 2.0.2
+Bundle-Name: ArrowTelematicsSolution
+Bundle-Activator: arrowtelematicssolution.Activator
+Bundle-ManifestVersion: 2
+Bundle-Description: Simple demonstration application displaying the LC
+ D acceleration and GPS lat/lon (when available) on the LCD.
+Import-Package: org.osgi.framework,com.buglabs.bug.module.gps.pub,com.
+ buglabs.bug.module.lcd.pub,org.osgi.util.tracker,org.osgi.service.log
+ ,com.buglabs.application,com.buglabs.util,javax.swing,com.buglabs.bug
+ .accelerometer.pub
+Bundle-SymbolicName: ArrowTelematicsSolution
+
@@ -0,0 +1,58 @@
+/**
+ * Generated by Dragonfly SDK.
+ */
+package arrowtelematicssolution;
+
+
+import com.buglabs.bug.module.gps.pub.IPositionProvider;
+import com.buglabs.bug.module.gps.pub.INMEASentenceProvider;
+import com.buglabs.bug.module.gps.pub.INMEARawFeed;
+import com.buglabs.bug.module.lcd.pub.IML8953Accelerometer;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+import com.buglabs.application.ServiceTrackerHelper;
+
+
+/**
+ * BundleActivator for ArrowTelematicsSolution. The OSGi entry point to the application.
+ *
+ */
+public class Activator implements BundleActivator {
+ /**
+ * OSGi services the application depends on.
+ */
+ private static final String [] services = {
+ IPositionProvider.class.getName(),
+ INMEASentenceProvider.class.getName(),
+ INMEARawFeed.class.getName(),
+ IML8953Accelerometer.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 ArrowTelematicsSolutionApplication());
+ System.out.println("DEBUG (" + this.getClass().getName() + "): Bundle Start");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+
+ System.out.println("DEBUG (" + this.getClass().getName() + "): Bundle Stop");
+
+ //Will cause the ManagedRunnable.shutdown() to be called.
+ serviceTracker.close();
+ }
+
+
+}
@@ -0,0 +1,72 @@
+package arrowtelematicssolution;
+
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Map;
+
+import arrowtelematicssolution.view.TelematicsFrame;
+
+import com.buglabs.bug.module.gps.pub.IPositionProvider;
+import com.buglabs.bug.module.gps.pub.INMEASentenceProvider;
+import com.buglabs.bug.module.gps.pub.INMEARawFeed;
+import com.buglabs.bug.module.lcd.pub.IML8953Accelerometer;
+
+import com.buglabs.application.ServiceTrackerHelper.ManagedRunnable;
+/**
+ * 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 ArrowTelematicsSolutionApplication implements ManagedRunnable {
+
+ private IPositionProvider ipositionprovider;
+ private INMEASentenceProvider inmeasentenceprovider;
+ private INMEARawFeed inmearawfeed;
+ private IML8953Accelerometer iml8953accelerometer;
+
+ @Override
+ public void run(Map<Object, Object> services) {
+ ipositionprovider = (IPositionProvider) services.get(IPositionProvider.class.getName());
+ inmeasentenceprovider = (INMEASentenceProvider) services.get(INMEASentenceProvider.class.getName());
+ inmearawfeed = (INMEARawFeed) services.get(INMEARawFeed.class.getName());
+ iml8953accelerometer = (IML8953Accelerometer) services.get(IML8953Accelerometer.class.getName());
+ System.out.println("DEBUG (" + this.getClass().getName() + "): Application Run");
+ final TelematicsFrame frame = new TelematicsFrame("Arrow Telematics Demo", this);
+ frame.addWindowListener(new WindowAdapter(){
+ public void windowClosing(WindowEvent e){
+ frame.dispose();
+ }
+ });
+ frame.schedule(0, 1000);
+
+ }
+
+ public IML8953Accelerometer getIml8953accelerometer() {
+ return iml8953accelerometer;
+ }
+
+ public INMEARawFeed getInmearawfeed() {
+ return inmearawfeed;
+ }
+
+ public INMEASentenceProvider getInmeasentenceprovider() {
+ return inmeasentenceprovider;
+ }
+
+ public IPositionProvider getIpositionprovider() {
+ return ipositionprovider;
+ }
+
+ @Override
+ public void shutdown() {
+ // TODO Add shutdown code here if necessary.
+ System.out.println("DEBUG (" + this.getClass().getName() + "): Application Shutdown");
+ }
+
+
+}
@@ -0,0 +1,179 @@
+/**
+ *
+ */
+package arrowtelematicssolution.view;
+
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GraphicsEnvironment;
+import java.awt.GridLayout;
+import java.awt.HeadlessException;
+import java.io.IOException;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import arrowtelematicssolution.ArrowTelematicsSolutionApplication;
+
+import com.buglabs.bug.accelerometer.pub.AccelerometerSample;
+import com.buglabs.bug.module.gps.pub.LatLon;
+
+/**
+ * @author jconnolly
+ *
+ */
+public class TelematicsFrame extends JFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6804508676226667277L;
+ private ArrowTelematicsSolutionApplication app;
+ private JLabel x;
+ private JLabel y;
+ private JLabel z;
+ private JLabel latlon;
+
+ /**
+ * @param title
+ * @throws HeadlessException
+ */
+ public TelematicsFrame(String title, ArrowTelematicsSolutionApplication app)
+ throws HeadlessException {
+ super(title);
+ this.app = app;
+ setup();
+ }
+
+ private void setup() {
+ this.setLayout(new FlowLayout());
+ JPanel topPanel = new JPanel();
+ JPanel bottomPanel = new JPanel();
+ JPanel accelerationLabelPanel = new JPanel();
+ JPanel locationLabelPanel = new JPanel();
+ this.getContentPane().add(accelerationLabelPanel);
+ this.getContentPane().add(topPanel);
+ this.getContentPane().add(locationLabelPanel);
+ this.getContentPane().add(bottomPanel);
+ topPanel.setLayout(new FlowLayout());
+ bottomPanel.setLayout(new FlowLayout());
+ x = new JLabel();
+ y = new JLabel();
+ z = new JLabel();
+ JLabel accelerationLabel = new JLabel(" Acceleration \n");
+ accelerationLabel.setFont(new Font("Liberation Sans", Font.PLAIN, 24));
+ x.setFont(new Font("Liberation Sans", Font.PLAIN, 16));
+ y.setFont(new Font("Liberation Sans", Font.PLAIN, 16));
+ z.setFont(new Font("Liberation Sans", Font.PLAIN, 16));
+
+ accelerationLabelPanel.add(accelerationLabel);
+ topPanel.add(x);
+ topPanel.add(y);
+ topPanel.add(z);
+ try {
+ x.setText("X: " + app.getIml8953accelerometer().readX());
+ y.setText("Y: " + app.getIml8953accelerometer().readY());
+ z.setText("Z: " + app.getIml8953accelerometer().readZ());
+ } catch (IOException e) {
+ e.printStackTrace();
+ x.setText("An error has occured.");
+ y.setText("");
+ z.setText("");
+ }
+ JLabel locationLabel = new JLabel(
+ " Location \n");
+ locationLabel.setFont(new Font("Liberation Sans", Font.PLAIN, 24));
+ locationLabelPanel.add(locationLabel);
+ latlon = new JLabel();
+ latlon.setFont(new Font("Liberation Sans", Font.PLAIN, 16));
+ bottomPanel.add(latlon);
+ try {
+ if (app.getIpositionprovider().getLatitudeLongitude() != null) {
+ LatLon reading = app.getIpositionprovider()
+ .getLatitudeLongitude();
+ String latRaw = Double.toString(reading.latitude);
+ String latTruncated;
+ String lonTruncated;
+ if (latRaw.indexOf('.') + 6 < latRaw.length()) {
+ latTruncated = latRaw.substring(0, latRaw.indexOf('.') + 6);
+ } else {
+ latTruncated = latRaw;
+ }
+ String lonRaw = Double.toString(reading.longitude);
+ if (lonRaw.indexOf('.') + 6 < lonRaw.length()) {
+ lonTruncated = lonRaw.substring(0, lonRaw.indexOf('.') + 6);
+ } else {
+ lonTruncated = lonRaw;
+ }
+ latlon.setText("Latitude: " + latTruncated + " "
+ + "Longitude: " + lonTruncated);
+ } else {
+ latlon.setText("No Fix");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this.setVisible(true);
+ }
+
+ public void schedule(final int delayMillis, final int intervalMillis) {
+ new Thread() {
+ public void run() {
+ AccelerometerSample sample;
+ try {
+ Thread.sleep(delayMillis);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ while (true) {
+ try {
+ if (app.getIpositionprovider().getLatitudeLongitude() != null) {
+ LatLon reading = app.getIpositionprovider()
+ .getLatitudeLongitude();
+ String latRaw = Double.toString(reading.latitude);
+ String latTruncated;
+ String lonTruncated;
+ if (latRaw.indexOf('.') + 6 < latRaw.length()) {
+ latTruncated = latRaw.substring(0,
+ latRaw.indexOf('.') + 6);
+ } else {
+ latTruncated = latRaw;
+ }
+ String lonRaw = Double.toString(reading.longitude);
+ if (lonRaw.indexOf('.') + 6 < lonRaw.length()) {
+ lonTruncated = lonRaw.substring(0,
+ lonRaw.indexOf('.') + 6);
+ } else {
+ lonTruncated = lonRaw;
+ }
+ latlon.setText("Latitude: " + latTruncated + " "
+ + "Longitude: " + lonTruncated);
+ } else {
+ latlon.setText("No Fix");
+ }
+
+ try {
+ sample = app.getIml8953accelerometer().readSample();
+ x.setText("X: " + sample.getAccelerationX());
+ y.setText("Y: " + sample.getAccelerationY());
+ z.setText("Z " + sample.getAccelerationZ());
+ } catch (IOException e) {
+ e.printStackTrace();
+ x.setText("An error has occured.");
+ y.setText("");
+ z.setText("");
+ }
+ try {
+ Thread.sleep(intervalMillis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+ }
+ }.start();
+ }
+}

0 comments on commit 8be3dca

Please sign in to comment.