Automatic commit. Fri Aug 10 00:00:03 WST 2012
[matches/honours.git] / research / TCS / apparatus / source_code / parser.c
1 #include "parser.h"\r
2 \r
3 /*\r
4  * @file parser.c\r
5  * @author Sam Moore\r
6  * @purpose Implementation of parsing function\r
7  */\r
8 \r
9 #include <string.h>\r
10 \r
11 #include "usart.h"\r
12 #include "commands.h" // The parsing function calls the required command\r
13 #include "LCD_functions.h"\r
14 \r
15 \r
16 \r
17 \r
18 uint8 ParseCommand()\r
19 {\r
20         //return 0;\r
21         \r
22         USART_Tx('#');\r
23         char c = USART_Rx();\r
24         //LCD_puts("input");\r
25         char arg[MAX_TOKEN_SIZE];\r
26         USART_Tx(c);\r
27 \r
28         uint8 i = 0;\r
29         do\r
30         {\r
31                 arg[i] = USART_Rx();\r
32                 USART_Tx(arg[i]);\r
33                 switch (arg[i])\r
34                 {\r
35                         case ' ':\r
36                                 break;\r
37                         case ';':\r
38                         case '\r':\r
39                         case '\n':\r
40                                 arg[i] = '\0';\r
41                         default:\r
42                                 ++i;\r
43                                 break;\r
44                 }\r
45                 \r
46         }\r
47         while ((arg[i-1] != '\0') && (i < MAX_TOKEN_SIZE));\r
48         USART_printf("\r\n");\r
49         if (arg[i-1] != '\0')\r
50         {\r
51                 LCD_puts("?");\r
52                 USART_printf("?\r\n");\r
53                 return 255;\r
54         }\r
55 \r
56         arg[i] = '\0';\r
57         \r
58 \r
59         command funct = NULL;\r
60                 \r
61         switch (c)\r
62         {\r
63                 case '\r':\r
64                 case 'r':\r
65                         funct = &read_adc;\r
66                         break;\r
67                 case 'p':\r
68                         funct = &poll_adc;\r
69                         break;\r
70                 case 'd':\r
71                         funct = &set_dac;\r
72                         break;\r
73                 case 't':\r
74                         funct = &set_timeout;\r
75                         break;\r
76                 case 'w':\r
77                         funct = &set_delay;\r
78                         break;\r
79                 case 'a':\r
80                         funct = &set_averages;\r
81                         break;\r
82                 case '!':\r
83                         funct = &reset;\r
84                         break;\r
85                 default:\r
86                         break;\r
87         }\r
88 \r
89         if (funct == NULL || funct(arg) != 0)\r
90         {\r
91                 LCD_puts("?");\r
92                 USART_printf("?\r\n");\r
93                 return 254;\r
94         }\r
95         return 0;\r
96 }\r

UCC git Repository :: git.ucc.asn.au