📄 atcmdparser.c
字号:
if ( nbtData=='R' ) {
gw_nRCVState_START = RCV_STARP_START_P_4; // Enter ERROR State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_4 :
if ( nbtData=='R' ) {
gw_nRCVState_START = RCV_STARP_START_P_5; // Enter ERROR State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_5 :
if ( nbtData=='O' ) {
gw_nRCVState_START = RCV_STARP_START_P_6; // Enter ERROR State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_6 :
if ( nbtData=='R' ) {
gw_nRCVState_START = RCV_STARP_START_P_7; // Enter ERROR State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_7 :
if ( (nbtData==0x0D) || (nbtData==0x0A) || (nbtData==':') ) {
// Enter to Main ERROR process state
gw_nRCVState = RCV_STATE_RP_ERROR;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
} else {
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_8 :
if ( nbtData =='e' ) {
gw_nRCVState_START = RCV_STARP_START_P_9; // Enter READY message State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_9 :
if ( nbtData =='a' ) {
gw_nRCVState_START = RCV_STARP_START_P_10; // Enter READY message State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_10 :
if ( nbtData == 'd' ) {
gw_nRCVState_START = RCV_STARP_START_P_11; // Enter READY message State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_11 :
if ( nbtData == 'y' ) {
gw_nRCVState_START = RCV_STARP_START_P_12; // Enter READY message State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_12 :
if ( (nbtData==0x0D) || (nbtData==0x0A) ) {
// Enter to Main Ready process state
gw_nRCVState = RCV_STATE_READY;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
} else {
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_13 :
gw_nRCVState = RCV_STATE_WAIT;
gw_nRCVState_START = RCV_STARP_START_P_0; // Enter Wait State
// Reset plus paramater for new message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW;
break;
default:
break;
} // end of switch(gw_nRCVState_START)
return 0;
}
//short funPro_ParserRspMain(unsigned char* pUartBufData, unsigned short shUartBufLen, unsigned char cRepMode)
short funPro_ParserRspMain( struct agsm_rcv_transparas* pInputParas)
{
int nBufIndex=0;
unsigned char cParserStatus = 0;
unsigned char nInData = 0;
pInputParas->shBackNChar = 0;
while ( ( cParserStatus==0 ) && ( nBufIndex<(pInputParas->shRcvUartBufLen) ) ) {
// Read one character to parser
nInData=pInputParas->pRcvUartBufData[nBufIndex];
// increase index to next character
nBufIndex++;
// should be need to make sure system has been Ready to process the response message
// 1. start to preprocess the first character to decide the first state.
if ( gw_nRCVState==RCV_STATE_START ) {
funPro_RepStartMS_MainStartParser(nInData);
} // end of if ( gw_nRCVState==RCV_STATE_START )
// 2. enter to each state by first character
switch(gw_nRCVState) {
case RCV_STATE_START:
break;
case RCV_STATE_CMD:
// Skip All command echo response
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
case RCV_STATE_RP_PLUS:
funPro_RepPlusMS_MainPlusParser(nInData);
// re-check some state, and decide which action to do.
// Fisrt to check if back some byte to re-parser..
if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_BACK_N_CHAR ) {
if ( nBufIndex >= gw_cmpendstr_Index ) {
// back <gw_cmpendstr_Index> byte to reparser new message..
nBufIndex-=gw_cmpendstr_Index;
} else {
// the input buffer can not go back to original status,
// therefore we may pasre the new message, and it will be fail.
// Please make sure that the condition does not happaned.
nBufIndex = 0;
pInputParas->shBackNChar = gw_cmpendstr_Index-nBufIndex;
}
// empty end compare string for next time comparsion
gw_str_CmpEndString[0]='\0';
gw_cmpendstr_Index=0;
// End of message, and ready to re-seatch other response message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
} // end of if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_BACK_N_CHAR )
if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_DATA_FINAL ) {
// if input response mode is not RCV_PARSER_MODE_PLUS, do not care anything
if ( pInputParas->cRepMode==RCV_PARSER_MODE_PLUS ) {
// Only check the first CR charchter, then make decision to response status value.
if ( nInData==0x0D ) {
// do not check the response 'OK" is which CMD send response.
switch (gw_nRCVState_RF_MS) {
case RCV_STARP_RP_CPIN:
case RCV_STARP_RP_CSQ:
case RCV_STARP_RP_CMGF:
case RCV_STARP_RP_CMGR:
case RCV_STARP_RP_CMGS:
case RCV_STARP_RP_AIPA:
case RCV_STARP_RP_AIPO:
case RCV_STARP_RP_AIPR:
case RCV_STARP_RP_AIPW:
case RCV_STARP_RP_AIPC:
// Get complete response sentence
cParserStatus = 1 ;
// IF we response to main process, and notice new plus message,
// then we do not care next OK or other message, so go back to start state
// Ready to seatch other response message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
// Go to start state to re-parser new message
gw_nRCVState = RCV_STATE_START;
break;
default:
// do not process other messages, CMTI, AIPRTCP, AIPRUDP, AIPRIPI, etc
break;
} // end of switch(gw_nRCVState_RFPLUS)
}// end of if ( (nInData==0x0D) || (nInData==0x0A) )
} // end of if ( pInputParas->cRepMode==RCV_PARSER_MODE_PLUS )
// end of if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_DATA_FINAL )
} else if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_EOM ) {
// Some actions that you want to preprocess commnad ,
// data parameters, or data text
switch (gw_nRCVState_RF_MS) {
case RCV_STARP_RP_CLIP:
break;
case RCV_STARP_RP_CPIN:
break;
case RCV_STARP_RP_CSQ:
break;
case RCV_STARP_RP_CMGF:
break;
case RCV_STARP_RP_CMTI:
break;
case RCV_STARP_RP_CMGR:
break;
case RCV_STARP_RP_CMGS:
break;
case RCV_STARP_RP_AIPA:
break;
case RCV_STARP_RP_AIPO:
break;
case RCV_STARP_RP_AIPR:
break;
case RCV_STARP_RP_AIPW:
break;
case RCV_STARP_RP_AIPC:
break;
case RCV_STARP_RP_AIPRTCP:
break;
case RCV_STARP_RP_AIPRUDP:
break;
case RCV_STARP_RP_AIPRIPI:
break;
default:
break;
} // end of switch(gw_nRCVState_RF_MS)
// do not care which pInputParas->cRepMode, RCV_PARSER_MODE_DEFAULT, RCV_PARSER_MODE_PLUS
// set return mode to notice that we get complete response sentence
cParserStatus = 1 ;
// Ready to seatch other response message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
// Go to start state to re-parser new message
gw_nRCVState = RCV_STATE_START;
// end of if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_EOM )
} else if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_POM ) {
// Some actions that you want to preprocess commnad ,
// data parameters, or data text
switch(gw_nRCVState_RF_MS) {
case RCV_STARP_RP_CMGL:
break;
default:
break;
} // end of switch(gw_nRCVState_RF_MS)
// do not care which pInputParas->cRepMode, RCV_PARSER_MODE_DEFAULT, RCV_PARSER_MODE_PLUS
// set return mode to notice that we get part of incoming message from CMGL, etc.
cParserStatus = 1 ;
// Ready to seatch other response message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA;
gw_rpplusms_Index = 0 ; // Reset Index to other part data and
} // end of if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_POM )
break;
case RCV_STATE_READY:
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_RF_MS = RCV_STARP_RP_READY;
// Get complete response sentence
cParserStatus = 1 ;
} else {
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
case RCV_STATE_RP_OK:
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_RF_MS = RCV_STARP_RP_OK;
// Get complete response sentence
cParserStatus = 1 ;
} else {
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
case RCV_STATE_RP_ERROR:
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_RF_MS = RCV_STARP_RP_ERROR;
// Get complete response sentence
cParserStatus = 1 ;
} else {
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
case RCV_STATE_WAIT:
// Current parser does not go to other state to input SMS context transfer
// Get complete response sentence
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
// Get complete response sentence
//cParserStatus = 1 ;
} else {
if ( gw_nRCVState_RF_MS != RCV_STARP_RP_CMGS_SENDMODE ) {
gw_nRCVState_RF_MS = RCV_STARP_RP_CMGS_SENDMODE;
// Get complete response sentence
cParserStatus = 1 ;
} // end of if ( gw_nRCVState_RF_MS != RCV_STARP_RP_CMGS_SENDMODE )
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
case RCV_STATE_OTHERS:
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
default:
if ( (nInData==0x0D) || (nInData==0x0A) ) {
// Skip LF charater if next character is 0x0A
if ( pInputParas->pRcvUartBufData[nBufIndex]==0x0A )
nBufIndex++;
gw_nRCVState = RCV_STATE_START;
} // end of if ( (nInData==0x0D) || (nInData==0x0A) )
break;
} // end of switch(gw_nRCVState)
} // end of while ( cParserStatus==0 )
pInputParas->shHasParsedUartBufIndex = nBufIndex;
pInputParas->cParsRspTypeStatus = cParserStatus ;
if ( cParserStatus==1 ) {
// Get some complete response message
// Return parser and read character
// read byte count from input buffer
return nBufIndex;
} else {
// else if (cParserStatus==0)
// read byte count from input buffer,
// but not completely recevive or parser , or not get valid incoming message
return ( -nBufIndex );
} // end of else if ( cParserStatus==0 )
}
void funProc_ParserRspInit(void)
{
gw_nRCVState = RCV_STATE_START;; // RCV_STATE
gw_nRCVState_START = RCV_STARP_START_P_0; // RCV_STARP_START_P
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM; // RCV_STARP_PLUS
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW; // RCV_STARP_RP_MS
gw_szRFPLUS_Command[0] = '\0'; // response message command
gw_szRFPLUS_Data[0] = '\0'; // responsemessage data
gw_rpplusms_Index = 0; // reset index
gw_str_CmpEndString[0]='\0'; // compare end string
gw_cmpendstr_Index = 0; // reset index
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -