Commit 932f2ca3 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Added option buffered_time and management of skipped packets


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@568 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent e9ead50b
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.98 2007-12-17 08:38:03 mtheo Exp $
* $Id: nmxptool.c,v 1.99 2007-12-17 10:36:57 mtheo Exp $
*
*/
......@@ -593,6 +593,8 @@ int main (int argc, char **argv) {
}
#endif
double after_start_time = params.buffered_time;
int skip_current_packet = 0;
while(exitpdscondition) {
......@@ -612,6 +614,29 @@ int main (int argc, char **argv) {
nmxp_data_log(pd);
}
skip_current_packet = 0;
if(pd) {
if(pd->time + ((double) pd->nSamp / (double) pd->sampRate) >= after_start_time) {
if(pd->time < after_start_time) {
int first_nsample_to_remove = (after_start_time - pd->time) * (double) pd->sampRate;
/* Remove the first sample in order avoiding overlap */
first_nsample_to_remove++;
if(pd->nSamp > first_nsample_to_remove) {
pd->nSamp -= first_nsample_to_remove;
pd->time = after_start_time;
pd->pDataPtr += first_nsample_to_remove;
pd->x0 = pd->pDataPtr[0];
} else {
skip_current_packet = 1;
}
}
} else {
skip_current_packet = 1;
}
}
if(!skip_current_packet) {
if(pd) {
/* Set cur_chan */
cur_chan = nmxp_chan_lookupKeyIndex(pd->key, channelList_subset);
......@@ -678,17 +703,18 @@ int main (int argc, char **argv) {
#endif
}
}
} /* End skip_current_packet condition */
if(pd) {
/* Store x_1 */
if(pd->nSamp > 0) {
channelListSeq[cur_chan].x_1 = pd->pDataPtr[pd->nSamp-1];
}
/* Free pd->buffer */
if(pd->buffer) {
free(pd->buffer);
pd->buffer = NULL;
}
/* Store x_1 */
if(pd->nSamp > 0) {
channelListSeq[cur_chan].x_1 = pd->pDataPtr[pd->nSamp-1];
}
/* Free pd->buffer */
if(pd->buffer) {
free(pd->buffer);
pd->buffer = NULL;
}
}
#ifdef HAVE_EARTHWORMOBJS
......@@ -706,7 +732,7 @@ int main (int argc, char **argv) {
}
#endif
}
} /* End main PDS loop */
/* Flush raw data stream for each channel */
flushing_raw_data_stream();
......@@ -794,7 +820,11 @@ static void save_channel_states() {
);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "%s\n", state_line_str);
if(fstatefile) {
fprintf(fstatefile, "%s\n", state_line_str);
if( (channelListSeq[to_cur_chan].last_time != 0) || (channelListSeq[to_cur_chan].raw_stream_buffer.last_sample_time != -1.0) ) {
fprintf(fstatefile, "%s\n", state_line_str);
} else {
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "%s\n", state_line_str);
}
}
to_cur_chan++;
}
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.47 2007-12-17 07:37:10 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.48 2007-12-17 10:36:57 mtheo Exp $
*
*/
......@@ -43,6 +43,7 @@ const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
DEFAULT_VERBOSE_LEVEL,
NULL,
NULL,
0.0,
0,
0,
0,
......@@ -223,6 +224,8 @@ PDS arguments:\n\
0 for original sample rate and decompressed data.\n\
>0 for specified sample rate and decompressed data.\n\
-b, --buffered Request also recent packets into the past.\n\
-B, --buff_date=DATE Request also recent packets into the past\n\
but consider only samples after DATE.\n\
-L, --listchannelsnaqs Print list of available channels on NaqsServer.\n\
-M, --maxlatency=SECs Max tolerable latency (default %d) [%d..%d].\n\
-T, --timeoutrecv=SECs Time-out for flushing buffered packets.\n\
......@@ -290,6 +293,7 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
{"maxlatency", required_argument, 0, 'M'},
{"timeoutrecv", required_argument, 0, 'T'},
{"verbose", required_argument, 0, 'v'},
{"bufferedt", required_argument, 0, 'B'},
/* Following are flags */
{"logdata", no_argument, 0, 'g'},
{"buffered", no_argument, 0, 'b'},
......@@ -309,7 +313,7 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
{0, 0, 0, 0}
};
char optstr[100] = "H:P:D:C:N:n:S:R:s:e:t:d:u:p:M:T:v:F:gblLiwhV";
char optstr[100] = "H:P:D:C:N:n:S:R:s:e:t:d:u:p:M:T:v:B:F:gblLiwhV";
#ifdef HAVE_LIBMSEED
strcat(optstr, "m");
......@@ -452,6 +456,16 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
params->verbose_level = atoi(optarg);
break;
case 'B':
params->flag_buffered = 1;
if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
// MESSAGE ERROR
ret_errors++;
} else {
params->buffered_time = nmxp_data_tm_to_time(&tmp_tmt);
}
break;
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
case 'k':
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.h,v 1.37 2007-12-17 08:40:08 mtheo Exp $
* $Id: nmxptool_getoptlong.h,v 1.38 2007-12-17 10:36:57 mtheo Exp $
*
*/
......@@ -71,6 +71,7 @@ typedef struct {
int32_t verbose_level;
char *ew_configuration_file;
char *statefile;
double buffered_time;
int flag_writeseed;
int flag_listchannels;
int flag_listchannelsnaqs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment