>From fef0df236e479611a9364711d8e3393821d2edc7 Mon Sep 17 00:00:00 2001 From: "Fulup.ArFoll" Date: Sat, 23 Nov 2013 13:10:03 +0100 Subject: [PATCH] Updated documentation and fixes gps2udp command line parsing --- gps2udp.c | 67 +++++++++++++++++++++++++++++++------------------------------ gps2udp.xml | 11 +++++----- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/gps2udp.c b/gps2udp.c index 313ef36..a1c41e8 100644 --- a/gps2udp.c +++ b/gps2udp.c @@ -23,7 +23,6 @@ #include #include #include -#include #ifndef S_SPLINT_S #include @@ -80,15 +79,16 @@ static bool aisonly = false; static int send_udp (char *nmeastring, size_t ind) { - char message[255]; + char message [255]; char *buffer; int channel; + ssize_t status; - /* if string length is unknown make a copy and compute it */ + /* if string length is unknow make a copy and compute it */ if (ind == 0) { /* compute message size and add 0x0a 0x0d */ for (ind=0; nmeastring [ind] != '\0'; ind ++) { - if (ind >= sizeof(message) - 3) { + if (ind > sizeof(message)) { fprintf(stderr, "gps2udp: too big [%s] \n", nmeastring); return -1; } @@ -96,7 +96,7 @@ static int send_udp (char *nmeastring, size_t ind) } buffer = message; } else { - /* use directly nmeastring but change termination */ + /* use directly nmeastring but change terminition */ buffer = nmeastring; ind = ind-1; } @@ -108,7 +108,6 @@ static int send_udp (char *nmeastring, size_t ind) /* send message on udp channel */ /address@hidden@*/ for (channel=0; channel < udpchannel; channel ++) { - ssize_t status; status = sendto(sock[channel], buffer, ind, @@ -128,14 +127,14 @@ static int send_udp (char *nmeastring, size_t ind) static int open_udp(char **hostport) /* Open and bind udp socket to host */ { - int channel; - for (channel=0; channel < udpchannel; channel ++) + struct hostent *hp; + char *hostname = NULL; + char *portname = NULL; + int portnum, channel; + + for (channel=0; channel 0) - /address@hidden@*/ignore_return(write (1, ".", 1)); + (void)write (1, ".", 1); break; default: /* we lost connection with gpsd */ @@ -299,7 +299,7 @@ static ssize_t read_gpsd(char *message, size_t len) break; } } - message[ind-1] = '\0'; + message[ind] = '\0'; (void)fprintf (stderr,"\n gps2udp: message too big [%s]\n", message); return(-1); } @@ -331,12 +331,10 @@ static unsigned int AISGetInt(unsigned char *bitbytes, unsigned int sp, unsigned { unsigned int acc = 0; unsigned int s0p = sp-1; // to zero base - unsigned int i; + unsigned int cp, cx, c0, i; for(i=0 ; i= byte_length? @@ -352,15 +350,19 @@ int main(int argc, char **argv) { bool daemonize = false; long count = -1; - int option; + int option, status; char *udphostport[MAX_UDP_DEST]; flags = WATCH_ENABLE; - while ((option = getopt(argc, argv, "?habnjcvl:u:d:")) != -1) + while ((option = getopt(argc, argv, "?habnjvc:l:u:d:")) != -1) { switch (option) { case 'd': debug = atoi(optarg); + if ((debug <1) || (debug > 2)) { + usage(); + exit(1); + } break; case 'n': if (debug >0) @@ -382,7 +384,7 @@ int main(int argc, char **argv) daemonize = true; break; case 'u': - if (udpchannel >= MAX_UDP_DEST) { + if (udpchannel > MAX_UDP_DEST) { (void)fprintf(stderr, "gps2udp: too many UDP destinations (max=%d)\n", MAX_UDP_DEST); @@ -393,12 +395,12 @@ int main(int argc, char **argv) case 'v': (void)fprintf(stderr, "%s: %s (revision %s)\n", argv[0], VERSION, REVISION); - exit(EXIT_SUCCESS); + exit(0); case '?': case 'h': default: usage(); - exit(EXIT_FAILURE); + exit(1); } } @@ -415,9 +417,8 @@ int main(int argc, char **argv) /* Open UDP port */ if (udpchannel > 0) { - int status = open_udp(udphostport); - if (status !=0) - exit(EXIT_FAILURE); + status = open_udp(udphostport); + if (status !=0) exit (1); } /* Daemonize if the user requested it. */ @@ -460,7 +461,7 @@ int main(int argc, char **argv) // strtok break original string (void)strncpy((char *)packet, buffer, sizeof(packet)); for (j=0; j 3 @@ -494,7 +495,7 @@ int main(int argc, char **argv) // This is an infinite loop, should never be here /address@hidden@*/ fprintf (stderr, "gpsd2udp ERROR abnormal exit\n"); - exit(EXIT_FAILURE); + exit (-1); } /address@hidden address@hidden/ diff --git a/gps2udp.xml b/gps2udp.xml index e43ddae..5df8800 100644 --- a/gps2udp.xml +++ b/gps2udp.xml @@ -28,7 +28,7 @@ BSD terms apply: see the file COPYING in the distribution root for details. -a -u hostname:udpport -c count - -d + -d 1|2 -v server @@ -86,7 +86,7 @@ destinations). -n [count] causes [count] sentences to be output. gps2udp will then exit gracefully. --d prints sent packet on stdout. +-d 1 prints sent packet on stdout. -v prints the version, then exits. @@ -94,13 +94,12 @@ destinations). With a running gpsd accessible on the network -gps2udp -d -n -u data.aishub.net:2222 will +gps2udp -d 1 -n -u data.aishub.net:2222 will collect data from localhost:gpsd display them on stdout and send a copy to test aishub in NMEA format. -gps2udp -a -n -b -u data.aishub.net 2222 -u 5.9.207.224 -5321 -u 109.200.19.151 4001 vz-fulup.vpn:2947 will collect -data from a remote gpsd located on vz-fulup.vpn host, will filter AIS +gps2udp -a -n -b -u data.aishub.net:2222 -u 5.9.207.224:5321 -u 109.200.19.151:4001 fridu.net:2947 will collect +data from a remote gpsd located on fridu.net host, will filter AIS messages and send them to 3 destination (aishub, marinetraffic, shipfinder) in NMEA format, command is running in background mode -- 1.8.3.2