nmxptool_getoptlong.c 31.2 KB
Newer Older
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1
2
3
4
5
6
7
8
9
/*! \file
 *
 * \brief Nanometrics Protocol Tool
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
10
 * $Id: nmxptool_getoptlong.c,v 1.85 2008-03-19 20:42:18 mtheo Exp $
Matteo Quintiliani's avatar
Matteo Quintiliani committed
11
12
13
 *
 */

14
15
16
17
18
19
20
21
22
23
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "config.h"
#include "nmxp.h"

#include "nmxptool_getoptlong.h"


24
const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
25
26
{
    NULL,
27
28
    DEFAULT_PORT_DAP,
    DEFAULT_PORT_PDS,
29
30
31
    NULL,
    NULL,
    NULL,
32
33
    0.0,
    0.0,
34
    DEFAULT_INTERVAL_NO_VALUE,
35
36
    NULL,
    NULL,
37
38
    DEFAULT_STC,
    DEFAULT_RATE,
39
    NULL,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
40
    DEFAULT_DELAY,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
41
42
    DEFAULT_MAX_TOLERABLE_LATENCY,
    DEFAULT_TIMEOUTRECV,
43
    DEFAULT_VERBOSE_LEVEL,
44
    NULL,
45
    NULL,
46
    DEFAULT_BUFFERED_TIME,
47
    DEFAULT_N_CHANNEL,
48
    DEFAULT_USEC,
49
    DEFAULT_MAX_TIME_TO_RETRIEVE,
50
    0,
51
52
53
54
    0,
    0,
    0,
    0,
55
    0,
56
    0,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
57
    0,
58
59
60
    0
};

61
62

void nmxptool_author_support() {
63
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
64
65
Matteo Quintiliani - Istituto Nazionale di Geofisica e Vulcanologia - Italy\n\
Mail bug reports and suggestions to <%s>.\n",
66
	    NMXP_LOG_STR(PACKAGE_BUGREPORT)
67
68
69
70
71
	    );
}


void nmxptool_version() {
72
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
73
%s %s, Nanometrics tool\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
74
        (Private Data Stream 1.4, Data Access Protocol 1.0)\n",
75
	NMXP_LOG_STR(PACKAGE_NAME), NMXP_LOG_STR(PACKAGE_VERSION)
76
	/*
77
	nmxp_log_version()
78
	*/
79
	    );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
80
81

    nmxptool_supports();
82
83
}

Matteo Quintiliani's avatar
Matteo Quintiliani committed
84
void nmxptool_supports() {
85
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
86
         Enabled features: libmseed ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
87
#ifdef HAVE_LIBMSEED
88
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
89
#else
90
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
91
92
#endif

93
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", SeedLink ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
94
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
95
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
96
#else
97
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
98
99
#endif

100
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", Earthworm ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
101
#ifdef HAVE_EARTHWORMOBJS
102
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
103
#else
104
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
105
#endif
106
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ".\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
107
108
}

109

110
111
void nmxptool_usage(struct option long_options[])
{
112
    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
113

114
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
115
\n\
116
Usage: %s -H hostname   -l | -L\n\
117
118
             Print list of available Time Series channels\n\
             on DataServer and NaqsServer respectively.\n\
119
120
\n\
       %s -H hostname -C channellist [...]\n\
121
             Receive data in near real-time from NaqsServer by PDS.\n\
122
\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
123
       %s -H hostname -F statefile [-A SECs] [...]\n\
124
             Receive data from NaqsServer, and from DataServer if is necessary.\n\
125
126
\n\
       %s -H hostname -C channellist -s DATE -e DATE [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
127
       %s -H hostname -C channellist -s DATE -t SECs [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
128
             Receive data from DataServer by DAP.\n\
129
130
131
132
133
134
\n",
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME));
Matteo Quintiliani's avatar
Matteo Quintiliani committed
135
136

#ifdef HAVE_EARTHWORMOBJS
137
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
138
       %s nmxptool.d\n\
139
             Launched as Earthworm module to redirect data into the EW-Rings.\n\
140
\n", NMXP_LOG_STR(PACKAGE_NAME));
141
142
143
144
145
146
#endif

#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
       %s <option ... option> -k\n\
             Launched as SeedLink plug-in to feed the SL-Server.\n\
147
\n", NMXP_LOG_STR(PACKAGE_NAME));
Matteo Quintiliani's avatar
Matteo Quintiliani committed
148
149
#endif

150
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
151
152
       %s --help\n\
             Print this help.\n\
153
\n", NMXP_LOG_STR(PACKAGE_NAME));
154
155

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
156
Main arguments:\n\
157
158
  -H, --hostname=HOST     NaqsServer or DataServer hostname.\n\
  -C, --channels=LIST     List of NET.STA.CHAN separated by comma.\n\
159
                          NET  is optional and used only for output.\n\
160
161
                          STA  can be '*', it stands for all stations.\n\
                          CHAN can contain '?', it stands for any character.\n\
162
163
			  Network code will be assigned from the first\n\
                          pattern that includes station and channel.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
164
                          DO NOT USE with -F.\n\
165
166
167
168
                                Example: N1.AAA.HH?,N2.*.HH?,MMM.BH?\n\
                          Second pattern includes the first. Unless AAA, all\n\
                          stations with HH channels will have network to N2.\n\
                          Station MMM will have default network defined by -N.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
169
  -F, --statefile=FILE    List of channel patterns like -C. One for each line.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
170
171
172
                          Load/Save time of the last sample of each channel\n\
                          into a file with the same name, same directory,\n\
                          appending the suffix '%s'.\n\
173
                          Allow data continuity between program restarts.\n\
174
                          Related to -A and -f, it enables -b.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
175
176
177
                          DO NOT USE with -C.\n",
			  NMXP_STR_STATE_EXT
);
178
179

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
180
  -A, --maxdataretr=SECs  Max amount of data of the past to retrieve from the\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
