• R/O
  • HTTP
  • SSH
  • HTTPS

scilog: Commit

Overoで動作するデータ収録プログラム
サブCPUからGPS時刻付きADデータを取得してSDに記録する。


Commit MetaInfo

Revisão542dc2688dc0b3810b65993a2a1ecc1b2ada784f (tree)
Hora2011-12-17 01:00:44
AutorNaoya Takamura <ntaka206@user...>
CommiterNaoya Takamura

Mensagem de Log

check sum calc add
conf.c:
gain関係set/get add
main.c:
 PICへのgain設定送信コード追加
 起動時にGain設定追加
thread_disp.c:

LCD表示追加

Mudança Sumário

Diff

--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ INCDIR = ${STAGEDIR}/include
3030
3131 TARGET = scilog
3232
33-OBJS = scilog.o spi.o thread_rcv.o ring.o ad_ring.o thread_rec.o sts.o ad_file.o conf.o lcd.o
33+OBJS = scilog.o spi.o thread_rcv.o ring.o ad_ring.o thread_rec.o sts.o ad_file.o conf.o lcd.o thread_disp.o
3434
3535 HDRS = mes_print.h debug_print.h spi.h my_thread.h ring.h ad_ring.h thread_rec.h sts.h ad_file.h conf.h lcd.h
3636
--- a/conf.c
+++ b/conf.c
@@ -30,6 +30,29 @@ pthread_mutex_lock(&mutex_conf);
3030 pthread_mutex_unlock(&mutex_conf);
3131 return f;
3232 }
33+//
34+/**** Gain ***************************************************
35+*/
36+/*
37+ 0=1/8, 1=1/4, 2=1/2, 3=1, 4=2, 5=4
38+ 6=8, 7=16, 8=32, 9=64, 10=128
39+*/
40+static int gain;
41+
42+void conf_gain_set(int f)
43+{
44+pthread_mutex_lock(&mutex_conf);
45+ gain = f;
46+pthread_mutex_unlock(&mutex_conf);
47+}
48+int conf_gain_get(void)
49+{
50+ int f;
51+pthread_mutex_lock(&mutex_conf);
52+ f = gain;
53+pthread_mutex_unlock(&mutex_conf);
54+ return f;
55+}
3356
3457 //
3558 /**** 設定ファイル *******************************************
@@ -143,6 +166,11 @@ int conf_read(void)
143166 conf_freq_set(f);
144167 syslog(LOG_INFO, "freq=%d", conf_freq_get());
145168 }
169+ // Gain
170+ if (sscanf(buf, "gain = %d", &f) == 1) {
171+ conf_gain_set(f);
172+ syslog(LOG_INFO, "gain=%d", conf_gain_get());
173+ }
146174 }
147175 fclose(fp);
148176 return 0;
--- a/conf.h
+++ b/conf.h
@@ -6,6 +6,10 @@
66
77 void conf_freq_set(int f);
88 int conf_freq_get(void);
9+
10+void conf_gain_set(int f);
11+int conf_gain_get(void);
12+
913 int conf_read(void);
1014
1115 #endif
--- a/my_thread.h
+++ b/my_thread.h
@@ -2,6 +2,7 @@
22 #define __MY_THREAD_H__
33
44 void* thread_rcv(void* pParam);
5+void* thread_disp(void* pParam);
56
67 #ifdef CUNIT
78 #include <CUnit/CUnit.h>
Binary files a/scilog and b/scilog differ
--- a/scilog.c
+++ b/scilog.c
@@ -46,7 +46,7 @@
4646 /**** 設定デフォルト値
4747 */
4848 #define CONF_FREQ_DEF 50
49-
49+#define CONF_GAIN_DEF SPI_CMD_GAIN_1P4
5050
5151 //
5252 /**** signal ***********************************************************
@@ -76,7 +76,7 @@ void sig_handler(int sig)
7676 */
7777 int main (int argc, char *argv[])
7878 {
79- pthread_t tid_rcv;
79+ pthread_t tid_rcv, tid_disp;
8080 // char buf[512];
8181
8282 signal(SIGINT, sig_handler);
@@ -98,9 +98,11 @@ int main (int argc, char *argv[])
9898
9999 // デフォルト設定
100100 conf_freq_set(CONF_FREQ_DEF);
101+ conf_gain_set(CONF_GAIN_DEF);
101102 // 設定ファイル読み込み
102103 conf_read();
103104 PDEBUG("freq=%d\n", conf_freq_get());
105+ PDEBUG("gain=%d\n", conf_gain_get());
104106 lcd_print("*");
105107
106108 PDEBUG("sciLogger %s START\n", VERSION);
@@ -115,20 +117,34 @@ int main (int argc, char *argv[])
115117 lcd_print("*");
116118
117119 //
120+/**** PGA設定
121+*/
122+ spi_cmd_send_gain(conf_gain_get());
123+ lcd_print("*");
124+//
118125 /**** スレッド生成
119126 */
120- // SPI RCV
127+ // SPI RCVと平均
121128 if (pthread_create(&tid_rcv, NULL, thread_rcv, NULL) != 0) {
122129 perror("pthread_create(SPI RCV)");
123- exit(EXIT_FAILURE);
130+ goto END;
124131 } else {
125132 PDEBUG("SPI RCV thread create\n");
126133 }
127134 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("*");
128143
129144 //
130145 /**** メインループ 記録 ************************
131146 */
147+ // 記録スレッド
132148 thread_rec(NULL);
133149 END:
134150 sig_handler(0);
--- a/spi.c
+++ b/spi.c
@@ -3,8 +3,10 @@
33 #include <sys/ioctl.h>
44 //#include <termios.h>
55 #include <fcntl.h>
6+#include <string.h>
67
78 #include "spi.h"
9+#include "ad_ring.h"
810
911 static int fd_spi = -1;
1012
@@ -66,3 +68,34 @@ int spi_rcvd_len_get(void)
6668 spi_ioctl(CMD_RECEIVED_LEN_GET, &i);
6769 return i;
6870 }
71+// コマンド送信
72+void spi_cmd_send(char cmd_code, char *cmd_data, int data_len)
73+{
74+ char cmd[SPI_CMD_LEN];
75+
76+ memset(cmd, 0, SPI_CMD_LEN);
77+
78+ cmd[SPI_CMD_OFS_HEAD] = SPI_HEAD_CHAR;
79+ cmd[SPI_CMD_OFS_CMDCODE] = cmd_code;
80+
81+ // data
82+ if (data_len > (SPI_CMD_LEN - SPI_CMD_OFS_CMDDATA)) {
83+ data_len = SPI_CMD_LEN - SPI_CMD_OFS_CMDDATA;
84+ }
85+ memcpy(&cmd[SPI_CMD_OFS_CMDDATA], cmd_data, data_len);
86+
87+ spi_tx_set(cmd);
88+}
89+// Gainコマンド送信
90+void spi_cmd_send_gain(int gain)
91+{
92+ char cmd[SPI_CMD_LEN];
93+ int i;
94+
95+ memset(cmd, 0, SPI_CMD_LEN);
96+
97+ for(i = 0; i < AD_CHNUM; i++)
98+ cmd[i] = gain;
99+ spi_cmd_send(SPI_CMDCODE_GAIN, cmd, AD_CHNUM);
100+}
101+
--- a/spi.h
+++ b/spi.h
@@ -1,9 +1,9 @@
11 #if !defined(__SPI_H__)
22 #define __SPI_H__
33
4+// ioctlコマンド
45 // SPI受信データ取得
56 #define CMD_RX_GET 11
6-
77 // SPI送信データ長セット
88 #define CMD_TX_LEN 12
99 // SPI送信データセット PICへのコマンド
@@ -16,7 +16,7 @@
1616 #define CMD_RECEIVED_LEN_GET 20
1717
1818 // SPIで受信するデータ長 固定長 $含む
19-#define SPI_DATA_LEN 965
19+#define SPI_DATA_LEN (965)
2020 // SPI受信データの先頭文字 送信コマンドでも使用
2121 #define SPI_HEAD_CHAR '$'
2222
@@ -26,16 +26,37 @@
2626 // SPI受信データ Checksum 長さ
2727 #define SPI_CHECKSUM_LEN 2
2828
29-// SPI送信するコマンド長 固定長 $含む
30-#define SPI_CMD_LEN 20
31-
32-
3329 // SPI受信データの先頭からのオフセット
34-#define SPI_OFS_GPS (19)
30+#define SPI_OFS_RESCODE 1
31+#define SPI_OFS_RESDATA 2
32+#define SPI_OFS_GPS (19)
3533 #define SPI_OFS_1SEC (39)
3634 #define SPI_OFS_DATA (63)
35+#define SPI_OFS_SUM 963
3736
37+// SPI送信コマンド長 固定長 $含む
38+#define SPI_CMD_LEN 20
39+
40+// SPI送信コマンド フィールドのオフセット位置
41+#define SPI_CMD_OFS_HEAD 0
42+#define SPI_CMD_OFS_CMDCODE 1
43+#define SPI_CMD_OFS_CMDDATA 2
3844
45+// SPIコマンドコード
46+#define SPI_CMDCODE_GAIN 1
47+
48+// SPIコマンドGainの設定値
49+#define SPI_CMD_GAIN_1P8 0 // 1/8
50+#define SPI_CMD_GAIN_1P4 1 // 1/4
51+#define SPI_CMD_GAIN_1P2 2 // 1/2
52+#define SPI_CMD_GAIN_1 3
53+#define SPI_CMD_GAIN_2 4
54+#define SPI_CMD_GAIN_4 5
55+#define SPI_CMD_GAIN_8 6
56+#define SPI_CMD_GAIN_16 7
57+#define SPI_CMD_GAIN_32 8
58+#define SPI_CMD_GAIN_64 9
59+#define SPI_CMD_GAIN_128 10
3960
4061
4162 int spi_get_fd(void);
@@ -50,4 +71,7 @@ void spi_buf_clear(void);
5071 int spi_dnum_get(void);
5172 int spi_rcvd_len_get(void);
5273
74+void spi_cmd_send(char cmd_code, char *cmd_data, int data_len);
75+void spi_cmd_send_gain(int gain);
76+
5377 #endif
--- /dev/null
+++ b/thread_disp.c
@@ -0,0 +1,94 @@
1+#include <stdio.h>
2+
3+#include "ad_ring.h"
4+#include "lcd.h"
5+
6+static void scr_init(void)
7+{
8+ int iLeft = 0;
9+ int iY = 0;
10+
11+ lcd_clear();
12+
13+ lcd_pos(iLeft, iY);
14+ lcd_print("TIME:");
15+ iY++;
16+// lcd_pos(iLeft, iY);
17+// lcd_print("STS:");
18+// iY++;
19+ lcd_pos(iLeft, iY);
20+ lcd_print("HX:");
21+ iY++;
22+ lcd_pos(iLeft, iY);
23+ lcd_print("HY:");
24+ iY++;
25+ lcd_pos(iLeft, iY);
26+ lcd_print("HZ:");
27+ iY++;
28+}
29+
30+/*
31+
32+*/
33+static void scr_disp_time(AdData *d)
34+{
35+ int iLeft, iY;
36+ char buf[128];
37+ struct tm *t;
38+
39+ t = &(d->t);
40+ iLeft = 0;
41+ iY = 0;
42+ /* Time */
43+ lcd_pos(iLeft, iY++);
44+ sprintf(buf, "%02d/%02d/%02d %02d:%02d:%02d %02X",
45+ t->tm_year % 100, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,
46+ d->gps.valid);
47+ lcd_print(buf);
48+}
49+/*
50+
51+*/
52+static void scr_disp_ad(AdData *d)
53+{
54+ int iLeft, iY;
55+ char buf[128];
56+ int ch = 0;
57+
58+ iLeft = 0;
59+ iY = 1;
60+ for(ch = 0; ch < 3; ch++) {
61+ sprintf(buf, "%d% 8ld", ch+1, d->data1sec[ch]);
62+ lcd_pos(iLeft, iY++);
63+ lcd_print(buf);
64+ }
65+ iLeft = 10;
66+ iY = 1;
67+ for(ch = 3; ch < 6; ch++) {
68+ sprintf(buf, "%d% 8ld", ch+1, d->data1sec[ch]);
69+ lcd_pos(iLeft, iY++);
70+ lcd_print(buf);
71+ }
72+}
73+
74+void* thread_disp(void* pParam)
75+{
76+ int i;
77+ AdData *d;
78+
79+ i = ad_ring_latest_get();
80+// scr_init();
81+ lcd_clear();
82+ while(1) {
83+ // FG表示
84+ if (i != ad_ring_latest_get()) {
85+ i = ad_ring_latest_get();
86+ // データ取得
87+ d = ad_ring_get(i);
88+ // 時刻表示
89+ scr_disp_time(d);
90+ // AD表示
91+ scr_disp_ad(d);
92+ }
93+ }
94+}
--- a/thread_rcv.c
+++ b/thread_rcv.c
@@ -70,7 +70,7 @@ static int decode(char *buf, AdData *ad)
7070 }
7171 }
7272 // Checksum
73- memcpy(&(ad->checksum), ptr, SPI_CHECKSUM_LEN);
73+ ad->checksum = *((u_int16_t*)ptr);
7474
7575 // gps->struct tm
7676 ad->t.tm_year = gps->year - 1900;
@@ -105,6 +105,21 @@ static void do_avg(int freq, AdData *ad)
105105 }
106106 }
107107 }
108+static unsigned int sum_calc(char *buf)
109+{
110+ int i;
111+ u_int8_t suma = 0;
112+ u_int8_t sumb = 0;
113+ u_int16_t uint_sum;
114+
115+ for(i = SPI_OFS_RESCODE; i < SPI_OFS_SUM; i++) {
116+ suma += (u_int8_t)buf[i];
117+ sumb += suma;
118+ }
119+ uint_sum = ((sumb << 8) & 0xFF00U) | suma;
120+ return uint_sum;
121+}
122+
108123 void* thread_rcv(void* pParam)
109124 {
110125
@@ -113,6 +128,7 @@ void* thread_rcv(void* pParam)
113128 int i;
114129 int fd_spi;
115130 AdData ad, *ad_ptr;
131+ unsigned int sum;
116132 #if 0
117133 char cmd[SPI_CMD_LEN];
118134 char c;
@@ -135,12 +151,12 @@ c=0;
135151 if(FD_ISSET(fd_spi, &fds)) {
136152 #if 0
137153 // SPI送信データセット
138-memset(cmd, 0, SPI_CMD_LEN);
139-cmd[0] = SPI_HEAD_CHAR;
140-cmd[1] = 1;
141-cmd[2] = 2;
142-cmd[3] = c++;
143-spi_tx_set(cmd);
154+if (c++ % 5 == 0) {
155+ memset(cmd, 0, SPI_CMD_LEN);
156+ for(i = 0; i < AD_CHNUM; i++)
157+ cmd[i] = SPI_CMD_GAIN_128;
158+ spi_cmd_send(SPI_CMDCODE_GAIN, cmd, AD_CHNUM);
159+}
144160 #endif
145161 // 受信した
146162 i = spi_dnum_get();
@@ -151,14 +167,19 @@ spi_tx_set(cmd);
151167 spi_rx_get(buf);
152168 // デコード
153169 decode(buf, &ad);
170+ // chekcsum check
171+ sum = sum_calc(buf);
172+ if (sum != ad.checksum) {
173+ PDEBUG("thread_rcv(): SUM ERR! CALC=%04X RCV=%04X\r\n", sum, ad.checksum);
174+ }
175+ // 平均
154176 ad.freq = conf_freq_get();
155- // 平均 仮コード 要変更
156177 do_avg(AD_SAMPLE, &ad);
157178 #if 1
158179 int ch;
159-PDEBUG("%04d/%02d/%02d %02d:%02d:%02d.%09ld,%6lums,%6luns,%02X",
180+PDEBUG("%04d/%02d/%02d %02d:%02d:%02d.%09ld,%6lums,%6luns,%02X,%d",
160181 ad.gps.year, ad.gps.month, ad.gps.day, ad.gps.hour, ad.gps.min, ad.gps.sec, ad.gps.nano,
161- ad.gps.tow, ad.gps.tacc, ad.gps.valid);
182+ ad.gps.tow, ad.gps.tacc, ad.gps.valid, ad.rescode);
162183 for(ch = 0; ch < AD_CHNUM; ch++) {
163184 PDEBUG(",%+7ld", ad.data1sec[ch]);
164185 }
Show on old repository browser