mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
vk2828u7: Initial implementation
This module provides support for the VK2828U7 (ublox based) GPS module from DFRobot. It is connected via a UART, and emits NMEA data. Ideally this data could be fed to an external library like TinyGPS to parse the NMEA data and provide an easier method of extracting GPS information. Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
8e9e0976bb
commit
64e81def0f
@ -274,6 +274,7 @@ add_example (l3gd20)
|
||||
add_example (l3gd20-i2c)
|
||||
add_example (bmx055)
|
||||
add_example (ms5611)
|
||||
add_example (vk2828u7)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
|
69
examples/c++/vk2828u7.cxx
Normal file
69
examples/c++/vk2828u7.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 "vk2828u7.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
const size_t bufferLength = 256;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a VK2828U7 sensor on uart 0 at 9600 baud with enable
|
||||
// pin on D3
|
||||
upm::VK2828U7 *sensor = new upm::VK2828U7(0, 9600, 3);
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun && sensor->dataAvailable(5000))
|
||||
{
|
||||
cout << sensor->readStr(bufferLength);
|
||||
}
|
||||
|
||||
if (shouldRun)
|
||||
cerr << "Timed out" << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -87,3 +87,4 @@ link_directories (${MRAA_LIBDIR})
|
||||
# mq? will use module gas
|
||||
# grove* will use module grove
|
||||
add_example (dfrph)
|
||||
add_example (vk2828u7)
|
||||
|
80
examples/c/vk2828u7.c
Normal file
80
examples/c/vk2828u7.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 <signal.h>
|
||||
|
||||
#include "vk2828u7.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
const size_t bufferLength = 256;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a VK2828U7 sensor on uart 0 at 9600 baud with enable
|
||||
// pin on D3
|
||||
vk2828u7_context sensor = vk2828u7_init(0, 9600, 3);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("vk2828u7_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[bufferLength];
|
||||
int rv = 0;
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun && vk2828u7_data_available(sensor, 5000))
|
||||
{
|
||||
if ((rv = vk2828u7_read(sensor, buffer, bufferLength)) >= 0)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<rv; i++)
|
||||
printf("%c", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRun)
|
||||
printf("Timed out\n");
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
vk2828u7_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
@ -131,6 +131,7 @@ add_example(VCAP_Example vcap)
|
||||
add_example(BMP280_Example bmp280)
|
||||
add_example(BNO055_Example bno055)
|
||||
add_example(BMX055_Example bmx055)
|
||||
add_example(VK2828U7_Example vk2828u7)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
|
48
examples/java/VK2828U7_Example.java
Normal file
48
examples/java/VK2828U7_Example.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 upm_vk2828u7.VK2828U7;
|
||||
|
||||
public class VK2828U7_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
System.out.println("Initializing...");
|
||||
|
||||
// Instantiate a VK2828U7 sensor on uart 0 at 9600 baud with
|
||||
// enable pin on D3
|
||||
VK2828U7 sensor = new VK2828U7(0, 9600, 3);
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (sensor.dataAvailable(5000))
|
||||
{
|
||||
System.out.print(sensor.readStr(256));
|
||||
}
|
||||
System.out.println("Timed out");
|
||||
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
50
examples/javascript/vk2828u7.js
Normal file
50
examples/javascript/vk2828u7.js
Normal file
@ -0,0 +1,50 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 sensorObj = require('jsupm_vk2828u7');
|
||||
|
||||
// Instantiate a VK2828U7 sensor on uart 0 at 9600 baud with enable
|
||||
// pin on D3
|
||||
var sensor = new sensorObj.VK2828U7(0, 9600, 3);
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (sensor.dataAvailable(5000))
|
||||
{
|
||||
process.stdout.write(sensor.readStr(256));
|
||||
}
|
||||
console.log("Timed out");
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
||||
|
51
examples/python/vk2828u7.py
Normal file
51
examples/python/vk2828u7.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 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_vk2828u7 as sensorObj
|
||||
|
||||
# Instantiate a VK2828U7 sensor on uart 0 at 9600 baud with enable
|
||||
# pin on D3
|
||||
sensor = sensorObj.VK2828U7(0, 9600, 3)
|
||||
|
||||
## 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
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# Every second, sample the VK2828U7 and output the measured lux value
|
||||
|
||||
# loop, dumping NMEA data out as fast as it comes in
|
||||
while (sensor.dataAvailable(5000)):
|
||||
sys.stdout.write(sensor.readStr(256))
|
||||
|
||||
print "Timed out"
|
9
src/vk2828u7/CMakeLists.txt
Normal file
9
src/vk2828u7/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
upm_mixed_module_init (NAME vk2828u7
|
||||
DESCRIPTION "upm dfrobot VK2828u7/NMEA serial GPS sensor"
|
||||
C_HDR vk2828u7.h
|
||||
C_SRC vk2828u7.c
|
||||
CPP_HDR vk2828u7.hpp
|
||||
CPP_SRC vk2828u7.cxx
|
||||
FTI_SRC vk2828u7_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa)
|
20
src/vk2828u7/javaupm_vk2828u7.i
Normal file
20
src/vk2828u7/javaupm_vk2828u7.i
Normal file
@ -0,0 +1,20 @@
|
||||
%module javaupm_vk2828u7
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
%include "vk2828u7.hpp"
|
||||
%{
|
||||
#include "vk2828u7.hpp"
|
||||
%}
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_vk2828u7");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
9
src/vk2828u7/jsupm_vk2828u7.i
Normal file
9
src/vk2828u7/jsupm_vk2828u7.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_vk2828u7
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%include "vk2828u7.hpp"
|
||||
%{
|
||||
#include "vk2828u7.hpp"
|
||||
%}
|
||||
|
13
src/vk2828u7/pyupm_vk2828u7.i
Normal file
13
src/vk2828u7/pyupm_vk2828u7.i
Normal file
@ -0,0 +1,13 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_vk2828u7
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "vk2828u7.hpp"
|
||||
%{
|
||||
#include "vk2828u7.hpp"
|
||||
%}
|
||||
|
151
src/vk2828u7/vk2828u7.c
Normal file
151
src/vk2828u7/vk2828u7.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "vk2828u7.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
|
||||
vk2828u7_context vk2828u7_init(unsigned int uart, unsigned int baudrate,
|
||||
int enable_pin)
|
||||
{
|
||||
vk2828u7_context dev =
|
||||
(vk2828u7_context)malloc(sizeof(struct _vk2828u7_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
// zero out context
|
||||
memset((void *)dev, 0, sizeof(struct _vk2828u7_context));
|
||||
|
||||
dev->uart = NULL;
|
||||
dev->gpio_en = NULL;
|
||||
|
||||
// initialize the MRAA contexts
|
||||
|
||||
// uart, default should be 8N1
|
||||
if (!(dev->uart = mraa_uart_init(uart)))
|
||||
{
|
||||
printf("%s: mraa_uart_init() failed.\n", __FUNCTION__);
|
||||
vk2828u7_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vk2828u7_set_baudrate(dev, baudrate))
|
||||
{
|
||||
printf("%s: vk2828u7_set_baudrate() failed.\n", __FUNCTION__);
|
||||
vk2828u7_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mraa_uart_set_flowcontrol(dev->uart, false, false);
|
||||
|
||||
// now the gpio_en, if enabled
|
||||
if (enable_pin >= 0)
|
||||
{
|
||||
if (!(dev->gpio_en = mraa_gpio_init(enable_pin)))
|
||||
{
|
||||
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
|
||||
vk2828u7_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mraa_gpio_dir(dev->gpio_en, MRAA_GPIO_OUT);
|
||||
|
||||
// wake up
|
||||
vk2828u7_enable(dev, true);
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void vk2828u7_close(vk2828u7_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// sleepy-time
|
||||
vk2828u7_enable(dev, false);
|
||||
|
||||
if (dev->uart)
|
||||
mraa_uart_stop(dev->uart);
|
||||
if (dev->gpio_en)
|
||||
mraa_gpio_close(dev->gpio_en);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t vk2828u7_enable(const vk2828u7_context dev, bool enable)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (!dev->gpio_en)
|
||||
return UPM_ERROR_NO_RESOURCES;
|
||||
|
||||
if (enable)
|
||||
mraa_gpio_write(dev->gpio_en, 1);
|
||||
else
|
||||
mraa_gpio_write(dev->gpio_en, 0);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
int vk2828u7_read(const vk2828u7_context dev, char *buffer, size_t len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return mraa_uart_read(dev->uart, buffer, len);
|
||||
}
|
||||
|
||||
int vk2828u7_write(const vk2828u7_context dev, char *buffer, size_t len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return mraa_uart_write(dev->uart, buffer, len);
|
||||
}
|
||||
|
||||
bool vk2828u7_data_available(const vk2828u7_context dev, unsigned int millis)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (mraa_uart_data_available(dev->uart, millis))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
upm_result_t vk2828u7_set_baudrate(const vk2828u7_context dev,
|
||||
unsigned int baudrate)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (mraa_uart_set_baudrate(dev->uart, baudrate))
|
||||
{
|
||||
printf("%s: mraa_uart_set_baudrate() failed.\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
89
src/vk2828u7/vk2828u7.cxx
Normal file
89
src/vk2828u7/vk2828u7.cxx
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 <stdexcept>
|
||||
|
||||
#include "vk2828u7.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
VK2828U7::VK2828U7(unsigned int uart, unsigned int baudrate,
|
||||
int enable_pin) :
|
||||
m_vk2828u7(vk2828u7_init(uart, baudrate, enable_pin))
|
||||
{
|
||||
if (!m_vk2828u7)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": vk2828u7_init() failed");
|
||||
}
|
||||
|
||||
VK2828U7::~VK2828U7()
|
||||
{
|
||||
vk2828u7_close(m_vk2828u7);
|
||||
}
|
||||
|
||||
std::string VK2828U7::readStr(unsigned int size)
|
||||
{
|
||||
char buffer[size];
|
||||
|
||||
int rv;
|
||||
|
||||
if ((rv = vk2828u7_read(m_vk2828u7, buffer, size)) < 0)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": vk2828u7_read() failed");
|
||||
|
||||
return string(buffer, rv);
|
||||
}
|
||||
|
||||
int VK2828U7::writeStr(std::string buffer)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if ((rv = vk2828u7_write(m_vk2828u7, (char*)buffer.data(),
|
||||
buffer.size())) < 0)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": vk2828u7_write() failed");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void VK2828U7::enable(bool enable)
|
||||
{
|
||||
if (vk2828u7_enable(m_vk2828u7, enable))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": vk2828u7_enable() failed");
|
||||
}
|
||||
|
||||
void VK2828U7::setBaudrate(unsigned int baudrate)
|
||||
{
|
||||
if (vk2828u7_set_baudrate(m_vk2828u7, baudrate))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": vk2828u7_baudrate() failed");
|
||||
}
|
||||
|
||||
bool VK2828U7::dataAvailable(unsigned int millis)
|
||||
{
|
||||
return vk2828u7_data_available(m_vk2828u7, millis);
|
||||
}
|
126
src/vk2828u7/vk2828u7.h
Normal file
126
src/vk2828u7/vk2828u7.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 <stdint.h>
|
||||
#include "upm.h"
|
||||
#include "mraa/uart.h"
|
||||
#include "mraa/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief UPM C API for the DFRobot VK2828U7 GPS Module
|
||||
*
|
||||
* The driver was tested with the DFRobot VK2828U7 GPS Module. It
|
||||
* is accessed via a UART and provides NMEA data.
|
||||
*
|
||||
* @snippet vk2828u7.c Interesting
|
||||
*/
|
||||
|
||||
/**
|
||||
* Device context
|
||||
*/
|
||||
typedef struct _vk2828u7_context {
|
||||
mraa_uart_context uart;
|
||||
mraa_gpio_context gpio_en;
|
||||
} *vk2828u7_context;
|
||||
|
||||
/**
|
||||
* VK2828U7 Initializer
|
||||
*
|
||||
* @param uart Specify which uart to use.
|
||||
* @param baudrate Specify the baudrate to use. The device defaults
|
||||
* to 9600 baud.
|
||||
* @param enable_pin Specify the GPIO pin to use for the enable pin,
|
||||
* -1 to not use an enable pin.
|
||||
* @return an initialized device context on success, NULL on error.
|
||||
*/
|
||||
vk2828u7_context vk2828u7_init(unsigned int uart, unsigned int baudrate,
|
||||
int enable_pin);
|
||||
|
||||
/**
|
||||
* VK2828U7 sensor close function
|
||||
*/
|
||||
void vk2828u7_close(vk2828u7_context dev);
|
||||
|
||||
/**
|
||||
* Read character data from the device.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param buffer The character buffer to read data into.
|
||||
* @param len The maximum size of the buffer
|
||||
* @return The number of bytes successfully read, or -1 on error
|
||||
*/
|
||||
int vk2828u7_read(const vk2828u7_context dev, char *buffer, size_t len);
|
||||
|
||||
/**
|
||||
* Write character data to the device.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param buffer The character buffer containing data to write.
|
||||
* @param len The number of bytes to write.
|
||||
* @return The number of bytes successfully written, or -1 on error.
|
||||
*/
|
||||
int vk2828u7_write(const vk2828u7_context dev, char *buffer, size_t len);
|
||||
|
||||
/**
|
||||
* Enable or disable the device. When disabled, the device enters a
|
||||
* low power mode and does not emit NMEA data. It will still
|
||||
* maintain location data however.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param enable true to enable the device, false otherwise.
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t vk2828u7_enable(const vk2828u7_context dev, bool enable);
|
||||
|
||||
/**
|
||||
* Set the baudrate of the device. By default, vk2828u7_init() will
|
||||
* set the baudrate to 9600.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param baudrate The baud rate to set for the device.
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t vk2828u7_set_baudrate(const vk2828u7_context dev,
|
||||
unsigned int baudrate);
|
||||
|
||||
/**
|
||||
* Determine whether there is data available to be read.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param millis The number of milliseconds to wait for data to
|
||||
* become available.
|
||||
* @return true if data is available to be read, false otherwise.
|
||||
*/
|
||||
bool vk2828u7_data_available(const vk2828u7_context dev,
|
||||
unsigned int millis);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
131
src/vk2828u7/vk2828u7.hpp
Normal file
131
src/vk2828u7/vk2828u7.hpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "vk2828u7.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief UPM C++ API for the DFRobot VK2828U7 Analog Accelerometer
|
||||
* @defgroup vk2828u7 libupm-vk2828u7
|
||||
* @ingroup dfrobot uart gpio gps
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library vk2828u7
|
||||
* @sensor vk2828u7
|
||||
* @comname DFRobot VK2828U7 GPS Module
|
||||
* @type gps
|
||||
* @man dfrobot
|
||||
* @con uart gpio
|
||||
* @web http://www.dfrobot.com/index.php?route=product/product&search=gps&description=true&product_id=1302#.V7tMfN9ytNK
|
||||
*
|
||||
* @brief API for the DFRobot VK2828U7 GPS Module
|
||||
*
|
||||
* The driver was tested with the DFRobot VK2828U7 GPS module. The
|
||||
* website claims the device can be run at 5v, however the datasheet
|
||||
* says the logic inputs and outputs can only handle 3.3v, and there
|
||||
* does not appear to be a schematic available. So this module was
|
||||
* tested only at 3.3v.
|
||||
*
|
||||
* @snippet vk2828u7.cxx Interesting
|
||||
*/
|
||||
|
||||
class VK2828U7 {
|
||||
public:
|
||||
|
||||
/**
|
||||
* VK2828U7 object constructor
|
||||
*
|
||||
* @param uart Specify which uart to use.
|
||||
* @param baudrate Specify the baudrate to use. The device defaults
|
||||
* to 9600 baud.
|
||||
* @param enable_pin Specify the GPIO pin to use for the enable pin,
|
||||
* -1 to not use an enable pin.
|
||||
*/
|
||||
VK2828U7(unsigned int uart, unsigned int baudrate,
|
||||
int enable_pin);
|
||||
|
||||
/**
|
||||
* VK2828U7 object destructor
|
||||
*/
|
||||
~VK2828U7();
|
||||
|
||||
/**
|
||||
* Read character data from the device.
|
||||
*
|
||||
* @param size The maximum number of characters to read.
|
||||
* @return string containing the data read.
|
||||
*/
|
||||
std::string readStr(size_t size);
|
||||
|
||||
/**
|
||||
* Write character data to the device.
|
||||
*
|
||||
* @param buffer The string containing the data to write.
|
||||
* @return The number of bytes written.
|
||||
*/
|
||||
int writeStr(std::string buffer);
|
||||
|
||||
/**
|
||||
* Enable or disable the device. When disabled, the device enters a
|
||||
* low power mode and does not emit NMEA data. It will still
|
||||
* maintain location data however.
|
||||
*
|
||||
* @param enable true to enable the device, false otherwise.
|
||||
*/
|
||||
void enable(bool enable);
|
||||
|
||||
/**
|
||||
* Set the baudrate of the device. By default, the constructor
|
||||
* will set the baudrate to 9600.
|
||||
*
|
||||
* @param baudrate The baud rate to set for the device.
|
||||
*/
|
||||
void setBaudrate(unsigned int baudrate);
|
||||
|
||||
/**
|
||||
* Determine whether there is data available to be read.
|
||||
*
|
||||
* @param millis The number of milliseconds to wait for data to
|
||||
* become available.
|
||||
* @return true if data is available to be read, false otherwise.
|
||||
*/
|
||||
bool dataAvailable(unsigned int millis);
|
||||
|
||||
protected:
|
||||
// vk2828u7 device context
|
||||
vk2828u7_context m_vk2828u7;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
96
src/vk2828u7/vk2828u7_fti.c
Normal file
96
src/vk2828u7/vk2828u7_fti.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 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 "vk2828u7.h"
|
||||
#include "upm_fti.h"
|
||||
|
||||
/**
|
||||
* This file implements the Function Table Interface (FTI) for this sensor
|
||||
*/
|
||||
|
||||
const char upm_vk2828u7_name[] = "VK2828U7";
|
||||
const char upm_vk2828u7_description[] = "Serial GPS (providing NMEA data)";
|
||||
const upm_protocol_t upm_vk2828u7_protocol[] = {UPM_UART, UPM_GPIO};
|
||||
const upm_sensor_t upm_vk2828u7_category[] = {UPM_STREAM};
|
||||
|
||||
// forward declarations
|
||||
const void* upm_vk2828u7_get_ft(upm_sensor_t sensor_type);
|
||||
void* upm_vk2828u7_init_name();
|
||||
void upm_vk2828u7_close(void *dev);
|
||||
int upm_vk2828u7_read(void *dev, char *buffer, int len);
|
||||
int upm_vk2828u7_write(void *dev, char *buffer, int len);
|
||||
bool upm_vk2828u7_data_available(void *dev, unsigned int timeout);
|
||||
|
||||
static const upm_sensor_ft ft =
|
||||
{
|
||||
.upm_sensor_init_name = &upm_vk2828u7_init_name,
|
||||
.upm_sensor_close = &upm_vk2828u7_close,
|
||||
};
|
||||
|
||||
static const upm_stream_ft sft =
|
||||
{
|
||||
.upm_stream_read = upm_vk2828u7_read,
|
||||
.upm_stream_write = upm_vk2828u7_write,
|
||||
.upm_stream_data_available = upm_vk2828u7_data_available
|
||||
};
|
||||
|
||||
const void* upm_vk2828u7_get_ft(upm_sensor_t sensor_type)
|
||||
{
|
||||
switch(sensor_type)
|
||||
{
|
||||
case UPM_SENSOR:
|
||||
return &ft;
|
||||
|
||||
case UPM_STREAM:
|
||||
return &sft;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void* upm_vk2828u7_init_name()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void upm_vk2828u7_close(void *dev)
|
||||
{
|
||||
vk2828u7_close((vk2828u7_context)dev);
|
||||
}
|
||||
|
||||
int upm_vk2828u7_read(void *dev, char *buffer, int len)
|
||||
{
|
||||
return vk2828u7_read((vk2828u7_context)dev, buffer, len);
|
||||
}
|
||||
|
||||
int upm_vk2828u7_write(void *dev, char *buffer, int len)
|
||||
{
|
||||
return vk2828u7_write((vk2828u7_context)dev, buffer, len);
|
||||
}
|
||||
|
||||
bool upm_vk2828u7_data_available(void *dev, unsigned int timeout)
|
||||
{
|
||||
return vk2828u7_data_available((vk2828u7_context)dev, timeout);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user