181
                          DataServer when program restarts (default %d) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
182
183
184
                          0 to disable connection to DataServer.\n\
                          If this option is equal to zero and -F is used,\n\
                          only data buffered by NaqsServer will be retrieved.\n\
185
186
                          It is preferable, inside the section Datastream of\n\
                          the file Naqs.ini, setting DataBufferLength to a high\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
187
188
189
190
                          value, than using -A. It allows to retrieve much more\n\
                          data of the past when the program restarts but it\n\
                          slows down the execution.\n\
                          It is extremely harmful when you have many channels.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
191
                          Related to -F.\n\
192
193
194
195
196
197
198
\n",
	    DEFAULT_MAX_TIME_TO_RETRIEVE,
	    DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM,
	    DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
199
200
PDS arguments for NaqsServer:\n\
  -P, --portpds=PORT      NaqsServer port number (default %d).\n\
201
202
  -S, --stc=SECs          Short-Term-Completion (default %d).\n\
                          -1 is for Raw Stream, no Short-Term-Completion.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
203
                             Packets contain compressed data. Related to -M, -T.\n\
204
205
                             It enables --rate=-1.\n\
                           0 decompressed packets are received in chronological\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
206
                             order without waiting for missing packets.\n\
207
                          [1..300] decompressed packets are received in\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
208
                             chronological order but waiting for missing packets\n\
209
                             at most SECs seconds.\n\
210
211
212
213
214
215
  -R, --rate=Hz           Receive data with specified sample rate (default %d).\n\
                          -1 for original sample rate and compressed data.\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\
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
                          but consider only samples after DATE.\n",
	    DEFAULT_PORT_PDS,
	    DEFAULT_STC,
	    DEFAULT_RATE);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
  -f, --mschan=mSECs/nC   mSECs are the milliseconds to wait before next request,\n\
                          nC is the number of channels to request at a time.\n\
                          This kind of request management makes data buffering\n\
                          on NaqsServer side more efficient.\n\
                          Related to -F and -b. (Default %d/%d)\
\n",
 DEFAULT_USEC / 1000, DEFAULT_N_CHANNEL);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
231
  -L, --listchannelsnaqs  List of available Time Series channels on NaqsServer.\n\
232
233
  -M, --maxlatency=SECs   Max tolerable latency (default %d) [%d..%d].\n\
  -T, --timeoutrecv=SECs  Time-out for flushing buffered packets.\n\
234
                          (default %d, no time-out) [%d..%d].\n\
235
                          -T is useful for retrieving Data On Demand.\n\
236
                          -M, -T are usable only with Raw Stream, -S=-1.\n\
237
238
239
240
241
242
243
244
245
246
247
248
                          In general, -M and -T are not used together.\n\
\n\
",
	    DEFAULT_MAX_TOLERABLE_LATENCY,
	    DEFAULT_MAX_TOLERABLE_LATENCY_MINIMUM,
	    DEFAULT_MAX_TOLERABLE_LATENCY_MAXIMUM,
	    DEFAULT_TIMEOUTRECV,
	    DEFAULT_TIMEOUTRECV_MINIMUM,
	    DEFAULT_TIMEOUTRECV_MAXIMUM
	  );

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
249
DAP arguments for DataServer:\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
250
  -D, --portdap=PORT      DataServer port number (default %d).\n\
