Hi, anyone got any ideas about this one? – I’ve got a array of characters that I’m using to create and display various error messages. It’s all very basic, I’m not doing rocket science here but it’s getting corrupted straight away.
Here’s the code that populates and displays the array….
if (ret_val != RX_FINISHED_STR_RECV)
{
// Strip all the control characters from the output buffer, and use this to populate clean_buff...
cleanBuffer();
info[0]=0; // reset string
sprintf(info,"WaitResp. Expected <%s>",expected_resp_string);
if (ret_val == RX_FINISHED_STR_NOT_RECV)
{
strcat(info,", got <"); // this is the bit that's getting corrupted
strcat(info,clean_buff); // add the actual error message
strcat(info,">");
}
else if (ret_val == RX_TMOUT_ERR)
{
strcat(info,". Timeout");
}
Serial.println(info); // display message.
loggerMiniGSM->writeLn(info); // write message to log file (and echo to screen)
}
And here’s what I see on the screen…..
WaitResp. Expected <>>,çgotñ<+CMS ERROR: 310>
33:24:27 WaitResp. Expected <>>,çgotñ<+CMS ERROR: 310>
As you can see the characters immediately before and after the word ‘got’ have somehow been corrupted. The second line (with the timestamp) is also written to the logfile. (I check the logfile, and those characters are also corrupted there) So whats going on?
One of the things I don’t get how the array can get corrupted so quickly, - the error message is formed, and then it’s displayed straight away, no other functions are getting called in the meantime so what’s causing the corruption?
Also, the ‘info’ array is constantly being reset (i.e. info[0]=0;) and constantly been used by other functions without problems, and yet the same corruption is always appearing in the same place.
Other points….
Info is declared as “char info[90+1];”
The error is repeatable.
The array ‘info’ is available to all functions in the class, each of the functions use ‘info’ to display the error message in a similar manner, but none of those functions is there any similar corruption.
The arduino application is cycling through the same code, but the corruption doesn’t appear straight away. In the above example, the corruption after ‘got’ appeared after about five minutes, and the corruption before it about 5 minutes later.
The corruption doesn’t get any worse – the above example is after 33 hours of running.
The whole application involves a dozen librarys and external hardware, so I can’t really post the whole thing.
It’s running on an Mega2560