Goby v2
waveglider_sv2_codecs.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include "waveglider_sv2_frontseat_driver.pb.h"
24 #include <dccl.h>
25 #include <dccl/field_codec_id.h>
26 
27 extern "C"
28 {
29  void dccl3_load(dccl::Codec* dccl);
30  void dccl3_unload(dccl::Codec* dccl);
31 }
32 
33 namespace goby
34 {
35 namespace moos
36 {
37 class SV2IdentifierCodec : public dccl::DefaultIdentifierCodec
38 {
39  private:
40  dccl::Bitset encode() { return encode(0); }
41 
42  dccl::Bitset encode(const dccl::uint32& wire_value)
43  {
44  return dccl::Bitset(size(), wire_value - 0x7E0000);
45  }
46 
47  dccl::uint32 decode(dccl::Bitset* bits) { return 0x7E0000 + bits->to<dccl::uint32>(); }
48 
49  unsigned size() { return 2 * dccl::BITS_IN_BYTE; }
50 
51  unsigned size(const dccl::uint32& field_value) { return size(); }
52 
53  unsigned max_size() { return size(); }
54 
55  unsigned min_size() { return size(); }
56 };
57 
58 template <typename Integer> class SV2NumericCodec : public dccl::TypedFixedFieldCodec<Integer>
59 {
60  private:
61  unsigned size()
62  {
63  dccl::uint64 v = dccl::FieldCodecBase::dccl_field_options().max() + 1;
64  unsigned r = 0;
65  while (v >>= 1) r++;
66  return r;
67  }
68 
69  dccl::Bitset encode() { return dccl::Bitset(size()); }
70 
71  // this works because both DCCL and the SV2 protocol uses little-endian representation
72  dccl::Bitset encode(const Integer& i)
73  {
74  dccl::Bitset b;
75  b.from<Integer>(i, size());
76  return b;
77  }
78 
79  Integer decode(dccl::Bitset* bits) { return bits->to<Integer>(); }
80 
81  void validate() {}
82 };
83 } // namespace moos
84 } // namespace goby
The global namespace for the Goby project.