MCPcopy Create free account
hub / github.com/SmingHub/Sming / processor

Method processor

Sming/Libraries/AtClient/src/AtClient.cpp:24–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24void AtClient::processor(Stream& source, char arrivedChar, uint16_t availableCharsCount)
25{
26 if(!currentCommand.text.length()) {
27 return;
28 }
29
30 if(state == State::Error) {
31 // discard input at error state
32 return;
33 }
34
35 if(currentCommand.onReceive) {
36 if(currentCommand.onReceive(*this, source)) {
37 next();
38 }
39 return;
40 }
41
42 if(arrivedChar != '\n') {
43 return;
44 }
45
46 commandTimer.stop();
47 debug_d("Processing: %d ms, %s", millis(), currentCommand.text.substring(0, 20).c_str());
48
49 char response[availableCharsCount];
50 for(int i = 0; i < availableCharsCount; i++) {
51 response[i] = stream.read();
52 if(response[i] == '\r' || response[i] == '\n') {
53 response[i] = '\0';
54 }
55 }
56
57 debug_d("Got response: %s", response);
58
59 String reply(response);
60 if(reply.indexOf(AT_REPLY_OK) + reply.indexOf(currentCommand.response2) == -2) {
61 // we did not get what we wanted. Check if we should repeat.
62 if(--currentCommand.retries > 0) {
63 sendDirect(currentCommand);
64 return;
65 }
66
67 if(currentCommand.breakOnError) {
68 state = State::Error;
69 return;
70 }
71 }
72
73 if(currentCommand.onComplete) {
74 if(!currentCommand.onComplete(*this, reply)) {
75 return;
76 }
77 }
78
79 next();
80}
81

Callers

nothing calls this directly

Calls 8

millisFunction · 0.85
lengthMethod · 0.45
onReceiveMethod · 0.45
stopMethod · 0.45
c_strMethod · 0.45
substringMethod · 0.45
readMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected