?? atrespparser.cpp
字號:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* ATRespParser.cpp
*
* Project:
* --------
* Maui_SW factory hardware testing tool.
*
* Description:
* ------------
* This module implements the parser of the AT response. This parser will
* parse the response of modern and send the result to upper layer.
*
* Author:
* -------
* Spancer (mtk00264)
*
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "ATRespParser.h"
#include "ATResult.h"
ATRespParser::ATRespParser()
{
AThread::AThread();
Raw_Buffer = NULL;
readIndex =0;
cr = 0x0d;
lf = 0x0a;
m_usc_cb = NULL;
stopEvent = false;
m_waitGtAndSpace = false;
}
ATRespParser::~ATRespParser()
{
}
bool ATRespParser::CheckIfGetGtandSpace()
{
if(respDataBuf[0]=='>' && respDataBuf[1]==' ')
return true;
else
return false;
}
void ATRespParser::CleanResult(ATResult& rt)
{
rt.resultLst.clear();
}
// Get the data from the two CR LF tag
void ATRespParser::FillBufferByState(unsigned char ch, int &state)
{
unsigned char ch2;
switch(state)
{
case 0:
// Get the first tag of CR LF
if(ch == GetCrByte())
{
while(!stopEvent)
{
if( Raw_Buffer->CheckOut(ch2)==true)
{
if(ch2 == GetLfByte())
{
state = 1;
writeIndex = 0;
break;
}
}
}
}
break;
case 1:
// Get the data between two CR LF
if(ch!=GetCrByte())
{
respDataBuf[writeIndex++]=ch;
}
else
{
while(!stopEvent)
{
if(Raw_Buffer->CheckOut(ch2)==true)
{
if(ch2 == GetLfByte())
{
respDataBuf[writeIndex]='\0';
AnalyingRespString();
writeIndex =0;
state = 0;
break;
}
}
}
}
break;
default:
break;
}
}
void ATRespParser::SetCallBack(void(*unSolicitedFunc)(ATResult& result))
{
m_usc_cb = unSolicitedFunc;
}
bool ATRespParser::AnalyingBuffer()
{
GetOneCrLf();
return true;
}
bool ATRespParser::AnalyingRespString()
{
int size = strlen(respDataBuf);
char tmp[1024];
int tmpWI =0;
bool ignoreWhiteSpace = false;
string endString;
string command = "";
bool stag = false;
bool getDbQEmptyString=false;
ATParamElem elem;
ATParamLst paraLst;
readIndex =0;
while(readIndex!=(size+1))
{
switch(respDataBuf[readIndex])
{
case '\0':
tmp[tmpWI] = '\0';
if (command.empty())
command = tmp;
else
endString = tmp;
if(command == "> ")
{
tmp[0]='\0';
}
else if(command == "OK"
|| command == "ERROR"
|| command == "CONNECT"
)
{
// Just fill the data to the result structure
result.result = AT_SUCCESS;
elem.type = AT_STRING;
elem.str_value = command;
paraLst.eleLst.push_back(elem);
result.resultLst.push_back(paraLst);
if(result.expectedCommand == "+ESLP"
&& command == "OK")
{
if(Raw_Buffer!=NULL)
Raw_Buffer->Clear();
}
Sync();
tmp[0]='\0';
}
else if(command == "+CME ERROR"
|| command == "+CMS ERROR")
{
ATParamElem telem;
telem.type = AT_INTEGER;
telem.int_value = atoi(tmp);
paraLst.eleLst.push_back(telem);
result.result = AT_SUCCESS;
result.resultLst.push_back(paraLst);
tmp[0] = '\0';
Sync();
}
else if(IsUnsolicited(command, paraLst))
{
//Check if current paraLst is a unsolicited command
// Call the unsolicited call back function to notify
// upper layer.
if(sizeof(tmp)!=0)
GetParam(tmp, paraLst, false);
UnsolicitedGetPdu(tmp, 2047, paraLst);
unsolicitedRt.result = AT_SUCCESS;
unsolicitedRt.resultLst.push_back(paraLst);
m_usc_cb(unsolicitedRt);
CleanResult(unsolicitedRt);
}
else if(command == result.expectedCommand )
{
// Get the pdu block and push it the the parameter list
if((strlen(tmp)!=0 )
|| (getDbQEmptyString == true))
GetParam( tmp, paraLst, stag);
if(pduFlag)
{
// Get PDU
GetPdu(tmp, 2047);
// Put to parameter list
elem.type = AT_STRING;
elem.str_value = tmp;
paraLst.eleLst.push_back(elem);
}
result.resultLst.push_back(paraLst);
}
break;
case ',':
tmp[tmpWI]='\0';
GetParam( tmp, paraLst, stag);
tmpWI = 0;
stag = false;
ignoreWhiteSpace = true;
break;
case ':':
tmp[tmpWI]='\0';
ignoreWhiteSpace = true;
readIndex++; // skip ':'
command = tmp;
elem.type = AT_STRING;
elem.str_value = command;
paraLst.eleLst.push_back(elem);
tmpWI = 0; // clear tmp
break;
case '(':
GetList(tmp, tmpWI, elem);
paraLst.eleLst.push_back(elem);
elem.paramLst.clear();
SkipComma(respDataBuf, readIndex, size);
tmp[0]='\0';
break;
case '"':
if(!GetStringToBuf(tmp, tmpWI, (size+1)))
return false;
if(strlen(tmp)==0)
getDbQEmptyString = true;
stag = true;
break;
default:
if(ignoreWhiteSpace == false)
{
tmp[tmpWI++] = respDataBuf[readIndex];
}
else
{
if(respDataBuf[readIndex]!=' ')
{
ignoreWhiteSpace = false;
tmpWI = 0;
tmp[tmpWI++] = respDataBuf[readIndex];
}
}
break;
}
readIndex++;
}
return true;
}
char ATRespParser::GetCrByte()
{
return cr;
}
HANDLE ATRespParser::GetWriteEvent()
{
return m_hWriteEvt;
}
DWORD ATRespParser::HelpThreadFunc(LPVOID param)
{
ATRespParser *pto = (ATRespParser *)param;
return pto->ThreadFunc();
}
char ATRespParser::GetLfByte()
{
return lf;
}
bool ATRespParser::GetInteger(char *ptr, int length, ATResult &result)
{
return true;
}
bool ATRespParser::GetInterval(char *ptr, int length, ATResult& result)
{
return true;
}
// Parse the data between ()
bool ATRespParser::GetList(char* ptr, int& wi, ATParamLst& lst)
{
ATParamElem elems;
bool intervalFlag=false;
bool stag = false;
wi = 0;
readIndex++; // Skip (
while(respDataBuf[readIndex]!=')')
{
switch(respDataBuf[readIndex])
{
case ',':
GetParam(ptr, elems, stag);
stag = false;
break;
case '"':
GetString(ptr, wi, elems);
stag = true;
wi = 0;
break;
case '-':
// Case of interval
intervalFlag = true;
ptr[wi]='\0';
if(IsNumber(ptr))
elems.int_range_begin = atoi(ptr);
else
return false;
wi = 0;
readIndex++;
while(respDataBuf[readIndex]!=')')
{
ptr[wi++] = respDataBuf[readIndex++];
}
ptr[wi]='\0';
if(IsNumber(ptr))
elems.int_range_end = atoi(ptr);
else
return false;
break;
case '\0':
return false;
break;
case '(':
GetList(ptr, wi, elems);
break;
default:
ptr[wi++] = respDataBuf[readIndex++];
break;
}
}
if(intervalFlag)
{
elems.type = AT_INTERVAL;
}
else
{
elems.type = AT_PARA_LIST;
}
lst.eleLst.push_back(elems);
return true;
}
bool ATRespParser::GetLstParam(char *ptr, ATParamElem& elem)
{
ATParamElem elemLocal;
if(strlen(ptr)==0)
elemLocal.type = AT_OMIT;
if(IsNumber(ptr))
{
elemLocal.type = AT_INTEGER;
elemLocal.int_value = atoi(ptr);
}
else
{
elemLocal.type = AT_STRING;
elemLocal.str_value = ptr;
}
elem.paramLst.push_back(elem);
return true;
}
bool ATRespParser::GetLstString(char *ptr, int& wi, ATParamElem& elem)
{
ATParamElem elemLocal;
readIndex++; // Skip "
wi = 0;
while(respDataBuf[readIndex]!='"')
{
switch(respDataBuf[readIndex])
{
case '\0':
return false;
break;
default:
ptr[wi++] = respDataBuf[readIndex++];
break;
}
}
ptr[wi]='\0';
return true;
}
bool ATRespParser::GetList(char *ptr, int& wi, ATParamElem& elem)
{
ATParamElem elemLocal;
elem.type = AT_PARA_LIST;
bool stag = false;
wi = 0;
readIndex++; // Skip (
while(respDataBuf[readIndex]!=')')
{
switch(respDataBuf[readIndex])
{
case ',':
GetParam(ptr, elem, stag);
ptr[0]='\0';;
wi = 0;
stag = false;
break;
case '"':
GetLstString(ptr, wi, elem);
stag = true;
break;
case '-':
// Case of interval
elem.type = AT_INTERVAL;
ptr[wi]='\0';
if(IsNumber(ptr))
elem.int_range_begin = atoi(ptr);
else
return false;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -