Hey,
Thanks for the suggestion!
I am using a file system to process my data, and I’ve already implemented a method similar to what you suggested. However, I’m still facing an issue where certain unwanted patterns, such as +HTTPREAD:, remain uncleaned from the data.
Here’s the code I’m currently using:
const char *unwantedPatterns[] = {
"OK",
"AT+HTTPREAD=0,1024",
"+HTTPREAD: 1024",
"+HTTPREAD: 0",
"+HTTPREAD: 268"
"+HTTPREAD:",
"ERROR",
"PB DONE",
"\n",
"\r",
};
const size_t numPatterns = sizeof(unwantedPatterns) / sizeof(unwantedPatterns[0]);
if (myFile) {
Serial.println("Reading firmware.bin...");
myFile1 = SD.open("cleanFirmware.bin", FILE_WRITE);
if (!myFile1) {
Serial.println("Error opening cleanFirmware.bin");
myFile.close();
return;
}
const size_t bufferSize = 512; // Process in chunks of 512 bytes
uint8_t buffer[bufferSize];
size_t bytesRead;
while ((bytesRead = myFile.read(buffer, bufferSize)) > 0) {
size_t cleanIndex = 0;
for (size_t i = 0; i < bytesRead; i++) {
bool patternMatched = false;
// Check for unwanted patterns
for (size_t j = 0; j < numPatterns; j++) {
size_t patternLength = strlen(unwantedPatterns[j]);
// Ensure the pattern can fit in the remaining buffer
if (i + patternLength <= bytesRead && memcmp(&buffer[i], unwantedPatterns[j], patternLength) == 0) {
i += patternLength - 1; // Skip the pattern
patternMatched = true;
break;
}
}
// If no pattern matched, copy the byte to the clean buffer
if (!patternMatched) {
buffer[cleanIndex++] = buffer[i];
}
}
// Write the cleaned chunk to the output file
myFile1.write(buffer, cleanIndex);
}
}
Here’s an example of the data I received after processing it with this code:
Ñãy¢yeC@+ ÙwçŒ"rCH2ªªç+щ3sC yâx¡xäyH3$Cë @, Ù@ €² ) Ð,ÙxŒBÑ83€² 0 ü÷Tþ Rç+ûÑ‹3sCáxëYqK +Ð0 à ¿ ( ÑAç! 8 ÿ÷Òûèç+æÑŒ"rC2Áç+àÑŒ"rC2»ç+ìÐ+ØÑ‰3sC¡xíK)q +ÐÐ0 à ¿ÌçÀFœ sµeL xbxˆBБBÐ" Ž4 x2xˆBÐ ŠBÑ L à bxŠB ÑJ *Ð! š²1 à ¿ v½¢xŠBúÑ& "H6›² “3 ü÷êý@#2 ( ¡xÿ÷2øëçÀFœ ( Kpµ %04%p J<4p™hškŠšb$x ,Ñ
M‡ >5,p )Ð *Ð{Ò Ð.3xÿ÷;øp½/3ùçô Kpµ L +Ð`{ à ¿ (ÑK!£‡>4 p( ÿ÷Ãÿp½£h¢k›@+ Ù@#/4( J!x›²þ÷ßÿðç ô
+HTTPREAD: 1024
' ´ ðµ(L እh‰° )ÐIº‰²( ðü²"i#}§keCeº8 “ ðmüK “›íeÁ`{@- Ù@% •›ü÷býÚK!£‡ #>40 #pÿ÷zÿ °ð½.4$x (Ñ «"Àþ÷yü #¯) 8 >p{p<q • ðüç烲! 0 šþ÷†ÿàçÀFô ´ : Ã}‚}eCBzzCz CÂzCÑ C˜A@ pGÁ{()Ñ{ É ÷Ð +ôÐ[º›²šB’ARBP íç*)óÑ{ É ïÐæçµ@" !Hþ÷.ü½ÀFô µ@" !Hþ÷$ü½ÀFô sµKy +Ð v½‹y+úÑËyP+÷Ñ*õÙŠxKNp
x –É
As you can see, some patterns like +HTTPREAD: are still present in the data.
Do you have any additional suggestions to refine this process and fully clean the data?
Much appreciated!