]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_mout.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_mout.c
1 /*
2  * Copyright (C) 2012-2013, 2016 Czech Technical University in Prague
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use,
8  * copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * File : cmd_mout.c
26  *
27  * Abstract:
28  *      This file contains commands for testing MOUT
29  *
30  */
31
32
33 #include "cmd_mout.h"
34 #include "stdio.h"
35
36 #ifndef DOCGEN
37
38 #include "rpp/rpp.h"
39 #include "cmdproc_utils.h"
40
41 int cmd_do_mout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
42 {
43         int pin;
44         char *p = param[1];
45         char spareParams[2];
46         int val;
47         int ret;
48
49         if (sscanf(p, "%d %d %1s", &pin, &val, spareParams) != 2)
50                 return -CMDERR_BADPAR;
51         ret = rpp_mout_set(pin, val);
52         if (ret == -1) {
53                 rpp_sci_printf("Pin out of range.\n");
54                 return -CMDERR_BADPAR;
55         }
56
57         if (ret != SUCCESS) {
58                 rpp_sci_printf("MOUT set failed.\n");
59                 return -CMDERR_EIO;
60         }
61
62         return cmd_opchar_replong(cmd_io, param, val, 0, 10);
63 }
64
65 int cmd_do_mout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
66 {
67         int pin;
68         char *p = param[1];
69         char spareParams[2];
70         int ret;
71
72         if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
73                 return -CMDERR_BADPAR;
74
75         ret = rpp_mout_diag(pin);
76         if (ret < 0) {
77                 rpp_sci_printf("Pin out of range.\n");
78                 return -CMDERR_BADPAR;
79         }
80
81         rpp_sci_printf("moutdiag%d=%d\n", pin, ret);
82         return 0;
83 }
84
85 #endif  /* DOCGEN */
86
87 /** Command descriptor for mout set port value */
88 cmd_des_t const cmd_des_mout_set = {
89         0, 0,
90         "moutset*","Set a value of the MOUT pin",
91         "### Command syntax ###\n"
92         "\n"
93         "    moutset<PIN> <VALUE>\n"
94         "where\n"
95         "\n"
96         "- `<PIN>` is a number in range 1-6\n"
97         "- `<VALUE>` is a binary value to be set (0 or 1)\n"
98         "\n"
99         "### Description ###\n"
100         "\n"
101         "The command sets the digital value on the MOUT pin.\n"
102         "\n"
103         "### Example ###\n"
104         "\n"
105         "    --> moutset1 1\n"
106         "    moutset1 =1\n"
107         "\n"
108         "Sets MOUT1 to 1.\n"
109         "\n"
110         "    --> moutset2 0\n"
111         "    moutset2 =0\n"
112         "\n"
113         "Sets MOUT2 to 0.\n",
114         CMD_HANDLER(cmd_do_mout_set), (void *)&cmd_list_mout
115 };
116
117 /** Command descriptor for mout get pin diag value */
118 cmd_des_t const cmd_des_mout_diag = {
119         0, 0,
120         "moutdiag*","Read a diagnostic value from an MOUT pin",
121         "### Command syntax ###\n"
122         "\n"
123         "    moutdiag<PIN>\n"
124         "\n"
125         "where `<PIN>` is a number in range 1-8\n"
126         "\n"
127         "### Description ###\n"
128         "\n"
129         "The command reads a logical value of the MOUT diagnostic signal.\n"
130         "\n"
131         "### Example ###\n"
132         "\n"
133         "    --> moutdiag1\n"
134         "\n"
135         "Reads value of the MOUT1 diagnostic signal.\n",
136         CMD_HANDLER(cmd_do_mout_diag), (void *)&cmd_list_mout
137 };
138
139
140 /** List of commands for hout, defined as external */
141 cmd_des_t const *cmd_list_mout[] = {
142         &cmd_des_mout_set,
143         &cmd_des_mout_diag,
144         NULL
145 };