?? modemgtm900.c
字號:
** 功能描述: 讀MODEM設備的信源和輸入電平
** 輸 入: INT8U *dest,總的返回字節長度為9字節,依次順序為:運營商代碼(1),位置區編碼(2),
基站識別碼(1),BCCH絕對載頻號(2),BCCH接收電平(有符號數,1),小區識別碼實時值(2)
** 輸 出: TRUE,表示成功讀取modem的信源信息;
FALSE,表示讀取modem信源信息不成功
********************************************************************************
*/
BOOLEAN ModemReadEquipInfo( OUT INT8U *dest)
{
if((GetModemStat() == MODEM_SMS)||(GetModemStat() == MODEM_DATA))
{
memcpy(dest,ModemInfo,9);
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////
void ModemEquipInfoPro(X_PACKET *ptrTemp)
{
DATACONV temp;
INT8U i,j;
i = 0;
for(j = 0; j < 5; j ++)
{
while( ptrTemp->pBuf[i] < 0x30)
i ++;
temp.integ = ptrTemp->pBuf[i] - 0x30;
i ++;
while(ptrTemp->pBuf[i] > 0x2f)
{
temp.integ = temp.integ * 10 + (ptrTemp->pBuf[i] - 0x30);
i ++;
}
ptrTemp->pBuf[j * 2] = temp.chr[0];
ptrTemp->pBuf[j * 2 + 1] = temp.chr[1];
}
ModemInfo[4] = ptrTemp->pBuf[0];
ModemInfo[5] = ptrTemp->pBuf[1];
ModemInfo[6] = -ptrTemp->pBuf[4] + 20; //20的耦合器補償
ModemInfo[0] = ptrTemp->pBuf[8];
for(j = 0; j < 2; j ++)
{
while( ptrTemp->pBuf[i] < 0x30)
i ++;
if(ptrTemp->pBuf[i]> 0x39)
ptrTemp->pBuf[i] -= 0x37;
else
ptrTemp->pBuf[i] -= 0x30;
temp.integ = ptrTemp->pBuf[i];
i ++;
while(ptrTemp->pBuf[i] > 0x2f)
{
if(ptrTemp->pBuf[i] > 0x39)
ptrTemp->pBuf[i] -= 0x37;
else
ptrTemp->pBuf[i] -= 0x30;
temp.integ = temp.integ * 256 + ptrTemp->pBuf[i];
i ++;
}
ptrTemp->pBuf[j * 2] = ((temp.chr[1] << 4) & 0XF0) +temp.chr[0];
ptrTemp->pBuf[j * 2 + 1] = ((temp.chr[3] << 4) & 0XF0) + temp.chr[2];
}
ModemInfo[1] = ptrTemp->pBuf[0];
ModemInfo[2] = ptrTemp->pBuf[1];
ModemInfo[7] = ptrTemp->pBuf[2];
ModemInfo[8] = ptrTemp->pBuf[3];
for(j = 0; j < 2; j ++)
{
while( ptrTemp->pBuf[i] < 0x30)
i ++;
temp.integ = ptrTemp->pBuf[i] - 0x30;
i ++;
while(ptrTemp->pBuf[i] > 0x2f)
{
temp.integ = temp.integ * 10 + (ptrTemp->pBuf[i] - 0x30);
i ++;
}
ptrTemp->pBuf[j * 2] = temp.chr[0];
ptrTemp->pBuf[j * 2 + 1] = temp.chr[1];
}
ModemInfo[3] = ptrTemp->pBuf[0] * 8 + ptrTemp->pBuf[2];
}
/******************************************************************************
**函數名稱:ATCmdPRO
**函數功能:AT命令接收解析 SMS方式接收
******************************************************************************/
void ATCmdRcvPro(INT8U fchr)
{
INT8U ch,err;
INT8U i,j;
DATACONV temp;
X_PACKET *ptrTemp = NULL;
FlagModemSmsRcv = 0;
FlagModemSmsRcv = 1;
ptrTemp = GetPcktBuf();
while(ptrTemp == NULL)
{
OSTimeDly(OS_TICKS_PER_SEC/200);//延時5ms
ptrTemp = GetPcktBuf();
#ifdef DEBUG_MODEM
printf("\r\n when receive sms,no packet %s, line %u\n",__FILE__, __LINE__ );
#endif
}
ptrTemp->pBuf[0] = fchr;
for(i = 1; i < MAX_BUFLEN - 1; i ++)
{
ch = EXTUARTGetchTmA(OS_TICKS_PER_SEC/10,&ptrTemp->pBuf[i]);
if(ch == OS_TIMEOUT)
{
break;
}
if(ptrTemp->pBuf[i] == 0x0D)
{
ptrTemp->Info.bufLen = i + 1;
break;
}
}
if (ch != OS_TIMEOUT)
{
//優化處理
for(j = 0; j < 4; j ++)
{
temp.chr[j] = ptrTemp->pBuf[4 - j]; //ARM為小端系統
}
switch(temp.integ)
{
case 0x2043684D: //Q ChMod,讀信源信息
{
err = EXTUARTGetchTmA(OS_TICKS_PER_SEC/2,&ch);
for(i = 0; i < MAX_BUFLEN - 1; i ++)
{
ch = EXTUARTGetchTmA(OS_TICKS_PER_SEC/10,&ptrTemp->pBuf[i]);
if((ch == OS_TIMEOUT) || (ptrTemp->pBuf[i] == 0x0D))
{
break;
}
}
if(( i < MAX_BUFLEN) && (ch != OS_TIMEOUT) && (i > 50) && (ptrTemp->pBuf[2] != 'S'))
{
ModemEquipInfoPro(ptrTemp);
ModemCnt = 0;
}
else if(ptrTemp->pBuf[2] == 'S')
{
ModemCnt ++;
}
FreePcktBuf(ptrTemp);
break;
}
case 0x434D474C: //CMGL 列出卡中短信
{
#ifdef DEBUG_MODEM
INT8U k = 0;
#endif
for(j = i + 1; j < MAX_BUFLEN - 1; j ++)
{
#ifdef DEBUG_MODEM
if(ReadPowerInfo(10) == FALSE)
{
turnOnLed(0,k);
if(k == 0)
k = 2;
else
k = 0;
}
#endif
ch = EXTUARTGetchTmA(OS_TICKS_PER_SEC / 10,&ptrTemp->pBuf[j]);
if(ch != OS_TIMEOUT)
{
if(ptrTemp->pBuf[j] == 0x0D)
{
ptrTemp->Info.bufLen = j;
ptrTemp->pBuf[j + 1] = '\0';
ptrTemp->Info.comType = COM_SMS;
ptrTemp->Info.srcPort = PKT_PORT_MODEM;
break;
}
}
else
{
break;
}
}
ptrTemp->pBuf[j + 1] = '\0'; //wjx
//發送命令(AT),MODEM中斷短信的LIST并回復ERROR
//防止后面還在LIST時發送的AT命令無效
OSSemPend(EXTUARTSemShareA, 0, &err);
EXTUARTWriteA((INT8U *)ST_M_ATAT,strlen((const char *)ST_M_ATAT));
OSSemPost(EXTUARTSemShareA);
#ifdef DEBUG_MODEM
if(ReadPowerInfo(10) == FALSE)
{
printf("\r\nreceived sms %s, line %u\n",__FILE__, __LINE__ );
//DebugOut(ptrTemp->pBuf,ptrTemp->Info.bufLen);
//DebugOut((INT8U *)"\r\n",2);
turnOnLed(0,0);
}
#endif
if(ch != OS_TIMEOUT)
{
if(ModemSMSPro(ptrTemp,0) == TRUE)
{
#ifdef DEBUG_MODEM
printf("authentic passed %s, line %u\n",__FILE__, __LINE__ );
#endif
OSQPost(QueuePcktApNpa, ptrTemp);
break;
}
}
FreePcktBuf(ptrTemp);
break;
}
case 0x434D4753: //CMGS
{
FreePcktBuf(ptrTemp);
OSSemPost(SMSSndSuc);
break;
}
case 0x434D5449: //CMTI
{
FreePcktBuf(ptrTemp);
#ifdef DEBUG_MODEM
printf("receive sms CMTI: %s, line %u\n",__FILE__, __LINE__ );
#endif
break;
}
case 0x434C4950: //CLIP
{
#ifdef DEBUG_MODEM
//DebugOut(ptrTemp->pBuf,ptrTemp->Info.bufLen);
//DebugOut((INT8U*)"\r\n",2);
#endif
//在此鑒權 如果鑒權不通過,掛斷來電
ReadTel(ptrTemp->pBuf,ptrTemp->Info.telNum);
ptrTemp->Info.comType = COM_DATA;
if(AuthPcktBuf(ptrTemp) != TRUE)
{
#ifdef DEBUG_MODEM
printf("\r\nthe calling not passed authentic %s, line %u\n",__FILE__, __LINE__ );
#endif
OSSemPend(EXTUARTSemShareA,OS_TICKS_PER_SEC / 10,&err);
EXTUARTWriteA((INT8U *)ST_M_ATH,strlen((const char *)ST_M_ATH));
OSSemPost(EXTUARTSemShareA);
}
else
{
#ifdef DEBUG_MODEM
printf("\r\n the calling passed authentic %s, line %u\n",__FILE__, __LINE__ );
#endif
DataFlag ++;
ConnectTimeOut = OSTimeGet() + 40 * OS_TICKS_PER_SEC;
}
FreePcktBuf(ptrTemp);
break;
}
case 0x434D543A: //CMT: 自動上發的短信接收
{
#ifdef DEBUG_MODEM
INT8U k = 0;
#endif
for(j = i + 1; j < MAX_BUFLEN - 1; j ++)
{
#ifdef DEBUG_MODEM
if(ReadPowerInfo(10) == FALSE)
{
turnOnLed(0,k);
if(k == 0)
k = 2;
else
k = 0;
}
#endif
ch = EXTUARTGetchTmA(OS_TICKS_PER_SEC / 10,&ptrTemp->pBuf[j]);
if(ch != OS_TIMEOUT)
{
if(ptrTemp->pBuf[j] == 0x0D)
{
ptrTemp->Info.bufLen = j;
ptrTemp->pBuf[j + 1] = '\0';
ptrTemp->Info.comType = COM_SMS;
ptrTemp->Info.srcPort = PKT_PORT_MODEM;
break;
}
}
else
{
break;
}
}
#ifdef DEBUG_MODEM
printf("\r\nreceive sms: %s, line %u\n",__FILE__, __LINE__ );
turnOnLed(0,0);
#endif
if(ch != OS_TIMEOUT)
{
if(ModemSMSPro(ptrTemp,1) == TRUE) //對接收到的短信進行處理,解碼
{
#ifdef DEBUG_MODEM
printf("sms passed authentic %s, line %u\n",__FILE__, __LINE__ );
#endif
SMSSendDelay = OSTimeGet() + SmsSendSpan * OS_TICKS_PER_SEC;
OSQPost(QueuePcktApNpa, ptrTemp);
break;
}
}
FreePcktBuf(ptrTemp);
break;
}
default:
{
FreePcktBuf(ptrTemp);
break;
}
}
}
else
{
FreePcktBuf(ptrTemp);
}
}
/*******************************************************************************
** 函數名稱: ModemDataRcvPRO
** 功能描述: modem數傳模式下的接收處理 語音數傳
** 輸 入: 無
*******************************************************************************/
void ModemDataRcvPRO(void)
{
INT8U ch,err,*pt1;
INT32U i,j;
DATACONV crc;
X_PACKET *ptrTemp = NULL;
err = EXTUARTGetchTmA(OS_TICKS_PER_SEC/2,&ch);
if((err == OS_TIMEOUT) || (ch != 'X'))
return;
ptrTemp = GetPcktBuf();
while(ptrTemp == NULL)
{
OSTimeDly(OS_TICKS_PER_SEC/200);//延時5ms
ptrTemp = GetPcktBuf();
}
pt1 = (INT8U *)ptrTemp->pBuf;
for(i = 0; i < MAX_BUFLEN - 1; i ++)
{
err = EXTUARTGetchTmA(OS_TICKS_PER_SEC / 10,pt1);
if(err != OS_TIMEOUT)
{
if(*pt1 == 'X')
{
if(i >= 28)
{
ptrTemp->Info.bufLen = i - 2; //該長度僅表示AP層協議包長度,不包括CRC
ptrTemp->Info.comType = COM_DATA;
ptrTemp->Info.srcPort = PKT_PORT_MODEM;
break;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -