-
Notifications
You must be signed in to change notification settings - Fork 1
/
offline.c
150 lines (129 loc) · 4.03 KB
/
offline.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
139
140
141
142
143
144
145
146
147
148
149
150
/**
* __ ____
* / /__ _ __ / __/ __
* / //_/(_)/ /_ / / ___ ____ ___ __ __ / /_
* / ,< / // __/_\ \ / _ \ / __// _ \/ // // __/
* /_/|_|/_/ \__//___// .__//_/ \___/\_,_/ \__/
* /_/ github.com/KitSprout
*
* @file offline.c
* @author KitSprout
* @brief
*
*/
/* Includes --------------------------------------------------------------------------------*/
#include <stdlib.h>
#include <string.h>
#include "kslog.h"
#include "kscsv.h"
#include "ksfeeder.h"
/* Define ----------------------------------------------------------------------------------*/
#ifndef OFFLINE_LOGOUT_RELATE_PATH
#define OFFLINE_LOGOUT_RELATE_PATH "output/"
#endif
#ifndef OFFLINE_LOGOUT_FILE_TAG
#define OFFLINE_LOGOUT_FILE_TAG "_output"
#endif
/* Macro -----------------------------------------------------------------------------------*/
/* Typedef ---------------------------------------------------------------------------------*/
/* Variables -------------------------------------------------------------------------------*/
static char *LOG[] = {"sn","dt","gx","gy","gz","mx","my","mz","mbx","mby","mbz"};
static char RelatePath[1024] = {OFFLINE_LOGOUT_RELATE_PATH};
static char OutputFileTag[1024] = {OFFLINE_LOGOUT_FILE_TAG};
/* Prototypes ------------------------------------------------------------------------------*/
static void ksraw_update(int index, ksraw_t *raw, kscsv_t *csv);
static int ksfeed_csv(ksraw_t *raw, kscsv_t *csv, int start, int stop);
/* Functions -------------------------------------------------------------------------------*/
/**
* @brief run_offline
*/
int run_offline(char *filename, int *range)
{
kscsv_t csv = {0};
ksraw_t raw = {0};
int start = 0, stop = 0;
raw.raw.mode = OFFLINE_MODE;
// read csv
if (kscsv_open(&csv, filename) != KS_OK)
{
klogd("\nopen csv failed !!!\n");
return -1;
}
#if 0
kscsv_info(&csv);
#endif
kscsv_read(&csv, -1);
if (range != NULL)
{
start = range[0] - 1;
stop = range[1];
if (stop > csv.raw.size)
{
stop = csv.raw.size;
}
}
else
{
stop = csv.raw.size;
}
// if (relatepath != NULL)
// {
// strcpy(RelatePath, relatepath);
// }
// if (filetag != NULL)
// {
// strcpy(OutputFileTag, filetag);
// }
// create csv
if (kscsv_create(&csv, RelatePath, OutputFileTag, LOG, sizeof(LOG) >> 2) != KS_OK)
{
klogd("create csv failed !!!\n");
return -1;
}
// feed
ksfeed_csv(&raw, &csv, start, stop);
// close csv
return kscsv_close(&csv);
}
static void ksraw_update(int index, ksraw_t *praw, kscsv_t *pcsv)
{
praw->raw.index++;
praw->raw.t = 25.0f;
for (int i = 0; i < pcsv->tagcnt; i++)
{
int tag = pcsv->tags[i];
if ((tag > KSCSV_IDX_TS) && (tag < KSCSV_IDX_UNKNOWN))
{
if (tag != KSCSV_IDX_DT)
{
praw->mem[tag] = (float)((double*)pcsv->mem[tag])[index];
}
else
{
praw->mem[tag] = (float)((double*)pcsv->mem[tag])[index] * 1e-9;
}
}
}
}
static int ksfeed_csv(ksraw_t *raw, kscsv_t *csv, int start, int stop)
{
// for (int i = 0; i < csv.raw.size; i++)
for (int i = start; i < stop; i++)
{
# if 1
// process
ksraw_update(i, raw, csv);
ksfeeder(i + 1, &raw->raw);
#endif
#if 1
// tag: sn,dt,gx,gy,gz,mx,my,mz,mbx,mby,mbz
kscsv_write(csv, "%.0f,%.0f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f",
csv->raw.sn[i], csv->raw.dt[i],
csv->raw.g[0][i], csv->raw.g[1][i], csv->raw.g[2][i],
csv->raw.m[0][i], csv->raw.m[1][i], csv->raw.m[2][i],
csv->raw.mb[0][i], csv->raw.mb[1][i], csv->raw.mb[2][i]);
#endif
}
return KS_OK;
}
/*************************************** END OF FILE ****************************************/