add trigo file in beacon
[aversive.git] / projects / microb2010 / tests / beacon_tsop / commands.c
1 /*
2  *  Copyright Droids Corporation (2009)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: commands.c,v 1.7 2009-04-24 19:30:41 zer0 Exp $
19  *
20  *  Olivier MATZ <zer0@droids-corp.org> 
21  */
22
23 #include <stdio.h>
24 #include <string.h>
25
26 #include <aversive/pgmspace.h>
27 #include <aversive/wait.h>
28 #include <aversive/error.h>
29
30 #include <pid.h>
31 #include <pwm_ng.h>
32 #include <parse.h>
33 #include <rdline.h>
34 #include <parse_string.h>
35
36 #include "main.h"
37
38 /**********************************************************/
39 /* Reset */
40
41 /* this structure is filled when cmd_reset is parsed successfully */
42 struct cmd_reset_result {
43         fixed_string_t arg0;
44 };
45
46 /* function called when cmd_reset is parsed successfully */
47 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
48                              __attribute__((unused)) void *data)
49 {
50         reset();
51 }
52
53 prog_char str_reset_arg0[] = "reset";
54 parse_pgm_token_string_t cmd_reset_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_reset_result, arg0, str_reset_arg0);
55
56 prog_char help_reset[] = "Reset the board";
57 parse_pgm_inst_t cmd_reset = {
58         .f = cmd_reset_parsed,  /* function to call */
59         .data = NULL,      /* 2nd arg of func */
60         .help_str = help_reset,
61         .tokens = {        /* token list, NULL terminated */
62                 (prog_void *)&cmd_reset_arg0, 
63                 NULL,
64         },
65 };
66
67 /**********************************************************/
68 /* Debug_Frame */
69
70 /* this structure is filled when cmd_debug_frame is parsed successfully */
71 struct cmd_debug_frame_result {
72         fixed_string_t arg0;
73         fixed_string_t arg1;
74 };
75
76 /* function called when cmd_debug_frame is parsed successfully */
77 static void cmd_debug_frame_parsed(void *parsed_result,
78                                    __attribute__((unused)) void *data)
79 {
80         struct cmd_debug_frame_result *res = parsed_result;
81         if (!strcmp_P(res->arg1, PSTR("on")))
82                 beacon_tsop.debug_frame = 1;
83         else
84                 beacon_tsop.debug_frame = 0;
85 }
86
87 prog_char str_debug_frame_arg0[] = "debug_frame";
88 parse_pgm_token_string_t cmd_debug_frame_arg0 =
89         TOKEN_STRING_INITIALIZER(struct cmd_debug_frame_result,
90                                  arg0, str_debug_frame_arg0);
91 prog_char str_debug_frame_arg1[] = "on#off";
92 parse_pgm_token_string_t cmd_debug_frame_arg1 =
93         TOKEN_STRING_INITIALIZER(struct cmd_debug_frame_result,
94                                  arg1, str_debug_frame_arg1);
95
96 prog_char help_debug_frame[] = "Enable frame debug [debug_frame on|off]";
97 parse_pgm_inst_t cmd_debug_frame = {
98         .f = cmd_debug_frame_parsed,  /* function to call */
99         .data = NULL,      /* 2nd arg of func */
100         .help_str = help_debug_frame,
101         .tokens = {        /* token list, NULL terminated */
102                 (prog_void *)&cmd_debug_frame_arg0, 
103                 (prog_void *)&cmd_debug_frame_arg1, 
104                 NULL,
105         },
106 };
107
108 /**********************************************************/
109 /* Debug_Speed */
110
111 /* this structure is filled when cmd_debug_speed is parsed successfully */
112 struct cmd_debug_speed_result {
113         fixed_string_t arg0;
114         fixed_string_t arg1;
115 };
116
117 /* function called when cmd_debug_speed is parsed successfully */
118 static void cmd_debug_speed_parsed(void *parsed_result,
119                                    __attribute__((unused)) void *data)
120 {
121         struct cmd_debug_speed_result *res = parsed_result;
122         if (!strcmp_P(res->arg1, PSTR("on")))
123                 beacon_tsop.debug_speed = 1;
124         else
125                 beacon_tsop.debug_speed = 0;
126 }
127
128 prog_char str_debug_speed_arg0[] = "debug_speed";
129 parse_pgm_token_string_t cmd_debug_speed_arg0 =
130         TOKEN_STRING_INITIALIZER(struct cmd_debug_speed_result,
131                                  arg0, str_debug_speed_arg0);
132 prog_char str_debug_speed_arg1[] = "on#off";
133 parse_pgm_token_string_t cmd_debug_speed_arg1 =
134         TOKEN_STRING_INITIALIZER(struct cmd_debug_speed_result,
135                                  arg1, str_debug_speed_arg1);
136
137 prog_char help_debug_speed[] = "Enable speed debug [debug_speed on|off]";
138 parse_pgm_inst_t cmd_debug_speed = {
139         .f = cmd_debug_speed_parsed,  /* function to call */
140         .data = NULL,      /* 2nd arg of func */
141         .help_str = help_debug_speed,
142         .tokens = {        /* token list, NULL terminated */
143                 (prog_void *)&cmd_debug_speed_arg0, 
144                 (prog_void *)&cmd_debug_speed_arg1, 
145                 NULL,
146         },
147 };
148
149 /**********************************************************/
150 /* Test */
151
152 /* this structure is filled when cmd_test is parsed successfully */
153 struct cmd_test_result {
154         fixed_string_t arg0;
155 };
156
157 /* function called when cmd_test is parsed successfully */
158 static void cmd_test_parsed(__attribute__((unused)) void *parsed_result,
159                              __attribute__((unused)) void *data)
160 {
161
162 }
163
164 prog_char str_test_arg0[] = "test";
165 parse_pgm_token_string_t cmd_test_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_test_result, arg0, str_test_arg0);
166
167 prog_char help_test[] = "Test the board";
168 parse_pgm_inst_t cmd_test = {
169         .f = cmd_test_parsed,  /* function to call */
170         .data = NULL,      /* 2nd arg of func */
171         .help_str = help_test,
172         .tokens = {        /* token list, NULL terminated */
173                 (prog_void *)&cmd_test_arg0, 
174                 NULL,
175         },
176 };
177
178 /**********************************************************/
179
180 /* in progmem */
181 parse_pgm_ctx_t main_ctx[] = {
182
183         /* commands_gen.c */
184         (parse_pgm_inst_t *)&cmd_reset,
185         (parse_pgm_inst_t *)&cmd_debug_frame,
186         (parse_pgm_inst_t *)&cmd_debug_speed,
187         (parse_pgm_inst_t *)&cmd_test,
188         NULL,
189 };