source: multiio/pcmmio/original/main_pcmmio_dac.c @ 9175425

Last change on this file since 9175425 was 9175425, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 22, 2009 at 4:50:06 PM

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.
  • Property mode set to 100644
File size: 2.3 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#include <stdlib.h>
18
19#if defined(TESTING)
20  #define set_dac_voltage(_dac, _voltage) \
21    printf( "Testing: Write %6.4f to to dac %d\n", _voltage, _dac );
22#endif
23
24char pcmmio_dac_usage[] =
25  "Usage: %s dac voltage\n"
26  "Where: dac must be 0-7\n"
27  "       voltage must be -10V to +10V\n";
28
29#define PRINT_USAGE() \
30   printf( pcmmio_dac_usage, argv[0] );
31
32int main_pcmmio_dac(int argc, char **argv)
33{
34  int    dac;
35  float  voltage;
36  bool   fail = false;
37
38  /*
39   *  Verify that we have the right number of arguments.
40   */
41  if ( argc != 3 ) {
42    printf( "Incorrect number of arguments\n" );
43    PRINT_USAGE();
44    return -1;
45  }
46
47  /*
48   *  Convert the string arguments into number values
49   */
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;
53  }
54
55  if ( !rtems_string_to_float( argv[2], &voltage, NULL ) ) {
56    printf( "Voltage (%s) is not a number\n", argv[2] );
57    fail = true;
58  }
59
60  /*
61   *  Validate the output dac and voltage.
62   */
63  if ( dac < 0 || dac > 7 ) {
64    puts( "DAC number must be 0-7" );
65    fail = true;
66  }
67
68  if ( voltage < -10.0 || voltage > 10.0 ) {
69    printf( "Voltage must be between -10.0V and +10.0V\n" );
70    fail = true;
71  }
72
73  if ( fail ) {
74    PRINT_USAGE();
75    return -1;
76  }
77
78  /*
79   *  Now write the voltage
80   */
81  printf( "Write %6.4f to to dac %d\n", voltage, dac );
82  set_dac_voltage(dac, voltage);
83
84  return 0;
85}
86
87rtems_shell_cmd_t Shell_PCMMIO_DAC_Command = {
88  "pcmmio_dac",                                    /* name */
89  "Read PCMMIO Analog Inputs",                     /* usage */
90  "pcmmio",                                        /* topic */
91  main_pcmmio_dac,                                 /* command */
92  NULL,                                            /* alias */
93  NULL                                             /* next */
94};
95
96rtems_shell_alias_t Shell_PCMMIO_DAC_Alias = {
97  "pcmmio_dac",          /* command */
98  "dac"                  /* alias */
99};
100
Note: See TracBrowser for help on using the repository browser.