📄 atcmdparser.c
字号:
// CB: Callback function to process the parameters
// gw_rpplusms_Index=0;
} else {
// Get new match string, continue to match
nMoveCount = nComEndStrLen-nCheckIndex;
for( i=0; i<nMoveCount; i++) {
gw_str_CmpEndString[i]=gw_str_CmpEndString[nCheckIndex+i];
}
nComEndStrLen = nMoveCount;
gw_str_CmpEndString[nComEndStrLen]='\0';
gw_cmpendstr_Index = nComEndStrLen;
nContinueCheckIndex=0;
break;
} // end of if ( (nComEndStrLen-nCheckIndex)==8 )
return 0;
} // end of if ( nAgainEachLineEndCheck==0 )
} // end of if ( (nComEndStrLen-nCheckIndex) >= 3 )
} // end of if ( nRtnCheck==0 )
}
if ( nContinueCheckIndex==-1 ) {
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_OTHERS;
// emptr end compare string for next time comparsion
gw_str_CmpEndString[0]='\0';
gw_cmpendstr_Index=0;
} // end of if ( nContinueCheckIndex==-1 )
} // end of if ( nRtnCheck==0 )
return 0;
}
unsigned char funPro_RepPlusMS_CheckIfEndData(unsigned char nbtData)
{
switch(gw_nRCVState_RF_MS) {
case RCV_STARP_RP_CPIN:
case RCV_STARP_RP_CSQ:
case RCV_STARP_RP_CMGF:
case RCV_STARP_RP_CMGS:
case RCV_STARP_RP_AIPA:
case RCV_STARP_RP_AIPO:
case RCV_STARP_RP_AIPW:
case RCV_STARP_RP_AIPR:
case RCV_STARP_RP_AIPC:
funPro_RepPlusMS_FINAL_CheckIfEndData(nbtData);
break;
case RCV_STARP_RP_CMGR:
funPro_RepPlusMS_CMGR_CheckIfEndData(nbtData);
break;
case RCV_STARP_RP_CMGL:
funPro_RepPlusMS_CMGL_CheckIfEndData(nbtData);
break;
} // end of switch(gw_nRCVState_RF_MS)
return 0;
}
unsigned char funPro_RepPlusMS_Command(char *pCommand, char *pData)
{
// show command text
// int nCmdLen=0;
// int nDataLen=0;
if ( pCommand==0 || pData==0 )
return 1;
// nCmdLen = strlen(pCommand);
// nDataLen = strlen(pData);
// if ( nCmdLen==0 || nDataLen==0 )
// return 2;
// Parse this statement..
if ( fun_strcmp(pCommand, "CPIN")==0 ) {
//funPro_RepPlusMS_CPINCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_CPIN;
} else if ( fun_strcmp(pCommand, "CLIP")==0 ) {
//funPro_RepPlusMS_CLIPCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_CLIP;
} else if ( fun_strcmp(pCommand, "CSQ")==0 ) {
//funPro_RepPlusMS_CSQCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_CSQ;
} else if ( fun_strcmp(pCommand, "CMGF")==0 ) {
//funPro_RepPlusMS_CMGFCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_CMGF;
} else if ( fun_strcmp(pCommand, "CMTI")==0 ) {
//funPro_RepPlusMS_CMTICommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_CMTI;
} else if ( fun_strcmp(pCommand, "CMGR")==0 ) {
//funPro_RepPlusMS_CMGRCommand(pData);
// Go to retail CMGR data state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_OTHERS;
gw_nRCVState_RF_MS = RCV_STARP_RP_CMGR;
} else if ( fun_strcmp(pCommand, "CMGL")==0 ) {
//funPro_RepPlusMS_CMGLCommand(pData);
// Go to retail CMGL data state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_OTHERS;
gw_nRCVState_RF_MS = RCV_STARP_RP_CMGL;
} else if ( fun_strcmp(pCommand, "CMGS")==0 ) {
//funPro_RepPlusMS_CMGSCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_CMGS;
} else if( fun_strcmp(pCommand, "AIPA")==0){
//funPro_RepPlusMS_AIPACommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPA;
} else if( fun_strcmp(pCommand, "AIPO")==0){
//funPro_RepPlusMS_AIPOCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPO;
} else if( fun_strcmp(pCommand, "AIPW")==0){
//funPro_RepPlusMS_AIPWCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPW;
} else if( fun_strcmp(pCommand, "AIPR")==0){
//funPro_RepPlusMS_AIPRCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPR;
} else if( fun_strcmp(pCommand, "AIPC")==0){
//funPro_RepPlusMS_AIPCCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_FINAL;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPC;
} else if( fun_strcmp(pCommand, "AIPRTCP")==0){
//funPro_RepPlusMS_AIPRTCPCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPRTCP;
} else if( fun_strcmp(pCommand, "AIPRUDP")==0){
//funPro_RepPlusMS_AIPRUDPCommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPRUDP;
} else if( fun_strcmp(pCommand, "AIPRIPI")==0){
//funPro_RepPlusMS_AIPRIPICommand(pData);
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_AIPRIPI;
} else {
// Go to start state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_EOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW;
}
return 0;
}
unsigned char funPro_RepPlusMS_MainPlusParser(unsigned char nbtData)
{
unsigned char nRtnValue=0;
switch(gw_nRCVState_RFPLUS)
{
///////////////////////////////////////////////////////////////////////
// Search for start of message '$'
case RCV_STARP_PLUS_SOM :
if(nbtData == '+')
{
gw_rpplusms_Index = 0; // reset index
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_CMD;
}
break;
// Retrieve command (response message header)
case RCV_STARP_PLUS_CMD :
if( (nbtData == ':') || (nbtData == '\r') || (nbtData == '\n') || \
(nbtData == ' ') || (nbtData == '\0')) {
// End of collect command string
gw_szRFPLUS_Command[gw_rpplusms_Index] = '\0'; // terminate command
// Output Command String to View..
gw_rpplusms_Index = 0;
// goto get data state
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA;
} else {
// ( (nbtData != ':') && (nbtData != '\r') && (nbtData != '\n') &&
// (nbtData != ' ') && (nbtData != '\0') )
// Check for command overflow
if (gw_rpplusms_Index < RCV_RP_MAX_CMD_LEN) {
gw_szRFPLUS_Command[gw_rpplusms_Index++] = nbtData;
} else {
// else (gw_rpplusms_Index >= RP_MAX_CMD_LEN)
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
} // end of if (gw_rpplusms_Index < RP_MAX_CMD_LEN)
} // end of check command string
break;
///////////////////////////////////////////////////////////////////////
// Store data and check for end of sentence or checksum flag if have checksum
case RCV_STARP_PLUS_DATA :
if( (nbtData == '\r') || (nbtData == '\n')) // check CR and LF
{
gw_szRFPLUS_Data[gw_rpplusms_Index] = '\0';
funPro_RepPlusMS_Command(gw_szRFPLUS_Command, gw_szRFPLUS_Data);
// Check that state enter to multi-line result state: CMGR, CMGL, etc
if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_DATA_FINAL ) {
// Start to check the end string \r\n\r\nOK\r\b
if ( nbtData=='\r' ) {
gw_cmpendstr_Index=0;
gw_str_CmpEndString[gw_cmpendstr_Index++]=nbtData;
gw_str_CmpEndString[gw_cmpendstr_Index]='\0';
} // end of if ( nbtData=='\r' )
} else if ( gw_nRCVState_RFPLUS==RCV_STARP_PLUS_DATA_OTHERS) {
// Go to Next state and collect content from CMGR, CMGL, etc
// Claer content for CMGR, CMGL, etc
gw_rppluctxsms_Index=0;
gw_szRFPLUS_CxtData[gw_rppluctxsms_Index]='\0';
//gw_rpplusms_Index=0;
} // end of if ( gw_nRCVState_RFPLUS==CV_STARP_PLUS::RCV_STARP_PLUS_DATA_OTHERS)
}
else // no CR and LF character, store data
{
//
// Store data
//
if ( (gw_rpplusms_Index==0) && (nbtData==' ') ) {
// skip first space character
break;
} else {
// if ( (gw_rpplusms_Index!=0) || (nbtData!=' ') )
// Check for Data buffer overflow
if (gw_rpplusms_Index < RCV_RP_MAX_DATA_LEN) {
gw_szRFPLUS_Data[gw_rpplusms_Index++] = nbtData;
} else {
// else (gw_rpplusms_Index >= RP_MAX_DATA_LEN)
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
} // end of if (gw_rpplusms_Index < RP_MAX_DATA_LEN)
}
}
break;
case RCV_STARP_PLUS_DATA_FINAL:
// Check if end data of this Plus message
funPro_RepPlusMS_CheckIfEndData(nbtData);
break;
case RCV_STARP_PLUS_DATA_OTHERS:
if ( (gw_rppluctxsms_Index==0) && (nbtData == '\n') ) {
// Skip last <LF> character and get tail data that may include severial lines.
break;
} else {
//gw_szRFPLUS_Data[gw_rpplusms_Index] = nbtData;
gw_szRFPLUS_CxtData[gw_rppluctxsms_Index] = nbtData;
if(++gw_rppluctxsms_Index >= RCV_RP_MAX_DATA_LEN) // Check for buffer overflow
{
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
} else {
if ( nbtData=='\r' ) {
gw_cmpendstr_Index=0;
gw_str_CmpEndString[gw_cmpendstr_Index++]=nbtData;
gw_str_CmpEndString[gw_cmpendstr_Index]='\0';
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_OTHERS_FINAL;
}
}
} // end of if ( (gw_rppluctxsms_Index==0) && (nbtData == '\n') )
break;
case RCV_STARP_PLUS_DATA_OTHERS_FINAL:
if ( gw_str_CmpEndString[0]=='\0' ) {
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_DATA_OTHERS;
} else {
//gw_szRFPLUS_Data[gw_rpplusms_Index] = nbtData;
//if(++gw_rpplusms_Index >= RP_MAX_DATA_LEN) // Check for buffer overflow
gw_szRFPLUS_CxtData[gw_rppluctxsms_Index] = nbtData;
if(++gw_rppluctxsms_Index >= RCV_RP_MAX_DATA_LEN) // Check for buffer overflow
{
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
} else {
// Check if end data of this Plus message
funPro_RepPlusMS_CheckIfEndData(nbtData);
} // end of if(++gw_rppluctxsms_Index >= RP_MAX_DATA_LEN)
} // end of if ( m_Str_CmpEndString == String::Empty )
break;
default:
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
break;
}
return nRtnValue;
}
unsigned char funPro_RepStartMS_MainStartParser(unsigned char nbtData)
{
switch(gw_nRCVState_START)
{
case RCV_STARP_START_P_0 :
// preprocessing to define state
if ( (nbtData==0x0D) || (nbtData==0x0A) ) {
gw_nRCVState = RCV_STATE_START;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
} else {
switch(nbtData) {
case 'A':
case 'a':
gw_nRCVState = RCV_STATE_CMD;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
// Reset plus paramater for new message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW;
break;
case '+':
gw_nRCVState = RCV_STATE_RP_PLUS;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
// Reset plus paramater for new message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW;
break;
case '>':
gw_nRCVState_START = RCV_STARP_START_P_13;
break;
case 'O':
gw_nRCVState_START = RCV_STARP_START_P_1; // Enter OK State
break;
case 'E':
gw_nRCVState_START = RCV_STARP_START_P_3; // Enter ERROR State
break;
case 'R':
gw_nRCVState_START = RCV_STARP_START_P_8; // Enter ERROR State
break;
default :
gw_nRCVState = RCV_STATE_OTHERS;
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
// Reset plus paramater for new message
gw_nRCVState_RFPLUS = RCV_STARP_PLUS_SOM;
gw_nRCVState_RF_MS = RCV_STARP_RP_UNKNOW;
break;
} // end of switch(nbtData)
} // end of if ( (nbtData==0x0D) || (nbtData==0x0A) )
break;
case RCV_STARP_START_P_1 :
if ( nbtData=='K' ) {
gw_nRCVState_START = RCV_STARP_START_P_2; // Enter OK State
} else {
gw_nRCVState_START = RCV_STARP_START_P_0; // Init State
}
break;
case RCV_STARP_START_P_2 :
if ( (nbtData==0x0D) || (nbtData==0x0A) ) {
// Enter to Main OK process state
gw_nRCVState = RCV_STATE_RP_OK;
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_3 :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -