1 通过串口或者虚拟串口发送指令
2 等待串口返回消息
3 处理消息
使用AT其实很简单:
范例如下:
BOOL CSMGTask::GsmDial (MESSAGE *pmsg)
{
CHAR cmd[COM_WRITE_NORMAL_SIZE];
BYTE result;
BYTE Gain = 0;
if(ChageSpeakerChannel(g_SysStatus.FlagEarphone) == FALSE)//设置音频状态
{
result = 0 ;
SendMsg(TASK_SMG, TASK_MMI, MMIM_OutGoingRequestRespond_G, 1, &result);
return FALSE;
}
#if 0
//开机init时先调节音量
Gain = CProfileData::GetGSMEarVolume(CProfileData::GetIndex());
if(EarphoneGainControl(Gain) == FALSE)
{
result = 0 ;
SendMsg(TASK_SMG, TASK_MMI, MMIM_OutGoingRequestRespond_G, 1, &result);
return FALSE;
}
#endif
sprintf(cmd, "ATD%s;/r",pmsg->Union.content);//参照AT指令集写的
return Send_Receive_Data(cmd, DEDUALT_TIME_OUT, GsmTestreult);//发给模块并且等待响应,反馈处理函数GsmTestreult()
}
=================================相关函数
---------发送函数
INT CSMGTask::Send_Receive_Data(CHAR * cmd, INT delay, BOOL (* at_fun)(CHAR * str, WORD length))
{
INT re = FALSE;
WORD bufferlength = 0;
if(CSMGTask::GetGsmTurnDownFlag() == TRUE)
{
smgdebug0("Se_Re off/r/n");
return re;
}
if(g_AppExit)//应用退出
{
return re;
}
int count=strlen(cmd);
memset(Gsm_Send_Data,0,sizeof(Gsm_Send_Data));
char* p=cmd;
char* p1=Gsm_Send_Data;
while(*p!='=' && *p!='?' && *p!='/r' && *p!='/n')
{
*p1++=*p++;
}
HW_UART1_Send_Data(cmd, count);//发送数据
MmiSleep(30);
/*char buff[100]={0};
sprintf(buff, "cmd=%s/r/n",cmd);
HW_Printf((unsigned char *) buff);*/
smgdebug1("cmd=%s/r/n",cmd);
NU_Reset_Timer(TIMEROUT_TIMER, Expire_CkeckTimeout,
TICKFROMMS(delay), TICKFROMMS(DEDUALT_TIME_OUT), NU_ENABLE_TIMER);
memset(gAtbuffer, 0, COM_READ_HUGE_SIZE);
while(( bufferlength = HW_UART1_Receive_Data(0, gAtbuffer, COM_READ_BIG_SIZE))==0 && timeout == FALSE)
{
if(CSMGTask::GetGsmTurnDownFlag() == TRUE)
{
return re;
}
if(g_AppExit)
{
return re;
}
MmiSleep(5);
}
smgdebug1("ans=%s/r/n",gAtbuffer);
if(timeout == TRUE)
{
timeout = FALSE;
re = FALSE;
}
else
{
NU_Control_Timer(TIMEROUT_TIMER, NU_DISABLE_TIMER);//启动个定时器
re = (*at_fun)(gAtbuffer,bufferlength);
}
return re;
}
-------------反馈处理函数
BOOL GsmTestreult(CHAR * atbuffer, WORD length)
{
DetectMessage(atbuffer, length);
if((memstr(atbuffer, length, "ERROR")) != NULL)
{
return FALSE;
}
if((memstr(atbuffer, length, "OK")) != NULL)
{
return TRUE;
}
return FALSE;
}
可以参考我资源smg标准AT范例