generated from Template/H563ZI-HAL-CMake-Template
替换\n结尾,replace with $
This commit is contained in:
103
fun/HCBle.c
103
fun/HCBle.c
@@ -77,7 +77,7 @@ void HCBle_SendData(char *p,...)
|
||||
// <20><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>һ<EFBFBD><D2BB>DMA
|
||||
|
||||
|
||||
|
||||
// <20>ҷ<EFBFBD><D2B7>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD> --- \n <20><><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ծ<EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
if (huart->Instance == UART4)
|
||||
@@ -87,65 +87,44 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
uint8_t ch = uart_dma_rx_buf[i];
|
||||
uint16_t next_head = (ble_rx_ring.head + 1) % RING_BUFFER_SIZE;
|
||||
|
||||
if (next_head != ble_rx_ring.tail)
|
||||
{
|
||||
ble_rx_ring.buffer[ble_rx_ring.head] = ch;
|
||||
ble_rx_ring.head = next_head;
|
||||
}
|
||||
if(next_head != ble_rx_ring.tail)
|
||||
{
|
||||
ble_rx_ring.buffer[ble_rx_ring.head] = ch;
|
||||
ble_rx_ring.head = next_head;
|
||||
}
|
||||
}
|
||||
|
||||
tx_event_flags_set(&ble_event_flags, BLE_EVENT_DATA_READY, TX_OR);
|
||||
tx_event_flags_set(&ble_event_flags, BLE_EVENT_DATA_READY, TX_OR);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD> Json<6F><6E><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD> <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8>ֻ<EFBFBD>App
|
||||
|
||||
void HCBle_ParseAndHandleFrame(const char *frame)
|
||||
{
|
||||
int left, right;
|
||||
float lat, lon, angle;
|
||||
|
||||
void HCBle_ExtractAndParseFrame(void) {
|
||||
static char json_buf[128];
|
||||
static int idx = 0;
|
||||
static int parsing = 0;
|
||||
// if (sscanf(frame, "#{\"leftSpeed\":%d,\"rightSpeed\":%d}", &left, &right) == 2) {
|
||||
// cmd.LeftSpeed = left;
|
||||
// cmd.RightSpeed = right;
|
||||
// HCBle_SendData("? <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>: <20><>=%d, <20><>=%d\r\n", left, right);
|
||||
// return;
|
||||
// }
|
||||
|
||||
while (ble_rx_ring.tail != ble_rx_ring.head) {
|
||||
char c = ble_rx_ring.buffer[ble_rx_ring.tail];
|
||||
ble_rx_ring.tail = (ble_rx_ring.tail + 1) % RING_BUFFER_SIZE;
|
||||
|
||||
if (!parsing) {
|
||||
if (c == '#') {
|
||||
idx = 0;
|
||||
parsing = 1;
|
||||
memset(json_buf, 0, sizeof(json_buf));
|
||||
json_buf[idx++] = c;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx < sizeof(json_buf) - 1) {
|
||||
json_buf[idx++] = c;
|
||||
if (c == '\n') {
|
||||
json_buf[idx] = '\0';
|
||||
int left, right;
|
||||
if (sscanf(json_buf, "#{\"leftSpeed\":%d,\"rightSpeed\":%d}\n", &left, &right) == 2) {
|
||||
HCBle_SendData("? <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>: <20><>=%d, <20><>=%d\r\n", left, right);
|
||||
cmd.LeftSpeed = left;
|
||||
cmd.RightSpeed = right;
|
||||
} else {
|
||||
HCBle_SendData("? JSON<4F><4E>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>: %s\r\n", json_buf);
|
||||
}
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
}
|
||||
} else {
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
memset(json_buf, 0, sizeof(json_buf));
|
||||
}
|
||||
if (sscanf(frame, "%*[^0-9]%d%*[^0-9]%d", &left, &right) == 2) {
|
||||
cmd.LeftSpeed = left;
|
||||
cmd.RightSpeed = right;
|
||||
HCBle_SendData("? <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>: <20><>=%d, <20><>=%d\r\n", left, right);
|
||||
return;
|
||||
}
|
||||
|
||||
HCBle_SendData("? <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>: %s\r\n", frame);
|
||||
}
|
||||
|
||||
|
||||
//Ϊɶһֱʹ<D6B1>ò<EFBFBD><C3B2>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB>ٵȴ<D9B5>TX<54><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20>ں<EFBFBD>̨<EFBFBD><CCA8><EFBFBD>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>UART<52>յ<EFBFBD>BLE<4C><45><EFBFBD>ݺ<DDBA><F3B4A5B7><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD>
|
||||
void ble_rx_task_entry(ULONG thread_input)
|
||||
@@ -153,19 +132,47 @@ void ble_rx_task_entry(ULONG thread_input)
|
||||
HCBle_InitDMAReception();
|
||||
|
||||
ULONG actual_flags;
|
||||
static char json_buf[128];
|
||||
static int idx = 0;
|
||||
static int parsing = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
tx_event_flags_get(&ble_event_flags, BLE_EVENT_DATA_READY, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER);
|
||||
|
||||
if (actual_flags & BLE_EVENT_DATA_READY)
|
||||
while (ble_rx_ring.tail != ble_rx_ring.head)
|
||||
{
|
||||
HCBle_ExtractAndParseFrame();
|
||||
char c = ble_rx_ring.buffer[ble_rx_ring.tail];
|
||||
ble_rx_ring.tail = (ble_rx_ring.tail + 1) % RING_BUFFER_SIZE;
|
||||
|
||||
if (!parsing) {
|
||||
if (c == '#') {
|
||||
parsing = 1;
|
||||
idx = 0;
|
||||
json_buf[idx++] = c;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx < sizeof(json_buf) - 1) {
|
||||
json_buf[idx++] = c;
|
||||
if (c == '$') {
|
||||
json_buf[idx] = '\0';
|
||||
HCBle_SendData("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>json_buf: %s\r\n", json_buf);
|
||||
HCBle_ParseAndHandleFrame(json_buf);
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
}
|
||||
} else {
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// "#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",23.123456, 113.654321, 95.0);
|
||||
// HCBle_SendData("#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",
|
||||
// current_location.lat, current_location.lon, current_location.angle);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#define __HCBLE_H
|
||||
|
||||
#include "headfile.h"
|
||||
//#define DEBUG_EN 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> ʹ<><CAB9>DMA <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> <20><><EFBFBD><EFBFBD>ʽ
|
||||
#define DEBUG_EN 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> ʹ<><CAB9>DMA <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> <20><><EFBFBD><EFBFBD>ʽ
|
||||
#define RX_DataSize 128
|
||||
#define RING_BUFFER_SIZE 256
|
||||
#define UART_DMA_RX_BUF_SIZE 64
|
||||
#define UART_DMA_RX_BUF_SIZE 20
|
||||
|
||||
|
||||
// HCBle <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
||||
|
||||
10
fun/gps.c
10
fun/gps.c
@@ -161,14 +161,6 @@ void GPS_Data_CLR(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GPS_DMA_Start(void)
|
||||
{
|
||||
HAL_UART_Receive_DMA(&huart2,GPS_DMA_RX_BUF,GPS_DMA_RX_BUF_LEN);
|
||||
__HAL_DMA_ENABLE_IT(huart2.hdmarx,DMA_IT_HT); //<2F>봫<EFBFBD><EBB4AB><EFBFBD>ж<EFBFBD>
|
||||
__HAL_DMA_ENABLE_IT(huart2.hdmarx,DMA_IT_TC); //ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
|
||||
//void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
//{
|
||||
// if(huart->Instance == USART2)
|
||||
@@ -181,7 +173,6 @@ void GPS_DMA_Start(void)
|
||||
// tx_event_flags_set(&system_events, EVENT_GPS_DATA_READY, TX_OR);
|
||||
// //<2F><><EFBFBD>¿<EFBFBD><C2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// HAL_UARTEx_ReceiveToIdle_DMA(&huart2,GPS_DMA_RX_BUF,GPS_DMA_RX_BUF_LEN);
|
||||
// __HAL_DMA_DISABLE_IT(&handle_GPDMA1_Channel3,DMA_IT_HT);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -216,7 +207,6 @@ void gps_thread_entry(ULONG thread_input)
|
||||
current_location.angle);
|
||||
tx_queue_send(&ble_tx_queue, &msg, TX_WAIT_FOREVER);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user