summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2026-08-13 22:16:05 +0200
committerThomas Schmucker <ts@its1.de>2026-08-13 22:16:05 +0200
commit46c9893607ecd32f8d9e2e6b7c3afa38bfc7e324 (patch)
tree21b80c763a65e81a883b96761f5277cdb21f1905
downloaduse-minmea-46c9893607ecd32f8d9e2e6b7c3afa38bfc7e324.tar.gz
use-minmea-46c9893607ecd32f8d9e2e6b7c3afa38bfc7e324.tar.bz2
use-minmea-46c9893607ecd32f8d9e2e6b7c3afa38bfc7e324.zip
erster import
-rw-r--r--.clang-format45
-rw-r--r--.clang-tidy19
-rw-r--r--.gitignore2
-rw-r--r--compile_flags.txt10
-rw-r--r--config.mk2
-rw-r--r--makefile15
-rw-r--r--src/main.cpp86
7 files changed, 179 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ff96bb5
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,45 @@
1---
2AccessModifierOffset: -4
3AlignConsecutiveAssignments: 'true'
4AlignConsecutiveDeclarations: 'true'
5AlignEscapedNewlines: Left
6AlignTrailingComments: 'true'
7AlwaysBreakAfterReturnType: TopLevelDefinitions
8BreakBeforeBraces: Stroustrup
9BreakConstructorInitializers: BeforeComma
10BreakInheritanceList: BeforeComma
11ColumnLimit: '0'
12CompactNamespaces: 'false'
13Cpp11BracedListStyle: 'false'
14FixNamespaceComments: 'true'
15IncludeBlocks: Regroup
16IncludeCategories:
17 - Regex: '^.*(precomp|pch|stdafx)'
18 Priority: -1
19 - Regex: '^<.*>'
20 Priority: 1
21 - Regex: '^".*"'
22 Priority: 2
23 - Regex: '.*'
24 Priority: 3
25IndentCaseLabels: 'false'
26IndentPPDirectives: AfterHash
27IndentWidth: '4'
28IndentWrappedFunctionNames: 'false'
29KeepEmptyLinesAtTheStartOfBlocks: 'false'
30PointerAlignment: Left
31SortIncludes: 'true'
32SpaceAfterCStyleCast: 'true'
33SpaceAfterTemplateKeyword: 'false'
34SpaceBeforeAssignmentOperators: 'true'
35SpaceBeforeParens: ControlStatements
36SpaceBeforeRangeBasedForLoopColon: 'false'
37SpaceInEmptyParentheses: 'false'
38SpacesInAngles: 'false'
39SpacesInCStyleCastParentheses: 'false'
40SpacesInConditionalStatement: 'true'
41SpacesInParentheses: 'false'
42Standard: Auto
43TabWidth: '4'
44UseTab: ForIndentation
45...
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..0bceb5b
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,19 @@
1---
2Checks: "*,
3 -abseil-*,
4 -altera-*,
5 -android-*,
6 -fuchsia-*,
7 -google-*,
8 -llvm*,
9 -modernize-use-trailing-return-type,
10 -zircon-*,
11 -readability-else-after-return,
12 -readability-static-accessed-through-instance,
13 -readability-avoid-const-params-in-decls,
14 -cppcoreguidelines-non-private-member-variables-in-classes,
15 -misc-non-private-member-variables-in-classes,
16"
17WarningsAsErrors: ''
18HeaderFilterRegex: ''
19FormatStyle: none
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cd42ee3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
1bin/
2obj/
diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 0000000..3ea2c1a
--- /dev/null
+++ b/compile_flags.txt
@@ -0,0 +1,10 @@
1-Wall
2-Werror
3-Wextra
4-Wconversion
5-Wdouble-promotion
6-pedantic
7-std=c++17
8-Iinclude
9-I../minmea/include
10-I/usr/local/include
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..29f8ca1
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,2 @@
1CPPFLAGS=-Wall -Werror -pedantic -std=c++17 -O2 -Iinclude -I../minmea/include -I/usr/local/include -DNDEBUG
2LDFLAGS=-L../minmea/lib -lminmea -L/usr/local/lib -lpthread
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..3f481bc
--- /dev/null
+++ b/makefile
@@ -0,0 +1,15 @@
1include config.mk
2
3bin/app: obj/main.o | bin
4 c++ $(LDFLAGS) $^ -o $@
5
6obj/%.o: src/%.cpp | obj
7 c++ $(CPPFLAGS) -c $< -o $@
8
9clean:
10 rm -rf bin obj
11
12bin obj:
13 mkdir $@
14
15.PHONY: all clean
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..e699c6a
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,86 @@
1#include <asio.hpp>
2#include <ctime>
3#include <iostream>
4#include <string>
5
6#include "minmea.h"
7
8using namespace std;
9
10// constexpr auto PORT = "/dev/cuaU0";
11constexpr auto PORT = "/dev/ugen0.14";
12constexpr auto BAUDRATE = 9600;
13
14namespace {
15
16auto
17read_line(asio::serial_port& com)
18{
19 for ( string result;; ) {
20 char chr = 0;
21
22 asio::read(com, asio::buffer(&chr, 1));
23 switch ( chr ) {
24 case '\r':
25 break;
26 case '\n':
27 return result;
28 default:
29 result += chr;
30 }
31 }
32}
33
34string
35get_gps_timestamp(const minmea_time& time, const minmea_date& date)
36{
37 tm tm_utc{};
38 ::minmea_getdatetime(&tm_utc, &date, &time);
39
40 auto timestamp = ::timegm(&tm_utc);
41
42 tm tm_local{};
43 (void) ::localtime_r(&timestamp, &tm_local);
44
45 static const auto buffer_size = 100;
46 array<char, buffer_size> buffer{};
47
48 (void) ::strftime(buffer.data(), buffer.size(), "%Y-%m-%d %H:%M:%S", &tm_local);
49
50 return buffer.data();
51}
52
53} // namespace
54
55int
56main()
57{
58 try {
59 asio::io_context io_context{};
60 asio::serial_port com(io_context, PORT);
61 com.set_option(asio::serial_port::baud_rate(BAUDRATE));
62
63 for ( ;; ) {
64 const auto line = read_line(com);
65 const auto nmea_id = ::minmea_sentence_id(line.c_str(), true);
66
67 if ( nmea_id != MINMEA_SENTENCE_RMC ) {
68 continue;
69 }
70
71 minmea_sentence_rmc frame{};
72 if ( !::minmea_parse_rmc(&frame, line.c_str()) || !frame.valid ) {
73 continue;
74 }
75
76 auto timestamp = get_gps_timestamp(frame.time, frame.date);
77
78 cout << timestamp << ": $RMC floating point degree coordinates and speed: ("
79 << ::minmea_tocoord(&frame.latitude) << "," << ::minmea_tocoord(&frame.longitude) << ") "
80 << ::minmea_tofloat(&frame.speed) << '\n';
81 }
82 }
83 catch ( exception& e ) {
84 cerr << "io-error: " << e.what() << '\n';
85 }
86}