5.测试实例分析- #include "LSD_WLAN_AT_CMD.h"
- #include "task.h"
- #include <stdarg.h>
- #include "queue.h"
- #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
- #define pdTRUE 1
- #define LSD_ERR_OK 1
- main()
- {
- unsigned char *Buf = NULL;
- unsigned int bufLen;
- char *at_type={"AT_CMD\ri\n"};
- if (pdTRUE == xQueueReceive(xQueueUart2AT, (void *)&Buf, (portTickType)portMAX_DELAY))
- {
- if (Buf == NULL)
- {
- continue;
- }
- bufLen = strlen(Buf);
- if ( lsdat_send_cmd(Buf,bufLen,at_type,strlen(at_type)) == LSD_ERR_OK )
- {
- printf("send cmd ok !);
- }
- else
- {
- printf("send Fail !);
- }
- }
- }
复制代码
要发送指令,首先要通过FreeRTOS操作系统的xQueueReceive函数从xQueueUart2AT队列中接收数据单元,而接收到的单元同时会从队列中删除。接收到的数据存到Buf中,然后通过lsd_send_cmd函数将AT指令发送出去。发送成功后会返回成功。 - #include "LSD_WLAN_AT_CMD.h"
- #include "task.h"
- #include <stdarg.h>
- #include "queue.h"
- #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
- #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
- extern xQueueHandle xQueueUart2AT;
- main()
- {
- if (xQueueUart2AT == NULL)
- {
- at_init();
- xTaskCreate(at_cmd_task,(uint8_t const*)"at_cmd",320,NULL,4,NULL);
- }
- else
- {
复制代码
先判断接收串口数据的队是否为空,该队列用于缓存待处理的串口数据,如过队列不为空会通过xQueueCreate函数清空队列。则会返回失败,无法创建at_cmd_task任务,那就无法将AT指令传给回调函数。 在保证xQueueUart2AT 为空的情况下,利用Free RTOS操作系统的任务创建函数,其中分配给任务的栈空间大小为320字节,优先级仅次于串口接收和发送的优先级,AT指令的优先级为4。
|