]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
lout: Document command output
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_lout.c
1 /*
2  * Copyright (C) 2012-2013, 2016 Czech Technical University in Prague
3  *
4  * Created on: 28.2.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
9  * This document contains proprietary information belonging to Czech
10  * Technical University in Prague. Passing on and copying of this
11  * document, and communication of its contents is not permitted
12  * without prior written authorization.
13  *
14  * File : cmd_lout.c
15  *
16  * Abstract:
17  *      This file contains commands for testing LOUT (8x100mA Digital output).
18  *
19  */
20
21
22 #include "cmd_lout.h"
23 #include "stdio.h"
24
25 #ifndef DOCGEN
26
27 #include "rpp/rpp.h"
28 #include "cmdproc_utils.h"
29
30 /**
31  * @brief Set digital value to LOUT pin
32  *
33  * @param[in]   cmd_io  Pointer to IO stack
34  * @param[in]   des             Pointer to command descriptor
35  * @param[in]   param   Parameters of command
36  * @return 0 when OK or error code lower than 0
37  */
38 int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
39 {
40         int pin;
41         char *p = param[1];
42         char spareParams[2];
43         int val;
44         int ret;
45
46         if (sscanf(p, "%d %d %1s", &pin, &val, spareParams) != 2)
47                 return -CMDERR_BADPAR;
48         ret = rpp_lout_set(pin, val);
49         if (ret == -1) {
50                 rpp_sci_printf("Pin out of range.\n");
51                 return -CMDERR_BADPAR;
52         }
53
54         if (rpp_lout_update() == FAILURE) {
55                 rpp_sci_printf("LOUT update failed.\n");
56                 return -CMDERR_EIO;
57         }
58
59         return cmd_opchar_replong(cmd_io, param, val, 0, 10);
60 }
61
62 /**
63  * @brief Read digital diagnostic value from LOUT DIAG pin
64  *
65  * @param[in]   cmd_io  Pointer to IO stack
66  * @param[in]   des             Pointer to command descriptor
67  * @param[in]   param   Parameters of command
68  * @return 0 when OK or error code lower than 0
69  */
70 int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
71 {
72         int pin;
73         char *p = param[1];
74         char spareParams[2];
75         int ret;
76
77         if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
78                 return -CMDERR_BADPAR;
79
80         if (rpp_lout_update() == FAILURE) {
81                 rpp_sci_printf("LOUT update failed.\n");
82                 return -CMDERR_EIO;
83         }
84
85         ret = rpp_lout_diag(pin);
86         if (ret == -1) {
87                 rpp_sci_printf("Pin out of range.\n");
88                 return -CMDERR_BADPAR;
89         }
90
91         rpp_sci_printf("loutdiag%d=%d\n", pin, ret, ret);
92         return 0;
93 }
94
95 #endif  /* DOCGEN */
96
97 /** Command descriptor for lout set port value */
98 cmd_des_t const cmd_des_lout_set = {
99         0, 0,
100         "loutset*","Set a value of the LOUT pin",
101         "### Command syntax ###\n"
102         "\n"
103         "    loutset<PIN> <VALUE>\n"
104         "where\n"
105         "\n"
106         "- `<PIN>` is a number in range 1-8\n"
107         "- `<VALUE>` is a binary value to be set (0 or 1)\n"
108         "\n"
109         "### Description ###\n"
110         "\n"
111         "The command sets the digital value on the LOUT pin.\n"
112         "\n"
113         "### Example ###\n"
114         "\n"
115         "    --> loutset1 1\n"
116         "    loutset1 =1\n"
117         "\n"
118         "Sets LOUT1 to 1.\n"
119         "\n"
120         "    --> loutset2 0\n"
121         "    loutset2 =0\n"
122         "\n"
123         "Sets LOUT2 to 0.\n",
124         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
125 };
126
127 /** Command descriptor for lout get pin diag value */
128 cmd_des_t const cmd_des_lout_diag = {
129         0, 0,
130         "loutdiag*","Read a diagnostic value from an LOUT pin",
131         "### Command syntax ###\n"
132         "\n"
133         "    loutdiag<PIN>\n"
134         "\n"
135         "where `<PIN>` is a number in range 1-8\n"
136         "\n"
137         "### Description ###\n"
138         "\n"
139         "The command reads a logical value of the LOUT diagnostic signal.\n"
140         "\n"
141         "### Example ###\n"
142         "\n"
143         "    --> loutdiag1\n"
144         "\n"
145         "Reads value of the LOUT1 diagnostic signal.\n",
146         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
147 };
148
149
150 /** List of commands for hout, defined as external */
151 cmd_des_t const *cmd_list_lout[] = {
152         &cmd_des_lout_set,
153         &cmd_des_lout_diag,
154         NULL
155 };