31 #include "ccl_compatibility.h"
42 if (
dccl->get_id_codec() !=
"dccl.ccl.id")
43 dccl->set_id_codec(
"dccl.ccl.id");
102 dccl::Bitset dccl::legacyccl::LatLonCompressedCodec::encode() {
return encode(0); }
104 dccl::Bitset dccl::legacyccl::LatLonCompressedCodec::encode(
const double& wire_value)
108 encoded.as_compressed = Encode_latlon(wire_value);
109 return dccl::Bitset(size(),
static_cast<unsigned long>(encoded.as_long));
112 double dccl::legacyccl::LatLonCompressedCodec::decode(
Bitset* bits)
115 decoded.as_long =
static_cast<long>(bits->
to_ulong());
116 return Decode_latlon(decoded.as_compressed);
119 unsigned dccl::legacyccl::LatLonCompressedCodec::size()
121 return LATLON_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
128 dccl::Bitset dccl::legacyccl::TimeDateCodec::encode() {
return encode(0); }
134 encoded.as_time_date = Encode_time_date(wire_value / MICROSECONDS_IN_SECOND);
135 return dccl::Bitset(size(),
static_cast<unsigned long>(encoded.as_long));
142 short mon, day, hour, min, sec;
143 Decode_time_date(decoded.as_time_date, &mon, &day, &hour, &min, &sec);
146 auto now = std::chrono::system_clock::now();
147 std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
150 std::tm current_year_tm = *std::gmtime(&now_time_t);
151 int current_year = current_year_tm.tm_year + 1900;
155 input_tm.tm_year = current_year - 1900;
156 input_tm.tm_mon = mon - 1;
157 input_tm.tm_mday = day;
158 input_tm.tm_hour = hour;
159 input_tm.tm_min = min;
160 input_tm.tm_sec = sec;
161 input_tm.tm_isdst = -1;
164 std::time_t input_time_t = timegm(&input_tm);
166 return to_uint64_time(input_time_t);
169 dccl::uint64 dccl::legacyccl::TimeDateCodec::to_uint64_time(
const std::time_t& time_date)
171 std::chrono::system_clock::duration input_duration =
172 std::chrono::system_clock::from_time_t(time_date) -
173 std::chrono::system_clock::from_time_t(0);
174 uint64_t microseconds_since_epoch =
175 std::chrono::duration_cast<std::chrono::microseconds>(input_duration).count();
176 return microseconds_since_epoch;
179 unsigned dccl::legacyccl::TimeDateCodec::size()
181 return TIME_DATE_COMPRESSED_BYTE_SIZE * BITS_IN_BYTE;
187 dccl::Bitset dccl::legacyccl::HeadingCodec::encode(
const float& wire_value)
189 return dccl::Bitset(size(), Encode_heading(wire_value));
192 float dccl::legacyccl::HeadingCodec::decode(
Bitset* bits)
194 return Decode_heading(bits->
to_ulong());
200 dccl::Bitset dccl::legacyccl::DepthCodec::encode(
const float& wire_value)
205 float dccl::legacyccl::DepthCodec::decode(
Bitset* bits) {
return Decode_depth(bits->
to_ulong()); }
210 dccl::Bitset dccl::legacyccl::VelocityCodec::encode(
const float& wire_value)
212 return dccl::Bitset(size(), Encode_est_velocity(wire_value));
215 float dccl::legacyccl::VelocityCodec::decode(
Bitset* bits)
217 return Decode_est_velocity(bits->
to_ulong());
223 dccl::Bitset dccl::legacyccl::SpeedCodec::encode(
const float& wire_value)
226 const google::protobuf::FieldDescriptor* thrust_mode_field_desc =
227 root->GetDescriptor()->FindFieldByNumber(
230 switch (root->GetReflection()->GetEnum(*root, thrust_mode_field_desc)->number())
233 case protobuf::CCLMDATRedirect::RPM:
234 return dccl::Bitset(size(), Encode_speed(SPEED_MODE_RPM, wire_value));
236 case protobuf::CCLMDATRedirect::METERS_PER_SECOND:
237 return dccl::Bitset(size(), Encode_speed(SPEED_MODE_MSEC, wire_value));
241 float dccl::legacyccl::SpeedCodec::decode(
Bitset* bits)
244 const google::protobuf::FieldDescriptor* thrust_mode_field_desc =
245 root->GetDescriptor()->FindFieldByNumber(
248 switch (root->GetReflection()->GetEnum(*root, thrust_mode_field_desc)->number())
251 case protobuf::CCLMDATRedirect::RPM:
return Decode_speed(SPEED_MODE_RPM, bits->
to_ulong());
253 case protobuf::CCLMDATRedirect::METERS_PER_SECOND:
254 return Decode_speed(SPEED_MODE_MSEC, bits->
to_ulong());
261 dccl::Bitset dccl::legacyccl::WattsCodec::encode(
const float& wire_value)
263 return dccl::Bitset(size(), Encode_watts(wire_value, 1));
266 float dccl::legacyccl::WattsCodec::decode(
Bitset* bits) {
return Decode_watts(bits->
to_ulong()); }
275 size(), Encode_gfi_pitch_oil(wire_value.gfi(), wire_value.pitch(), wire_value.oil()));
279 dccl::legacyccl::GFIPitchOilCodec::decode(
Bitset* bits)
281 float gfi, pitch, oil;
282 Decode_gfi_pitch_oil(bits->
to_ulong(), &gfi, &pitch, &oil);
284 decoded.set_gfi(gfi);
285 decoded.set_pitch(pitch);
286 decoded.set_oil(oil);
293 dccl::Bitset dccl::legacyccl::HiResAltitudeCodec::encode(
const float& wire_value)
295 return dccl::Bitset(size(), Encode_hires_altitude(wire_value));
298 float dccl::legacyccl::HiResAltitudeCodec::decode(
Bitset* bits)
300 return Decode_hires_altitude(bits->
to_ulong());
306 dccl::Bitset dccl::legacyccl::SalinityCodec::encode(
const float& wire_value)
308 return dccl::Bitset(size(), Encode_salinity(wire_value));
311 float dccl::legacyccl::SalinityCodec::decode(
Bitset* bits)
313 return Decode_salinity(bits->
to_ulong());
319 dccl::Bitset dccl::legacyccl::TemperatureCodec::encode(
const float& wire_value)
321 return dccl::Bitset(size(), Encode_temperature(wire_value));
324 float dccl::legacyccl::TemperatureCodec::decode(
Bitset* bits)
326 return Decode_temperature(bits->
to_ulong());
332 dccl::Bitset dccl::legacyccl::SoundSpeedCodec::encode(
const float& wire_value)
334 return dccl::Bitset(size(), Encode_sound_speed(wire_value));
337 float dccl::legacyccl::SoundSpeedCodec::decode(
Bitset* bits)
339 return Decode_sound_speed(bits->
to_ulong());