@@ -59,15 +59,24 @@ void RapiSender::_commandComplete(int result)
5959}
6060
6161void
62- RapiSender::sendCmd (const char *cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout) {
62+ RapiSender::sendCmd (const char *cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout)
63+ {
64+ String cmd = cmdstr;
65+ return sendCmd (cmd, callback, timeout);
6366}
6467
6568void
66- RapiSender::sendCmd (String &cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout) {
69+ RapiSender::sendCmd (String &cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout)
70+ {
71+ int ret = sendCmdSync (cmdstr, timeout);
72+ callback (ret);
6773}
6874
6975void
70- RapiSender::sendCmd (const __FlashStringHelper *cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout) {
76+ RapiSender::sendCmd (const __FlashStringHelper *cmdstr, RapiCommandCompleteHandler callback, unsigned long timeout)
77+ {
78+ String cmd = cmdstr;
79+ return sendCmd (cmd, callback, timeout);
7180}
7281
7382int
@@ -79,62 +88,163 @@ RapiSender::sendCmdSync(const char *cmdstr, unsigned long timeout) {
7988int
8089RapiSender::sendCmdSync (String &cmd, unsigned long timeout)
8190{
91+ DBUGVAR (cmd);
92+
8293 static char ok[] = " $OK" ;
8394 static char zero[] = " 0" ;
84- static char buf1[16 ];
95+ static char buf1[32 ];
8596
86- if (cmd == " $GE" )
87- {
88- sprintf (buf1, " %ld" , pilot);
89- _tokens[0 ] = ok;
90- _tokens[1 ] = buf1;
91- _tokens[2 ] = zero;
92- _tokenCnt = 3 ;
93- }
94- else if (cmd.startsWith (" $SC" ))
97+ switch (cmd[1 ])
9598 {
96- sscanf (cmd.c_str (), " $SC %ld V" , &pilot);
97- _tokens[0 ] = ok;
98- _tokenCnt = 1 ;
99- }
100- else if (cmd == " $GD" )
101- {
102- _tokens[0 ] = ok;
103- _tokens[1 ] = zero;
104- _tokens[2 ] = zero;
105- _tokens[3 ] = zero;
106- _tokens[4 ] = zero;
107- _tokenCnt = 5 ;
108- }
109- else if (cmd == " $FE" )
110- {
111- state = OPENEVSE_STATE_CHARGING;
112- _tokens[0 ] = ok;
113- _tokenCnt = 1 ;
114- }
115- else if (cmd == " $FD" )
116- {
117- state = OPENEVSE_STATE_DISABLED;
118- _tokens[0 ] = ok;
119- _tokenCnt = 1 ;
120- }
121- else if (cmd == " $FS" )
122- {
123- state = OPENEVSE_STATE_SLEEPING;
124- _tokens[0 ] = ok;
125- _tokenCnt = 1 ;
126- }
127- else if (cmd == " $GG" )
128- {
129- _tokens[0 ] = ok;
130- _tokens[1 ] = zero;
131- _tokenCnt = 2 ;
132- }
133- else
134- {
135- DBUGF (" Unhandled command: %s" , cmd.c_str ());
99+ case ' G' :
100+ switch (cmd[2 ])
101+ {
102+ case ' E' :
103+ {
104+ sprintf (buf1, " %ld" , pilot);
105+ _tokens[0 ] = ok;
106+ _tokens[1 ] = buf1;
107+ _tokens[2 ] = zero;
108+ _tokenCnt = 3 ;
109+ } break ;
110+
111+ case ' D' :
112+ {
113+ _tokens[0 ] = ok;
114+ _tokens[1 ] = zero;
115+ _tokens[2 ] = zero;
116+ _tokens[3 ] = zero;
117+ _tokens[4 ] = zero;
118+ _tokenCnt = 5 ;
119+ } break ;
120+ case ' G' :
121+ {
122+ _tokens[0 ] = ok;
123+ _tokens[1 ] = zero;
124+ _tokenCnt = 2 ;
125+ } break ;
126+ case ' V' :
127+ {
128+ _tokens[0 ] = ok;
129+ _tokens[1 ] = " 1.2.3" ;
130+ _tokens[2 ] = " 1.2.3" ;
131+ _tokenCnt = 3 ;
132+ } break ;
133+ case ' F' :
134+ {
135+ _tokens[0 ] = ok;
136+ _tokens[1 ] = zero;
137+ _tokens[2 ] = zero;
138+ _tokens[3 ] = zero;
139+ _tokenCnt = 4 ;
140+ } break ;
141+ case ' C' :
142+ {
143+ sprintf (buf1, " %ld" , pilot);
144+ _tokens[0 ] = ok;
145+ _tokens[1 ] = " 6" ;
146+ _tokens[2 ] = " 32" ;
147+ _tokens[3 ] = buf1;
148+ _tokens[4 ] = " 32" ;
149+ _tokenCnt = 5 ;
150+ } break ;
151+ case ' A' :
152+ {
153+ _tokens[0 ] = ok;
154+ _tokens[1 ] = " 220" ;
155+ _tokens[2 ] = zero;
156+ _tokenCnt = 3 ;
157+ } break ;
158+ case ' I' :
159+ {
160+ _tokens[0 ] = ok;
161+ _tokens[1 ] = " Y57414FF020F0C" ;
162+ _tokenCnt = 2 ;
163+ } break ;
164+ case ' S' :
165+ {
166+ char *ptr = buf1;
167+
168+ _tokens[0 ] = ok;
169+ _tokens[1 ] = ptr;
170+ ptr += sprintf (ptr, " %ld" , state) + 1 ;
171+ _tokens[2 ] = zero;
172+ _tokens[3 ] = ptr;
173+ ptr += sprintf (ptr, " %ld" , state) + 1 ; // Should not reflect the Sleep/Disabled state
174+ _tokens[4 ] = zero;
175+ _tokenCnt = 5 ;
176+ } break ;
177+ case ' P' :
178+ {
179+ _tokens[0 ] = ok;
180+ _tokens[1 ] = " 200" ;
181+ _tokens[2 ] = " -2560" ;
182+ _tokens[3 ] = " -2560" ;
183+ _tokenCnt = 4 ;
184+ } break ;
185+
186+ default :
187+ DBUGF (" Unhandled get command: %s" , cmd.c_str ());
188+ return RAPI_RESPONSE_NK;
189+ } break ;
190+
191+ case ' S' :
192+ switch (cmd[2 ])
193+ {
194+ case ' C' :
195+ {
196+ sscanf (cmd.c_str (), " $SC %ld V" , &pilot);
197+ _tokens[0 ] = ok;
198+ _tokenCnt = 1 ;
199+ } break ;
200+ case ' Y' :
201+ {
202+ _tokens[0 ] = ok;
203+ _tokenCnt = 1 ;
204+ } break ;
205+ case ' B' :
206+ {
207+ _tokens[0 ] = ok;
208+ _tokenCnt = 1 ;
209+ } break ;
210+
211+ default :
212+ DBUGF (" Unhandled set command: %s" , cmd.c_str ());
213+ return RAPI_RESPONSE_NK;
214+ } break ;
215+
216+ case ' F' :
217+ switch (cmd[2 ])
218+ {
219+ case ' E' :
220+ {
221+ state = OPENEVSE_STATE_CHARGING;
222+ _tokens[0 ] = ok;
223+ _tokenCnt = 1 ;
224+ } break ;
225+ case ' D' :
226+ {
227+ state = OPENEVSE_STATE_DISABLED;
228+ _tokens[0 ] = ok;
229+ _tokenCnt = 1 ;
230+ } break ;
231+ case ' S' :
232+ {
233+ state = OPENEVSE_STATE_SLEEPING;
234+ _tokens[0 ] = ok;
235+ _tokenCnt = 1 ;
236+ } break ;
237+
238+ default :
239+ DBUGF (" Unhandled function command: %s" , cmd.c_str ());
240+ return RAPI_RESPONSE_NK;
241+ } break ;
242+
243+ default :
244+ break ;
136245 }
137246
247+
138248 return RAPI_RESPONSE_OK;
139249}
140250
0 commit comments