NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / ais_helper.cpp
blob8b61fc1b7eb726ab49ff2087059e08576074e4e1
1 #include "ais_helper.hpp"
2 #include <marnav/utils/unique.hpp>
4 namespace marnav
6 namespace nmea
8 /// Creates and returns a container of VDM sentences, created from the specified
9 /// payload.
10 ///
11 /// @param[in] payload The payload to create VDM sentences from.
12 /// @param[in] seq_msg_id The optional sequence message ID to be configured for
13 /// the resulting sentences.
14 /// @param[in] radio_channel Specifies which AIS radio channel to configure for
15 /// the resulting sentences.
16 /// @return Container of NMEA sentences containing VDM sentences.
17 std::vector<std::unique_ptr<nmea::sentence>> make_vdms(
18 const std::vector<std::pair<std::string, uint32_t>> & payload,
19 utils::optional<uint32_t> seq_msg_id, ais_channel radio_channel)
21 std::vector<std::unique_ptr<nmea::sentence>> sentences;
23 for (uint32_t fragment = 0; fragment < payload.size(); ++fragment) {
24 auto sentence = utils::make_unique<vdm>();
26 sentence->set_n_fragments(payload.size());
27 sentence->set_fragment(fragment + 1);
28 sentence->set_radio_channel(radio_channel);
29 sentence->set_payload(payload[fragment]);
31 if (seq_msg_id)
32 sentence->set_seq_msg_id(*seq_msg_id);
34 sentences.push_back(std::move(sentence));
37 return sentences;