Pico GPS Teseo I2C
Loading...
Searching...
No Matches
teseo_reply_response.cpp
Go to the documentation of this file.
1// https://www.st.com/resource/en/application_note/an5203-teseoliv3f--i2c-positioning-sensor--stmicroelectronics.pdf
2
3#include <string>
4// for std::find
5#include <algorithm>
6// for debug messages
7#include <stdio.h>
8#include "pico/stdlib.h"
9
10import teseo;
11import port_pico_reset;
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;
22
24 gps.writer().set([](const std::string& s) -> void { write(s); });
25 gps.reader().set([](std::string& s) -> void { read(s); });
26 gps.resetter().set([]() -> void { port_pico::reset(); });
27}
28
29int main() {
30 initialize();
32
33 /*
34 when the teseo is preset for i2c according to AN5203,
35 init is not required, and you can cut 4s 10ms from the startup sequence
36 https://www.st.com/resource/en/application_note/an5203-teseoliv3f--i2c-positioning-sensor--stmicroelectronics.pdf
37 */
38 gps.initialize();
39
40 uint count; // intentionally uninitialised
41 bool valid; // intentionally uninitialised
42
43 while (true) {
44 printf("+-- start --+\r\n");
45
46 valid = gps.ask_gll(reply);
47 printf("GLL valid: %s.\r\n", valid ? "yes" : "no");
48 printf(reply.c_str());
49
50 valid = gps.ask_gsv(replies, count);
51 printf("GSV valid: %s. count: %u.\r\n", valid ? "yes" : "no", count);
52 std::for_each(replies.begin(), replies.begin() + count, [](auto &s) {
53 printf(s.c_str()); });
54
55 valid = gps.ask_gsa(replies, count);
56 printf("GSA valid: %s. count: %u.\r\n", valid ? "yes" : "no", count);
57 std::for_each(replies.begin(), replies.begin() + count, [](auto &s) {
58 printf(s.c_str()); });
59
60 valid = gps.ask_gga(reply);
61 printf("GGA valid: %s.\r\n", valid ? "yes" : "no");
62 printf(reply.c_str());
63
64 valid = gps.ask_vtg(reply);
65 printf("VTG valid: %s.\r\n", valid ? "yes" : "no");
66 printf(reply.c_str());
67
68 valid = gps.ask_rmc(reply);
69 printf("RMC valid: %s.\r\n", valid ? "yes" : "no");
70 printf(reply.c_str());
71
72 /* commented out because this is a slow command. It's here to show
73 how to call a custom multi line command.
74 Uncomment if you want to test this.
75 */
76 // // example: execute a custom command that returns multiple lines
77 // printf("DUMPALMANAC command will take a while to reply.\r\n");
78 // teseo::nmea_rr almanac("$PSTMDUMPALMANAC\n\r", "$PSTMDUMPALMANAC");
79 // valid = gps.ask_nmea_multiple(almanac, replies, count);
80 // printf("DUMPALMANAC valid: %s. count: %u.\r\n", valid ? "yes" : "no", count);
81 // std::for_each(replies.begin(), replies.begin() + count, [](auto &s) {
82 // printf(s.c_str()); });
83
84 printf("+-- end --+\r\n\r\n");
85 sleep_ms(1000);
86 }
87}
Driver class for ST Teseo IC.
void initialize()
void read(::std::string &s)
void write(const ::std::string &s)
void reset()
Definition reset.cpp:17
std::array< std::string, NMEA_MAX_REPLIES > replies
void setCallbacks()
int main()