]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - source/commands.c
a5340c9d980c4cbdb12f6439c063b800fa59a3d7
[pes-rpp/rpp-test-sw.git] / source / commands.c
1 /*
2  * commands.c
3  *
4  *  Created on: 31.7.2012
5  *      Author: Michal Horn
6  *
7  *  Definition of commands for cmdProc library. Command are stored as lists.
8  *
9  */
10
11 #include "cmd_proc.h"
12 #include "sys_common.h"
13 #include "cmdio_tisci.h"
14 #include "string.h"
15 #include "stdio.h"
16
17 cmd_des_t const **cmd_list;
18
19 /* ------------------------------
20  * User defined command functions
21  * ------------------------------
22  */
23 int cmd_do_testopchar(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
24 {
25   int opchar;
26
27   opchar=cmd_opchar_check(cmd_io,des,param);
28   if(opchar<0) return opchar;
29   char str[] = {"\r\ncmd_do_testopchar called\r\nparam[0]="};
30
31   print((uint8_t *)str);
32   print((uint8_t *)param[0]);
33   print((uint8_t *)"\r\nparam[1]=");
34   print((uint8_t *)param[1]);
35   print((uint8_t *)"\r\nparam[2]=");
36   print((uint8_t *)param[2]);
37   print((uint8_t *)"\r\nparam[3]=");
38   print((uint8_t *)param[3]);
39   print((uint8_t *)"\r\nopchar=");
40   char opcharBuf[4];
41   i2str(opcharBuf, opchar, 1, 10);
42   print((uint8_t *)opcharBuf);
43   print((uint8_t *)"\r\n");
44   return 0;
45 }
46
47 int cmd_do_testparam(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
48 {
49
50           char str[] = {"cmd_do_testparam called\r\nparam[0]="};
51
52           print((uint8_t *)str);
53           print((uint8_t *)param[0]);
54           print((uint8_t *)"\r\nparam[1]=");
55           print((uint8_t *)param[1]);
56           print((uint8_t *)"\r\nparam[2]=");
57           print((uint8_t *)param[2]);
58           print((uint8_t *)"\r\n");
59
60           return 0;
61 }
62
63 int cmd_do_testerror(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
64 {
65   return -1234;
66 }
67
68 int cmd_do_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
69 {
70         char str[] = {"This is the simplest command\r\n"};
71         print((uint8_t *)str);
72
73         return 0;
74 }
75
76 int cmd_do_testcmdio(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
77 {
78     cmd_io_puts(cmd_io, "The first line of text\r\n");
79     cmd_io_puts(cmd_io, "The second line of text\r\n");
80     char str[1000];
81     int i;
82     for (i = 0; i < 1000; i++) {
83         str[i] = 'q';
84     }
85     str[999]='\0';
86     print((uint8_t *)str);
87     /* Only ED_LINE_CHARS character can be sent. */
88     return 0;
89 }
90
91
92 /* ------------------------------
93  * User defined command variables
94  * ------------------------------
95  */
96 int val;
97
98 /* -------------------
99  * Command definitions
100  * -------------------
101  */
102 cmd_des_t const cmd_des_help={
103     0, 0,
104     "HELP","prints help for commands\r\n",
105     cmd_do_help, (void *)&cmd_list
106 };
107
108 cmd_des_t const cmd_des_val={
109     0, CDESM_OPCHR|CDESM_RW,
110     "VAL","use ':' or '?' to store/read value of an integer variable",
111     cmd_do_rw_int,  (void *)&val};
112
113 cmd_des_t const cmd_des_valro={
114     0, CDESM_OPCHR|CDESM_RD,
115     "VALRO","read only access to an integer variable",
116     cmd_do_rw_int, (void *)&val};
117
118 cmd_des_t const cmd_des_valwo={
119     0, CDESM_OPCHR|CDESM_WR,
120     "VALWO","write only access to an integer variable",
121     cmd_do_rw_int, (void *)&val};
122
123 cmd_des_t const cmd_des_opchar_test={
124     0, CDESM_OPCHR|CDESM_RW,
125     "OPCHAR","opchar test (use ':' or '?' as suffix)",
126     cmd_do_testopchar};
127
128 cmd_des_t const cmd_des_testio={
129     0, 0,
130     "TESTIO","test of cmd_io inside functions (universal way to print results)",
131     cmd_do_testcmdio};
132
133 cmd_des_t const cmd_des_error={
134     0, 0,
135     "TESTERROR","should produce an error",
136     cmd_do_testerror};
137
138 cmd_des_t const cmd_des_param={
139     0, 0,
140     "PARAM","test of parameters",
141     cmd_do_testparam};
142
143 cmd_des_t const cmd_des_opchar_testro={
144     0, CDESM_OPCHR|CDESM_RD,
145     "OPCHARRO","opchar test (only '?' is allowed)",
146     cmd_do_testopchar};
147
148 cmd_des_t const cmd_des_test={
149     0, 0,
150     "TEST","the simplest command",
151     cmd_do_test};
152
153 cmd_des_t const cmd_des_prefix={
154     0, 0,
155     "PREFIX*","suffix of the command is supplied as a parametr",
156     cmd_do_testparam};
157
158 cmd_des_t const cmd_des_num={
159     0, 0,
160     "NUM##","suffix of the command (two digits) is supplied as a parametr",
161     cmd_do_testparam};
162
163 cmd_des_t const cmd_des_char={
164     0, 0,
165     "CHAR?","suffix of the command (one character) is supplied as a parametr",
166     cmd_do_testparam};
167
168 cmd_des_t const cmd_des_charmid={
169     0, 0,
170     "CHAR?MID","middle character of the command is supplied as a parametr",
171     cmd_do_testparam};
172
173 cmd_des_t const cmd_des_hiddedn={
174     0, 0,
175     "HIDDEN","should not be available",
176     cmd_do_test};
177
178 /*  ------------------------
179  *  Command lists definitons
180  *  ------------------------
181  */
182 cmd_des_t const *cmd_list_1[]={
183     &cmd_des_val,
184     &cmd_des_valro,
185     &cmd_des_valwo,
186     &cmd_des_opchar_test,
187     &cmd_des_opchar_testro,
188     NULL
189     };
190
191 cmd_des_t const *cmd_list_2[]={
192     &cmd_des_test,
193     &cmd_des_testio,
194     &cmd_des_param,
195     &cmd_des_prefix,
196     &cmd_des_num,
197     &cmd_des_char,
198     &cmd_des_charmid,
199     NULL
200     };
201
202 cmd_des_t const *cmd_list_main[]={
203   &cmd_des_help,
204   &cmd_des_error,
205   CMD_DES_INCLUDE_SUBLIST(cmd_list_1),
206   CMD_DES_CONTINUE_AT(cmd_list_2),
207   &cmd_des_hiddedn,
208   NULL
209 };
210
211 cmd_des_t const **cmd_list = cmd_list_main;