Pico GPS Teseo I2C
Loading...
Searching...
No Matches
teseo_with_nmea_parse.cpp
Go to the documentation of this file.
1#include <string>
2#include <chrono>
3
4// for debug messages
5#include <stdio.h>
6#include "pico/stdlib.h"
7
8import teseo;
9import nmea;
10import port_pico_reset;
12
13
15std::string reply;
16// for the container that will hold multy-line replies,
17// you can use an array, vector, C array
18// based on what your architecture prefers or requires.
19// vector size is a suggestion. STL will allocate at least NMEA_MAX_REPLIES
20//std::vector<std::string> replies(NMEA_MAX_REPLIES);
21std::array<std::string, NMEA_MAX_REPLIES> replies;
22uint count; // intentionally uninitialised
23bool valid; // intentionally uninitialised
24
25void print_t(const nmea::time_t& t) {
26 printf("%02i:%02i:%02i.%03i",
27 (int)(t.hours().count()), (int)(t.minutes().count()),
28 (int)(t.seconds().count()), (int)(t.subseconds().count()));
29}
30
31void print_d(const std::chrono::year_month_day& t) {
32 printf("%4i-%02i-%02i",
33 t.year(), t.month(),
34 t.day());
35}
36
37void print_talker(const nmea::talker_id& talker_id) {
38 switch (talker_id) {
40 printf("gps");
41 break;
43 printf("glonass");
44 break;
46 printf("galileo");
47 break;
48 default:
49 printf("other");
50 break;
51 }
52}
53
54void test_gll() {
55 valid = gps.ask_gll(reply);
56 if (!valid) { return; }
57 assert(reply.size());
58 nmea::gll o;
60 printf("GLL source: ");
62 printf(". lat: %f lon: %f, time: ",
63 o.lat, o.lon);
64 print_t(o.t);
65 printf(".\n");
66 return;
67}
68
69void test_gsv() {
70 valid = gps.ask_gsv(replies, count);
71 if (!valid) { return; }
72 for(auto r : std::ranges::subrange(replies.begin(), replies.begin() + count)) {
73 nmea::gsv o;
75 printf("GSV source: ");
77 printf(".\r\n");
78 for(const auto s : o.sats) {
79 printf("sat prn: %i, elev: %i, azim: %i, snr: %i.\r\n",
80 s.prn, s.elev, s.azim, s.snr);
81 }
82 }
83 return;
84}
85
86void test_gga() {
87 valid = gps.ask_gga(reply);
88 if (!valid) { return; }
89 nmea::gga o;
91 printf("GGA source: ");
93 printf(". lat: %f lon: %f, alt: %.3f, geosep: %.3f, sats: %i. ",
94 o.lat, o.lon, o.alt, o.geosep, o.sats);
95 print_t(o.t);
96 printf(".\n");
97 return;
98}
99
100void test_rmc() {
101 valid = gps.ask_rmc(reply);
102 if (!valid) { return; }
103 nmea::rmc o;
105 printf("RMC source: ");
107 printf(". lat: %f lon: %f. ",
108 o.lat, o.lon);
109 print_t(o.t);
110 printf(". ");
111 print_d(o.d);
112 printf(".\n");
113 return;
114}
115
117 gps.writer().set([](const std::string& s) -> void { write(s); });
118 gps.reader().set([](std::string& s) -> void { read(s); });
119 gps.resetter().set([]() -> void { port_pico::reset(); });
120}
121
122int main() {
123 initialize();
124 setCallbacks();
125
126 /*
127 when the teseo is preset for i2c according to AN5203,
128 init is not required, and you can cut 4s 10ms from the startup sequence
129 https://www.st.com/resource/en/application_note/an5203-teseoliv3f--i2c-positioning-sensor--stmicroelectronics.pdf
130 */
131 gps.initialize();
132
133 while (true) {
134 printf("+-- start --+\r\n");
135 test_gll();
136 test_gsv();
137 test_gga();
138 test_rmc();
139 printf("+-- end --+\r\n\r\n");
140 sleep_ms(1000);
141 }
142}
float geosep
static bool from_data(const std::string &data, gga &gga)
Definition nmea.cpp:160
talker_id source
unsigned int sats
talker_id source
static bool from_data(const std::string &data, gll &gll)
Definition nmea.cpp:121
static bool from_data(const std::string &data, gsv &gsv)
Definition nmea.cpp:253
talker_id source
gsv_sat_array sats
std::chrono::year_month_day d
talker_id source
static bool from_data(const std::string &data, rmc &rmc)
Definition nmea.cpp:314
Driver class for ST Teseo IC.
void initialize()
void read(::std::string &s)
void write(const ::std::string &s)
std::chrono::hh_mm_ss< std::chrono::duration< long long, std::ratio< 1, 1000 > > > time_t
void reset()
Definition reset.cpp:17
std::array< std::string, NMEA_MAX_REPLIES > replies
void print_d(const std::chrono::year_month_day &t)
void test_gsv()
void test_gga()
void setCallbacks()
void print_t(const nmea::time_t &t)
void print_talker(const nmea::talker_id &talker_id)
void test_gll()
void test_rmc()