View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Control RDA |
Posted: Mon Apr 01, 2019 9:19 am |
|
|
Hi, I need help logic for can capture this string
Example AT Commad
AT CMD Response
AT{0D} {0D}{0A}OK{0D}{0A}
AT+CGSN{0D} {0D}{0A}861445030295583 {0D}{0A}{0D}{0A}OK{0D}{0A}
AT+CPIN?{0D} {0D}{0A}+CPIN: READY {0D}{0A}{0D}{0A}OK{0D}{0A}
AT+CSQ{0D} {0D}{0A}+CSQ: 26,0 {0D}{0A}{0D}{0A}OK{0D}{0A}
AT+CREG?{0D} {0D}{0A}+CREG: 0,1 {0D}{0A}{0D}{0A}OK{0D}{0A}
AT+CIFSR{0D} {0D}{0A}10.140.148.116 {0D}{0A}
AT+CBC{0D} {0D}{0A}+CBC: 0,100,4202 {0D}{0A}{0D}{0A}OK {0D}{0A}
start {0D}{0A}
---
end {0D}{0A}
I am working with sim800L module 2G, I want use the RDA for capture the response.
The problem is repeat the 0D many times.
Code: | #int_rda
void rda_isr(){
bufferByte = getchar(MODEM);
// See what we got
if (bufferByte == 0x0D){
moduleResonseBuffer[moduleBufferIndex] = 0x00; // Add Null terminator
messageReady=1; // Message Ready
moduleBufferIndex = 0; // Prepare index for next message
}
else if ( (bufferByte == 0x00) || (bufferByte == 0x0A) )
{
// Do nothing
}
else
{
moduleResonseBuffer[moduleBufferIndex++] = bufferByte; // Add Byte to Buffer
}
}
|
someone idea please? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Mon Apr 01, 2019 10:22 am |
|
|
You need to look for the OK sequence, not the 0xD. 0xD is the end of line
marker, and it'll send this at several points in the reply. OK marks
the end of the actual response. |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Mon Apr 01, 2019 11:56 am |
|
|
There might be a better way, but I used the esp8266, which also uses the AT codes.
My RDA interrupt puts things into a circular buffer. In my main loop, and whenever there's stuff in the buffer, I take it out of there and put it into my own buffer until I encounter a '\n'. My own buffer signals that at that point that it "has a complete message". At that point, I do use the strstr function in string.h to find the "OK" or whatever other string I am searching for inside the string in my buffer. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Apr 01, 2019 2:07 pm |
|
|
Inside RDA interrupt:
Code: |
// ****************************************************************************
tmp=getc(); // get received char and thus also clear interrupt flag
// Process reception through state machine
//Possible data from GSM module that will be handled is:
// OK + CR +LF
switch (gsm_state) {
//get initial character 'O'
case 0:{
else if(tmp == 'o' || tmp == 'O'){ //we have "O", could be "OK"
gsm_state = 3; //expecting 'K'
}
else {
gsm_state = 0;
}
break;
}
//********WE HAVE RECIEVED 'O' AS A FIRST CHARACTER***************************
case 3:{
if(tmp == 'K') //we have 'OK'
gsm_state = 31; //expecting CR + LF
else
gsm_state = 0;
break;
}
case 31:{
if(tmp == 13) //we have OK + CR (binary 13)
gsm_state = 32; //expecting LF (binary 10)
else
gsm_state = 0;
break;
}
case 32:{
if(tmp == 10){ //we have OK + CR +LF, OK response is complete
// ****************************************************************************
Got_OK = 1; // HERE YOU HAVE AN INDICATION THAT YOU GOT AN OK FROM THE MODULE
// ****************************************************************************
}
gsm_state = 0; //reset state machine
break;
}
//*****************************************************************************
//we don't have anything good, ERROR
default:{
gsm_state = 0;
break;
}
} // switch brace
|
You issue a command to GSM module and right after that you can call this function that waits for a response you want, in this case "OK"
Code: |
// ********************* Wait_OK_Response *************************************
// uses Got_OK flag set in the receive routine
// ****************************************************************************
void Wait_OK_Response(){
Got_OK = 0;
OK_Response = 0; // init
int i = 0;
delay_cycles(1);
while (i < 80){ // two ways to exit this loop
i++; // either find "OK" in four seconds
if(Got_OK){
Got_OK = 0;
OK_Response = 1; // OK received
break;
}
else{
delay_ms(50); // or timeout
}
}
if(i > 80){
OK_Response = 0; // OK not received in 4 seconds
}
}
|
|
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Apr 01, 2019 2:13 pm |
|
|
Delete the first else in case 0:, I cut this from a larger function that also parses other responses from GSM and didn't notice it. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Apr 01, 2019 2:35 pm |
|
|
And drop this, it is wrong because i can only go up to 80 and is also redundant, since OK_Response is already preset to 0.
if(i > 80){
OK_Response = 0; // OK not received in 4 seconds
} |
|
|
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Mon Apr 01, 2019 4:06 pm |
|
|
Thank you so much, I work on your idea. |
|
|
|