Utils: bitset update to e865429e8a6c17366105e985fd037e42261a1af9.
[marnav.git] / src / marnav / ais / binary_200_10.cpp
blob63a6388bf70432f97278193a14c0b7467dfc0b0c
1 #include "binary_200_10.hpp"
2 #include <algorithm>
3 #include <cmath>
5 namespace marnav
7 namespace ais
9 binary_200_10::binary_200_10()
10 : vessel_id("@@@@@@@@")
14 void binary_200_10::read_from(const raw & payload)
16 if (payload.size() != SIZE_BITS)
17 throw std::invalid_argument{"wrong number of bits in playload of binary_200_10"};
19 get(payload, vessel_id);
20 get(payload, length);
21 get(payload, beam);
22 get(payload, shiptype);
23 get(payload, hazard);
24 get(payload, draught);
25 get(payload, loaded);
26 get(payload, speed_q);
27 get(payload, course_q);
28 get(payload, heading_q);
31 void binary_200_10::write_to(raw & payload) const
33 payload = raw(SIZE_BITS);
34 set(payload, vessel_id);
35 set(payload, length);
36 set(payload, beam);
37 set(payload, shiptype);
38 set(payload, hazard);
39 set(payload, draught);
40 set(payload, loaded);
41 set(payload, speed_q);
42 set(payload, course_q);
43 set(payload, heading_q);
46 std::string binary_200_10::get_vessel_id() const
48 return trim_ais_string(vessel_id);
51 void binary_200_10::set_vessel_id(const std::string & t)
53 if (t.size() > 8) {
54 vessel_id = t.substr(0, 8);
55 } else {
56 vessel_id = t;
60 /// Returns the lenght in meters.
61 double binary_200_10::get_length() const
63 return 0.1 * length;
66 void binary_200_10::set_length(double t)
68 length = std::max(0u, std::min(8000u, static_cast<uint32_t>(std::round(10.0 * t))));
71 /// Returns the beam in meters.
72 double binary_200_10::get_beam() const
74 return 0.1 * beam;
77 void binary_200_10::set_beam(double t)
79 beam = std::max(0u, std::min(1000u, static_cast<uint32_t>(std::round(10.0 * t))));
82 /// Returns the draught in meters.
83 double binary_200_10::get_draught() const
85 return 0.01 * draught;
88 void binary_200_10::set_draught(double t)
90 draught = std::max(0u, std::min(200u, static_cast<uint32_t>(std::round(100.0 * t))));