00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdint.h>
00031 #include <string.h>
00032 #include "an_packet_protocol.h"
00033 #include "spatial_packets.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int decode_acknowledge_packet(acknowledge_packet_t *acknowledge_packet, an_packet_t *an_packet)
00068 {
00069 if(an_packet->id == packet_id_acknowledge && an_packet->length == 4)
00070 {
00071 acknowledge_packet->packet_id = an_packet->data[0];
00072 memcpy(&acknowledge_packet->packet_crc, &an_packet->data[1], sizeof(uint16_t));
00073 acknowledge_packet->acknowledge_result = an_packet->data[3];
00074 return 0;
00075 }
00076 else return 1;
00077 }
00078
00079 an_packet_t *encode_request_packet(uint8_t requested_packet_id)
00080 {
00081 an_packet_t *an_packet = an_packet_allocate(1, packet_id_request);
00082 an_packet->data[0] = requested_packet_id;
00083 return an_packet;
00084 }
00085
00086 int decode_boot_mode_packet(boot_mode_packet_t *boot_mode_packet, an_packet_t *an_packet)
00087 {
00088 if(an_packet->id == packet_id_boot_mode && an_packet->length == 1)
00089 {
00090 boot_mode_packet->boot_mode = an_packet->data[0];
00091 return 0;
00092 }
00093 else return 1;
00094 }
00095
00096 an_packet_t *encode_boot_mode_packet(boot_mode_packet_t *boot_mode_packet)
00097 {
00098 an_packet_t *an_packet = an_packet_allocate(1, packet_id_boot_mode);
00099 an_packet->data[0] = boot_mode_packet->boot_mode;
00100 return an_packet;
00101 }
00102
00103 int decode_device_information_packet(device_information_packet_t *device_information_packet, an_packet_t *an_packet)
00104 {
00105 if(an_packet->id == packet_id_device_information && an_packet->length == 24)
00106 {
00107 memcpy(&device_information_packet->software_version, &an_packet->data[0], sizeof(uint32_t));
00108 memcpy(&device_information_packet->device_id, &an_packet->data[4], sizeof(uint32_t));
00109 memcpy(&device_information_packet->hardware_revision, &an_packet->data[8], sizeof(uint32_t));
00110 memcpy(&device_information_packet->serial_number[0], &an_packet->data[12], 3*sizeof(uint32_t));
00111 return 0;
00112 }
00113 else return 1;
00114 }
00115
00116 an_packet_t *encode_restore_factory_settings_packet()
00117 {
00118 uint32_t verification = 0x85429E1C;
00119 an_packet_t *an_packet = an_packet_allocate(4, packet_id_restore_factory_settings);
00120 memcpy(&an_packet->data[0], &verification, sizeof(uint32_t));
00121 return an_packet;
00122 }
00123
00124 an_packet_t *encode_reset_packet()
00125 {
00126 uint32_t verification = 0x21057A7E;
00127 an_packet_t *an_packet = an_packet_allocate(4, packet_id_reset);
00128 memcpy(&an_packet->data[0], &verification, sizeof(uint32_t));
00129 return an_packet;
00130 }
00131
00132 int decode_system_state_packet(system_state_packet_t *system_state_packet, an_packet_t *an_packet)
00133 {
00134 if(an_packet->id == packet_id_system_state && an_packet->length == 100)
00135 {
00136 memcpy(&system_state_packet->system_status, &an_packet->data[0], sizeof(uint16_t));
00137 memcpy(&system_state_packet->filter_status, &an_packet->data[2], sizeof(uint16_t));
00138 memcpy(&system_state_packet->unix_time_seconds, &an_packet->data[4], sizeof(uint32_t));
00139 memcpy(&system_state_packet->microseconds, &an_packet->data[8], sizeof(uint32_t));
00140 memcpy(&system_state_packet->latitude, &an_packet->data[12], sizeof(double));
00141 memcpy(&system_state_packet->longitude, &an_packet->data[20], sizeof(double));
00142 memcpy(&system_state_packet->height, &an_packet->data[28], sizeof(double));
00143 memcpy(&system_state_packet->velocity[0], &an_packet->data[36], 3 * sizeof(float));
00144 memcpy(&system_state_packet->body_acceleration[0], &an_packet->data[48], 3 * sizeof(float));
00145 memcpy(&system_state_packet->g_force, &an_packet->data[60], sizeof(float));
00146 memcpy(&system_state_packet->orientation[0], &an_packet->data[64], 3 * sizeof(float));
00147 memcpy(&system_state_packet->angular_velocity[0], &an_packet->data[76], 3 * sizeof(float));
00148 memcpy(&system_state_packet->standard_deviation[0], &an_packet->data[88], 3 * sizeof(float));
00149 return 0;
00150 }
00151 else return 1;
00152 }
00153
00154 int decode_unix_time_packet(unix_time_packet_t *unix_time_packet, an_packet_t *an_packet)
00155 {
00156 if(an_packet->id == packet_id_unix_time && an_packet->length == 8)
00157 {
00158 memcpy(&unix_time_packet->unix_time_seconds, &an_packet->data[0], sizeof(uint32_t));
00159 memcpy(&unix_time_packet->microseconds, &an_packet->data[4], sizeof(uint32_t));
00160 return 0;
00161 }
00162 else return 1;
00163 }
00164
00165 int decode_formatted_time_packet(formatted_time_packet_t *formatted_time_packet, an_packet_t *an_packet)
00166 {
00167 if(an_packet->id == packet_id_formatted_time && an_packet->length == 14)
00168 {
00169 memcpy(&formatted_time_packet->microseconds, &an_packet->data[0], sizeof(uint32_t));
00170 memcpy(&formatted_time_packet->year, &an_packet->data[4], sizeof(uint16_t));
00171 memcpy(&formatted_time_packet->year_day, &an_packet->data[6], sizeof(uint16_t));
00172 formatted_time_packet->month = an_packet->data[8];
00173 formatted_time_packet->month_day = an_packet->data[9];
00174 formatted_time_packet->week_day = an_packet->data[10];
00175 formatted_time_packet->hour = an_packet->data[11];
00176 formatted_time_packet->minute = an_packet->data[12];
00177 formatted_time_packet->second = an_packet->data[13];
00178 return 0;
00179 }
00180 else return 1;
00181 }
00182
00183 int decode_status_packet(status_packet_t *status_packet, an_packet_t *an_packet)
00184 {
00185 if(an_packet->id == packet_id_status && an_packet->length == 4)
00186 {
00187 memcpy(&status_packet->system_status, &an_packet->data[0], sizeof(uint16_t));
00188 memcpy(&status_packet->filter_status, &an_packet->data[2], sizeof(uint16_t));
00189 return 0;
00190 }
00191 else return 1;
00192 }
00193
00194 int decode_position_standard_deviation_packet(position_standard_deviation_packet_t *position_standard_deviation_packet, an_packet_t *an_packet)
00195 {
00196 if(an_packet->id == packet_id_position_standard_deviation && an_packet->length == 12)
00197 {
00198 memcpy(&position_standard_deviation_packet->standard_deviation[0], &an_packet->data[0], 3*sizeof(float));
00199 return 0;
00200 }
00201 else return 1;
00202 }
00203
00204 int decode_velocity_standard_deviation_packet(velocity_standard_deviation_packet_t *velocity_standard_deviation_packet, an_packet_t *an_packet)
00205 {
00206 if(an_packet->id == packet_id_velocity_standard_deviation && an_packet->length == 12)
00207 {
00208 memcpy(&velocity_standard_deviation_packet->standard_deviation[0], &an_packet->data[0], 3*sizeof(float));
00209 return 0;
00210 }
00211 else return 1;
00212 }
00213
00214 int decode_euler_orientation_standard_deviation_packet(euler_orientation_standard_deviation_packet_t *euler_orientation_standard_deviation, an_packet_t *an_packet)
00215 {
00216 if(an_packet->id == packet_id_euler_orientation_standard_deviation && an_packet->length == 12)
00217 {
00218 memcpy(&euler_orientation_standard_deviation->standard_deviation[0], &an_packet->data[0], 3*sizeof(float));
00219 return 0;
00220 }
00221 else return 1;
00222 }
00223
00224 int decode_quaternion_orientation_standard_deviation_packet(quaternion_orientation_standard_deviation_packet_t *quaternion_orientation_standard_deviation_packet, an_packet_t *an_packet)
00225 {
00226 if(an_packet->id == packet_id_quaternion_orientation_standard_deviation && an_packet->length == 16)
00227 {
00228 memcpy(&quaternion_orientation_standard_deviation_packet->standard_deviation[0], &an_packet->data[0], 4*sizeof(float));
00229 return 0;
00230 }
00231 else return 1;
00232 }
00233
00234 int decode_raw_sensors_packet(raw_sensors_packet_t *raw_sensors_packet, an_packet_t *an_packet)
00235 {
00236 if(an_packet->id == packet_id_raw_sensors && an_packet->length == 48)
00237 {
00238 memcpy(&raw_sensors_packet->accelerometers[0], &an_packet->data[0], 3 * sizeof(float));
00239 memcpy(&raw_sensors_packet->gyroscopes[0], &an_packet->data[12], 3 * sizeof(float));
00240 memcpy(&raw_sensors_packet->magnetometers[0], &an_packet->data[24], 3 * sizeof(float));
00241 memcpy(&raw_sensors_packet->imu_temperature, &an_packet->data[36], sizeof(float));
00242 memcpy(&raw_sensors_packet->pressure, &an_packet->data[40], sizeof(float));
00243 memcpy(&raw_sensors_packet->pressure_temperature, &an_packet->data[44], sizeof(float));
00244 return 0;
00245 }
00246 else return 1;
00247 }
00248
00249 int decode_raw_gnss_packet(raw_gnss_packet_t *raw_gnss_packet, an_packet_t *an_packet)
00250 {
00251 if(an_packet->id == packet_id_raw_gnss && an_packet->length == 36)
00252 {
00253 memcpy(&raw_gnss_packet->position[0], &an_packet->data[0], 3*sizeof(double));
00254 memcpy(&raw_gnss_packet->velocity[0], &an_packet->data[24], 3*sizeof(float));
00255 return 0;
00256 }
00257 else return 1;
00258 }
00259
00260 int decode_satellites_packet(satellites_packet_t *satellites_packet, an_packet_t *an_packet)
00261 {
00262 if(an_packet->id == packet_id_satellites && an_packet->length == 13)
00263 {
00264 memcpy(&satellites_packet->hdop, &an_packet->data[0], sizeof(float));
00265 memcpy(&satellites_packet->vdop, &an_packet->data[4], sizeof(float));
00266 memcpy(&satellites_packet->gps_satellites, &an_packet->data[8], 5*sizeof(uint8_t));
00267 return 0;
00268 }
00269 else return 1;
00270 }
00271
00272 int decode_detailed_satellites_packet(detailed_satellites_packet_t *detailed_satellites_packet, an_packet_t *an_packet)
00273 {
00274 if(an_packet->id == packet_id_satellites_detailed && (an_packet->length % 7) == 0)
00275 {
00276 int number_of_satellites = an_packet->length / 7;
00277 int i;
00278 for(i = 0; i < MAXIMUM_DETAILED_SATELLITES; i++)
00279 {
00280 if(i < number_of_satellites)
00281 {
00282 detailed_satellites_packet->satellites[i].satellite_system = an_packet->data[7*i];
00283 detailed_satellites_packet->satellites[i].number = an_packet->data[7*i + 1];
00284 detailed_satellites_packet->satellites[i].frequency = an_packet->data[7*i + 2];
00285 detailed_satellites_packet->satellites[i].elevation = an_packet->data[7*i + 3];
00286 memcpy(&detailed_satellites_packet->satellites[i].azimuth, &an_packet->data[7*i + 4], sizeof(uint16_t));
00287 detailed_satellites_packet->satellites[i].snr = an_packet->data[7*i + 6];
00288 }
00289 else memset(&detailed_satellites_packet->satellites[i], 0, sizeof(satellite_t));
00290 }
00291 return 0;
00292 }
00293 else return 1;
00294 }
00295
00296 int decode_geodetic_position_packet(geodetic_position_packet_t *geodetic_position_packet, an_packet_t *an_packet)
00297 {
00298 if(an_packet->id == packet_id_geodetic_position && an_packet->length == 24)
00299 {
00300 memcpy(&geodetic_position_packet->position[0], &an_packet->data[0], 3*sizeof(double));
00301 return 0;
00302 }
00303 else return 1;
00304 }
00305
00306 int decode_ecef_position_packet(ecef_position_packet_t *ecef_position_packet, an_packet_t *an_packet)
00307 {
00308 if(an_packet->id == packet_id_ecef_position && an_packet->length == 24)
00309 {
00310 memcpy(&ecef_position_packet->position[0], &an_packet->data[0], 3*sizeof(double));
00311 return 0;
00312 }
00313 else return 1;
00314 }
00315
00316 int decode_utm_position_packet(utm_position_packet_t *utm_position_packet, an_packet_t *an_packet)
00317 {
00318 if(an_packet->id == packet_id_utm_position && an_packet->length == 25)
00319 {
00320 memcpy(&utm_position_packet->position, &an_packet->data[0], 3*sizeof(double));
00321 utm_position_packet->zone = an_packet->data[24];
00322 return 0;
00323 }
00324 else return 1;
00325 }
00326
00327 int decode_ned_velocity_packet(ned_velocity_packet_t *ned_velocity_packet, an_packet_t *an_packet)
00328 {
00329 if(an_packet->id == packet_id_ned_velocity && an_packet->length == 12)
00330 {
00331 memcpy(&ned_velocity_packet->velocity, &an_packet->data[0], 3*sizeof(float));
00332 return 0;
00333 }
00334 else return 1;
00335 }
00336
00337 int decode_body_velocity_packet(body_velocity_packet_t *body_velocity_packet, an_packet_t *an_packet)
00338 {
00339 if(an_packet->id == packet_id_body_velocity && an_packet->length == 12)
00340 {
00341 memcpy(&body_velocity_packet->velocity, &an_packet->data[0], 3*sizeof(float));
00342 return 0;
00343 }
00344 else return 1;
00345 }
00346
00347 int decode_acceleration_packet(acceleration_packet_t *acceleration, an_packet_t *an_packet)
00348 {
00349 if(an_packet->id == packet_id_acceleration && an_packet->length == 12)
00350 {
00351 memcpy(&acceleration->acceleration[0], &an_packet->data[0], 3*sizeof(float));
00352 return 0;
00353 }
00354 else return 1;
00355 }
00356
00357 int decode_body_acceleration_packet(body_acceleration_packet_t *body_acceleration, an_packet_t *an_packet)
00358 {
00359 if(an_packet->id == packet_id_body_acceleration && an_packet->length == 16)
00360 {
00361 memcpy(&body_acceleration->acceleration[0], &an_packet->data[0], 3*sizeof(float));
00362 memcpy(&body_acceleration->g_force, &an_packet->data[12], sizeof(float));
00363 return 0;
00364 }
00365 else return 1;
00366 }
00367
00368 int decode_euler_orientation_packet(euler_orientation_packet_t *euler_orientation_packet, an_packet_t *an_packet)
00369 {
00370 if(an_packet->id == packet_id_euler_orientation && an_packet->length == 12)
00371 {
00372 memcpy(&euler_orientation_packet->orientation[0], &an_packet->data[0], 3*sizeof(float));
00373 return 0;
00374 }
00375 else return 1;
00376 }
00377
00378 int decode_quaternion_orientation_packet(quaternion_orientation_packet_t *quaternion_orientation_packet, an_packet_t *an_packet)
00379 {
00380 if(an_packet->id == packet_id_quaternion_orientation && an_packet->length == 16)
00381 {
00382 memcpy(&quaternion_orientation_packet->orientation[0], &an_packet->data[0], 4*sizeof(float));
00383 return 0;
00384 }
00385 else return 1;
00386 }
00387
00388 int decode_dcm_orientation_packet(dcm_orientation_packet_t *dcm_orientation_packet, an_packet_t *an_packet)
00389 {
00390 if(an_packet->id == packet_id_dcm_orientation && an_packet->length == 36)
00391 {
00392 memcpy(&dcm_orientation_packet->orientation[0][0], &an_packet->data[0], 9*sizeof(float));
00393 return 0;
00394 }
00395 else return 1;
00396 }
00397
00398 int decode_angular_velocity_packet(angular_velocity_packet_t *angular_velocity_packet, an_packet_t *an_packet)
00399 {
00400 if(an_packet->id == packet_id_angular_velocity && an_packet->length == 12)
00401 {
00402 memcpy(&angular_velocity_packet->angular_velocity[0], &an_packet->data[0], 3*sizeof(float));
00403 return 0;
00404 }
00405 else return 1;
00406 }
00407
00408 int decode_angular_acceleration_packet(angular_acceleration_packet_t *angular_acceleration_packet, an_packet_t *an_packet)
00409 {
00410 if(an_packet->id == packet_id_angular_acceleration && an_packet->length == 12)
00411 {
00412 memcpy(&angular_acceleration_packet->angular_acceleration[0], &an_packet->data[0], 3*sizeof(float));
00413 return 0;
00414 }
00415 else return 1;
00416 }
00417
00418 int decode_external_position_velocity_packet(external_position_velocity_packet_t *external_position_velocity_packet, an_packet_t *an_packet)
00419 {
00420 if(an_packet->id == packet_id_external_position_velocity && an_packet->length == 60)
00421 {
00422 memcpy(&external_position_velocity_packet->position[0], &an_packet->data[0], 3*sizeof(double));
00423 memcpy(&external_position_velocity_packet->velocity[0], &an_packet->data[24], 3*sizeof(float));
00424 memcpy(&external_position_velocity_packet->position_standard_deviation[0], &an_packet->data[36], 3*sizeof(float));
00425 memcpy(&external_position_velocity_packet->velocity_standard_deviation[0], &an_packet->data[48], 3*sizeof(float));
00426 return 0;
00427 }
00428 else return 1;
00429 }
00430
00431 an_packet_t *encode_external_position_velocity_packet(external_position_velocity_packet_t *external_position_velocity_packet)
00432 {
00433 an_packet_t *an_packet = an_packet_allocate(60, packet_id_external_position_velocity);
00434 if(an_packet != NULL)
00435 {
00436 memcpy(&an_packet->data[0], &external_position_velocity_packet->position[0], 3*sizeof(double));
00437 memcpy(&an_packet->data[24], &external_position_velocity_packet->velocity[0], 3*sizeof(float));
00438 memcpy(&an_packet->data[36], &external_position_velocity_packet->position_standard_deviation[0], 3*sizeof(float));
00439 memcpy(&an_packet->data[48], &external_position_velocity_packet->velocity_standard_deviation[0], 3*sizeof(float));
00440 }
00441 return an_packet;
00442 }
00443
00444 int decode_external_position_packet(external_position_packet_t *external_position_packet, an_packet_t *an_packet)
00445 {
00446 if(an_packet->id == packet_id_external_position && an_packet->length == 36)
00447 {
00448 memcpy(&external_position_packet->position[0], &an_packet->data[0], 3*sizeof(double));
00449 memcpy(&external_position_packet->standard_deviation[0], &an_packet->data[24], 3*sizeof(float));
00450 return 0;
00451 }
00452 else return 1;
00453 }
00454
00455 an_packet_t *encode_external_position_packet(external_position_packet_t *external_position_packet)
00456 {
00457 an_packet_t *an_packet = an_packet_allocate(36, packet_id_external_position);
00458 if(an_packet != NULL)
00459 {
00460 memcpy(&an_packet->data[0], &external_position_packet->position[0], 3*sizeof(double));
00461 memcpy(&an_packet->data[24], &external_position_packet->standard_deviation[0], 3*sizeof(float));
00462 }
00463 return an_packet;
00464 }
00465
00466 int decode_external_velocity_packet(external_velocity_packet_t *external_velocity_packet, an_packet_t *an_packet)
00467 {
00468 if(an_packet->id == packet_id_external_velocity && an_packet->length == 24)
00469 {
00470 memcpy(&external_velocity_packet->velocity[0], &an_packet->data[0], 3*sizeof(float));
00471 memcpy(&external_velocity_packet->standard_deviation[0], &an_packet->data[12], 3*sizeof(float));
00472 return 0;
00473 }
00474 else return 1;
00475 }
00476
00477 an_packet_t *encode_external_velocity_packet(external_velocity_packet_t *external_velocity_packet)
00478 {
00479 an_packet_t *an_packet = an_packet_allocate(24, packet_id_external_velocity);
00480 if(an_packet != NULL)
00481 {
00482 memcpy(&an_packet->data[0], &external_velocity_packet->velocity[0], 3*sizeof(float));
00483 memcpy(&an_packet->data[12], &external_velocity_packet->standard_deviation[0], 3*sizeof(float));
00484 }
00485 return an_packet;
00486 }
00487
00488 int decode_external_body_velocity_packet(external_body_velocity_packet_t *external_body_velocity_packet, an_packet_t *an_packet)
00489 {
00490 if(an_packet->id == packet_id_external_body_velocity && an_packet->length == 16)
00491 {
00492 memcpy(&external_body_velocity_packet->velocity, &an_packet->data[0], 3*sizeof(float));
00493 memcpy(&external_body_velocity_packet->standard_deviation, &an_packet->data[12], sizeof(float));
00494 return 0;
00495 }
00496 else return 1;
00497 }
00498
00499 an_packet_t *encode_external_body_velocity_packet(external_body_velocity_packet_t *external_body_velocity_packet)
00500 {
00501 an_packet_t *an_packet = an_packet_allocate(16, packet_id_external_body_velocity);
00502 if(an_packet != NULL)
00503 {
00504 memcpy(&an_packet->data[0], &external_body_velocity_packet->velocity[0], 3*sizeof(float));
00505 memcpy(&an_packet->data[12], &external_body_velocity_packet->standard_deviation, sizeof(float));
00506 }
00507 return an_packet;
00508 }
00509
00510 int decode_external_heading_packet(external_heading_packet_t *external_heading_packet, an_packet_t *an_packet)
00511 {
00512 if(an_packet->id == packet_id_external_heading && an_packet->length == 8)
00513 {
00514 memcpy(&external_heading_packet->heading, &an_packet->data[0], sizeof(float));
00515 memcpy(&external_heading_packet->standard_deviation, &an_packet->data[4], sizeof(float));
00516 return 0;
00517 }
00518 else return 1;
00519 }
00520
00521 an_packet_t *encode_external_heading_packet(external_heading_packet_t *external_heading_packet)
00522 {
00523 an_packet_t *an_packet = an_packet_allocate(8, packet_id_external_heading);
00524 if(an_packet != NULL)
00525 {
00526 memcpy(&an_packet->data[0], &external_heading_packet->heading, sizeof(float));
00527 memcpy(&an_packet->data[4], &external_heading_packet->standard_deviation, sizeof(float));
00528 }
00529 return an_packet;
00530 }
00531
00532 int decode_running_time_packet(running_time_packet_t *running_time_packet, an_packet_t *an_packet)
00533 {
00534 if(an_packet->id == packet_id_running_time && an_packet->length == 8)
00535 {
00536 memcpy(&running_time_packet->seconds, &an_packet->data[0], sizeof(uint32_t));
00537 memcpy(&running_time_packet->microseconds, &an_packet->data[4], sizeof(uint32_t));
00538 return 0;
00539 }
00540 else return 1;
00541 }
00542
00543 int decode_local_magnetics_packet(local_magnetics_packet_t *local_magnetics_packet, an_packet_t *an_packet)
00544 {
00545 if(an_packet->id == packet_id_local_magnetics && an_packet->length == 12)
00546 {
00547 memcpy(&local_magnetics_packet->magnetic_field[0], &an_packet->data[0], 3*sizeof(float));
00548 return 0;
00549 }
00550 else return 1;
00551 }
00552
00553 int decode_odometer_state_packet(odometer_state_packet_t *odometer_state_packet, an_packet_t *an_packet)
00554 {
00555 if(an_packet->id == packet_id_odometer_state && an_packet->length == 20)
00556 {
00557 memcpy(&odometer_state_packet->pulse_count, &an_packet->data[0], sizeof(uint32_t));
00558 memcpy(&odometer_state_packet->distance, &an_packet->data[4], sizeof(float));
00559 memcpy(&odometer_state_packet->speed, &an_packet->data[8], sizeof(float));
00560 memcpy(&odometer_state_packet->slip, &an_packet->data[12], sizeof(float));
00561 odometer_state_packet->active = an_packet->data[16];
00562 return 0;
00563 }
00564 else return 1;
00565 }
00566
00567 int decode_external_time_packet(external_time_packet_t *external_time_packet, an_packet_t *an_packet)
00568 {
00569 if(an_packet->id == packet_id_external_time && an_packet->length == 8)
00570 {
00571 memcpy(&external_time_packet->unix_time_seconds, &an_packet->data[0], sizeof(float));
00572 memcpy(&external_time_packet->microseconds, &an_packet->data[4], sizeof(float));
00573 return 0;
00574 }
00575 else return 1;
00576 }
00577
00578 an_packet_t *encode_external_time_packet(external_time_packet_t *external_time_packet)
00579 {
00580 an_packet_t *an_packet = an_packet_allocate(8, packet_id_external_time);
00581 if(an_packet != NULL)
00582 {
00583 memcpy(&an_packet->data[0], &external_time_packet->unix_time_seconds, sizeof(float));
00584 memcpy(&an_packet->data[4], &external_time_packet->microseconds, sizeof(float));
00585 }
00586 return an_packet;
00587 }
00588
00589 int decode_external_depth_packet(external_depth_packet_t *external_depth_packet, an_packet_t *an_packet)
00590 {
00591 if(an_packet->id == packet_id_external_depth && an_packet->length == 8)
00592 {
00593 memcpy(&external_depth_packet->depth, &an_packet->data[0], sizeof(float));
00594 memcpy(&external_depth_packet->standard_deviation, &an_packet->data[4], sizeof(float));
00595 return 0;
00596 }
00597 else return 1;
00598 }
00599
00600 an_packet_t *encode_external_depth_packet(external_depth_packet_t *external_depth_packet)
00601 {
00602 an_packet_t *an_packet = an_packet_allocate(8, packet_id_external_depth);
00603 if(an_packet != NULL)
00604 {
00605 memcpy(&an_packet->data[0], &external_depth_packet->depth, sizeof(float));
00606 memcpy(&an_packet->data[4], &external_depth_packet->standard_deviation, sizeof(float));
00607 }
00608 return an_packet;
00609 }
00610
00611 int decode_geoid_height_packet(geoid_height_packet_t *geoid_height_packet, an_packet_t *an_packet)
00612 {
00613 if(an_packet->id == packet_id_geoid_height && an_packet->length == 4)
00614 {
00615 memcpy(&geoid_height_packet->geoid_height, &an_packet->data[0], sizeof(float));
00616 return 0;
00617 }
00618 else return 1;
00619 }
00620
00621 int decode_external_pitot_pressure_packet(external_pitot_pressure_packet_t *external_pitot_pressure_packet, an_packet_t *an_packet)
00622 {
00623 if(an_packet->id == packet_id_external_pitot_pressure && an_packet->length == 8)
00624 {
00625 memcpy(&external_pitot_pressure_packet->differential_pressure, &an_packet->data[0], sizeof(float));
00626 memcpy(&external_pitot_pressure_packet->outside_air_temperature, &an_packet->data[4], sizeof(float));
00627 return 0;
00628 }
00629 else return 1;
00630 }
00631
00632 an_packet_t *encode_external_pitot_pressure_packet(external_pitot_pressure_packet_t *external_pitot_pressure_packet)
00633 {
00634 an_packet_t *an_packet = an_packet_allocate(8, packet_id_external_pitot_pressure);
00635 if(an_packet != NULL)
00636 {
00637 memcpy(&an_packet->data[0], &external_pitot_pressure_packet->differential_pressure, sizeof(float));
00638 memcpy(&an_packet->data[4], &external_pitot_pressure_packet->outside_air_temperature, sizeof(float));
00639 }
00640 return an_packet;
00641 }
00642
00643 int decode_wind_estimation_packet(wind_estimation_packet_t *wind_estimation_packet, an_packet_t *an_packet)
00644 {
00645 if(an_packet->id == packet_id_wind_estimation && an_packet->length == 12)
00646 {
00647 memcpy(&wind_estimation_packet->wind_velocity[0], &an_packet->data[0], 3*sizeof(float));
00648 return 0;
00649 }
00650 else return 1;
00651 }
00652
00653 int decode_heave_packet(heave_packet_t *heave_packet, an_packet_t *an_packet)
00654 {
00655 if(an_packet->id == packet_id_heave && an_packet->length == 16)
00656 {
00657 memcpy(&heave_packet->heave_point_1, &an_packet->data[0], sizeof(float));
00658 memcpy(&heave_packet->heave_point_2, &an_packet->data[4], sizeof(float));
00659 memcpy(&heave_packet->heave_point_3, &an_packet->data[8], sizeof(float));
00660 memcpy(&heave_packet->heave_point_4, &an_packet->data[12], sizeof(float));
00661 return 0;
00662 }
00663 else return 1;
00664 }
00665
00666 int decode_packet_timer_period_packet(packet_timer_period_packet_t *packet_timer_period_packet, an_packet_t *an_packet)
00667 {
00668 if(an_packet->id == packet_id_packet_timer_period && an_packet->length == 4)
00669 {
00670 packet_timer_period_packet->permanent = an_packet->data[0];
00671 packet_timer_period_packet->utc_synchronisation = an_packet->data[1];
00672 memcpy(&packet_timer_period_packet->packet_timer_period, &an_packet->data[2], sizeof(uint16_t));
00673 return 0;
00674 }
00675 else return 1;
00676 }
00677
00678 an_packet_t *encode_packet_timer_period_packet(packet_timer_period_packet_t *packet_timer_period_packet)
00679 {
00680 an_packet_t *an_packet = an_packet_allocate(4, packet_id_packet_timer_period);
00681 if(an_packet != NULL)
00682 {
00683 an_packet->data[0] = packet_timer_period_packet->permanent > 0;
00684 an_packet->data[1] = packet_timer_period_packet->utc_synchronisation > 0;
00685 memcpy(&an_packet->data[2], &packet_timer_period_packet->packet_timer_period, sizeof(uint16_t));
00686 }
00687 return an_packet;
00688 }
00689
00690 int decode_packet_periods_packet(packet_periods_packet_t *packet_periods_packet, an_packet_t *an_packet)
00691 {
00692 if(an_packet->id == packet_id_packet_periods && (an_packet->length - 2) % 5 == 0)
00693 {
00694 int i;
00695 int packet_periods_count = (an_packet->length - 2) / 5;
00696 packet_periods_packet->permanent = an_packet->data[0];
00697 packet_periods_packet->clear_existing_packets = an_packet->data[1];
00698 for(i = 0; i < MAXIMUM_PACKET_PERIODS; i++)
00699 {
00700 if(i < packet_periods_count)
00701 {
00702 packet_periods_packet->packet_periods[i].packet_id = an_packet->data[2 + 5*i];
00703 memcpy(&packet_periods_packet->packet_periods[i].period, &an_packet->data[2 + 5*i + 1], sizeof(uint32_t));
00704 }
00705 else memset(&packet_periods_packet->packet_periods[i], 0, sizeof(packet_period_t));
00706 }
00707 return 0;
00708 }
00709 else return 1;
00710 }
00711
00712 an_packet_t *encode_packet_periods_packet(packet_periods_packet_t *packet_periods_packet)
00713 {
00714 int i;
00715 an_packet_t *an_packet = an_packet_allocate(252, packet_id_packet_periods);
00716 if(an_packet != NULL)
00717 {
00718 an_packet->data[0] = packet_periods_packet->permanent > 0;
00719 an_packet->data[1] = packet_periods_packet->clear_existing_packets;
00720 for(i = 0; i < MAXIMUM_PACKET_PERIODS; i++)
00721 {
00722 if(packet_periods_packet->packet_periods[i].packet_id)
00723 {
00724 an_packet->data[2 + 5*i] = packet_periods_packet->packet_periods[i].packet_id;
00725 memcpy(&an_packet->data[2 + 5*i + 1], &packet_periods_packet->packet_periods[i].period, sizeof(uint32_t));
00726 }
00727 else break;
00728 }
00729 an_packet->length = 2 + 5*i;
00730 }
00731 return an_packet;
00732 }
00733
00734 int decode_baud_rates_packet(baud_rates_packet_t *baud_rates_packet, an_packet_t *an_packet)
00735 {
00736 if(an_packet->id == packet_id_baud_rates && an_packet->length == 17)
00737 {
00738 baud_rates_packet->permanent = an_packet->data[0];
00739 memcpy(&baud_rates_packet->primary_baud_rate, &an_packet->data[1], sizeof(uint32_t));
00740 memcpy(&baud_rates_packet->gpio_1_2_baud_rate, &an_packet->data[5], sizeof(uint32_t));
00741 memcpy(&baud_rates_packet->gpio_3_4_baud_rate, &an_packet->data[9], sizeof(uint32_t));
00742 memcpy(&baud_rates_packet->reserved, &an_packet->data[13], sizeof(uint32_t));
00743 return 0;
00744 }
00745 else return 1;
00746 }
00747
00748 an_packet_t *encode_baud_rates_packet(baud_rates_packet_t *baud_rates_packet)
00749 {
00750 an_packet_t *an_packet = an_packet_allocate(17, packet_id_baud_rates);
00751 if(an_packet != NULL)
00752 {
00753 an_packet->data[0] = baud_rates_packet->permanent;
00754 memcpy(&an_packet->data[1], &baud_rates_packet->primary_baud_rate, sizeof(uint32_t));
00755 memcpy(&an_packet->data[5], &baud_rates_packet->gpio_1_2_baud_rate, sizeof(uint32_t));
00756 memcpy(&an_packet->data[9], &baud_rates_packet->gpio_3_4_baud_rate, sizeof(uint32_t));
00757 memcpy(&an_packet->data[13], &baud_rates_packet->reserved, sizeof(uint32_t));
00758 }
00759 return an_packet;
00760 }
00761
00762 int decode_sensor_ranges_packet(sensor_ranges_packet_t *sensor_ranges_packet, an_packet_t *an_packet)
00763 {
00764 if(an_packet->id == packet_id_sensor_ranges && an_packet->length == 4)
00765 {
00766 memcpy(sensor_ranges_packet, an_packet->data, 4*sizeof(uint8_t));
00767 return 0;
00768 }
00769 else return 1;
00770 }
00771
00772 an_packet_t *encode_sensor_ranges_packet(sensor_ranges_packet_t *sensor_ranges_packet)
00773 {
00774 an_packet_t *an_packet = an_packet_allocate(4, packet_id_sensor_ranges);
00775 if(an_packet != NULL)
00776 {
00777 memcpy(an_packet->data, sensor_ranges_packet, 4*sizeof(uint8_t));
00778 }
00779 return an_packet;
00780 }
00781
00782 int decode_installation_alignment_packet(installation_alignment_packet_t *installation_alignment_packet, an_packet_t *an_packet)
00783 {
00784 if(an_packet->id == packet_id_installation_alignment && an_packet->length == 73)
00785 {
00786 installation_alignment_packet->permanent = an_packet->data[0];
00787 memcpy(&installation_alignment_packet->alignment_dcm[0][0], &an_packet->data[1], 9*sizeof(float));
00788 memcpy(&installation_alignment_packet->gnss_antenna_offset[0], &an_packet->data[37], 3*sizeof(float));
00789 memcpy(&installation_alignment_packet->odometer_offset[0], &an_packet->data[49], 3*sizeof(float));
00790 memcpy(&installation_alignment_packet->external_data_offset[0], &an_packet->data[61], 3*sizeof(float));
00791 return 0;
00792 }
00793 else return 1;
00794 }
00795
00796 an_packet_t *encode_installation_alignment_packet(installation_alignment_packet_t *installation_alignment_packet)
00797 {
00798 an_packet_t *an_packet = an_packet_allocate(73, packet_id_installation_alignment);
00799 if(an_packet != NULL)
00800 {
00801 an_packet->data[0] = installation_alignment_packet->permanent;
00802 memcpy(&an_packet->data[1], &installation_alignment_packet->alignment_dcm[0][0], 9*sizeof(float));
00803 memcpy(&an_packet->data[37], &installation_alignment_packet->gnss_antenna_offset[0], 3*sizeof(float));
00804 memcpy(&an_packet->data[49], &installation_alignment_packet->odometer_offset[0], 3*sizeof(float));
00805 memcpy(&an_packet->data[61], &installation_alignment_packet->external_data_offset[0], 3*sizeof(float));
00806 }
00807 return an_packet;
00808 }
00809
00810 int decode_filter_options_packet(filter_options_packet_t *filter_options_packet, an_packet_t *an_packet)
00811 {
00812 if(an_packet->id == packet_id_filter_options && an_packet->length == 17)
00813 {
00814 memcpy(filter_options_packet, &an_packet->data[0], 6*sizeof(uint8_t));
00815 return 0;
00816 }
00817 else return 1;
00818 }
00819
00820 an_packet_t *encode_filter_options_packet(filter_options_packet_t *filter_options_packet)
00821 {
00822 an_packet_t *an_packet = an_packet_allocate(17, packet_id_filter_options);
00823 if(an_packet != NULL)
00824 {
00825 memcpy(&an_packet->data[0], filter_options_packet, 6*sizeof(uint8_t));
00826 memset(&an_packet->data[6], 0, 11*sizeof(uint8_t));
00827 }
00828 return an_packet;
00829 }
00830
00831 int decode_gpio_configuration_packet(gpio_configuration_packet_t *gpio_configuration_packet, an_packet_t *an_packet)
00832 {
00833 if(an_packet->id == packet_id_gpio_configuration && an_packet->length == 13)
00834 {
00835 memcpy(gpio_configuration_packet, &an_packet->data[0], 5*sizeof(uint8_t));
00836 return 0;
00837 }
00838 else return 1;
00839 }
00840
00841 an_packet_t *encode_gpio_configuration_packet(gpio_configuration_packet_t *gpio_configuration_packet)
00842 {
00843 an_packet_t *an_packet = an_packet_allocate(13, packet_id_gpio_configuration);
00844 if(an_packet != NULL)
00845 {
00846 memcpy(&an_packet->data[0], gpio_configuration_packet, 5*sizeof(uint8_t));
00847 memset(&an_packet->data[5], 0, 8*sizeof(uint8_t));
00848 }
00849 return an_packet;
00850 }
00851
00852 int decode_magnetic_calibration_values_packet(magnetic_calibration_values_packet_t *magnetic_calibration_values_packet, an_packet_t *an_packet)
00853 {
00854 if(an_packet->id == packet_id_magnetic_calibration_values && an_packet->length == 49)
00855 {
00856 magnetic_calibration_values_packet->permanent = an_packet->data[0];
00857 memcpy(magnetic_calibration_values_packet->hard_iron, &an_packet->data[5], 3*sizeof(float));
00858 memcpy(magnetic_calibration_values_packet->soft_iron, &an_packet->data[13], 9*sizeof(float));
00859 return 0;
00860 }
00861 else return 1;
00862 }
00863
00864 an_packet_t *encode_magnetic_calibration_values_packet(magnetic_calibration_values_packet_t *magnetic_calibration_values_packet)
00865 {
00866 an_packet_t *an_packet = an_packet_allocate(49, packet_id_magnetic_calibration_values);
00867 if(an_packet != NULL)
00868 {
00869 an_packet->data[0] = magnetic_calibration_values_packet->permanent;
00870 memcpy(&an_packet->data[1], magnetic_calibration_values_packet->hard_iron, 3*sizeof(float));
00871 memcpy(&an_packet->data[13], magnetic_calibration_values_packet->soft_iron, 9*sizeof(float));
00872 }
00873 return an_packet;
00874 }
00875
00876 an_packet_t *encode_magnetic_calibration_configuration_packet(magnetic_calibration_configuration_packet_t *magnetic_calibration_configuration_packet)
00877 {
00878 an_packet_t *an_packet = an_packet_allocate(1, packet_id_magnetic_calibration_configuration);
00879 if(an_packet != NULL)
00880 {
00881 an_packet->data[0] = magnetic_calibration_configuration_packet->magnetic_calibration_action;
00882 }
00883 return an_packet;
00884 }
00885
00886 int decode_magnetic_calibration_status_packet(magnetic_calibration_status_packet_t *magnetic_calibration_status_packet, an_packet_t *an_packet)
00887 {
00888 if(an_packet->id == packet_id_magnetic_calibration_status && an_packet->length == 3)
00889 {
00890 magnetic_calibration_status_packet->magnetic_calibration_status = an_packet->data[0];
00891 magnetic_calibration_status_packet->magnetic_calibration_progress_percentage = an_packet->data[1];
00892 magnetic_calibration_status_packet->local_magnetic_error_percentage = an_packet->data[2];
00893 return 0;
00894 }
00895 return 1;
00896 }
00897
00898 int decode_odometer_configuration_packet(odometer_configuration_packet_t *odometer_configuration_packet, an_packet_t *an_packet)
00899 {
00900 if(an_packet->id == packet_id_odometer_configuration && an_packet->length == 8)
00901 {
00902 odometer_configuration_packet->permanent = an_packet->data[0];
00903 odometer_configuration_packet->automatic_calibration = an_packet->data[1];
00904 memcpy(&odometer_configuration_packet->pulse_length, &an_packet->data[4], sizeof(float));
00905 return 0;
00906 }
00907 else return 1;
00908 }
00909
00910 an_packet_t *encode_odometer_configuration_packet(odometer_configuration_packet_t *odometer_configuration_packet)
00911 {
00912 an_packet_t *an_packet = an_packet_allocate(8, packet_id_odometer_configuration);
00913 if(an_packet != NULL)
00914 {
00915 an_packet->data[0] = odometer_configuration_packet->permanent;
00916 an_packet->data[1] = odometer_configuration_packet->automatic_calibration;
00917 memset(&an_packet->data[2], 0, 2*sizeof(uint8_t));
00918 memcpy(&an_packet->data[4], &odometer_configuration_packet->pulse_length, sizeof(float));
00919 }
00920 return an_packet;
00921 }
00922
00923 an_packet_t *encode_zero_alignment_packet(zero_alignment_packet_t *zero_alignment_packet)
00924 {
00925 an_packet_t *an_packet = an_packet_allocate(1, packet_id_zero_alignment);
00926 if(an_packet != NULL)
00927 {
00928 an_packet->data[0] = zero_alignment_packet->permanent;
00929 }
00930 return an_packet;
00931 }
00932
00933 int decode_heave_offset_packet(heave_offset_packet_t *heave_offset_packet, an_packet_t *an_packet)
00934 {
00935 if(an_packet->id == packet_id_heave_offset && an_packet->length == 49)
00936 {
00937 heave_offset_packet->permanent = an_packet->data[0];
00938 memcpy(&heave_offset_packet->heave_point_1_offset[0], &an_packet->data[1], 3*sizeof(float));
00939 memcpy(&heave_offset_packet->heave_point_2_offset[0], &an_packet->data[13], 3*sizeof(float));
00940 memcpy(&heave_offset_packet->heave_point_3_offset[0], &an_packet->data[25], 3*sizeof(float));
00941 memcpy(&heave_offset_packet->heave_point_4_offset[0], &an_packet->data[37], 3*sizeof(float));
00942 return 0;
00943 }
00944 else return 1;
00945 }
00946
00947 an_packet_t *encode_heave_offset_packet(heave_offset_packet_t *heave_offset_packet)
00948 {
00949 an_packet_t *an_packet = an_packet_allocate(49, packet_id_odometer_configuration);
00950 if(an_packet != NULL)
00951 {
00952 an_packet->data[0] = heave_offset_packet->permanent;
00953 memcpy(&an_packet->data[1], &heave_offset_packet->heave_point_1_offset[0], 3*sizeof(float));
00954 memcpy(&an_packet->data[13], &heave_offset_packet->heave_point_2_offset[0], 3*sizeof(float));
00955 memcpy(&an_packet->data[25], &heave_offset_packet->heave_point_3_offset[0], 3*sizeof(float));
00956 memcpy(&an_packet->data[37], &heave_offset_packet->heave_point_4_offset[0], 3*sizeof(float));
00957 }
00958 return an_packet;
00959 }