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

Function onDataReceived

samples/LiveDebug/app/application.cpp:98–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98void onDataReceived(Stream& source, char arrivedChar, unsigned short availableCharsCount)
99{
100 static LineBuffer<MAX_COMMAND_LENGTH> commandBuffer;
101
102 // Error detection
103 unsigned status = Serial.getStatus();
104 if(status != 0) {
105 Serial.println();
106 if(bitRead(status, eSERS_Overflow)) {
107 Serial.println(_F("** RECEIVE OVERFLOW **"));
108 }
109 if(bitRead(status, eSERS_BreakDetected)) {
110 Serial.println(_F("** BREAK DETECTED **"));
111 }
112 if(bitRead(status, eSERS_FramingError)) {
113 Serial.println(_F("** FRAMING ERROR **"));
114 }
115 if(bitRead(status, eSERS_ParityError)) {
116 Serial.println(_F("** PARITY ERROR **"));
117 }
118 // Discard what is likely to be garbage
119 Serial.clear(SERIAL_RX_ONLY);
120 commandBuffer.clear();
121 showPrompt();
122 return;
123 }
124
125 switch(commandBuffer.process(source, Serial)) {
126 case LineBufferBase::Action::clear:
127 showPrompt();
128 break;
129 case LineBufferBase::Action::submit: {
130 if(commandBuffer) {
131 handleCommand(String(commandBuffer));
132 commandBuffer.clear();
133 }
134 showPrompt();
135 break;
136 }
137 default:
138 break;
139 }
140}
141
142/*
143 * Demonstrate opening and reading a file from the host.

Callers

nothing calls this directly

Calls 7

printlnMethod · 0.80
showPromptFunction · 0.70
handleCommandFunction · 0.70
StringClass · 0.50
getStatusMethod · 0.45
clearMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected