string search in struct buffer

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Does the compiler mind doing a string search on a buffer in struct. like this...

   

COM.Buf[LastByte] = '\0';

   

if(strstr(COM.Buf,"OK")

   

{

   

  //got it

   

}

   

This appeared to working initially when I had debugger attached to target, when I programmed the target and ran on its own, the code program did not perform the same as when debugging.

   

I then connected to debugger again and re-ran.When I stepped through this code, I noted the COM.Buf contained CR LF OK CR LF but the loop failed to find the string.

   

I also tried below code and it appeared to work but when I programmed device, the code did not perform the same.

   

COM.Buf[LastByte] = '\0';

   

sprinft(tempsrtr,COM.Buf)

   

if(strstr(temstr,"OK")

   

{

   

  //got it

   

}

   

What I mean by "did not perform the same" is that the fisrt part of initiation for the GSM modem simply issues and AT command to check modem responds with "OK", before sending setup parameters to it.

   

I have a seried of LEDs that show progress, AT OK, SIM OK, Network OK etc.

   

When I program the target and run on its own, It never indicates AT is OK. I have been running on debugger for several days developing the code and it appeared to get the AT OK response every single time.

0 Likes
5 Replies