6 定義するとファイルが1日単位ではなく指定された分単位になる
7 ただし、ファイルのサイズは1日と同じサイズのまま
8 #deifne DEBUG_FILE_MIN_PERIOD
15 #include <sys/types.h>
24 #include "debug_print.h"
28 #define MKDIR_MODE "755"
41 static int mkdir_p(const char *path, char *mode)
46 // コピー先ディレクトリ存在しなければ作成する
47 if (stat(path, &st) == -1) {
48 PDEBUG("mkdir_p(): make dir %s\n", path);
50 sprintf(cmd, "mkdir -p -m %s %s > /dev/null 2> /dev/null &", mode, path);
54 PDEBUG("mkdir_p(): shell exec error\n");
55 syslog(LOG_ERR, "mkdir_p(): system() shell exec error");
59 PDEBUG("mkdir_p(): error\n");
60 syslog(LOG_ERR, "mkdir_p(): system() error");
72 /**** 1秒ファイル関係 ************************************************************
81 int sec_file_open(FILE **fp, AdData *D)
89 sprintf(szDir, "%s/%s/%04d/%02d", DIR_DATA, sid_getp(), D->t.tm_year+1900, D->t.tm_mon+1);
91 if (stat(szDir, &st) == -1) mkdir_p(szDir, MKDIR_MODE);
95 sprintf(fname, "%04d%02d%02d_%02d%02d.sec",
96 D->t.tm_year+1900, D->t.tm_mon+1, D->t.tm_mday, D->t.tm_hour, D->t.tm_min / DEBUG_FILE_MIN_PERIOD * DEBUG_FILE_MIN_PERIOD);
98 sprintf(fname, "%04d%02d%02d.sec", D->t.tm_year+1900, D->t.tm_mon+1, D->t.tm_mday);
104 PDEBUGF("path=%s\n", path);
106 *fp = fopen(path, "a");
108 syslog(LOG_ERR, "%s(): fopen() ERROR. %s", __FUNCTION__, strerror(errno));
118 int sec_file_out(FILE *fp, char *out, int len)
122 if (fp == NULL) return 1;
123 if ((ret = fwrite(out, 1, len, fp)) < len) {
124 syslog(LOG_ERR, "%s(): fwrite() return %d < %d. %s", __FUNCTION__, ret, len, strerror(errno));
136 int sec_file_close(FILE *fp)
138 if (fp == NULL) return 1;
146 int sec_make_rec_data(AdData *ad, char *buf)
151 sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d,%3lu,%02X",
152 ad->gps.year, ad->gps.month, ad->gps.day, ad->gps.hour, ad->gps.min, ad->gps.sec,
153 ad->gps.tacc, ad->gps.valid);
154 for(ch = 0; ch < AD_CHNUM; ch++) {
155 sprintf(buf2, ",%+7ld", ad->data1sec[ch]);
161 /**** 高速サンプルファイル関係 ************************************************************
168 int high_file_open(FILE **fp, AdData *D)
176 sprintf(szDir, "%s/%s/%04d/%02d", DIR_DATA, sid_getp(), D->t.tm_year+1900, D->t.tm_mon+1);
178 if (stat(szDir, &st) == -1) mkdir_p(szDir, MKDIR_MODE);
181 #ifdef DEBUG_FILE_MIN
182 sprintf(fname, "%04d%02d%02d_%02d%02d.sec",
183 D->t.tm_year+1900, D->t.tm_mon+1, D->t.tm_mday, D->t.tm_hour, D->t.tm_min / DEBUG_FILE_MIN_PERIOD * DEBUG_FILE_MIN_PERIOD);
185 sprintf(fname, "%04d%02d%02d%02d.high", D->t.tm_year+1900, D->t.tm_mon+1, D->t.tm_mday, D->t.tm_hour);
191 PDEBUGF("path=%s\n", path);
193 *fp = fopen(path, "a");
195 syslog(LOG_ERR, "%s(): fopen() ERROR. %s", __FUNCTION__, strerror(errno));
205 int high_file_out(FILE *fp, char *out, int len)
209 if (fp == NULL) return 1;
210 if ((ret = fwrite(out, 1, len, fp)) < len) {
211 syslog(LOG_ERR, "%s(): fwrite() return %d < %d. %s", __FUNCTION__, ret, len, strerror(errno));
221 int high_file_close(FILE *fp)
223 if (fp == NULL) return 1;
231 int high_make_rec_data(AdData *ad, char *ptr)
236 *ptr++ = ad->gps.year & 0xFF;
237 *ptr++ = (ad->gps.year >> 8) & 0xFF;
238 *ptr++ = ad->gps.month;
239 *ptr++ = ad->gps.day;
240 *ptr++ = ad->gps.hour;
241 *ptr++ = ad->gps.min;
242 *ptr++ = ad->gps.sec;
243 *ptr++ = ad->gps.nano;
244 *ptr++ = ad->gps.valid;
247 for(ch = 0; ch < AD_CHNUM; ch++) {
248 for(i = 0; i < AD_SAMPLE; i++) {
249 for(j = 0; j < AD_BYTES; j++) {