?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 MRF24WB0M Driver Console Messages
4 Module for Microchip TCP/IP Stack
5 -Provides access to MRF24WB0M WiFi controller
6 -Reference: MRF24WB0M Data sheet, IEEE 802.11 Standard
7  
8 *******************************************************************************
9 FileName: WFConsoleMsgs.c
10 Dependencies: TCP/IP Stack header files
11 Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
12 Compiler: Microchip C32 v1.10b or higher
13 Microchip C30 v3.22 or higher
14 Microchip C18 v3.34 or higher
15 Company: Microchip Technology, Inc.
16  
17 Software License Agreement
18  
19 Copyright (C) 2002-2010 Microchip Technology Inc. All rights reserved.
20  
21 Microchip licenses to you the right to use, modify, copy, and distribute:
22 (i) the Software when embedded on a Microchip microcontroller or digital
23 signal controller product ("Device") which is integrated into
24 Licensee's product; or
25 (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
26 ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device used in
27 conjunction with a Microchip ethernet controller for the sole purpose
28 of interfacing with the ethernet controller.
29  
30 You should refer to the license agreement accompanying this Software for
31 additional information regarding your rights and obligations.
32  
33 THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
34 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
35 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
36 NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL,
37 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST
38 OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS BY
39 THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS
40 FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON
41 THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR
42 OTHERWISE.
43  
44  
45 Author Date Comment
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 KH 27 Jan 2010 Updated for MRF24WB0M
48 ******************************************************************************/
49  
50 #include <string.h>
51 #include <ctype.h>
52  
53 #include "TCPIP Stack/TCPIP.h"
54 #include "TCPIP Stack/WFConsole.h"
55  
56 #if defined ( WF_CONSOLE )
57  
58 //---------------------
59 // token parsing states
60 //---------------------
61 enum
62 {
63 kWFWaitingForStartOfToken,
64 kWFWaitingForEndOfToken
65 };
66  
67 //----------------
68 // Command strings
69 //----------------
70 ROM INT8 helpCmd[] = "help";
71 ROM INT8 helpHelp[] = "Lists all commands";
72  
73 ROM INT8 getwfverCmd[] = "getwfver";
74 ROM INT8 getwfverHelp[] = "Gets WiFi device version";
75  
76 ROM INT8 resetCmd[] = "reset";
77 ROM INT8 resetHelp[] = "Reset host MCU";
78  
79 ROM INT8 clsCmd[] = "cls";
80 ROM INT8 clsHelp[] = "Clears screen";
81  
82 #if defined(WF_CONSOLE_IFCFGUTIL)
83 ROM INT8 ifConfigCmd[] = "ifconfig";
84 ROM INT8 iwConfigCmd[] = "iwconfig";
85 ROM INT8 iwPrivCmd[] = "iwpriv";
86 #endif // WF_CONSOLE_IFCFGUTIL
87  
88 ROM INT8 seeDocHelp[] = "see documentation";
89  
90  
91 //----------------------
92 // Console Command Table
93 //-----------------------
94 const tWFCmd g_consoleCmd[] = {
95  
96 {helpCmd, // cmd name
97 helpHelp, // cmd description
98 2}, // max tokens
99  
100 {getwfverCmd, // [1]
101 getwfverHelp,
102 1},
103  
104 {resetCmd, // [2]
105 resetHelp,
106 1},
107  
108 {clsCmd, // [3]
109 clsHelp,
110 1},
111 #if defined(WF_CONSOLE_IFCFGUTIL)
112 {ifConfigCmd, // [4]
113 seeDocHelp,
114 12},
115  
116 {iwConfigCmd, // [5]
117 seeDocHelp,
118 12},
119  
120 {iwPrivCmd, // [6]
121 seeDocHelp,
122 12}
123 #endif // WF_CONSOLE_IFCFGUTIL
124 };
125  
126 const UINT8 g_numCmds = sizeof(g_consoleCmd) / sizeof(tWFCmd);
127  
128  
129 /*****************************************************************************
130 * FUNCTION: TokenizeCmdLine
131 *
132 * RETURNS: None
133 *
134 * PARAMS: p_line -- pointer to the null terminated command line
135 *
136 * NOTES: Converts the input string into tokens separated by '\0'.
137 *****************************************************************************/
138 void TokenizeCmdLine(INT8 *p_line)
139 {
140 UINT8 state = kWFWaitingForStartOfToken;
141 UINT8 index = 0;
142  
143 ARGC = 0;
144  
145 //---------------------------
146 // while not at end of string
147 //---------------------------
148 while (p_line[index] != (INT8)'\0')
149 {
150  
151 //----------------------------------------
152 if (state == (UINT8)kWFWaitingForStartOfToken)
153 //----------------------------------------
154 {
155 // if hit non whitespace
156 if (!isspace((int)p_line[index]))
157 {
158 // argument string starts here
159 ARGV[ARGC++] = (INT8 *)(&(p_line[index]));
160 if (ARGC >= (UINT8)kWFMaxTokensPerCmd)
161 {
162 return; // truncate because too many tokens
163 }
164 state = kWFWaitingForEndOfToken;
165 }
166 ++index;
167  
168 }
169 //----------------------------------------
170 else if (state == (UINT8)kWFWaitingForEndOfToken)
171 //----------------------------------------
172 {
173 // if white space, then end of token
174 if (isspace((int)p_line[index]))
175 {
176 // string terminate the token
177 p_line[index] = '\0';
178 state = kWFWaitingForStartOfToken;
179 }
180 ++index;
181 }
182 }
183 }
184  
185  
186 /*****************************************************************************
187 * FUNCTION: GetCmdId
188 *
189 * RETURNS: None
190 *
191 * PARAMS: void
192 *
193 * NOTES: Determines index of cmd in CMD struct
194 *****************************************************************************/
195 UINT8 GetCmdId(void)
196 {
197 UINT8 i;
198 const tWFCmd *p_msgList;
199 UINT16 msgCount;
200  
201 p_msgList = g_consoleCmd;
202 msgCount = g_numCmds;
203  
204 for (i = 0; i < msgCount; ++i)
205 {
206 if ( strcmppgm2ram( (FAR char *)ARGV[0], (FAR ROM char *) p_msgList[i].p_cmdName) == 0)
207 {
208 return i;
209 }
210 }
211  
212 return INVALID_CMD;
213 }
214  
215  
216  
217 /*****************************************************************************
218 * FUNCTION: ConvertASCIIHexToBinary
219 *
220 * RETURNS: TRUE if conversion successful, else FALSE
221 *
222 * PARAMS: p_ascii -- ascii string to be converted
223 * p_binary -- binary value if conversion successful
224 *
225 * NOTES: Converts an input ascii hex string to binary value (up to 32-bit value)
226 *****************************************************************************/
227 BOOL ConvertASCIIHexToBinary(INT8 *p_ascii, UINT16 *p_binary)
228 {
229 INT8 i;
230 UINT32 multiplier = 1;
231  
232 *p_binary = 0;
233  
234 // not allowed to have a string of more than 4 nibbles
235 if (strlen((char*)p_ascii) > 8u)
236 {
237 return FALSE;
238 }
239  
240 // first, ensure all characters are a hex digit
241 for (i = (UINT8)strlen((char *)p_ascii) - 1; i >= 0 ; --i)
242 {
243 if (!isxdigit(p_ascii[i]))
244 {
245 return FALSE;
246 }
247 *p_binary += multiplier * HexToBin(p_ascii[i]);
248 multiplier *= 16;
249 }
250  
251 return TRUE;
252 }
253  
254 /*****************************************************************************
255 * FUNCTION: ConvertASCIIUnsignedDecimalToBinary
256 *
257 * RETURNS: TRUE if conversion successful, else FALSE
258 *
259 * PARAMS: p_ascii -- ascii string to be converted
260 * p_binary -- binary value if conversion successful
261 *
262 * NOTES: Converts an input ascii decimal string to binary value
263 *****************************************************************************/
264 BOOL ConvertASCIIUnsignedDecimalToBinary(INT8 *p_ascii, UINT16 *p_binary)
265 {
266 INT8 i;
267 UINT32 multiplier = 1;
268 INT8 len;
269  
270 *p_binary = 0;
271 len = (INT8)strlen((char *)p_ascii);
272  
273 // should not be any numbers greater than 6 digits
274 if ((len > 5) || (len == 0))
275 {
276 return FALSE;
277 }
278  
279 // first, ensure all characters are a decimal digit
280 for (i = len - 1; i >= 0 ; --i)
281 {
282 if (!isdigit(p_ascii[i]))
283 {
284 return FALSE;
285 }
286 *p_binary += multiplier * (p_ascii[i] - '0');
287 multiplier *= 10;
288 }
289  
290 return TRUE;
291 }
292  
293 /*****************************************************************************
294 * FUNCTION: ConvertASCIISignedDecimalToBinary
295 *
296 * RETURNS: TRUE if conversion successful, else FALSE
297 *
298 * PARAMS: p_ascii -- ascii string to be converted
299 * p_binary -- binary value if conversion successful
300 *
301 * NOTES: Converts an input ascii signed decimal string to binary value
302 *****************************************************************************/
303 BOOL ConvertASCIISignedDecimalToBinary(INT8 *p_ascii, INT16 *p_binary)
304 {
305 INT8 i;
306 UINT32 multiplier = 1;
307 BOOL negFlag = FALSE;
308 INT8 endIndex = 0;
309 INT8 len;
310  
311 *p_binary = 0;
312 len = (INT8)strlen((char *)p_ascii);
313  
314 // should not be any numbers greater than 5 digits (with -)
315 if (len > 6)
316 {
317 return FALSE;
318 }
319  
320 if (p_ascii[0] == (INT8)'-')
321 {
322 negFlag = TRUE;
323 endIndex = 1;
324 }
325  
326  
327 // first, ensure all characters are a decimal digit
328  
329 for (i = len - 1; i >= endIndex ; --i)
330 {
331 if (!isdigit(p_ascii[i]))
332 {
333 return FALSE;
334 }
335 *p_binary += multiplier * (p_ascii[i] - '0');
336 multiplier *= 10;
337 }
338  
339 if (negFlag == TRUE)
340 {
341 *p_binary *= -1;
342 }
343  
344 return TRUE;
345 }
346  
347 /*****************************************************************************
348 * FUNCTION: HexToBin
349 *
350 * RETURNS: binary value associated with ASCII hex input value
351 *
352 * PARAMS: hexChar -- ASCII hex character
353 *
354 * NOTES: Converts an input ascii hex character to its binary value. Function
355 * does not error check; it assumes only hex characters are passed in.
356 *****************************************************************************/
357 UINT8 HexToBin(UINT8 hexChar)
358 {
359 if ((hexChar >= 'a') && (hexChar <= 'f'))
360 {
361 return (0x0a + (hexChar - 'a'));
362 }
363 else if ((hexChar >= 'A') && (hexChar <= 'F'))
364 {
365 return (0x0a + (hexChar - 'A'));
366 }
367 else // ((hexChar >= '0') && (hexChar <= '9'))
368 {
369 return (0x00 + (hexChar - '0'));
370 }
371  
372 }
373  
374 BOOL ExtractandValidateU16Range(INT8 *p_string, UINT16 *pValue, UINT16 minValue, UINT16 maxValue)
375 {
376 /* extract next parameter as an unsigned short integer */
377 if (!ConvertASCIIUnsignedDecimalToBinary(p_string, pValue))
378 {
379 /* WFConsolePrintf(" Unable to parse paramter value"); */
380 return FALSE;
381 }
382  
383 if ((*pValue < minValue) || (*pValue > maxValue))
384 {
385 /* WFConsolePrintf(" parameter value out of range"); */
386 return FALSE;
387 }
388  
389 return TRUE;
390 }
391  
392 #endif /* WF_CONSOLE */
393  
394  
395  
396  
397  
398  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3