From bc2cc24c19467155c0d73ac6e4e0051e85898304 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:24:49 +0900 Subject: [PATCH 01/16] sensord: remove unnecessary testcases for fusion library Change-Id: Iaf95f379ccf05cfa2c8f001d1976804d50ad7b10 Signed-off-by: kibak.yoon --- src/sensor/rotation_vector/test/gravity_sensor.cpp | 40 ----- src/sensor/rotation_vector/test/gravity_sensor.h | 36 ---- .../test/linear_acceleration_sensor.cpp | 39 ---- .../test/linear_acceleration_sensor.h | 36 ---- .../rotation_vector/test/orientation_sensor.cpp | 53 ------ .../rotation_vector/test/orientation_sensor.h | 36 ---- .../euler_angles_test/euler_angles_main.cpp | 78 -------- .../gravity_sensor_test/gravity_sensor_main.cpp | 91 ---------- .../linear_acceleration_sensor_main.cpp | 91 ---------- .../test/test_projects/matrix_test/matrix_main.cpp | 154 ---------------- .../orientation_sensor_main.cpp | 121 ------------- .../quaternion_test/quaternion_main.cpp | 77 -------- .../rotation_matrix_test/rotation_matrix_main.cpp | 62 ------- .../sensor_data_test/sensor_data_main.cpp | 69 -------- .../test/test_projects/vector_test/vector_main.cpp | 196 --------------------- 15 files changed, 1179 deletions(-) delete mode 100644 src/sensor/rotation_vector/test/gravity_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/gravity_sensor.h delete mode 100644 src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/linear_acceleration_sensor.h delete mode 100644 src/sensor/rotation_vector/test/orientation_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/orientation_sensor.h delete mode 100644 src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp diff --git a/src/sensor/rotation_vector/test/gravity_sensor.cpp b/src/sensor/rotation_vector/test/gravity_sensor.cpp deleted file mode 100644 index 94a82e7..0000000 --- a/src/sensor/rotation_vector/test/gravity_sensor.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifdef _GRAVITY_SENSOR_H_ - -#define GRAVITY 9.80665 - -sensor_data gravity_sensor::get_gravity(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic) -{ - euler_angles orientation; - sensor_data gravity; - - orientation = orien_sensor.get_orientation(accel, gyro, magnetic); - - gravity.m_data.m_vec[0] = GRAVITY * sin(orientation.m_ang.m_vec[0]); - gravity.m_data.m_vec[1] = GRAVITY * sin(orientation.m_ang.m_vec[1]); - gravity.m_data.m_vec[2] = GRAVITY * cos(orientation.m_ang.m_vec[0]) * - cos(orientation.m_ang.m_vec[1]); - - return gravity; -} - -#endif diff --git a/src/sensor/rotation_vector/test/gravity_sensor.h b/src/sensor/rotation_vector/test/gravity_sensor.h deleted file mode 100644 index 7d3fa6c..0000000 --- a/src/sensor/rotation_vector/test/gravity_sensor.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifndef _GRAVITY_SENSOR_H_ -#define _GRAVITY_SENSOR_H_ - -#include "orientation_sensor.h" - -class gravity_sensor -{ -public: - orientation_sensor orien_sensor; - - sensor_data get_gravity(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic); -}; - -#include "gravity_sensor.cpp" - -#endif /* _GRAVITY_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp b/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp deleted file mode 100644 index b38a2d1..0000000 --- a/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifdef _LINEAR_ACCELERATION_SENSOR_H_ - -sensor_data linear_acceleration_sensor::get_linear_acceleration(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic) -{ - sensor_data gravity_data; - float la_x, la_y, la_z; - - gravity_data = grav_sensor.get_gravity(accel, gyro, magnetic); - - la_x = accel.m_data.m_vec[0] - gravity_data.m_data.m_vec[1]; - la_y = accel.m_data.m_vec[1] - gravity_data.m_data.m_vec[0]; - la_z = accel.m_data.m_vec[2] - gravity_data.m_data.m_vec[2]; - - sensor_data lin_accel_data(la_x, la_y, la_z); - - return lin_accel_data; -} - -#endif diff --git a/src/sensor/rotation_vector/test/linear_acceleration_sensor.h b/src/sensor/rotation_vector/test/linear_acceleration_sensor.h deleted file mode 100644 index 1942f3b..0000000 --- a/src/sensor/rotation_vector/test/linear_acceleration_sensor.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifndef _LINEAR_ACCELERATION_SENSOR_H_ -#define _LINEAR_ACCELERATION_SENSOR_H_ - -#include "gravity_sensor.h" - -class linear_acceleration_sensor -{ -public: - gravity_sensor grav_sensor; - - sensor_data get_linear_acceleration(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic); -}; - -#include "linear_acceleration_sensor.cpp" - -#endif /* _LINEAR_ACCELERATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/orientation_sensor.cpp b/src/sensor/rotation_vector/test/orientation_sensor.cpp deleted file mode 100644 index 25099e2..0000000 --- a/src/sensor/rotation_vector/test/orientation_sensor.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifdef _ORIENTATION_SENSOR_H_ - -float bias_accel[] = {0.098586, 0.18385, (10.084 - GRAVITY)}; -float bias_gyro[] = {-5.3539, 0.24325, 2.3391}; -float bias_magnetic[] = {0, 0, 0}; -int sign_accel[] = {+1, +1, +1}; -int sign_gyro[] = {+1, +1, +1}; -int sign_magnetic[] = {+1, +1, +1}; -float scale_accel = 1; -float scale_gyro = 1150; -float scale_magnetic = 1; -int magnetic_alignment_factor = -1; - -void orientation_sensor::get_device_orientation(sensor_data *accel_data, - sensor_data *gyro_data, sensor_data *magnetic_data) -{ - vect vec_bias_gyro(bias_gyro); - - pre_process_data(accel_data, accel_data, bias_accel, sign_accel, scale_accel); - normalize(*accel_data); - - if (gyro_data != NULL) { - pre_process_data(gyro_data, gyro_data, bias_gyro, sign_gyro, scale_gyro); - } - - if (magnetic_data != NULL) { - pre_process_data(magnetic_data, magnetic_data, bias_magnetic, sign_magnetic, scale_magnetic); - normalize(*magnetic_data); - } - - orien_filter.get_device_orientation(accel_data, gyro_data, magnetic_data); -} - -#endif /* _ORIENTATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/orientation_sensor.h b/src/sensor/rotation_vector/test/orientation_sensor.h deleted file mode 100644 index c7aff2f..0000000 --- a/src/sensor/rotation_vector/test/orientation_sensor.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#ifndef _ORIENTATION_SENSOR_H_ -#define _ORIENTATION_SENSOR_H_ - -#include "../orientation_filter.h" - -class orientation_sensor -{ -public: - orientation_filter orien_filter; - - void get_device_orientation(sensor_data *accel, - sensor_data *gyro, sensor_data *magnetic); -}; - -#include "orientation_sensor.cpp" - -#endif /* _ORIENTATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp b/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp deleted file mode 100644 index fc69bd5..0000000 --- a/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../euler_angles.h" - -int main() -{ - float arr0[3] = {234.98, 345.24, -56.12}; - float arr1[3] = {56, -34, 76}; - float arr2[4] = {0.6, 0.6, -.18, -.44}; - float arr3[4] = {-0.5, -0.36, .43, .03}; - - vect v0(arr0); - vect v1(arr1); - vect v2(arr2); - vect v3(arr3); - - quaternion q1(v2); - quaternion q2(v3); - - euler_angles e0(v0); - euler_angles e1(v1); - euler_angles e2((float)234.98, (float)345.24, (float)-56.12); - euler_angles e3(e1); - euler_angles e4; - - cout << "Constructor tests\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << e0.m_ang << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << e1.m_ang << "\n\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << e2.m_ang << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << e3.m_ang << "\n\n"; - cout << "default constructor\n"; - cout << "output\t" << e4.m_ang << "\n\n"; - - cout << "Quaternion to Euler\n"; - euler_angles e5 = quat2euler(q1); - cout << "input\t" << q1.m_quat << "\n"; - cout << "output\t" << e5.m_ang << "\n\n"; - euler_angles e8 = quat2euler(q2); - cout << "input\t" << q2.m_quat << "\n"; - cout << "output\t" << e8.m_ang << "\n\n"; - - cout << "Euler to Quaternion\n"; - quaternion q3 = euler2quat(e8); - cout << "input\t" << e8.m_ang << "\n"; - cout << "output\t" << q3.m_quat << "\n\n"; - - cout << "Radians to Degrees\n"; - euler_angles e6 = deg2rad(e0); - cout << "input\t" << e0.m_ang << "\n"; - cout << "output\t" << e6.m_ang << "\n\n"; - - cout << "Degrees to Radians\n"; - euler_angles e7 = rad2deg(e6); - cout << "input\t" << e6.m_ang << "\n"; - cout << "output\t" << e7.m_ang << "\n\n"; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp deleted file mode 100644 index 3525c32..0000000 --- a/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../gravity_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define GRAVITY_DATA_PATH "../../../design/data/100ms/gravity/throw/" -#define GRAVITY_DATA_SIZE 135 - -int main() -{ - int data_available = GRAVITY_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream gravity_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - sensor_data gravity; - gravity_sensor grav_sensor; - - accel_in.open(((string)GRAVITY_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)GRAVITY_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)GRAVITY_DATA_PATH + (string)"magnetic.txt").c_str()); - - gravity_file.open(((string)"gravity.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - gravity = grav_sensor.get_gravity(accel_data, gyro_data, magnetic_data); - - gravity_file << gravity.m_data; - - cout << "Gravity Data\t" << gravity.m_data << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - gravity_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp deleted file mode 100644 index 958559a..0000000 --- a/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../linear_acceleration_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define LA_DATA_PATH "../../../design/data/100ms/linear_acceleration/move_x_y_z/" -#define LA_DATA_SIZE 170 - -int main() -{ - int data_available = LA_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream la_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - sensor_data lin_accel; - linear_acceleration_sensor la_sensor; - - accel_in.open(((string)LA_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)LA_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)LA_DATA_PATH + (string)"magnetic.txt").c_str()); - - la_file.open(((string)"linear_acceleration.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - lin_accel = la_sensor.get_linear_acceleration(accel_data, gyro_data, magnetic_data); - - la_file << lin_accel.m_data; - - cout << "Linear Acceleration Data\t" << lin_accel.m_data << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - la_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp b/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp deleted file mode 100644 index 05b1743..0000000 --- a/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../matrix.h" - -int main() -{ - float arr0[2][2] = {{-2.243, 2.57}, {3.56, -3.02}}; - float arr1[2][2] = {{2.2, 2.5}, {3.5, 3.0}}; - float arr5[3][2] = {{0.22, 4.56}, {3.652, 5.86}, {1.430, 0.45}}; - float arr11[1][3] = {{2.0, 3.0, 4.0}}; - float arr12[3][1] = {{2.0}, {1.0}, {3.0}}; - float arr15[2][3] = {{20.0, -40.0, 10.0}, {36.0, 52.0, -55.0}}; - float arr3[3][3] = {{20.2, 40.5, 10.0}, {3.6, 52.0, 5.5}, {1.0, 45.5, 66.6}}; - float arr4[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - float arr8[3][3] = {{4.75, 0.65, 0.123}, {0.075, 5.302, 0.56}, {1.113, 0.475, 2.362}}; - float arr9[3][3] = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}}; - - matrix m1(arr0); - matrix m2(arr1); - matrix m3; - matrix m10(arr3); - matrix m11(arr5); - matrix m6; - matrix m13; - matrix m12(arr4); - matrix m15(arr8); - matrix m20(arr11); - matrix m21(arr12); - matrix m22(arr15); - matrix m9(arr9); - - cout << "Constructor Test\n"; - cout << "\n" << m6; - - cout << "\n\nAddition\n"; - m6 = m10 + m15; - m13 = m11 + m11; - cout << "\n" << m10 << "\n" << m15; - cout << "\nSum:\n" << m6 << endl; - cout << "\n" << m11 << "\n" << m11; - cout << "\nSum:\n" << m13 << endl; - - cout << "\n\n\nSubtraction\n"; - m6 = m10 - m12; - cout << "\n" << m10 << "\n" << m12; - cout << "\nDifference:\n" << m6 << endl; - - cout << "\n\n\nMultiplication\n"; - m6 = m10 * m12; - m3 = m1 * m2; - matrix m7; - m7 = m20 * m21; - cout << "\n" << m10 << "\n" << m12; - cout << "\nProduct:\n" << m6 << endl; - cout << "\n" << m1 << "\n" << m2; - cout << "\nProduct:\n" << m3 << endl; - cout << "\n" << m20 << "\n" << m21; - cout << "\nProduct:\n" << m7 << endl; - cout << "\n" << m9 << "\n" << m21; - m21 = m9 * m21; - cout << "\nProduct:\n" << m21 << endl; - - cout << "\n\n\nDivision\n"; - m3 = m1 / (float)2.5; - cout << "\n" << m1 << "\n" << "2.5"; - cout << "\nResult:\n" << m3 << endl; - m6 = m12 / (float)0.125; - cout << "\n" << m12 << "\n" << ".125"; - cout << "\nResult:\n" << m6 << endl; - - float num = 5.5650; - float num1 = -2.32; - cout << "\n\n\nScalar addition\n"; - m3 = m2 + num; - m6 = m10 + num1; - cout << "\nNumber added:" << num; - cout << "\n\n" << m2; - cout << "\nResult:\n\n" << m3; - cout << "\nNumber added:" << num1; - cout << "\n\n" << m10; - cout << "\nResult:\n\n" << m6; - - float x = 4.0; - float x1 = -2.5; - cout << "\n\n\nScalar subtraction\n"; - m13 = m11 - x; - m6 = m10 - x1; - cout << "\nNumber Subtracted:" << x; - cout << "\n\n" << m11; - cout << "\nResult:\n\n" << m13; - cout << "\nNumber Subtracted:" << x1; - cout << "\n\n" << m10; - cout << "\nResult:\n\n" << m6; - - float z = 3.50; - float z1 = -5.567; - cout << "\n\n\nScalar multiplication\n"; - m3 = m1 * z; - m6 = m12 * z1; - cout << "\nNumber Multiplied:" << z; - cout << "\n\n" << m1; - cout << "\nResult:\n\n" << m3; - cout << "\nNumber Multiplied:" << z1; - cout << "\n\n" << m12; - cout << "\nResult:\n\n" << m6; - - m6 = tran(m15); - cout << "\n\n\nTranspose:"; - cout << "\n\n" << m15; - cout << "\nResult:\n\n" << m6; - - cout << "\n\nm1:\n\n" << m1; - cout << "\n\nm2:\n\n" << m2; - cout << "\n\n\nm1 == m2 :"; - cout << (m1 == m2); - - cout << "\n\nm2:\n\n" << m2; - cout << "\n\nm2:\n\n" << m2; - cout << "\n\n\nm2 == m2 :"; - cout << (m2 == m2); - - cout << "\n\nm6:\n\n" << m6; - cout << "\n\nm6:\n\n" << m6; - cout << "\n\n\nm6 != m6 :"; - cout << (m6 != m6); - - cout << "\n\nm6:\n\n" << m6; - cout << "\n\nm1:\n\n" << m1; - cout << "\n\n\nm6 != m1 :"; - cout << (m6 != m1); - - - cout << "\n\nAssignment\n"; - matrix m30 = m12; - cout << "Input \n" << m12; - cout << "\nOutput:\n" << m30 << endl; -} diff --git a/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp deleted file mode 100644 index d0a41fd..0000000 --- a/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../orientation_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define ORIENTATION_DATA_PATH "../../../design/data/100ms/orientation/roll_pitch_yaw/" -#define ORIENTATION_DATA_SIZE 1095 -int pitch_phase_compensation = -1; -int roll_phase_compensation = -1; -int azimuth_phase_compensation = -1; - -int main() -{ - int data_available = ORIENTATION_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream orien_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - euler_angles orientation; - rotation_matrix orientation_mat; - quaternion orientation_9axis_quat; - quaternion orientation_geomagnetic_quat; - quaternion orientation_gaming_quat; - orientation_sensor orien_sensor; - - accel_in.open(((string)ORIENTATION_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)ORIENTATION_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)ORIENTATION_DATA_PATH + (string)"magnetic.txt").c_str()); - - orien_file.open(((string)"orientation.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - orien_sensor.get_device_orientation(&accel_data, &gyro_data, &magnetic_data); - - orientation = orien_sensor.orien_filter.m_orientation; - - cout << "Gyro Bias in radians\t" << orien_sensor.orien_filter.m_gyro_bias; - - orientation = rad2deg(orientation); - - orientation.m_ang.m_vec[0] *= pitch_phase_compensation; - orientation.m_ang.m_vec[1] *= roll_phase_compensation; - orientation.m_ang.m_vec[2] *= azimuth_phase_compensation; - - if (orientation.m_ang.m_vec[2] < 0) - orientation.m_ang.m_vec[2] += 360; - - orien_file << orientation.m_ang; - - orientation = orien_sensor.orien_filter.m_orientation; - - cout << "Orientation angles\t" << orientation.m_ang << "\n\n"; - - cout << "Orientation matrix\t" << orien_sensor.orien_filter.m_rot_matrix.m_rot_mat << "\n\n"; - - cout << "Orientation 9-axis quaternion\t" << orien_sensor.orien_filter.m_quat_9axis.m_quat << "\n\n"; - - cout << "Orientation geomagnetic quaternion\t" << orien_sensor.orien_filter.m_quat_aid.m_quat << "\n\n"; - - cout << "Orientation gaming quaternion\t" << orien_sensor.orien_filter.m_quat_gaming_rv.m_quat << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - orien_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp b/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp deleted file mode 100644 index f437d6c..0000000 --- a/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../quaternion.h" - -int main() -{ - float arr0[4] = {2344.98, 345.24, 456.12, 98.33}; - float arr1[4] = {0.056, 0.34, -0.0076, 0.001}; - float axis1[3] = {6.5, 7.5, 8.3}; - float ang1 = 8.4; - - vect v0(arr0); - vect v1(arr1); - vect v2(axis1); - - quaternion q0(v0); - quaternion q1(v1); - quaternion q2((float)2344.98, (float)345.24, (float)456.12, (float)98.33); - quaternion q3(q1); - quaternion q4; - - cout << "Constructor tests\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << q0.m_quat << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << q1.m_quat << "\n\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << q2.m_quat << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << q3.m_quat << "\n\n"; - cout << "default constructor\n"; - cout << "output\t" << q4.m_quat << "\n\n"; - - cout << "Multiplication\n"; - float val = 0.1; - quaternion q5 = q0 * val; - cout << "input\t" << q0.m_quat << "\n" << 0.1 << "\n"; - cout << "output\t" << q5.m_quat << "\n\n"; - quaternion q6 = q0 * q1; - cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n"; - cout << "output\t" << q6.m_quat << "\n\n"; - - cout << "Addition\n"; - quaternion q7 = q0 + q1; - cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n"; - cout << "output\t" << q7.m_quat << "\n\n"; - - cout << "Quaternion Normalization\n"; - cout << "input\t" << q1.m_quat << "\n"; - q1.quat_normalize(); - cout << "output\t" << q1.m_quat << "\n\n"; - - cout << "Axis2quat\n"; - cout << "input\t" << " " << v2 << endl; - cout << endl; - quaternion q11 = axis2quat(v2, ang1); - cout << "output\t" << q11.m_quat << "\n\n"; - cout << endl; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp b/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp deleted file mode 100644 index 9ab8c35..0000000 --- a/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../rotation_matrix.h" - -int main() -{ - float arr1[3][3] = {{20.2, 40.5, 10.0}, {3.6, 52.0, 5.5}, {1.0, 45.5, 66.6}}; - float arr2[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - float arr3[3][3] = {{4.75, 0.65, 0.123}, {0.075, 5.302, 0.56}, {1.113, 0.475, 2.362}}; - - matrix m1(arr1); - matrix m2(arr2); - matrix m3(arr3); - - rotation_matrix rm0, rm5; - rotation_matrix rm1(m1); - rotation_matrix rm2(m2); - rotation_matrix rm3(m3); - rotation_matrix rm4(arr1); - - quaternion q0(-0.612372, 0.456436, 0.456436, 0.456436); - quaternion q1; - - cout << "Constructor tests\n"; - cout << "input\n" << m1 << "\n"; - cout << "output\n" << rm1.m_rot_mat << "\n\n"; - cout << "input\n" << m2 << "\n"; - cout << "output\n" << rm2.m_rot_mat << "\n\n"; - cout << "input\n" << m3 << "\n"; - cout << "output\n" << rm3.m_rot_mat << "\n\n"; - cout << "input\n" << m1 << "\n"; - cout << "output\n" << rm4.m_rot_mat << "\n\n"; - cout << "default constructor\n"; - cout << "output\n" << rm0.m_rot_mat << "\n\n"; - - cout << "Quaternion to Rotation Matrix\n"; - cout << "input\n" << q0.m_quat << "\n"; - rm0 = quat2rot_mat(q0); - cout << "output\n" << rm0.m_rot_mat << "\n\n"; - - cout << "Rotation Matrix to Quaternion\n"; - cout << "input\n" << rm0.m_rot_mat << "\n"; - q1 = rot_mat2quat(rm0); - cout << "output\n" << q1.m_quat << "\n\n"; -} diff --git a/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp b/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp deleted file mode 100644 index 526bda4..0000000 --- a/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../sensor_data.h" - -int main() -{ - float arr1[3] = {1.04, -4.678, -2.34}; - float arr2[3] = {0, 0, 1}; - vect v1(arr1); - vect v2(arr2); - - sensor_data sd1(2.0, 3.0, 4.0, 140737488355328); - sensor_data sd2(1.04, -4.678, -2.34, 0); - sensor_data sd3(0.054, 1.097, 4.456, 140737488355328); - - sensor_data sd10(v1, 140737488355328); - sensor_data sd11(0.2, 0.1, 0.3, 140737488355328); - - cout << "Constructor tests\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << sd10.m_data << "\t" << sd10.m_time_stamp << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << sd2.m_data << "\t" << sd2.m_time_stamp << "\n\n"; - - cout << "Addition:\n"; - sensor_data sd4 = sd1 + sd2; - cout << "\n" << sd1.m_data << "\n" << sd2.m_data; - cout << "\nSum:\n" << sd4.m_data << endl; - sensor_data sd9 = sd1 + sd10; - cout << "\n" << sd1.m_data << "\n" << sd10.m_data; - cout << "\nSum:\n" << sd9.m_data << endl; - - cout << "\n\n\nNormalization:\n"; - cout << "\n" << sd3.m_data; - normalize(sd3); - cout << "\nResult:\n" << sd3.m_data << endl; - cout << "\n" << sd2.m_data; - normalize(sd2); - cout << "\nResult:\n" << sd2.m_data << endl; - - float xx = 2.5; - cout << "\n\n\nScale data:\n"; - sensor_data sd8 = scale_data(sd2, xx); - cout << "\n" << sd2.m_data << "\n" << xx; - cout << "\nResult:\n" << sd8.m_data << endl; - - cout << "\n\n\nConvert Sensor Data to Quaternion:\n"; - quaternion q = sensor_data2quat(sd11, v2); - cout << "\n" << sd11.m_data << "\n" << v2; - cout << "\nResult:\n" << q.m_quat << endl; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp b/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp deleted file mode 100644 index 2a81f83..0000000 --- a/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 "../../../vector.h" - -int main() -{ - float arr2[3] = {0.056, 2.34, -65.76}; - float arr15[3] = {1.04, -4.678, -2.34}; - float arr3[4] = {1.03, 2.345, 6.78, 5.55}; - float arr4[4] = {-6.78, -45.213, -7.89, -3.456}; - float arr8[5] = {0.0123, 5.678, 2.345, 0.345, 8.956}; - float arr0[5] = {2344.98, 345.24, 456.12, 98.33, 144.67}; - float arr1[6] = {1.234, 4.5, 6.8987, 3.33, 5.66, 77.695}; - float arr43[6] = {2.3454, -0.0384, -8.90, 3.455, 6.785, 21.345}; - float arr5[5] = {0.2, -0.4, 0.6, -0.8, 1.0}; - - vect v1(arr0); - vect v2(arr8); - vect v10(arr3); - vect v12(arr4); - vect v15(arr1); - vect v20(arr43); - vect v21(arr2); - vect v22(arr15); - vect v31(arr0); - vect v3; - vect vn; - vect v61(arr4); - vect v6; - vect vm; - vect v13; - vect v95; - vect v35(arr5); - vect vl; - vect vp; - vect vr(arr4); - vect vf; - - float arr57[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - matrix m12(arr57); - float arr67[3][1] = {{2.0}, {3.0}, {4.0}}; - matrix m32(arr67); - - cout << "Constructor Test\n"; - cout << "\n" << v3; - - cout << "\n\nAddition\n"; - v3 = v21 + v22; - v95 = v15 + v20; - cout << "\n\nNumbers added\n"; - cout << "\n" << v21 << "\n" << v22; - cout << "\nSum:\n" << v3 << endl; - cout << "\n\nNumbers added\n"; - cout << "\n" << v15 << "\n" << v20; - cout << "\nSum:\n" << v95 << endl; - - float num = 5.5650; - float num1 = -2.32; - cout << "\n\n\nScalar addition\n"; - vl = v2 + num; - vm = v10 + num1; - cout << "\nNumber added:" << num; - cout << "\n\n" << v2; - cout << "\nResult:\n\n" << vl; - cout << "\nNumber added:" << num1; - cout << "\n\n" << v10; - cout << "\nResult:\n\n" << vm; - - cout << "\n\n\nSubtraction\n"; - vp = v10 - v12; - cout << "\n" << v10 << "\n" << v12; - cout << "\nDifference:\n" << vp << endl; - - float x = 4.0; - float x1 = -2.5; - cout << "\n\n\nScalar subtraction\n"; - v13 = v1 - x; - vp = v10 - x1; - cout << "\nNumber Subtracted:" << x; - cout << "\n\n" << v1; - cout << "\nResult:\n\n" << v13; - cout << "\nNumber Subtracted:" << x1; - cout << "\n\n" << v10; - cout << "\nResult:\n\n" << vp; - - float xx = 7.2; - cout << "\n\n\nMultiplication\n"; - v13 = v2 * xx; - cout << "\n" << v2 << "\n" << xx; - cout << "\nProduct:\n" << v13 << endl; - - cout << "\n\n\nMultiplication matrix x vector:\n"; - matrix m102 = m32 * v22; - cout << "\n" << m32 << "\n" << v22; - cout << "\nProduct:\n" << m102 << endl; - - cout << "\n\n\nVector x Multiplication matrix:\n"; - vect v102 = (v22 * m12); - cout << "\n" << v22 << "\n" << m12; - cout << "\nProduct:\n" << v102 << endl; - - float z = 3.50; - float z1 = -5.567; - cout << "\n\n\nScalar multiplication\n"; - v13 = v1 * z; - v61 = v12 * z1; - cout << "\nNumber Multiplied:" << z; - cout << "\n\n" << v1; - cout << "\nResult:\n\n" << v13; - cout << "\nNumber Multiplied:" << z1; - cout << "\n\n" << v12; - cout << "\nResult:\n\n" << v6; - - float num2 = 5.5; - cout << "\n\n\nDivision\n"; - v31 = v1 / num2; - cout << "\n" << v1 << "\n" << num2; - cout << "\nResult:\n" << v3 << endl; - - cout << "\n\n\nTranspose:"; - cout << "\n\n" << v20; - cout << "\nResult:\n\n"; - matrix m101 = transpose(v20); - cout << m101; - cout << "\n\n" << m101; - cout << "\nResult:\n\n"; - v20 = transpose(m101); - cout << v20; - - cout << "\n\nv1:\n\n" << v1; - cout << "\n\nv2:\n\n" << v2; - cout << "\n\n\nv1 == v2 :"; - cout << (v1 == v2); - - cout << "\n\nv10:\n\n" << v10; - cout << "\n\nv10:\n\n" << v10; - cout << "\n\n\nv10 == v10 :"; - cout << (v10 == v10); - - cout << "\n\nv12:\n\n" << v12; - cout << "\n\nv15:\n\n" << vr; - cout << "\n\n\nv12 != v15 :"; - cout << (v12 != vr); - - cout << "\n\nv15:\n\n" << v15; - cout << "\n\nv15:\n\n" << v15; - cout << "\n\n\nv15 != v15 :"; - cout << (v15 != v15); - - cout << "\n\nAssignment\n"; - v3 = vf; - cout << "Input \n" << v1; - cout << "\nOutput:\n" << v3 << endl; - - vect v111 = cross(v21, v22); - cout << "\n\n\nCross Product:"; - cout << "\n\n" << v21 << "\n\n" << v22; - cout << "\nResult:\n\n" << v111; - - float val = dot(v21, v22); - cout << "\n\n\nDot Product:"; - cout << "\n\n" << v21 << "\n\n" << v22; - cout << "\nResult:\n\n" << val; - - cout << "\n\n\nQueue insert function:"; - cout << "\nInput:\n\n" << v111; - insert_end(v111, (float) 0.9191919); - cout << "\nResult:\n\n" << v111; - - cout << "\n\n\nVariance:"; - cout << "\nInput:\n\n" << v35; - val = var(v35); - cout << "\nResult:\n\n" << val; - - cout << "\n\n\nIs Initialized:"; - cout << "\nInput:\n\n" << v35; - cout << "\nResult:\n\n" << is_initialized(v35) << endl; -} - -- 2.7.4 From 00782e26f24f88a8895ee54587bf718fc2ae0bab Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:30:02 +0900 Subject: [PATCH 02/16] sensord: enable rotation vector/orientation sensors Change-Id: I60368ad616e34f17107565c6014135a4aeb4aacb Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 12 ++ src/sensor/create.cpp | 18 ++ src/sensor/orientation/orientation_sensor.cpp | 180 ++++-------------- src/sensor/orientation/orientation_sensor.h | 41 +--- src/sensor/rotation_vector/fusion_base.cpp | 9 +- src/sensor/rotation_vector/fusion_base.h | 2 +- src/sensor/rotation_vector/gyro_fusion.h | 2 +- src/sensor/rotation_vector/gyro_magnetic_fusion.h | 2 +- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 204 ++++++-------------- src/sensor/rotation_vector/gyro_rv_sensor.h | 34 +--- src/sensor/rotation_vector/magnetic_fusion.h | 2 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 204 ++++++-------------- src/sensor/rotation_vector/magnetic_rv_sensor.h | 34 +--- src/sensor/rotation_vector/rv_sensor.cpp | 220 ++++++---------------- src/sensor/rotation_vector/rv_sensor.h | 41 +--- 15 files changed, 277 insertions(+), 728 deletions(-) diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 227698b..9735d8d 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -5,6 +5,8 @@ INCLUDE(GNUInstallDirs) SET(AUTO_ROTATION "ON") SET(GRAVITY "ON") SET(LINEAR_ACCEL "ON") +SET(RV "ON") +SET(ORIENTATION "ON") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared @@ -47,6 +49,16 @@ FILE(GLOB_RECURSE SRCS ${SRCS} linear_accel/*.cpp) ADD_DEFINITIONS(-DENABLE_LINEAR_ACCEL) ENDIF() +IF("${RV}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} rotation_vector/*.cpp) +ADD_DEFINITIONS(-DENABLE_ROTATION_VECTOR) +ENDIF() + +IF("${ORIENTATION}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} orientation/*.cpp) +ADD_DEFINITIONS(-DENABLE_ORIENTATION) +ENDIF() + MESSAGE("Sources: ${SRCS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS}) diff --git a/src/sensor/create.cpp b/src/sensor/create.cpp index 10dd21f..0dd39b5 100644 --- a/src/sensor/create.cpp +++ b/src/sensor/create.cpp @@ -29,6 +29,14 @@ #ifdef ENABLE_LINEAR_ACCEL #include "linear_accel/linear_accel_sensor.h" #endif +#ifdef ENABLE_ROTATION_VECTOR +#include "rotation_vector/rv_sensor.h" +#include "rotation_vector/magnetic_rv_sensor.h" +#include "rotation_vector/gyro_rv_sensor.h" +#endif +#ifdef ENABLE_ORIENTATION +#include "orientation/orientation_sensor.h" +#endif static std::vector sensors; @@ -64,6 +72,16 @@ extern "C" int create(fusion_sensor_t **fsensors) create_sensor("Linear Acceleration Sensor"); #endif +#ifdef ENABLE_ROTATION_VECTOR + create_sensor("Rotation Vector Sensor"); + create_sensor("Magnetic Rotation Vector Sensor"); + create_sensor("Gyroscope Rotation Vector Sensor"); +#endif + +#ifdef ENABLE_ORIENTATION + create_sensor("Orientation Sensor"); +#endif + *fsensors = &sensors[0]; return sensors.size(); } diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index c9cad8b..393ec9a 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -17,136 +17,83 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "orientation_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_ORIENTATION" +#define NAME_SENSOR "http://tizen.org/sensor/orientation/orientation" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_RV 0x1 +#define SRC_STR_RV "http://tizen.org/sensor/rotation_vector" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: ORIENTATION_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -180, + max_range: 360, + resolution: 0.01, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_RV, SRC_STR_RV}, +}; + orientation_sensor::orientation_sensor() -: m_rotation_vector_sensor(NULL) -, m_azimuth(-1) +: m_azimuth(-1) , m_pitch(-1) , m_roll(-1) , m_accuracy(-1) , m_time(0) +, m_interval(0) { } orientation_sensor::~orientation_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool orientation_sensor::init(void) -{ - m_rotation_vector_sensor = sensor_loader::get_instance().get_sensor(ROTATION_VECTOR_SENSOR); - - if (!m_rotation_vector_sensor) { - _W("cannot load sensor[%s]", SENSOR_NAME); - return false; - } - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t orientation_sensor::get_type(void) -{ - return ORIENTATION_SENSOR; } -unsigned int orientation_sensor::get_event_type(void) +int orientation_sensor::get_sensor_info(const sensor_info2_t **info) { - return ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME; + *info = &sensor_info; + return OP_SUCCESS; } -const char* orientation_sensor::get_name(void) +int orientation_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 1; } -bool orientation_sensor::get_sensor_info(sensor_info &info) -{ - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(-180); - info.set_max_range(360); - info.set_resolution(0.01); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void orientation_sensor::synthesize(const sensor_event_t& event) +int orientation_sensor::update(uint32_t id, sensor_data_t *data, int len) { int error; - sensor_event_t *orientation_event; float azimuth, pitch, roll; - if (CONVERT_ID_TYPE(event.sensor_id) != ROTATION_VECTOR_SENSOR) - return; - - error = quat_to_orientation(event.data->values, azimuth, pitch, roll); - ret_if(error); - - orientation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!orientation_event) { - _E("Failed to allocate memory"); - return; - } - orientation_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!orientation_event->data) { - _E("Failed to allocate memory"); - free(orientation_event); - return; - } - - orientation_event->sensor_id = get_id(); - orientation_event->event_type = CONVERT_TYPE_EVENT(ORIENTATION_SENSOR); - orientation_event->data_length = sizeof(sensor_data_t); - orientation_event->data->accuracy = event.data->accuracy; - orientation_event->data->timestamp = event.data->timestamp; - orientation_event->data->value_count = 3; - orientation_event->data->values[0] = azimuth; - orientation_event->data->values[1] = pitch; - orientation_event->data->values[2] = roll; - push(orientation_event); + error = quat_to_orientation(data->values, azimuth, pitch, roll); + retv_if(error, OP_ERROR); m_azimuth = azimuth; m_pitch = pitch; m_roll = roll; - m_time = event.data->timestamp; - m_accuracy = event.data->accuracy; + m_time = data->timestamp; + m_accuracy = data->accuracy; _D("[orientation] : [%10f] [%10f] [%10f]", m_azimuth, m_pitch, m_roll); + return OP_SUCCESS; } int orientation_sensor::get_data(sensor_data_t **data, int *length) { - /* if It is batch sensor, remains can be 2+ */ - int remains = 1; - sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); @@ -160,52 +107,5 @@ int orientation_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return --remains; -} - -bool orientation_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool orientation_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool orientation_sensor::on_start(void) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->start(); - - m_time = 0; - - return activate(); -} - -bool orientation_sensor::on_stop(void) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->stop(); - - m_time = 0; - - return deactivate(); -} - -bool orientation_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool orientation_sensor::delete_interval(int client_id, bool is_processor) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); + return 1; } diff --git a/src/sensor/orientation/orientation_sensor.h b/src/sensor/orientation/orientation_sensor.h index 4e5f4c3..03de5b0 100644 --- a/src/sensor/orientation/orientation_sensor.h +++ b/src/sensor/orientation/orientation_sensor.h @@ -17,53 +17,30 @@ * */ -#ifndef _ORIENTATION_SENSOR_H_ -#define _ORIENTATION_SENSOR_H_ +#ifndef __ORIENTATION_SENSOR_H__ +#define __ORIENTATION_SENSOR_H__ -#include +#include #include -#include -class orientation_sensor : public virtual_sensor { +class orientation_sensor : public fusion_sensor { public: orientation_sensor(); virtual ~orientation_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_rotation_vector_sensor; - float m_azimuth; float m_pitch; float m_roll; int m_accuracy; unsigned long long m_time; unsigned long m_interval; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); - - int rotation_to_orientation(const float *rotation, float &azimuth, float &pitch, float &roll); }; -#endif /* _ORIENTATION_SENSOR_H_ */ +#endif /* __ORIENTATION_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 89b5a44..ad92d2a 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include "fusion_base.h" @@ -35,13 +33,16 @@ fusion_base::fusion_base() : m_enable_accel(false) , m_enable_gyro(false) , m_enable_magnetic(false) +, m_x(0) +, m_y(0) +, m_z(0) +, m_w(0) +, m_timestamp(0) { - _I("fusion_base is created!"); } fusion_base::~fusion_base() { - _I("fusion_sensor is destroyed!"); } void fusion_base::clear(void) diff --git a/src/sensor/rotation_vector/fusion_base.h b/src/sensor/rotation_vector/fusion_base.h index 3af7c91..96a3301 100644 --- a/src/sensor/rotation_vector/fusion_base.h +++ b/src/sensor/rotation_vector/fusion_base.h @@ -19,7 +19,7 @@ #ifndef __FUSION_BASE_H__ #define __FUSION_BASE_H__ -#include +#include "fusion.h" #include "fusion_utils/orientation_filter.h" class fusion_base : public virtual fusion { diff --git a/src/sensor/rotation_vector/gyro_fusion.h b/src/sensor/rotation_vector/gyro_fusion.h index 0089e0d..9139e0d 100644 --- a/src/sensor/rotation_vector/gyro_fusion.h +++ b/src/sensor/rotation_vector/gyro_fusion.h @@ -20,7 +20,7 @@ #ifndef __GYRO_FUSION_H__ #define __GYRO_FUSION_H__ -#include +#include "fusion_base.h" class gyro_fusion : public fusion_base { public: diff --git a/src/sensor/rotation_vector/gyro_magnetic_fusion.h b/src/sensor/rotation_vector/gyro_magnetic_fusion.h index 54bf75c..b95aafd 100644 --- a/src/sensor/rotation_vector/gyro_magnetic_fusion.h +++ b/src/sensor/rotation_vector/gyro_magnetic_fusion.h @@ -20,7 +20,7 @@ #ifndef __GYRO_MAGNETIC_FUSION_H__ #define __GYRO_MAGNETIC_FUSION_H__ -#include +#include "fusion_base.h" class gyro_magnetic_fusion : public fusion_base { public: diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 7c7c9b3..3a738d0 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -17,143 +17,89 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include "gyro_rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_GYROSCOPE_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/gyro_rotation_vector/gyro_rv" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GYRO 0x2 +#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GYROSCOPE_RV_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GYRO, SRC_STR_GYRO}, +}; gyro_rv_sensor::gyro_rv_sensor() -: m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } gyro_rv_sensor::~gyro_rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool gyro_rv_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); - - if (!m_accel_sensor || !m_gyro_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t gyro_rv_sensor::get_type(void) -{ - return GYROSCOPE_RV_SENSOR; } -unsigned int gyro_rv_sensor::get_event_type(void) +int gyro_rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* gyro_rv_sensor::get_name(void) +int gyro_rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 2; } -bool gyro_rv_sensor::get_sensor_info(sensor_info &info) +int gyro_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void gyro_rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_gyro(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_GYRO) + m_fusion.push_gyro(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if(timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int gyro_rv_sensor::get_data(sensor_data_t **data, int *length) @@ -163,58 +109,14 @@ int gyro_rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool gyro_rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool gyro_rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool gyro_rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_gyro_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool gyro_rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_gyro_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool gyro_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_gyro_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool gyro_rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_gyro_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.h b/src/sensor/rotation_vector/gyro_rv_sensor.h index 052f0e3..c6c16b1 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.h +++ b/src/sensor/rotation_vector/gyro_rv_sensor.h @@ -20,36 +20,22 @@ #ifndef __GYRO_RV_SENSOR_H__ #define __GYRO_RV_SENSOR_H__ -#include +#include #include -#include +#include "gyro_fusion.h" -class gyro_rv_sensor : public virtual_sensor { +class gyro_rv_sensor : public fusion_sensor { public: gyro_rv_sensor(); virtual ~gyro_rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; gyro_fusion m_fusion; float m_x; @@ -59,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; #endif /* __GYRO_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/magnetic_fusion.h b/src/sensor/rotation_vector/magnetic_fusion.h index 41758ea..e5aca7e 100644 --- a/src/sensor/rotation_vector/magnetic_fusion.h +++ b/src/sensor/rotation_vector/magnetic_fusion.h @@ -20,7 +20,7 @@ #ifndef __MAGNETIC_FUSION_H__ #define __MAGNETIC_FUSION_H__ -#include +#include "fusion_base.h" class magnetic_fusion: public fusion_base { public: diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 61001c1..66c8808 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -17,143 +17,89 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include "magnetic_rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_MAGNETIC_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/mag_rotation_vector/mag_rv" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_MAG 0x3 +#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GEOMAGNETIC_RV_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_MAG, SRC_STR_MAG}, +}; magnetic_rv_sensor::magnetic_rv_sensor() -: m_accel_sensor(NULL) -, m_mag_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } magnetic_rv_sensor::~magnetic_rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool magnetic_rv_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - if (!m_accel_sensor || !m_mag_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t magnetic_rv_sensor::get_type(void) -{ - return GEOMAGNETIC_RV_SENSOR; } -unsigned int magnetic_rv_sensor::get_event_type(void) +int magnetic_rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* magnetic_rv_sensor::get_name(void) +int magnetic_rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 2; } -bool magnetic_rv_sensor::get_sensor_info(sensor_info &info) +int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void magnetic_rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_mag(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_MAG) + m_fusion.push_mag(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if (timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length) @@ -163,58 +109,14 @@ int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool magnetic_rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool magnetic_rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool magnetic_rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_mag_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool magnetic_rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_mag_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool magnetic_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_mag_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool magnetic_rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_mag_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.h b/src/sensor/rotation_vector/magnetic_rv_sensor.h index 34b5d49..cc6ee79 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.h +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.h @@ -20,36 +20,22 @@ #ifndef __MAGNETIC_RV_SENSOR_H__ #define __MAGNETIC_RV_SENSOR_H__ -#include +#include #include -#include +#include "magnetic_fusion.h" -class magnetic_rv_sensor : public virtual_sensor { +class magnetic_rv_sensor : public fusion_sensor { public: magnetic_rv_sensor(); virtual ~magnetic_rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_mag_sensor; magnetic_fusion m_fusion; float m_x; @@ -59,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; #endif /* __MAGNETIC_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 9fb42c7..6d69cda 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -17,149 +17,95 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/rotation_vector" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GYRO 0x2 +#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" + +#define SRC_ID_MAG 0x3 +#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: ROTATION_VECTOR_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GYRO, SRC_STR_GYRO}, + {SRC_ID_MAG, SRC_STR_MAG}, +}; rv_sensor::rv_sensor() -: m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_mag_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } rv_sensor::~rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool rv_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); - m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - if (!m_accel_sensor || !m_gyro_sensor|| !m_mag_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t rv_sensor::get_type(void) -{ - return ROTATION_VECTOR_SENSOR; } -unsigned int rv_sensor::get_event_type(void) +int rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* rv_sensor::get_name(void) +int rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 3; } -bool rv_sensor::get_sensor_info(sensor_info &info) +int rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_mag(*(event.data)); - else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_gyro(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_MAG) + m_fusion.push_mag(*data); + else if (id == SRC_ID_GYRO) + m_fusion.push_gyro(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if (timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int rv_sensor::get_data(sensor_data_t **data, int *length) @@ -169,62 +115,14 @@ int rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_gyro_sensor->start(); - m_mag_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_gyro_sensor->stop(); - m_mag_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_gyro_sensor->add_interval(client_id, interval, true); - m_mag_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_gyro_sensor->delete_interval(client_id, true); - m_mag_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/rv_sensor.h b/src/sensor/rotation_vector/rv_sensor.h index db23d01..0e06370 100644 --- a/src/sensor/rotation_vector/rv_sensor.h +++ b/src/sensor/rotation_vector/rv_sensor.h @@ -17,40 +17,25 @@ * */ -#ifndef _ROTATION_VECTOR_SENSOR_H_ -#define _ROTATION_VECTOR_SENSOR_H_ +#ifndef __ROTATION_VECTOR_SENSOR_H__ +#define __ROTATION_VECTOR_SENSOR_H__ -#include +#include #include -#include +#include "gyro_magnetic_fusion.h" -class rv_sensor : public virtual_sensor { +class rv_sensor : public fusion_sensor { public: rv_sensor(); virtual ~rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; - sensor_base *m_mag_sensor; gyro_magnetic_fusion m_fusion; float m_x; @@ -60,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; -#endif /* _ROTATION_VECTOR_SENSOR_H_ */ +#endif /* __ROTATION_VECTOR_SENSOR_H__ */ -- 2.7.4 From 4a604f34e0801e1ce2c414305b806cec65386fe5 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:30:48 +0900 Subject: [PATCH 03/16] sensord: use emplace_back instead of push_back Change-Id: I812a34b162a982dfa1ba7033bcb35e758d8d71dd Signed-off-by: kibak.yoon --- src/sensorctl/test_bench.cpp | 4 +--- src/server/sensor_loader.cpp | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp index 201a7f5..3b9cd51 100644 --- a/src/sensorctl/test_bench.cpp +++ b/src/sensorctl/test_bench.cpp @@ -133,9 +133,7 @@ void test_bench::add_testcase(const std::string &group, test_case *testcase) void test_bench::add_failure(const std::string &function, long line, const std::string &msg) { - test_result fail(function, line, msg); - - results.push_back(fail); + results.emplace_back(function, line, msg); m_failure_count++; } diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 4d1d20e..9ea7e7f 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -73,7 +73,6 @@ bool sensor_loader::load(const std::string &dir_path, std::vector module_paths; void **results; - T *sensor; ret = get_module_paths(dir_path, module_paths); retv_if(!ret, false); @@ -97,11 +96,8 @@ bool sensor_loader::load(const std::string &dir_path, std::vector(results[i]); - std::shared_ptr sensor_ptr(sensor); - sensors.push_back(sensor_ptr); - } + for (int i = 0; i < size; ++i) + sensors.emplace_back(static_cast(results[i])); m_modules[path.c_str()] = handle; } -- 2.7.4 From 83e771e00fbd3ffd2cd36e7f4966103da1ce338b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:31:56 +0900 Subject: [PATCH 04/16] sensord: use underscore(_) instead of dot(.) for URI string - [TBD] discuss what is the better Change-Id: I6c41cc4eca22062159734ebfae422f9da0ce7c04 Signed-off-by: kibak.yoon --- src/shared/sensor_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 6ef0504..817eb31 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -52,13 +52,13 @@ static std::map types = { {TEMPERATURE_SENSOR, "http://tizen.org/sensor/temperature"}, {HUMIDITY_SENSOR, "http://tizen.org/sensor/humidity"}, {HRM_SENSOR, "http://tizen.org/sensor/heart_rate_monitor"}, - {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/hrm.led_green"}, - {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/hrm.led_ir"}, - {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/hrm.led_red"}, - {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/gyroscope.uncalibrated"}, - {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/geomagnetic.uncalibrated"}, - {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/rotation_vector.gyroscope"}, - {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/rotation_vector.geomagnetic"}, + {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/hrm_led_green"}, + {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/hrm_led_ir"}, + {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/hrm_led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/gyro_uncalibrated"}, + {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/mag_uncalibrated"}, + {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/gyro_rotation_vector"}, + {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/mag_rotation_vector"}, {HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/human_pedometer"}, {HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/human_sleep_monitor"}, -- 2.7.4 From 877af40d645dc7aa3b07f1db55a14f82ba08a095 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:42:10 +0900 Subject: [PATCH 05/16] sensord: return the appropriate error Change-Id: I953af6979592f003b7967898f2389b782b562f63 Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 4be1065..7d5197f 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -104,11 +104,7 @@ int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count) infos = get_infos(uri); size = infos.size(); - - if (size == 0) { - *count = 0; - return -ENODATA; - } + retv_if(size == 0, -EACCES); *list = (sensor_t *)malloc(sizeof(sensor_info *) * size); retvm_if(!*list, -ENOMEM, "Failed to allocate memory"); -- 2.7.4 From eff2a8e3c95b2a8c68703724d842034070c9887c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:51:14 +0900 Subject: [PATCH 06/16] sensord: use int32_t instead size_t - compatibility with 64bit platform Change-Id: I16299dfe15418492506063ce6572e7cdf9502127 Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 7d5197f..2d14a4d 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -220,22 +220,22 @@ void sensor_manager::decode_sensors(const char *buf, std::vector &i { int count = 0; sensor_info info; - const size_t *size; + const int32_t *size; const char *data; cmd_manager_sensor_list_t *raw; raw = (cmd_manager_sensor_list_t *)buf; count = raw->sensor_cnt; - size = (const size_t *)raw->data; - data = (const char *)raw->data + sizeof(size_t); + size = (const int32_t *)raw->data; + data = (const char *)raw->data + sizeof(int32_t); for (int i = 0; i < count; ++i) { info.clear(); info.deserialize(data, size[0]); infos.push_back(info); - size = (const size_t *)((const char *)data + size[0]); - data = (const char *)size + sizeof(size_t); + size = (const int32_t *)((const char *)data + size[0]); + data = (const char *)size + sizeof(int32_t); } _D("Sensor count : %d", count); -- 2.7.4 From 0c29aefea18c854e60b089f7550693e0de42c530 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:53:52 +0900 Subject: [PATCH 07/16] sensord: add required privilege to pre-defined types Change-Id: I0f08ad04497fa544318b1bd57dc7a2af470fa99a Signed-off-by: kibak.yoon --- src/server/physical_sensor_handler.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index 00cf361..0fa3a2d 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -34,6 +34,21 @@ physical_sensor_handler::physical_sensor_handler(const sensor_info &info, , m_sensor(sensor) , m_hal_id(hal_id) { + /* TODO: temporary walkaround */ + switch (m_info.get_type()) { + case HRM_SENSOR: + case HRM_LED_GREEN_SENSOR: + case HRM_LED_IR_SENSOR: + case HRM_LED_RED_SENSOR: + case HUMAN_PEDOMETER_SENSOR: + case HUMAN_SLEEP_MONITOR_SENSOR: + case HUMAN_SLEEP_DETECTOR_SENSOR: + case HUMAN_STRESS_MONITOR_SENSOR: + m_info.set_privilege("http://tizen.org/privilege/healthinfo"); + break; + default: + break; + }; } physical_sensor_handler::~physical_sensor_handler() -- 2.7.4 From e3b33421686cbfa14cb99e1822789029fda1242f Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:56:05 +0900 Subject: [PATCH 08/16] sensord: compare previous interval with current interval Change-Id: I65c56ce4a3757447fb1fdc61b344732fcd4dbc9b Signed-off-by: kibak.yoon --- src/server/physical_sensor_handler.cpp | 23 ++++++++++++++--------- src/server/physical_sensor_handler.h | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index 0fa3a2d..3ee22b7 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -33,6 +33,7 @@ physical_sensor_handler::physical_sensor_handler(const sensor_info &info, , m_device(device) , m_sensor(sensor) , m_hal_id(hal_id) +, m_prev_interval(0) { /* TODO: temporary walkaround */ switch (m_info.get_type()) { @@ -166,22 +167,26 @@ int physical_sensor_handler::set_interval(sensor_observer *ob, int32_t interval) retv_if(!m_device, -EINVAL); bool ret = false; - int _interval = interval; + int32_t cur_interval = interval; int policy = OP_DEFAULT; if (m_sensor) { - policy = m_sensor->set_interval(ob, interval); + policy = m_sensor->set_interval(ob, cur_interval); retv_if(policy <= OP_ERROR, policy); } - m_interval_map[ob] = interval; + m_interval_map[ob] = cur_interval; if (policy == OP_DEFAULT) - _interval = get_min_interval(); + cur_interval = get_min_interval(); - ret = m_device->set_interval(m_hal_id, _interval); + retv_if(m_prev_interval == cur_interval, OP_SUCCESS); - return (ret ? OP_SUCCESS : OP_SUCCESS); + ret = m_device->set_interval(m_hal_id, cur_interval); + + m_prev_interval = cur_interval; + + return (ret ? OP_SUCCESS : OP_ERROR); } int physical_sensor_handler::get_min_batch_latency(void) @@ -221,7 +226,7 @@ int physical_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t late ret = m_device->set_batch_latency(m_hal_id, _latency); - return (ret ? OP_SUCCESS : OP_SUCCESS); + return (ret ? OP_SUCCESS : OP_ERROR); } int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int32_t value) @@ -246,7 +251,7 @@ int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, in ret = m_device->set_attribute_int(m_hal_id, attr, value); - return (ret ? OP_SUCCESS : OP_SUCCESS); + return (ret ? OP_SUCCESS : OP_ERROR); } int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) @@ -271,7 +276,7 @@ int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, co ret = m_device->set_attribute_str(m_hal_id, attr, const_cast(value), len); - return (ret ? OP_SUCCESS : OP_SUCCESS); + return (ret ? OP_SUCCESS : OP_ERROR); } int physical_sensor_handler::flush(sensor_observer *ob) diff --git a/src/server/physical_sensor_handler.h b/src/server/physical_sensor_handler.h index 1983dbd..edb29dd 100644 --- a/src/server/physical_sensor_handler.h +++ b/src/server/physical_sensor_handler.h @@ -62,7 +62,8 @@ private: sensor_info m_info; sensor_device *m_device; physical_sensor *m_sensor; - int m_hal_id; + uint32_t m_hal_id; + int32_t m_prev_interval; std::unordered_map m_interval_map; std::unordered_map m_batch_latency_map; -- 2.7.4 From 93dfbb164c2f19c015f32a02f9cde5adfcba0e24 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 01:00:56 +0900 Subject: [PATCH 09/16] sensord: separate channel for event and command - if the event occurs during sending command, a timing issue will occur. Change-Id: I8ed5ad2f7c6bcc9ea44641c619458639553822c2 Signed-off-by: kibak.yoon --- src/client/sensor_listener.cpp | 73 ++++++++++++++++++------------ src/client/sensor_listener.h | 3 +- src/server/server_channel_handler.cpp | 84 +++++++++++++++++++++-------------- src/server/server_channel_handler.h | 7 ++- 4 files changed, 101 insertions(+), 66 deletions(-) diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index a5c4af2..95c411c 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -66,7 +66,8 @@ sensor_listener::sensor_listener(sensor_t sensor) : m_id(0) , m_sensor(reinterpret_cast(sensor)) , m_client(NULL) -, m_channel(NULL) +, m_cmd_channel(NULL) +, m_evt_channel(NULL) , m_handler(NULL) , m_evt_handler(NULL) , m_acc_handler(NULL) @@ -148,8 +149,11 @@ void sensor_listener::restore(void) bool sensor_listener::connect(void) { - m_channel = m_client->connect(m_handler, &m_loop); - retvm_if(!m_channel, false, "Failed to connect to server"); + m_cmd_channel = m_client->connect(NULL); + retvm_if(!m_cmd_channel, false, "Failed to connect to server"); + + m_evt_channel = m_client->connect(m_handler, &m_loop); + retvm_if(!m_evt_channel, false, "Failed to connect to server"); ipc::message msg; ipc::message reply; @@ -158,9 +162,9 @@ bool sensor_listener::connect(void) memcpy(buf.sensor, m_sensor->get_uri().c_str(), m_sensor->get_uri().size()); msg.set_type(CMD_LISTENER_CONNECT); msg.enclose((const char *)&buf, sizeof(buf)); - m_channel->send_sync(&msg); + m_evt_channel->send_sync(&msg); - m_channel->read_sync(reply); + m_evt_channel->read_sync(reply); reply.disclose((char *)&buf); m_id = buf.listener_id; @@ -180,13 +184,17 @@ void sensor_listener::disconnect(void) ipc::message reply; msg.set_type(CMD_LISTENER_DISCONNECT); - m_channel->send_sync(&msg); + m_evt_channel->send_sync(&msg); + + m_evt_channel->read_sync(reply); + m_evt_channel->disconnect(); - m_channel->read_sync(reply); - m_channel->disconnect(); + delete m_evt_channel; + m_evt_channel = NULL; - delete m_channel; - m_channel = NULL; + m_cmd_channel->disconnect(); + delete m_cmd_channel; + m_cmd_channel = NULL; _I("Disconnected[%d]", get_id()); } @@ -234,14 +242,14 @@ int sensor_listener::start(void) ipc::message reply; cmd_listener_start_t buf; - retvm_if(!m_channel, -EINVAL, "Failed to connect to server"); + retvm_if(!m_cmd_channel, -EINVAL, "Failed to connect to server"); buf.listener_id = m_id; msg.set_type(CMD_LISTENER_START); msg.enclose((char *)&buf, sizeof(buf)); - m_channel->send_sync(&msg); - m_channel->read_sync(reply); + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) return reply.header()->err; @@ -257,15 +265,15 @@ int sensor_listener::stop(void) ipc::message reply; cmd_listener_stop_t buf; - retvm_if(!m_channel, -EINVAL, "Failed to connect to server"); + retvm_if(!m_cmd_channel, -EINVAL, "Failed to connect to server"); retvm_if(!m_started.load(), -EAGAIN, "Already stopped"); buf.listener_id = m_id; msg.set_type(CMD_LISTENER_STOP); msg.enclose((char *)&buf, sizeof(buf)); - m_channel->send_sync(&msg); - m_channel->read_sync(reply); + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) return reply.header()->err; @@ -343,7 +351,7 @@ int sensor_listener::set_attribute(int attribute, int value) ipc::message reply; cmd_listener_attr_int_t buf; - retvm_if(!m_channel, false, "Failed to connect to server"); + retvm_if(!m_cmd_channel, false, "Failed to connect to server"); buf.listener_id = m_id; buf.attribute = attribute; @@ -351,8 +359,8 @@ int sensor_listener::set_attribute(int attribute, int value) msg.set_type(CMD_LISTENER_ATTR_INT); msg.enclose((char *)&buf, sizeof(buf)); - m_channel->send_sync(&msg); - m_channel->read_sync(reply); + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) return reply.header()->err; @@ -368,7 +376,7 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) ipc::message reply; cmd_listener_attr_str_t buf; - retvm_if(!m_channel, false, "Failed to connect to server"); + retvm_if(!m_cmd_channel, false, "Failed to connect to server"); msg.set_type(CMD_LISTENER_ATTR_STR); buf.listener_id = m_id; @@ -378,8 +386,8 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) msg.enclose((char *)&buf, sizeof(buf) + len); - m_channel->send_sync(&msg); - m_channel->read_sync(reply); + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); return reply.header()->err; } @@ -390,19 +398,26 @@ int sensor_listener::get_sensor_data(sensor_data_t *data) ipc::message reply; cmd_listener_get_data_t buf; - retvm_if(!m_channel, false, "Failed to connect to server"); + retvm_if(!m_cmd_channel, false, "Failed to connect to server"); buf.listener_id = m_id; msg.set_type(CMD_LISTENER_GET_DATA); msg.enclose((char *)&buf, sizeof(buf)); - m_channel->send_sync(&msg); - m_channel->read_sync(reply); - /* TODO */ - /* + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); + reply.disclose((char *)&buf); - memcpy(data, buf.data, sizeof(buf.len)); - */ + int size = sizeof(sensor_data_t); + + if (buf.len > size || buf.len < 0) { + data->accuracy = -1; + data->value_count = 0; + /* TODO: it should return OP_ERROR */ + return OP_SUCCESS; + } + + memcpy(data, &buf.data, buf.len); return OP_SUCCESS; } diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h index ea30092..f0a1f1b 100644 --- a/src/client/sensor_listener.h +++ b/src/client/sensor_listener.h @@ -80,7 +80,8 @@ private: sensor_info *m_sensor; ipc::ipc_client *m_client; - ipc::channel *m_channel; + ipc::channel *m_cmd_channel; + ipc::channel *m_evt_channel; ipc::channel_handler *m_handler; ipc::channel_handler *m_evt_handler; ipc::channel_handler *m_acc_handler; diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 1c18d1d..86abf93 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -47,13 +47,14 @@ void server_channel_handler::connected(channel *ch) void server_channel_handler::disconnected(channel *ch) { - auto it = m_listeners.find(ch); - ret_if(it == m_listeners.end()); + auto it = m_listener_ids.find(ch); + ret_if(it == m_listener_ids.end()); - _I("Disconnected listener[%u]", it->second->get_id()); + _I("Disconnected listener[%u]", it->second); - delete it->second; - m_listeners.erase(ch); + delete m_listeners[it->second]; + m_listeners.erase(it->second); + m_listener_ids.erase(ch); } void server_channel_handler::read(channel *ch, message &msg) @@ -104,6 +105,7 @@ int server_channel_handler::manager_get_sensor_list(channel *ch, message &msg) retv_if(size < 0, size); reply.enclose((const char *)bytes, size); + reply.header()->err = OP_SUCCESS; ch->send_sync(&reply); delete [] bytes; @@ -138,24 +140,26 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) return OP_ERROR; _I("Connected sensor_listener[fd(%d) -> id(%u)]", ch->get_fd(), listener_id); + m_listeners[listener_id] = listener; + m_listener_ids[ch] = listener_id; listener_id++; - m_listeners[ch] = listener; return OP_SUCCESS; } int server_channel_handler::listener_disconnect(channel *ch, message &msg) { - auto it = m_listeners.find(ch); - retv_if(it == m_listeners.end(), -EINVAL); + auto it = m_listener_ids.find(ch); + retv_if(it == m_listener_ids.end(), -EINVAL); - uint32_t id = m_listeners[ch]->get_id(); + uint32_t id = it->second; - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), -EACCES, "Permission denied"); - delete m_listeners[ch]; - m_listeners.erase(ch); + delete m_listeners[id]; + m_listeners.erase(id); + m_listener_ids.erase(ch); _D("Disconnected sensor_listener[%u]", id); @@ -164,12 +168,16 @@ int server_channel_handler::listener_disconnect(channel *ch, message &msg) int server_channel_handler::listener_start(channel *ch, message &msg) { - auto it = m_listeners.find(ch); + cmd_listener_start_t buf; + msg.disclose((char *)&buf); + uint32_t id = buf.listener_id; + + auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), -EACCES, "Permission denied"); - int ret = m_listeners[ch]->start(); + int ret = m_listeners[id]->start(); retv_if(ret < 0, ret); return send_reply(ch, OP_SUCCESS); @@ -177,12 +185,16 @@ int server_channel_handler::listener_start(channel *ch, message &msg) int server_channel_handler::listener_stop(channel *ch, message &msg) { - auto it = m_listeners.find(ch); + cmd_listener_stop_t buf; + msg.disclose((char *)&buf); + uint32_t id = buf.listener_id; + + auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), -EACCES, "Permission denied"); - int ret = m_listeners[ch]->stop(); + int ret = m_listeners[id]->stop(); retv_if(ret < 0, ret); return send_reply(ch, OP_SUCCESS); @@ -190,44 +202,48 @@ int server_channel_handler::listener_stop(channel *ch, message &msg) int server_channel_handler::listener_attr_int(channel *ch, message &msg) { + cmd_listener_attr_int_t buf; + msg.disclose((char *)&buf); + uint32_t id = buf.listener_id; + int ret = OP_SUCCESS; - auto it = m_listeners.find(ch); + auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), -EACCES, "Permission denied"); - cmd_listener_attr_int_t buf; - msg.disclose((char *)&buf); - switch (buf.attribute) { case SENSORD_ATTRIBUTE_INTERVAL: - ret = m_listeners[ch]->set_interval(buf.value); break; + ret = m_listeners[id]->set_interval(buf.value); break; case SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY: - ret = m_listeners[ch]->set_max_batch_latency(buf.value); break; + ret = m_listeners[id]->set_max_batch_latency(buf.value); break; case SENSORD_ATTRIBUTE_PASSIVE_MODE: - ret = m_listeners[ch]->set_passive_mode(buf.value); break; + ret = m_listeners[id]->set_passive_mode(buf.value); break; case SENSORD_ATTRIBUTE_PAUSE_POLICY: case SENSORD_ATTRIBUTE_AXIS_ORIENTATION: default: - ret = m_listeners[ch]->set_attribute(buf.attribute, buf.value); + ret = m_listeners[id]->set_attribute(buf.attribute, buf.value); } - retv_if(ret < 0, ret); + /* TODO : check return value */ + if (ret < 0) + _W("Return : %d", ret); return send_reply(ch, OP_SUCCESS); } int server_channel_handler::listener_attr_str(channel *ch, message &msg) { - auto it = m_listeners.find(ch); - retv_if(it == m_listeners.end(), -EINVAL); - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), - -EACCES, "Permission denied"); - cmd_listener_attr_str_t buf; msg.disclose((char *)&buf); + uint32_t id = buf.listener_id; + + auto it = m_listeners.find(id); + retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), + -EACCES, "Permission denied"); - int ret = m_listeners[ch]->set_attribute(buf.attribute, buf.value, buf.len); + int ret = m_listeners[id]->set_attribute(buf.attribute, buf.value, buf.len); retv_if(ret < 0, ret); return send_reply(ch, OP_SUCCESS); diff --git a/src/server/server_channel_handler.h b/src/server/server_channel_handler.h index 1ccc998..a2d9fce 100644 --- a/src/server/server_channel_handler.h +++ b/src/server/server_channel_handler.h @@ -67,8 +67,11 @@ private: sensor_manager *m_manager; - /* {fd, listener} */ - std::unordered_map m_listeners; + /* {id, listener} */ + std::unordered_map m_listeners; + + /* {channel, id} */ + std::unordered_map m_listener_ids; /* {name, application_sensor_handler} */ /* TODO: move it to sensor_manager */ -- 2.7.4 From 5bc863fd19c73c047383009ca23f57f52eb6e290 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 01:07:36 +0900 Subject: [PATCH 10/16] sensord: support get_data() API simply - [TBD] it doesn't consider whether the value is normal or not. Change-Id: I5b5517c82d8282cf433fe6b7eb4b9a2956346d0b Signed-off-by: kibak.yoon --- src/server/fusion_sensor_handler.cpp | 5 +++-- src/server/server_channel_handler.cpp | 29 ++++++++++++++++++++++++++--- src/shared/command_types.h | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index 05ab314..18ecd71 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -214,8 +214,9 @@ int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, cons int fusion_sensor_handler::get_data(sensor_data_t **data, int *len) { - /* TODO */ - return OP_SUCCESS; + retv_if(!m_sensor, -EINVAL); + + return m_sensor->get_data(data, len); } int fusion_sensor_handler::flush(sensor_observer *ob) diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 86abf93..6fad489 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -251,12 +251,35 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) int server_channel_handler::listener_get_data(channel *ch, message &msg) { - auto it = m_listeners.find(ch); + ipc::message reply; + cmd_listener_get_data_t buf; + sensor_data_t *data; + int len; + uint32_t id; + + msg.disclose((char *)&buf); + id = buf.listener_id; + + auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); - retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), -EACCES, "Permission denied"); - return send_reply(ch, OP_ERROR); + int ret = m_listeners[id]->get_data(&data, &len); + retv_if(ret < 0, ret); + + memcpy(&buf.data, data, sizeof(sensor_data_t)); + buf.len = sizeof(sensor_data_t); + + reply.enclose((const char *)&buf, sizeof(cmd_listener_get_data_t)); + reply.header()->err = OP_SUCCESS; + reply.header()->type = CMD_LISTENER_GET_DATA; + + ch->send_sync(&reply); + + free(data); + + return OP_SUCCESS; } int server_channel_handler::provider_connect(channel *ch, message &msg) diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 6b5e0c6..a75ef6e 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -94,7 +94,7 @@ typedef struct { typedef struct { int listener_id; int len; - char data[0]; + sensor_data_t data; } cmd_listener_get_data_t; typedef struct { -- 2.7.4 From e69c92e77630def6f7f131cf223ae90e44dd3cbd Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 01:10:01 +0900 Subject: [PATCH 11/16] sensord: suppress verbos log message - highlight compile errors/warnings Change-Id: I19b34adff7fd0488109c6361dea70d0865f7a1db Signed-off-by: kibak.yoon --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f30d92..45e0775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,9 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) # Common Options SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections") +SET(CMAKE_VERBOSE_MAKEFILE OFF) MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}") MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") -- 2.7.4 From 1bf0daf6be1856cf5d22ecbae078dd784d9552eb Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 6 Apr 2017 19:55:46 +0900 Subject: [PATCH 12/16] sensord: remove unnecessary socket log Change-Id: I7a7213ebd917ccf88172b159667ad8b9169daa63 Signed-off-by: kibak.yoon --- src/shared/socket.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp index b29ba96..871031f 100644 --- a/src/shared/socket.cpp +++ b/src/shared/socket.cpp @@ -254,10 +254,8 @@ bool socket::close(void) { retv_if(m_sock_fd < 0, false); - if (::close(m_sock_fd) < 0) { - _ERRNO(errno, _E, "Failed to close socket[%d]", m_sock_fd); + if (::close(m_sock_fd) < 0) return false; - } _D("Closed[%d]", m_sock_fd); -- 2.7.4 From c13290dcc185dd17aea4c4f00c443eba07ec445e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 12:24:47 +0900 Subject: [PATCH 13/16] sensord: add defensive code for blocking issue - this issue is related to hrm_raw sensor device driver Change-Id: Ib75c56b7847b4afe8aeb3a14609168a47a669b64 Signed-off-by: kibak.yoon --- src/server/physical_sensor_handler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index 3ee22b7..85a5515 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -75,11 +75,12 @@ int physical_sensor_handler::get_poll_fd(void) int physical_sensor_handler::read_fd(std::vector &ids) { + retv_if(observer_count() == 0, OP_ERROR); + retv_if(!m_device, -EINVAL); + int size; uint32_t *_ids; - retv_if(!m_device, -EINVAL); - size = m_device->read_fd(&_ids); retv_if(size == 0, -ENODATA); -- 2.7.4 From c4a3c8a910ec06ffe96917169d873bddc1026507 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 16:44:54 +0900 Subject: [PATCH 14/16] sensord: rename fusion sensors to proper name Change-Id: Ied998d22a50464a735b7f37a893c0de51c6d282f Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 4 ++-- src/sensor/gravity/gravity_comp_sensor.cpp | 4 ++-- src/sensor/gravity/gravity_lowpass_sensor.cpp | 4 ++-- src/sensor/linear_accel/linear_accel_sensor.cpp | 4 ++-- src/sensor/orientation/orientation_sensor.cpp | 4 ++-- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 4 ++-- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 4 ++-- src/sensor/rotation_vector/rv_sensor.cpp | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 2a6aa98..33f1fda 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -24,8 +24,8 @@ #include "auto_rotation_alg_emul.h" -#define NAME_SENSOR "http://tizen.org/sensor/auto_rotation/AUTO_ROTATION" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/auto_rotation/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/gravity/gravity_comp_sensor.cpp b/src/sensor/gravity/gravity_comp_sensor.cpp index 2a09115..9552e74 100644 --- a/src/sensor/gravity/gravity_comp_sensor.cpp +++ b/src/sensor/gravity/gravity_comp_sensor.cpp @@ -24,8 +24,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gravity/complementary" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/gravity/tizen_complementary" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/gravity/gravity_lowpass_sensor.cpp b/src/sensor/gravity/gravity_lowpass_sensor.cpp index f3e7d7b..bc31ce2 100644 --- a/src/sensor/gravity/gravity_lowpass_sensor.cpp +++ b/src/sensor/gravity/gravity_lowpass_sensor.cpp @@ -24,8 +24,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gravity/lowpass" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/gravity/tizen_lowpass" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index e46f74a..27cce33 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -23,8 +23,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/linear_accel/linear_accel" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/linear_accel/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index 393ec9a..551c73f 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -23,8 +23,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/orientation/orientation" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/orientation/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_RV 0x1 #define SRC_STR_RV "http://tizen.org/sensor/rotation_vector" diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 3a738d0..ccafce8 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -23,8 +23,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gyro_rotation_vector/gyro_rv" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/gyro_rotation_vector/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 66c8808..fd9ad36 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -23,8 +23,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/mag_rotation_vector/mag_rv" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/mag_rotation_vector/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 6d69cda..116541f 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -23,8 +23,8 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/rotation_vector" -#define NAME_VENDOR "Samsung" +#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/tizen_default" +#define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" -- 2.7.4 From 237aeb9c0a720c59a6881f0f7922f4ca4cd3540f Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 17:22:54 +0900 Subject: [PATCH 15/16] sensord: fix bug with invalid character(!) Change-Id: Ib35b0f4c2ea3dc1d9c169ef24fa533a99d21c9c8 Signed-off-by: kibak.yoon --- src/shared/channel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index b56d49e..8dc25ac 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -25,6 +25,8 @@ #include "sensor_log.h" +#define SYSTEMD_SOCK_BUF_SIZE 40000 + using namespace ipc; class send_event_handler : public event_handler @@ -146,7 +148,7 @@ bool channel::send(message *msg) /* TODO: check buffer size(is there any linux api for this?) */ int cur_buffer_size = m_socket->get_current_buffer_size(); - retvm_if(!cur_buffer_size > 40000, false, "Failed to send data"); + retvm_if(cur_buffer_size > SYSTEMD_SOCK_BUF_SIZE, false, "Failed to send data"); send_event_handler *handler = new(std::nothrow) send_event_handler(this, msg); retvm_if(!handler, false, "Failed to allocate memory"); -- 2.7.4 From 734c56cd6d0e13c1d8fbd62a88bc55459707b533 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 17:58:03 +0900 Subject: [PATCH 16/16] sensord: use readdir() instead of deprecated readdir_r Change-Id: Iad45c3eea70923dc6f42a966b4ed0c62fcb3ebc4 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 9ea7e7f..9611b3a 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -107,10 +107,8 @@ bool sensor_loader::load(const std::string &dir_path, std::vector &paths) { - int ret; DIR *dir = NULL; - struct dirent entry; - struct dirent *result; + struct dirent *entry; struct stat buf; std::string filename; @@ -118,14 +116,10 @@ bool sensor_loader::get_module_paths(const std::string &dir_path, std::vectord_name); if (filename == "." || filename == "..") continue; -- 2.7.4