diff options
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | compile_flags.txt | 5 | ||||
| -rw-r--r-- | config.mk | 5 | ||||
| -rw-r--r-- | makefile | 20 | ||||
| -rw-r--r-- | src/main.cpp | 27 |
5 files changed, 43 insertions, 19 deletions
| @@ -1,2 +1,7 @@ | |||
| 1 | minmea.tgz | ||
| 2 | src/minmea.c | ||
| 3 | src/minmea.h | ||
| 4 | src/.minmea.stamp | ||
| 1 | bin/ | 5 | bin/ |
| 2 | obj/ | 6 | obj/ |
| 7 | |||
diff --git a/compile_flags.txt b/compile_flags.txt index 3ea2c1a..cccab63 100644 --- a/compile_flags.txt +++ b/compile_flags.txt | |||
| @@ -4,7 +4,4 @@ | |||
| 4 | -Wconversion | 4 | -Wconversion |
| 5 | -Wdouble-promotion | 5 | -Wdouble-promotion |
| 6 | -pedantic | 6 | -pedantic |
| 7 | -std=c++17 | 7 | -std=c++23 |
| 8 | -Iinclude | ||
| 9 | -I../minmea/include | ||
| 10 | -I/usr/local/include | ||
| @@ -1,2 +1,3 @@ | |||
| 1 | CPPFLAGS=-Wall -Werror -pedantic -std=c++17 -O2 -Iinclude -I../minmea/include -I/usr/local/include -DNDEBUG | 1 | CPPFLAGS=-Wall -Wno-gnu-anonymous-struct -pedantic -std=c++23 -O2 -DNDEBUG |
| 2 | LDFLAGS=-L../minmea/lib -lminmea -L/usr/local/lib -lpthread | 2 | CFLAGS=-Wall -pedantic -std=c11 -O2 -DNDEBUG |
| 3 | LDFLAGS=-lpthread | ||
| @@ -1,15 +1,27 @@ | |||
| 1 | include config.mk | 1 | include config.mk |
| 2 | 2 | ||
| 3 | bin/app: obj/main.o | bin | 3 | bin/app: obj/main.o obj/minmea.o | bin |
| 4 | c++ $(LDFLAGS) $^ -o $@ | 4 | c++ $(LDFLAGS) $^ -o $@ |
| 5 | 5 | ||
| 6 | obj/%.o: src/%.cpp | obj | 6 | obj/%.o: src/%.cpp src/minmea.h | obj |
| 7 | c++ $(CPPFLAGS) -c $< -o $@ | 7 | c++ $(CPPFLAGS) -c $< -o $@ |
| 8 | 8 | ||
| 9 | obj/%.o: src/%.c src/minmea.h | obj | ||
| 10 | cc $(CFLAGS) -c $< -o $@ | ||
| 11 | |||
| 12 | minmea.tgz: | ||
| 13 | curl -s -o $@ https://codeload.github.com/kosma/minmea/tar.gz/refs/tags/v1.0.0 | ||
| 14 | |||
| 15 | src/.minmea.stamp: minmea.tgz | src | ||
| 16 | tar -xzvf $< --strip-components=1 -C src/ minmea-1.0.0/minmea.h minmea-1.0.0/minmea.c | ||
| 17 | touch $@ | ||
| 18 | |||
| 19 | src/minmea.h src/minmea.c: src/.minmea.stamp | ||
| 20 | |||
| 9 | clean: | 21 | clean: |
| 10 | rm -rf bin obj | 22 | rm -rf bin obj minmea.tgz |
| 11 | 23 | ||
| 12 | bin obj: | 24 | bin obj: |
| 13 | mkdir $@ | 25 | mkdir -p $@ |
| 14 | 26 | ||
| 15 | .PHONY: all clean | 27 | .PHONY: all clean |
diff --git a/src/main.cpp b/src/main.cpp index e699c6a..ed98cb4 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -1,15 +1,22 @@ | |||
| 1 | #include <asio.hpp> | 1 | // Standard C++ |
| 2 | #include <array> | ||
| 2 | #include <ctime> | 3 | #include <ctime> |
| 4 | #include <exception> | ||
| 5 | #include <format> | ||
| 3 | #include <iostream> | 6 | #include <iostream> |
| 4 | #include <string> | 7 | #include <string> |
| 5 | 8 | ||
| 9 | // Asio | ||
| 10 | #include <asio.hpp> | ||
| 11 | |||
| 12 | // minmea | ||
| 6 | #include "minmea.h" | 13 | #include "minmea.h" |
| 7 | 14 | ||
| 8 | using namespace std; | 15 | using namespace std; |
| 9 | 16 | ||
| 10 | // constexpr auto PORT = "/dev/cuaU0"; | 17 | constexpr auto PORT = "/dev/cuaU0"; |
| 11 | constexpr auto PORT = "/dev/ugen0.14"; | 18 | constexpr auto BAUDRATE = 9600; |
| 12 | constexpr auto BAUDRATE = 9600; | 19 | constexpr auto KNOTS_TO_KMH = 1.852F; |
| 13 | 20 | ||
| 14 | namespace { | 21 | namespace { |
| 15 | 22 | ||
| @@ -32,7 +39,7 @@ read_line(asio::serial_port& com) | |||
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | string | 41 | string |
| 35 | get_gps_timestamp(const minmea_time& time, const minmea_date& date) | 42 | get_gps_datetime(const minmea_time& time, const minmea_date& date) |
| 36 | { | 43 | { |
| 37 | tm tm_utc{}; | 44 | tm tm_utc{}; |
| 38 | ::minmea_getdatetime(&tm_utc, &date, &time); | 45 | ::minmea_getdatetime(&tm_utc, &date, &time); |
| @@ -73,11 +80,13 @@ main() | |||
| 73 | continue; | 80 | continue; |
| 74 | } | 81 | } |
| 75 | 82 | ||
| 76 | auto timestamp = get_gps_timestamp(frame.time, frame.date); | 83 | auto timestamp = get_gps_datetime(frame.time, frame.date); |
| 77 | 84 | ||
| 78 | cout << timestamp << ": $RMC floating point degree coordinates and speed: (" | 85 | cout << format("{}: $RMC floating point degree coordinates and speed: ({},{}) {} km/h\n", |
| 79 | << ::minmea_tocoord(&frame.latitude) << "," << ::minmea_tocoord(&frame.longitude) << ") " | 86 | timestamp, |
| 80 | << ::minmea_tofloat(&frame.speed) << '\n'; | 87 | ::minmea_tocoord(&frame.latitude), |
| 88 | ::minmea_tocoord(&frame.longitude), | ||
| 89 | ::minmea_tofloat(&frame.speed) * KNOTS_TO_KMH); | ||
| 81 | } | 90 | } |
| 82 | } | 91 | } |
| 83 | catch ( exception& e ) { | 92 | catch ( exception& e ) { |