251
252
253
254
255
256
257
  -s, --start_time=DATE   Start time in date format.\n\
  -e, --end_time=DATE     End time in date format.\n\
                          DATE can be in formats:\n\
                              <date>,<time> | <date>\n\
                          where:\n\
                              <date> = yyyy/mm/dd | yyy.jjj\n\
                              <time> = hh:mm:ss | hh:mm:ss.dddd | hh:mm\n\
258
259
260
  -t, --interval=TIME     Time interval from start_time (greater than zero).\n\
                          TIME is in seconds, otherwise append 'm' for minutes\n\
                          'h' for hours or 'd' for days. [1 sec .. %d days]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
261
                          DO NOT USE with -e.\n\
262
  -d, --delay=TIME        Receive continuosly data with delay [%d sec .. %d days].\n\
263
264
  -u, --username=USER     DataServer username.\n\
  -p, --password=PASS     DataServer password.\n\
265
  -l, --listchannels      List of available Time Series channels on DataServer.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
266
  -i, --channelinfo       Print channelinfo (network name) when using -l.\n\
267
268
\n\
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
269
DEFAULT_PORT_DAP,
270
(DEFAULT_INTERVAL_MAXIMUM / 86400),
271
DEFAULT_DELAY_MINIMUM,
272
(DEFAULT_DELAY_MAXIMUM / 86400));
273

274
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
275
Other arguments:\n\
276
  -N, --network=NET       Default output Network code. (default '%s').\n\
277
  -n, --location=LOC      Default output Location code. DISABLED!\n\
278
  -v, --verbose=level     Be verbose. level is a bitmap:\n\
279
                          %d Channel State, %d Channel, %d Raw Stream,\n\
280
281
282
                          %d CRC32, %d Connection flow,\n\
                          %d Packet Management, %d Extra, %d Date,\n\
                          %d Gap, %d DOD, %d All messages.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
283
  -g, --logdata           Print info about packet data.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
284
  -G, --logsample         Print sample values of packets. Includes -g.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
285
",
286
	    NMXP_LOG_STR(DEFAULT_NETWORK),
287
	    NMXP_LOG_D_CHANSTATE,
288
289
290
291
292
293
294
295
296
297
	    NMXP_LOG_D_CHANNEL,
	    NMXP_LOG_D_RAWSTREAM,
	    NMXP_LOG_D_CRC,
	    NMXP_LOG_D_CONNFLOW,
	    NMXP_LOG_D_PACKETMAN,
	    NMXP_LOG_D_EXTRA,
	    NMXP_LOG_D_DATE,
	    NMXP_LOG_D_GAP,
	    NMXP_LOG_D_DOD,
	    NMXP_LOG_D_ANY
298
299
300
		);

#ifdef HAVE_LIBMSEED
301
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
302
303
  -m, --writeseed         Pack received data in Mini-SEED records\n\
                          and write to a file.\n");
304
305
#endif

306
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
307
  -w, --writefile         Dump received packets to a file.\n");
308

309
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
310
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
311
  -k, --slink=pluginid    Send received data to SeedLink as a plug-in.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
312
                          THIS OPTION, INSIDE THE FILE seedlink.ini, MUST BE\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
313
314
                          THE LAST WITHOUT ADDING VALUE FOR pluginid!\n\
                          pluginid is set by SeisComP daemon.\n");
315
#endif
316

317
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
318
  -V, --version           Print tool version.\n\
319
  -h, --help              Print this help.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
320
321
\n");

322
    nmxptool_author_support();
323
324
325
326
327

    /*
    if(long_options) {
	int i=0;
	while(long_options[i].name) {
328
329
330
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "%s %d %d %d %c\n",
	    NMXP_LOG_STR(long_options[i].name), long_options[i].has_arg,
	    (long_options[i].flag)? *(long_options[i].flag) : 0, long_options[i].val, long_options[i].val);
331
332
333
334
335
336
337
	    i++;
	}
    }
    */
}


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#define MAXSIZE_LINE_CHAN_STATE 2048
#define MAXSIZECHANNELSTRINGARGUMENT 8000
#define MAXSIZE_CHANNEL_STRING 64

char *get_channel_list_argument_from_state_file(const char *filename) {
    char *ret_channel_string = NULL;
    char line[MAXSIZE_LINE_CHAN_STATE];
    char str_chan[MAXSIZE_CHANNEL_STRING];
    int k;
    FILE *fstatefile = NULL;

    fstatefile = fopen(filename, "r");

    /* Read only channel names from state file */
    if(fstatefile) {
	ret_channel_string = (char *) malloc (MAXSIZECHANNELSTRINGARGUMENT);
	ret_channel_string[0] = 0;
	while(fgets(line, MAXSIZE_LINE_CHAN_STATE, fstatefile) != NULL) {
	    k = 0;
	    while(line[k] != 0
		    &&  line[k] != ' '
		    &&  line[k] != 10
		    &&  line[k] != 13
		    &&  k < MAXSIZE_CHANNEL_STRING) {
		str_chan[k] = line[k];
		k++;
	    }
	    str_chan[k] = 0;
	    if(ret_channel_string[0] == 0) {
		strncpy(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
	    } else {
		strncat(ret_channel_string, ",", MAXSIZECHANNELSTRINGARGUMENT);
		strncat(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
	    }
	}
	fclose(fstatefile);
    }
    return ret_channel_string;
}

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
int nmxptool_read_time(char *str_input, int32_t *pvalue) {
    char str_value[100];
    int len_int;
    int32_t value;
    int j;
    char unit = 'X';
    int ret_errors = 0;

    value = 0;
    strncpy(str_value, str_input, 100);
    len_int = strlen(str_value);
    if(len_int <= 0) {
	/* ERROR */
	ret_errors++;
    } else {
	j=0;
	while(j < len_int  && str_value[j] >= '0' && str_value[j] <= '9') {
	    j++;
	}
	if(j < len_int) {
	    if(j == len_int-1) {
		unit = str_value[j];
		str_value[j] = 0;
		if(unit == 'm' || unit == 'h' || unit == 'd') {
		    value = atoi(str_value);
		    switch(unit) {
			case 'm' :
			    value *= 60;
			    break;
			case 'h' :
			    value *= ( 60 * 60 );
			    break;
			case 'd' :
			    value *= ( 60 * 60 * 24 );
			    break;
		    }
		} else {
		    ret_errors++;
		    nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
			    "Syntax of time '%s' is not correct!\n", NMXP_LOG_STR(str_value));
		}
	    } else {
		ret_errors++;
		nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
			"Syntax of time '%s' is not correct!\n", NMXP_LOG_STR(str_value));
	    }
	} else {
	    /* All numbers, then seconds */
	    value = atoi(str_value);
	}

    }

    *pvalue = value;
    return ret_errors;
}

435
int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
436
{
437
438
    int ret_errors = 0;

439
    NMXP_TM_T tmp_tmt;
440
441
442
443
    int i;
    char one_time_option[255];
    int c;

444
    /*
445
446
447
    int len_int, j;
    char unit = 'X';
    char str_interval[100];
448
    */
449

450
451
    char *sep = NULL;

452
453
454
455
456
457
458
459
    struct option long_options[] =
    {
	/* These options set a flag. */
	/* It is not safe use reference to params in this way */
	/* {"verbose",        no_argument,       &(params->flag_verbose), 1}, */
	/* {"quiet",          no_argument,       &(params->flag_verbose), 0}, */
	/* These options don't set a flag.
	 *                   We distinguish them by their indices. */
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
	{"hostname",     required_argument, NULL, 'H'},
	{"portpds",      required_argument, NULL, 'P'},
	{"portdap",      required_argument, NULL, 'D'},
	{"channels",     required_argument, NULL, 'C'},
	{"network",      required_argument, NULL, 'N'},
	{"location",     required_argument, NULL, 'n'},
	{"stc",          required_argument, NULL, 'S'},
	{"rate",         required_argument, NULL, 'R'},
	{"start_time",   required_argument, NULL, 's'},
	{"end_time",     required_argument, NULL, 'e'},
	{"interval",     required_argument, NULL, 't'},
	{"delay",        required_argument, NULL, 'd'},
	{"username",     required_argument, NULL, 'u'},
	{"password",     required_argument, NULL, 'p'},
	{"maxlatency",   required_argument, NULL, 'M'},
	{"timeoutrecv",  required_argument, NULL, 'T'},
	{"verbose",      required_argument, NULL, 'v'},
	{"bufferedt",    required_argument, NULL, 'B'},
478
	{"maxdataretr",  required_argument, NULL, 'A'},
479
	/* Following are flags */
480
	{"logdata",      no_argument,       NULL, 'g'},
Matteo Quintiliani's avatar
Matteo Quintiliani committed
481
	{"logsample",    no_argument,       NULL, 'G'},
482
483
484
485
	{"buffered",     no_argument,       NULL, 'b'},
	{"listchannels", no_argument,       NULL, 'l'},
	{"listchannelsnaqs", no_argument,   NULL, 'L'},
	{"channelinfo",  no_argument,       NULL, 'i'},
486
#ifdef HAVE_LIBMSEED
487
	{"writeseed",    no_argument,       NULL, 'm'},
488
#endif
489
	{"writefile",    no_argument,       NULL, 'w'},
490
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
491
	{"slink",        required_argument, NULL, 'k'},
492
#endif
493
	{"statefile",    required_argument, NULL, 'F'},
494
	{"mschan",       required_argument, NULL, 'f'},
495
496
	{"help",         no_argument,       NULL, 'h'},
	{"version",      no_argument,       NULL, 'V'},
497
498
499
	{0, 0, 0, 0}
    };

500
    char optstr[300] = "H:P:D:C:N:n:S:R:s:e:t:d:u:p:M:T:v:B:A:F:f:gGblLiwhV";
501

Matteo Quintiliani's avatar
Matteo Quintiliani committed
502
503
504
    int option_index = 0;


505
506
507
#ifdef HAVE_LIBMSEED
    strcat(optstr, "m");
#endif
508

509
510
511
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    strcat(optstr, "k:");
#endif
512
513
514
515
516
517
518
519
520
521


    /* getopt_long stores the option index here. */
    /* init array for checking one time option */
    for(i=0; i<255; i++) {
	one_time_option[i] = 0;
    }


    /* init params */
522
    memcpy(params, &NMXPTOOL_PARAMS_DEFAULT, sizeof(NMXPTOOL_PARAMS_DEFAULT));
523

524
525
526
527
528
529
530
531
532
533
534
535
536
537
    /* Check number of command line arguments for earthworm */
    if (argc == 2)
    {
	int l = strlen(argv[1]);
	if(l >= 3) {
	    if(argv[1][0] != '-') {
		if(argv[1][l-2] == '.'  &&  argv[1][l-1] == 'd') {
		    params->ew_configuration_file = argv[1];
		    return 0;
		}
	    }
	}
    }

538
539
540
541
542
543
544
    while ( (c = getopt_long (argc, argv, optstr, long_options, &option_index)) != -1) {

	/* BE CAREFUL if use synonym options !!! */
	one_time_option[c]++;

	if(one_time_option[c] > 1) {
	    ret_errors++;
545
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Replicated option -%c (value %s)\n", c, NMXP_LOG_STR(optarg));
546
547
548
549
550
551
552
	} else {
	    switch (c)
	    {
		case 0:
		    /* If this option set a flag, do nothing else now. */
		    if (long_options[option_index].flag != 0)
			break;
553
554
555
556
557
		    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "option %s",
			    NMXP_LOG_STR(long_options[option_index].name));
		    if (optarg) {
			nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, " with arg %s", NMXP_LOG_STR(optarg));
		    }
558
		    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\n");
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
		    break;

		case 'H':
		    params->hostname = optarg;
		    break;

		case 'P':
		    params->portnumberpds = atoi(optarg);
		    break;

		case 'D':
		    params->portnumberdap = atoi(optarg);
		    break;

		case 'C':
574
		    if(params->channels) {
575
576
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by State File (option -F)!\n");
577
578
579
580
			ret_errors++;
		    } else {
			params->channels = optarg;
		    }
581
582
583
584
585
586
		    break;

		case 'N':
		    params->network = optarg;
		    break;

587
		case 'n':
588
589
590
591
592
		    if(1) {
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Location is currently disabled!\n");
		    } else {
			params->location = optarg;
		    }
593
594
		    break;

595
596
		case 'S':
		    params->stc = atoi(optarg);
597
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Short-Term-Completion %d.\n", params->stc);
598
599
600
601
602
603
		    break;

		case 'R':
		    params->rate = atoi(optarg);
		    break;

604
		case 's':
605
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
606
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
607
			ret_errors++;
608
		    } else {
609
			params->start_time = nmxp_data_tm_to_time(&tmp_tmt);
610
611
612
613
		    }
		    break;

		case 'e':
614
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
615
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
616
			ret_errors++;
617
		    } else {
618
			params->end_time = nmxp_data_tm_to_time(&tmp_tmt);
619
620
621
		    }
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
622
		case 't':
623
		    ret_errors += nmxptool_read_time(optarg, &(params->interval) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
624
625
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
626
		case 'd':
627
		    ret_errors += nmxptool_read_time(optarg, &(params->delay) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
628
629
		    break;

630
631
632
633
634
635
636
637
		case 'u':
		    params->datas_username = optarg;
		    break;

		case 'p':
		    params->datas_password = optarg;
		    break;

638
		case 'M':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
639
		    params->max_tolerable_latency = atoi(optarg);
640
641
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Max_tolerable_latency %d\n",
			    params->max_tolerable_latency);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
642
643
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
644
		case 'T':
645
		    params->timeoutrecv = atoi(optarg);
646
647
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Time-out receiving %d\n",
			    params->timeoutrecv);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
648
649
		    break;

650
651
652
653
		case 'v':
		    params->verbose_level = atoi(optarg);
		    break;

654
655
656
		case 'B':
		    params->flag_buffered = 1;
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
657
			/* MESSAGE ERROR */
658
659
660
661
662
663
			ret_errors++;
		    } else {
			params->buffered_time = nmxp_data_tm_to_time(&tmp_tmt);
		    }
		    break;

664
665
		case 'A':
		    if(optarg) {
666
			params->max_data_to_retrieve = atoi(optarg);
667
		    }
668
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Max_time_to_retrieve %d\n", params->max_data_to_retrieve);
669
		    break;
670

671
672
673
674
675
676
677
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
		case 'k':
		    params->flag_slink = 1;
		    params->plugin_slink = optarg;
		    break;
#endif

678
		case 'F':
679
		    params->flag_buffered = 1;
680
		    params->statefile = optarg;
681
682
683
684
685
686
		    if(params->channels == NULL) {
			params->channels = get_channel_list_argument_from_state_file(params->statefile);
			if(params->channels) {
			    /* Do nothing */
			} else {
			    ret_errors++;
687
688
			    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY,
				    "State file %s not found or unable to read!\n", NMXP_LOG_STR(params->statefile));
689
			}
690
691
		    } else {
			ret_errors++;
692
693
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by option -C!\n");
694
695
696
		    }
		    break;

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
		case 'f':
		    sep = strstr(optarg, "/");
		    if(sep) {
			sep[0] = 0;
			sep++;
			params->n_usec = atoi(optarg) * 1000;
			params->n_channel = atoi(sep);
		    } else {
			/*
			 * TODO ERROR
			 */
			ret_errors++;
		    }
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY,
				"Channels %d usec %d!\n", params->n_channel, params->n_usec);
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
714
		case 'g':
715
716
717
		    params->flag_logdata = 1;
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
718
		case 'G':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
719
		    params->flag_logdata = 1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
720
721
722
		    params->flag_logsample = 1;
		    break;

723
		case 'b':
724
		    params->flag_buffered = 1;
725
726
		    break;

727
728
729
730
		case 'l':
		    params->flag_listchannels = 1;
		    break;

731
732
733
734
		case 'L':
		    params->flag_listchannelsnaqs = 1;
		    break;

735
736
737
738
		case 'i':
		    params->flag_request_channelinfo = 1;
		    break;

739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
#ifdef HAVE_LIBMSEED
		case 'm':
		    params->flag_writeseed = 1;
		    break;
#endif

		case 'w':
		    params->flag_writefile = 1;
		    break;

		case 'h':
		    nmxptool_usage(long_options);
		    exit (1);
		    break;

754
755
		case 'V':
		    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
756
		    nmxptool_author_support();
757
758
759
		    exit (1);
		    break;

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
		case '?':
		    /* getopt_long already printed an error message. */
		    ret_errors++;
		    break;

		default:
		    nmxptool_usage(long_options);
		    exit (1);
	    }
	}
    }

    /* Print any remaining command line arguments (not options). */
    if (optind < argc)
    {
	ret_errors += optind;

777
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "non-option ARGV-elements: ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
778
779
	while (optind < argc) {
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "%s ",
780
781
		    NMXP_LOG_STR(argv[optind]));
	    optind++;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
782
	}
783
784
785
786
787
788
789
	putchar ('\n');
    }

    return ret_errors;
}


790
791
792
793
794
void nmxptool_log_params(NMXPTOOL_PARAMS *params) {
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
    char *hostname: %s\n\
    int portnumberdap: %d\n\
    int portnumberpds: %d\n\
795
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
796
    NMXP_LOG_STR(params->hostname),
797
798
799
800
801
    params->portnumberdap,
    params->portnumberpds
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
802
    char *channels: %s\n\
803
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
804
    NMXP_LOG_STR(params->channels)
805
806
807
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
808
809
810
811
812
    char *network: %s\n\
    char *location: %s\n\
    double start_time: %f\n\
    double end_time: %f\n\
    int32_t interval: %d\n\
813
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
814
815
    NMXP_LOG_STR(params->network),
    NMXP_LOG_STR(params->location),
816
817
818
819
820
821
822
    params->start_time,
    params->end_time,
    params->interval
);


    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
823
824
    char *datas_username: %s\n\
    char *datas_password: %s\n\
825
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
826
827
    NMXP_LOG_STR(params->datas_username),
    NMXP_LOG_STR(params->datas_password)
828
829
830
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
831
832
833
834
835
836
837
    int32_t stc: %d\n\
    int32_t rate: %d\n\
    char *plugin_slink: %s\n\
    int32_t delay: %d\n\
    int32_t max_tolerable_latency: %d\n\
    int32_t timeoutrecv: %d\n\
    int32_t verbose_level: %d\n\
838
839
840
",
    params->stc,
    params->rate,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
841
    NMXP_LOG_STR(params->plugin_slink),
842
843
844
845
846
847
848
    params->delay,
    params->max_tolerable_latency,
    params->timeoutrecv,
    params->verbose_level
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
849
850
    char *ew_configuration_file: %s\n\
    char *statefile: %s\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
851
    int32_t max_data_to_retrieve: %d\n\
852
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
853
854
    NMXP_LOG_STR(params->ew_configuration_file),
    NMXP_LOG_STR(params->statefile),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
855
    params->max_data_to_retrieve
856
857
858
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
859
860
861
862
863
864
865
866
867
    double buffered_time: %f\n\
    int flag_writeseed: %d\n\
    int flag_listchannels: %d\n\
    int flag_listchannelsnaqs: %d\n\
    int flag_request_channelinfo: %d\n\
    int flag_writefile: %d\n\
    int flag_slink: %d\n\
    int flag_buffered: %d\n\
    int flag_logdata: %d\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
868
    int flag_logsample: %d\n\
869
870
871
872
873
874
875
876
877
",
    params->buffered_time,
    params->flag_writeseed,
    params->flag_listchannels,
    params->flag_listchannelsnaqs,
    params->flag_request_channelinfo,
    params->flag_writefile,
    params->flag_slink,
    params->flag_buffered,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
878
879
    params->flag_logdata,
    params->flag_logsample
880
881
882
    );
}

883
884


885
int nmxptool_check_params(NMXPTOOL_PARAMS *params) {
886
887
    int ret = 0;

888
889
890
    if(params->ew_configuration_file != NULL) {
	/* Do nothing */
    } else if(params->hostname == NULL) {
891
	ret = -1;
892
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
893
    } else if(params->flag_listchannels) {
894
895
896
897
898
	if(params->flag_listchannelsnaqs) {
	    ret = -1;
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "-l and -L can not be used together!\n");
	}
    } else if(params->flag_listchannelsnaqs) {
899
900
901
	/* Do nothing */
    } else if(params->hostname == NULL) {
	ret = -1;
902
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
903
904
    } else if(params->channels == NULL) {
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
905
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Channel list is required!\n");
906
    } else if(params->start_time == 0.0 &&  params->end_time != 0.0) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
907
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
908
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<end_time> is required when declaring <start_time>!\n");
909
    } else if(params->start_time != 0.0  &&  params->end_time != 0.0  && params->interval != DEFAULT_INTERVAL_NO_VALUE) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
910
	ret = -1;
911
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<start_time> has to be used with either <end_time> or <interval>!\n");
912
913
914
    } else if(params->interval != DEFAULT_INTERVAL_NO_VALUE && params->interval <= 0) {
	ret = -1;
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<interval> has to be greater than zero!\n");
915
916
917
    } else if(params->interval > DEFAULT_INTERVAL_MAXIMUM) {
	ret = -1;
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<interval> has to be less than %d seconds (%d days)!\n", DEFAULT_INTERVAL_MAXIMUM, DEFAULT_INTERVAL_MAXIMUM / 86400);
918
    } else if(params->start_time != 0.0   &&   params->end_time != 0.0
919
	    && params->start_time >= params->end_time) {
920
	ret = -1;
921
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<start_time> is less than <end_time>!\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
922
    } else if(params->stc < DEFAULT_STC_MINIMUM   ||   params->stc > DEFAULT_STC_MAXIMUM) {
923
	ret = -1;
924
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<stc> has to be in the interval [%d..%d] secs.\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
925
		DEFAULT_STC_MINIMUM, DEFAULT_STC_MAXIMUM);
926
927
    } else if(params->stc == -1   &&   params->rate != DEFAULT_RATE) {
	ret = -1;
928
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<rate> has to be equal to -1 when <stc> is equal to -1 (Raw Stream).\n");
929
    } else if(params->delay > 0 && params->start_time != 0.0   &&   params->end_time != 0.0) {
930
	ret = -1;
931
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<delay> can not be used with options <start_time> and <end_time>.\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
932
933
934
    } else if( params->delay != DEFAULT_DELAY &&
	    (params->delay < DEFAULT_DELAY_MINIMUM  || params->delay > DEFAULT_DELAY_MAXIMUM) ) {
	ret = -1;
935
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<delay> has to be in the interval [%d..%d] secs.\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
936
		DEFAULT_DELAY_MINIMUM, DEFAULT_DELAY_MAXIMUM);
