NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / string.cpp
blob31d67d7069b10da4da70da5576d811253c9a3235
1 #include "string.hpp"
2 #include <marnav/utils/mmsi.hpp>
4 namespace marnav
6 namespace nmea
8 std::string to_string(char data)
10 char buf[sizeof(int)]; // sizeof(int) is for stack anlignment and protection
11 snprintf(buf, sizeof(buf), "%c", data);
12 return buf;
15 std::string to_string(uint64_t data)
17 return std::to_string(data);
20 std::string to_string(uint32_t data)
22 return std::to_string(data);
25 std::string to_string(int32_t data)
27 return std::to_string(data);
30 std::string to_string(double data)
32 char buf[32];
33 snprintf(buf, sizeof(buf), "%g", data);
34 return buf;
37 std::string to_string(const std::string & data)
39 return data;
42 std::string to_string(side t)
44 switch (t) {
45 case side::left:
46 return "L";
47 case side::right:
48 return "R";
50 return ""; // never reached, gcc does not get it, prevents compiler warning
53 std::string to_string(route t)
55 switch (t) {
56 case route::complete:
57 return "c";
58 case route::working:
59 return "w";
61 return ""; // never reached, gcc does not get it, prevents compiler warning
64 std::string to_string(selection_mode t)
66 switch (t) {
67 case selection_mode::manual:
68 return "M";
69 case selection_mode::automatic:
70 return "A";
72 return ""; // never reached, gcc does not get it, prevents compiler warning
75 std::string to_string(ais_channel t)
77 switch (t) {
78 case ais_channel::A:
79 return "A";
80 case ais_channel::B:
81 return "B";
83 return ""; // never reached, gcc does not get it, prevents compiler warning
86 std::string to_string(type_of_point t)
88 switch (t) {
89 case type_of_point::collision:
90 return "C";
91 case type_of_point::turning_point:
92 return "T";
93 case type_of_point::reference:
94 return "R";
95 case type_of_point::wheelover:
96 return "W";
98 return ""; // never reached, gcc does not get it, prevents compiler warning
101 std::string to_string(direction t)
103 switch (t) {
104 case direction::north:
105 return "N";
106 case direction::south:
107 return "S";
108 case direction::east:
109 return "E";
110 case direction::west:
111 return "W";
112 case direction::none:
113 return "none";
115 return ""; // never reached, gcc does not get it, prevents compiler warning
118 std::string to_string(reference t)
120 switch (t) {
121 case reference::TRUE:
122 return "T";
123 case reference::MAGNETIC:
124 return "M";
125 case reference::RELATIVE:
126 return "R";
128 return ""; // never reached, gcc does not get it, prevents compiler warning
131 std::string to_string(mode_indicator t)
133 switch (t) {
134 case mode_indicator::invalid:
135 return "V";
136 case mode_indicator::autonomous:
137 return "A";
138 case mode_indicator::differential:
139 return "D";
140 case mode_indicator::estimated:
141 return "E";
142 case mode_indicator::manual_input:
143 return "M";
144 case mode_indicator::simulated:
145 return "S";
146 case mode_indicator::data_not_valid:
147 return "N";
148 case mode_indicator::precise:
149 return "P";
151 return ""; // never reached, gcc does not get it, prevents compiler warning
154 std::string to_string(status t)
156 switch (t) {
157 case status::ok:
158 return "A";
159 case status::warning:
160 return "V";
162 return ""; // never reached, gcc does not get it, prevents compiler warning
165 std::string to_string(quality t)
167 switch (t) {
168 case quality::invalid:
169 return "0";
170 case quality::gps_fix:
171 return "1";
172 case quality::dgps_fix:
173 return "2";
174 case quality::guess:
175 return "6";
176 case quality::simulation:
177 return "8";
179 return ""; // never reached, gcc does not get it, prevents compiler warning
182 std::string to_string(target_status t)
184 switch (t) {
185 case target_status::lost:
186 return "L";
187 case target_status::query:
188 return "Q";
189 case target_status::tracking:
190 return "T";
192 return ""; // never reached, gcc does not get it, prevents compiler warning
195 std::string to_string(unit::distance t)
197 switch (t) {
198 case unit::distance::meter:
199 return "M";
200 case unit::distance::feet:
201 return "f";
202 case unit::distance::nm:
203 return "N";
204 case unit::distance::km:
205 return "K";
206 case unit::distance::fathom:
207 return "F";
209 return ""; // never reached, gcc does not get it, prevents compiler warning
212 std::string to_string(unit::velocity t)
214 switch (t) {
215 case unit::velocity::knot:
216 return "N";
217 case unit::velocity::kmh:
218 return "K";
219 case unit::velocity::mps:
220 return "M";
222 return ""; // never reached, gcc does not get it, prevents compiler warning
225 std::string to_string(unit::temperature t)
227 switch (t) {
228 case unit::temperature::celsius:
229 return "C";
231 return ""; // never reached, gcc does not get it, prevents compiler warning
234 std::string to_string(unit::pressure t)
236 switch (t) {
237 case unit::pressure::bar:
238 return "B";
239 case unit::pressure::pascal:
240 return "P";
242 return ""; // never reached, gcc does not get it, prevents compiler warning
245 std::string to_string(const utils::mmsi & t)
247 char buf[16];
248 snprintf(buf, sizeof(buf), "%09u", static_cast<uint32_t>(t));
249 return buf;