<AT框架>做什么
<AT框架>介绍
ATFrame
流程
-
开启AT流程: ATCommandRegister(CSQ,EXEXCMD,NULL);
发送消息队列xQueueSend(ATcmdQueue,(void *) &RegcommandInfo,(TickType_t)100) -
AT主流程 ATCommandSendScheduler
- 等待开启xQueueReceive(ATcmdQueue, (void *)&SendATInfo, (TickType_t)portMAX_DELAY);
- 嫁接AT指令:AT+动作(执行、读取’?‘、写入’=')+结束符(\r\n)
- 等待串口信号量:xSemaphoreTake(ATRXCplSemaphore,pdMS_TO_TICKS(ATMaxResponseTime));
-
串口中断USER_UART_IDLECallback
- 获取数据 UartRXBuff
- 给主流程信号量 xSemaphoreGiveFromISR(ATRXCplSemaphore,&xHightPriorityTaskWoken);
-
继续AT主流程 ATCommandSendScheduler
- 检查回显:CheckEcho(SendATInfo,UartRXBuff,&ReStr)!=ATSUCCESS
- 执行回调:ATResult=ATCommandList[SendATInfo.RegCommandName].ATRxCpltCallback(ReStr);
void ATCommandSendScheduler(void)
{
BaseType_t xResult;
ATStatus ATResult;
ATCommandRegInfo SendATInfo;
//队列等待数据
xResult = xQueueReceive(ATcmdQueue, (void *)&SendATInfo, (TickType_t)portMAX_DELAY);
if(xResult != pdPASS)
{
__ERRORLOG("读取队列数据失败");
}
//发送AT指令并数据处理
int ATMaxResponseTime = ATCommandList[SendATInfo.RegCommandName].MaxResponseTime;
int ATRetryCount = ATCommandList[SendATInfo.RegCommandName].MaxTryCount;
int ATResetCount = ATCommandList[SendATInfo.RegCommandName].MaxResetCount;
char *ATSendCommand = ATCommandList[SendATInfo.RegCommandName].ATStr;
char *ATSendParam = SendATInfo.RegCommandParam;
for(int j=0;j<ATResetCount;j++)
{ //发送失败后重启
for(int i=0;i<ATRetryCount;i++)
{//发送失败后重试
__LOG("---------------------------------------------------------");
__LOG("发送次数:%d",i);
switch((int)SendATInfo.RegCommandType)
{
case EXEXCMD:{
SendMultiStr(3,ATSendCommand,ATSendParam,"\r\n");
}break;
case READCMD:{
SendMultiStr(4,ATSendCommand,"?",ATSendParam,"\r\n");
}break;
case WRITECMD:{
SendMultiStr(4,ATSendCommand,"=",ATSendParam,"\r\n");
}break;
default:{
__ERRORLOG("未知命令类型");
} break;
}
//等待中断接收完数据
xResult=xSemaphoreTake(ATRXCplSemaphore,pdMS_TO_TICKS(ATMaxResponseTime));
if(xResult != pdPASS)
{ //等待数据超时,重新发起下一次请求
__ERRORLOG("等待数据超时,重新发起下一次请求");
continue;
}
//进入接收数据处理回调函数
//检查回显
char * ReStr;
if(CheckEcho(SendATInfo,UartRXBuff,&ReStr)!=ATSUCCESS)
{continue;}
//检查结束状态
if(CheckEnd(ReStr)!=ATSUCCESS)
{continue;}
if(ATCommandList[SendATInfo.RegCommandName].ATRxCpltCallback!=NULL)
{
__LOGNOLF("接收参数为:%s",ReStr);
ATResult=ATCommandList[SendATInfo.RegCommandName].ATRxCpltCallback(ReStr);
if(ATResult==ATSUCCESS)
{return;}
}else
{
return;
}
}
}
}
AT Device
<AT框架>使用
<AT指令>介绍
AT指令介绍
MCU发AT指令,通讯模块响应返回