OSDN Git Service

756cd89dfac822eb16ca0412701b3075f20f1dc0
[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
26 // debug_print.h内で#define   DEBUG_PRINTしているので
27 // リリース時は、debug_print.hでコメントする
28 #include "debug_print.h"
29
30 #define MES_PRINT
31 #include        "mes_print.h"
32
33 // ダミーデータを自分で発生するときに定義
34 //#define       DUMMY
35
36 #define VERSION "1.0"
37
38 #define DEV_SPI "/dev/spike-ad"
39
40 /**** 設定デフォルト値
41 */
42 //#define       SID_DEF "DEF"
43
44
45 //
46 /**** signal ***********************************************************
47 */
48 void cleanup(void)
49 {
50         spi_close();
51 }
52 void sig_handler(int sig)
53 {
54         char    szBuf[128];
55         static int      busy = 0;
56
57         if (busy) return;
58         busy = 1;
59
60         sprintf(szBuf, "signal trap. signal=%d\n", sig);
61         PDEBUG("%s", szBuf);
62         fflush(stdout);
63         fflush(stderr);
64
65         cleanup();
66         exit(0);
67 }
68 //
69 /**** main
70 */
71 int main (int argc, char *argv[])
72 {
73         pthread_t       tid_rcv;
74 //      char    buf[512];
75         
76         signal(SIGINT, sig_handler);
77         signal(SIGQUIT, sig_handler);
78         signal(SIGKILL, sig_handler);
79         signal(SIGTERM, sig_handler);
80
81 //      lcd_init();
82 //      lcd_pos(6, 1);
83 //      lcd_print("sciLogger");
84 //      lcd_pos(0, 3);
85
86         // デフォルト設定
87 //      sid_set(SID_DEF);
88         // 設定ファイル読み込み
89 //      conf_read();
90 //      PDEBUG("sid=%s\n", sid_getp());
91 //      lcd_print("*");
92
93         PDEBUG("sciLogger %s START\n", VERSION);
94         sleep(1);
95 //
96 /**** デバイスOPEN
97 */
98         if (spi_open(DEV_SPI) < 0) {
99                 perror("spi_open() ERROR!");
100                 goto END;
101         }
102 //      lcd_print(fd_lcd0, "*");
103
104 //
105 /**** スレッド生成
106 */
107         // SPI RCV
108         if (pthread_create(&tid_rcv, NULL, thread_rcv, NULL) != 0) {
109                 perror("pthread_create(SPI RCV)");
110                 exit(EXIT_FAILURE);
111         } else {
112                 PDEBUG("SPI RCV thread create\n");
113         }
114 //      lcd_print("*");
115
116 //
117 /**** メインループ 記録 ************************
118 */
119         while(1) {
120                 sleep(1);
121         } // メインループ終わり
122 END:
123         sig_handler(0);
124
125         return 0;
126 }