Hi Alex,

Thanks your for your comments. They make plenty of sense. I'll
update the patches accordingly. However, I won't change the return
values: there might be some scripts that depends on these return values
(or it could be that using various return values here makes debugging
easier).

Regards,
        Tony

Le Thu, 25 Apr 2013 07:01:03 +0200,
Alexander Aring <alex.ar...@gmail.com> a écrit :

> Dear Tony,
> 
> On Wed, Apr 24, 2013 at 10:49:16AM -0400, Tony Cheneau wrote:
> > Add a "baudrate" parameter on the CLI that enables the user to
> > choose from different baudrates. If no parameter is passed, the
> > baudrate is set to 115200 (retaining the previous behavior).
> > 
> > Signed-off-by: Tony Cheneau <tony.chen...@amnesiak.org>
> > ---
> >  src/serial.c | 103
> > +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file
> > changed, 82 insertions(+), 21 deletions(-)
> > 
> > diff --git a/src/serial.c b/src/serial.c
> > index ab76aea..d42ea5b 100644
> > --- a/src/serial.c
> > +++ b/src/serial.c
> > @@ -25,6 +25,7 @@
> >  
> >  #include <stdio.h>
> >  #include <string.h>
> > +#include <stdlib.h>
> >  
> >  #include <sys/types.h>
> >  #include <sys/ioctl.h>
> > @@ -32,33 +33,93 @@
> >  #include <termios.h>
> >  #include <unistd.h>
> >  #include <errno.h>
> > +#include <getopt.h>
> >  
> >  #include "ieee802154.h"
> >  
> > +#ifdef HAVE_GETOPT_LONG
> > +static const struct option iz_long_opts[] = {
> > +   { "baudrate", optional_argument, NULL, 'b' },
> > +   { "help", no_argument, NULL, 'h' },
> Maybe we should add "version" and 'v' here.
> > +   { NULL, 0, NULL, 0 },
> > +};
> > +#endif
> > +
> > +void serial_help(const char * pname) {
> > +   printf("Usage: %s [options] SERIAL_DEV\n", pname);
> > +   printf("Attach serial devices via UART to IEEE
> > 802.15.4/ZigBee stack\n\n");
> > +   printf("Options:\n");
> > +   printf("  -b, --baudrate[=115200]        set the
> > baudrate\n");
> > +   printf("  -h, --help                     print help\n");
> Same here.
> > +   printf("  SERIAL_DEV                     this specifies
> > the serial device to attach.\n");
> > +   printf("Report bugs to " PACKAGE_BUGREPORT "\n\n");
> > +   printf(PACKAGE_NAME " homepage <" PACKAGE_URL ">\n");
> > +}
> > +
> > +speed_t baudrate_to_speed(long baudrate) {
> > +   switch(baudrate) {
> > +           case 9600: return B9600;
> > +           case 19200: return B19200;
> > +           case 38400: return B38400;
> > +           case 57600: return B57600;
> > +           case 115200: return B115200;
> > +           case 230400: return B230400;
> > +           case 460800: return B460800;
> > +           case 921600: return B921600;
> Intend here like linux kernel?
> it's
> 
> switch(foo) {
> case bar:
> ...
> }
> > +           default:
> > +                   printf("Unrecognized baudrate %ld\n",
> > baudrate);
> > +                   exit(EXIT_FAILURE);
> > +    }
> > +}
> > +
> >  int main(int argc, char **argv) {
> > -   int fd, ret, s;
> > -
> > -   if (argc == 1 || !strcmp(argv[1], "--version")) {
> > -           printf( "izattach " VERSION "\n"
> > -                   "Copyright (C) 2008, 2009 by Siemens AG\n"
> > -                   "License GPLv2 GNU GPL version 2
> > <http://gnu.org/licenses/gpl.html>.\n"
> > -                   "This is free software: you are free to
> > change and redistribute it.\n"
> > -                   "There is NO WARRANTY, to the extent
> > permitted by law.\n"
> > -                   "\n"
> > -                   "Written by Dmitry Eremin-Solenikov,
> > Sergey Lapin and Maxim Osipov\n");
> > -           return 0;
> > +   int fd, ret, s, c;
> > +   long baudrate;
> > +   char * endptr;
> > +   speed_t speed = B115200;
> > +
> > +   /* Parse options */
> > +   while (1) {
> > +#ifdef HAVE_GETOPT_LONG
> > +           int opt_idx = -1;
> > +           c = getopt_long(argc, argv, "b:h", iz_long_opts,
> > &opt_idx); +#else
> > +           c = getopt(argc, argv, "b:h");
> > +#endif
> > +           if (c == -1)
> > +                   break;
> > +
> > +           switch(c) {
> > +               case 'h':
> > +                   serial_help(argv[0]);
> > +                   return 0;
> > +               case 'b':
> > +                   baudrate = strtol(optarg, &endptr, 10);
> > +                   if (* endptr == '\0')
> > +                       speed = baudrate_to_speed(baudrate);
> > +                   break;
> > +               case 'v':
> > +                   printf( "izattach " VERSION "\n"
> > +                           "Copyright (C) 2008, 2009 by
> > Siemens AG\n"
> > +                           "License GPLv2 GNU GPL version 2
> > <http://gnu.org/licenses/gpl.html>.\n"
> > +                           "This is free software: you are
> > free to change and redistribute it.\n"
> > +                           "There is NO WARRANTY, to the
> > extent permitted by law.\n"
> > +                           "\n"
> > +                           "Written by Dmitry
> > Eremin-Solenikov, Sergey Lapin and Maxim Osipov\n");
> > +                   return 0;
> > +               default:
> > +                   serial_help(argv[0]);
> > +                   return 1;
> > +           }
> >     }
> >  
> > -   if (argc != 2 || (argc >= 1 && !strcmp(argv[1],
> > "--help"))) {
> > -           printf("Usage: %s SERIAL_DEV\n", argv[0]);
> > -           printf("Attach serial devices via UART to IEEE
> > 802.15.4/ZigBee stack\n\n");
> > -           printf("  SERIAL_DEV  This specifies the serial
> > device to attach.\n");
> > -           printf("Report bugs to " PACKAGE_BUGREPORT "\n\n");
> > -           printf(PACKAGE_NAME " homepage <" PACKAGE_URL
> > ">\n");
> > -           return 1;
> > +   if (argc <= optind) {
> > +           printf("SERIAL_DEV argument is missing\n\n");
> > +           serial_help(argv[0]);
> > +           return 2;
> Maybe we should only use return 1 for error and 0 for success. Maybe
> we should use the standard EXIT_FAILURE and EXIT_SUCCESS defines for
> that.
> 
> Regards
> Alex

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

Reply via email to