JustPaste.it

Hello, so sorry to bother you. Would you mind quickly helping me out with a problem I have concerning my question on StackExchange (arduino.stackexchange.com/…)?

 

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX, TX

void setup() {
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("Communication with HC-05 successfully started.");
}

const char* BOOK_UPLOAD_START_TAG = "(__BOOK_UPLOAD_START__)";
const char* BOOK_UPLOAD_END_TAG = "(__BOOK_UPLOAD_END__)";
int tag_pos = 0;
char c;
bool is_uploading_book = false;

#define DELAY_SIZE 50
char delay_chars[DELAY_SIZE];
int update_count = 0;

void loop(){
if (BTserial.available()) {
c = BTserial.read();
if (is_uploading_book) {
Serial.write(c);
if(update_count < DELAY_SIZE) {
delay_chars[update_count] = c;
} else {
for (int i = 0; i < (DELAY_SIZE - 1); i++) {
delay_chars[i] = delay_chars[i + 1];
delay_chars[DELAY_SIZE - 1] = c;
}

// Checking if the end tag is in the delay_chars
for (int i = 0; i < (DELAY_SIZE - 1); i++) {
if (check_tag_in_char(delay_chars[i], BOOK_UPLOAD_END_TAG)) {
tag_pos = 0;
Serial.println("Uploaded");
is_uploading_book = false;
}
}
}
update_count++;
} else {
if (check_tag_in_char(c, BOOK_UPLOAD_START_TAG)) {
tag_pos = 0;
Serial.println("Starting");
is_uploading_book = true;
}
}
}

}

int check_tag_in_char(char a, const char* TAG_STR) {
if (a == TAG_STR[tag_pos]) { tag_pos++; } else if (a == TAG_STR[0]) { tag_pos = 1; } else { tag_pos = 0; }
if (TAG_STR[tag_pos] == '\0') {
return true;
} else {
return false;
}
}

 

Most of the code, you are familiar with. The new thing is in the if(is_updating_book) { here } part.
I'm trying to detect the book-uploading-ends tag so I can prevent it from displaying.
In order to do that I use a delay system where it will store the incoming characters in a char array and before "displaying" will check if the tag is found in those characters. I believe my code is right but something weird happens with what my Arduino Uno sees as incoming.

 

Communication with HC-05 successfully started.
Starting
Test document PDF 
 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla est purus, ultrices in porttitor 
in, accus⸮o⸮a⸮a⸮nct⸮oto⸮ou.Cat⸮ue⸮tl⸮eg⸮
crv⸮u⸮om⸮⸮tlu⸮or⸮tatcsu⸮le⸮lu⸮oaess⸮vi⸮pdteea⸮aestp⸮r⸮tdmuaoe⸮⸮iu⸮bo
mr⸮o⸮u⸮ue⸮i⸮g⸮oinmlot.Qseiei⸮pmv⸮mn⸮vr⸮um⸮r⸮ir⸮oseua⸮t⸮eil⸮ui⸮rs⸮.
sbu⸮ls⸮c⸮ci⸮bd⸮au⸮etsi⸮ld⸮es⸮cpuele⸮uaa⸮l.Mca⸮n⸮i⸮icu⸮ndisn,vil⸮⸮u⸮u⸮an⸮fnlamssa. u⸮oi⸮tque petu⸮⸮ai⸮sptitmt,ncu⸮iiu⸮s⸮tcsu⸮lie⸮t⸮nrnsmr⸮ou⸮r.Vau⸮vr⸮uitfi⸮e⸮nmt.C⸮oi⸮aq⸮etu⸮⸮ai⸮sptit
ns⸮serril⸮u⸮ng⸮inmsii⸮il⸮o⸮ub⸮uavua⸮ie⸮u⸮csnoepab⸮e⸮gsd⸮aue⸮oe⸮aerril⸮u naqt⸮m⸮⸮etbeu⸮cs.C⸮oi⸮tu⸮nise⸮gs⸮s
rrn⸮ns⸮st⸮icu⸮s⸮sbl⸮ieiu⸮causp⸮apcga⸮⸮au⸮rsti⸮lnseoi⸮r⸮og⸮ir⸮i⸮e⸮ou⸮Iermt,iu⸮⸮iin⸮md⸮lu⸮c⸮enmet⸮at mol⸮r⸮n ac 
ss⸮⸮ott⸮t⸮⸮ri⸮lii,vi⸮g⸮uitem⸮iu⸮ld⸮aa
c⸮cle⸮uafii.Dse⸮hu⸮r.Nl⸮ci.Men⸮eeeu⸮ottfi⸮u⸮rsq⸮il⸮csv.S⸮e⸮⸮es⸮te⸮g⸮n,slid⸮uaoe⸮tset⸮lu⸮ne.Mb⸮lcunle⸮e⸮g⸮ins⸮t
nct⸮u⸮lp.Nl⸮cii⸮usessvtumnu⸮rstcu.
ocs⸮m⸮uiroi⸮
iu⸮ottprr⸮ndt⸮s⸮ae⸮c,mei⸮e⸮rsees⸮ais⸮⸮r.S⸮tnii⸮e⸮essaqmu⸮⸮l.Ae⸮asd⸮ci⸮i⸮
⸮mr⸮c⸮gt⸮oea⸮a⸮b⸮cs⸮ad⸮d egesa⸮,fgt quis⸮or⸮n⸮ul⸮n,n⸮lrtae⸮r⸮iu⸮mrvpa.⸮als
tcsru⸮lau⸮gt⸮um.Vau⸮ndtpca⸮s⸮⸮lu.Cs
i⸮⸮cnnptmaia⸮ea⸮enmeta⸮t⸮oo⸮hc.
ia⸮l⸮ue⸮oao⸮gtsqs⸮cs⸮ies.Psl⸮dltsot,
e⸮ln⸮ue⸮imetvi⸮⸮usfnl⸮ld.De⸮i⸮i⸮atssd
ci⸮d⸮nct⸮g⸮e⸮oeis⸮ors⸮m,cstu⸮isn⸮i⸮Mca⸮cs⸮eivltp⸮uu⸮⸮ol⸮i⸮let⸮
iu⸮csuacp⸮ets⸮m⸮ors⸮i⸮lu⸮es⸮lteqsrns
c⸮rnmetoo⸮vu⸮lipsum cau⸮des moli⸮io⸮ctl.
u⸮eag⸮uu⸮n⸮mrvil⸮lsp⸮i.⸮⸮letesdqma⸮au⸮e⸮ie⸮crnh⸮rbu⸮luafmt⸮asv⸮ama⸮u⸮oa⸮cesenl⸮cpva⸮ga⸮pss⸮m.I⸮ar⸮uaa⸮t⸮cesupse⸮heu⸮⸮n⸮es⸮dhdrtisa⸮u⸮sr⸮uu⸮Psl⸮uau⸮i⸮o⸮nvtum⸮u⸮ee⸮cmnml⸮ae⸮t
eeds⸮ld⸮t⸮vu⸮csm⸮e⸮r⸮orspat.Psl⸮ttt⸮qm⸮⸮lp⸮pu⸮tmslid⸮r⸮e⸮i⸮bdme⸮pdtru⸮ndt⸮tmetvi⸮oueu⸮ln⸮c⸮nmt⸮g⸮uo⸮ueaetvi⸮im 
imped⸮ure⸮orci ⸮eri _OUO_D_

 

Everything starts fine and then turns into jibberish. I tried doing the delay with a String first but it didn't work. I just tried with a character array, didn't work. I don't know what's going on. I believe I'm "overloading" the Arduino or something like that, because the Serial.write(c); should simply print the incoming characters and has nothing to do with the code but it seems that simply running the code, the whole Arduino gets bugged.
Am I running out of runtime memory? Should I try with another Arduino?