mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
ublox6: remove driver and replace with generic nmea_gps driver
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
a040f51cda
commit
d456066277
@ -4,6 +4,11 @@ API Changes {#apichanges}
|
|||||||
Here's a list of other API changes made to the library that break source/binary
|
Here's a list of other API changes made to the library that break source/binary
|
||||||
compatibility between releases:
|
compatibility between releases:
|
||||||
|
|
||||||
|
* The Ublox6 driver has been removed and replaced with a generic
|
||||||
|
implementation called nmea_gps. This driver should handle all
|
||||||
|
generic serial GPS devices that output NMEA data going forward. This
|
||||||
|
new driver has been tested with ublox6, DFRobot VK2828U7 (ublox7) and
|
||||||
|
ublox LEA-6H GPS devices.
|
||||||
* There were frequent misspellings of the word *Celsius* in the UPM
|
* There were frequent misspellings of the word *Celsius* in the UPM
|
||||||
code. In some cases, these were in method names, which will cause
|
code. In some cases, these were in method names, which will cause
|
||||||
some API compatibility issues. These have all been corrected for UPM
|
some API compatibility issues. These have all been corrected for UPM
|
||||||
|
@ -150,7 +150,6 @@ add_example (grovevdiv)
|
|||||||
add_example (grovewater)
|
add_example (grovewater)
|
||||||
add_example (guvas12d)
|
add_example (guvas12d)
|
||||||
add_example (mpr121)
|
add_example (mpr121)
|
||||||
add_example (ublox6)
|
|
||||||
add_example (yg1006)
|
add_example (yg1006)
|
||||||
add_example (wt5001)
|
add_example (wt5001)
|
||||||
add_example (ppd42ns)
|
add_example (ppd42ns)
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <signal.h>
|
|
||||||
#include "ublox6.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
bool shouldRun = true;
|
|
||||||
|
|
||||||
void sig_handler(int signo)
|
|
||||||
{
|
|
||||||
if (signo == SIGINT)
|
|
||||||
shouldRun = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t bufferLength = 256;
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
signal(SIGINT, sig_handler);
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Instantiate a Ublox6 GPS device on uart 0.
|
|
||||||
upm::Ublox6* nmea = new upm::Ublox6(0);
|
|
||||||
|
|
||||||
// make sure port is initialized properly. 9600 baud is the default.
|
|
||||||
if (!nmea->setupTty(B9600))
|
|
||||||
{
|
|
||||||
cerr << "Failed to setup tty port parameters" << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect and output NMEA data. There are various libraries out on
|
|
||||||
// the Internet, such as tinyGPS or tinyGPS++ that can handle
|
|
||||||
// decoding NMEA data and presenting 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 stdout.
|
|
||||||
|
|
||||||
// This device also supports numerous configuration options, which
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
char nmeaBuffer[bufferLength];
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// we don't want the read to block in this example, so always
|
|
||||||
// check to see if data is available first.
|
|
||||||
if (nmea->dataAvailable())
|
|
||||||
{
|
|
||||||
int rv = nmea->readData(nmeaBuffer, bufferLength);
|
|
||||||
|
|
||||||
if (rv > 0)
|
|
||||||
write(1, nmeaBuffer, rv);
|
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occurred
|
|
||||||
{
|
|
||||||
cerr << "Port read error." << endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(100000); // 100ms
|
|
||||||
}
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete nmea;
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -97,7 +97,6 @@ add_example(TM1637Sample tm1637)
|
|||||||
add_example(TP401Sample gas)
|
add_example(TP401Sample gas)
|
||||||
add_example(TSL2561Sample tsl2561)
|
add_example(TSL2561Sample tsl2561)
|
||||||
add_example(TTP223Sample ttp223)
|
add_example(TTP223Sample ttp223)
|
||||||
add_example(Ublox6Sample ublox6)
|
|
||||||
add_example(ULN200XASample uln200xa)
|
add_example(ULN200XASample uln200xa)
|
||||||
add_example(WaterLevelSensor waterlevel)
|
add_example(WaterLevelSensor waterlevel)
|
||||||
add_example(WT5001Sample wt5001)
|
add_example(WT5001Sample wt5001)
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Ublox6Sample {
|
|
||||||
private static final int BUFFERLENGTH = 256;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
// ! [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()) {
|
|
||||||
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
|
|
||||||
// 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
|
|
||||||
// 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) {
|
|
||||||
// we don't want the read to block in this example, so always
|
|
||||||
// check to see if data is available first.
|
|
||||||
if (nmea.dataAvailable()) {
|
|
||||||
int rv = nmea.readData(nmeaBuffer);
|
|
||||||
|
|
||||||
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.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Zion Orent <zorent@ics.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var GPSSensor = require('jsupm_ublox6');
|
|
||||||
|
|
||||||
// Instantiate a Ublox6 GPS device on uart 0.
|
|
||||||
var myGPSSensor = new GPSSensor.Ublox6(0);
|
|
||||||
|
|
||||||
if (!myGPSSensor.setupTty(GPSSensor.int_B9600))
|
|
||||||
{
|
|
||||||
console.log("Failed to setup tty port parameters");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect and output NMEA data.
|
|
||||||
|
|
||||||
// This device also supports numerous configuration options, which
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
var bufferLength = 256;
|
|
||||||
var nmeaBuffer = new GPSSensor.charArray(bufferLength);
|
|
||||||
|
|
||||||
function getGPSInfo()
|
|
||||||
{
|
|
||||||
// we don't want the read to block in this example, so always
|
|
||||||
// check to see if data is available first.
|
|
||||||
if (myGPSSensor.dataAvailable())
|
|
||||||
{
|
|
||||||
var rv = myGPSSensor.readData(nmeaBuffer, bufferLength);
|
|
||||||
|
|
||||||
var GPSData, dataCharCode, isNewLine, lastNewLine;
|
|
||||||
var numlines= 0;
|
|
||||||
if (rv > 0)
|
|
||||||
{
|
|
||||||
GPSData = "";
|
|
||||||
// read only the number of characters
|
|
||||||
// specified by myGPSSensor.readData
|
|
||||||
for (var x = 0; x < rv; x++)
|
|
||||||
GPSData += nmeaBuffer.getitem(x);
|
|
||||||
process.stdout.write(GPSData)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occurred
|
|
||||||
{
|
|
||||||
console.log("Port read error.");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setInterval(getGPSInfo, 100);
|
|
||||||
|
|
||||||
// Print message when exiting
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
console.log("Exiting...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,82 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# Author: Zion Orent <zorent@ics.com>
|
|
||||||
# Copyright (c) 2015 Intel Corporation.
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
# a copy of this software and associated documentation files (the
|
|
||||||
# "Software"), to deal in the Software without restriction, including
|
|
||||||
# without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
# permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
# the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be
|
|
||||||
# included in all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
import time, sys, signal, atexit
|
|
||||||
import pyupm_ublox6 as upmUblox6
|
|
||||||
|
|
||||||
# Instantiate a Ublox6 GPS device on uart 0.
|
|
||||||
myGPSSensor = upmUblox6.Ublox6(0)
|
|
||||||
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit, including functions from myGPSSensor
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
|
|
||||||
if (not myGPSSensor.setupTty(upmUblox6.cvar.int_B9600)):
|
|
||||||
print "Failed to setup tty port parameters"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Collect and output NMEA data.
|
|
||||||
|
|
||||||
# This device also supports numerous configuration options, which
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
|
|
||||||
bufferLength = 256
|
|
||||||
nmeaBuffer = upmUblox6.charArray(bufferLength)
|
|
||||||
|
|
||||||
def getGPSInfo():
|
|
||||||
# we don't want the read to block in this example, so always
|
|
||||||
# check to see if data is available first.
|
|
||||||
if (myGPSSensor.dataAvailable()):
|
|
||||||
rv = myGPSSensor.readData(nmeaBuffer, bufferLength)
|
|
||||||
|
|
||||||
numlines= 0
|
|
||||||
if (rv > 0):
|
|
||||||
GPSData = ""
|
|
||||||
# read only the number of characters
|
|
||||||
# specified by myGPSSensor.readData
|
|
||||||
for x in range(rv):
|
|
||||||
GPSData += nmeaBuffer.__getitem__(x)
|
|
||||||
sys.stdout.write(GPSData)
|
|
||||||
|
|
||||||
if (rv < 0): # some sort of read error occurred
|
|
||||||
print "Port read error."
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
while (1):
|
|
||||||
getGPSInfo()
|
|
||||||
time.sleep(.1)
|
|
@ -1,5 +0,0 @@
|
|||||||
set (libname "ublox6")
|
|
||||||
set (libdescription "upm u-blox 6 GPS UART support module")
|
|
||||||
set (module_src ${libname}.cxx)
|
|
||||||
set (module_hpp ${libname}.hpp)
|
|
||||||
upm_module_init()
|
|
@ -1,30 +0,0 @@
|
|||||||
%module javaupm_ublox6
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "../java_buffer.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_ublox6");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,21 +0,0 @@
|
|||||||
%module jsupm_ublox6
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "stdint.i"
|
|
||||||
%include "carrays.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
%array_class(char, charArray);
|
|
@ -1,25 +0,0 @@
|
|||||||
// Include doxygen-generated documentation
|
|
||||||
%include "pyupm_doxy2swig.i"
|
|
||||||
%module pyupm_ublox6
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "stdint.i"
|
|
||||||
%include "carrays.i"
|
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "ublox6.hpp"
|
|
||||||
speed_t int_B2400 = B2400;
|
|
||||||
speed_t int_B4800 = B4800;
|
|
||||||
speed_t int_B9600 = B9600;
|
|
||||||
speed_t int_B19200 = B19200;
|
|
||||||
speed_t int_B38400 = B38400;
|
|
||||||
%array_class(char, charArray);
|
|
@ -1,167 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "ublox6.hpp"
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Ublox6::Ublox6(int uart)
|
|
||||||
{
|
|
||||||
m_ttyFd = -1;
|
|
||||||
|
|
||||||
if ( !(m_uart = mraa_uart_init(uart)) )
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_uart_init() failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This requires a recent MRAA (1/2015)
|
|
||||||
const char *devPath = mraa_uart_get_dev_path(m_uart);
|
|
||||||
|
|
||||||
if (!devPath)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": mraa_uart_get_dev_path() failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now open the tty
|
|
||||||
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
|
||||||
{
|
|
||||||
string err = __FUNCTION__;
|
|
||||||
err += ": open of " + std::string(devPath) + " failed: " +
|
|
||||||
std::string(strerror(errno));
|
|
||||||
|
|
||||||
throw std::runtime_error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ublox6::~Ublox6()
|
|
||||||
{
|
|
||||||
if (m_ttyFd != -1)
|
|
||||||
close(m_ttyFd);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Ublox6::dataAvailable()
|
|
||||||
{
|
|
||||||
if (m_ttyFd == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
struct timeval timeout;
|
|
||||||
|
|
||||||
// no waiting
|
|
||||||
timeout.tv_sec = 0;
|
|
||||||
timeout.tv_usec = 0;
|
|
||||||
|
|
||||||
int nfds;
|
|
||||||
fd_set readfds;
|
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
|
||||||
|
|
||||||
FD_SET(m_ttyFd, &readfds);
|
|
||||||
|
|
||||||
if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0)
|
|
||||||
return true; // data is ready
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Ublox6::readData(char *buffer, int len)
|
|
||||||
{
|
|
||||||
if (m_ttyFd == -1)
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
int rv = read(m_ttyFd, buffer, len);
|
|
||||||
|
|
||||||
if (rv < 0)
|
|
||||||
{
|
|
||||||
string err = string(__FUNCTION__) + ": read failed: " +
|
|
||||||
string(strerror(errno));
|
|
||||||
|
|
||||||
throw std::runtime_error(err);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Ublox6::writeData(char * buffer, int len)
|
|
||||||
{
|
|
||||||
if (m_ttyFd == -1)
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
int rv = write(m_ttyFd, buffer, len);
|
|
||||||
|
|
||||||
if (rv < 0)
|
|
||||||
{
|
|
||||||
string err = string(__FUNCTION__) + ": write failed: " +
|
|
||||||
string(strerror(errno));
|
|
||||||
|
|
||||||
throw std::runtime_error(err);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
tcdrain(m_ttyFd);
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Ublox6::setupTty(speed_t baud)
|
|
||||||
{
|
|
||||||
if (m_ttyFd == -1)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
struct termios termio;
|
|
||||||
|
|
||||||
// get current modes
|
|
||||||
tcgetattr(m_ttyFd, &termio);
|
|
||||||
|
|
||||||
// setup for a 'raw' mode. 81N, no echo or special character
|
|
||||||
// handling, such as flow control.
|
|
||||||
cfmakeraw(&termio);
|
|
||||||
|
|
||||||
// set our baud rates
|
|
||||||
cfsetispeed(&termio, baud);
|
|
||||||
cfsetospeed(&termio, baud);
|
|
||||||
|
|
||||||
// make it so
|
|
||||||
int rv;
|
|
||||||
if ( (rv = tcsetattr(m_ttyFd, TCSAFLUSH, &termio)) < 0)
|
|
||||||
{
|
|
||||||
string err = string(__FUNCTION__) + ": tcsetattr failed: " +
|
|
||||||
string(strerror(errno));
|
|
||||||
|
|
||||||
throw std::runtime_error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <mraa/uart.h>
|
|
||||||
|
|
||||||
const int UBLOX6_DEFAULT_UART = 0;
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
/**
|
|
||||||
* @brief UBLOX6 & SIM28 GPS Module library
|
|
||||||
* @defgroup ublox6 libupm-ublox6
|
|
||||||
* @ingroup seeed uart gps tsk
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @library ublox6
|
|
||||||
* @sensor ublox6
|
|
||||||
* @comname Grove GPS
|
|
||||||
* @altname U-BLOX 6 SIM28
|
|
||||||
* @type gps
|
|
||||||
* @man seeed
|
|
||||||
* @web http://www.seeedstudio.com/depot/Grove-GPS-p-959.html
|
|
||||||
* @con uart
|
|
||||||
* @kit tsk
|
|
||||||
*
|
|
||||||
* @brief API for the U-BLOX 6 and SIM28 GPS Modules
|
|
||||||
*
|
|
||||||
* UPM support for the U-BLOX 6 GPS module. It is also compatible with
|
|
||||||
* the SIM28 GPS module.
|
|
||||||
*
|
|
||||||
* @image html ublox6.jpg
|
|
||||||
* @snippet ublox6.cxx Interesting
|
|
||||||
*/
|
|
||||||
class Ublox6 {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Ublox6 object constructor
|
|
||||||
*
|
|
||||||
* @param uart Default UART to use (0 or 1)
|
|
||||||
*/
|
|
||||||
Ublox6(int uart);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ublox6 object destructor
|
|
||||||
*/
|
|
||||||
~Ublox6();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if there is data available for reading
|
|
||||||
*
|
|
||||||
* @return True if there is data available for reading
|
|
||||||
*/
|
|
||||||
bool dataAvailable();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads any available data in a user-supplied buffer. Note: the
|
|
||||||
* call blocks until data is available to be read. Use
|
|
||||||
* dataAvailable() to determine whether there is data available
|
|
||||||
* beforehand, to avoid blocking.
|
|
||||||
*
|
|
||||||
* @param buffer Buffer to hold the data read
|
|
||||||
* @param len Length of the buffer
|
|
||||||
* @return the Number of bytes read
|
|
||||||
*/
|
|
||||||
int readData(char *buffer, int len);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the data in the buffer to the device
|
|
||||||
*
|
|
||||||
* @param buffer Buffer to hold the data read
|
|
||||||
* @param len Length of the buffer
|
|
||||||
* @return Number of bytes written
|
|
||||||
*/
|
|
||||||
int writeData(char *buffer, int len);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up proper tty I/O modes and the baud rate. The default
|
|
||||||
* baud rate is 9,600 (B9600).
|
|
||||||
*
|
|
||||||
* @param baud Desired baud rate
|
|
||||||
* @return True if successful
|
|
||||||
*/
|
|
||||||
bool setupTty(speed_t baud=B9600);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int ttyFd() { return m_ttyFd; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
mraa_uart_context m_uart;
|
|
||||||
int m_ttyFd;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user