30#include "ccl_compatibility.h"
41 if (
dccl->get_id_codec() !=
"dccl.ccl.id")
42 dccl->set_id_codec(
"dccl.ccl.id");
58 dccl->load<protobuf::CCLMDATEmpty>();
59 dccl->load<protobuf::CCLMDATRedirect>();
60 dccl->load<protobuf::CCLMDATBathy>();
61 dccl->load<protobuf::CCLMDATCTD>();
62 dccl->load<protobuf::CCLMDATState>();
63 dccl->load<protobuf::CCLMDATCommand>();
64 dccl->load<protobuf::CCLMDATError>();
72 dccl->unload<protobuf::CCLMDATEmpty>();
73 dccl->unload<protobuf::CCLMDATRedirect>();
74 dccl->unload<protobuf::CCLMDATBathy>();
75 dccl->unload<protobuf::CCLMDATCTD>();
76 dccl->unload<protobuf::CCLMDATState>();
77 dccl->unload<protobuf::CCLMDATCommand>();
78 dccl->unload<protobuf::CCLMDATError>();
101dccl::Bitset dccl::legacyccl::LatLonCompressedCodec::encode() {
return encode(0); }
103dccl::Bitset dccl::legacyccl::LatLonCompressedCodec::encode(
const double& wire_value)
107 encoded.as_compressed = Encode_latlon(wire_value);
108 return dccl::Bitset(size(),
static_cast<unsigned long>(encoded.as_long));
111double dccl::legacyccl::LatLonCompressedCodec::decode(
Bitset* bits)
114 decoded.as_long =
static_cast<long>(bits->
to_ulong());
115 return Decode_latlon(decoded.as_compressed);
118unsigned dccl::legacyccl::LatLonCompressedCodec::size()
120 return LATLON_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
127dccl::Bitset dccl::legacyccl::TimeDateCodec::encode() {
return encode(0); }
133 encoded.as_time_date = Encode_time_date(wire_value / MICROSECONDS_IN_SECOND);
134 return dccl::Bitset(size(),
static_cast<unsigned long>(encoded.as_long));
141 short mon, day, hour, min, sec;
142 Decode_time_date(decoded.as_time_date, &mon, &day, &hour, &min, &sec);
145 auto now = std::chrono::system_clock::now();
146 std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
149 std::tm current_year_tm = *std::gmtime(&now_time_t);
150 int current_year = current_year_tm.tm_year + 1900;
154 input_tm.tm_year = current_year - 1900;
155 input_tm.tm_mon = mon - 1;
156 input_tm.tm_mday = day;
157 input_tm.tm_hour = hour;
158 input_tm.tm_min = min;
159 input_tm.tm_sec = sec;
160 input_tm.tm_isdst = -1;
163 std::time_t input_time_t = timegm(&input_tm);
165 return to_uint64_time(input_time_t);
168dccl::uint64 dccl::legacyccl::TimeDateCodec::to_uint64_time(
const std::time_t& time_date)
170 std::chrono::system_clock::duration input_duration =
171 std::chrono::system_clock::from_time_t(time_date) -
172 std::chrono::system_clock::from_time_t(0);
173 uint64_t microseconds_since_epoch =
174 std::chrono::duration_cast<std::chrono::microseconds>(input_duration).count();
175 return microseconds_since_epoch;
178unsigned dccl::legacyccl::TimeDateCodec::size()
180 return TIME_DATE_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
186dccl::Bitset dccl::legacyccl::HeadingCodec::encode(
const float& wire_value)
188 return dccl::Bitset(size(), Encode_heading(wire_value));
191float dccl::legacyccl::HeadingCodec::decode(
Bitset* bits)
193 return Decode_heading(bits->
to_ulong());
199dccl::Bitset dccl::legacyccl::DepthCodec::encode(
const float& wire_value)
204float dccl::legacyccl::DepthCodec::decode(
Bitset* bits) {
return Decode_depth(bits->
to_ulong()); }
209dccl::Bitset dccl::legacyccl::VelocityCodec::encode(
const float& wire_value)
211 return dccl::Bitset(size(), Encode_est_velocity(wire_value));
214float dccl::legacyccl::VelocityCodec::decode(
Bitset* bits)
216 return Decode_est_velocity(bits->
to_ulong());
222dccl::Bitset dccl::legacyccl::SpeedCodec::encode(
const float& wire_value)
224 const google::protobuf::Message* root = FieldCodecBase::root_message();
225 const google::protobuf::FieldDescriptor* thrust_mode_field_desc =
226 root->GetDescriptor()->FindFieldByNumber(
229 switch (root->GetReflection()->GetEnum(*root, thrust_mode_field_desc)->number())
232 case protobuf::CCLMDATRedirect::RPM:
233 return dccl::Bitset(size(), Encode_speed(SPEED_MODE_RPM, wire_value));
235 case protobuf::CCLMDATRedirect::METERS_PER_SECOND:
236 return dccl::Bitset(size(), Encode_speed(SPEED_MODE_MSEC, wire_value));
240float dccl::legacyccl::SpeedCodec::decode(
Bitset* bits)
242 const google::protobuf::Message* root = FieldCodecBase::root_message();
243 const google::protobuf::FieldDescriptor* thrust_mode_field_desc =
244 root->GetDescriptor()->FindFieldByNumber(
247 switch (root->GetReflection()->GetEnum(*root, thrust_mode_field_desc)->number())
250 case protobuf::CCLMDATRedirect::RPM:
return Decode_speed(SPEED_MODE_RPM, bits->
to_ulong());
252 case protobuf::CCLMDATRedirect::METERS_PER_SECOND:
253 return Decode_speed(SPEED_MODE_MSEC, bits->
to_ulong());
260dccl::Bitset dccl::legacyccl::WattsCodec::encode(
const float& wire_value)
262 return dccl::Bitset(size(), Encode_watts(wire_value, 1));
265float dccl::legacyccl::WattsCodec::decode(
Bitset* bits) {
return Decode_watts(bits->
to_ulong()); }
271dccl::legacyccl::GFIPitchOilCodec::encode(
const protobuf::CCLMDATState::GFIPitchOil& wire_value)
274 size(), Encode_gfi_pitch_oil(wire_value.gfi(), wire_value.pitch(), wire_value.oil()));
277dccl::legacyccl::protobuf::CCLMDATState::GFIPitchOil
278dccl::legacyccl::GFIPitchOilCodec::decode(
Bitset* bits)
280 float gfi, pitch, oil;
281 Decode_gfi_pitch_oil(bits->
to_ulong(), &gfi, &pitch, &oil);
282 protobuf::CCLMDATState::GFIPitchOil decoded;
283 decoded.set_gfi(gfi);
284 decoded.set_pitch(pitch);
285 decoded.set_oil(oil);
292dccl::Bitset dccl::legacyccl::HiResAltitudeCodec::encode(
const float& wire_value)
294 return dccl::Bitset(size(), Encode_hires_altitude(wire_value));
297float dccl::legacyccl::HiResAltitudeCodec::decode(
Bitset* bits)
299 return Decode_hires_altitude(bits->
to_ulong());
305dccl::Bitset dccl::legacyccl::SalinityCodec::encode(
const float& wire_value)
307 return dccl::Bitset(size(), Encode_salinity(wire_value));
310float dccl::legacyccl::SalinityCodec::decode(
Bitset* bits)
312 return Decode_salinity(bits->
to_ulong());
318dccl::Bitset dccl::legacyccl::TemperatureCodec::encode(
const float& wire_value)
320 return dccl::Bitset(size(), Encode_temperature(wire_value));
323float dccl::legacyccl::TemperatureCodec::decode(
Bitset* bits)
325 return Decode_temperature(bits->
to_ulong());
331dccl::Bitset dccl::legacyccl::SoundSpeedCodec::encode(
const float& wire_value)
333 return dccl::Bitset(size(), Encode_sound_speed(wire_value));
336float dccl::legacyccl::SoundSpeedCodec::decode(
Bitset* bits)
338 return Decode_sound_speed(bits->
to_ulong());
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
unsigned long to_ulong() const
Returns the value of the Bitset as an unsigned long integer. Equivalent to to<unsigned long>().
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
dccl::DCCLFieldOptions dccl_field_options() const
Get the DCCL field option extension value for the current field.
DCCL Implementation of the REMUS CCL Language Library namespace.
Dynamic Compact Control Language namespace.
google::protobuf::uint64 uint64
an unsigned 64 bit integer