]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
Update library
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_lout.c
1 /*
2  * Copyright (C) 2012-2013 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;
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.");
51                 return -CMDERR_BADPAR;
52         }
53
54         if (rpp_lout_update() == FAILURE) {
55                 rpp_sci_printf("LOUT update failed.");
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;
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.");
82                 return -CMDERR_EIO;
83         }
84
85         ret = rpp_lout_diag(pin);
86         if (ret == -1) {
87                 rpp_sci_printf("Pin out of range.");
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         "\n"
117         "Sets LOUT1 to 1.\n"
118         "\n"
119         "    --> loutset2 0\n"
120         "\n"
121         "Sets LOUT2 to 0.\n",
122         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
123 };
124
125 /** Command descriptor for lout get pin diag value */
126 cmd_des_t const cmd_des_lout_diag = {
127         0, 0,
128         "loutdiag*","Read a diagnostic value from an LOUT pin",
129         "### Command syntax ###\n"
130         "\n"
131         "    loutdiag<PIN>\n"
132         "\n"
133         "where `<PIN>` is a number in range 1-8\n"
134         "\n"
135         "### Description ###\n"
136         "\n"
137         "The command reads a logical value of the LOUT diagnostic signal.\n"
138         "\n"
139         "### Example ###\n"
140         "\n"
141         "    --> loutdiag1\n"
142         "\n"
143         "Reads value of the LOUT1 diagnostic signal.\n",
144         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
145 };
146
147
148 /** List of commands for hout, defined as external */
149 cmd_des_t const *cmd_list_lout[] = {
150         &cmd_des_lout_set,
151         &cmd_des_lout_diag,
152         NULL
153 };