I've a problem with the GPS functions in leJOS.
I want the device to connect with a Bluetooth GPS device, that works fine. But in most cases I get an "Exception: 16", somewhere after the println("Verbunden."). What does that mean?
The System has two Coordinates: koor and koor_aktuell. koor is the previous coordinate, koor_aktuell the current. In the while-part, the distance between these coordinates is added to "entfernung".
Here is my code:
- Code: Select all
import.....
public class BLUBB {
public static SimpleGPS gps = null;
public static InputStream in = null;
public static Coordinates koor, koor_aktuell;
public static final byte[] pin = {(byte) '0', (byte) '0', (byte) '0', (byte) '0'};
public static void main(String[] args) {
System.out.println("Geraet-Suche...");
RemoteDevice btrd = Bluetooth.getKnownDevice("B-Speech GPS2");
if (btrd == null) {
System.out.println("Kein Geraet gefunden.");
Button.waitForPress();
return;
} else {
System.out.println("Geraet gefunden.");
}
System.out.println();
System.out.println("Verbinden...");
BTConnection btGPS = Bluetooth.connect(btrd.getDeviceAddr(), NXTConnection.RAW, pin);
if (btGPS == null) {
System.out.println("Nicht verbunden.)");
Button.waitForPress();
return;
} else {
System.out.println("Verbunden.");
}
System.out.println();
in = btGPS.openInputStream();
gps = new GPS(in);
double entfernung = 0;
koor = new Coordinates(gps.getLatitude(), gps.getLongitude(), gps.getAltitude());
int count = 0;
while(true) {
try{Thread.sleep(6000);}catch(Exception e) {}
koor_aktuell = new Coordinates(gps.getLatitude(), gps.getLongitude(), gps.getAltitude());
entfernung += koor_aktuell.distance(koor);
System.out.println(count + ": " + entfernung);
System.out.println();
koor = koor_aktuell;
count++;
}
}
}
Hopefully someone of you can help me.
Thanks, Andrej

