?? gprs_modem.c
字號:
/****************************************Copyright (c)**************************************************
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#include "config.h"
/*********************************************************
** Function name: UART2_read
** Descriptions: UART2的讀串口函數
** Input: 無
** Output: 讀到串口數據的長度
*************************************************************/
OS_EVENT *poeUart0ReviceSem;
OS_EVENT *poeUart1ReviceSem;
OS_EVENT *poeUart2ReviceSem;
OS_EVENT *poeUart3ReviceSem;
uint8 UART_read(uint32 uiId,uint8 *uiReviceBuf,uint16 * puiNum)
{
//INT8U iUartErr;
uint16 shGetNData = 0;
OS_EVENT *pevent;
switch (uiId)
{
case UART0: //讀串口0的數據
pevent= poeUart0ReviceSem;
break;
case UART1://讀串口1的數據
pevent= poeUart1ReviceSem;
break;
case UART2://讀串口2的數據
pevent= poeUart2ReviceSem;
break;
case UART3://讀串口3的數據
pevent= poeUart3ReviceSem;
break;
}
//OSSemPend(pevent, 0, &iUartErr); // 請求信號量
//*puiNum = uartFifoStatus(uiId, RX_FIFO); // 查看收到多少數據
//uartRead(uiId, uiReviceBuf, *puiNum, NULL);
shGetNData = uartFifoStatus(uiId, RX_FIFO);
shGetNData = uartRead(uiId, uiReviceBuf, shGetNData, NULL);
//shGetNData = uartRead(uiId, uiReviceBuf, 128, NULL);
*puiNum = shGetNData;
return TRUE;
}
/*********************************************************
** Function name: Send_data
** Descriptions: 發送數據格式,將需要發送的數據加上AT+AIPW=1,"XXXXXXXXXX"指令
** Input: data, 需要發送的數據
uint32 uiId
** Output:
*************************************************************/
uint8 Send_data(uint8 * data,uint16 datalen,uint16 * puiNum)
{
char * szs="AT+AIPW=1,\"";
char * sgs="\"\r\0";
if(data[0]==0xff&&data[1]==0xff)
{
return FALSE;
}
if(data[0]==0x00&&data[1]==0x00)
{
return FALSE;
}
memmove(data+strlen(szs),data,*puiNum);
memmove(data,szs,strlen(szs));
memmove(data+strlen(szs)+*puiNum,sgs,strlen(sgs));
*puiNum=*puiNum+strlen(szs)+strlen(sgs);
if((*puiNum)>datalen)
return FALSE;
else
memset(data+*puiNum,0,datalen-*puiNum);
return TRUE;
}
/*********************************************************
** Function name: (uint32 uiId,char * GPRS_data)
** Descriptions: 讀取上位機回復GPRS數據信息,對其進行解包
** Input: char data, 需要發送的數據
uint32 uiId
** Output: GPRS_data
*************************************************************/
#if 1
#include "atcmdParser.h"
// New verison: 2009.05.11 \, Chad
uint8 RING_COU=0; //ring筧羘Ω計
//uint8 LoadUart2(uint32 uiId,uint8 * GPRS_data,uint16 * puiNum)
uint8 GPRSLoadData(uint32 uiId,uint8 * GPRS_data,uint16 * puiNum, unsigned char cGetType)
{
char gw_szUartBuffer[700];
char gw_szOutBuffer[700];
char * str=",\"";
// Chad
//char * str1="\"\r\n";
char * str1="\"\r";
char * p=NULL;
char * p1=NULL;
#if 0
// 0: Not get match response, 1: has get match response
unsigned char nRtnStatus = 0 ;
#endif
unsigned char fHasGetResp = 0;
unsigned short nRtnParserByte = 0;
// unsigned short nGetFixedBufSize = 128;
unsigned short nDisplayIndex = 0;
// Save original total free buffer size
int nInputTotalBufSize = *puiNum;
int nHasParserBytes = 0;
int nHasRevBytes = 0;
unsigned short shDlyTime = 0;
unsigned short shTimeout = 10*10; // 0.05 seconds * 10 = 0.5 seconds
unsigned short iLoopidx=0;
unsigned short iMaxidx=0;
// parameters for Uart2 transfer data
struct agsm_rcv_transparas struSendRCVUartParas;
unsigned char nDispBgEdMsg = 0;
unsigned char nNeedProcessRsp = 0;
// sprintf(gw_szUartBuffer,"\r\n++ LoadUart: begin get message ++\r\n");
// uartWrite(UART3,(uint8 *)gw_szUartBuffer,strlen(gw_szUartBuffer),NULL);
funProc_ParserRspInit(); // Init Parser state
do
{
// We need to reduce the UAT read critical section time
// if ( (*puiNum)>nGetFixedBufSize )
// *puiNum = nGetFixedBufSize;
if ( cGetType==0 || cGetType==2) {
// cGetType==0: default mdoe, read all data until no incoming data
// cGetType==2: Flush data and not parser GPRS data
UART_read( UART2, (GPRS_data+nHasRevBytes), puiNum);
} else {
// cGetType==1
*puiNum = uartRead(UART2, (GPRS_data+nHasRevBytes), 1, NULL);
}
if ( (*puiNum > 0) || (nHasParserBytes < nHasRevBytes) ) {
// Chad add: display debug information
#if 1
if ( nDispBgEdMsg==0 ) {
nDispBgEdMsg = 1;
sprintf(gw_szUartBuffer,"\r\n++ GPRS: begin get message ++\r\n");
// uartWrite(UART3,(uint8 *)gw_szUartBuffer,strlen(gw_szUartBuffer),NULL);
nDisplayIndex = strlen( gw_szUartBuffer );
}
if ( *puiNum > 0 ) {
iLoopidx = 0;
#if 0
gw_szUartBuffer[nDisplayIndex+0]='\r';
gw_szUartBuffer[nDisplayIndex+1]='\n';
for ( iLoopidx=2; iLoopidx<12; iLoopidx++) {
gw_szUartBuffer[nDisplayIndex+iLoopidx]='=';
} // end of for ( iLoopidx=0; iLoopidx<10; iLoopidx++
gw_szUartBuffer[nDisplayIndex+iLoopidx]='\r'; iLoopidx++;
gw_szUartBuffer[nDisplayIndex+iLoopidx]='\n'; iLoopidx++;
#endif
memcpy(gw_szUartBuffer+nDisplayIndex+iLoopidx, GPRS_data+nHasRevBytes, *puiNum);
#if 0
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='\r'; iLoopidx++;
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='\n'; iLoopidx++;
iMaxidx = iLoopidx+10;
for ( ; iLoopidx<iMaxidx; iLoopidx++) {
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='=';
} // end of for ( iLoopidx=0; iLoopidx<10; iLoopidx++
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='\r'; iLoopidx++;
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='\n'; iLoopidx++;
#endif
gw_szUartBuffer[nDisplayIndex+(*puiNum)+iLoopidx]='\0';
nDisplayIndex = strlen(gw_szUartBuffer);
//uartWrite(UART3,GPRS_data+nHasRevBytes,(*puiNum)+iLoopidx,NULL); // output debug messasge to UART3
// uartWrite(UART3,(unsigned char *)gw_szUartBuffer,nDisplayIndex+(*puiNum)+iLoopidx,NULL); // output debug messasge to UART3
}
#endif // #if 1 or 0
// Update buffer size variable
if ( *puiNum > 0 ) {
// Update new parameters
nHasRevBytes += *puiNum; // Add new receive bytes count
*puiNum = nInputTotalBufSize - nHasRevBytes; // Update new free Buffer Size
} else {
// else if ( *puiNum <= 0 )
*puiNum = nInputTotalBufSize - nHasRevBytes; // Update new free Buffer Size
} // end of if ( *puiNum > 0 )
if ( cGetType==0 || cGetType==1 ) {
// cGetType==0: default mdoe, read all data until no incoming data
// set some input parameters
struSendRCVUartParas.pRcvUartBufData = ( GPRS_data + nHasParserBytes );
struSendRCVUartParas.shRcvUartBufLen = nHasRevBytes - nHasParserBytes;
struSendRCVUartParas.cRepMode = 0; // o: default mode
// get some output result
struSendRCVUartParas.shHasParsedUartBufIndex = 0;
struSendRCVUartParas.cParsRspTypeStatus = 0;
struSendRCVUartParas.shBackNChar = 0;
nRtnParserByte = funPro_ParserRspMain( &struSendRCVUartParas );
// Check if we have back N character to parser again..
if ( struSendRCVUartParas.shHasParsedUartBufIndex==0 ) {
if ( struSendRCVUartParas.shBackNChar > 0 ) {
if ( nHasParserBytes >= struSendRCVUartParas.shBackNChar ) {
nHasParserBytes -= struSendRCVUartParas.shBackNChar;
} else {
// Can not go back to original start postion
// We have find out some other way to solve this issue
nHasParserBytes = 0;
} // end of if ( nHasParserBytes >= struSendRCVUartParas.shBackNChar )
} // end of if ( struSendRCVUartParas.shBackNChar > 0 )
// end of if ( struSendRCVUartParas.shHasParsedUartBufIndex==0 )
} else if ( struSendRCVUartParas.shHasParsedUartBufIndex > 0 ) {
nHasParserBytes += struSendRCVUartParas.shHasParsedUartBufIndex;
} // end of if ( struSendRCVUartParas.shHasParsedUartBufIndex > 0 )
if ( struSendRCVUartParas.cParsRspTypeStatus == 1 ) {
#if 0
unsigned char *pGSMDataBuf;
unsigned short shGSMDataLen=0;
#endif
// We have get valid incoming data, no matter that
// we should already know or not. Just only pre-porcessing it.
//if ( gw_nRCVState_RF_MS >= 0 ) {
// PLUS Respn\onse: CMTI, CPIN, CSQ, CMGR, CMGL, AIPA, etc
fHasGetResp = 1;
nNeedProcessRsp++;
//} // end of if ( gw_nRCVState_RF_MS > 0 )
#if 0
pGSMDataBuf = struSendRCVUartParas.pRcvUartBufData;
shGSMDataLen = struSendRCVUartParas.shHasParsedUartBufIndex;
sprintf(gw_szOutBuffer,"\r\n++ Get Rsp sentencs: (%d:%d) ++\r\n", pGSMDataBuf, shGSMDataLen);
//uartWrite(UART3,(uint8 *)gw_szOutBuffer,strlen(gw_szOutBuffer),NULL);
__DBG2_printf1(gw_szOutBuffer);
// Parser completely and get some valid incoming message
switch (gw_nRCVState_RF_MS) {
case 0: // RCV_STARP_PLUS_UNKNOW
break;
case 1: //RCV_STARP_PLUS_READY:
break;
case 2: //RCV_STARP_PLUS_OK:
break;
case 3: //RCV_STARP_PLUS_ERROR:
break;
case 4: //RCV_STARP_PLUS_CLIP:
if((p=strstr((char *)pGSMDataBuf,"+CLIP"))!=NULL)
MotormanLoadingOrExit(pGSMDataBuf, &shGSMDataLen); //駕駛員登陸或退出
break;
case 5: //RCV_STARP_PLUS_CPIN:
break;
case 6: //RCV_STARP_PLUS_CSQ:
if((p=strstr((char *)pGSMDataBuf,"+CSQ: "))!=NULL)
{
char temp[2];
memset(temp,0,sizeof(temp));
p+=strlen("+CSQ: ");
if((*(p+1)>=0x30)&&(*(p+1)<=0x39))
{
temp[0]=*p;
temp[1]=*(p+1);
}
else
temp[0]=*p;
CSQVal=(uint8)atoi(temp);
}
break;
case 7: //RCV_STARP_PLUS_CMGF:
break;
case 8: //RCV_STARP_PLUS_CMTI:
{
char strAT[30];
char * str="\r\nAT+CMGR=";
memset(strAT,0,sizeof(strAT));
if((p=strstr((char *)pGSMDataBuf,"\","))!=NULL)
{
//取短信標號
char * p2=NULL;
p+=strlen("\",");
if((p2=strstr(p,"\r\n"))!=NULL)
{
memset(MsgNum,0,sizeof(MsgNum));
memcpy(MsgNum,p,p2-p);
strcat(strAT,str);
memcpy(strAT+strlen(str),p,p2-p);
strcat(strAT,"\r\n");
uartWrite(UART2,(uint8 *)("\r\nAT+CMGF=1\r\n\0"),strlen("\r\nAT+CMGF=1\r\n\0"),NULL);
OSTimeDlyHMSM(0,0,0,300);
uartWrite(UART2,(uint8 *)strAT,strlen(strAT),NULL);
}
}
}
break;
case 9: //RCV_STARP_PLUS_CMGR:
if((p=strstr((char *)pGSMDataBuf,"+CMGR"))!=NULL)
MsgWatchOrSet(pGSMDataBuf, &shGSMDataLen); //手機調度及自定義手機查詢設置
break;
case 10: //RCV_STARP_PLUS_CMGL:
break;
case 11: //RCV_STARP_PLUS_CMGS:
break;
case 12: //RCV_STARP_PLUS_CMGS_SENDMODE:
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -