[Client] Add verbose and quiet options (-v / -q)
This commit is contained in:
parent
9701a2d393
commit
b859734d23
2
TODO.t2t
2
TODO.t2t
|
@ -170,8 +170,6 @@ Work to do in OwlPS
|
|||
|
||||
= Client =
|
||||
|
||||
- Add verbose & quiet options.
|
||||
|
||||
- Log sent requests?
|
||||
|
||||
- Allow to use a string for the direction?
|
||||
|
|
|
@ -20,13 +20,13 @@ OwlPS {{OWLPS_VERSION}}
|
|||
|
||||
= Synopsis =
|
||||
|
||||
**owlps-client** **-i** dest_ip [ **-p** //dest_port// ] [ **-I** //iface// ] [ **-t** //delay// ]
|
||||
[ **-n** //nb_packets// ] [ **-s** //packet_size// ] [ **-F** [ //delay// ]
|
||||
[ **-N** //nb_requests// ] [ **-D** ] ] [ **-l** [ //port// ] ]
|
||||
**owlps-client** [ **-v** | **-q** ] **-i** dest_ip [ **-p** //dest_port// ] [ **-I** //iface// ]
|
||||
[ **-t** //delay// ] [ **-n** //nb_packets// ] [ **-s** //packet_size// ]
|
||||
[ **-F** [ //delay// ] [ **-N** //nb_requests// ] [ **-D** ] ] [ **-l** [ //port// ] ]
|
||||
|
||||
**owlps-client** **-i** dest_ip [ **-p** //dest_port// ] [ **-I** //iface// ] [ **-t** //delay// ]
|
||||
[ **-n** //nb_packets// ] [ **-s** //packet_size// ] [ **-F** [ //delay// ]
|
||||
[ **-N** //nb_requests// ] [ **-D** ] ] //direction x y z//
|
||||
**owlps-client** [ **-v** | **-q** ] **-i** dest_ip [ **-p** //dest_port// ] [ **-I** //iface// ]
|
||||
[ **-t** //delay// ] [ **-n** //nb_packets// ] [ **-s** //packet_size// ]
|
||||
[ **-F** [ //delay// ] [ **-N** //nb_requests// ] [ **-D** ] ] //direction x y z//
|
||||
|
||||
|
||||
|
||||
|
@ -96,6 +96,11 @@ Where:
|
|||
Print help message.
|
||||
: **-V**
|
||||
Print version information.
|
||||
: **-v**
|
||||
Turn on verbose mode (default).
|
||||
: **-q**
|
||||
Do not print informational messages and some (less important)
|
||||
warnings.
|
||||
: **-i** //dest_ip//
|
||||
Destination IP address of the localisation request.
|
||||
: **-p** //dest_port//
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
#define MAX_PKT_SIZE 1450u
|
||||
|
||||
/* Program arguments (getopt string) */
|
||||
#define OPTIONS "DF::hi:I:l::n:N:p:s:t:V"
|
||||
#define OPTIONS "DF::hi:I:l::n:N:p:qs:t:vV"
|
||||
|
||||
|
||||
/* Function headers */
|
||||
|
@ -59,9 +59,7 @@ void parse_main_options(int argc, char **argv) ;
|
|||
void check_destination_ip(void) ;
|
||||
void parse_calibration_data(int argc, char **argv) ;
|
||||
void check_configuration(void) ;
|
||||
#ifdef OWLPS_DEBUG
|
||||
void print_configuration(void) ;
|
||||
#endif // OWLPS_DEBUG
|
||||
void create_socket(void) ;
|
||||
void send_request(void) ;
|
||||
void make_packet(void) ;
|
||||
|
@ -78,6 +76,7 @@ void print_version(void) ;
|
|||
/* Options */
|
||||
struct {
|
||||
bool daemon ;
|
||||
bool verbose ;
|
||||
char dest_ip[INET_ADDRSTRLEN] ; // Destination IP of the packets
|
||||
uint_fast16_t dest_port ;
|
||||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||
|
@ -94,6 +93,7 @@ struct {
|
|||
float z ;
|
||||
} options = {
|
||||
false, // daemon
|
||||
true, // verbose
|
||||
"", // dest_ip
|
||||
OWL_DEFAULT_REQUEST_PORT, // dest_port
|
||||
"", // iface
|
||||
|
@ -131,6 +131,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (options.daemon)
|
||||
{
|
||||
if (options.verbose)
|
||||
fprintf(stderr, "Detaching to background...\n") ;
|
||||
if (daemon(0, 0))
|
||||
perror("Cannot daemonize") ;
|
||||
|
@ -179,9 +180,8 @@ void parse_command_line(int argc, char **argv)
|
|||
parse_calibration_data(argc, argv) ;
|
||||
check_configuration() ;
|
||||
|
||||
#ifdef OWLPS_DEBUG
|
||||
if (options.verbose)
|
||||
print_configuration() ;
|
||||
#endif // OWLPS_DEBUG
|
||||
}
|
||||
|
||||
|
||||
|
@ -265,12 +265,18 @@ void parse_main_options(int argc, char **argv)
|
|||
case 'p' :
|
||||
options.dest_port = strtoul(optarg, NULL, 0) ;
|
||||
break ;
|
||||
case 'q' :
|
||||
options.verbose = false ;
|
||||
break ;
|
||||
case 's' :
|
||||
options.pkt_size = strtoul(optarg, NULL, 0) ;
|
||||
break ;
|
||||
case 't' :
|
||||
options.delay = strtol(optarg, NULL, 0) ;
|
||||
break ;
|
||||
case 'v' :
|
||||
options.verbose = true ;
|
||||
break ;
|
||||
case 'V' :
|
||||
print_version() ;
|
||||
exit(0) ;
|
||||
|
@ -325,10 +331,9 @@ void check_configuration()
|
|||
// Delay not specified (or bad delay):
|
||||
if (options.delay < 0)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
if (options.verbose)
|
||||
fprintf(stderr,
|
||||
"Warning! delay: failing back to default value.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
if (is_calibration_request)
|
||||
options.delay = DEFAULT_DELAY_CALIB ;
|
||||
else
|
||||
|
@ -338,10 +343,9 @@ void check_configuration()
|
|||
// Number of packet not specified (or bad number)
|
||||
if (options.nb_pkt < 1)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
if (options.verbose)
|
||||
fprintf(stderr,
|
||||
"Warning! nb_pkt: failing back to default value.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
if (is_calibration_request)
|
||||
options.nb_pkt = DEFAULT_NBPKT_CALIB ;
|
||||
else
|
||||
|
@ -351,11 +355,10 @@ void check_configuration()
|
|||
// Packet size too big
|
||||
if (options.pkt_size > MAX_PKT_SIZE)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
if (options.verbose)
|
||||
fprintf(stderr,
|
||||
"Warning! pkt_size cannot be greater than %d bytes:"
|
||||
" failing back to %d.\n", MAX_PKT_SIZE, MAX_PKT_SIZE) ;
|
||||
#endif // OWLPS_DEBUG
|
||||
options.pkt_size = MAX_PKT_SIZE ;
|
||||
}
|
||||
|
||||
|
@ -372,28 +375,22 @@ void check_configuration()
|
|||
// Check port numbers
|
||||
if (options.dest_port < 1 || options.dest_port > 65535)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! Bad dest_port:"
|
||||
" failing back to default value.\n") ;
|
||||
options.dest_port = OWL_DEFAULT_REQUEST_PORT ;
|
||||
#endif // OWLPS_DEBUG
|
||||
}
|
||||
if (options.listening_port > 65535)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! listening_port too high: ignored.\n") ;
|
||||
options.listening_port = 0 ;
|
||||
#endif // OWLPS_DEBUG
|
||||
}
|
||||
|
||||
// We want to send a calibration request AND to be located, which is
|
||||
// not allowed:
|
||||
if (is_calibration_request && options.listening_port > 0)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! You cannot wait for a server answer when"
|
||||
" you calibrate. Option -l ignored.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
options.listening_port = 0 ;
|
||||
}
|
||||
|
||||
|
@ -402,10 +399,8 @@ void check_configuration()
|
|||
// We want to flood AND to be located, which is not allowed:
|
||||
if (options.listening_port > 0)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! You cannot wait for a server answer"
|
||||
" when you flood. Option -l ignored.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
options.listening_port = 0 ;
|
||||
}
|
||||
}
|
||||
|
@ -413,19 +408,15 @@ void check_configuration()
|
|||
{
|
||||
if (options.nb_requests)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! The -N option can be used only along"
|
||||
" with -F. Option -N ignored.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
options.nb_requests = 0 ;
|
||||
}
|
||||
if (options.daemon)
|
||||
{
|
||||
#ifdef OWLPS_DEBUG
|
||||
fprintf(stderr, "Warning! It is useless to detach from"
|
||||
" the foreground if the flood mode is not activated"
|
||||
" Option -D ignored.\n") ;
|
||||
#endif // OWLPS_DEBUG
|
||||
options.daemon = false ;
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +424,6 @@ void check_configuration()
|
|||
|
||||
|
||||
|
||||
#ifdef OWLPS_DEBUG
|
||||
void print_configuration()
|
||||
{
|
||||
fprintf(stderr, "Options:\n"
|
||||
|
@ -464,7 +454,6 @@ void print_configuration()
|
|||
options.z
|
||||
) ;
|
||||
}
|
||||
#endif // OWLPS_DEBUG
|
||||
|
||||
|
||||
|
||||
|
@ -499,6 +488,7 @@ void make_packet()
|
|||
|
||||
if (is_calibration_request) // Calibration packet
|
||||
{
|
||||
if (options.verbose)
|
||||
printf("Preparing calibration request packet...\n") ;
|
||||
|
||||
packet_size =
|
||||
|
@ -518,6 +508,7 @@ void make_packet()
|
|||
|
||||
else // Standard packet
|
||||
{
|
||||
if (options.verbose)
|
||||
printf("Preparing request packet...\n") ;
|
||||
|
||||
packet_size =
|
||||
|
@ -548,6 +539,7 @@ void add_padding()
|
|||
if (options.pkt_size > packet_size)
|
||||
packet_size = options.pkt_size ;
|
||||
|
||||
if (options.verbose)
|
||||
printf("Packet size: %"PRIuFAST16"\n", packet_size) ;
|
||||
}
|
||||
|
||||
|
@ -586,6 +578,7 @@ uint_fast16_t initialise_common_fields(uint_fast8_t packet_type)
|
|||
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
|
||||
offset += sizeof(request_time) ;
|
||||
|
||||
if (options.verbose)
|
||||
printf("Packet timestamp: %s\n", request_time_str) ;
|
||||
|
||||
return offset ;
|
||||
|
@ -603,10 +596,9 @@ uint_fast16_t initialise_calibration_fields(uint_fast16_t offset)
|
|||
// Direction:
|
||||
packet[offset++] = options.direction ;
|
||||
|
||||
#ifdef OWLPS_DEBUG
|
||||
if (options.verbose)
|
||||
printf("Direction = %d, X = %f, Y = %f, Z = %f\n",
|
||||
packet[offset - 1], options.x, options.y, options.z) ;
|
||||
#endif // OWLPS_DEBUG
|
||||
|
||||
// Convert the coordinates to the network endianness:
|
||||
x = owl_htonf(options.x) ;
|
||||
|
@ -657,11 +649,18 @@ int receive_position()
|
|||
|
||||
|
||||
|
||||
/*
|
||||
* Prints the usage message on the standard output.
|
||||
*
|
||||
* /!\ Don't forget to update the documentation when modifying something
|
||||
* here!
|
||||
*/
|
||||
void print_usage()
|
||||
{
|
||||
printf("Usage:\n"
|
||||
"Localisation request:\n"
|
||||
"\t%s"
|
||||
" [-v | -q]"
|
||||
" -i dest_ip"
|
||||
" [-p dest_port]"
|
||||
" [-I iface]"
|
||||
|
@ -674,6 +673,7 @@ void print_usage()
|
|||
" [-l [port]]\n"
|
||||
"Calibration request:\n"
|
||||
"\t%s"
|
||||
" [-v | -q]"
|
||||
" -i dest_ip"
|
||||
" [-p dest_port]"
|
||||
" [-I iface]"
|
||||
|
@ -688,6 +688,9 @@ void print_usage()
|
|||
"Options:\n"
|
||||
"\t-h\t\tPrint this help.\n"
|
||||
"\t-V\t\tPrint version information.\n"
|
||||
"\t-v\t\tTurn on verbose mode (default).\n"
|
||||
"\t-q\t\tDo not print informational messages and some (less\n"
|
||||
"\t\t\timportant) warnings.\n"
|
||||
"\t-i dest_ip\tDestination IP address of the localisation"
|
||||
" request.\n"
|
||||
"\t-p dest_port\tDestination port of the localisation request"
|
||||
|
|
Loading…
Reference in New Issue