1 /* 2 * Author: Jon Trulson <jtrulson@ics.com> 3 * Copyright (c) 2014 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 #pragma once 25 26 #include <string> 27 #include <iostream> 28 29 #include <stdint.h> 30 #include <stdlib.h> 31 #include <unistd.h> 32 #include <string.h> 33 #include <fcntl.h> 34 #include <errno.h> 35 #include <termios.h> 36 #include <sys/time.h> 37 #include <sys/select.h> 38 #include <sys/types.h> 39 #include <sys/stat.h> 40 41 #include <mraa/uart.h> 42 43 const int UBLOX6_DEFAULT_UART = 0; 44 45 namespace upm { 46 /** 47 * @brief UBLOX6 & SIM28 GPS Module library 48 * @defgroup ublox6 libupm-ublox6 49 * @ingroup seeed uart gps tsk 50 */ 51 /** 52 * @library ublox6 53 * @sensor ublox6 54 * @comname Grove GPS 55 * @altname U-BLOX 6 SIM28 56 * @type gps 57 * @man seeed 58 * @web http://www.seeedstudio.com/depot/Grove-GPS-p-959.html 59 * @con uart 60 * @kit tsk 61 * 62 * @brief API for the U-BLOX 6 and SIM28 GPS Modules 63 * 64 * UPM support for the U-BLOX 6 GPS module. It is also compatible with 65 * the SIM28 GPS module. 66 * 67 * @image html ublox6.jpg 68 * @snippet ublox6.cxx Interesting 69 */ 70 class Ublox6 { 71 public: 72 /** 73 * Ublox6 object constructor 74 * 75 * @param uart Default UART to use (0 or 1) 76 */ 77 Ublox6(int uart); 78 79 /** 80 * Ublox6 object destructor 81 */ 82 ~Ublox6(); 83 84 /** 85 * Checks to see if there is data available for reading 86 * 87 * @return True if there is data available for reading 88 */ 89 bool dataAvailable(); 90 91 /** 92 * Reads any available data in a user-supplied buffer. Note: the 93 * call blocks until data is available to be read. Use 94 * dataAvailable() to determine whether there is data available 95 * beforehand, to avoid blocking. 96 * 97 * @param buffer Buffer to hold the data read 98 * @param len Length of the buffer 99 * @return the Number of bytes read 100 */ 101 int readData(char *buffer, int len); 102 103 /** 104 * Writes the data in the buffer to the device 105 * 106 * @param buffer Buffer to hold the data read 107 * @param len Length of the buffer 108 * @return Number of bytes written 109 */ 110 int writeData(char *buffer, int len); 111 112 /** 113 * Sets up proper tty I/O modes and the baud rate. The default 114 * baud rate is 9,600 (B9600). 115 * 116 * @param baud Desired baud rate 117 * @return True if successful 118 */ 119 bool setupTty(speed_t baud=B9600); 120 121 protected: ttyFd()122 int ttyFd() { return m_ttyFd; }; 123 124 private: 125 mraa_uart_context m_uart; 126 int m_ttyFd; 127 }; 128 } 129 130 131