-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_helper.c
138 lines (116 loc) · 4.53 KB
/
main_helper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//==============================================================================
//
// main_helper.c - Epson IMU helper functions for console utilities
//
//
// THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// NONINFRINGEMENT, SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A
// PARTICULAR PURPOSE. IN NO EVENT SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE
// OR CLAIM, ARISING FROM OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE
// SOFTWARE.
//
//==============================================================================
#include <stdio.h>
#include "main_helper.h"
#include "sensor_epsonCommon.h"
/*****************************************************************************
** Function name: printHeaderRow
** Description: Output header row based on EpsonOptions
** Parameters: fp - file pointer to send data
** EpsonOptions* - pointer to struct describing the IMU
** configuration.
** Return value: None
** Notes:
*****************************************************************************/
void printHeaderRow(FILE* fp, const struct EpsonOptions* options) {
fprintf(fp, "\r\nsample[dec]");
if (options->flag_out) {
fprintf(fp, ", ndflags[hex]");
}
if (options->temp_out) {
fprintf(fp, ", tempC[degC]");
}
if (options->gyro_out) {
fprintf(fp, ", gx[deg/s], gy[deg/s], gz[deg/s]");
}
if (options->accel_out) {
fprintf(fp, ", ax[mG], ay[mG], az[mG]");
}
if (options->gyro_delta_out) {
fprintf(fp, ", dax[deg], day[deg], daz[deg]");
}
if (options->accel_delta_out) {
fprintf(fp, ", dvx[m/s], dvy[m/s], dvz[m/s]");
}
if (options->qtn_out) {
fprintf(fp, ", qtn0, qtn1, qtn2, qtn3");
}
if (options->atti_out) {
fprintf(fp, ", ang1[deg], ang2[deg], ang3[deg]");
}
if (options->gpio_out) {
fprintf(fp, ", gpio[hex]");
}
if (options->count_out) {
fprintf(fp, ", count");
}
fprintf(fp, "\n");
}
/*****************************************************************************
** Function name: printSensorRow
** Description: Prints formatted row of sensor data based on
** EpsonOptions
** Parameters: fp - file pointer to send data
** EpsonOptions* - pointer to struct describing the IMU
** configuration.
** EpsonData* - pointer to struct that contains scaled
** sensor
** data
** sample_count - index for the sample row
** Return value: none
** Notes:
******************************************************************************/
void printSensorRow(FILE* fp, const struct EpsonOptions* options,
const struct EpsonData* epson_data, int sample_count) {
fprintf(fp, "%08d", sample_count);
if (options->flag_out) {
fprintf(fp, ", %04x", epson_data->ndflags);
}
if (options->temp_out) {
fprintf(fp, ", %8.3f", epson_data->temperature);
}
if (options->gyro_out) {
fprintf(fp, ", %8.5f, %8.5f, %8.5f", epson_data->gyro_x * RAD2DEG,
epson_data->gyro_y * RAD2DEG, epson_data->gyro_z * RAD2DEG);
}
if (options->accel_out) {
fprintf(fp, ", %8.5f, %8.5f, %8.5f", epson_data->accel_x * MPS22MG,
epson_data->accel_y * MPS22MG, epson_data->accel_z * MPS22MG);
}
if (options->gyro_delta_out) {
fprintf(fp, ", %8.5f, %8.5f, %8.5f", epson_data->gyro_delta_x * RAD2DEG,
epson_data->gyro_delta_y * RAD2DEG,
epson_data->gyro_delta_z * RAD2DEG);
}
if (options->accel_delta_out) {
fprintf(fp, ", %8.5f, %8.5f, %8.5f", epson_data->accel_delta_x,
epson_data->accel_delta_y, epson_data->accel_delta_z);
}
if (options->qtn_out) {
fprintf(fp, ", %8.8f, %8.8f, %8.8f, %8.8f", epson_data->qtn0,
epson_data->qtn1, epson_data->qtn2, epson_data->qtn3);
}
if (options->atti_out) {
fprintf(fp, ", %8.3f, %8.3f, %8.3f", epson_data->ang1 * RAD2DEG,
epson_data->ang2 * RAD2DEG, epson_data->ang3 * RAD2DEG);
}
if (options->gpio_out) {
fprintf(fp, ", %04x", epson_data->gpio);
}
if (options->count_out) {
fprintf(fp, ", %09d", epson_data->count);
}
fprintf(fp, "\n");
}