2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Committer:
shimniok
Date:
Thu Jan 03 19:07:20 2019 +0000
Revision:
43:9a285515f33a
Child:
44:0d72a8a1288a
implemented tinygps serial, parsing, and callback

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 43:9a285515f33a 1 #ifndef __GPS_H
shimniok 43:9a285515f33a 2 #define __GPS_H
shimniok 43:9a285515f33a 3
shimniok 43:9a285515f33a 4 /** uBlox GPS UBX Protocol Reader
shimniok 43:9a285515f33a 5 * Parses uBlox GPS binary protocol
shimniok 43:9a285515f33a 6 *
shimniok 43:9a285515f33a 7 * @author Wayne Holder; Ported to mbed by Michael Shimniok
shimniok 43:9a285515f33a 8 */
shimniok 43:9a285515f33a 9 #include "mbed.h"
shimniok 43:9a285515f33a 10
shimniok 43:9a285515f33a 11 class GPS {
shimniok 43:9a285515f33a 12 public:
shimniok 43:9a285515f33a 13 GPS(): _callback(0) {}
shimniok 43:9a285515f33a 14
shimniok 43:9a285515f33a 15 /**
shimniok 43:9a285515f33a 16 * Parse one character of protocol
shimniok 43:9a285515f33a 17 * @param c is the character to parse
shimniok 43:9a285515f33a 18 * @return 1 when entire packet of data obtained, 0 otherwise
shimniok 43:9a285515f33a 19 */
shimniok 43:9a285515f33a 20 virtual int parse(char c) = 0;
shimniok 43:9a285515f33a 21
shimniok 43:9a285515f33a 22 void subscribe(Callback<void()> cb) {
shimniok 43:9a285515f33a 23 _callback = cb;
shimniok 43:9a285515f33a 24 }
shimniok 43:9a285515f33a 25
shimniok 43:9a285515f33a 26 /** Read the latest data from GPS
shimniok 43:9a285515f33a 27 * @param lat latitude in degrees
shimniok 43:9a285515f33a 28 * @param lon longitude in degrees
shimniok 43:9a285515f33a 29 * @param course heading/course in degrees
shimniok 43:9a285515f33a 30 * @param speed speed m/s
shimniok 43:9a285515f33a 31 * @param hdop horizontal dilution of precision
shimniok 43:9a285515f33a 32 * @param svcount is the number of sattelites being tracked
shimniok 43:9a285515f33a 33 * @return all parameters
shimniok 43:9a285515f33a 34 */
shimniok 43:9a285515f33a 35 void read(double& lat, double& lon, float& course, float& speed, float& hdop, int& svcount) {
shimniok 43:9a285515f33a 36 lat = latest.lat;
shimniok 43:9a285515f33a 37 lon = latest.lon;
shimniok 43:9a285515f33a 38 course = latest.course;
shimniok 43:9a285515f33a 39 speed = latest.speed;
shimniok 43:9a285515f33a 40 hdop = latest.hdop;
shimniok 43:9a285515f33a 41 svcount = latest.svcount;
shimniok 43:9a285515f33a 42 }
shimniok 43:9a285515f33a 43
shimniok 43:9a285515f33a 44 protected:
shimniok 43:9a285515f33a 45 typedef struct {
shimniok 43:9a285515f33a 46 double lat;
shimniok 43:9a285515f33a 47 double lon;
shimniok 43:9a285515f33a 48 float course;
shimniok 43:9a285515f33a 49 float speed;
shimniok 43:9a285515f33a 50 float hdop;
shimniok 43:9a285515f33a 51 int svcount;
shimniok 43:9a285515f33a 52 } gps_data_t;
shimniok 43:9a285515f33a 53
shimniok 43:9a285515f33a 54 gps_data_t latest;
shimniok 43:9a285515f33a 55 gps_data_t tmp;
shimniok 43:9a285515f33a 56
shimniok 43:9a285515f33a 57 Callback<void()> _callback;
shimniok 43:9a285515f33a 58 };
shimniok 43:9a285515f33a 59
shimniok 43:9a285515f33a 60 #endif