26 #include "../../ccl/ccl_compatibility.h"
27 #include "../../codec.h"
28 #include "../../field_codec.h"
33 using dccl::operator<<;
35 bool double_cmp(
double a,
double b,
int precision)
40 int a_part = (a - a_whole) * pow(10.0, precision);
41 int b_part = (b - b_whole) * pow(10.0, precision);
43 return (a_whole == b_whole) && (a_part == b_part);
46 template <
typename N>
void check_normal_dccl(
dccl::Codec& codec)
49 codec.info<N>(&dccl::dlog);
50 N normal_msg, normal_msg_out;
51 normal_msg.set_a(123);
52 normal_msg.set_b(321);
55 codec.encode(&encoded, normal_msg);
58 codec.decode(encoded, &normal_msg_out);
60 assert(normal_msg.SerializeAsString() == normal_msg_out.SerializeAsString());
63 int main(
int ,
char* [])
65 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
67 dccl::Codec codec(
"dccl.ccl.id", DCCL_CCL_COMPAT_NAME);
69 check_normal_dccl<NormalDCCL1Byte>(codec);
70 check_normal_dccl<NormalDCCL2Byte>(codec);
75 std::string test_state_encoded =
76 "0e86fa11ad20c9011b4432bf47d10000002401042f0e7d87fa111620c95a200a";
78 state_in.set_latitude(25.282416667);
79 state_in.set_longitude(-77.164266667);
80 state_in.set_fix_age(4);
82 auto now = std::chrono::system_clock::now();
83 std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
84 std::tm input_tm = *std::gmtime(&now_time_t);
87 input_tm.tm_hour = 17;
90 input_tm.tm_isdst = -1;
91 std::time_t time_date = timegm(&input_tm);
93 state_in.set_time_date(dccl::legacyccl::TimeDateCodec::to_uint64_time(time_date));
94 state_in.set_heading(270);
95 state_in.set_depth(2323);
96 state_in.set_mission_mode(dccl::legacyccl::protobuf::CCLMDATState::NORMAL);
99 state_in.set_mission_leg(4);
100 state_in.set_est_velocity(1.88);
102 state_in.set_watts(500);
103 state_in.set_lat_goal(25.282440815262891);
104 state_in.set_lon_goal(-77.167505880296929);
105 state_in.set_battery_percent(90);
106 state_in.mutable_gfi_pitch_oil()->set_gfi(0);
107 state_in.mutable_gfi_pitch_oil()->set_pitch(6);
108 state_in.mutable_gfi_pitch_oil()->set_oil(55);
110 assert(double_cmp(state_in.latitude(), state_out.latitude(), 4));
111 assert(double_cmp(state_in.longitude(), state_out.longitude(), 4));
112 assert(state_in.fix_age() == state_out.fix_age());
113 assert(state_in.time_date() == state_out.time_date());
114 assert(dccl::round(state_in.heading(), 0) == dccl::round(state_out.heading(), 0));
115 assert(double_cmp(state_in.depth(), state_out.depth(), 1));
116 assert(state_in.mission_mode() == state_out.mission_mode());
119 std::shared_ptr<google::protobuf::Message> state_in_2 =
121 dccl::legacyccl::protobuf::CCLMDATState::descriptor());
122 state_in_2->CopyFrom(state_in);
124 std::string state_encoded;
125 codec.encode(&state_encoded, *state_in_2);
128 codec.decode(state_encoded, &state_out_2);
130 std::cout <<
"in:" << state_in << std::endl;
131 std::cout << test_state_encoded << std::endl;
133 std::cout << std::setprecision(16) << state_out.lon_goal() << std::endl;
134 std::cout <<
"out:" << state_out << std::endl;
135 std::cout <<
"out2: " << state_out_2 << std::endl;
137 assert(state_out.SerializeAsString() == state_out_2.SerializeAsString());
146 std::string test_redirect_encoded =
147 "07522cf9113d20c99964003d6464003d640be60014142035f911ef21c9000000";
149 redirect_in.set_message_number(82);
150 redirect_in.set_latitude(25.274995002149939);
151 redirect_in.set_longitude(-77.166669030984522);
152 redirect_in.set_transit_vertical_mode(dccl::legacyccl::protobuf::CCLMDATRedirect::ALTITUDE);
153 redirect_in.set_transit_thrust_mode(
154 dccl::legacyccl::protobuf::CCLMDATRedirect::METERS_PER_SECOND);
155 redirect_in.set_survey_vertical_mode(dccl::legacyccl::protobuf::CCLMDATRedirect::ALTITUDE);
156 redirect_in.set_survey_thrust_mode(
157 dccl::legacyccl::protobuf::CCLMDATRedirect::METERS_PER_SECOND);
159 redirect_in.set_depth_goal_transit(10.0);
160 redirect_in.set_speed_transit(2.0333333);
161 redirect_in.set_device_cmd_transit(100);
163 redirect_in.set_depth_goal_survey(10.0);
164 redirect_in.set_speed_survey(2.0333333);
165 redirect_in.set_device_cmd_survey(100);
167 redirect_in.set_num_rows(11);
168 redirect_in.set_row_length(230);
169 redirect_in.set_spacing_0(20);
170 redirect_in.set_spacing_1(20);
171 redirect_in.set_heading(45.176472);
173 redirect_in.set_lat_start(25.275183333);
174 redirect_in.set_lon_start(-77.15735);
176 redirect_in.set_spare(std::string(3,
'\0'));
178 std::string redirect_encoded;
179 codec.encode(&redirect_encoded, redirect_in);
182 codec.decode(redirect_encoded, &redirect_out_2);
184 std::cout <<
"in:" << redirect_in << std::endl;
185 std::cout << test_redirect_encoded << std::endl;
187 std::cout <<
"out:" << redirect_out << std::endl;
188 std::cout <<
"out2: " << redirect_out_2 << std::endl;
190 assert(redirect_out.SerializeAsString() == redirect_out_2.SerializeAsString());
199 std::cout <<
"all tests passed" << std::endl;