1 /* 2 * Author: Stefan Andritoiu <stefan.andritoiu (at) intel.com> 3 * Copyright (c) 2015 Intel Corporation. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 public class Ublox6Sample { 26 private static final int BUFFERLENGTH = 256; 27 28 static { 29 try { 30 System.loadLibrary("javaupm_ublox6"); 31 } catch (UnsatisfiedLinkError e) { 32 System.err.println("error in loading native library"); 33 System.exit(-1); 34 } 35 } 36 37 public static void main(String[] args) throws InterruptedException { 38 // ! [Interesting] 39 // Instantiate a Ublox6 GPS device on uart 0 40 upm_ublox6.Ublox6 nmea = new upm_ublox6.Ublox6(0); 41 42 // make sure port is initialized properly. 9600 baud is the default. 43 if (!nmea.setupTty()) { 44 throw new RuntimeException("Failed to setup tty port parameters"); 45 } 46 47 // Collect and output NMEA data. There are various libraries out on 48 // the Internet, that can handle decoding NMEA data and presenting 49 // it in a more easily accessible format. This example will just 50 // check for, and read raw NMEA data from the device and output it 51 // on standard output. 52 53 // This device also supports numerous configuration options, which 54 // you can set with writeData(). Please refer to the Ublox-6 data 55 // sheet for further information on the formats of the data sent and 56 // received, and the various operating modes available. 57 58 byte[] nmeaBuffer = new byte[BUFFERLENGTH]; 59 60 while (true) { 61 // we don't want the read to block in this example, so always 62 // check to see if data is available first. 63 if (nmea.dataAvailable()) { 64 int rv = nmea.readData(nmeaBuffer); 65 66 if (rv > 0) 67 for (int i = 0; i < rv; i++) 68 System.out.print((char) nmeaBuffer[i]); 69 70 if (rv < 0) { // some sort of read error occurred 71 System.err.println("Port read error."); 72 break; 73 } 74 continue; 75 } 76 77 Thread.sleep(1000); 78 } 79 // ! [Interesting] 80 } 81 82 }