java: Added java samples and applied coding style rules to all previous samples

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Stefan Andritoiu
2015-10-08 14:30:12 +03:00
committed by Mihai Tudor Panu
parent 27f34face1
commit e34863f223
71 changed files with 2433 additions and 649 deletions

View File

@ -23,60 +23,60 @@
*/
public class Ublox6Sample {
private static final int BUFFERLENGTH = 256;
private static final int BUFFERLENGTH = 256;
static {
try {
System.loadLibrary("javaupm_ublox6");
}catch (UnsatisfiedLinkError e) {
} catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// ! [Interesting]
// Instantiate a Ublox6 GPS device on uart 0
upm_ublox6.Ublox6 nmea = new upm_ublox6.Ublox6(0);
// make sure port is initialized properly. 9600 baud is the default.
if(!nmea.setupTty()){
// make sure port is initialized properly. 9600 baud is the default.
if (!nmea.setupTty()) {
throw new RuntimeException("Failed to setup tty port parameters");
}
}
// Collect and output NMEA data. There are various libraries out on
// the Internet, that can handle decoding NMEA data and presenting
// it in a more easily accessible format. This example will just
// it in a more easily accessible format. This example will just
// check for, and read raw NMEA data from the device and output it
// on standard output.
// This device also supports numerous configuration options, which
// you can set with writeData(). Please refer to the Ublox-6 data
// you can set with writeData(). Please refer to the Ublox-6 data
// sheet for further information on the formats of the data sent and
// received, and the various operating modes available.
byte[] nmeaBuffer = new byte[BUFFERLENGTH];
while(true){
while (true) {
// we don't want the read to block in this example, so always
// check to see if data is available first.
if (nmea.dataAvailable()){
if (nmea.dataAvailable()) {
int rv = nmea.readData(nmeaBuffer);
if(rv > 0)
if (rv > 0)
for (int i = 0; i < rv; i++)
System.out.print((char)nmeaBuffer[i]);
if (rv < 0){ // some sort of read error occurred
System.err.println("Port read error.") ;
System.out.print((char) nmeaBuffer[i]);
if (rv < 0) { // some sort of read error occurred
System.err.println("Port read error.");
break;
}
continue;
}
Thread.sleep(1000);
}
//! [Interesting]
// ! [Interesting]
}
}