The escape character is inserted at the end in the function for sending binary data, which is used in the function for receiving binary data to interrupt reading.
Since binary data can spread across the value range of a byte, there is no wise choice for escapeCharacter.
It seems to me that it is better to leave escapeCharacter only in send and receive functions for strings and remove it from functions for binary data:
diff --git a/src/E220.cpp b/src/E220.cpp
index 11b3497..5d06406 100644
--- a/src/E220.cpp
+++ b/src/E220.cpp
@@ -1008,7 +1008,6 @@ bool E220::sendTransparentData(uint8_t *data, int size) {
for(int i = 0; i < size; i++){
_streamSerial->write(data[i]);
}
- _streamSerial->write(escapeCharacter);
_streamSerial->flush();
return true;
}
@@ -1096,13 +1095,12 @@ bool E220::sendFixedData(unsigned int address, int channel, uint8_t *data, int s
delay(10);
}
}
- uint8_t message[size+4];
+ uint8_t message[size+3];
message[0] = highByte(address);
message[1] = lowByte(address);
message[2] = (uint8_t) channel;
memcpy(&message[3],data,size);
- message[size+3] = escapeCharacter;
- _streamSerial->write(message,size+4);
+ _streamSerial->write(message,size+3);
_streamSerial->flush();
return true;
}
@@ -1128,7 +1126,7 @@ String E220::receiveData() {
*/
bool E220::receiveData(uint8_t *data, int size) {
if(_streamSerial->available()){
- _streamSerial->readBytesUntil(escapeCharacter,data,size);
+ _streamSerial->readBytes(data,size);
return true;
}
else{