From: Ankur Date: Thu, 9 Apr 2015 11:57:40 +0000 (+0530) Subject: Addition of Test case for fusion data collection X-Git-Tag: submit/tizen/20151218.070016~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b35f82121ecf4fac092e77eef13d547fcb6f1064;p=platform%2Fcore%2Fsystem%2Fsensord.git Addition of Test case for fusion data collection This test case registers accelerometer, gyroscope, magnetometer and proximity sensors from one single client. This is useful for collecting data from these physical sensors for any particular motion. Change-Id: Ie2c866c5ec624290f9988b17ee33ea92bc8752ca --- diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 0f3c296..48c8cf1 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -141,5 +141,6 @@ systemctl daemon-reload %{_bindir}/api-test %{_bindir}/sensor-test %{_bindir}/performance-test +%{_bindir}/fusion-data-collection %license LICENSE.APLv2 %endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8716991..81213f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,15 +28,19 @@ link_directories(../src/libsensord/) add_executable(api-test src/api-test.c) add_executable(sensor-test src/sensor-test.c src/check-sensor.c) add_executable(performance-test src/performance-test.c src/check-sensor.c) +add_executable(fusion-data-collection src/fusion-data-collection.c) SET_TARGET_PROPERTIES(api-test PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(sensor-test PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(performance-test PROPERTIES LINKER_LANGUAGE C) +SET_TARGET_PROPERTIES(fusion-data-collection PROPERTIES LINKER_LANGUAGE C) target_link_libraries(api-test glib-2.0 dlog sensor) target_link_libraries(sensor-test glib-2.0 dlog sensor) target_link_libraries(performance-test glib-2.0 dlog sensor) +target_link_libraries(fusion-data-collection glib-2.0 dlog sensor) INSTALL(TARGETS api-test DESTINATION /usr/bin/) INSTALL(TARGETS sensor-test DESTINATION /usr/bin/) INSTALL(TARGETS performance-test DESTINATION /usr/bin/) +INSTALL(TARGETS fusion-data-collection DESTINATION /usr/bin/) diff --git a/test/src/fusion-data-collection.c b/test/src/fusion-data-collection.c new file mode 100644 index 0000000..62e63f8 --- /dev/null +++ b/test/src/fusion-data-collection.c @@ -0,0 +1,125 @@ +/* + * sensord + * + * Copyright (c) 2014-15 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXSIZE 4 + +static GMainLoop *mainloop; +FILE* file_output[MAXSIZE]; + +void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + sensor_type_t sensor_type = event_type >> 16; + + switch (sensor_type) { + case ACCELEROMETER_SENSOR: + fprintf(file_output[0], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); + break; + case GEOMAGNETIC_SENSOR: + fprintf(file_output[1], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); + break; + case GYROSCOPE_SENSOR: + fprintf(file_output[2], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); + break; + case PROXIMITY_SENSOR: + fprintf(file_output[MAXSIZE-1], "%6.6f %lld\n", data->values[0], data->timestamp); + break; + default: + return; + } +} + +void usage() +{ + printf("Usage : ./one-client-multiple-sensors \n\n"); + + printf("interval:\n"); + printf("The sampling interval in ms.\n"); + exit(-1); +} + +int main(int argc, char **argv) +{ + int interval; + + if (argc == 2) { + interval = atoi(argv[1]); + if (interval <= 0) + usage(); + } + else + usage(); + + int i; + + int handle[MAXSIZE]; + int result[MAXSIZE], start_handle[MAXSIZE], stop_handle[MAXSIZE]; + unsigned int event[MAXSIZE]; + int sensors[MAXSIZE]; + + sensors[0] = ACCELEROMETER_SENSOR; + sensors[1] = GEOMAGNETIC_SENSOR; + sensors[2] = GYROSCOPE_SENSOR; + sensors[MAXSIZE-1] = PROXIMITY_SENSOR; + + mainloop = g_main_loop_new(NULL, FALSE); + + char file_name[50]; + + for (i = 0; i < MAXSIZE; i++) { + sprintf(file_name, "output_%d", sensors[i]); + file_output[i] = fopen(file_name, "w+"); + sensor_t sensor = sensord_get_sensor(sensors[i]); + handle[i] = sensord_connect(sensor); + event[i] = (sensors[i] << 16) | 0x0001; + result[i] = sensord_register_event(handle[i], event[i], interval, 0, callback, NULL); + + if (result[i] < 0) { + printf("error: unable to register sensor\n"); + return -1; + } + start_handle[i] = sensord_start(handle[i], 1); + + if (start_handle[i] < 0) { + printf("error: unable to start handle\n"); + sensord_unregister_event(handle[i], event[i]); + sensord_disconnect(handle[i]); + return -1; + } + } + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + for (i = 0; i < MAXSIZE; i++) { + sensord_unregister_event(handle[i], event[i]); + sensord_stop(handle[i]); + sensord_disconnect(handle[i]); + } + + return 0; +}