20260107:实现简单的MQTT协议。
This commit is contained in:
@@ -40,7 +40,7 @@ void vUsartInit(USART_TypeDef *xUsartId, uint32_t ulBaudrate)
|
||||
NVIC_InitTypeDef NVIC_InitStructure; // <20><>ʼ<EFBFBD><CABC>NVIC<49><43>USART1ͨ<31><CDA8>
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; // <20>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5; // <20><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>FreeRTOS<4F><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>ڷ<EFBFBD>Χ<EFBFBD>ڿ<EFBFBD><DABF>Ե<EFBFBD><D4B5><EFBFBD>FreeRTOS<4F><53><EFBFBD>ԡ<EFBFBD>FromISR()<29><><EFBFBD><EFBFBD>β<EFBFBD><CEB2>api<70><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6; // <20><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>FreeRTOS<4F><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>ڷ<EFBFBD>Χ<EFBFBD>ڿ<EFBFBD><DABF>Ե<EFBFBD><D4B5><EFBFBD>FreeRTOS<4F><53><EFBFBD>ԡ<EFBFBD>FromISR()<29><><EFBFBD><EFBFBD>β<EFBFBD><CEB2>api<70><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // <20><>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
NVIC_Init(&NVIC_InitStructure); // ָ<><D6B8>NVIC_InitStructure<72>ĵ<EFBFBD>ַ
|
||||
|
||||
@@ -221,6 +221,7 @@ void USART1_IRQHandler(void)
|
||||
{
|
||||
/* code */
|
||||
#if (USE_RTOS == NONE)
|
||||
|
||||
#elif (USE_RTOS == FREERTOS && ENABLE_FREERTOS_API_QUEUE_USART1_IRQ == 1)
|
||||
uint8_t ulRxData = (uint8_t)USART_ReceiveData(USART1);
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
@@ -244,17 +245,17 @@ void USART2_IRQHandler(void)
|
||||
{
|
||||
#if (USE_RTOS == NONE && defined __ESP8266_SAMPLE_H__)
|
||||
uint8_t ulRxData;
|
||||
if ( USART_GetITStatus ( macESP8266_USART, USART_IT_RXNE ) != RESET )
|
||||
if ( USART_GetITStatus ( USART2, USART_IT_RXNE ) != RESET )
|
||||
{
|
||||
ulRxData = USART_ReceiveData( macESP8266_USART );
|
||||
if ( strEsp8266_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) ) //Ԥ<><D4A4>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ++ ] = ulRxData;
|
||||
ulRxData = USART_ReceiveData( USART2 );
|
||||
if ( xSerialFrameRecord .Bits_t .usFrameLength < ( BUFFER_MAX_LENGTH - 1 ) ) //Ԥ<><D4A4>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
xSerialFrameRecord .cSerialReceivedBuffer [ xSerialFrameRecord .Bits_t .usFrameLength ++ ] = ulRxData;
|
||||
}
|
||||
if ( USART_GetITStatus( macESP8266_USART, USART_IT_IDLE ) == SET ) //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if ( USART_GetITStatus( USART2, USART_IT_IDLE ) == SET ) //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
strEsp8266_Fram_Record .InfBit .FramFinishFlag = 1;
|
||||
ulRxData = USART_ReceiveData( macESP8266_USART ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ(<28>ȶ<EFBFBD>USART_SR<53><52>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>USART_DR)
|
||||
ucTcpClosedFlag = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CLOSED\r\n" ) ? 1 : 0;
|
||||
xSerialFrameRecord .Bits_t .usFrameFinishFlag = 1;
|
||||
ulRxData = USART_ReceiveData( USART2 ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ(<28>ȶ<EFBFBD>USART_SR<53><52>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>USART_DR)
|
||||
ucTcpClosedFlag = strstr ( xSerialFrameRecord .cSerialReceivedBuffer, "CLOSED\r\n" ) ? 1 : 0;
|
||||
}
|
||||
#elif (USE_RTOS == FREERTOS && ENABLE_FREERTOS_API_QUEUE_USART2_IRQ == 1)
|
||||
if (USART_GetITStatus(USART2, USART_IT_RXNE) == SET)
|
||||
@@ -269,17 +270,17 @@ void USART2_IRQHandler(void)
|
||||
}
|
||||
#elif (USE_RTOS == FREERTOS && ENABLE_FREERTOS_API_QUEUE_USART2_IRQ == 0)
|
||||
uint8_t ulRxData;
|
||||
if ( USART_GetITStatus ( macESP8266_USART, USART_IT_RXNE ) != RESET )
|
||||
if ( USART_GetITStatus ( USART2, USART_IT_RXNE ) != RESET )
|
||||
{
|
||||
ulRxData = USART_ReceiveData( macESP8266_USART );
|
||||
if ( strEsp8266_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) ) //Ԥ<><D4A4>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ++ ] = ulRxData;
|
||||
ulRxData = USART_ReceiveData( USART2 );
|
||||
if ( xSerialFrameRecord .Bits_t .usFrameLength < ( BUFFER_MAX_LENGTH - 1 ) ) //Ԥ<><D4A4>1<EFBFBD><31><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
xSerialFrameRecord .cSerialReceivedBuffer [ xSerialFrameRecord .Bits_t .usFrameLength ++ ] = ulRxData;
|
||||
}
|
||||
if ( USART_GetITStatus( macESP8266_USART, USART_IT_IDLE ) == SET ) //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if ( USART_GetITStatus( USART2, USART_IT_IDLE ) == SET ) //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
strEsp8266_Fram_Record .InfBit .FramFinishFlag = 1;
|
||||
ulRxData = USART_ReceiveData( macESP8266_USART ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ(<28>ȶ<EFBFBD>USART_SR<53><52>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>USART_DR)
|
||||
ucTcpClosedFlag = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CLOSED\r\n" ) ? 1 : 0;
|
||||
xSerialFrameRecord .Bits_t .usFrameFinishFlag = 1;
|
||||
ulRxData = USART_ReceiveData( USART2 ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ(<28>ȶ<EFBFBD>USART_SR<53><52>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>USART_DR)
|
||||
ucTcpClosedFlag = strstr ( xSerialFrameRecord .cSerialReceivedBuffer, "CLOSED\r\n" ) ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -293,6 +294,7 @@ void USART2_IRQHandler(void)
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
#if (USE_RTOS == NONE)
|
||||
|
||||
#elif (USE_RTOS == FREERTOS && ENABLE_FREERTOS_API_QUEUE_USART3_IRQ == 1)
|
||||
if (USART_GetITStatus(USART3, USART_IT_RXNE) == SET)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#elif (USE_RTOS == FREERTOS)
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
#define ENABLE_FREERTOS_API_QUEUE_USART1_IRQ 1
|
||||
#define ENABLE_FREERTOS_API_QUEUE_USART1_IRQ 0
|
||||
#define ENABLE_FREERTOS_API_QUEUE_USART2_IRQ 0
|
||||
#define ENABLE_FREERTOS_API_QUEUE_USART3_IRQ 1
|
||||
#endif
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "ESP8266.h"
|
||||
|
||||
#if (ENABLE_FREERTOS_API_QUEUE_USART1_IRQ == 1)
|
||||
extern QueueHandle_t xQueueUsart1IrqHdlr;
|
||||
@@ -48,6 +47,21 @@
|
||||
extern QueueHandle_t xQueueUsart3IrqHdlr;
|
||||
#endif
|
||||
|
||||
extern volatile uint8_t ucTcpClosedFlag;
|
||||
|
||||
#define BUFFER_MAX_LENGTH 1024 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
extern struct SerialFrame_t // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
{
|
||||
char cSerialReceivedBuffer [ BUFFER_MAX_LENGTH ];
|
||||
union {
|
||||
__IO uint16_t usInfoAll;
|
||||
struct {
|
||||
__IO uint16_t usFrameLength :15; // 14:0
|
||||
__IO uint16_t usFrameFinishFlag :1; // 15
|
||||
} Bits_t;
|
||||
};
|
||||
} xSerialFrameRecord;
|
||||
|
||||
void vUsartInit(USART_TypeDef *xUsartId, uint32_t ulBaudrate);
|
||||
void vUsartSendByte(USART_TypeDef *xUsartId, uint8_t ucByte);
|
||||
void vUsartSendArray(USART_TypeDef *xUsartId, uint8_t *pucArray, uint16_t usLength);
|
||||
|
||||
Reference in New Issue
Block a user