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