Changeset 9175425 in multiio


Ignore:
Timestamp:
Jul 22, 2009, 4:50:06 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
master
Children:
f89686d
Parents:
69f7221
Message:

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • README, main_pcmmio_adc.c, main_pcmmio_dac.c, main_pcmmio_din.c, main_pcmmio_dout.c, pcmmio_commands.h: Switch to rtems/string2.h methods. Verify negative voltages are allowed as input.
Location:
pcmmio/original
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pcmmio/original/ChangeLog

    r69f7221 r9175425  
     12009-07-22      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * README, main_pcmmio_adc.c, main_pcmmio_dac.c, main_pcmmio_din.c,
     4        main_pcmmio_dout.c, pcmmio_commands.h: Switch to rtems/string2.h
     5        methods. Verify negative voltages are allowed as input.
     6
    172009-07-21      Joel Sherrill <joel.sherrill@oarcorp.com>
    28
  • pcmmio/original/README

    r69f7221 r9175425  
    3535
    3636pcmmio_dout - Write a Discrete Output
    37     pcmmio_dout [-v] bit value
     37    pcmmio_dout bit value
    3838    Where: bit must be 0-47
    3939           value must be 0 or 1
     
    4545
    4646pcmmio_adc - Write Analog Output
    47     pcmmio_dac [-v] dac voltage\n"
     47    pcmmio_dac dac voltage
    4848    Where: dac must be 0-7
    4949           voltage must be -10V to +10V
  • pcmmio/original/main_pcmmio_adc.c

    r69f7221 r9175425  
    1313
    1414#include "pcmmio_commands.h"
     15#include <rtems/stringto.h>
    1516
    1617#define __need_getopt_newlib
     
    5354  "       the period is in milliseconds and defaults to 1000\n";
    5455
     56#define PRINT_USAGE() \
     57   printf( pcmmio_adc_usage, argv[0] )
     58
    5559int main_pcmmio_adc(int argc, char **argv)
    5660{
    57   int    milliseconds;
    58   int    maximum;
    59   int    iterations;
    60   char   ch;
    61   bool   changed;
    62   bool   verbose;
    63   struct getopt_data getopt_reent;
    64   float  adc_last[16];
    65   float  adc_current[16];
     61  int                 milliseconds;
     62  int                 maximum;
     63  int                 iterations;
     64  char                ch;
     65  bool                changed;
     66  bool                verbose;
     67  struct getopt_data  getopt_reent;
     68  float               adc_last[16];
     69  float               adc_current[16];
     70  const  char        *s;
    6671
    6772  /*
     
    7681    switch (ch) {
    7782      case 'i': /* maximum iterations */
    78         maximum = rtems_shell_str2int( getopt_reent.optarg );
     83        s = getopt_reent.optarg;
     84        if ( !rtems_string_to_int( s, &maximum, NULL, 0 ) ) {
     85          printf( "Maximum iterations (%s) is not a number\n", s );
     86          PRINT_USAGE();
     87          return -1;
     88        }
     89
    7990        break;
    8091      case 'p': /* sampling period */
    81         milliseconds = rtems_shell_str2int( getopt_reent.optarg );
     92        s = getopt_reent.optarg;
     93        if ( !rtems_string_to_int( s, &milliseconds, NULL, 0 ) ) {
     94          printf( "Sampling period (%s) is not a number\n", s );
     95          PRINT_USAGE();
     96          return -1;
     97        }
     98        if ( milliseconds == 0 ) {
     99          printf( "Sampling period (%d) is 0\n", milliseconds );
     100          PRINT_USAGE();
     101          return -1;
     102        }
     103
    82104        break;
    83105      case 'v': /* verbose*/
     
    85107        break;
    86108      default:
    87         printf( pcmmio_adc_usage, argv[0] );
     109        PRINT_USAGE();
    88110        return -1;
    89111    }
  • pcmmio/original/main_pcmmio_dac.c

    r69f7221 r9175425  
    1515#include <rtems/string2.h>
    1616
    17 #define __need_getopt_newlib
    18 #include <getopt.h>
    1917#include <stdlib.h>
    2018
     
    2523
    2624char pcmmio_dac_usage[] =
    27   "Usage: %s [-v] dac voltage\n"
     25  "Usage: %s dac voltage\n"
    2826  "Where: dac must be 0-7\n"
    2927  "       voltage must be -10V to +10V\n";
     
    3432int main_pcmmio_dac(int argc, char **argv)
    3533{
    36   char   ch;
    37   bool   verbose;
    38   struct getopt_data getopt_reent;
    3934  int    dac;
    4035  float  voltage;
     36  bool   fail = false;
    4137
    4238  /*
    43    * Parse arguments here
     39   *  Verify that we have the right number of arguments.
    4440   */
    45   verbose = false;
    46 
    47   memset(&getopt_reent, 0, sizeof(getopt_data));
    48   while ((ch = getopt_r(argc, argv, "v", &getopt_reent)) != -1) {
    49     switch (ch) {
    50       case 'v': /* verbose*/
    51         verbose = true;
    52         break;
    53       default:
    54         PRINT_USAGE();
    55         return -1;
    56     }
    57   }
    58 
    59   if ( (argc - getopt_reent.optind) != 2 ) {
     41  if ( argc != 3 ) {
    6042    printf( "Incorrect number of arguments\n" );
    6143    PRINT_USAGE();
     
    6648   *  Convert the string arguments into number values
    6749   */
    68   if ( !rtems_string_to_int( argv[getopt_reent.optind], &dac, NULL, 0 ) ) {
    69     printf( "DAC (%s) is not a number\n", argv[getopt_reent.optind] );
    70     PRINT_USAGE();
    71     return -1;
     50  if ( !rtems_string_to_int( argv[1], &dac, NULL, 0 ) ) {
     51    printf( "DAC (%s) is not a number\n", argv[1] );
     52    fail = true;
    7253  }
    7354
    74   if ( !rtems_string_to_float( argv[getopt_reent.optind+1], &voltage, NULL ) ) {
    75     printf( "Voltage (%s) is not a number\n", argv[getopt_reent.optind + 1] );
    76     PRINT_USAGE();
    77     return -1;
     55  if ( !rtems_string_to_float( argv[2], &voltage, NULL ) ) {
     56    printf( "Voltage (%s) is not a number\n", argv[2] );
     57    fail = true;
    7858  }
    79 
    80   voltage = strtof( argv[getopt_reent.optind + 1], NULL );
    8159
    8260  /*
     
    8563  if ( dac < 0 || dac > 7 ) {
    8664    puts( "DAC number must be 0-7" );
    87     PRINT_USAGE();
    88     return -1;
     65    fail = true;
    8966  }
    9067
    9168  if ( voltage < -10.0 || voltage > 10.0 ) {
    9269    printf( "Voltage must be between -10.0V and +10.0V\n" );
     70    fail = true;
     71  }
     72
     73  if ( fail ) {
    9374    PRINT_USAGE();
    9475    return -1;
     
    9879   *  Now write the voltage
    9980   */
    100   if ( verbose )
    101     printf( "Write %6.4f to to dac %d\n", voltage, dac );
     81  printf( "Write %6.4f to to dac %d\n", voltage, dac );
    10282  set_dac_voltage(dac, voltage);
    10383
  • pcmmio/original/main_pcmmio_din.c

    r69f7221 r9175425  
    1313
    1414#include "pcmmio_commands.h"
     15#include <rtems/stringto.h>
    1516
    1617#define __need_getopt_newlib
     
    5657  "       the period is in milliseconds and defaults to 1000\n";
    5758
     59#define PRINT_USAGE() \
     60   printf( pcmmio_din_usage, argv[0] )
     61
    5862int main_pcmmio_din(int argc, char **argv)
    5963{
    60   int    milliseconds;
    61   int    maximum;
    62   int    iterations;
    63   char   ch;
    64   bool   changed;
    65   bool   verbose;
    66   struct getopt_data getopt_reent;
    67   int    dio_last[48];
    68   int    dio_current[48];
     64  int                 milliseconds;
     65  int                 maximum;
     66  int                 iterations;
     67  char                ch;
     68  bool                changed;
     69  bool                verbose;
     70  struct getopt_data  getopt_reent;
     71  int                 dio_last[48];
     72  int                 dio_current[48];
     73  const  char        *s;
    6974
    7075  /*
     
    7984    switch (ch) {
    8085      case 'i': /* maximum iterations */
    81         maximum = rtems_shell_str2int( getopt_reent.optarg );
     86        s = getopt_reent.optarg;
     87        if ( !rtems_string_to_int( s, &maximum, NULL, 0 ) ) {
     88          printf( "Maximum iterations (%s) is not a number\n", s );
     89          PRINT_USAGE();
     90          return -1;
     91        }
     92
    8293        break;
    8394      case 'p': /* sampling period */
    84         milliseconds = rtems_shell_str2int( getopt_reent.optarg );
     95        s = getopt_reent.optarg;
     96        if ( !rtems_string_to_int( s, &milliseconds, NULL, 0 ) ) {
     97          printf( "Sampling period (%s) is not a number\n", s );
     98          PRINT_USAGE();
     99          return -1;
     100        }
     101        if ( milliseconds == 0 ) {
     102          printf( "Sampling period (%d) is 0\n", milliseconds );
     103          PRINT_USAGE();
     104          return -1;
     105        }
    85106        break;
    86107      case 'v': /* verbose*/
  • pcmmio/original/main_pcmmio_dout.c

    r69f7221 r9175425  
    1313
    1414#include "pcmmio_commands.h"
    15 #include <rtems/string2.h>
    16 
    17 #define __need_getopt_newlib
    18 #include <getopt.h>
     15#include <rtems/stringto.h>
    1916
    2017#if defined(TESTING)
     
    2421
    2522char pcmmio_dout_usage[] =
    26   "Usage: %s [-v] bit value\n"
     23  "Usage: %s bit value\n"
    2724  "Where: bit must be 0-47\n"
    2825  "       value must be 0 or 1\n";
    2926
    3027#define PRINT_USAGE() \
    31    printf( pcmmio_dout_usage, argv[0] );
     28   printf( pcmmio_dout_usage, argv[0] )
    3229
    3330int main_pcmmio_dout(int argc, char **argv)
    3431{
    35   char   ch;
    36   bool   verbose;
    37   struct getopt_data getopt_reent;
    3832  int    bit;
    3933  int    value;
     34  bool   fail = false;
    4035
    4136  /*
    42    * Parse arguments here
     37   *  Verify that we have the right number of arguments.
    4338   */
    44   verbose = false;
    45 
    46   memset(&getopt_reent, 0, sizeof(getopt_data));
    47   while ((ch = getopt_r(argc, argv, "v", &getopt_reent)) != -1) {
    48     switch (ch) {
    49       case 'v': /* verbose*/
    50         verbose = true;
    51         break;
    52       default:
    53         PRINT_USAGE();
    54         return -1;
    55     }
    56   }
    57 
    58   if ( (argc - getopt_reent.optind) != 2 ) {
     39  if ( argc != 3 ) {
    5940    printf( "Incorrect number of arguments\n" );
    6041    PRINT_USAGE();
     
    6546   *  Convert the string arguments into number values
    6647   */
    67   if ( !rtems_string_to_int( argv[getopt_reent.optind], &bit, NULL, 0 ) ) {
    68     printf( "Bit (%s) is not a number\n", argv[getopt_reent.optind] );
    69     PRINT_USAGE();
    70     return -1;
     48  if ( !rtems_string_to_int( argv[1], &bit, NULL, 0 ) ) {
     49    printf( "Bit (%s) is not a number\n", argv[1] );
     50    fail = true;
    7151  }
    7252
    73   if ( !rtems_string_to_int(argv[getopt_reent.optind + 1], &value, NULL, 0) ) {
    74     printf( "Value (%s) is not a number\n", argv[getopt_reent.optind] );
    75     PRINT_USAGE();
    76     return -1;
     53  if ( !rtems_string_to_int(argv[2], &value, NULL, 0) ) {
     54    printf( "Value (%s) is not a number\n", argv[2] );
     55    fail = true;
    7756  }
    7857
     
    8261  if ( bit < 0 || bit > 47 ) {
    8362    printf( "Bit number must be 0-47\n" );
    84     PRINT_USAGE();
    85     return -1;
     63    fail = true;
    8664  }
    8765
    8866  if ( value != 0 && value != 1 ) {
    8967    printf( "Value must be 0 or 1\n" );
     68    fail = true;
     69  }
     70
     71  if ( fail ) {
    9072    PRINT_USAGE();
    9173    return -1;
     
    9577   *  Now write the value
    9678   */
    97   if ( verbose )
    98     printf( "Write %d to to bit %d\n", value, bit );
     79  printf( "Write %d to to bit %d\n", value, bit );
    9980  dio_write_bit(bit, value);
    10081
  • pcmmio/original/pcmmio_commands.h

    r69f7221 r9175425  
    2626  &Shell_PCMMIO_DIN_Command, \
    2727  &Shell_PCMMIO_DOUT_Command, \
     28  &Shell_PCMMIO_ADC_Command, \
    2829  &Shell_PCMMIO_DAC_Command
    2930
Note: See TracChangeset for help on using the changeset viewer.