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