nmxptool_getoptlong.c 32.1 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
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
10
 * $Id: nmxptool_getoptlong.c,v 1.90 2008-03-24 14:22:32 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
	    );
}


Matteo Quintiliani's avatar
Matteo Quintiliani committed
71
72
73
#define PDS_VERSION "1.4"
#define DAP_VERSION "1.0"

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

    nmxptool_supports();
86
87
}

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

97
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", SeedLink ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
98
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
99
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
100
#else
101
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
102
103
#endif

104
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", Earthworm ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
105
#ifdef HAVE_EARTHWORMOBJS
106
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
107
#else
108
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
109
#endif
110
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ".\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
111
112
}

113

114
115
void nmxptool_usage(struct option long_options[])
{
116
    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
117

118
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
119
\n\
120
Usage: %s -H hostname   -l | -L\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
121
             Print list of the available Time Series channels\n\
122
             on DataServer and NaqsServer respectively.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
123
124
125
126
\n",
NMXP_LOG_STR(PACKAGE_NAME));

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
127
       %s -H hostname -C channellist [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
128
             Receive data in near real-time from NaqsServer by PDS %s\n\
129
\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
130
       %s -H hostname -F statefile [-A SECs] [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
131
132
             Receive data from NaqsServer and, in case, retrieve previous\n\
             data from DataServer up to SECs seconds before.\n\
133
134
\n",
NMXP_LOG_STR(PACKAGE_NAME),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
135
136
137
138
139
140
141
142
NMXP_LOG_STR(PDS_VERSION),
NMXP_LOG_STR(PACKAGE_NAME));

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
       %s -H hostname -C channellist -s DATE -e DATE [...]\n\
       %s -H hostname -C channellist -s DATE -t TIME [...]\n\
             Receive a temporal interval of data from DataServer by DAP %s\n\
\n",
143
144
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
145
146
NMXP_LOG_STR(DAP_VERSION)
);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
147
148

#ifdef HAVE_EARTHWORMOBJS
149
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
150
       %s nmxptool.d\n\
151
             Launched as Earthworm module to redirect data into the EW-Rings.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
152
             Refer to nmxptool_cmd.html into the Earthworm documentation.\n\
153
\n", NMXP_LOG_STR(PACKAGE_NAME));
154
155
156
157
158
159
#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\
160
\n", NMXP_LOG_STR(PACKAGE_NAME));
Matteo Quintiliani's avatar
Matteo Quintiliani committed
161
162
#endif

163
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
164
       %s --help | -h\n\
165
             Print this help.\n\
166
\n", NMXP_LOG_STR(PACKAGE_NAME));
167
168

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
169
Main arguments:\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
170
  -H, --hostname=HOST     NaqsServer/DataServer hostname or IP address.\n\
171
  -C, --channels=LIST     List of NET.STA.CHAN separated by comma.\n\
172
                          NET  is optional and used only for output.\n\
173
174
                          STA  can be '*', it stands for all stations.\n\
                          CHAN can contain '?', it stands for any character.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
175
                          Network code will be assigned from the first\n\
176
                          pattern that includes station and channel.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
177
                          DO NOT USE with -F.\n\
178
179
180
181
                                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
182
  -F, --statefile=FILE    List of channel patterns, as in -C. One for each line.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
183
184
185
                          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\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
186
                          Allow data continuity when short disconnections occur.\n\
187
                          Related to -A and -f, it enables -b.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
188
189
190
                          DO NOT USE with -C.\n",
			  NMXP_STR_STATE_EXT
);
191
192

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
193
  -A, --maxdataretr=SECs  Max amount of data of the past to retrieve from the\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
194
                          DataServer when program restarts (default %d) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
195
196
197
                          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\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
198
199
200
                          Rather than using -A, it is preferable, inside the section\n\
                          Datastream of the file Naqs.ini, setting DataBufferLength \n\
                          to a high value. -A allows to retrieve much more\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
201
                          data of the past when the program restarts but it\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
202
                          considerably slows down the execution.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
203
                          It is extremely harmful when you have many channels.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
204
                          Related to -F.\n\
205
206
207
208
209
210
211
\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
212
213
PDS arguments for NaqsServer:\n\
  -P, --portpds=PORT      NaqsServer port number (default %d).\n\
214
215
  -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
216
                             Packets contain compressed data. Related to -M, -T.\n\
217
218
                             It enables --rate=-1.\n\
                           0 decompressed packets are received in chronological\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
219
                             order without waiting for missing packets.\n\
220
                          [1..300] decompressed packets are received in\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
221
                             chronological order but waiting for missing packets\n\
222
                             at most SECs seconds.\n\
223
224
225
226
227
  -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\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
228
  -B, --buffdate=DATE     Request also recent packets into the past\n\
229
230
231
232
233
234
                          but consider only samples after DATE.\n",
	    DEFAULT_PORT_PDS,
	    DEFAULT_STC,
	    DEFAULT_RATE);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
235
  -f, --mschan=mSECs/nC   mSECs are milliseconds to wait before the next request,\n\
236
                          nC is the number of channels to request at a time.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
237
                          Delaying and requesting few channels at a time make\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
238
239
                          data buffering on NaqsServer side more efficient.\n\
                          Determined empiric values are default %d/%d.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
240
                          Condition: TotalNumberOfChannels * (mSECs/nC) < %d sec. \n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
241
                          Related to -F and -b. 0/0 for disabling.\
242
\n",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
243
DEFAULT_USEC / 1000, DEFAULT_N_CHANNEL, NMXP_MAX_MSCHAN_MSEC / 1000);
244
245

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
246
  -L, --listchannelsnaqs  List of the available Time Series channels on NaqsServer.\n\
247
  -M, --maxlatency=SECs   Max tolerable latency (default %d) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
248
  -T, --timeoutrecv=SECs  Time-out for flushing queued packets of each channel.\n\
249
                          (default %d, no time-out) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
250
                          -T is useful for retrieving Data On Demand with minimum delay.\n\
251
                          -M, -T are usable only with Raw Stream, -S=-1.\n\
252
253
254
255
256
257
258
259
260
261
262
263
                          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
264
DAP arguments for DataServer:\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
265
  -D, --portdap=PORT      DataServer port number (default %d).\n\
266
267
268
269
270
271
272
  -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\
273
274
275
  -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
276
                          DO NOT USE with -e.\n\
277
  -d, --delay=TIME        Receive continuosly data with delay [%d sec .. %d days].\n\
278
279
  -u, --username=USER     DataServer username.\n\
  -p, --password=PASS     DataServer password.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
280
  -l, --listchannels      List of the available Time Series channels on DataServer.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
281
  -i, --channelinfo       Print channelinfo (network name) when using -l.\n\
282
283
\n\
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
284
DEFAULT_PORT_DAP,
285
(DEFAULT_INTERVAL_MAXIMUM / 86400),
286
DEFAULT_DELAY_MINIMUM,
287
(DEFAULT_DELAY_MAXIMUM / 86400));
288

289
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
290
Other arguments:\n\
291
  -N, --network=NET       Default output Network code. (default '%s').\n\
292
  -n, --location=LOC      Default output Location code. DISABLED!\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
293
  -v, --verbose=LEVEL     Be verbose. LEVEL is a bitmap:\n\
294
                          %d Channel State, %d Channel, %d Raw Stream,\n\
295
296
297
                          %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
298
  -g, --logdata           Print info about packet data.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
299
  -G, --logsample         Print sample values of packets. Includes -g.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
300
",
301
	    NMXP_LOG_STR(DEFAULT_NETWORK),
302
	    NMXP_LOG_D_CHANSTATE,
303
304
305
306
307
308
309
310
311
312
	    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
313
314
315
		);

#ifdef HAVE_LIBMSEED
316
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
317
318
  -m, --writeseed         Pack received data in Mini-SEED records\n\
                          and write to a file.\n");
319
320
#endif

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

324
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
325
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
326
327
328
329
  -k, --slink=PLUGINID    Send received data to SeedLink as a plug-in.\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");
330
#endif
331

332
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
333
  -V, --version           Print tool version.\n\
334
  -h, --help              Print this help.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
335
336
\n");

337
    nmxptool_author_support();
338
339
340
341
342

    /*
    if(long_options) {
	int i=0;
	while(long_options[i].name) {
343
344
345
	    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);
346
347
348
349
350
351
352
	    i++;
	}
    }
    */
}


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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#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;
}

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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
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;
}

450
int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
451
{
452
453
    int ret_errors = 0;

454
    NMXP_TM_T tmp_tmt;
455
456
457
458
    int i;
    char one_time_option[255];
    int c;

459
    /*
460
461
462
    int len_int, j;
    char unit = 'X';
    char str_interval[100];
463
    */
464

465
466
    char *sep = NULL;

467
468
469
470
471
472
473
474
    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. */
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
	{"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'},
493
	{"maxdataretr",  required_argument, NULL, 'A'},
494
	/* Following are flags */
495
	{"logdata",      no_argument,       NULL, 'g'},
Matteo Quintiliani's avatar
Matteo Quintiliani committed
496
	{"logsample",    no_argument,       NULL, 'G'},
497
498
499
500
	{"buffered",     no_argument,       NULL, 'b'},
	{"listchannels", no_argument,       NULL, 'l'},
	{"listchannelsnaqs", no_argument,   NULL, 'L'},
	{"channelinfo",  no_argument,       NULL, 'i'},
501
#ifdef HAVE_LIBMSEED
502
	{"writeseed",    no_argument,       NULL, 'm'},
503
#endif
504
	{"writefile",    no_argument,       NULL, 'w'},
505
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
506
	{"slink",        required_argument, NULL, 'k'},
507
#endif
508
	{"statefile",    required_argument, NULL, 'F'},
509
	{"mschan",       required_argument, NULL, 'f'},
510
511
	{"help",         no_argument,       NULL, 'h'},
	{"version",      no_argument,       NULL, 'V'},
512
513
514
	{0, 0, 0, 0}
    };

515
    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";
516

Matteo Quintiliani's avatar
Matteo Quintiliani committed
517
518
519
    int option_index = 0;


520
521
522
#ifdef HAVE_LIBMSEED
    strcat(optstr, "m");
#endif
523

524
525
526
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    strcat(optstr, "k:");
#endif
527
528
529
530
531
532
533
534
535
536


    /* 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 */
537
    memcpy(params, &NMXPTOOL_PARAMS_DEFAULT, sizeof(NMXPTOOL_PARAMS_DEFAULT));
538

539
540
541
542
543
544
545
546
547
548
549
550
551
552
    /* 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;
		}
	    }
	}
    }

553
554
555
556
557
558
559
    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++;
560
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Replicated option -%c (value %s)\n", c, NMXP_LOG_STR(optarg));
561
562
563
564
565
566
567
	} else {
	    switch (c)
	    {
		case 0:
		    /* If this option set a flag, do nothing else now. */
		    if (long_options[option_index].flag != 0)
			break;
568
569
570
571
572
		    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));
		    }
573
		    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\n");
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
		    break;

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

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

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

		case 'C':
589
		    if(params->channels) {
590
591
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by State File (option -F)!\n");
592
593
594
595
			ret_errors++;
		    } else {
			params->channels = optarg;
		    }
596
597
598
599
600
601
		    break;

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

602
		case 'n':
603
604
605
606
607
		    if(1) {
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Location is currently disabled!\n");
		    } else {
			params->location = optarg;
		    }
608
609
		    break;

610
611
		case 'S':
		    params->stc = atoi(optarg);
612
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Short-Term-Completion %d.\n", params->stc);
613
614
615
616
617
618
		    break;

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

619
		case 's':
620
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
621
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
622
			ret_errors++;
623
		    } else {
624
			params->start_time = nmxp_data_tm_to_time(&tmp_tmt);
625
626
627
628
		    }
		    break;

		case 'e':
629
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
630
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
631
			ret_errors++;
632
		    } else {
633
			params->end_time = nmxp_data_tm_to_time(&tmp_tmt);
634
635
636
		    }
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
637
		case 't':
638
		    ret_errors += nmxptool_read_time(optarg, &(params->interval) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
639
640
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
641
		case 'd':
642
		    ret_errors += nmxptool_read_time(optarg, &(params->delay) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
643
644
		    break;

645
646
647
648
649
650
651
652
		case 'u':
		    params->datas_username = optarg;
		    break;

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

653
		case 'M':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
654
		    params->max_tolerable_latency = atoi(optarg);
655
656
		    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
657
658
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
659
		case 'T':
660
		    params->timeoutrecv = atoi(optarg);
661
662
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Time-out receiving %d\n",
			    params->timeoutrecv);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
663
664
		    break;

665
666
667
668
		case 'v':
		    params->verbose_level = atoi(optarg);
		    break;

669
670
671
		case 'B':
		    params->flag_buffered = 1;
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
672
			/* MESSAGE ERROR */
673
674
675
676
677
678
			ret_errors++;
		    } else {
			params->buffered_time = nmxp_data_tm_to_time(&tmp_tmt);
		    }
		    break;

679
680
		case 'A':
		    if(optarg) {
681
			params->max_data_to_retrieve = atoi(optarg);
682
		    }
683
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Max_time_to_retrieve %d\n", params->max_data_to_retrieve);
684
		    break;
685

686
687
688
689
690
691
692
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
		case 'k':
		    params->flag_slink = 1;
		    params->plugin_slink = optarg;
		    break;
#endif

693
		case 'F':
694
		    params->flag_buffered = 1;
695
		    params->statefile = optarg;
696
697
698
699
700
701
		    if(params->channels == NULL) {
			params->channels = get_channel_list_argument_from_state_file(params->statefile);
			if(params->channels) {
			    /* Do nothing */
			} else {
			    ret_errors++;
702
703
			    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));
704
			}
705
706
		    } else {
			ret_errors++;
707
708
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by option -C!\n");
709
710
711
		    }
		    break;

712
713
714
715
716
		case 'f':
		    sep = strstr(optarg, "/");
		    if(sep) {
			sep[0] = 0;
			sep++;
717
			params->usec = atoi(optarg) * 1000;
718
			params->n_channel = atoi(sep);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
719
720
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY,
				"Channels %d usec %d!\n", params->n_channel, params->usec);
721
722
		    } else {
			ret_errors++;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
723
724
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Syntax error in option -%c %s!\n", c, NMXP_LOG_STR(optarg));
725
726
727
		    }
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
728
		case 'g':
729
730
731
		    params->flag_logdata = 1;
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
732
		case 'G':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
733
		    params->flag_logdata = 1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
734
735
736
		    params->flag_logsample = 1;
		    break;

737
		case 'b':
738
		    params->flag_buffered = 1;
739
740
		    break;

741
742
743
744
		case 'l':
		    params->flag_listchannels = 1;
		    break;

745
746
747
748
		case 'L':
		    params->flag_listchannelsnaqs = 1;
		    break;

749
750
751
752
		case 'i':
		    params->flag_request_channelinfo = 1;
		    break;

753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#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;

768
769
		case 'V':
		    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
770
		    nmxptool_author_support();
771
772
773
		    exit (1);
		    break;

774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
		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;

791
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "non-option ARGV-elements: ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
792
793
	while (optind < argc) {
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "%s ",
794
795
		    NMXP_LOG_STR(argv[optind]));
	    optind++;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
796
	}
797
798
799
800
801
802
803
	putchar ('\n');
    }

    return ret_errors;
}


804
805
806
807
808
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\
809
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
810
    NMXP_LOG_STR(params->hostname),
811
812
813
814
815
    params->portnumberdap,
    params->portnumberpds
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
816
    char *channels: %s\n\
817
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
818
    NMXP_LOG_STR(params->channels)
819
820
821
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
822
823
824
825
826
    char *network: %s\n\
    char *location: %s\n\
    double start_time: %f\n\
    double end_time: %f\n\
    int32_t interval: %d\n\
827
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
828
829
    NMXP_LOG_STR(params->network),
    NMXP_LOG_STR(params->location),
830
831
832
833
834
835
836
    params->start_time,
    params->end_time,
    params->interval
);


    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
837
838
    char *datas_username: %s\n\
    char *datas_password: %s\n\
839
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
840
841
    NMXP_LOG_STR(params->datas_username),
    NMXP_LOG_STR(params->datas_password)
842
843
844
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
845
846
847
848
849
850
851
    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\
852
853
854
",
    params->stc,
    params->rate,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
855
    NMXP_LOG_STR(params->plugin_slink),
856
857
858
859
860
861
862
    params->delay,
    params->max_tolerable_latency,
    params->timeoutrecv,
    params->verbose_level
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
863
864
    char *ew_configuration_file: %s\n\
    char *statefile: %s\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
865
    int32_t max_data_to_retrieve: %d\n\
866
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
867
868
    NMXP_LOG_STR(params->ew_configuration_file),
    NMXP_LOG_STR(params->statefile),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
869
    params->max_data_to_retrieve
870
871
872
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
873
874
875
876
877
878
879
880
881
    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
882
    int flag_logsample: %d\n\
883
884
885
886
887
888
889
890
891
",
    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
892
893
    params->flag_logdata,
    params->flag_logsample
894
895
896
    );
}

897
898


899
int nmxptool_check_params(NMXPTOOL_PARAMS *params) {
900
901
    int ret = 0;

902
903
904
    if(params->ew_configuration_file != NULL) {
	/* Do nothing */
    } else if(params->hostname == NULL) {
905
	ret = -1;
906
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
907
    } else if(params->flag_listchannels) {
908
909
910
911
912
	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) {
913
914
915
	/* Do nothing */
    } else if(params->hostname == NULL) {
	ret = -1;
916
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
917
918
    } else if(params->channels == NULL) {
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
919
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Channel list is required!\n");
920
    } else if(params->start_time == 0.0 &&  params->end_time != 0.0) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
921
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
922
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<end_time> is required when declaring <start_time>!\n");
923
    } 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
924
	ret = -1;
925
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<start_time> has to be used with either <end_time> or <interval>!\n");
926
927
928
    } 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");
929
930
931
    } 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);
932
    } else if(params->start_time != 0.0   &&   params->end_time != 0.0
933
	    && params->start_time >= params->end_time) {
934
	ret = -1;
935
	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
936
    } else if(params->stc < DEFAULT_STC_MINIMUM   ||   params->stc > DEFAULT_STC_MAXIMUM) {
937
	ret = -1;
938
	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
939
		DEFAULT_STC_MINIMUM, DEFAULT_STC_MAXIMUM);
940
941
    } else if(params->stc == -1   &&   params->rate != DEFAULT_RATE) {
	ret = -1;
942
	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");
943
    } else if(params->delay > 0 && params->start_time != 0.0   &&   params->end_time != 0.0) {
944
	ret = -1;
945
	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
946
947
948
    } else if( params->delay != DEFAULT_DELAY &&
	    (params->delay < DEFAULT_DELAY_MINIMUM  || params->delay > DEFAULT_DELAY_MAXIMUM) ) {
	ret = -1;
949
	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
950
		DEFAULT_DELAY_MINIMUM, DEFAULT_DELAY_MAXIMUM);
951
952
953
954
    } 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
955
956
    } else if(params->rate < DEFAULT_RATE_MINIMUM  ||  params->rate > DEFAULT_RATE_MAXIMUM) {
	ret = -1;
957
	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
958
		DEFAULT_RATE_MINIMUM, DEFAULT_RATE_MAXIMUM);
959
    } else if(params->rate != -1 && params->start_time != 0.0   &&   params->end_time != 0.0) {
960
	ret = -1;
961
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<rate> can not be used with options <start_time> and <end_time>.\n");
962
    } else if(params->flag_buffered != 0 && params->start_time != 0.0   &&   params->end_time != 0.0) {
963
	ret = -1;
964
	nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "<buffered> can not be used with options <start_time> and <end_time>.\n");
965
966
    } else if( (params->max_data_to_retrieve < DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM  ||
		params->max_data_to_retrieve > DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM)) {
967
	ret = -1;
968
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<maxdataretr> has to be within [%d..%d].\n",
969
970
		DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM,
		DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM);
971
    } else if( params->stc == -1
Matteo Quintiliani's avatar
Matteo Quintiliani committed
972
973
	    && (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
974
	ret = -1;
975
	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
976
977
978
979
980
981
982
		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;
983
	    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
984
985
986
		    DEFAULT_TIMEOUTRECV_MINIMUM,
		    DEFAULT_TIMEOUTRECV_MAXIMUM);
	}
987
988

	/* Follow warning messages only */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
989
    } else if( params->stc != -1 && params->max_tolerable_latency > 0 ){
990
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<maxlatency> ignored since not defined --stc=-1.\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
991
992
    } else if(params->stc != -1 && params->timeoutrecv > 0) {
	params->timeoutrecv = 0;
993
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<timeoutrecv> ignored since not defined --stc=-1.\n");
994
    }
995

Matteo Quintiliani's avatar
Matteo Quintiliani committed
996
997
998
    if(params->usec == 0  &&  params->n_channel == 0) {
	/* Do nothing */
    } else if(params->usec < DEFAULT_USEC_MINIMUM  ||  params->usec > DEFAULT_USEC_MAXIMUM) {
999
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1000
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "ms in <mschan> has to be within [%d..%d] or equal to zero if 0/0.\n",
1001
1002
1003
		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;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1004
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "nC in <mschan> has to be within [%d..%d] or equal to zero if 0/0.\n",
1005
1006
1007
		DEFAULT_N_CHANNEL_MINIMUM, DEFAULT_N_CHANNEL_MAXIMUM);
    }
    
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1008
    /*
1009
    if( params->stc == -1 ) {
1010
	nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "<maxlatency> is equal to %d sec.\n", params->max_tolerable_latency);
1011
    }
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1012
    */
1013

1014
1015
    return ret;
}