Commit 7ab962cc authored by Matteo Quintiliani's avatar Matteo Quintiliani

Added option to send data to Seedlink by the function send_mseed() instead of send_raw_depoch().

Option added is -K that is not usable togheter with -k.


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1207 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 785bd9c7
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.208 2009-01-15 08:50:45 mtheo Exp $
* $Id: nmxptool.c,v 1.209 2009-02-16 07:51:50 mtheo Exp $
*
*/
......@@ -79,6 +79,13 @@ int nmxptool_logerr_miniseed(const char *s);
int nmxptool_send_raw_depoch(NMXP_DATA_PROCESS *pd);
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
void nmxptool_msr_send_mseed_handler (char *record, int reclen, void *handlerdata);
int nmxptool_msr_send_mseed(NMXP_DATA_PROCESS *pd);
#endif
#endif
#ifdef HAVE_PTHREAD_H
pthread_t thread_request_channels;
pthread_attr_t attr_request_channels;
......@@ -342,6 +349,15 @@ int main (int argc, char **argv) {
}
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
/* Send data to SeedLink Server */
if(params.flag_slinkms) {
p_func_pd[n_func_pd++] = nmxptool_msr_send_mseed;
}
#endif
#endif
#ifdef HAVE_EARTHWORMOBJS
if(params.ew_configuration_file) {
p_func_pd[n_func_pd++] = nmxptool_ew_nmx2ew;
......@@ -397,7 +413,7 @@ int main (int argc, char **argv) {
nmxptool_chanseq_init(&channelList_Seq, channelList_subset->number, DEFAULT_BUFFERED_TIME, params.max_tolerable_latency, params.timeoutrecv);
#ifdef HAVE_LIBMSEED
if(params.type_writeseed) {
if(params.type_writeseed || params.flag_slinkms) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_EXTRA, "Init mini-SEED record list.\n");
/* Init mini-SEED record list */
......@@ -755,6 +771,15 @@ int main (int argc, char **argv) {
}
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
/* Send data to SeedLink Server */
if(params.flag_slinkms) {
nmxptool_msr_send_mseed(pd);
}
#endif
#endif
#ifdef HAVE_EARTHWORMOBJS
if(params.ew_configuration_file) {
nmxptool_ew_nmx2ew(pd);
......@@ -1085,6 +1110,15 @@ int main (int argc, char **argv) {
if(params.flag_slink) {
nmxptool_send_raw_depoch(pd);
}
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
/* Send data to SeedLink Server */
if(params.flag_slinkms) {
nmxptool_msr_send_mseed(pd);
}
#endif
#endif
}
}
......@@ -1172,7 +1206,8 @@ int main (int argc, char **argv) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "End communication.\n");
#ifdef HAVE_LIBMSEED
if(params.type_writeseed) {
if(params.type_writeseed || params.flag_slinkms) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_EXTRA, "Free mini-SEED record list.\n");
if(*msr_list_chan) {
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
if(msr_list_chan[i_chan]) {
......@@ -1320,6 +1355,7 @@ void *nmxptool_print_params(void *arg) {
int flag_request_channelinfo: %d\n\
int flag_writefile: %d\n\
int flag_slink: %d\n\
int flag_slinkms: %d\n\
int flag_buffered: %d\n\
int flag_logdata: %d\n\
int flag_logsample: %d\n\
......@@ -1331,6 +1367,7 @@ void *nmxptool_print_params(void *arg) {
params.flag_request_channelinfo,
params.flag_writefile,
params.flag_slink,
params.flag_slinkms,
params.flag_buffered,
params.flag_logdata,
params.flag_logsample
......@@ -1464,6 +1501,77 @@ int nmxptool_write_miniseed(NMXP_DATA_PROCESS *pd) {
}
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
void nmxptool_msr_send_mseed_handler (char *record, int reclen, void *handlerdata) {
int ret = 0;
NMXP_DATA_PROCESS *pd = handlerdata;
ret = send_mseed(pd->station, record, reclen);
if ( ret <= 0 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
"send_mseed() for %s.%s.%s\n", pd->network, pd->station, pd->channel);
}
}
int nmxptool_msr_send_mseed(NMXP_DATA_PROCESS *pd) {
int ret = 0;
int cur_chan;
MSRecord *msr = NULL;
int psamples;
int precords;
flag verbose = 0;
flag flush = 1;
if( (cur_chan = nmxp_chan_lookupKeyIndex(pd->key, channelList_subset)) != -1) {
msr = msr_list_chan[cur_chan];
if(pd) {
if(pd->nSamp > 0) {
/* Populate MSRecord values */
msr->starttime = MS_EPOCH2HPTIME(pd->time);
msr->samprate = pd->sampRate;
/* msr->byteorder = 0; */ /* big endian byte order */
msr->byteorder = nmxp_data_bigendianhost ();
msr->sequence_number = pd->seq_no % 1000000;
msr->sampletype = 'i'; /* declare type to be 32-bit integers */
msr->numsamples = pd->nSamp;
msr->datasamples = NMXP_MEM_MALLOC (sizeof(int) * (msr->numsamples));
memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
/* ??? TODO msr_srcname (msr, data_seed->srcname, 0); ??? */
/* msr_print(msr, 2); */
precords = msr_pack (msr, &nmxptool_msr_send_mseed_handler, pd, &psamples, flush, verbose);
if ( precords == -1 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
"Cannot pack records %s.%s.%s\n", pd->network, pd->station, pd->channel);
} else {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN,
"Packed %d samples into %d records for %s.%s.%s\n",
psamples, precords, pd->network, pd->station, pd->channel);
}
}
}
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "Key %d not found in channelList_subset!\n", pd->key);
}
return ret;
}
#endif
#endif
int nmxptool_print_seq_no(NMXP_DATA_PROCESS *pd) {
int ret = 0;
char str_time[200];
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.108 2008-11-07 22:44:32 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.109 2009-02-16 07:50:46 mtheo Exp $
*
*/
......@@ -61,6 +61,7 @@ const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
0,
0,
0,
0,
0
};
......@@ -372,9 +373,22 @@ Other arguments:\n\
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
-k, --slink=PLUGINID Send received data to SeedLink as a plug-in.\n\
Data are sent by send_raw_depoch().\n\
This option, inside the file seedlink.ini, must be\n\
the last without adding value for PLUGINID!\n\
PLUGINID is set by SeisComP daemon.\n");
PLUGINID is set by SeisComP daemon.\n\
Not usable together with -K.\n");
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
-K, --slinkms=PLUGINID Send received data to SeedLink as a plug-in.\n\
This option is similar to previous -k,\n\
the difference is by -K program use send_mseed()\n\
instead of send_raw_depoch().\n\
Not usable together with -k.\n");
#endif
#endif
#ifndef HAVE_WINDOWS_H
......@@ -569,6 +583,11 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
{"slink", required_argument, NULL, 'k'},
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
{"slinkms", required_argument, NULL, 'K'},
#endif
#endif
#ifndef HAVE_WINDOWS_H
{"socketport", required_argument, NULL, 'E'},
#endif
......@@ -593,6 +612,12 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
strcat(optstr, "k:");
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
strcat(optstr, "K:");
#endif
#endif
#ifndef HAVE_WINDOWS_H
strcat(optstr, "E:");
#endif
......@@ -757,13 +782,37 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
case 'k':
params->flag_slink = 1;
params->plugin_slink = optarg;
if(params->plugin_slink) {
nmxp_log_set_prefix(params->plugin_slink);
if(params->flag_slinkms) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
"Options -k and -K are declared in the same command line!\n");
ret_errors++;
} else {
params->plugin_slink = optarg;
if(params->plugin_slink) {
nmxp_log_set_prefix(params->plugin_slink);
}
}
break;
#endif
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
case 'K':
params->flag_slinkms = 1;
if(params->flag_slink) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
"Options -k and -K are declared in the same command line!\n");
ret_errors++;
} else {
params->plugin_slink = optarg;
if(params->plugin_slink) {
nmxp_log_set_prefix(params->plugin_slink);
}
}
break;
#endif
#endif
#ifndef HAVE_WINDOWS_H
case 'E':
params->listen_port = atoi(optarg);
......@@ -977,6 +1026,7 @@ void nmxptool_log_params(NMXPTOOL_PARAMS *params) {
int flag_request_channelinfo: %d\n\
int flag_writefile: %d\n\
int flag_slink: %d\n\
int flag_slinkms: %d\n\
int flag_buffered: %d\n\
int flag_logdata: %d\n\
int flag_logsample: %d\n\
......@@ -988,6 +1038,7 @@ void nmxptool_log_params(NMXPTOOL_PARAMS *params) {
params->flag_request_channelinfo,
params->flag_writefile,
params->flag_slink,
params->flag_slinkms,
params->flag_buffered,
params->flag_logdata,
params->flag_logsample
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.h,v 1.103 2008-11-06 14:59:21 mtheo Exp $
* $Id: nmxptool_getoptlong.h,v 1.104 2009-02-16 07:50:46 mtheo Exp $
*
*/
......@@ -111,6 +111,7 @@ typedef struct {
int flag_request_channelinfo;
int flag_writefile;
int flag_slink;
int flag_slinkms;
int flag_buffered;
int flag_logdata;
int flag_logsample;
......
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