Hi Mikmo,
Thanks for getting back
I've been working on other aspects so haven't experienced the problem again. I'll try and re-create it and test the memory usage as you ask.
There is no load at all on the Arduino, apart from the Ocean Controls Thermocouple Shield - i would doubt this as the cause, but I'll see if I can rule it out.
Can I safely run Gobetwino at baud rates higher than 9600?
Here are the sections of code relating to GBT
// GLOBALS
// globals for tracking processes and reading serial using PCcomm
int GBT_serInLen = SBS;
char GBT_serInString[SBS];
int GBT_pId =0;
char* GBTCommandBase[4]; // 1 + 3 log file types
// logging
GBTCommandBase[INTERVAL_LOG]="IC";
GBTCommandBase[TEMPERATURE_LOG]="TC";
GBTCommandBase[CONTROL_LOG]="CTRLLOG";
void listenForInstruction(char*buf){
// buf must already be null - can safely do a jump return without assigning to itt
char sbuffer[10];
static int instSerial=0;
int returnCode;
buf[0]=NULL; // anticipate failure
returnCode=sendGobetwinoCommand("KILNINST",itoa(instSerial+1,sbuffer,10),INSTRUCTION_HEADER, INSTRUCTION_HEADER_LENGTH, "",0,1000);
// "" means no prescribed "Good" code(ends wait for more reads), 0 is its length, finally milliseconds to respond
// deal with transport level return codes
// TIMEOUTS ARE EXPECTED
if (GBT_serInString[0]==NULL) return;
if (returnCode&B1) alert("Bad before Instr"); // 1st bit shows garbage - warning only
// now deal with GOBETWINO return codes
if ((strcmp(GBT_serInString,"-2")==0) || (strcmp(GBT_serInString,"-3")==0)) return; // gives -3 at end of file, -2 beyond end
if (strcmp(GBT_serInString,"-1")==0) {alert("No Inst file"); return;} // no instruction file
instSerial+=1; // got a valid instruction
strcpy(buf,GBT_serInString); // transfer to applcation level buffer
if (echo) sendKDmsg("EC", GBT_serInString,CONTROL_LOG,NA); // NB original instruction geets overwitten here
return;
}
//Mikko - following is a little complicated, and tailored to my applcation
// a lot of the logic concerned with checking for incoming GOOD strings, but essentially
// it is a sequence of reads with 50ms delays
////////SERIAL COMMUNICATIONS -- READING
int readSerialString(char *strArray, int siz, char*required, int rlen, char*good, int glen, long timeOut) {
//read a string from the serial and store it in an array - with timeout
long startTime=millis();
boolean timedOut=true;
boolean garbage=false;
char ch;
int i=0;
while (millis()-startTime < timeOut){
timedOut=false; // since we're still looking!
if (glen && i && (glen==i) && strncmp(good,strArray,glen)==0) break;
// if a Good string has been specified, if i>0, if we've the right number of characters to make the comparison and if the comparison succeeds ...
if (Serial.available()>0) { // if there's something to look at
strArray[i] = Serial.read(); // look at it
ch=strArray[i]; // so as not to continually look up array, yet have strArray ready for return
if (ch==MESSAGE_END) { Serial.print("EOMessage"); break;}
if (ch == '\n') break; // new line
if (ch == '\r') break; // carriage return
delay(50); // ensure time for channel to react before next read
if (i>=rlen) { // aleady got the required markers
i++; // advance the index beyond the current accepted characters
if (i>=siz-1) stop("RS1"); // for size=10, max index is 9, but 9th position must be null so limit to 8
}
else if ((rlen==2)&&(i==1)) { // if a two character key, and we're at the second one (indx 1)
// can only get here if we have one of two instruction marker
if (strArray[i]==required[1]) i++; // instruction confirmed
else {
i=0 ; // it was just coincidence - back to try again
garbage=true;
}
}
else if (i==0) { // must be true or big probs
if (strArray[i]==required[0]) i++; // got our first marker, now look for second (if required), otherwise ignore
else {
garbage=true;
}
}
else stop("RS2");
} // if not available, just loop
timedOut=true; // set in case the timeout test fails
}
strArray[i]= '\0'; // null on end to terminate string
return (timedOut<<1)+garbage;
}
////////SERIAL COMMUNICATIONS -- WRITING
// Gobetwino layer
int sendGobetwinoCommand(char* commandType, char* content,char* required, int rlen, char* good, int glen, long timeout) {
Serial.print("#S|");
Serial.print(commandType);
Serial.print("|[");
Serial.print(content);
Serial.println("]#");
// normally wait up to 1000 ms for answer from Gobetwino, answer will be in GBT_serInString , answer is 0 if all is OK
// but using only RDFILN and LGFIL wait only up to 100 ms
// could tailor timeout to command type
return readSerialString(GBT_serInString ,GBT_serInLen, required, rlen, good, glen, timeout);
}
Thanks for Gobetwino.
Is your code available for customisation?
Kenny