Sorry, I forgot that I removed the "count" stuff that I included when the EOP was a comma..Now again when I introduce that piece of code with the SOP as + and EOP as \r I get pretty much the same output I got when the EOP was , .
===
OK
LLL
OK
AT+INQ
OK
SOP detected
INQ:00:12:39:00:34:35 EOP1 DETECTED
”RLMobile”
00:13:45:46:99:23 EOP1 DETECTED
”Je
The code is (i have posted the correct code that I have used unlike the previous time)
#define SOP '+'
#define EOP '\r'
#include <avr/wdt.h>
int count=0;
int i;
bool started = false;
bool ended = false;
char inData[200];
byte index;
void setup()
{
Serial.begin(9600);
// Other stuff...
}
void readprocess()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 199)
{
inData[index] = inChar;
Serial.print(inData[index]);
index++;
inData[index] = '\0';
}
}
}
Serial.println('\n');
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
void readatinq()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
Serial.print("SOP detected");
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{ Serial.print("EOP detected");
count=count+1;
if(count>=4)
{
ended = true;
break;
}}
else
{
if(index < 199)
{
inData[index] = inChar;
Serial.print(inData[index]);
index++;
inData[index] = '\0';
}
}
}
Serial.println('\n');
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
void loop()
{
Serial.write("===");
delay(100);
readprocess();
delay(2000);
Serial.write("LLL");
delay(100);
readprocess();
delay(2000);
Serial.write("\r\nAT+INQ\r\n");
delay(1000);
readprocess();
delay(30000);
readatinq();
delay(2000);
wdt_enable(WDTO_15MS);
wdt_reset();
}