Changeset 9175425 in multiio for pcmmio/original/main_pcmmio_dac.c


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.