Runs on: 1284p-16MHz
Memory used: 6%
Program memory: 15%
I'm struggling to find the reason why my program suddenly, sometimes after hours, stopped working and gets reset.
I finally saw something that I don't understand how that is possible:
I sequentially executed the following code every 5sec.:
uint8_t getGpsData() { char caReceiveBuf[STRINGBUFFERSIZE]=""; if (sendFIXATcmdWithRespons(caATCGPSSTATUS, caFIX, 1, 4, NORMAL) == 1) { // GPS has a fix ATOMIC_BLOCK(ATOMIC_FORCEON) { gpsled = 2; // show GPS led fix } if (getGpsInfo(caReceiveBuf)) { // GPS position is in GPS receive array if ((decodeGPS(caReceiveBuf) == 1) && (lLatitude > 0) && (lLongitude > 0)) { return 1; } } } else { // GPS has no fix ATOMIC_BLOCK(ATOMIC_FORCEON) { gpsled = 1; // show GPS led no fix } } return 0; }
Inside the function getGpsInfo before returning 1 I did some extra checks to make sure that the caReceiveBuf is correct AND displayed it via a serial out for debugging:
uint8_t getGpsInfo(char *receive) { char caReceiveBuf[STRINGBUFFERSIZE]=""; "¦ // complete cleaned-out string is in array if ((pos > 0) && (pos < STRINGBUFFERSIZE-1)) { caReceiveBuf[pos] = '\0'; // print the received string for debugging purposes debugPutc('>'); debugPrintStr(caReceiveBuf); debugPrintStrln("<"); p = strstr_P(caReceiveBuf, caOK); if (p == NULL) { // OK not found debugPrintStrln("gpslnok"); return 0; } else { // filter-out OK *p = '\0'; } len = strlen(caReceiveBuf); // surely no GPS INFO if length < MINLENGTHGPSINFO if (len < MINLENGTHGPSINFO) { debugPrintStrln("gpslen"); return 0; } // could be GPS INFO -> check further // extra checks to make sure if ((caReceiveBuf[1] != ',') || (caReceiveBuf[12] != ',') || (caReceiveBuf[24] != ',')) { debugPrintStrln("gpscomma"); return 0; } // looks ok: 01234567890123456789012345678901234567890123456789012345678901234567890123456 // 0,340.123455,5005.123456,53.312218,20130411174152.000,0,0,0.000000,0.000000OK strcpy(receive, caReceiveBuf); return 1; }
So via debugPrintStr I saw it was still ok AND the length was also ok and checked.
The call to decodeGPS(caReceiveBuf) that came DIRECTLY after returning from getGpsData however did behave strange:
The function starts with:
uint8_t decodeGPS(char *caReceiveBuf) { // returns following values: // 0 no valid GPS data // 1 valid GPS data // // we are getting everything out of CGPSINF=0 data (these are 9 fields) // 0 Message ID 0 header // 1 * Longitude 123.123456 123.123456 // 2 * Latitude 5105.123456 1234.123456 // 3 Altitude 1234.123456 1234.123456 // 4 * UTC Time 20130313193055.000 yyyyMMddHHmmSS.sss // 5 TTFF 23 xxxx // 6 * Number of sats 12 xx // 7 * Speed 123.123456 yyy.xxxxxx // 8 Course 320.123456 yyy.xxxxxx // looks ok: // 0,340.123455,5005.123456,53.312218,20130411174152.000,0,0,0.000000,0.000000 int iVeld = 0; char *pch=NULL; char *pch2=NULL; uint16_t len = 0; char *p; len = strlen(caReceiveBuf); if (len < MINLENGTHGPSINFO) { debugPrintStrln("gpsdecodeminlen"); return 0; }
Via my terminal window I could see that length was not OK??? Why???? It was OK just before.
No other calls in between these 2 functions that could corrupt the character array!
The terminal showed "˜gpsdecodeminle' without the last "˜n' and then reset the cpu.
The problem however is: how can it be that the length is now not OK?/
What happened with the variable in the meantime?
I only suspect that it has to do with an timer interrupt of 100ms which causes to stack to get corrupted"¦
That interrupt however does nothing special. Just some LED indications and generating some pulses.
Can PLEASE somebody explain this to me why this happened?