3 sciLogger high sample data decoder
6 このプログラムが動作するマシンもLittle Endianである必要あり。
10 * 記録するCH数を変更できるようになったので対応
11 * ヘッダにはCH数を保存していないので、CH数をコマンドラインで指定する必要がある
12 * 指定しなかった場合はDefault 6CH
14 * Usage: decode_sci -c CH_NUM inputfile
15 * CH_NUM ファイルに記録されているCH数を指定する 無指定時のDefaultは6
17 Copyright Naoya Takamura@NT systemd design, 2011
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
43 #define EXE_NAME "decode_sci"
45 struct _recdata_head_t {
54 uint16_t freq; // 記録周波数 Hz
55 } __attribute__((__packed__));
58 typedef struct _recdata_head_t recdata_head;
60 #define REC_DATALEN_HEAD sizeof(recdata_head)
64 3byte -> signed long(4byte)
66 static int32_t b3_to_long32(unsigned char *ptr)
78 return *((int32_t*)buf);
84 static void read_high(FILE *fp, int chn)
88 uint8_t data[AD_CH * AD_SAMPLE * AD_BYTES];
92 if (fread(&d, 1, REC_DATALEN_HEAD, fp) < 1) break;
93 //fprintf(stderr, "%02d:%02d:%02d.%03d %d %d", d.hour, d.min, d.sec, (1000*j/AD_SAMPLE), d.tacc, d.valid);
94 if (d.freq > AD_SAMPLE || d.freq < 1) {
95 fprintf(stderr, "read_high() Error freq=%d\n", d.freq);
98 int data_size = chn * d.freq * AD_BYTES;
100 if (fread(data, 1, data_size, fp) < 1) break;
101 for(j = 0; j < d.freq; j++) {
102 fprintf(stdout, "%02d:%02d:%02d.%03d", d.hour, d.min, d.sec, (1000*j/d.freq));
103 for(ch = 0; ch < chn; ch++) {
104 fprintf(stdout, ",%+07d", b3_to_long32((char*)(data + ch*d.freq*AD_BYTES + j*AD_BYTES)));
106 fprintf(stdout, "\n");
111 int main(int argc, char *argv[])
117 unsigned char buf[256];
122 printf("sciLogger high sample data converter Ver"VER"\n");
123 printf("Please set filename.\n");
125 printf(EXE_NAME " -c CH_NUM inputfile\n");
128 while((result = getopt(argc, argv, "c:")) != -1) {
132 if (chn <= 0 || chn > AD_CH) {
133 fprintf(stderr, "Invalid CH num %d.\n", chn);
140 fpin = fopen(argv[optind], "rb");
143 fprintf(stderr, "Input file open error.\n");
147 strcpy(fname_out, argv[optind]);
148 strcat(fname_out, ".txt");
150 fpout = freopen(fname_out, "w", stdout);
152 fprintf(stderr, "Output file open ERROR. %s\n", fname_out);
155 read_high(fpin, chn);