Atsushi Hattori
/
20210627_Logger
hattori&ide
MBed_Adafruit-GPS-Library/MBed_Adafruit_GPS.h@0:f77369cabd75, 18 months ago (annotated)
- Committer:
- hattori_atsushi
- Date:
- Sun Dec 18 08:16:01 2022 +0000
- Revision:
- 0:f77369cabd75
hattori
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hattori_atsushi | 0:f77369cabd75 | 1 | /*********************************** |
hattori_atsushi | 0:f77369cabd75 | 2 | This is the Adafruit GPS library - the ultimate GPS library |
hattori_atsushi | 0:f77369cabd75 | 3 | for the ultimate GPS module! |
hattori_atsushi | 0:f77369cabd75 | 4 | |
hattori_atsushi | 0:f77369cabd75 | 5 | Tested and works great with the Adafruit Ultimate GPS module |
hattori_atsushi | 0:f77369cabd75 | 6 | using MTK33x9 chipset |
hattori_atsushi | 0:f77369cabd75 | 7 | ------> http://www.adafruit.com/products/746 |
hattori_atsushi | 0:f77369cabd75 | 8 | Pick one up today at the Adafruit electronics shop |
hattori_atsushi | 0:f77369cabd75 | 9 | and help support open source hardware & software! -ada |
hattori_atsushi | 0:f77369cabd75 | 10 | |
hattori_atsushi | 0:f77369cabd75 | 11 | Adafruit invests time and resources providing this open source code, |
hattori_atsushi | 0:f77369cabd75 | 12 | please support Adafruit and open-source hardware by purchasing |
hattori_atsushi | 0:f77369cabd75 | 13 | products from Adafruit! |
hattori_atsushi | 0:f77369cabd75 | 14 | |
hattori_atsushi | 0:f77369cabd75 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. |
hattori_atsushi | 0:f77369cabd75 | 16 | BSD license, check license.txt for more information |
hattori_atsushi | 0:f77369cabd75 | 17 | All text above must be included in any redistribution |
hattori_atsushi | 0:f77369cabd75 | 18 | ****************************************/ |
hattori_atsushi | 0:f77369cabd75 | 19 | #include "mbed.h" |
hattori_atsushi | 0:f77369cabd75 | 20 | #include <stdint.h> |
hattori_atsushi | 0:f77369cabd75 | 21 | #include <math.h> |
hattori_atsushi | 0:f77369cabd75 | 22 | #include <ctype.h> |
hattori_atsushi | 0:f77369cabd75 | 23 | |
hattori_atsushi | 0:f77369cabd75 | 24 | #ifndef _MBED_ADAFRUIT_GPS_H |
hattori_atsushi | 0:f77369cabd75 | 25 | #define _MBED_ADAFRUIT_GPS_H |
hattori_atsushi | 0:f77369cabd75 | 26 | |
hattori_atsushi | 0:f77369cabd75 | 27 | |
hattori_atsushi | 0:f77369cabd75 | 28 | // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz) |
hattori_atsushi | 0:f77369cabd75 | 29 | #define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" |
hattori_atsushi | 0:f77369cabd75 | 30 | #define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" |
hattori_atsushi | 0:f77369cabd75 | 31 | #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F" |
hattori_atsushi | 0:f77369cabd75 | 32 | |
hattori_atsushi | 0:f77369cabd75 | 33 | |
hattori_atsushi | 0:f77369cabd75 | 34 | #define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C" |
hattori_atsushi | 0:f77369cabd75 | 35 | #define PMTK_SET_BAUD_9600 "$PMTK251,9600*17" |
hattori_atsushi | 0:f77369cabd75 | 36 | |
hattori_atsushi | 0:f77369cabd75 | 37 | // turn on only the second sentence (GPRMC) |
hattori_atsushi | 0:f77369cabd75 | 38 | #define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" |
hattori_atsushi | 0:f77369cabd75 | 39 | // turn on GPRMC and GGA |
hattori_atsushi | 0:f77369cabd75 | 40 | #define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" |
hattori_atsushi | 0:f77369cabd75 | 41 | // turn on ALL THE DATA |
hattori_atsushi | 0:f77369cabd75 | 42 | #define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28" |
hattori_atsushi | 0:f77369cabd75 | 43 | // turn off output |
hattori_atsushi | 0:f77369cabd75 | 44 | #define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" |
hattori_atsushi | 0:f77369cabd75 | 45 | |
hattori_atsushi | 0:f77369cabd75 | 46 | // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator |
hattori_atsushi | 0:f77369cabd75 | 47 | // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html |
hattori_atsushi | 0:f77369cabd75 | 48 | |
hattori_atsushi | 0:f77369cabd75 | 49 | #define PMTK_LOCUS_STARTLOG "$PMTK185,0*22" |
hattori_atsushi | 0:f77369cabd75 | 50 | #define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C" |
hattori_atsushi | 0:f77369cabd75 | 51 | #define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38" |
hattori_atsushi | 0:f77369cabd75 | 52 | #define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22" |
hattori_atsushi | 0:f77369cabd75 | 53 | #define LOCUS_OVERLAP 0 |
hattori_atsushi | 0:f77369cabd75 | 54 | #define LOCUS_FULLSTOP 1 |
hattori_atsushi | 0:f77369cabd75 | 55 | |
hattori_atsushi | 0:f77369cabd75 | 56 | // standby command & boot successful message |
hattori_atsushi | 0:f77369cabd75 | 57 | #define PMTK_STANDBY "$PMTK161,0*28" |
hattori_atsushi | 0:f77369cabd75 | 58 | #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36" // Not needed currently |
hattori_atsushi | 0:f77369cabd75 | 59 | #define PMTK_AWAKE "$PMTK010,002*2D" |
hattori_atsushi | 0:f77369cabd75 | 60 | |
hattori_atsushi | 0:f77369cabd75 | 61 | // ask for the release and version |
hattori_atsushi | 0:f77369cabd75 | 62 | #define PMTK_Q_RELEASE "$PMTK605*31" |
hattori_atsushi | 0:f77369cabd75 | 63 | |
hattori_atsushi | 0:f77369cabd75 | 64 | // request for updates on antenna status |
hattori_atsushi | 0:f77369cabd75 | 65 | #define PGCMD_ANTENNA "$PGCMD,33,1*6C" |
hattori_atsushi | 0:f77369cabd75 | 66 | #define PGCMD_NOANTENNA "$PGCMD,33,0*6D" |
hattori_atsushi | 0:f77369cabd75 | 67 | |
hattori_atsushi | 0:f77369cabd75 | 68 | // how long to wait when we're looking for a response |
hattori_atsushi | 0:f77369cabd75 | 69 | #define MAXWAITSENTENCE 5 |
hattori_atsushi | 0:f77369cabd75 | 70 | |
hattori_atsushi | 0:f77369cabd75 | 71 | |
hattori_atsushi | 0:f77369cabd75 | 72 | |
hattori_atsushi | 0:f77369cabd75 | 73 | class Adafruit_GPS { |
hattori_atsushi | 0:f77369cabd75 | 74 | public: |
hattori_atsushi | 0:f77369cabd75 | 75 | void begin(int baud); |
hattori_atsushi | 0:f77369cabd75 | 76 | |
hattori_atsushi | 0:f77369cabd75 | 77 | Adafruit_GPS(Serial * ser); |
hattori_atsushi | 0:f77369cabd75 | 78 | |
hattori_atsushi | 0:f77369cabd75 | 79 | char *lastNMEA(void); |
hattori_atsushi | 0:f77369cabd75 | 80 | bool newNMEAreceived(); |
hattori_atsushi | 0:f77369cabd75 | 81 | void common_init(void); |
hattori_atsushi | 0:f77369cabd75 | 82 | void sendCommand(char *); |
hattori_atsushi | 0:f77369cabd75 | 83 | void pause(bool b); |
hattori_atsushi | 0:f77369cabd75 | 84 | |
hattori_atsushi | 0:f77369cabd75 | 85 | bool parseNMEA(char *response); |
hattori_atsushi | 0:f77369cabd75 | 86 | uint8_t parseHex(char c); |
hattori_atsushi | 0:f77369cabd75 | 87 | |
hattori_atsushi | 0:f77369cabd75 | 88 | char read(void); |
hattori_atsushi | 0:f77369cabd75 | 89 | bool parse(char * nmea); |
hattori_atsushi | 0:f77369cabd75 | 90 | void interruptReads(bool r); |
hattori_atsushi | 0:f77369cabd75 | 91 | |
hattori_atsushi | 0:f77369cabd75 | 92 | bool wakeup(void); |
hattori_atsushi | 0:f77369cabd75 | 93 | bool standby(void); |
hattori_atsushi | 0:f77369cabd75 | 94 | |
hattori_atsushi | 0:f77369cabd75 | 95 | uint8_t hour, minute, seconds, year, month, day; |
hattori_atsushi | 0:f77369cabd75 | 96 | uint16_t milliseconds; |
hattori_atsushi | 0:f77369cabd75 | 97 | float latitude, longitude, geoidheight, altitude; |
hattori_atsushi | 0:f77369cabd75 | 98 | float speed, angle, magvariation, HDOP; |
hattori_atsushi | 0:f77369cabd75 | 99 | char lat, lon, mag; |
hattori_atsushi | 0:f77369cabd75 | 100 | bool fix; |
hattori_atsushi | 0:f77369cabd75 | 101 | uint8_t fixquality, satellites; |
hattori_atsushi | 0:f77369cabd75 | 102 | |
hattori_atsushi | 0:f77369cabd75 | 103 | bool waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE); |
hattori_atsushi | 0:f77369cabd75 | 104 | bool LOCUS_StartLogger(void); |
hattori_atsushi | 0:f77369cabd75 | 105 | bool LOCUS_ReadStatus(void); |
hattori_atsushi | 0:f77369cabd75 | 106 | |
hattori_atsushi | 0:f77369cabd75 | 107 | uint16_t LOCUS_serial, LOCUS_records; |
hattori_atsushi | 0:f77369cabd75 | 108 | uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent; |
hattori_atsushi | 0:f77369cabd75 | 109 | private: |
hattori_atsushi | 0:f77369cabd75 | 110 | bool paused; |
hattori_atsushi | 0:f77369cabd75 | 111 | |
hattori_atsushi | 0:f77369cabd75 | 112 | Serial * gpsSerial; |
hattori_atsushi | 0:f77369cabd75 | 113 | }; |
hattori_atsushi | 0:f77369cabd75 | 114 | |
hattori_atsushi | 0:f77369cabd75 | 115 | #endif |