1 #ifndef __MARNAV__NMEA__AIS_HELPER__HPP__
2 #define __MARNAV__NMEA__AIS_HELPER__HPP__
5 #include <marnav/nmea/vdm.hpp>
13 /// @brief Collects payload from proper NMEA sentences.
15 /// @note This function assumes, that all sentences in the specified range are
16 /// providing payload (VDM or descendents).
18 /// @param[in] begin Iterator pointing to the beginning of the messges to process.
19 /// @param[in] end Iterator pointing after the messages to process (will not be
21 /// @return The container with all payload and padding bit information.
23 /// std::unique_ptr<nmea::sentence> variant. Example:
25 /// std::vector<std::unique_ptr<nmea::sentence>> v;
26 /// v.push_back(nmea::make_sentence("..."));
27 /// v.push_back(nmea::make_sentence("..."));
28 /// auto data = nmea::collect_payload(v.begin(), v.end());
30 template <class InputIt
, typename
std::enable_if
<std::is_class
<InputIt
>::value
31 && std::is_convertible
<typename
InputIt::value_type
,
32 std::unique_ptr
<sentence
>>::value
,
35 std::vector
<std::pair
<std::string
, uint32_t>> collect_payload(InputIt begin
, InputIt end
)
37 std::vector
<std::pair
<std::string
, uint32_t>> v
;
38 v
.reserve(std::distance(begin
, end
));
40 for (; begin
!= end
; ++begin
) {
41 const auto & s
= sentence_cast
<nmea::vdm
>(*begin
);
42 v
.push_back(make_pair(s
->get_payload(), s
->get_n_fill_bits()));
48 /// Object iterator variant. Example:
50 /// std::vector<nmea::vdm> v; // collect data, for example:
51 /// v.push_back(nmea::vdm{});
52 /// v.push_back(nmea::vdm{});
53 /// auto data = nmea::collect_payload(v.begin(), v.end());
55 template <class InputIt
, typename
std::enable_if
<std::is_class
<InputIt
>::value
56 && !std::is_convertible
<typename
InputIt::value_type
,
57 std::unique_ptr
<sentence
>>::value
,
60 std::vector
<std::pair
<std::string
, uint32_t>> collect_payload(InputIt begin
, InputIt end
)
62 std::vector
<std::pair
<std::string
, uint32_t>> v
;
63 v
.reserve(std::distance(begin
, end
));
64 for (; begin
!= end
; ++begin
) {
65 v
.push_back(make_pair(begin
->get_payload(), begin
->get_n_fill_bits()));
70 /// Pointer variant. Example:
72 /// nmea::vdm v[3]; // initialize them in any way...
73 /// auto data = nmea::collect_payload(v, v + 3);
77 /// nmea::vdm v[3]; // initialize them in any way...
78 /// auto data = nmea::collect_payload(std::begin(v), std::end(v));
80 /// this will not compile, because MTW does not provide payload:
83 /// auto data = nmea::collect_payload(std::begin(v), std::end(v));
85 template <class InputIt
,
86 typename
std::enable_if
<std::is_pointer
<InputIt
>::value
, int>::type
= 0>
87 std::vector
<std::pair
<std::string
, uint32_t>> collect_payload(InputIt begin
, InputIt end
)
89 std::vector
<std::pair
<std::string
, uint32_t>> v
;
90 v
.reserve(std::distance(begin
, end
));
91 for (; begin
!= end
; ++begin
) {
92 v
.push_back(make_pair(begin
->get_payload(), begin
->get_n_fill_bits()));
99 std::vector
<std::unique_ptr
<nmea::sentence
>> make_vdms(
100 const std::vector
<std::pair
<std::string
, uint32_t>> & payload
,
101 utils::optional
<uint32_t> seq_msg_id
= utils::optional
<uint32_t>{},
102 ais_channel radio_channel
= ais_channel::B
);