OSDN Git Service

GPS valid=07にならなくても記録を開始してしまうバグ修正
[scilog/scilog.git] / scilog.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <time.h>
4 #include <math.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <errno.h>
8 #include <stdarg.h>
9 //#include <getopt.h>
10 #include <stdlib.h>
11 #include <assert.h>
12 #include <signal.h>
13 #include <pthread.h>
14 #include <syslog.h>
15
16 #include <stdint.h>
17 #include <sys/ioctl.h>
18 #include <fcntl.h>
19 #include <linux/i2c-dev.h> /* for I2C_SLAVE */
20
21 #include <sys/stat.h>
22
23 #include "my_thread.h"
24 #include "spi.h"
25 #include "ad_ring.h"
26 #include "sts.h"
27 #include "thread_rec.h"
28 #include "conf.h"
29 #include "ad_file.h"
30 #include "lcd.h"
31
32 // debug_print.h内で#define   DEBUG_PRINTしているので
33 // リリース時は、debug_print.hでコメントする
34 #include "debug_print.h"
35
36 #define MES_PRINT
37 #include        "mes_print.h"
38
39 // ダミーデータを自分で発生するときに定義
40 //#define       DUMMY
41
42 #define VERSION "1.0.1"
43
44 #define DEV_SPI "/dev/spike-ad"
45
46 /**** 設定デフォルト値
47 */
48 #define CONF_FREQ_DEF   50
49 #define CONF_GAIN_DEF   SPI_CMD_GAIN_1P4
50
51 //
52 /**** signal ***********************************************************
53 */
54 void cleanup(void)
55 {
56         spi_close();
57 }
58 void sig_handler(int sig)
59 {
60         char    szBuf[128];
61         static int      busy = 0;
62
63         if (busy) return;
64         busy = 1;
65
66         sprintf(szBuf, "signal trap. signal=%d\n", sig);
67         PDEBUG("%s", szBuf);
68         fflush(stdout);
69         fflush(stderr);
70
71         cleanup();
72         exit(0);
73 }
74 //
75 /**** main
76 */
77 int main (int argc, char *argv[])
78 {
79         pthread_t       tid_rcv, tid_disp;
80 //      char    buf[512];
81         
82         signal(SIGINT, sig_handler);
83         signal(SIGQUIT, sig_handler);
84         signal(SIGKILL, sig_handler);
85         signal(SIGTERM, sig_handler);
86
87         lcd_init();
88         lcd_pos(6, 1);
89         lcd_print("sciLogger");
90         lcd_pos(0, 3);
91
92         ad_ring_init();
93         sts_init();
94
95 //printf("%d\n", sizeof(UbloxNavTimeUtcRecType));
96 //printf("%d\n", sizeof(HighSampleRecType));
97 //goto END;
98
99         // デフォルト設定
100         conf_freq_set(CONF_FREQ_DEF);
101         conf_gain_set(CONF_GAIN_DEF);
102         // 設定ファイル読み込み
103         conf_read();
104         PDEBUG("freq=%d\n", conf_freq_get());
105         PDEBUG("gain=%d\n", conf_gain_get());
106         lcd_print("*");
107
108         PDEBUG("sciLogger %s START\n", VERSION);
109         sleep(1);
110 //
111 /**** デバイスOPEN
112 */
113         if (spi_open(DEV_SPI) < 0) {
114                 perror("spi_open() ERROR!");
115                 goto END;
116         }
117         lcd_print("*");
118
119 //
120 /**** PGA設定
121 */
122         spi_cmd_send_gain(conf_gain_get());
123         lcd_print("*");
124 //
125 /**** スレッド生成
126 */
127         // SPI RCVと平均
128         if (pthread_create(&tid_rcv, NULL, thread_rcv, NULL) != 0) {
129                 perror("pthread_create(SPI RCV)");
130                 goto END;
131         } else {
132                 PDEBUG("SPI RCV thread create\n");
133         }
134         lcd_print("*");
135         // 表示
136         if (pthread_create(&tid_disp, NULL, thread_disp, NULL) != 0) {
137                 perror("pthread_create(DISP)");
138                 goto END;
139         } else {
140                 PDEBUG("DISP thread create\n");
141         }
142         lcd_print("*");
143
144 //
145 /**** メインループ 記録 ************************
146 */
147         // 記録スレッド
148         thread_rec(NULL);
149 END:
150         sig_handler(0);
151
152         return 0;
153 }