Why my loop runs twice?
I'm trying to read from a gsm sim800,DSPIC33FJ64GP206A,XC16.
Here is my code:
bool GsmCommand(char * command, char * ResponseText, uint16_t Timeout)
{
uint16_t GsmCounter=0;
ClearGsmBuffer();
Eusart1_Write(command);
__delay_ms(20);
while(!strstr((char *)Eusart1_Received.bytes,ResponseText))
{
GsmCounter++;
if(GsmCounter>Timeout)
{
//ClearWifiBuffer();
return false;
break;
}
}
return true;
}
void ReadSms(void)
{
if(GsmModule.isReady && Sim.isReady && Network.isReady)
{
GsmCommand(CMGF,OK,NORMALTIME);
int i;
for(i=0;i<=20;i++)
{
sprintf(txt,"%s%d\r\n",READSMS,i);
if(GsmCommand(txt,MESSAGEISEXIST,LONGTIME))
{
if(NumberIsValid(i))
{
//GsmCommand(DeleteSms(i),OK,NORMALTIME);
}
}
}
}
}
bool NumberIsValid(int Index)
{
char *p;
for ( p = strtok((char *)Eusart1_Received.bytes,"\""); p != NULL; p = strtok(NULL, "\""))
{
if(strstr(p,"+")&&strlen(p)==13)
{
strcpy(MobileNumber, p);
sprintf(txt,"%s,%d",MobileNumber,Index);
Eusart2_Write(txt);
__delay_ms(20);
return true;
break;
}
}
return false;
}
When i write to uart and send it to my pc, I see that it not read all numbers.
Here is my terminal output.
+3069xxxxxxxx,3
+3069xxxxxxxx,5
+3069xxxxxxxx,7
+3069xxxxxxxx,9
+3069xxxxxxxx,11
+3069xxxxxxxx,13
+3069xxxxxxxx,15
+3069xxxxxxxx,17
+3069xxxxxxxx,19
As you can see it skips one sms in each read.