Merge branch 'devel/tizen_3.0' into tizen
[platform/core/system/sensord.git] / src / sensor / rotation_vector / test / test_projects / linear_acceleration_sensor_test / linear_acceleration_sensor_main.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "../../linear_acceleration_sensor.h"
21 #include <stdlib.h>
22 #include <iostream>
23 #include <fstream>
24 #include <string>
25 using namespace std;
26
27 #define LA_DATA_PATH "../../../design/data/100ms/linear_acceleration/move_x_y_z/"
28 #define LA_DATA_SIZE 170
29
30 int main()
31 {
32         int data_available = LA_DATA_SIZE;
33         ifstream accel_in, gyro_in, mag_in;
34         ofstream la_file;
35         string line_accel, line_gyro, line_magnetic;
36         float sdata[3];
37         unsigned long long time_stamp;
38         sensor_data<float> lin_accel;
39         linear_acceleration_sensor la_sensor;
40
41         accel_in.open(((string)LA_DATA_PATH + (string)"accel.txt").c_str());
42         gyro_in.open(((string)LA_DATA_PATH + (string)"gyro.txt").c_str());
43         mag_in.open(((string)LA_DATA_PATH + (string)"magnetic.txt").c_str());
44
45         la_file.open(((string)"linear_acceleration.txt").c_str());
46
47         char *token = NULL;
48
49         while (data_available-- > 0)
50         {
51                 getline(accel_in, line_accel);
52                 sdata[0] = strtof(line_accel.c_str(), &token);
53                 sdata[1] = strtof(token, &token);
54                 sdata[2] = strtof(token, &token);
55                 time_stamp = strtoull(token, NULL, 10);
56                 sensor_data<float> accel_data(sdata[0], sdata[1], sdata[2], time_stamp);
57
58                 cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n";
59
60                 getline(gyro_in, line_gyro);
61                 sdata[0] = strtof(line_gyro.c_str(), &token);
62                 sdata[1] = strtof(token, &token);
63                 sdata[2] = strtof(token, &token);
64                 time_stamp = strtoull(token, NULL, 10);
65                 sensor_data<float> gyro_data(sdata[0], sdata[1], sdata[2], time_stamp);
66
67                 cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n";
68
69                 getline(mag_in, line_magnetic);
70                 sdata[0] = strtof(line_magnetic.c_str(), &token);
71                 sdata[1] = strtof(token, &token);
72                 sdata[2] = strtof(token, &token);
73                 time_stamp = strtoull(token, NULL, 10);
74                 sensor_data<float> magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp);
75
76                 cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n";
77
78                 lin_accel = la_sensor.get_linear_acceleration(accel_data, gyro_data, magnetic_data);
79
80                 la_file << lin_accel.m_data;
81
82                 cout << "Linear Acceleration Data\t" << lin_accel.m_data << "\n\n";
83         }
84
85         accel_in.close();
86         gyro_in.close();
87         mag_in.close();
88         la_file.close();
89
90         return 0;
91 }