Overoで動作するデータ収録プログラム
サブCPUからGPS時刻付きADデータを取得してSDに記録する。
Revisão | e076a8cd6d376e3c93da458502890ebcc02afd65 (tree) |
---|---|
Hora | 2011-12-12 21:00:34 |
Autor | Naoya Takamura <ntaka206@user...> |
Commiter | Naoya Takamura |
conf.c
ad_ring.h
リングバッファ構造体
要素変更 nano->tacc
要素追加 freq
ad_file.c
平均化コード実装
@@ -86,7 +86,7 @@ int sec_file_open(FILE **fp, AdData *D) | ||
86 | 86 | char path[128]; |
87 | 87 | |
88 | 88 | // サブディレクトリ作成 |
89 | - sprintf(szDir, "%s/%s/%04d/%02d", DIR_DATA, sid_getp(), D->t.tm_year+1900, D->t.tm_mon+1); | |
89 | + sprintf(szDir, "%s/%04d/%02d", DIR_DATA, D->t.tm_year+1900, D->t.tm_mon+1); | |
90 | 90 | // ディレクトリ存在しなければ作成する |
91 | 91 | if (stat(szDir, &st) == -1) mkdir_p(szDir, MKDIR_MODE); |
92 | 92 |
@@ -173,7 +173,7 @@ int high_file_open(FILE **fp, AdData *D) | ||
173 | 173 | char path[128]; |
174 | 174 | |
175 | 175 | // サブディレクトリ作成 |
176 | - sprintf(szDir, "%s/%s/%04d/%02d", DIR_DATA, sid_getp(), D->t.tm_year+1900, D->t.tm_mon+1); | |
176 | + sprintf(szDir, "%s/%04d/%02d", DIR_DATA, D->t.tm_year+1900, D->t.tm_mon+1); | |
177 | 177 | // ディレクトリ存在しなければ作成する |
178 | 178 | if (stat(szDir, &st) == -1) mkdir_p(szDir, MKDIR_MODE); |
179 | 179 |
@@ -226,12 +226,13 @@ int high_file_close(FILE *fp) | ||
226 | 226 | } |
227 | 227 | |
228 | 228 | /* |
229 | + 高速サンプル記録データ | |
229 | 230 | 記録用データ作る |
230 | 231 | */ |
231 | 232 | int high_make_rec_data(AdData *ad, char *ptr) |
232 | 233 | { |
233 | - unsigned char *src; | |
234 | - int ch, i, j; | |
234 | +// char *src; | |
235 | + int ch, i; | |
235 | 236 | |
236 | 237 | *ptr++ = ad->gps.year & 0xFF; |
237 | 238 | *ptr++ = (ad->gps.year >> 8) & 0xFF; |
@@ -240,16 +241,22 @@ int high_make_rec_data(AdData *ad, char *ptr) | ||
240 | 241 | *ptr++ = ad->gps.hour; |
241 | 242 | *ptr++ = ad->gps.min; |
242 | 243 | *ptr++ = ad->gps.sec; |
243 | - *ptr++ = ad->gps.nano; | |
244 | + memcpy(ptr, (char*)(&(ad->gps.tacc)), 4); | |
245 | + ptr += 4; | |
244 | 246 | *ptr++ = ad->gps.valid; |
247 | + *ptr++ = ad->freq & 0xFF; | |
248 | + *ptr++ = (ad->freq >> 8) & 0xFF; | |
249 | + | |
245 | 250 | // |
246 | - src = ad->data; | |
251 | +// src = (char*)ad->avg; | |
247 | 252 | for(ch = 0; ch < AD_CHNUM; ch++) { |
248 | - for(i = 0; i < AD_SAMPLE; i++) { | |
249 | - for(j = 0; j < AD_BYTES; j++) { | |
250 | - *ptr++ = *src++; | |
251 | - } | |
252 | - src++; | |
253 | + for(i = 0; i < ad->freq; i++) { | |
254 | + memcpy(ptr, &(ad->avg[ch][i]), AD_BYTES); | |
255 | + ptr += AD_BYTES; | |
256 | +// for(j = 0; j < AD_BYTES; j++) { | |
257 | +// *ptr++ = *src++; | |
258 | +// } | |
259 | +// src++; | |
253 | 260 | } |
254 | 261 | } |
255 | 262 | return 0; |
@@ -2,6 +2,7 @@ | ||
2 | 2 | #define __AD_FILE_H__ |
3 | 3 | |
4 | 4 | #include "ad_ring.h" |
5 | +#include "conf.h" | |
5 | 6 | |
6 | 7 | // データ記録用dir 末尾に/付けない |
7 | 8 | #ifdef DUMMY |
@@ -36,9 +37,9 @@ typedef struct { | ||
36 | 37 | |
37 | 38 | #define HIGH_WRITE_LEN szieof(HighSampleRecType) |
38 | 39 | #endif |
39 | - | |
40 | -#define HIGH_WRITE_LEN (9 + AD_CHNUM*AD_SAMPLE*AD_BYTES) // 仮で50Hz 記録周波数で変わるので要変更!!!!!!!!!!!!!! | |
41 | - | |
40 | +#define HIGH_HEADER_LEN 14 | |
41 | +#define HIGH_WRITE_LEN_MAX (HIGH_HEADER_LEN + AD_CHNUM*AD_SAMPLE*AD_BYTES) | |
42 | +#define HIGH_WRITE_LEN (HIGH_HEADER_LEN + AD_CHNUM*conf_freq_get()*AD_BYTES) // 記録周波数で変わる | |
42 | 43 | |
43 | 44 | int sec_file_open(FILE **fp, AdData *D); |
44 | 45 | int sec_file_out(FILE *fp, char *out, int len); |
@@ -31,6 +31,7 @@ typedef struct { | ||
31 | 31 | typedef struct { |
32 | 32 | UbloxNavTimeUtc gps; // GPSタイムスタンプ SPIで受信 |
33 | 33 | struct tm t; // タイムスタンプ struct tmの月は(0〜11)なので注意 年は1900からのオフセット |
34 | + int freq; // 平均周波数 Hz | |
34 | 35 | long data1sec[AD_CHNUM]; // 1sec平均値 SPIで受信 |
35 | 36 | long data[AD_CHNUM][AD_SAMPLE]; // AD_SAMPLE[Hz]の生データ SPIで受信 |
36 | 37 | long avg[AD_CHNUM][AD_SAMPLE]; // 平均後データ |
@@ -7,32 +7,28 @@ | ||
7 | 7 | #include "conf.h" |
8 | 8 | #include "debug_print.h" |
9 | 9 | |
10 | +// ミューテックス | |
11 | +static pthread_mutex_t mutex_conf = PTHREAD_MUTEX_INITIALIZER; | |
12 | + | |
10 | 13 | // |
11 | -/**** Station ID *************************************************** | |
14 | +/**** 記録周波数 *************************************************** | |
12 | 15 | */ |
13 | -#define SID_MAX 16 | |
14 | -static char gsid[SID_MAX + 1]; | |
15 | 16 | |
16 | -// ミューテックス | |
17 | -static pthread_mutex_t mutex_sid = PTHREAD_MUTEX_INITIALIZER; | |
17 | +static int freq; | |
18 | 18 | |
19 | -void sid_set(char *s) | |
19 | +void conf_freq_set(int f) | |
20 | 20 | { |
21 | -pthread_mutex_lock(&mutex_sid); | |
22 | - strncpy(gsid, s, SID_MAX); | |
23 | - gsid[SID_MAX] = 0; | |
24 | -pthread_mutex_unlock(&mutex_sid); | |
21 | +pthread_mutex_lock(&mutex_conf); | |
22 | + freq = f; | |
23 | +pthread_mutex_unlock(&mutex_conf); | |
25 | 24 | } |
26 | -void sid_get(char *s) | |
25 | +int conf_freq_get(void) | |
27 | 26 | { |
28 | -pthread_mutex_lock(&mutex_sid); | |
29 | - strncpy(s, gsid, SID_MAX); | |
30 | - s[SID_MAX] = 0; | |
31 | -pthread_mutex_unlock(&mutex_sid); | |
32 | -} | |
33 | -char *sid_getp(void) | |
34 | -{ | |
35 | - return gsid; | |
27 | + int f; | |
28 | +pthread_mutex_lock(&mutex_conf); | |
29 | + f = freq; | |
30 | +pthread_mutex_unlock(&mutex_conf); | |
31 | + return f; | |
36 | 32 | } |
37 | 33 | |
38 | 34 | // |
@@ -126,8 +122,9 @@ int conf_read(void) | ||
126 | 122 | { |
127 | 123 | FILE *fp; |
128 | 124 | char buf[256]; |
129 | - char buf2[256]; | |
130 | - | |
125 | +// char buf2[256]; | |
126 | + int f; | |
127 | + | |
131 | 128 | fp = fopen(CONF_FILE, "rt"); |
132 | 129 | if (fp == NULL) { |
133 | 130 | syslog(LOG_ERR, "conf_read(): conf file not found. %s", CONF_FILE); |
@@ -141,10 +138,10 @@ int conf_read(void) | ||
141 | 138 | trim_space(buf); |
142 | 139 | PDEBUG(buf); |
143 | 140 | PDEBUG("\n"); |
144 | - // Station ID | |
145 | - if (sscanf(buf, "sid = %s", buf2) == 1) { | |
146 | - sid_set(buf2); | |
147 | - syslog(LOG_INFO, "sid=%s", sid_getp()); | |
141 | + // 記録周波数 | |
142 | + if (sscanf(buf, "freq = %d", &f) == 1) { | |
143 | + conf_freq_set(f); | |
144 | + syslog(LOG_INFO, "freq=%d", conf_freq_get()); | |
148 | 145 | } |
149 | 146 | } |
150 | 147 | fclose(fp); |
@@ -2,12 +2,10 @@ | ||
2 | 2 | #define __CONF_H__ |
3 | 3 | |
4 | 4 | // 設定ファイル |
5 | -#define CONF_FILE "/etc/meas.conf" | |
5 | +#define CONF_FILE "/etc/scilog.conf" | |
6 | 6 | |
7 | -void sid_set(char *s); | |
8 | -void sid_get(char *s); | |
9 | -char *sid_getp(void); | |
7 | +void conf_freq_set(int f); | |
8 | +int conf_freq_get(void); | |
10 | 9 | int conf_read(void); |
11 | 10 | |
12 | - | |
13 | 11 | #endif |
@@ -8,11 +8,11 @@ LDFLAGS = | ||
8 | 8 | LIBS = -lm -lpthread |
9 | 9 | TEST_LIBS = $(LIBS) -lcunit |
10 | 10 | |
11 | -SRCS0 = thread_rcv.c spi.c ring.c ad_ring.c rec.c sts.c ad_file.c | |
11 | +SRCS0 = thread_rcv.c spi.c ring.c ad_ring.c thread_rec.c sts.c ad_file.c conf.c | |
12 | 12 | SRCS = scilog.c $(SRCS0) |
13 | 13 | TEST_SRCS = test.c $(SRCS0) |
14 | 14 | |
15 | -HDRS = mes_print.h debug_print.h my_thread.h spi.h ring.h ad_ring.h rec.h sts.h ad_file.h | |
15 | +HDRS = mes_print.h debug_print.h my_thread.h spi.h ring.h ad_ring.h thread_rec.h sts.h ad_file.h conf.h | |
16 | 16 | |
17 | 17 | OBJS = $(SRCS:.c=.o) |
18 | 18 | TEST_OBJS = $(TEST_SRCS:.c=.o) |
@@ -44,7 +44,7 @@ | ||
44 | 44 | |
45 | 45 | /**** 設定デフォルト値 |
46 | 46 | */ |
47 | -#define SID_DEF "DEF" | |
47 | +#define CONF_FREQ_DEF 50 | |
48 | 48 | |
49 | 49 | |
50 | 50 | // |
@@ -96,10 +96,10 @@ int main (int argc, char *argv[]) | ||
96 | 96 | //goto END; |
97 | 97 | |
98 | 98 | // デフォルト設定 |
99 | - sid_set(SID_DEF); | |
99 | + conf_freq_set(CONF_FREQ_DEF); | |
100 | 100 | // 設定ファイル読み込み |
101 | 101 | conf_read(); |
102 | - PDEBUG("sid=%s\n", sid_getp()); | |
102 | + PDEBUG("freq=%d\n", conf_freq_get()); | |
103 | 103 | // lcd_print("*"); |
104 | 104 | |
105 | 105 | PDEBUG("sciLogger %s START\n", VERSION); |
@@ -9,6 +9,7 @@ | ||
9 | 9 | |
10 | 10 | #include "spi.h" |
11 | 11 | #include "ad_ring.h" |
12 | +#include "conf.h" | |
12 | 13 | |
13 | 14 | /* |
14 | 15 | Little Endian |
@@ -80,8 +81,22 @@ static int decode(char *buf, AdData *ad) | ||
80 | 81 | */ |
81 | 82 | static void do_avg(int freq, AdData *ad) |
82 | 83 | { |
83 | -// 仮コード | |
84 | - memcpy(ad->avg, ad->data, AD_CHNUM*AD_SAMPLE*AD_BYTES); | |
84 | + int ch, i, j; | |
85 | + long add; | |
86 | + int avg_freq; | |
87 | + int avg_num; | |
88 | + | |
89 | + avg_freq = conf_freq_get(); | |
90 | + avg_num = AD_SAMPLE/avg_freq; | |
91 | + for(ch = 0; ch < AD_CHNUM; ch++) { | |
92 | + for(i = 0; i < avg_freq; i++) { | |
93 | + add = 0; | |
94 | + for(j = 0; j < avg_num; j++) { | |
95 | + add += ad->data[ch][i*avg_num + j]; | |
96 | + } | |
97 | + ad->avg[ch][i] = add / avg_num; | |
98 | + } | |
99 | + } | |
85 | 100 | } |
86 | 101 | void* thread_rcv(void* pParam) |
87 | 102 | { |
@@ -106,13 +121,12 @@ void* thread_rcv(void* pParam) | ||
106 | 121 | i = spi_dnum_get(); |
107 | 122 | //printf("thread_rcv(): wakeup dnum=%d rcv_len=%d\n", i, spi_rcvd_len_get()); |
108 | 123 | while(i-- > 0) { |
109 | - // バッファ書き込み位置get | |
110 | -// d = ring_get(ring_write_get()); | |
111 | -// ring_zero(); | |
124 | + memset(&ad, 0, sizeof(ad)); | |
112 | 125 | // データ取得 |
113 | 126 | spi_rx_get(buf); |
114 | 127 | // デコード |
115 | 128 | decode(buf, &ad); |
129 | + ad.freq = conf_freq_get(); | |
116 | 130 | // 平均 仮コード 要変更 |
117 | 131 | do_avg(AD_SAMPLE, &ad); |
118 | 132 | #if 0 |
@@ -85,7 +85,7 @@ int ProcRec(void) | ||
85 | 85 | { |
86 | 86 | AdData *d; |
87 | 87 | FILE *fp = NULL; |
88 | - char buf[HIGH_WRITE_LEN+128]; | |
88 | + char buf[HIGH_WRITE_LEN_MAX+128]; | |
89 | 89 | |
90 | 90 | // |
91 | 91 | /**** 1secデータ記録 |