-
Notifications
You must be signed in to change notification settings - Fork 2
/
Parse_Command.c
163 lines (147 loc) · 3.9 KB
/
Parse_Command.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Parse_Command.c
*
* Created on: Jul 4, 2014
* Author: Nate
*/
/*
This file is part of MSP430 DAC.
MSP430 DAC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MSP430 DAC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MSP430 DAC. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Parse_Command.h"
#define PTR_SIZE uint16_t
const char * AT= "AT+";
const char * AT_READ_DIGITAL="READ_DIGITAL";
const char * AT_SET_OUTPUT = "SET_OUTPUT";
const char * AT_DEFINE_GPIO = "DEFINE_GPIO";
const char * AT_ACK = "ACK";
const char * AT_GET_ADC="GET_ADC";
const char * AT_PORT_1 =",PORT1";
const char * AT_PORT_2 =",PORT2";
const char * AT_PORT_3 =",PORT3";
const char * AT_PWM ="PWM";
const char * AT_SPI_CONFIG = "SPI_CONFIG";
const char * AT_SPI_SEND = "SPI_SEND";
const char * AT_INVALID = "\r\nInvalid Message\r\n";
//Checks for the string "AT+" and returns the pointer to the location past this if it is included in the string
char outputTextBuffer[30];
char * Check_For_AT(char * Input_String)
{
char * returnVal;
returnVal = strstr((const char *)Input_String,AT);
if(returnVal)
{
returnVal +=strlen(AT);
}
return returnVal;
}
// This function gets the AT command from a string of "AT+"
char * Get_AT_Command(char * Input_String,AT_COMMANDS *AT_COMMAND)
{
*AT_COMMAND = NO_COMMAND;
char * returnVal = 0;
returnVal =strstr((const char *)Input_String,AT_READ_DIGITAL);
if(returnVal)
{
*AT_COMMAND = READ_DIGITAL_INPUTS;
returnVal+=strlen(AT_READ_DIGITAL);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_SET_OUTPUT);
if(returnVal)
{
*AT_COMMAND = SET_GPIO_OUTPUT;
returnVal+=strlen(AT_SET_OUTPUT);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_GET_ADC);
if(returnVal)
{
*AT_COMMAND = READ_ADC;
returnVal+=strlen(AT_GET_ADC);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_DEFINE_GPIO);
if(returnVal)
{
*AT_COMMAND = DEFINE_GPIO;
returnVal+=strlen(AT_DEFINE_GPIO);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_ACK);
if(returnVal)
{
*AT_COMMAND = ACK;
returnVal+=strlen(AT_ACK);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_PWM);
if(returnVal)
{
*AT_COMMAND = SET_PWM;
returnVal+=strlen(AT_PWM);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_SPI_CONFIG);
if(returnVal)
{
*AT_COMMAND =CONFIG_SPI;
returnVal+=strlen(AT_SPI_CONFIG);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_SPI_SEND);
if(returnVal)
{
*AT_COMMAND = SEND_SPI;
returnVal+=strlen(AT_SPI_SEND);
return returnVal;
}
return returnVal;
}
char * AT_Get_Port(char * Input_String, GPIO_PORTS * GPIO_PORT)
{
char * returnVal = 0;
returnVal =strstr((const char *)Input_String,AT_PORT_1);
if(returnVal)
{
*GPIO_PORT = GPIO_PORT1;
returnVal+=strlen(AT_PORT_1);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_PORT_2);
if(returnVal)
{
*GPIO_PORT = GPIO_PORT2;
returnVal+=strlen(AT_PORT_1);
return returnVal;
}
returnVal = strstr((const char *)Input_String,AT_PORT_3);
if(returnVal)
{
*GPIO_PORT = GPIO_PORT3;
returnVal+=strlen(AT_PORT_1);
return returnVal;
}
return returnVal;
}
char * Get_Hex_Value(char * Input_String,uint16_t * Hex_Value)
{
char * returnVal;
char * tempPtr;
tempPtr=Input_String;
if(tempPtr[0]==',')
{
tempPtr++;
}
*Hex_Value = (uint16_t)strtoul((const char *)tempPtr,&returnVal,16);
return returnVal;
}