source: multiio/pcmmio/original/main_pcmmio_dac.c @ 69f7221

Last change on this file since 69f7221 was 69f7221, checked in by Joel Sherrill <joel.sherrill@…>, on 07/21/09 at 23:27:42

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

  • Makefile, README, main_pcmmio_dac.c, main_pcmmio_dout.c: Added string2XXX routines to RTEMS so we have ability to do heavy error checking on numeric inputs.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  pcmmio_dac command
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include "pcmmio_commands.h"
15#include <rtems/string2.h>
16
17#define __need_getopt_newlib
18#include <getopt.h>
19#include <stdlib.h>
20
21#if defined(TESTING)
22  #define set_dac_voltage(_dac, _voltage) \
23    printf( "Testing: Write %6.4f to to dac %d\n", _voltage, _dac );
24#endif
25
26char pcmmio_dac_usage[] =
27  "Usage: %s [-v] dac voltage\n"
28  "Where: dac must be 0-7\n"
29  "       voltage must be -10V to +10V\n";
30
31#define PRINT_USAGE() \
32   printf( pcmmio_dac_usage, argv[0] );
33
34int main_pcmmio_dac(int argc, char **argv)
35{
36  char   ch;
37  bool   verbose;
38  struct getopt_data getopt_reent;
39  int    dac;
40  float  voltage;
41
42  /*
43   * Parse arguments here
44   */
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 ) {
60    printf( "Incorrect number of arguments\n" );
61    PRINT_USAGE();
62    return -1;
63  }
64
65  /*
66   *  Convert the string arguments into number values
67   */
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;
72  }
73
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;
78  }
79
80  voltage = strtof( argv[getopt_reent.optind + 1], NULL );
81
82  /*
83   *  Validate the output dac and voltage.
84   */
85  if ( dac < 0 || dac > 7 ) {
86    puts( "DAC number must be 0-7" );
87    PRINT_USAGE();
88    return -1;
89  }
90
91  if ( voltage < -10.0 || voltage > 10.0 ) {
92    printf( "Voltage must be between -10.0V and +10.0V\n" );
93    PRINT_USAGE();
94    return -1;
95  }
96
97  /*
98   *  Now write the voltage
99   */
100  if ( verbose )
101    printf( "Write %6.4f to to dac %d\n", voltage, dac );
102  set_dac_voltage(dac, voltage);
103
104  return 0;
105}
106
107rtems_shell_cmd_t Shell_PCMMIO_DAC_Command = {
108  "pcmmio_dac",                                    /* name */
109  "Read PCMMIO Analog Inputs",                     /* usage */
110  "pcmmio",                                        /* topic */
111  main_pcmmio_dac,                                 /* command */
112  NULL,                                            /* alias */
113  NULL                                             /* next */
114};
115
116rtems_shell_alias_t Shell_PCMMIO_DAC_Alias = {
117  "pcmmio_dac",          /* command */
118  "dac"                  /* alias */
119};
120
Note: See TracBrowser for help on using the repository browser.