30 #include "ccl_compatibility.h"
41 if (
dccl->get_id_codec() !=
"dccl.ccl.id")
42 dccl->set_id_codec(
"dccl.ccl.id");
101 dccl::Bitset dccl::legacyccl::LatLonCompressedCodec::encode() {
return encode(0); }
103 dccl::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));
111 double dccl::legacyccl::LatLonCompressedCodec::decode(
Bitset* bits)
114 decoded.as_long =
static_cast<long>(bits->
to_ulong());
115 return Decode_latlon(decoded.as_compressed);
118 unsigned dccl::legacyccl::LatLonCompressedCodec::size()
120 return LATLON_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
127 dccl::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);
168 dccl::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;
178 unsigned dccl::legacyccl::TimeDateCodec::size()
180 return TIME_DATE_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
186 dccl::Bitset dccl::legacyccl::HeadingCodec::encode(
const float& wire_value)
188 return dccl::Bitset(size(), Encode_heading(wire_value));
191 float dccl::legacyccl::HeadingCodec::decode(
Bitset* bits)
193 return Decode_heading(bits->
to_ulong());
199 dccl::Bitset dccl::legacyccl::DepthCodec::encode(
const float& wire_value)
204 float dccl::legacyccl::DepthCodec::decode(
Bitset* bits) {
return Decode_depth(bits->
to_ulong()); }
209 dccl::Bitset dccl::legacyccl::VelocityCodec::encode(
const float& wire_value)
211 return dccl::Bitset(size(), Encode_est_velocity(wire_value));
214 float dccl::legacyccl::VelocityCodec::decode(
Bitset* bits)
216 return Decode_est_velocity(bits->
to_ulong());
222 dccl::Bitset dccl::legacyccl::SpeedCodec::encode(
const float& wire_value)
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));
240 float dccl::legacyccl::SpeedCodec::decode(
Bitset* bits)
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());
260 dccl::Bitset dccl::legacyccl::WattsCodec::encode(
const float& wire_value)
262 return dccl::Bitset(size(), Encode_watts(wire_value, 1));
265 float dccl::legacyccl::WattsCodec::decode(
Bitset* bits) {
return Decode_watts(bits->
to_ulong()); }
274 size(), Encode_gfi_pitch_oil(wire_value.gfi(), wire_value.pitch(), wire_value.oil()));
278 dccl::legacyccl::GFIPitchOilCodec::decode(
Bitset* bits)
280 float gfi, pitch, oil;
281 Decode_gfi_pitch_oil(bits->
to_ulong(), &gfi, &pitch, &oil);
283 decoded.set_gfi(gfi);
284 decoded.set_pitch(pitch);
285 decoded.set_oil(oil);
292 dccl::Bitset dccl::legacyccl::HiResAltitudeCodec::encode(
const float& wire_value)
294 return dccl::Bitset(size(), Encode_hires_altitude(wire_value));
297 float dccl::legacyccl::HiResAltitudeCodec::decode(
Bitset* bits)
299 return Decode_hires_altitude(bits->
to_ulong());
305 dccl::Bitset dccl::legacyccl::SalinityCodec::encode(
const float& wire_value)
307 return dccl::Bitset(size(), Encode_salinity(wire_value));
310 float dccl::legacyccl::SalinityCodec::decode(
Bitset* bits)
312 return Decode_salinity(bits->
to_ulong());
318 dccl::Bitset dccl::legacyccl::TemperatureCodec::encode(
const float& wire_value)
320 return dccl::Bitset(size(), Encode_temperature(wire_value));
323 float dccl::legacyccl::TemperatureCodec::decode(
Bitset* bits)
325 return Decode_temperature(bits->
to_ulong());
331 dccl::Bitset dccl::legacyccl::SoundSpeedCodec::encode(
const float& wire_value)
333 return dccl::Bitset(size(), Encode_sound_speed(wire_value));
336 float dccl::legacyccl::SoundSpeedCodec::decode(
Bitset* bits)
338 return Decode_sound_speed(bits->
to_ulong());