查看: 952|回复: 0

[技术交流] Wi-Fi SOC AT指令通信源码分析和实例分析(4)

[复制链接]

185

主题

204

帖子

596

积分

利尔达员工

Rank: 9Rank: 9Rank: 9

积分
596
发表于 2020-8-25 11:36:25 | 显示全部楼层 |阅读模式
5.测试实例分析
  1. #include "LSD_WLAN_AT_CMD.h"
  2. #include "task.h"
  3. #include <stdarg.h>
  4. #include "queue.h"
  5. #define xQueueReceive( xQueue, pvBuffer, xTicksToWait )  xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
  6. #define  pdTRUE 1
  7. #define  LSD_ERR_OK        1
  8. main()
  9. {
  10.     unsigned char *Buf = NULL;
  11.     unsigned int bufLen;
  12.     char *at_type={"AT_CMD\ri\n"};
  13.     if (pdTRUE == xQueueReceive(xQueueUart2AT, (void *)&Buf, (portTickType)portMAX_DELAY))
  14.     {
  15.         if (Buf == NULL)
  16.         {
  17.              continue;
  18.         }
  19.         bufLen = strlen(Buf);
  20.        if ( lsdat_send_cmd(Buf,bufLen,at_type,strlen(at_type)) == LSD_ERR_OK )
  21.        {
  22.             printf("send cmd ok !);
  23.        }
  24.        else
  25.       {
  26.             printf("send Fail !);
  27.       }

  28.    }
  29. }
复制代码

     要发送指令,首先要通过FreeRTOS操作系统的xQueueReceive函数从xQueueUart2AT队列中接收数据单元,而接收到的单元同时会从队列中删除。接收到的数据存到Buf中,然后通过lsd_send_cmd函数将AT指令发送出去。发送成功后会返回成功。
  1. #include "LSD_WLAN_AT_CMD.h"
  2. #include "task.h"
  3. #include <stdarg.h>
  4. #include "queue.h"
  5. #define xQueueCreate( uxQueueLength, uxItemSize )  xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
  6. #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
  7. extern xQueueHandle xQueueUart2AT;
  8. main()
  9. {
  10.     if (xQueueUart2AT == NULL)
  11.     {
  12.         at_init();
  13.         xTaskCreate(at_cmd_task,(uint8_t const*)"at_cmd",320,NULL,4,NULL);
  14.     }
  15.     else
  16.    {
复制代码

先判断接收串口数据的队是否为空,该队列用于缓存待处理的串口数据,如过队列不为空会通过xQueueCreate函数清空队列。则会返回失败,无法创建at_cmd_task任务,那就无法将AT指令传给回调函数。
    在保证xQueueUart2AT 为空的情况下,利用Free RTOS操作系统的任务创建函数,其中分配给任务的栈空间大小为320字节,优先级仅次于串口接收和发送的优先级,AT指令的优先级为4


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表