summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--compile_flags.txt5
-rw-r--r--config.mk5
-rw-r--r--makefile20
-rw-r--r--src/main.cpp27
5 files changed, 43 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index cd42ee3..ca1f238 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
1minmea.tgz
2src/minmea.c
3src/minmea.h
4src/.minmea.stamp
1bin/ 5bin/
2obj/ 6obj/
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
diff --git a/config.mk b/config.mk
index 29f8ca1..aa17664 100644
--- a/config.mk
+++ b/config.mk
@@ -1,2 +1,3 @@
1CPPFLAGS=-Wall -Werror -pedantic -std=c++17 -O2 -Iinclude -I../minmea/include -I/usr/local/include -DNDEBUG 1CPPFLAGS=-Wall -Wno-gnu-anonymous-struct -pedantic -std=c++23 -O2 -DNDEBUG
2LDFLAGS=-L../minmea/lib -lminmea -L/usr/local/lib -lpthread 2CFLAGS=-Wall -pedantic -std=c11 -O2 -DNDEBUG
3LDFLAGS=-lpthread
diff --git a/makefile b/makefile
index 3f481bc..a8742bf 100644
--- a/makefile
+++ b/makefile
@@ -1,15 +1,27 @@
1include config.mk 1include config.mk
2 2
3bin/app: obj/main.o | bin 3bin/app: obj/main.o obj/minmea.o | bin
4 c++ $(LDFLAGS) $^ -o $@ 4 c++ $(LDFLAGS) $^ -o $@
5 5
6obj/%.o: src/%.cpp | obj 6obj/%.o: src/%.cpp src/minmea.h | obj
7 c++ $(CPPFLAGS) -c $< -o $@ 7 c++ $(CPPFLAGS) -c $< -o $@
8 8
9obj/%.o: src/%.c src/minmea.h | obj
10 cc $(CFLAGS) -c $< -o $@
11
12minmea.tgz:
13 curl -s -o $@ https://codeload.github.com/kosma/minmea/tar.gz/refs/tags/v1.0.0
14
15src/.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
19src/minmea.h src/minmea.c: src/.minmea.stamp
20
9clean: 21clean:
10 rm -rf bin obj 22 rm -rf bin obj minmea.tgz
11 23
12bin obj: 24bin 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
8using namespace std; 15using namespace std;
9 16
10// constexpr auto PORT = "/dev/cuaU0"; 17constexpr auto PORT = "/dev/cuaU0";
11constexpr auto PORT = "/dev/ugen0.14"; 18constexpr auto BAUDRATE = 9600;
12constexpr auto BAUDRATE = 9600; 19constexpr auto KNOTS_TO_KMH = 1.852F;
13 20
14namespace { 21namespace {
15 22
@@ -32,7 +39,7 @@ read_line(asio::serial_port& com)
32} 39}
33 40
34string 41string
35get_gps_timestamp(const minmea_time& time, const minmea_date& date) 42get_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 ) {