summaryrefslogtreecommitdiff
path: root/trunk/build/preprocessed/nav
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/build/preprocessed/nav')
-rwxr-xr-xtrunk/build/preprocessed/nav/locListener.java35
-rwxr-xr-xtrunk/build/preprocessed/nav/navigate.java93
-rwxr-xr-xtrunk/build/preprocessed/nav/processLoc.java104
-rwxr-xr-xtrunk/build/preprocessed/nav/processState.java50
4 files changed, 282 insertions, 0 deletions
diff --git a/trunk/build/preprocessed/nav/locListener.java b/trunk/build/preprocessed/nav/locListener.java
new file mode 100755
index 0000000..54ff7db
--- /dev/null
+++ b/trunk/build/preprocessed/nav/locListener.java
@@ -0,0 +1,35 @@
+/*
+ * locListener.java
+ *
+ * Created on July 14, 2007, 4:20 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package nav;
+
+import javax.microedition.location.*;
+
+/**
+ *
+ * @author manut
+ */
+public class locListener implements LocationListener {
+
+ private navigate nav;
+
+ /** Creates a new instance of locListener */
+ public locListener(navigate _nav) {
+ nav = _nav;
+ }
+
+ public void providerStateChanged(LocationProvider prov, int newState){
+ nav.setNewState(newState);
+ }
+
+ public void locationUpdated(LocationProvider prov, Location location){
+ nav.setNewLoc(location);
+ }
+
+}
diff --git a/trunk/build/preprocessed/nav/navigate.java b/trunk/build/preprocessed/nav/navigate.java
new file mode 100755
index 0000000..eeaffce
--- /dev/null
+++ b/trunk/build/preprocessed/nav/navigate.java
@@ -0,0 +1,93 @@
+/*
+ * navigate.java
+ *
+ * Created on July 14, 2007, 2:18 AM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package nav;
+
+import javax.microedition.location.*;
+import gui.geoc;
+import java.lang.Thread;
+
+/**
+ *
+ * @author manut
+ */
+public class navigate {
+
+ private geoc gui;
+ private LocationProvider pos;
+ private int provState;
+
+ private Location actLoc;
+ private Landmark dest;
+
+ private processLoc pLoc;
+ private processState pState;
+
+ /** Creates a new instance of navigate */
+ public navigate(geoc _gui) throws LocationException {
+
+ pos = LocationProvider.getInstance(null);
+ if (pos == null)
+ throw new LocationException();
+
+ gui = _gui;
+ pLoc = new processLoc(gui);
+ pState = new processState(gui);
+ }
+
+ /** sets destination */
+ public void setDestination ( String north, String east )
+ throws IllegalArgumentException {
+
+ double latitude, longitude;
+ float altitude, hAcc, vAcc;
+
+ latitude = Coordinates.convert(north);
+ longitude = Coordinates.convert(east);
+
+ altitude = Float.NaN;
+ hAcc = 0;
+ vAcc = 0;
+
+ QualifiedCoordinates coord;
+ coord = new QualifiedCoordinates( latitude,
+ longitude,
+ altitude, hAcc, vAcc
+ );
+
+ if(dest == null){
+ AddressInfo info = new AddressInfo();
+ dest = new Landmark("destination", "stageX", coord, info);
+ } else
+ dest.setQualifiedCoordinates(coord);
+
+
+ locListener locList = new locListener(this);
+ int interval = -1;
+
+ gui.get_stringItemDestNorth().setText(north);
+ gui.get_stringItemDestEast().setText(east);
+
+ pos.setLocationListener(locList, interval, 0, 0);
+
+ }
+
+ public void setNewLoc(Location loc){
+ actLoc = loc;
+ pLoc.set(loc, dest);
+ pLoc.run();
+ }
+
+ public void setNewState(int state){
+ provState = state;
+ pState.set(state);
+ pState.run();
+ }
+
+}
diff --git a/trunk/build/preprocessed/nav/processLoc.java b/trunk/build/preprocessed/nav/processLoc.java
new file mode 100755
index 0000000..fdcd863
--- /dev/null
+++ b/trunk/build/preprocessed/nav/processLoc.java
@@ -0,0 +1,104 @@
+/*
+ * processLoc.java
+ *
+ * Created on July 14, 2007, 4:59 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package nav;
+
+import java.lang.Thread;
+import javax.microedition.location.*;
+
+import gui.*;
+
+/**
+ *
+ * @author manut
+ */
+public class processLoc extends Thread {
+
+ private geoc gui;
+ private Landmark dest;
+ private Location loc;
+ private Coordinates lastloc;
+ private Coordinates north;
+
+ /** Creates a new instance of processLoc */
+ public processLoc(geoc _gui) {
+ gui = _gui;
+ north = new Coordinates(90, 0, 0);
+ lastloc = null;
+ }
+
+ public void set(Location _loc, Landmark _dest){
+
+ loc = _loc;
+ dest = _dest;
+
+ }
+
+ private double arcsin(double azimuth){
+ double calc;
+ double last_calc = 0;
+
+ for(double i = -1; i <= 1; i=i+0.001){
+ calc = java.lang.Math.sin(i);
+ if ( calc == azimuth ){
+ return i;
+ } else if (last_calc <= azimuth && calc > azimuth){
+ return i;
+ } else
+ last_calc = calc;
+ }
+ return -2;
+ }
+
+ public void run(){
+ // calc course, distance
+ // A = LastPosition
+ // B = Destination
+ // C = Northpole
+ // D = ActPosition
+ // E = going further on straight forward, until you meet BC
+ //
+ // alphaI = arcsin( ( CD * sin(gammaI) ) / AB )
+ // betaI = arcsin( ( CD * sin(gammaII)) / BD )
+ // deltaI = 180 - alphaI - gammaI
+ // deltaII = 180 - deltaI
+ // epsilI = 180 - deltaII - gammaII
+ // epsilII = 180 - epsilI
+ // gesucht = 180 - epsilII - betaI
+ // --> courseCorrection = - 180 - arcsin( (CD * sin(gammaI)) / AB ) - gammaI - gammaII - arcsin( CD * (sin(gammaII)) / BD )
+
+ if( (lastloc!= null) && loc.isValid())
+ {
+
+ float gammaI = lastloc.azimuthTo(loc.getQualifiedCoordinates());
+ float gammaII = loc.getQualifiedCoordinates().azimuthTo(dest.getQualifiedCoordinates());
+ float AB = lastloc.distance(dest.getQualifiedCoordinates());
+ float BD = loc.getQualifiedCoordinates().distance(dest.getQualifiedCoordinates());
+ float CD = loc.getQualifiedCoordinates().distance(north);
+
+ double actC = ( - 180 - arcsin( (CD * java.lang.Math.sin(gammaI)) / AB ) - gammaI - gammaII - arcsin( CD * (java.lang.Math.sin(gammaII)) / BD ) ) % 360;
+ int actCourse = (int) actC;
+ if (actCourse < 0)
+ actCourse = actCourse+360;
+
+ // set GUI
+ gui.get_stringItemActNorth().setText(Coordinates.convert(loc.getQualifiedCoordinates().getLatitude(), 2));
+ gui.get_stringItemActEast().setText(Coordinates.convert(loc.getQualifiedCoordinates().getLongitude(), 2));
+ gui.get_stringItemActHeight().setText(String.valueOf(loc.getQualifiedCoordinates().getAltitude()));
+ if ( (actCourse != 112) )
+ gui.get_stringItemCourse().setText(String.valueOf(actCourse));
+ gui.get_stringItemDistance().setText(String.valueOf(BD));
+
+ }
+
+ if ( loc.isValid() )
+ lastloc = loc.getQualifiedCoordinates();
+ }
+
+}
diff --git a/trunk/build/preprocessed/nav/processState.java b/trunk/build/preprocessed/nav/processState.java
new file mode 100755
index 0000000..9c7d756
--- /dev/null
+++ b/trunk/build/preprocessed/nav/processState.java
@@ -0,0 +1,50 @@
+/*
+ * processState.java
+ *
+ * Created on July 14, 2007, 5:02 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package nav;
+
+import gui.*;
+import java.lang.Thread;
+import javax.microedition.location.*;
+
+/**
+ *
+ * @author manut
+ */
+public class processState extends Thread{
+
+ private geoc gui;
+ private int state;
+
+ /** Creates a new instance of processState */
+ public processState(geoc _gui) {
+ gui = _gui;
+ }
+
+ public void set(int _state){
+ state = _state;
+ }
+
+ public void run(){
+ switch(state){
+ case LocationProvider.AVAILABLE:
+ gui.get_stringItemHead2().setLabel("GPS available");
+ break;
+ case LocationProvider.OUT_OF_SERVICE:
+ gui.get_stringItemHead2().setLabel("no GPS!");
+ break;
+ case LocationProvider.TEMPORARILY_UNAVAILABLE:
+ gui.get_stringItemHead2().setLabel("weak GPS signal");
+ break;
+ default:
+ gui.get_stringItemHead2().setLabel("Location API Error");
+ }
+ }
+
+}