[e38d987] | 1 | /* |
---|
| 2 | * dout 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 <stdio.h> |
---|
| 15 | #include <stdlib.h> |
---|
| 16 | #include <rtems.h> |
---|
| 17 | #include <rtems/shell.h> |
---|
| 18 | #include <rtems/stringto.h> |
---|
| 19 | #include "multiio.h" |
---|
| 20 | |
---|
| 21 | static char dout_usage[] = |
---|
| 22 | "Usage: %s bit value\n" |
---|
| 23 | "Where: bit must be 0-%d\n" |
---|
| 24 | " value must be 0 or 1\n"; |
---|
| 25 | |
---|
| 26 | #define PRINT_USAGE() \ |
---|
| 27 | printf( dout_usage, argv[0], maximum ) |
---|
| 28 | |
---|
| 29 | int main_multiio_dout(int argc, char **argv) |
---|
| 30 | { |
---|
| 31 | int bit; |
---|
| 32 | int value; |
---|
| 33 | bool fail = false; |
---|
| 34 | int maximum = rtems_dout_get_maximum(); |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * Verify that we have the right number of arguments. |
---|
| 38 | */ |
---|
| 39 | if ( argc != 3 ) { |
---|
| 40 | printf( "Incorrect number of arguments\n" ); |
---|
| 41 | PRINT_USAGE(); |
---|
| 42 | return -1; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | * Convert the string arguments into number values |
---|
| 47 | */ |
---|
| 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; |
---|
| 51 | } |
---|
| 52 | |
---|
| 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; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* |
---|
| 59 | * Validate the output bit and value. |
---|
| 60 | */ |
---|
| 61 | if ( bit < 0 || bit > maximum ) { |
---|
| 62 | printf( "Bit number must be 0-maximum\n" ); |
---|
| 63 | fail = true; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | if ( value != 0 && value != 1 ) { |
---|
| 67 | printf( "Value must be 0 or 1\n" ); |
---|
| 68 | fail = true; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | if ( fail ) { |
---|
| 72 | PRINT_USAGE(); |
---|
| 73 | return -1; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | * Now write the value |
---|
| 78 | */ |
---|
| 79 | printf( "Write %d to to bit %d\n", value, bit ); |
---|
| 80 | rtems_set_dout(bit, value); |
---|
| 81 | |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | rtems_shell_cmd_t Shell_MULTIIO_DOUT_Command = { |
---|
| 86 | "multiio_dout", /* name */ |
---|
| 87 | "Write Discrete Outputs", /* usage */ |
---|
| 88 | "multiio", /* topic */ |
---|
| 89 | main_multiio_dout, /* command */ |
---|
| 90 | NULL, /* alias */ |
---|
| 91 | NULL /* next */ |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | rtems_shell_alias_t Shell_MULTIIO_DOUT_Alias = { |
---|
| 95 | "multiio_dout", /* command */ |
---|
| 96 | "dout" /* alias */ |
---|
| 97 | }; |
---|