937
938
939
940
    } else if(params->verbose_level < DEFAULT_VERBOSE_LEVEL_MINIMUM  ||  params->verbose_level > DEFAULT_VERBOSE_LEVEL_MAXIMUM) {
	ret = -1;
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<verbose_level> has to be in the interval [%d..%d].\n",
		DEFAULT_VERBOSE_LEVEL_MINIMUM, DEFAULT_VERBOSE_LEVEL_MAXIMUM);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
941
942
    } else if(params->rate < DEFAULT_RATE_MINIMUM  ||  params->rate > DEFAULT_RATE_MAXIMUM) {
	ret = -1;
943
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<rate> has to be in the interval [%d..%d].\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
944
		DEFAULT_RATE_MINIMUM, DEFAULT_RATE_MAXIMUM);
945
    } else if(params->rate != -1 && params->start_time != 0.0   &&   params->end_time != 0.0) {
946
	ret = -1;
947
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<rate> can not be used with options <start_time> and <end_time>.\n");
948
    } else if(params->flag_buffered != 0 && params->start_time != 0.0   &&   params->end_time != 0.0) {
949
	ret = -1;
950
	nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "<buffered> can not be used with options <start_time> and <end_time>.\n");
951
952
    } else if( (params->max_data_to_retrieve < DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM  ||
		params->max_data_to_retrieve > DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM)) {
953
	ret = -1;
954
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<maxdataretr> has to be within [%d..%d].\n",
955
956
		DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM,
		DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM);
957
    } else if( params->stc == -1
Matteo Quintiliani's avatar
Matteo Quintiliani committed
958
959
	    && (params->max_tolerable_latency < DEFAULT_MAX_TOLERABLE_LATENCY_MINIMUM  ||
		params->max_tolerable_latency > DEFAULT_MAX_TOLERABLE_LATENCY_MAXIMUM)) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
960
	ret = -1;
961
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<maxlatency> has to be within [%d..%d].\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
962
963
964
965
966
967
968
		DEFAULT_MAX_TOLERABLE_LATENCY_MINIMUM,
		DEFAULT_MAX_TOLERABLE_LATENCY_MAXIMUM);
    } else if( params->stc == -1
	    && (params->timeoutrecv < DEFAULT_TIMEOUTRECV_MINIMUM  ||
		params->timeoutrecv > DEFAULT_TIMEOUTRECV_MAXIMUM)) {
	if(params->timeoutrecv != 0) {
	    ret = -1;
969
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<timeoutrecv> has to be within [%d..%d] or equal to zero for not time-out.\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
970
971
972
		    DEFAULT_TIMEOUTRECV_MINIMUM,
		    DEFAULT_TIMEOUTRECV_MAXIMUM);
	}
973
974

	/* Follow warning messages only */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
975
    } else if( params->stc != -1 && params->max_tolerable_latency > 0 ){
976
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<maxlatency> ignored since not defined --stc=-1.\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
977
978
    } else if(params->stc != -1 && params->timeoutrecv > 0) {
	params->timeoutrecv = 0;
979
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<timeoutrecv> ignored since not defined --stc=-1.\n");
980
    }
981

982
983
984
985
986
987
988
989
990
991
    if(params->n_usec < DEFAULT_USEC_MINIMUM  ||  params->n_usec > DEFAULT_USEC_MAXIMUM) {
	ret = -1;
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "ms in <mschan> has to be within [%d..%d].\n",
		DEFAULT_USEC_MINIMUM/1000, DEFAULT_USEC_MAXIMUM/1000);
    } else if(params->n_channel < DEFAULT_N_CHANNEL_MINIMUM  ||  params->n_channel > DEFAULT_N_CHANNEL_MAXIMUM) {
	ret = -1;
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "nC in <mschan> has to be within [%d..%d].\n",
		DEFAULT_N_CHANNEL_MINIMUM, DEFAULT_N_CHANNEL_MAXIMUM);
    }
    
Matteo Quintiliani's avatar
Matteo Quintiliani committed
992
    /*
993
    if( params->stc == -1 ) {
994
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<maxlatency> is equal to %d sec.\n", params->max_tolerable_latency);
995
    }
Matteo Quintiliani's avatar
Matteo Quintiliani committed
996
    */
997

998
999
    return ret;
}