-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaprstrack.hpp
More file actions
3369 lines (2715 loc) · 132 KB
/
Copy pathaprstrack.hpp
File metadata and controls
3369 lines (2715 loc) · 132 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// **************************************************************** //
// libaprstrack - APRS tracking library //
// Version 0.1.0 //
// https://github.com/iontodirel/libaprstrack //
// Copyright (c) 2025 Ion Todirel //
// **************************************************************** //
//
// aprstrack.hpp
//
// MIT License
//
// Copyright (c) 2025 Ion Todirel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// This library is reusing code from position-lib: https://github.com/iontodirel/position-lib
// Copyright (C) 2023 Ion Todirel
//
// This library is reusing code from libaprs: https://github.com/iontodirel/libaprs
// Copyright (C) 2023 Ion Todirel
// References:
//
// - APRS Specification: https://www.aprs.org/doc/APRS101.PDF (APRS 1.0)
// - UTF-8 Specification: https://www.aprs.org/aprs12/utf-8.txt
// - Mic-E examples: https://www.aprs.org/aprs12/mic-e-examples.txt
// - Mic-E types: https://www.aprs.org/aprs12/mic-e-types.txt
// - Understanding APRS Packets: https://raw.githubusercontent.com/wb2osz/aprsspec/main/Understanding-APRS-Packets.pdf
#pragma once
#include <string>
#include <optional>
#include <tuple>
#include <chrono>
#include <iterator>
#include <ranges>
#include <cmath>
#include <algorithm>
#include <array>
#ifndef APRS_TRACK_NAMESPACE
#define APRS_TRACK_NAMESPACE aprs::track
#endif
#ifndef APRS_TRACK_NAMESPACE_BEGIN
#define APRS_TRACK_NAMESPACE_BEGIN namespace APRS_TRACK_NAMESPACE {
#endif
#ifndef APRS_TRACK_DETAIL_NAMESPACE
#define APRS_TRACK_DETAIL_NAMESPACE detail
#endif
#ifndef APRS_TRACK_DETAIL_NAMESPACE_BEGIN
#define APRS_TRACK_DETAIL_NAMESPACE_BEGIN namespace APRS_TRACK_DETAIL_NAMESPACE {
#endif
#ifndef APRS_TRACK_NAMESPACE_END
#define APRS_TRACK_NAMESPACE_END }
#endif
#ifndef APRS_TRACK_DETAIL_NAMESPACE_END
#define APRS_TRACK_DETAIL_NAMESPACE_END }
#endif
#ifndef APRS_TRACK_NAMESPACE_USE
#define APRS_TRACK_NAMESPACE_USE using namespace APRS_TRACK_NAMESPACE;
#endif
#ifndef APRS_TRACK_DETAIL_NAMESPACE_USE
#define APRS_TRACK_DETAIL_NAMESPACE_USE using namespace APRS_TRACK_DETAIL_NAMESPACE;
#endif
#ifndef APRS_TRACK_DETAIL_NAMESPACE_REFERENCE
#define APRS_TRACK_DETAIL_NAMESPACE_REFERENCE APRS_TRACK_DETAIL_NAMESPACE ::
#endif
#ifndef APRS_TRACK_INLINE
#define APRS_TRACK_INLINE inline
#endif
#ifndef APRS_TRACK_INLINE_NO_DISABLE
#define APRS_TRACK_INLINE_NO_DISABLE inline
#endif
#ifdef APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
// Intentionally left empty
#endif
#ifndef APRS_TRACK_SMART_BEACONING_DEBUG
#define APRS_TRACK_SMART_BEACONING_DEBUG(...)
#endif
// **************************************************************** //
// //
// //
// private declarations //
// //
// //
// **************************************************************** //
APRS_TRACK_NAMESPACE_BEGIN
struct tracker; // forward declaration
enum class mic_e_status; // forward declaration
APRS_TRACK_DETAIL_NAMESPACE_BEGIN
template<typename T>
concept has_speed = requires(T t)
{
// expected in m/s
{ t.speed } -> std::convertible_to<double>;
};
template<typename T>
concept has_track = requires(T t)
{
// expected in degrees
{ t.track } -> std::convertible_to<double>;
};
template<typename T>
concept has_day_hour_minute_seconds = requires(T t)
{
{ t.second } -> std::convertible_to<int>;
{ t.minute } -> std::convertible_to<int>;
{ t.day } -> std::convertible_to<int>;
{ t.hour } -> std::convertible_to<int>;
};
template<typename T>
concept has_altitude = requires(T t)
{
// expected in meters
{ t.alt } -> std::convertible_to<double>;
};
struct data
{
double lat = 0.0;
double lon = 0.0;
std::optional<double> speed_knots;
std::optional<double> track_degrees;
std::optional<double> alt_feet;
int day = 0;
int hour = 0; // 24 hour format, 0-23
int minute = 0;
int second = 0;
};
template<typename Container = std::string> Container encode_position_packet_no_timestamp_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_no_timestamp_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_timestamp_dhm_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_timestamp_dhm_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_utc_timestamp_hms_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_utc_timestamp_hms_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_utc_timestamp_dhm_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_with_utc_timestamp_dhm_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_compressed_no_timestamp_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_position_packet_compressed_no_timestamp_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_mic_e_packet_no_message_to(const tracker& t, const data& d);
template<typename Container = std::string> Container encode_mic_e_packet_to(const tracker& t, const data& d);
bool smart_beaconing_test(int speed, int prev_course, int course, int low_speed, int high_speed, int slow_interval_seconds, int fast_interval_seconds, int min_turn_degrees, int turn_interval_seconds, int turn_slope, int last_update_seconds);
double meters_to_feet(double meters);
double mps_to_knots(double mps);
double knots_to_mps(double knots);
APRS_TRACK_NAMESPACE_END
APRS_TRACK_DETAIL_NAMESPACE_END
// **************************************************************** //
// //
// //
// public declarations //
// //
// //
// **************************************************************** //
APRS_TRACK_NAMESPACE_BEGIN
template<typename T>
concept Position = requires(T p)
{
{ p.lat } -> std::convertible_to<double>;
{ p.lon } -> std::convertible_to<double>;
};
enum class packet_type
{
mic_e,
position,
position_compressed,
position_with_timestamp,
position_with_timestamp_utc,
position_with_timestamp_utc_hms,
position_compressed_with_timestamp,
position_compressed_with_timestamp_utc,
position_compressed_with_timestamp_utc_hms,
};
enum class mic_e_status
{
off_duty, // 1 1 1
en_route, // 1 1 0
in_service, // 1 0 1
returning, // 1 0 0
commited, // 0 1 1
special, // 0 1 0
priority, // 0 0 1
emergency, // 0 0 0
custom0, // 1 1 1
custom1, // 1 1 0
custom2, // 1 0 1
custom3, // 1 0 0
custom4, // 0 1 1
custom5, // 0 1 0
custom6, // 0 0 1
unknown
};
enum class compression_type
{
old_other_compressed, // 0 00 000
old_other_tnc_b_text, // 0 00 001
old_other_software, // 0 00 010
old_other_tbd_1, // 0 00 011
old_other_kpc3, // 0 00 100
old_other_pico, // 0 00 101
old_other_other_tracker, // 0 00 110
old_other_digipeater, // 0 00 111
old_gll_compressed, // 0 01 000
old_gll_tnc_b_text, // 0 01 001
old_gll_software, // 0 01 010
old_gll_tbd_1, // 0 01 011
old_gll_kpc3, // 0 01 100
old_gll_pico, // 0 01 101
old_gll_other_tracker, // 0 01 110
old_gll_digipeater, // 0 01 111
old_gga_compressed, // 0 10 000
old_gga_tnc_b_text, // 0 10 001
old_gga_software, // 0 10 010
old_gga_tbd_1, // 0 10 011
old_gga_kpc3, // 0 10 100
old_gga_pico, // 0 10 101
old_gga_other_tracker, // 0 10 110
old_gga_digipeater, // 0 10 111
old_rmc_compressed, // 0 11 000
old_rmc_tnc_b_text, // 0 11 001
old_rmc_software, // 0 11 010
old_rmc_tbd_1, // 0 11 011
old_rmc_kpc3, // 0 11 100
old_rmc_pico, // 0 11 101
old_rmc_other_tracker, // 0 11 110
old_rmc_digipeater, // 0 11 111
current_other_compressed, // 1 00 000
current_other_tnc_b_text, // 1 00 001
current_other_software, // 1 00 010
current_other_tbd_1, // 1 00 011
current_other_kpc3, // 1 00 100
current_other_pico, // 1 00 101
current_other_other_tracker, // 1 00 110
current_other_digipeater, // 1 00 111
current_gll_compressed, // 1 01 000
current_gll_tnc_b_text, // 1 01 001
current_gll_software, // 1 01 010
current_gll_tbd_1, // 1 01 011
current_gll_kpc3, // 1 01 100
current_gll_pico, // 1 01 101
current_gll_other_tracker, // 1 01 110
current_gll_digipeater, // 1 01 111
current_gga_compressed, // 1 10 000
current_gga_tnc_b_text, // 1 10 001
current_gga_software, // 1 10 010
current_gga_tbd_1, // 1 10 011
current_gga_kpc3, // 1 10 100
current_gga_pico, // 1 10 101
current_gga_other_tracker, // 1 10 110
current_gga_digipeater, // 1 10 111
current_rmc_compressed, // 1 11 000
current_rmc_tnc_b_text, // 1 11 001
current_rmc_software, // 1 11 010
current_rmc_tbd_1, // 1 11 011
current_rmc_kpc3, // 1 11 100
current_rmc_pico, // 1 11 101
current_rmc_other_tracker, // 1 11 110
current_rmc_digipeater // 1 11 111
};
enum class device_id
{
original,
unknown,
th_d7a,
tm_d700,
tm_d710,
th_d72a,
th_d74a,
with_messaging,
no_messaging,
vx_8,
ftm_350,
vx_8g,
ft_1d,
ftm_400dr,
};
enum class algorithm
{
smart_beaconing,
periodic,
none,
};
struct tracker
{
void algorithm(enum algorithm a);
enum algorithm algorithm() const;
void symbol_code(char);
void symbol_table(char);
char symbol_code() const;
char symbol_table() const;
void from(std::string_view f);
void to(std::string_view t);
void path(std::string_view p);
std::string_view from() const;
std::string_view to() const;
std::string_view path() const;
void ambiguity(int a);
int ambiguity() const;
void messaging(bool m);
bool messaging() const;
void mic_e_status(enum mic_e_status s);
enum mic_e_status mic_e_status() const;
void low_speed(double speed_mps);
double low_speed() const;
void high_speed(double speed_mps);
double high_speed() const;
void slow_rate(int seconds);
int slow_rate() const;
void fast_rate(int seconds);
int fast_rate() const;
void turn_time(int seconds);
int turn_time() const;
void turn_angle(int degrees);
int turn_angle() const;
void turn_slope(int value);
int turn_slope() const;
template<typename CharType, typename Traits>
void message(const std::basic_string_view<CharType, Traits>& m);
template<typename CharType>
void message(const CharType* m);
template<typename CharType>
void message(const CharType* m, size_t count);
template<std::ranges::input_range InputRange>
void message(InputRange&& input_range);
template<std::input_iterator InputIterator>
void message(InputIterator begin, InputIterator end);
template<std::output_iterator<unsigned char> OutputIterator>
OutputIterator message(OutputIterator output) const;
std::string message() const;
std::u8string u8message() const;
template<class Rep, class Period>
void interval(std::chrono::duration<Rep, Period> interval);
void interval_seconds(int interval_seconds);
template<Position T>
void position(const T& p);
void position(double lat, double lon);
void position(double lat, double lon, double speed, double track_degrees);
void position(double lat, double lon, double speed, double track_degrees, double alt_meters);
void position(double lat, double lon, double speed, double track_degrees, double alt_meters, int day, int hour, int minute, int second);
void time(int day, int hour, int minute, int second);
void time(int hour, int minute, int second);
void time(int minute, int second);
void speed(double speed_mps);
void alt(double alt_meters);
void track(double track_degrees);
void update();
bool updated() const;
template<typename Container = std::string>
Container packet_string_no_message_to(packet_type p) const;
template<typename Container = std::string>
Container packet_string_to(packet_type p) const;
template<std::output_iterator<unsigned char> OutputIterator>
OutputIterator packet(packet_type p, OutputIterator output) const;
template<std::ranges::output_range<unsigned char> OutputRange>
void packet(packet_type p, OutputRange&& output_range) const;
bool smart_beaconing_test();
private:
APRS_TRACK_DETAIL_NAMESPACE_REFERENCE data data_;
std::vector<APRS_TRACK_DETAIL_NAMESPACE_REFERENCE data> data_list_;
std::array<char, 10> from_{};
std::array<char, 10> to_{};
std::array<char, 88> path_{};
enum algorithm algorithm_ = algorithm::none;
std::array<unsigned char, 256> message_data_{};
size_t message_data_length_ = 0;
size_t message_data_size_ = 0;
char symbol_code_ = '>';
char symbol_table_ = '/';
unsigned int interval_seconds_ = 30;
unsigned int last_update_seconds = 0;
std::optional<double> previous_track_degrees_;
std::chrono::time_point<std::chrono::high_resolution_clock> last_time;
double low_speed_knots_ = 4.0; // 5 mph -> 4 knots
double high_speed_knots_ = 52.0; // 60 mph -> 52 knots
int slow_rate_ = 60; // 60 seconds (1 minute)
int fast_rate_ = 30; // 30 seconds
int turn_time_ = 15; // 15 seconds
int turn_angle_ = 15; // 15 degrees
int turn_slope_ = 255; // 255 (no slope)
int ambiguity_ = 0;
bool aprs_messaging_ = false;
bool updated_ = false;
enum mic_e_status mic_e_status_ = mic_e_status::in_service;
};
std::string to_string(mic_e_status status);
std::string to_string(packet_type type);
APRS_TRACK_NAMESPACE_END
// **************************************************************** //
// //
// //
// public definitions //
// //
// //
// **************************************************************** //
APRS_TRACK_NAMESPACE_BEGIN
#ifndef APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
APRS_TRACK_INLINE std::string to_string(mic_e_status status)
{
switch (status)
{
case mic_e_status::off_duty: return "off_duty";
case mic_e_status::en_route: return "en_route";
case mic_e_status::in_service: return "in_service";
case mic_e_status::returning: return "returning";
case mic_e_status::commited: return "commited";
case mic_e_status::special: return "special";
case mic_e_status::priority: return "priority";
case mic_e_status::emergency: return "emergency";
case mic_e_status::custom0: return "custom0";
case mic_e_status::custom1: return "custom1";
case mic_e_status::custom2: return "custom2";
case mic_e_status::custom3: return "custom3";
case mic_e_status::custom4: return "custom4";
case mic_e_status::custom5: return "custom5";
case mic_e_status::custom6: return "custom6";
default:
break;
}
return "unknown";
}
APRS_TRACK_INLINE std::string to_string(packet_type type)
{
switch (type)
{
case packet_type::mic_e: return "mic_e";
case packet_type::position: return "position";
case packet_type::position_compressed: return "position_compressed";
case packet_type::position_with_timestamp: return "position_with_timestamp";
case packet_type::position_with_timestamp_utc: return "position_with_timestamp_utc";
case packet_type::position_with_timestamp_utc_hms: return "position_with_timestamp_utc_hms";
case packet_type::position_compressed_with_timestamp: return "position_compressed_with_timestamp";
case packet_type::position_compressed_with_timestamp_utc: return "position_compressed_with_timestamp_utc";
case packet_type::position_compressed_with_timestamp_utc_hms: return "position_compressed_with_timestamp_utc_hms";
default:
break;
}
return "";
}
APRS_TRACK_INLINE void tracker::algorithm(enum algorithm a)
{
algorithm_ = a;
}
APRS_TRACK_INLINE enum algorithm tracker::algorithm() const
{
return algorithm_;
}
APRS_TRACK_INLINE void tracker::symbol_code(char c)
{
symbol_code_ = c;
}
APRS_TRACK_INLINE char tracker::symbol_code() const
{
return symbol_code_;
}
APRS_TRACK_INLINE void tracker::symbol_table(char t)
{
symbol_table_ = t;
}
APRS_TRACK_INLINE char tracker::symbol_table() const
{
return symbol_table_;
}
APRS_TRACK_INLINE void tracker::from(std::string_view f)
{
auto len = (std::min)(f.size(), from_.size() - 1);
std::copy_n(f.data(), len, from_.data());
from_[len] = '\0';
}
APRS_TRACK_INLINE std::string_view tracker::from() const
{
return from_.data();
}
APRS_TRACK_INLINE void tracker::to(std::string_view t)
{
auto len = (std::min)(t.size(), to_.size() - 1);
std::copy_n(t.data(), len, to_.data());
to_[len] = '\0';
}
APRS_TRACK_INLINE std::string_view tracker::to() const
{
return to_.data();
}
APRS_TRACK_INLINE void tracker::path(std::string_view p)
{
auto len = (std::min)(p.size(), path_.size() - 1);
std::copy_n(p.data(), len, path_.data());
path_[len] = '\0';
}
APRS_TRACK_INLINE std::string_view tracker::path() const
{
return path_.data();
}
APRS_TRACK_INLINE void tracker::ambiguity(int a)
{
ambiguity_ = a;
}
APRS_TRACK_INLINE int tracker::ambiguity() const
{
return ambiguity_;
}
APRS_TRACK_INLINE void tracker::messaging(bool m)
{
aprs_messaging_ = m;
}
APRS_TRACK_INLINE bool tracker::messaging() const
{
return aprs_messaging_;
}
APRS_TRACK_INLINE void tracker::mic_e_status(enum mic_e_status s)
{
mic_e_status_ = s;
}
APRS_TRACK_INLINE enum mic_e_status tracker::mic_e_status() const
{
return mic_e_status_;
}
APRS_TRACK_INLINE void tracker::low_speed(double speed_mps)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
low_speed_knots_ = mps_to_knots(speed_mps);
}
APRS_TRACK_INLINE double tracker::low_speed() const
{
APRS_TRACK_DETAIL_NAMESPACE_USE
return knots_to_mps(low_speed_knots_);
}
APRS_TRACK_INLINE void tracker::high_speed(double speed_mps)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
high_speed_knots_ = mps_to_knots(speed_mps);
}
APRS_TRACK_INLINE double tracker::high_speed() const
{
APRS_TRACK_DETAIL_NAMESPACE_USE
return knots_to_mps(high_speed_knots_);
}
APRS_TRACK_INLINE void tracker::slow_rate(int seconds)
{
slow_rate_ = seconds;
}
APRS_TRACK_INLINE int tracker::slow_rate() const
{
return slow_rate_;
}
APRS_TRACK_INLINE void tracker::fast_rate(int seconds)
{
fast_rate_ = seconds;
}
APRS_TRACK_INLINE int tracker::fast_rate() const
{
return fast_rate_;
}
APRS_TRACK_INLINE void tracker::turn_time(int seconds)
{
turn_time_ = seconds;
}
APRS_TRACK_INLINE int tracker::turn_time() const
{
return turn_time_;
}
APRS_TRACK_INLINE void tracker::turn_angle(int degrees)
{
turn_angle_ = degrees;
}
APRS_TRACK_INLINE int tracker::turn_angle() const
{
return turn_angle_;
}
APRS_TRACK_INLINE void tracker::turn_slope(int value)
{
turn_slope_ = value;
}
APRS_TRACK_INLINE int tracker::turn_slope() const
{
return turn_slope_;
}
#endif // APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
template<typename CharType, typename Traits>
APRS_TRACK_INLINE_NO_DISABLE void tracker::message(const std::basic_string_view<CharType, Traits>& m)
{
message_data_length_ = m.size();
const unsigned char* data = reinterpret_cast<const unsigned char*>(m.data());
size_t size = (std::min)(m.size() * sizeof(CharType), message_data_.size());
std::copy_n(data, size, message_data_.begin());
message_data_size_ = size;
}
template<typename CharType>
APRS_TRACK_INLINE_NO_DISABLE void tracker::message(const CharType* m)
{
message(std::basic_string_view<CharType>(m));
}
template<typename CharType>
APRS_TRACK_INLINE_NO_DISABLE void tracker::message(const CharType* m, size_t count)
{
message(std::basic_string_view<CharType>(m, count));
}
template<std::ranges::input_range InputRange>
APRS_TRACK_INLINE_NO_DISABLE void tracker::message(InputRange&& input_range)
{
message(std::ranges::begin(input_range), std::ranges::end(input_range));
}
template<std::input_iterator InputIterator>
APRS_TRACK_INLINE_NO_DISABLE void tracker::message(InputIterator begin, InputIterator end)
{
message_data_length_ = std::distance(begin, end);
message_data_size_ = (std::min)(static_cast<size_t>(message_data_length_), message_data_.size());
std::copy_n(begin, message_data_size_, message_data_.begin());
}
template<std::output_iterator<unsigned char> OutputIterator>
APRS_TRACK_INLINE_NO_DISABLE OutputIterator tracker::message(OutputIterator output) const
{
output = std::copy_n(message_data_.begin(), message_data_size_, output);
return output;
}
#ifndef APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
APRS_TRACK_INLINE std::string tracker::message() const
{
const char* data = reinterpret_cast<const char*>(message_data_.data());
return std::string(data, message_data_length_);
}
APRS_TRACK_INLINE std::u8string tracker::u8message() const
{
const char8_t* data = reinterpret_cast<const char8_t*>(message_data_.data());
return std::u8string(data, message_data_length_);
}
#endif
template<class Rep, class Period>
APRS_TRACK_INLINE_NO_DISABLE void tracker::interval(std::chrono::duration<Rep, Period> interval)
{
interval_seconds_ = static_cast<int>(std::chrono::duration_cast<std::chrono::seconds>(interval).count());
}
template<Position T>
APRS_TRACK_INLINE_NO_DISABLE void tracker::position(const T& p)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.lat = p.lat;
data_.lon = p.lon;
if constexpr (has_speed<T>)
{
data_.speed_knots = mps_to_knots(p.speed);
}
if constexpr (has_track<T>)
{
data_.track_degrees = p.track;
}
if constexpr (has_day_hour_minute_seconds<T>)
{
data_.day = p.day;
data_.hour = p.hour;
data_.minute = p.minute;
data_.second = p.second;
}
if constexpr (has_altitude<T>)
{
data_.alt_feet = meters_to_feet(p.alt);
}
}
#ifndef APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
APRS_TRACK_INLINE void tracker::interval_seconds(int interval_seconds)
{
interval_seconds_ = interval_seconds;
}
APRS_TRACK_INLINE void tracker::position(double lat, double lon)
{
data_.lat = lat;
data_.lon = lon;
}
APRS_TRACK_INLINE void tracker::position(double lat, double lon, double speed_mps, double track_degrees)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.lat = lat;
data_.lon = lon;
data_.speed_knots = mps_to_knots(speed_mps);
data_.track_degrees = track_degrees;
}
APRS_TRACK_INLINE void tracker::position(double lat, double lon, double speed_mps, double track_degrees, double alt_meters)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.lat = lat;
data_.lon = lon;
data_.speed_knots = mps_to_knots(speed_mps);
data_.track_degrees = track_degrees;
data_.alt_feet = meters_to_feet(alt_meters);
}
APRS_TRACK_INLINE void tracker::position(double lat, double lon, double speed_mps, double track_degrees, double alt_meters, int day, int hour, int minute, int second)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.lat = lat;
data_.lon = lon;
data_.speed_knots = mps_to_knots(speed_mps);
data_.track_degrees = track_degrees;
data_.alt_feet = meters_to_feet(alt_meters);
data_.day = day;
data_.hour = hour;
data_.minute = minute;
data_.second = second;
}
APRS_TRACK_INLINE void tracker::time(int day, int hour, int minute, int second)
{
data_.day = day;
data_.hour = hour;
data_.minute = minute;
data_.second = second;
}
APRS_TRACK_INLINE void tracker::time(int hour, int minute, int second)
{
data_.hour = hour;
data_.minute = minute;
data_.second = second;
}
APRS_TRACK_INLINE void tracker::time(int minute, int second)
{
data_.minute = minute;
data_.second = second;
}
APRS_TRACK_INLINE void tracker::speed(double speed_mps)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.speed_knots = mps_to_knots(speed_mps);
}
APRS_TRACK_INLINE void tracker::alt(double alt_meters)
{
APRS_TRACK_DETAIL_NAMESPACE_USE
data_.alt_feet = meters_to_feet(alt_meters);
}
APRS_TRACK_INLINE void tracker::track(double track_degrees)
{
data_.track_degrees = track_degrees;
}
APRS_TRACK_INLINE void tracker::update()
{
auto current_time = std::chrono::high_resolution_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(current_time - last_time).count();
last_update_seconds = static_cast<unsigned int>(elapsed_time);
if (algorithm_ == algorithm::smart_beaconing)
{
if (smart_beaconing_test())
{
last_time = std::chrono::high_resolution_clock::now();
previous_track_degrees_ = data_.track_degrees;
updated_ = true;
return;
}
}
else if (algorithm_ == algorithm::periodic)
{
if (last_update_seconds >= interval_seconds_)
{
last_time = std::chrono::high_resolution_clock::now();
updated_ = true;
return;
}
}
updated_ = false;
}
APRS_TRACK_INLINE bool tracker::updated() const
{
return updated_;
}
#endif // APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
template<typename Container>
APRS_TRACK_INLINE_NO_DISABLE Container tracker::packet_string_no_message_to(packet_type p) const
{
APRS_TRACK_DETAIL_NAMESPACE_USE
switch (p)
{
case aprs::track::packet_type::mic_e:
return encode_mic_e_packet_no_message_to<Container>(*this, data_);
case aprs::track::packet_type::position:
return encode_position_packet_no_timestamp_no_message_to<Container>(*this, data_);
case aprs::track::packet_type::position_compressed:
return encode_position_packet_compressed_no_timestamp_no_message_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp:
return encode_position_packet_with_timestamp_dhm_no_message_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp_utc:
return encode_position_packet_with_utc_timestamp_dhm_no_message_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp_utc_hms:
return encode_position_packet_with_utc_timestamp_hms_no_message_to<Container>(*this, data_);
default:
return Container{};
}
}
template<typename Container>
APRS_TRACK_INLINE_NO_DISABLE Container tracker::packet_string_to(packet_type p) const
{
APRS_TRACK_DETAIL_NAMESPACE_USE
switch (p)
{
case aprs::track::packet_type::mic_e:
return encode_mic_e_packet_to<Container>(*this, data_);
case aprs::track::packet_type::position:
return encode_position_packet_no_timestamp_to<Container>(*this, data_);
case aprs::track::packet_type::position_compressed:
return encode_position_packet_compressed_no_timestamp_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp:
return encode_position_packet_with_timestamp_dhm_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp_utc:
return encode_position_packet_with_utc_timestamp_dhm_to<Container>(*this, data_);
case aprs::track::packet_type::position_with_timestamp_utc_hms:
return encode_position_packet_with_utc_timestamp_hms_to<Container>(*this, data_);
default:
return Container{};
}
}
template<std::output_iterator<unsigned char> OutputIterator>
APRS_TRACK_INLINE_NO_DISABLE OutputIterator tracker::packet(packet_type p, OutputIterator output) const
{
auto packet = packet_string_no_message_to(p);
output = std::copy(reinterpret_cast<const unsigned char*>(packet.data()), reinterpret_cast<const unsigned char*>(packet.data() + packet.size()), output);
output = std::copy_n(message_data_.begin(), message_data_size_, output);
return output;
}
template<std::ranges::output_range<unsigned char> OutputRange>
APRS_TRACK_INLINE_NO_DISABLE void tracker::packet(packet_type p, OutputRange&& output_range) const
{
packet(p, std::ranges::begin(output_range));
}
#ifndef APRS_TRACK_PUBLIC_FORWARD_DECLARATIONS_ONLY
APRS_TRACK_INLINE bool tracker::smart_beaconing_test()
{
int speed_knots = static_cast<int>(data_.speed_knots.value_or(0.0));
int course_degrees = static_cast<int>(data_.track_degrees.value_or(0));
int prev_course_degrees = static_cast<int>(previous_track_degrees_.value_or(0));
int low_speed_knots_int = static_cast<int>(std::round(low_speed_knots_));
int high_speed_knots_int = static_cast<int>(std::round(high_speed_knots_));
bool result = APRS_TRACK_DETAIL_NAMESPACE_REFERENCE smart_beaconing_test(speed_knots, prev_course_degrees, course_degrees, low_speed_knots_int, high_speed_knots_int, slow_rate_,
fast_rate_, turn_time_, turn_angle_, turn_slope_, last_update_seconds);
return result;
}