00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define IPCON_EXPOSE_INTERNALS
00013
00014 #include "brick_imu.h"
00015
00016 #include <string.h>
00017
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021
00022
00023
00024 typedef void (*AccelerationCallbackFunction)(int16_t, int16_t, int16_t, void *);
00025
00026 typedef void (*MagneticFieldCallbackFunction)(int16_t, int16_t, int16_t, void *);
00027
00028 typedef void (*AngularVelocityCallbackFunction)(int16_t, int16_t, int16_t, void *);
00029
00030 typedef void (*AllDataCallbackFunction)(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, void *);
00031
00032 typedef void (*OrientationCallbackFunction)(int16_t, int16_t, int16_t, void *);
00033
00034 typedef void (*QuaternionCallbackFunction)(float, float, float, float, void *);
00035
00036 #if defined _MSC_VER || defined __BORLANDC__
00037 #pragma pack(push)
00038 #pragma pack(1)
00039 #define ATTRIBUTE_PACKED
00040 #elif defined __GNUC__
00041 #ifdef _WIN32
00042
00043
00044 #define ATTRIBUTE_PACKED __attribute__((gcc_struct, packed))
00045 #else
00046 #define ATTRIBUTE_PACKED __attribute__((packed))
00047 #endif
00048 #else
00049 #error unknown compiler, do not know how to enable struct packing
00050 #endif
00051
00052 typedef struct {
00053 PacketHeader header;
00054 } ATTRIBUTE_PACKED GetAcceleration_;
00055
00056 typedef struct {
00057 PacketHeader header;
00058 int16_t x;
00059 int16_t y;
00060 int16_t z;
00061 } ATTRIBUTE_PACKED GetAccelerationResponse_;
00062
00063 typedef struct {
00064 PacketHeader header;
00065 } ATTRIBUTE_PACKED GetMagneticField_;
00066
00067 typedef struct {
00068 PacketHeader header;
00069 int16_t x;
00070 int16_t y;
00071 int16_t z;
00072 } ATTRIBUTE_PACKED GetMagneticFieldResponse_;
00073
00074 typedef struct {
00075 PacketHeader header;
00076 } ATTRIBUTE_PACKED GetAngularVelocity_;
00077
00078 typedef struct {
00079 PacketHeader header;
00080 int16_t x;
00081 int16_t y;
00082 int16_t z;
00083 } ATTRIBUTE_PACKED GetAngularVelocityResponse_;
00084
00085 typedef struct {
00086 PacketHeader header;
00087 } ATTRIBUTE_PACKED GetAllData_;
00088
00089 typedef struct {
00090 PacketHeader header;
00091 int16_t acc_x;
00092 int16_t acc_y;
00093 int16_t acc_z;
00094 int16_t mag_x;
00095 int16_t mag_y;
00096 int16_t mag_z;
00097 int16_t ang_x;
00098 int16_t ang_y;
00099 int16_t ang_z;
00100 int16_t temperature;
00101 } ATTRIBUTE_PACKED GetAllDataResponse_;
00102
00103 typedef struct {
00104 PacketHeader header;
00105 } ATTRIBUTE_PACKED GetOrientation_;
00106
00107 typedef struct {
00108 PacketHeader header;
00109 int16_t roll;
00110 int16_t pitch;
00111 int16_t yaw;
00112 } ATTRIBUTE_PACKED GetOrientationResponse_;
00113
00114 typedef struct {
00115 PacketHeader header;
00116 } ATTRIBUTE_PACKED GetQuaternion_;
00117
00118 typedef struct {
00119 PacketHeader header;
00120 float x;
00121 float y;
00122 float z;
00123 float w;
00124 } ATTRIBUTE_PACKED GetQuaternionResponse_;
00125
00126 typedef struct {
00127 PacketHeader header;
00128 } ATTRIBUTE_PACKED GetIMUTemperature_;
00129
00130 typedef struct {
00131 PacketHeader header;
00132 int16_t temperature;
00133 } ATTRIBUTE_PACKED GetIMUTemperatureResponse_;
00134
00135 typedef struct {
00136 PacketHeader header;
00137 } ATTRIBUTE_PACKED LedsOn_;
00138
00139 typedef struct {
00140 PacketHeader header;
00141 } ATTRIBUTE_PACKED LedsOff_;
00142
00143 typedef struct {
00144 PacketHeader header;
00145 } ATTRIBUTE_PACKED AreLedsOn_;
00146
00147 typedef struct {
00148 PacketHeader header;
00149 bool leds;
00150 } ATTRIBUTE_PACKED AreLedsOnResponse_;
00151
00152 typedef struct {
00153 PacketHeader header;
00154 uint8_t range;
00155 } ATTRIBUTE_PACKED SetAccelerationRange_;
00156
00157 typedef struct {
00158 PacketHeader header;
00159 } ATTRIBUTE_PACKED GetAccelerationRange_;
00160
00161 typedef struct {
00162 PacketHeader header;
00163 uint8_t range;
00164 } ATTRIBUTE_PACKED GetAccelerationRangeResponse_;
00165
00166 typedef struct {
00167 PacketHeader header;
00168 uint8_t range;
00169 } ATTRIBUTE_PACKED SetMagnetometerRange_;
00170
00171 typedef struct {
00172 PacketHeader header;
00173 } ATTRIBUTE_PACKED GetMagnetometerRange_;
00174
00175 typedef struct {
00176 PacketHeader header;
00177 uint8_t range;
00178 } ATTRIBUTE_PACKED GetMagnetometerRangeResponse_;
00179
00180 typedef struct {
00181 PacketHeader header;
00182 uint16_t speed;
00183 } ATTRIBUTE_PACKED SetConvergenceSpeed_;
00184
00185 typedef struct {
00186 PacketHeader header;
00187 } ATTRIBUTE_PACKED GetConvergenceSpeed_;
00188
00189 typedef struct {
00190 PacketHeader header;
00191 uint16_t speed;
00192 } ATTRIBUTE_PACKED GetConvergenceSpeedResponse_;
00193
00194 typedef struct {
00195 PacketHeader header;
00196 uint8_t typ;
00197 int16_t data[10];
00198 } ATTRIBUTE_PACKED SetCalibration_;
00199
00200 typedef struct {
00201 PacketHeader header;
00202 uint8_t typ;
00203 } ATTRIBUTE_PACKED GetCalibration_;
00204
00205 typedef struct {
00206 PacketHeader header;
00207 int16_t data[10];
00208 } ATTRIBUTE_PACKED GetCalibrationResponse_;
00209
00210 typedef struct {
00211 PacketHeader header;
00212 uint32_t period;
00213 } ATTRIBUTE_PACKED SetAccelerationPeriod_;
00214
00215 typedef struct {
00216 PacketHeader header;
00217 } ATTRIBUTE_PACKED GetAccelerationPeriod_;
00218
00219 typedef struct {
00220 PacketHeader header;
00221 uint32_t period;
00222 } ATTRIBUTE_PACKED GetAccelerationPeriodResponse_;
00223
00224 typedef struct {
00225 PacketHeader header;
00226 uint32_t period;
00227 } ATTRIBUTE_PACKED SetMagneticFieldPeriod_;
00228
00229 typedef struct {
00230 PacketHeader header;
00231 } ATTRIBUTE_PACKED GetMagneticFieldPeriod_;
00232
00233 typedef struct {
00234 PacketHeader header;
00235 uint32_t period;
00236 } ATTRIBUTE_PACKED GetMagneticFieldPeriodResponse_;
00237
00238 typedef struct {
00239 PacketHeader header;
00240 uint32_t period;
00241 } ATTRIBUTE_PACKED SetAngularVelocityPeriod_;
00242
00243 typedef struct {
00244 PacketHeader header;
00245 } ATTRIBUTE_PACKED GetAngularVelocityPeriod_;
00246
00247 typedef struct {
00248 PacketHeader header;
00249 uint32_t period;
00250 } ATTRIBUTE_PACKED GetAngularVelocityPeriodResponse_;
00251
00252 typedef struct {
00253 PacketHeader header;
00254 uint32_t period;
00255 } ATTRIBUTE_PACKED SetAllDataPeriod_;
00256
00257 typedef struct {
00258 PacketHeader header;
00259 } ATTRIBUTE_PACKED GetAllDataPeriod_;
00260
00261 typedef struct {
00262 PacketHeader header;
00263 uint32_t period;
00264 } ATTRIBUTE_PACKED GetAllDataPeriodResponse_;
00265
00266 typedef struct {
00267 PacketHeader header;
00268 uint32_t period;
00269 } ATTRIBUTE_PACKED SetOrientationPeriod_;
00270
00271 typedef struct {
00272 PacketHeader header;
00273 } ATTRIBUTE_PACKED GetOrientationPeriod_;
00274
00275 typedef struct {
00276 PacketHeader header;
00277 uint32_t period;
00278 } ATTRIBUTE_PACKED GetOrientationPeriodResponse_;
00279
00280 typedef struct {
00281 PacketHeader header;
00282 uint32_t period;
00283 } ATTRIBUTE_PACKED SetQuaternionPeriod_;
00284
00285 typedef struct {
00286 PacketHeader header;
00287 } ATTRIBUTE_PACKED GetQuaternionPeriod_;
00288
00289 typedef struct {
00290 PacketHeader header;
00291 uint32_t period;
00292 } ATTRIBUTE_PACKED GetQuaternionPeriodResponse_;
00293
00294 typedef struct {
00295 PacketHeader header;
00296 int16_t x;
00297 int16_t y;
00298 int16_t z;
00299 } ATTRIBUTE_PACKED AccelerationCallback_;
00300
00301 typedef struct {
00302 PacketHeader header;
00303 int16_t x;
00304 int16_t y;
00305 int16_t z;
00306 } ATTRIBUTE_PACKED MagneticFieldCallback_;
00307
00308 typedef struct {
00309 PacketHeader header;
00310 int16_t x;
00311 int16_t y;
00312 int16_t z;
00313 } ATTRIBUTE_PACKED AngularVelocityCallback_;
00314
00315 typedef struct {
00316 PacketHeader header;
00317 int16_t acc_x;
00318 int16_t acc_y;
00319 int16_t acc_z;
00320 int16_t mag_x;
00321 int16_t mag_y;
00322 int16_t mag_z;
00323 int16_t ang_x;
00324 int16_t ang_y;
00325 int16_t ang_z;
00326 int16_t temperature;
00327 } ATTRIBUTE_PACKED AllDataCallback_;
00328
00329 typedef struct {
00330 PacketHeader header;
00331 int16_t roll;
00332 int16_t pitch;
00333 int16_t yaw;
00334 } ATTRIBUTE_PACKED OrientationCallback_;
00335
00336 typedef struct {
00337 PacketHeader header;
00338 float x;
00339 float y;
00340 float z;
00341 float w;
00342 } ATTRIBUTE_PACKED QuaternionCallback_;
00343
00344 typedef struct {
00345 PacketHeader header;
00346 } ATTRIBUTE_PACKED OrientationCalculationOn_;
00347
00348 typedef struct {
00349 PacketHeader header;
00350 } ATTRIBUTE_PACKED OrientationCalculationOff_;
00351
00352 typedef struct {
00353 PacketHeader header;
00354 } ATTRIBUTE_PACKED IsOrientationCalculationOn_;
00355
00356 typedef struct {
00357 PacketHeader header;
00358 bool orientation_calculation_on;
00359 } ATTRIBUTE_PACKED IsOrientationCalculationOnResponse_;
00360
00361 typedef struct {
00362 PacketHeader header;
00363 char port;
00364 } ATTRIBUTE_PACKED GetProtocol1BrickletName_;
00365
00366 typedef struct {
00367 PacketHeader header;
00368 uint8_t protocol_version;
00369 uint8_t firmware_version[3];
00370 char name[40];
00371 } ATTRIBUTE_PACKED GetProtocol1BrickletNameResponse_;
00372
00373 typedef struct {
00374 PacketHeader header;
00375 } ATTRIBUTE_PACKED GetChipTemperature_;
00376
00377 typedef struct {
00378 PacketHeader header;
00379 int16_t temperature;
00380 } ATTRIBUTE_PACKED GetChipTemperatureResponse_;
00381
00382 typedef struct {
00383 PacketHeader header;
00384 } ATTRIBUTE_PACKED Reset_;
00385
00386 typedef struct {
00387 PacketHeader header;
00388 } ATTRIBUTE_PACKED GetIdentity_;
00389
00390 typedef struct {
00391 PacketHeader header;
00392 char uid[8];
00393 char connected_uid[8];
00394 char position;
00395 uint8_t hardware_version[3];
00396 uint8_t firmware_version[3];
00397 uint16_t device_identifier;
00398 } ATTRIBUTE_PACKED GetIdentityResponse_;
00399
00400 #if defined _MSC_VER || defined __BORLANDC__
00401 #pragma pack(pop)
00402 #endif
00403 #undef ATTRIBUTE_PACKED
00404
00405 static void imu_callback_wrapper_acceleration(DevicePrivate *device_p, Packet *packet) {
00406 AccelerationCallbackFunction callback_function;
00407 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_ACCELERATION];
00408 AccelerationCallback_ *callback = (AccelerationCallback_ *)packet;
00409 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_ACCELERATION];
00410
00411 if (callback_function == NULL) {
00412 return;
00413 }
00414
00415 callback->x = leconvert_int16_from(callback->x);
00416 callback->y = leconvert_int16_from(callback->y);
00417 callback->z = leconvert_int16_from(callback->z);
00418
00419 callback_function(callback->x, callback->y, callback->z, user_data);
00420 }
00421
00422 static void imu_callback_wrapper_magnetic_field(DevicePrivate *device_p, Packet *packet) {
00423 MagneticFieldCallbackFunction callback_function;
00424 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_MAGNETIC_FIELD];
00425 MagneticFieldCallback_ *callback = (MagneticFieldCallback_ *)packet;
00426 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_MAGNETIC_FIELD];
00427
00428 if (callback_function == NULL) {
00429 return;
00430 }
00431
00432 callback->x = leconvert_int16_from(callback->x);
00433 callback->y = leconvert_int16_from(callback->y);
00434 callback->z = leconvert_int16_from(callback->z);
00435
00436 callback_function(callback->x, callback->y, callback->z, user_data);
00437 }
00438
00439 static void imu_callback_wrapper_angular_velocity(DevicePrivate *device_p, Packet *packet) {
00440 AngularVelocityCallbackFunction callback_function;
00441 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_ANGULAR_VELOCITY];
00442 AngularVelocityCallback_ *callback = (AngularVelocityCallback_ *)packet;
00443 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_ANGULAR_VELOCITY];
00444
00445 if (callback_function == NULL) {
00446 return;
00447 }
00448
00449 callback->x = leconvert_int16_from(callback->x);
00450 callback->y = leconvert_int16_from(callback->y);
00451 callback->z = leconvert_int16_from(callback->z);
00452
00453 callback_function(callback->x, callback->y, callback->z, user_data);
00454 }
00455
00456 static void imu_callback_wrapper_all_data(DevicePrivate *device_p, Packet *packet) {
00457 AllDataCallbackFunction callback_function;
00458 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_ALL_DATA];
00459 AllDataCallback_ *callback = (AllDataCallback_ *)packet;
00460 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_ALL_DATA];
00461
00462 if (callback_function == NULL) {
00463 return;
00464 }
00465
00466 callback->acc_x = leconvert_int16_from(callback->acc_x);
00467 callback->acc_y = leconvert_int16_from(callback->acc_y);
00468 callback->acc_z = leconvert_int16_from(callback->acc_z);
00469 callback->mag_x = leconvert_int16_from(callback->mag_x);
00470 callback->mag_y = leconvert_int16_from(callback->mag_y);
00471 callback->mag_z = leconvert_int16_from(callback->mag_z);
00472 callback->ang_x = leconvert_int16_from(callback->ang_x);
00473 callback->ang_y = leconvert_int16_from(callback->ang_y);
00474 callback->ang_z = leconvert_int16_from(callback->ang_z);
00475 callback->temperature = leconvert_int16_from(callback->temperature);
00476
00477 callback_function(callback->acc_x, callback->acc_y, callback->acc_z, callback->mag_x, callback->mag_y, callback->mag_z, callback->ang_x, callback->ang_y, callback->ang_z, callback->temperature, user_data);
00478 }
00479
00480 static void imu_callback_wrapper_orientation(DevicePrivate *device_p, Packet *packet) {
00481 OrientationCallbackFunction callback_function;
00482 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_ORIENTATION];
00483 OrientationCallback_ *callback = (OrientationCallback_ *)packet;
00484 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_ORIENTATION];
00485
00486 if (callback_function == NULL) {
00487 return;
00488 }
00489
00490 callback->roll = leconvert_int16_from(callback->roll);
00491 callback->pitch = leconvert_int16_from(callback->pitch);
00492 callback->yaw = leconvert_int16_from(callback->yaw);
00493
00494 callback_function(callback->roll, callback->pitch, callback->yaw, user_data);
00495 }
00496
00497 static void imu_callback_wrapper_quaternion(DevicePrivate *device_p, Packet *packet) {
00498 QuaternionCallbackFunction callback_function;
00499 void *user_data = device_p->registered_callback_user_data[IMU_CALLBACK_QUATERNION];
00500 QuaternionCallback_ *callback = (QuaternionCallback_ *)packet;
00501 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_CALLBACK_QUATERNION];
00502
00503 if (callback_function == NULL) {
00504 return;
00505 }
00506
00507 callback->x = leconvert_float_from(callback->x);
00508 callback->y = leconvert_float_from(callback->y);
00509 callback->z = leconvert_float_from(callback->z);
00510 callback->w = leconvert_float_from(callback->w);
00511
00512 callback_function(callback->x, callback->y, callback->z, callback->w, user_data);
00513 }
00514
00515 void imu_create(IMU *imu, const char *uid, IPConnection *ipcon) {
00516 DevicePrivate *device_p;
00517
00518 device_create(imu, uid, ipcon->p, 2, 0, 1);
00519
00520 device_p = imu->p;
00521
00522 device_p->response_expected[IMU_FUNCTION_GET_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00523 device_p->response_expected[IMU_FUNCTION_GET_MAGNETIC_FIELD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00524 device_p->response_expected[IMU_FUNCTION_GET_ANGULAR_VELOCITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00525 device_p->response_expected[IMU_FUNCTION_GET_ALL_DATA] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00526 device_p->response_expected[IMU_FUNCTION_GET_ORIENTATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00527 device_p->response_expected[IMU_FUNCTION_GET_QUATERNION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00528 device_p->response_expected[IMU_FUNCTION_GET_IMU_TEMPERATURE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00529 device_p->response_expected[IMU_FUNCTION_LEDS_ON] = DEVICE_RESPONSE_EXPECTED_FALSE;
00530 device_p->response_expected[IMU_FUNCTION_LEDS_OFF] = DEVICE_RESPONSE_EXPECTED_FALSE;
00531 device_p->response_expected[IMU_FUNCTION_ARE_LEDS_ON] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00532 device_p->response_expected[IMU_FUNCTION_SET_ACCELERATION_RANGE] = DEVICE_RESPONSE_EXPECTED_FALSE;
00533 device_p->response_expected[IMU_FUNCTION_GET_ACCELERATION_RANGE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00534 device_p->response_expected[IMU_FUNCTION_SET_MAGNETOMETER_RANGE] = DEVICE_RESPONSE_EXPECTED_FALSE;
00535 device_p->response_expected[IMU_FUNCTION_GET_MAGNETOMETER_RANGE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00536 device_p->response_expected[IMU_FUNCTION_SET_CONVERGENCE_SPEED] = DEVICE_RESPONSE_EXPECTED_FALSE;
00537 device_p->response_expected[IMU_FUNCTION_GET_CONVERGENCE_SPEED] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00538 device_p->response_expected[IMU_FUNCTION_SET_CALIBRATION] = DEVICE_RESPONSE_EXPECTED_FALSE;
00539 device_p->response_expected[IMU_FUNCTION_GET_CALIBRATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00540 device_p->response_expected[IMU_FUNCTION_SET_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00541 device_p->response_expected[IMU_FUNCTION_GET_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00542 device_p->response_expected[IMU_FUNCTION_SET_MAGNETIC_FIELD_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00543 device_p->response_expected[IMU_FUNCTION_GET_MAGNETIC_FIELD_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00544 device_p->response_expected[IMU_FUNCTION_SET_ANGULAR_VELOCITY_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00545 device_p->response_expected[IMU_FUNCTION_GET_ANGULAR_VELOCITY_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00546 device_p->response_expected[IMU_FUNCTION_SET_ALL_DATA_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00547 device_p->response_expected[IMU_FUNCTION_GET_ALL_DATA_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00548 device_p->response_expected[IMU_FUNCTION_SET_ORIENTATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00549 device_p->response_expected[IMU_FUNCTION_GET_ORIENTATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00550 device_p->response_expected[IMU_FUNCTION_SET_QUATERNION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00551 device_p->response_expected[IMU_FUNCTION_GET_QUATERNION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00552 device_p->response_expected[IMU_CALLBACK_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00553 device_p->response_expected[IMU_CALLBACK_MAGNETIC_FIELD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00554 device_p->response_expected[IMU_CALLBACK_ANGULAR_VELOCITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00555 device_p->response_expected[IMU_CALLBACK_ALL_DATA] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00556 device_p->response_expected[IMU_CALLBACK_ORIENTATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00557 device_p->response_expected[IMU_CALLBACK_QUATERNION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00558 device_p->response_expected[IMU_FUNCTION_ORIENTATION_CALCULATION_ON] = DEVICE_RESPONSE_EXPECTED_FALSE;
00559 device_p->response_expected[IMU_FUNCTION_ORIENTATION_CALCULATION_OFF] = DEVICE_RESPONSE_EXPECTED_FALSE;
00560 device_p->response_expected[IMU_FUNCTION_IS_ORIENTATION_CALCULATION_ON] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00561 device_p->response_expected[IMU_FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00562 device_p->response_expected[IMU_FUNCTION_GET_CHIP_TEMPERATURE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00563 device_p->response_expected[IMU_FUNCTION_RESET] = DEVICE_RESPONSE_EXPECTED_FALSE;
00564 device_p->response_expected[IMU_FUNCTION_GET_IDENTITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00565
00566 device_p->callback_wrappers[IMU_CALLBACK_ACCELERATION] = imu_callback_wrapper_acceleration;
00567 device_p->callback_wrappers[IMU_CALLBACK_MAGNETIC_FIELD] = imu_callback_wrapper_magnetic_field;
00568 device_p->callback_wrappers[IMU_CALLBACK_ANGULAR_VELOCITY] = imu_callback_wrapper_angular_velocity;
00569 device_p->callback_wrappers[IMU_CALLBACK_ALL_DATA] = imu_callback_wrapper_all_data;
00570 device_p->callback_wrappers[IMU_CALLBACK_ORIENTATION] = imu_callback_wrapper_orientation;
00571 device_p->callback_wrappers[IMU_CALLBACK_QUATERNION] = imu_callback_wrapper_quaternion;
00572 }
00573
00574 void imu_destroy(IMU *imu) {
00575 device_release(imu->p);
00576 }
00577
00578 int imu_get_response_expected(IMU *imu, uint8_t function_id, bool *ret_response_expected) {
00579 return device_get_response_expected(imu->p, function_id, ret_response_expected);
00580 }
00581
00582 int imu_set_response_expected(IMU *imu, uint8_t function_id, bool response_expected) {
00583 return device_set_response_expected(imu->p, function_id, response_expected);
00584 }
00585
00586 int imu_set_response_expected_all(IMU *imu, bool response_expected) {
00587 return device_set_response_expected_all(imu->p, response_expected);
00588 }
00589
00590 void imu_register_callback(IMU *imu, uint8_t id, void *callback, void *user_data) {
00591 device_register_callback(imu->p, id, callback, user_data);
00592 }
00593
00594 int imu_get_api_version(IMU *imu, uint8_t ret_api_version[3]) {
00595 return device_get_api_version(imu->p, ret_api_version);
00596 }
00597
00598 int imu_get_acceleration(IMU *imu, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00599 DevicePrivate *device_p = imu->p;
00600 GetAcceleration_ request;
00601 GetAccelerationResponse_ response;
00602 int ret;
00603
00604 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ACCELERATION, device_p->ipcon_p, device_p);
00605
00606 if (ret < 0) {
00607 return ret;
00608 }
00609
00610
00611 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00612
00613 if (ret < 0) {
00614 return ret;
00615 }
00616 *ret_x = leconvert_int16_from(response.x);
00617 *ret_y = leconvert_int16_from(response.y);
00618 *ret_z = leconvert_int16_from(response.z);
00619
00620
00621
00622 return ret;
00623 }
00624
00625 int imu_get_magnetic_field(IMU *imu, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00626 DevicePrivate *device_p = imu->p;
00627 GetMagneticField_ request;
00628 GetMagneticFieldResponse_ response;
00629 int ret;
00630
00631 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_MAGNETIC_FIELD, device_p->ipcon_p, device_p);
00632
00633 if (ret < 0) {
00634 return ret;
00635 }
00636
00637
00638 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00639
00640 if (ret < 0) {
00641 return ret;
00642 }
00643 *ret_x = leconvert_int16_from(response.x);
00644 *ret_y = leconvert_int16_from(response.y);
00645 *ret_z = leconvert_int16_from(response.z);
00646
00647
00648
00649 return ret;
00650 }
00651
00652 int imu_get_angular_velocity(IMU *imu, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00653 DevicePrivate *device_p = imu->p;
00654 GetAngularVelocity_ request;
00655 GetAngularVelocityResponse_ response;
00656 int ret;
00657
00658 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ANGULAR_VELOCITY, device_p->ipcon_p, device_p);
00659
00660 if (ret < 0) {
00661 return ret;
00662 }
00663
00664
00665 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00666
00667 if (ret < 0) {
00668 return ret;
00669 }
00670 *ret_x = leconvert_int16_from(response.x);
00671 *ret_y = leconvert_int16_from(response.y);
00672 *ret_z = leconvert_int16_from(response.z);
00673
00674
00675
00676 return ret;
00677 }
00678
00679 int imu_get_all_data(IMU *imu, int16_t *ret_acc_x, int16_t *ret_acc_y, int16_t *ret_acc_z, int16_t *ret_mag_x, int16_t *ret_mag_y, int16_t *ret_mag_z, int16_t *ret_ang_x, int16_t *ret_ang_y, int16_t *ret_ang_z, int16_t *ret_temperature) {
00680 DevicePrivate *device_p = imu->p;
00681 GetAllData_ request;
00682 GetAllDataResponse_ response;
00683 int ret;
00684
00685 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ALL_DATA, device_p->ipcon_p, device_p);
00686
00687 if (ret < 0) {
00688 return ret;
00689 }
00690
00691
00692 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00693
00694 if (ret < 0) {
00695 return ret;
00696 }
00697 *ret_acc_x = leconvert_int16_from(response.acc_x);
00698 *ret_acc_y = leconvert_int16_from(response.acc_y);
00699 *ret_acc_z = leconvert_int16_from(response.acc_z);
00700 *ret_mag_x = leconvert_int16_from(response.mag_x);
00701 *ret_mag_y = leconvert_int16_from(response.mag_y);
00702 *ret_mag_z = leconvert_int16_from(response.mag_z);
00703 *ret_ang_x = leconvert_int16_from(response.ang_x);
00704 *ret_ang_y = leconvert_int16_from(response.ang_y);
00705 *ret_ang_z = leconvert_int16_from(response.ang_z);
00706 *ret_temperature = leconvert_int16_from(response.temperature);
00707
00708
00709
00710 return ret;
00711 }
00712
00713 int imu_get_orientation(IMU *imu, int16_t *ret_roll, int16_t *ret_pitch, int16_t *ret_yaw) {
00714 DevicePrivate *device_p = imu->p;
00715 GetOrientation_ request;
00716 GetOrientationResponse_ response;
00717 int ret;
00718
00719 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ORIENTATION, device_p->ipcon_p, device_p);
00720
00721 if (ret < 0) {
00722 return ret;
00723 }
00724
00725
00726 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00727
00728 if (ret < 0) {
00729 return ret;
00730 }
00731 *ret_roll = leconvert_int16_from(response.roll);
00732 *ret_pitch = leconvert_int16_from(response.pitch);
00733 *ret_yaw = leconvert_int16_from(response.yaw);
00734
00735
00736
00737 return ret;
00738 }
00739
00740 int imu_get_quaternion(IMU *imu, float *ret_x, float *ret_y, float *ret_z, float *ret_w) {
00741 DevicePrivate *device_p = imu->p;
00742 GetQuaternion_ request;
00743 GetQuaternionResponse_ response;
00744 int ret;
00745
00746 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_QUATERNION, device_p->ipcon_p, device_p);
00747
00748 if (ret < 0) {
00749 return ret;
00750 }
00751
00752
00753 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00754
00755 if (ret < 0) {
00756 return ret;
00757 }
00758 *ret_x = leconvert_float_from(response.x);
00759 *ret_y = leconvert_float_from(response.y);
00760 *ret_z = leconvert_float_from(response.z);
00761 *ret_w = leconvert_float_from(response.w);
00762
00763
00764
00765 return ret;
00766 }
00767
00768 int imu_get_imu_temperature(IMU *imu, int16_t *ret_temperature) {
00769 DevicePrivate *device_p = imu->p;
00770 GetIMUTemperature_ request;
00771 GetIMUTemperatureResponse_ response;
00772 int ret;
00773
00774 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_IMU_TEMPERATURE, device_p->ipcon_p, device_p);
00775
00776 if (ret < 0) {
00777 return ret;
00778 }
00779
00780
00781 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00782
00783 if (ret < 0) {
00784 return ret;
00785 }
00786 *ret_temperature = leconvert_int16_from(response.temperature);
00787
00788
00789
00790 return ret;
00791 }
00792
00793 int imu_leds_on(IMU *imu) {
00794 DevicePrivate *device_p = imu->p;
00795 LedsOn_ request;
00796 int ret;
00797
00798 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_LEDS_ON, device_p->ipcon_p, device_p);
00799
00800 if (ret < 0) {
00801 return ret;
00802 }
00803
00804
00805 ret = device_send_request(device_p, (Packet *)&request, NULL);
00806
00807
00808 return ret;
00809 }
00810
00811 int imu_leds_off(IMU *imu) {
00812 DevicePrivate *device_p = imu->p;
00813 LedsOff_ request;
00814 int ret;
00815
00816 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_LEDS_OFF, device_p->ipcon_p, device_p);
00817
00818 if (ret < 0) {
00819 return ret;
00820 }
00821
00822
00823 ret = device_send_request(device_p, (Packet *)&request, NULL);
00824
00825
00826 return ret;
00827 }
00828
00829 int imu_are_leds_on(IMU *imu, bool *ret_leds) {
00830 DevicePrivate *device_p = imu->p;
00831 AreLedsOn_ request;
00832 AreLedsOnResponse_ response;
00833 int ret;
00834
00835 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_ARE_LEDS_ON, device_p->ipcon_p, device_p);
00836
00837 if (ret < 0) {
00838 return ret;
00839 }
00840
00841
00842 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00843
00844 if (ret < 0) {
00845 return ret;
00846 }
00847 *ret_leds = response.leds;
00848
00849
00850
00851 return ret;
00852 }
00853
00854 int imu_set_acceleration_range(IMU *imu, uint8_t range) {
00855 DevicePrivate *device_p = imu->p;
00856 SetAccelerationRange_ request;
00857 int ret;
00858
00859 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_ACCELERATION_RANGE, device_p->ipcon_p, device_p);
00860
00861 if (ret < 0) {
00862 return ret;
00863 }
00864
00865 request.range = range;
00866
00867 ret = device_send_request(device_p, (Packet *)&request, NULL);
00868
00869
00870 return ret;
00871 }
00872
00873 int imu_get_acceleration_range(IMU *imu, uint8_t *ret_range) {
00874 DevicePrivate *device_p = imu->p;
00875 GetAccelerationRange_ request;
00876 GetAccelerationRangeResponse_ response;
00877 int ret;
00878
00879 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ACCELERATION_RANGE, device_p->ipcon_p, device_p);
00880
00881 if (ret < 0) {
00882 return ret;
00883 }
00884
00885
00886 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00887
00888 if (ret < 0) {
00889 return ret;
00890 }
00891 *ret_range = response.range;
00892
00893
00894
00895 return ret;
00896 }
00897
00898 int imu_set_magnetometer_range(IMU *imu, uint8_t range) {
00899 DevicePrivate *device_p = imu->p;
00900 SetMagnetometerRange_ request;
00901 int ret;
00902
00903 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_MAGNETOMETER_RANGE, device_p->ipcon_p, device_p);
00904
00905 if (ret < 0) {
00906 return ret;
00907 }
00908
00909 request.range = range;
00910
00911 ret = device_send_request(device_p, (Packet *)&request, NULL);
00912
00913
00914 return ret;
00915 }
00916
00917 int imu_get_magnetometer_range(IMU *imu, uint8_t *ret_range) {
00918 DevicePrivate *device_p = imu->p;
00919 GetMagnetometerRange_ request;
00920 GetMagnetometerRangeResponse_ response;
00921 int ret;
00922
00923 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_MAGNETOMETER_RANGE, device_p->ipcon_p, device_p);
00924
00925 if (ret < 0) {
00926 return ret;
00927 }
00928
00929
00930 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00931
00932 if (ret < 0) {
00933 return ret;
00934 }
00935 *ret_range = response.range;
00936
00937
00938
00939 return ret;
00940 }
00941
00942 int imu_set_convergence_speed(IMU *imu, uint16_t speed) {
00943 DevicePrivate *device_p = imu->p;
00944 SetConvergenceSpeed_ request;
00945 int ret;
00946
00947 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_CONVERGENCE_SPEED, device_p->ipcon_p, device_p);
00948
00949 if (ret < 0) {
00950 return ret;
00951 }
00952
00953 request.speed = leconvert_uint16_to(speed);
00954
00955 ret = device_send_request(device_p, (Packet *)&request, NULL);
00956
00957
00958 return ret;
00959 }
00960
00961 int imu_get_convergence_speed(IMU *imu, uint16_t *ret_speed) {
00962 DevicePrivate *device_p = imu->p;
00963 GetConvergenceSpeed_ request;
00964 GetConvergenceSpeedResponse_ response;
00965 int ret;
00966
00967 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_CONVERGENCE_SPEED, device_p->ipcon_p, device_p);
00968
00969 if (ret < 0) {
00970 return ret;
00971 }
00972
00973
00974 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00975
00976 if (ret < 0) {
00977 return ret;
00978 }
00979 *ret_speed = leconvert_uint16_from(response.speed);
00980
00981
00982
00983 return ret;
00984 }
00985
00986 int imu_set_calibration(IMU *imu, uint8_t typ, int16_t data[10]) {
00987 DevicePrivate *device_p = imu->p;
00988 SetCalibration_ request;
00989 int ret;
00990 int i;
00991
00992 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_CALIBRATION, device_p->ipcon_p, device_p);
00993
00994 if (ret < 0) {
00995 return ret;
00996 }
00997
00998 request.typ = typ;
00999 for (i = 0; i < 10; i++) request.data[i] = leconvert_int16_to(data[i]);
01000
01001 ret = device_send_request(device_p, (Packet *)&request, NULL);
01002
01003
01004 return ret;
01005 }
01006
01007 int imu_get_calibration(IMU *imu, uint8_t typ, int16_t ret_data[10]) {
01008 DevicePrivate *device_p = imu->p;
01009 GetCalibration_ request;
01010 GetCalibrationResponse_ response;
01011 int ret;
01012 int i;
01013
01014 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_CALIBRATION, device_p->ipcon_p, device_p);
01015
01016 if (ret < 0) {
01017 return ret;
01018 }
01019
01020 request.typ = typ;
01021
01022 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01023
01024 if (ret < 0) {
01025 return ret;
01026 }
01027 for (i = 0; i < 10; i++) ret_data[i] = leconvert_int16_from(response.data[i]);
01028
01029
01030
01031 return ret;
01032 }
01033
01034 int imu_set_acceleration_period(IMU *imu, uint32_t period) {
01035 DevicePrivate *device_p = imu->p;
01036 SetAccelerationPeriod_ request;
01037 int ret;
01038
01039 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01040
01041 if (ret < 0) {
01042 return ret;
01043 }
01044
01045 request.period = leconvert_uint32_to(period);
01046
01047 ret = device_send_request(device_p, (Packet *)&request, NULL);
01048
01049
01050 return ret;
01051 }
01052
01053 int imu_get_acceleration_period(IMU *imu, uint32_t *ret_period) {
01054 DevicePrivate *device_p = imu->p;
01055 GetAccelerationPeriod_ request;
01056 GetAccelerationPeriodResponse_ response;
01057 int ret;
01058
01059 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01060
01061 if (ret < 0) {
01062 return ret;
01063 }
01064
01065
01066 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01067
01068 if (ret < 0) {
01069 return ret;
01070 }
01071 *ret_period = leconvert_uint32_from(response.period);
01072
01073
01074
01075 return ret;
01076 }
01077
01078 int imu_set_magnetic_field_period(IMU *imu, uint32_t period) {
01079 DevicePrivate *device_p = imu->p;
01080 SetMagneticFieldPeriod_ request;
01081 int ret;
01082
01083 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_MAGNETIC_FIELD_PERIOD, device_p->ipcon_p, device_p);
01084
01085 if (ret < 0) {
01086 return ret;
01087 }
01088
01089 request.period = leconvert_uint32_to(period);
01090
01091 ret = device_send_request(device_p, (Packet *)&request, NULL);
01092
01093
01094 return ret;
01095 }
01096
01097 int imu_get_magnetic_field_period(IMU *imu, uint32_t *ret_period) {
01098 DevicePrivate *device_p = imu->p;
01099 GetMagneticFieldPeriod_ request;
01100 GetMagneticFieldPeriodResponse_ response;
01101 int ret;
01102
01103 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_MAGNETIC_FIELD_PERIOD, device_p->ipcon_p, device_p);
01104
01105 if (ret < 0) {
01106 return ret;
01107 }
01108
01109
01110 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01111
01112 if (ret < 0) {
01113 return ret;
01114 }
01115 *ret_period = leconvert_uint32_from(response.period);
01116
01117
01118
01119 return ret;
01120 }
01121
01122 int imu_set_angular_velocity_period(IMU *imu, uint32_t period) {
01123 DevicePrivate *device_p = imu->p;
01124 SetAngularVelocityPeriod_ request;
01125 int ret;
01126
01127 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, device_p->ipcon_p, device_p);
01128
01129 if (ret < 0) {
01130 return ret;
01131 }
01132
01133 request.period = leconvert_uint32_to(period);
01134
01135 ret = device_send_request(device_p, (Packet *)&request, NULL);
01136
01137
01138 return ret;
01139 }
01140
01141 int imu_get_angular_velocity_period(IMU *imu, uint32_t *ret_period) {
01142 DevicePrivate *device_p = imu->p;
01143 GetAngularVelocityPeriod_ request;
01144 GetAngularVelocityPeriodResponse_ response;
01145 int ret;
01146
01147 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, device_p->ipcon_p, device_p);
01148
01149 if (ret < 0) {
01150 return ret;
01151 }
01152
01153
01154 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01155
01156 if (ret < 0) {
01157 return ret;
01158 }
01159 *ret_period = leconvert_uint32_from(response.period);
01160
01161
01162
01163 return ret;
01164 }
01165
01166 int imu_set_all_data_period(IMU *imu, uint32_t period) {
01167 DevicePrivate *device_p = imu->p;
01168 SetAllDataPeriod_ request;
01169 int ret;
01170
01171 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_ALL_DATA_PERIOD, device_p->ipcon_p, device_p);
01172
01173 if (ret < 0) {
01174 return ret;
01175 }
01176
01177 request.period = leconvert_uint32_to(period);
01178
01179 ret = device_send_request(device_p, (Packet *)&request, NULL);
01180
01181
01182 return ret;
01183 }
01184
01185 int imu_get_all_data_period(IMU *imu, uint32_t *ret_period) {
01186 DevicePrivate *device_p = imu->p;
01187 GetAllDataPeriod_ request;
01188 GetAllDataPeriodResponse_ response;
01189 int ret;
01190
01191 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ALL_DATA_PERIOD, device_p->ipcon_p, device_p);
01192
01193 if (ret < 0) {
01194 return ret;
01195 }
01196
01197
01198 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01199
01200 if (ret < 0) {
01201 return ret;
01202 }
01203 *ret_period = leconvert_uint32_from(response.period);
01204
01205
01206
01207 return ret;
01208 }
01209
01210 int imu_set_orientation_period(IMU *imu, uint32_t period) {
01211 DevicePrivate *device_p = imu->p;
01212 SetOrientationPeriod_ request;
01213 int ret;
01214
01215 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_ORIENTATION_PERIOD, device_p->ipcon_p, device_p);
01216
01217 if (ret < 0) {
01218 return ret;
01219 }
01220
01221 request.period = leconvert_uint32_to(period);
01222
01223 ret = device_send_request(device_p, (Packet *)&request, NULL);
01224
01225
01226 return ret;
01227 }
01228
01229 int imu_get_orientation_period(IMU *imu, uint32_t *ret_period) {
01230 DevicePrivate *device_p = imu->p;
01231 GetOrientationPeriod_ request;
01232 GetOrientationPeriodResponse_ response;
01233 int ret;
01234
01235 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_ORIENTATION_PERIOD, device_p->ipcon_p, device_p);
01236
01237 if (ret < 0) {
01238 return ret;
01239 }
01240
01241
01242 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01243
01244 if (ret < 0) {
01245 return ret;
01246 }
01247 *ret_period = leconvert_uint32_from(response.period);
01248
01249
01250
01251 return ret;
01252 }
01253
01254 int imu_set_quaternion_period(IMU *imu, uint32_t period) {
01255 DevicePrivate *device_p = imu->p;
01256 SetQuaternionPeriod_ request;
01257 int ret;
01258
01259 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_SET_QUATERNION_PERIOD, device_p->ipcon_p, device_p);
01260
01261 if (ret < 0) {
01262 return ret;
01263 }
01264
01265 request.period = leconvert_uint32_to(period);
01266
01267 ret = device_send_request(device_p, (Packet *)&request, NULL);
01268
01269
01270 return ret;
01271 }
01272
01273 int imu_get_quaternion_period(IMU *imu, uint32_t *ret_period) {
01274 DevicePrivate *device_p = imu->p;
01275 GetQuaternionPeriod_ request;
01276 GetQuaternionPeriodResponse_ response;
01277 int ret;
01278
01279 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_QUATERNION_PERIOD, device_p->ipcon_p, device_p);
01280
01281 if (ret < 0) {
01282 return ret;
01283 }
01284
01285
01286 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01287
01288 if (ret < 0) {
01289 return ret;
01290 }
01291 *ret_period = leconvert_uint32_from(response.period);
01292
01293
01294
01295 return ret;
01296 }
01297
01298 int imu_orientation_calculation_on(IMU *imu) {
01299 DevicePrivate *device_p = imu->p;
01300 OrientationCalculationOn_ request;
01301 int ret;
01302
01303 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_ORIENTATION_CALCULATION_ON, device_p->ipcon_p, device_p);
01304
01305 if (ret < 0) {
01306 return ret;
01307 }
01308
01309
01310 ret = device_send_request(device_p, (Packet *)&request, NULL);
01311
01312
01313 return ret;
01314 }
01315
01316 int imu_orientation_calculation_off(IMU *imu) {
01317 DevicePrivate *device_p = imu->p;
01318 OrientationCalculationOff_ request;
01319 int ret;
01320
01321 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_ORIENTATION_CALCULATION_OFF, device_p->ipcon_p, device_p);
01322
01323 if (ret < 0) {
01324 return ret;
01325 }
01326
01327
01328 ret = device_send_request(device_p, (Packet *)&request, NULL);
01329
01330
01331 return ret;
01332 }
01333
01334 int imu_is_orientation_calculation_on(IMU *imu, bool *ret_orientation_calculation_on) {
01335 DevicePrivate *device_p = imu->p;
01336 IsOrientationCalculationOn_ request;
01337 IsOrientationCalculationOnResponse_ response;
01338 int ret;
01339
01340 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_IS_ORIENTATION_CALCULATION_ON, device_p->ipcon_p, device_p);
01341
01342 if (ret < 0) {
01343 return ret;
01344 }
01345
01346
01347 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01348
01349 if (ret < 0) {
01350 return ret;
01351 }
01352 *ret_orientation_calculation_on = response.orientation_calculation_on;
01353
01354
01355
01356 return ret;
01357 }
01358
01359 int imu_get_protocol1_bricklet_name(IMU *imu, char port, uint8_t *ret_protocol_version, uint8_t ret_firmware_version[3], char ret_name[40]) {
01360 DevicePrivate *device_p = imu->p;
01361 GetProtocol1BrickletName_ request;
01362 GetProtocol1BrickletNameResponse_ response;
01363 int ret;
01364
01365 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, device_p->ipcon_p, device_p);
01366
01367 if (ret < 0) {
01368 return ret;
01369 }
01370
01371 request.port = port;
01372
01373 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01374
01375 if (ret < 0) {
01376 return ret;
01377 }
01378 *ret_protocol_version = response.protocol_version;
01379 memcpy(ret_firmware_version, response.firmware_version, 3 * sizeof(uint8_t));
01380 strncpy(ret_name, response.name, 40);
01381
01382
01383
01384 return ret;
01385 }
01386
01387 int imu_get_chip_temperature(IMU *imu, int16_t *ret_temperature) {
01388 DevicePrivate *device_p = imu->p;
01389 GetChipTemperature_ request;
01390 GetChipTemperatureResponse_ response;
01391 int ret;
01392
01393 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_CHIP_TEMPERATURE, device_p->ipcon_p, device_p);
01394
01395 if (ret < 0) {
01396 return ret;
01397 }
01398
01399
01400 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01401
01402 if (ret < 0) {
01403 return ret;
01404 }
01405 *ret_temperature = leconvert_int16_from(response.temperature);
01406
01407
01408
01409 return ret;
01410 }
01411
01412 int imu_reset(IMU *imu) {
01413 DevicePrivate *device_p = imu->p;
01414 Reset_ request;
01415 int ret;
01416
01417 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_RESET, device_p->ipcon_p, device_p);
01418
01419 if (ret < 0) {
01420 return ret;
01421 }
01422
01423
01424 ret = device_send_request(device_p, (Packet *)&request, NULL);
01425
01426
01427 return ret;
01428 }
01429
01430 int imu_get_identity(IMU *imu, 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) {
01431 DevicePrivate *device_p = imu->p;
01432 GetIdentity_ request;
01433 GetIdentityResponse_ response;
01434 int ret;
01435
01436 ret = packet_header_create(&request.header, sizeof(request), IMU_FUNCTION_GET_IDENTITY, device_p->ipcon_p, device_p);
01437
01438 if (ret < 0) {
01439 return ret;
01440 }
01441
01442
01443 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01444
01445 if (ret < 0) {
01446 return ret;
01447 }
01448 strncpy(ret_uid, response.uid, 8);
01449 strncpy(ret_connected_uid, response.connected_uid, 8);
01450 *ret_position = response.position;
01451 memcpy(ret_hardware_version, response.hardware_version, 3 * sizeof(uint8_t));
01452 memcpy(ret_firmware_version, response.firmware_version, 3 * sizeof(uint8_t));
01453 *ret_device_identifier = leconvert_uint16_from(response.device_identifier);
01454
01455
01456
01457 return ret;
01458 }
01459
01460 #ifdef __cplusplus
01461 }
01462 #endif