00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define IPCON_EXPOSE_INTERNALS
00013
00014 #include "bricklet_gps.h"
00015
00016 #include <string.h>
00017
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021
00022
00023
00024 typedef void (*CoordinatesCallbackFunction)(uint32_t, char, uint32_t, char, uint16_t, uint16_t, uint16_t, uint16_t, void *);
00025
00026 typedef void (*StatusCallbackFunction)(uint8_t, uint8_t, uint8_t, void *);
00027
00028 typedef void (*AltitudeCallbackFunction)(uint32_t, uint32_t, void *);
00029
00030 typedef void (*MotionCallbackFunction)(uint32_t, uint32_t, void *);
00031
00032 typedef void (*DateTimeCallbackFunction)(uint32_t, uint32_t, void *);
00033
00034 #if defined _MSC_VER || defined __BORLANDC__
00035 #pragma pack(push)
00036 #pragma pack(1)
00037 #define ATTRIBUTE_PACKED
00038 #elif defined __GNUC__
00039 #ifdef _WIN32
00040
00041
00042 #define ATTRIBUTE_PACKED __attribute__((gcc_struct, packed))
00043 #else
00044 #define ATTRIBUTE_PACKED __attribute__((packed))
00045 #endif
00046 #else
00047 #error unknown compiler, do not know how to enable struct packing
00048 #endif
00049
00050 typedef struct {
00051 PacketHeader header;
00052 } ATTRIBUTE_PACKED GetCoordinates_;
00053
00054 typedef struct {
00055 PacketHeader header;
00056 uint32_t latitude;
00057 char ns;
00058 uint32_t longitude;
00059 char ew;
00060 uint16_t pdop;
00061 uint16_t hdop;
00062 uint16_t vdop;
00063 uint16_t epe;
00064 } ATTRIBUTE_PACKED GetCoordinatesResponse_;
00065
00066 typedef struct {
00067 PacketHeader header;
00068 } ATTRIBUTE_PACKED GetStatus_;
00069
00070 typedef struct {
00071 PacketHeader header;
00072 uint8_t fix;
00073 uint8_t satellites_view;
00074 uint8_t satellites_used;
00075 } ATTRIBUTE_PACKED GetStatusResponse_;
00076
00077 typedef struct {
00078 PacketHeader header;
00079 } ATTRIBUTE_PACKED GetAltitude_;
00080
00081 typedef struct {
00082 PacketHeader header;
00083 uint32_t altitude;
00084 uint32_t geoidal_separation;
00085 } ATTRIBUTE_PACKED GetAltitudeResponse_;
00086
00087 typedef struct {
00088 PacketHeader header;
00089 } ATTRIBUTE_PACKED GetMotion_;
00090
00091 typedef struct {
00092 PacketHeader header;
00093 uint32_t course;
00094 uint32_t speed;
00095 } ATTRIBUTE_PACKED GetMotionResponse_;
00096
00097 typedef struct {
00098 PacketHeader header;
00099 } ATTRIBUTE_PACKED GetDateTime_;
00100
00101 typedef struct {
00102 PacketHeader header;
00103 uint32_t date;
00104 uint32_t time;
00105 } ATTRIBUTE_PACKED GetDateTimeResponse_;
00106
00107 typedef struct {
00108 PacketHeader header;
00109 uint8_t restart_type;
00110 } ATTRIBUTE_PACKED Restart_;
00111
00112 typedef struct {
00113 PacketHeader header;
00114 uint32_t period;
00115 } ATTRIBUTE_PACKED SetCoordinatesCallbackPeriod_;
00116
00117 typedef struct {
00118 PacketHeader header;
00119 } ATTRIBUTE_PACKED GetCoordinatesCallbackPeriod_;
00120
00121 typedef struct {
00122 PacketHeader header;
00123 uint32_t period;
00124 } ATTRIBUTE_PACKED GetCoordinatesCallbackPeriodResponse_;
00125
00126 typedef struct {
00127 PacketHeader header;
00128 uint32_t period;
00129 } ATTRIBUTE_PACKED SetStatusCallbackPeriod_;
00130
00131 typedef struct {
00132 PacketHeader header;
00133 } ATTRIBUTE_PACKED GetStatusCallbackPeriod_;
00134
00135 typedef struct {
00136 PacketHeader header;
00137 uint32_t period;
00138 } ATTRIBUTE_PACKED GetStatusCallbackPeriodResponse_;
00139
00140 typedef struct {
00141 PacketHeader header;
00142 uint32_t period;
00143 } ATTRIBUTE_PACKED SetAltitudeCallbackPeriod_;
00144
00145 typedef struct {
00146 PacketHeader header;
00147 } ATTRIBUTE_PACKED GetAltitudeCallbackPeriod_;
00148
00149 typedef struct {
00150 PacketHeader header;
00151 uint32_t period;
00152 } ATTRIBUTE_PACKED GetAltitudeCallbackPeriodResponse_;
00153
00154 typedef struct {
00155 PacketHeader header;
00156 uint32_t period;
00157 } ATTRIBUTE_PACKED SetMotionCallbackPeriod_;
00158
00159 typedef struct {
00160 PacketHeader header;
00161 } ATTRIBUTE_PACKED GetMotionCallbackPeriod_;
00162
00163 typedef struct {
00164 PacketHeader header;
00165 uint32_t period;
00166 } ATTRIBUTE_PACKED GetMotionCallbackPeriodResponse_;
00167
00168 typedef struct {
00169 PacketHeader header;
00170 uint32_t period;
00171 } ATTRIBUTE_PACKED SetDateTimeCallbackPeriod_;
00172
00173 typedef struct {
00174 PacketHeader header;
00175 } ATTRIBUTE_PACKED GetDateTimeCallbackPeriod_;
00176
00177 typedef struct {
00178 PacketHeader header;
00179 uint32_t period;
00180 } ATTRIBUTE_PACKED GetDateTimeCallbackPeriodResponse_;
00181
00182 typedef struct {
00183 PacketHeader header;
00184 uint32_t latitude;
00185 char ns;
00186 uint32_t longitude;
00187 char ew;
00188 uint16_t pdop;
00189 uint16_t hdop;
00190 uint16_t vdop;
00191 uint16_t epe;
00192 } ATTRIBUTE_PACKED CoordinatesCallback_;
00193
00194 typedef struct {
00195 PacketHeader header;
00196 uint8_t fix;
00197 uint8_t satellites_view;
00198 uint8_t satellites_used;
00199 } ATTRIBUTE_PACKED StatusCallback_;
00200
00201 typedef struct {
00202 PacketHeader header;
00203 uint32_t altitude;
00204 uint32_t geoidal_separation;
00205 } ATTRIBUTE_PACKED AltitudeCallback_;
00206
00207 typedef struct {
00208 PacketHeader header;
00209 uint32_t course;
00210 uint32_t speed;
00211 } ATTRIBUTE_PACKED MotionCallback_;
00212
00213 typedef struct {
00214 PacketHeader header;
00215 uint32_t date;
00216 uint32_t time;
00217 } ATTRIBUTE_PACKED DateTimeCallback_;
00218
00219 typedef struct {
00220 PacketHeader header;
00221 } ATTRIBUTE_PACKED GetIdentity_;
00222
00223 typedef struct {
00224 PacketHeader header;
00225 char uid[8];
00226 char connected_uid[8];
00227 char position;
00228 uint8_t hardware_version[3];
00229 uint8_t firmware_version[3];
00230 uint16_t device_identifier;
00231 } ATTRIBUTE_PACKED GetIdentityResponse_;
00232
00233 #if defined _MSC_VER || defined __BORLANDC__
00234 #pragma pack(pop)
00235 #endif
00236 #undef ATTRIBUTE_PACKED
00237
00238 static void gps_callback_wrapper_coordinates(DevicePrivate *device_p, Packet *packet) {
00239 CoordinatesCallbackFunction callback_function;
00240 void *user_data = device_p->registered_callback_user_data[GPS_CALLBACK_COORDINATES];
00241 CoordinatesCallback_ *callback = (CoordinatesCallback_ *)packet;
00242 *(void **)(&callback_function) = device_p->registered_callbacks[GPS_CALLBACK_COORDINATES];
00243
00244 if (callback_function == NULL) {
00245 return;
00246 }
00247
00248 callback->latitude = leconvert_uint32_from(callback->latitude);
00249 callback->longitude = leconvert_uint32_from(callback->longitude);
00250 callback->pdop = leconvert_uint16_from(callback->pdop);
00251 callback->hdop = leconvert_uint16_from(callback->hdop);
00252 callback->vdop = leconvert_uint16_from(callback->vdop);
00253 callback->epe = leconvert_uint16_from(callback->epe);
00254
00255 callback_function(callback->latitude, callback->ns, callback->longitude, callback->ew, callback->pdop, callback->hdop, callback->vdop, callback->epe, user_data);
00256 }
00257
00258 static void gps_callback_wrapper_status(DevicePrivate *device_p, Packet *packet) {
00259 StatusCallbackFunction callback_function;
00260 void *user_data = device_p->registered_callback_user_data[GPS_CALLBACK_STATUS];
00261 StatusCallback_ *callback = (StatusCallback_ *)packet;
00262 *(void **)(&callback_function) = device_p->registered_callbacks[GPS_CALLBACK_STATUS];
00263
00264 if (callback_function == NULL) {
00265 return;
00266 }
00267
00268 callback_function(callback->fix, callback->satellites_view, callback->satellites_used, user_data);
00269 }
00270
00271 static void gps_callback_wrapper_altitude(DevicePrivate *device_p, Packet *packet) {
00272 AltitudeCallbackFunction callback_function;
00273 void *user_data = device_p->registered_callback_user_data[GPS_CALLBACK_ALTITUDE];
00274 AltitudeCallback_ *callback = (AltitudeCallback_ *)packet;
00275 *(void **)(&callback_function) = device_p->registered_callbacks[GPS_CALLBACK_ALTITUDE];
00276
00277 if (callback_function == NULL) {
00278 return;
00279 }
00280
00281 callback->altitude = leconvert_uint32_from(callback->altitude);
00282 callback->geoidal_separation = leconvert_uint32_from(callback->geoidal_separation);
00283
00284 callback_function(callback->altitude, callback->geoidal_separation, user_data);
00285 }
00286
00287 static void gps_callback_wrapper_motion(DevicePrivate *device_p, Packet *packet) {
00288 MotionCallbackFunction callback_function;
00289 void *user_data = device_p->registered_callback_user_data[GPS_CALLBACK_MOTION];
00290 MotionCallback_ *callback = (MotionCallback_ *)packet;
00291 *(void **)(&callback_function) = device_p->registered_callbacks[GPS_CALLBACK_MOTION];
00292
00293 if (callback_function == NULL) {
00294 return;
00295 }
00296
00297 callback->course = leconvert_uint32_from(callback->course);
00298 callback->speed = leconvert_uint32_from(callback->speed);
00299
00300 callback_function(callback->course, callback->speed, user_data);
00301 }
00302
00303 static void gps_callback_wrapper_date_time(DevicePrivate *device_p, Packet *packet) {
00304 DateTimeCallbackFunction callback_function;
00305 void *user_data = device_p->registered_callback_user_data[GPS_CALLBACK_DATE_TIME];
00306 DateTimeCallback_ *callback = (DateTimeCallback_ *)packet;
00307 *(void **)(&callback_function) = device_p->registered_callbacks[GPS_CALLBACK_DATE_TIME];
00308
00309 if (callback_function == NULL) {
00310 return;
00311 }
00312
00313 callback->date = leconvert_uint32_from(callback->date);
00314 callback->time = leconvert_uint32_from(callback->time);
00315
00316 callback_function(callback->date, callback->time, user_data);
00317 }
00318
00319 void gps_create(GPS *gps, const char *uid, IPConnection *ipcon) {
00320 DevicePrivate *device_p;
00321
00322 device_create(gps, uid, ipcon->p, 2, 0, 0);
00323
00324 device_p = gps->p;
00325
00326 device_p->response_expected[GPS_FUNCTION_GET_COORDINATES] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00327 device_p->response_expected[GPS_FUNCTION_GET_STATUS] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00328 device_p->response_expected[GPS_FUNCTION_GET_ALTITUDE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00329 device_p->response_expected[GPS_FUNCTION_GET_MOTION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00330 device_p->response_expected[GPS_FUNCTION_GET_DATE_TIME] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00331 device_p->response_expected[GPS_FUNCTION_RESTART] = DEVICE_RESPONSE_EXPECTED_FALSE;
00332 device_p->response_expected[GPS_FUNCTION_SET_COORDINATES_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00333 device_p->response_expected[GPS_FUNCTION_GET_COORDINATES_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00334 device_p->response_expected[GPS_FUNCTION_SET_STATUS_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00335 device_p->response_expected[GPS_FUNCTION_GET_STATUS_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00336 device_p->response_expected[GPS_FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00337 device_p->response_expected[GPS_FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00338 device_p->response_expected[GPS_FUNCTION_SET_MOTION_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00339 device_p->response_expected[GPS_FUNCTION_GET_MOTION_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00340 device_p->response_expected[GPS_FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00341 device_p->response_expected[GPS_FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00342 device_p->response_expected[GPS_CALLBACK_COORDINATES] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00343 device_p->response_expected[GPS_CALLBACK_STATUS] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00344 device_p->response_expected[GPS_CALLBACK_ALTITUDE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00345 device_p->response_expected[GPS_CALLBACK_MOTION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00346 device_p->response_expected[GPS_CALLBACK_DATE_TIME] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00347 device_p->response_expected[GPS_FUNCTION_GET_IDENTITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00348
00349 device_p->callback_wrappers[GPS_CALLBACK_COORDINATES] = gps_callback_wrapper_coordinates;
00350 device_p->callback_wrappers[GPS_CALLBACK_STATUS] = gps_callback_wrapper_status;
00351 device_p->callback_wrappers[GPS_CALLBACK_ALTITUDE] = gps_callback_wrapper_altitude;
00352 device_p->callback_wrappers[GPS_CALLBACK_MOTION] = gps_callback_wrapper_motion;
00353 device_p->callback_wrappers[GPS_CALLBACK_DATE_TIME] = gps_callback_wrapper_date_time;
00354 }
00355
00356 void gps_destroy(GPS *gps) {
00357 device_release(gps->p);
00358 }
00359
00360 int gps_get_response_expected(GPS *gps, uint8_t function_id, bool *ret_response_expected) {
00361 return device_get_response_expected(gps->p, function_id, ret_response_expected);
00362 }
00363
00364 int gps_set_response_expected(GPS *gps, uint8_t function_id, bool response_expected) {
00365 return device_set_response_expected(gps->p, function_id, response_expected);
00366 }
00367
00368 int gps_set_response_expected_all(GPS *gps, bool response_expected) {
00369 return device_set_response_expected_all(gps->p, response_expected);
00370 }
00371
00372 void gps_register_callback(GPS *gps, uint8_t id, void *callback, void *user_data) {
00373 device_register_callback(gps->p, id, callback, user_data);
00374 }
00375
00376 int gps_get_api_version(GPS *gps, uint8_t ret_api_version[3]) {
00377 return device_get_api_version(gps->p, ret_api_version);
00378 }
00379
00380 int gps_get_coordinates(GPS *gps, uint32_t *ret_latitude, char *ret_ns, uint32_t *ret_longitude, char *ret_ew, uint16_t *ret_pdop, uint16_t *ret_hdop, uint16_t *ret_vdop, uint16_t *ret_epe) {
00381 DevicePrivate *device_p = gps->p;
00382 GetCoordinates_ request;
00383 GetCoordinatesResponse_ response;
00384 int ret;
00385
00386 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_COORDINATES, device_p->ipcon_p, device_p);
00387
00388 if (ret < 0) {
00389 return ret;
00390 }
00391
00392
00393 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00394
00395 if (ret < 0) {
00396 return ret;
00397 }
00398 *ret_latitude = leconvert_uint32_from(response.latitude);
00399 *ret_ns = response.ns;
00400 *ret_longitude = leconvert_uint32_from(response.longitude);
00401 *ret_ew = response.ew;
00402 *ret_pdop = leconvert_uint16_from(response.pdop);
00403 *ret_hdop = leconvert_uint16_from(response.hdop);
00404 *ret_vdop = leconvert_uint16_from(response.vdop);
00405 *ret_epe = leconvert_uint16_from(response.epe);
00406
00407
00408
00409 return ret;
00410 }
00411
00412 int gps_get_status(GPS *gps, uint8_t *ret_fix, uint8_t *ret_satellites_view, uint8_t *ret_satellites_used) {
00413 DevicePrivate *device_p = gps->p;
00414 GetStatus_ request;
00415 GetStatusResponse_ response;
00416 int ret;
00417
00418 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_STATUS, device_p->ipcon_p, device_p);
00419
00420 if (ret < 0) {
00421 return ret;
00422 }
00423
00424
00425 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00426
00427 if (ret < 0) {
00428 return ret;
00429 }
00430 *ret_fix = response.fix;
00431 *ret_satellites_view = response.satellites_view;
00432 *ret_satellites_used = response.satellites_used;
00433
00434
00435
00436 return ret;
00437 }
00438
00439 int gps_get_altitude(GPS *gps, uint32_t *ret_altitude, uint32_t *ret_geoidal_separation) {
00440 DevicePrivate *device_p = gps->p;
00441 GetAltitude_ request;
00442 GetAltitudeResponse_ response;
00443 int ret;
00444
00445 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_ALTITUDE, device_p->ipcon_p, device_p);
00446
00447 if (ret < 0) {
00448 return ret;
00449 }
00450
00451
00452 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00453
00454 if (ret < 0) {
00455 return ret;
00456 }
00457 *ret_altitude = leconvert_uint32_from(response.altitude);
00458 *ret_geoidal_separation = leconvert_uint32_from(response.geoidal_separation);
00459
00460
00461
00462 return ret;
00463 }
00464
00465 int gps_get_motion(GPS *gps, uint32_t *ret_course, uint32_t *ret_speed) {
00466 DevicePrivate *device_p = gps->p;
00467 GetMotion_ request;
00468 GetMotionResponse_ response;
00469 int ret;
00470
00471 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_MOTION, device_p->ipcon_p, device_p);
00472
00473 if (ret < 0) {
00474 return ret;
00475 }
00476
00477
00478 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00479
00480 if (ret < 0) {
00481 return ret;
00482 }
00483 *ret_course = leconvert_uint32_from(response.course);
00484 *ret_speed = leconvert_uint32_from(response.speed);
00485
00486
00487
00488 return ret;
00489 }
00490
00491 int gps_get_date_time(GPS *gps, uint32_t *ret_date, uint32_t *ret_time) {
00492 DevicePrivate *device_p = gps->p;
00493 GetDateTime_ request;
00494 GetDateTimeResponse_ response;
00495 int ret;
00496
00497 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_DATE_TIME, device_p->ipcon_p, device_p);
00498
00499 if (ret < 0) {
00500 return ret;
00501 }
00502
00503
00504 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00505
00506 if (ret < 0) {
00507 return ret;
00508 }
00509 *ret_date = leconvert_uint32_from(response.date);
00510 *ret_time = leconvert_uint32_from(response.time);
00511
00512
00513
00514 return ret;
00515 }
00516
00517 int gps_restart(GPS *gps, uint8_t restart_type) {
00518 DevicePrivate *device_p = gps->p;
00519 Restart_ request;
00520 int ret;
00521
00522 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_RESTART, device_p->ipcon_p, device_p);
00523
00524 if (ret < 0) {
00525 return ret;
00526 }
00527
00528 request.restart_type = restart_type;
00529
00530 ret = device_send_request(device_p, (Packet *)&request, NULL);
00531
00532
00533 return ret;
00534 }
00535
00536 int gps_set_coordinates_callback_period(GPS *gps, uint32_t period) {
00537 DevicePrivate *device_p = gps->p;
00538 SetCoordinatesCallbackPeriod_ request;
00539 int ret;
00540
00541 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_SET_COORDINATES_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00542
00543 if (ret < 0) {
00544 return ret;
00545 }
00546
00547 request.period = leconvert_uint32_to(period);
00548
00549 ret = device_send_request(device_p, (Packet *)&request, NULL);
00550
00551
00552 return ret;
00553 }
00554
00555 int gps_get_coordinates_callback_period(GPS *gps, uint32_t *ret_period) {
00556 DevicePrivate *device_p = gps->p;
00557 GetCoordinatesCallbackPeriod_ request;
00558 GetCoordinatesCallbackPeriodResponse_ response;
00559 int ret;
00560
00561 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_COORDINATES_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00562
00563 if (ret < 0) {
00564 return ret;
00565 }
00566
00567
00568 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00569
00570 if (ret < 0) {
00571 return ret;
00572 }
00573 *ret_period = leconvert_uint32_from(response.period);
00574
00575
00576
00577 return ret;
00578 }
00579
00580 int gps_set_status_callback_period(GPS *gps, uint32_t period) {
00581 DevicePrivate *device_p = gps->p;
00582 SetStatusCallbackPeriod_ request;
00583 int ret;
00584
00585 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_SET_STATUS_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00586
00587 if (ret < 0) {
00588 return ret;
00589 }
00590
00591 request.period = leconvert_uint32_to(period);
00592
00593 ret = device_send_request(device_p, (Packet *)&request, NULL);
00594
00595
00596 return ret;
00597 }
00598
00599 int gps_get_status_callback_period(GPS *gps, uint32_t *ret_period) {
00600 DevicePrivate *device_p = gps->p;
00601 GetStatusCallbackPeriod_ request;
00602 GetStatusCallbackPeriodResponse_ response;
00603 int ret;
00604
00605 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_STATUS_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00606
00607 if (ret < 0) {
00608 return ret;
00609 }
00610
00611
00612 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00613
00614 if (ret < 0) {
00615 return ret;
00616 }
00617 *ret_period = leconvert_uint32_from(response.period);
00618
00619
00620
00621 return ret;
00622 }
00623
00624 int gps_set_altitude_callback_period(GPS *gps, uint32_t period) {
00625 DevicePrivate *device_p = gps->p;
00626 SetAltitudeCallbackPeriod_ request;
00627 int ret;
00628
00629 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00630
00631 if (ret < 0) {
00632 return ret;
00633 }
00634
00635 request.period = leconvert_uint32_to(period);
00636
00637 ret = device_send_request(device_p, (Packet *)&request, NULL);
00638
00639
00640 return ret;
00641 }
00642
00643 int gps_get_altitude_callback_period(GPS *gps, uint32_t *ret_period) {
00644 DevicePrivate *device_p = gps->p;
00645 GetAltitudeCallbackPeriod_ request;
00646 GetAltitudeCallbackPeriodResponse_ response;
00647 int ret;
00648
00649 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00650
00651 if (ret < 0) {
00652 return ret;
00653 }
00654
00655
00656 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00657
00658 if (ret < 0) {
00659 return ret;
00660 }
00661 *ret_period = leconvert_uint32_from(response.period);
00662
00663
00664
00665 return ret;
00666 }
00667
00668 int gps_set_motion_callback_period(GPS *gps, uint32_t period) {
00669 DevicePrivate *device_p = gps->p;
00670 SetMotionCallbackPeriod_ request;
00671 int ret;
00672
00673 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_SET_MOTION_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00674
00675 if (ret < 0) {
00676 return ret;
00677 }
00678
00679 request.period = leconvert_uint32_to(period);
00680
00681 ret = device_send_request(device_p, (Packet *)&request, NULL);
00682
00683
00684 return ret;
00685 }
00686
00687 int gps_get_motion_callback_period(GPS *gps, uint32_t *ret_period) {
00688 DevicePrivate *device_p = gps->p;
00689 GetMotionCallbackPeriod_ request;
00690 GetMotionCallbackPeriodResponse_ response;
00691 int ret;
00692
00693 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_MOTION_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00694
00695 if (ret < 0) {
00696 return ret;
00697 }
00698
00699
00700 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00701
00702 if (ret < 0) {
00703 return ret;
00704 }
00705 *ret_period = leconvert_uint32_from(response.period);
00706
00707
00708
00709 return ret;
00710 }
00711
00712 int gps_set_date_time_callback_period(GPS *gps, uint32_t period) {
00713 DevicePrivate *device_p = gps->p;
00714 SetDateTimeCallbackPeriod_ request;
00715 int ret;
00716
00717 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00718
00719 if (ret < 0) {
00720 return ret;
00721 }
00722
00723 request.period = leconvert_uint32_to(period);
00724
00725 ret = device_send_request(device_p, (Packet *)&request, NULL);
00726
00727
00728 return ret;
00729 }
00730
00731 int gps_get_date_time_callback_period(GPS *gps, uint32_t *ret_period) {
00732 DevicePrivate *device_p = gps->p;
00733 GetDateTimeCallbackPeriod_ request;
00734 GetDateTimeCallbackPeriodResponse_ response;
00735 int ret;
00736
00737 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD, device_p->ipcon_p, device_p);
00738
00739 if (ret < 0) {
00740 return ret;
00741 }
00742
00743
00744 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00745
00746 if (ret < 0) {
00747 return ret;
00748 }
00749 *ret_period = leconvert_uint32_from(response.period);
00750
00751
00752
00753 return ret;
00754 }
00755
00756 int gps_get_identity(GPS *gps, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier) {
00757 DevicePrivate *device_p = gps->p;
00758 GetIdentity_ request;
00759 GetIdentityResponse_ response;
00760 int ret;
00761
00762 ret = packet_header_create(&request.header, sizeof(request), GPS_FUNCTION_GET_IDENTITY, device_p->ipcon_p, device_p);
00763
00764 if (ret < 0) {
00765 return ret;
00766 }
00767
00768
00769 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00770
00771 if (ret < 0) {
00772 return ret;
00773 }
00774 strncpy(ret_uid, response.uid, 8);
00775 strncpy(ret_connected_uid, response.connected_uid, 8);
00776 *ret_position = response.position;
00777 memcpy(ret_hardware_version, response.hardware_version, 3 * sizeof(uint8_t));
00778 memcpy(ret_firmware_version, response.firmware_version, 3 * sizeof(uint8_t));
00779 *ret_device_identifier = leconvert_uint16_from(response.device_identifier);
00780
00781
00782
00783 return ret;
00784 }
00785
00786 #ifdef __cplusplus
00787 }
00788 #endif