Commit 991cbd06 authored by 薛小虎's avatar 薛小虎

feat: 整理与底板通信程序

parent 53a60fb7
...@@ -8,112 +8,6 @@ ...@@ -8,112 +8,6 @@
#include "app_Ble_User.h" #include "app_Ble_User.h"
void Uart_ID10_process(void)
{
uint8_t ID10[1] = {0x00};
if(1)//蓝牙模组启动状态
{
ID10[0] = 0x01;
Protocol_Send(0x10,ID10,1);
}
else
{
Protocol_Send(0x10,ID10,1);
}
// printf("send 0x10 \r\n");
}
void Uart_ID01_process(void)
{
uint8_t ID01[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
if(Ble_User.Navi_Updat)
{
ID01[0] = Ble_Navi_Data.Navi_Sts;
ID01[1] = Ble_Navi_Data.Navi_Turn;//赋值为蓝牙收到的转向编码值
ID01[2] = Ble_Navi_Data.Navi_Dte[0];
ID01[3] = Ble_Navi_Data.Navi_Dte[1];
ID01[4] = Ble_Navi_Data.Navi_Dte[2];
ID01[5] = Ble_Navi_Data.Navi_Dte[3];
}
Protocol_Send(0x01,ID01,6);
}
void Uart_ID12_process(void)
{
uint8_t ID12[1] = {0x00};
ID12[0] = Ble_User.Ble_Sts;
Protocol_Send(0x12,ID12,1);
}
void Uart_ID20_process(const Protocol_Data_t *pData)
{
//开始正式通信
}
void Uart_ID02_process(void)
{
uint8_t ID02[1] = {0x00};
ID02[0] = 0;//蓝牙电话状态
Protocol_Send(0x02,ID02,1);
}
uint8_t ID03[33] = {0x00};
void Uart_ID03_process(const Protocol_Data_t *pData)
{
if(pData->Data[0] == 1/*接到值为1*/)
{
//来电
}
else if (pData->Data[0] == 2/*接到值为2*/)
{
//去电
}
else if (pData->Data[0] == 3/*接到值为3*/)
{
//通话中
}
else/*默认值*/
{
//无动作
}
/*接到UUID,给蓝牙*/
unsigned int i = 1;
for ( i = 1; i < 33; i++)
{
ID03[i] = pData->Data[i+1];//接到串口传来的UUID值
}
}
// unsigned char ID21_num = 0;
// void Uart_ID21_process(const Protocol_Data_t *pData)//底板给ESP32发
// {
// if (1)
// {
// ID21_num++;
// }
// printf("ID21 IS %d!!!\r\n",ID21_num);
// }
void MCU_SOC_Commnuication(void)
{
Protocol_Service();
}
...@@ -2,14 +2,5 @@ ...@@ -2,14 +2,5 @@
#define _MCU_CORE_PROTOCOL_H_ #define _MCU_CORE_PROTOCOL_H_
#include "Protocol_Lib.h" #include "Protocol_Lib.h"
extern void Uart_ID10_process(void);
extern void Uart_ID01_process(void);
extern void Uart_ID12_process(void);
//extern void Uart_ID21_process(const Protocol_Data_t *pData);
extern void Uart_ID20_process(const Protocol_Data_t *pData);
extern void Uart_ID02_process(void);
extern void Uart_ID03_process(const Protocol_Data_t *pData);
void MCU_SOC_Commnuication(void);
#endif #endif
...@@ -254,6 +254,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui ...@@ -254,6 +254,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui
frameLen++; frameLen++;
} }
// 校验码 Checksum // 校验码 Checksum
checksum = getCheckSum(dataBuf + 2, frameLen - 2); checksum = getCheckSum(dataBuf + 2, frameLen - 2);
dataBuf [ frameLen ] = (checksum >> 8) & 0x00FF; dataBuf [ frameLen ] = (checksum >> 8) & 0x00FF;
...@@ -261,6 +262,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui ...@@ -261,6 +262,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui
dataBuf [ frameLen ] = checksum & 0x00FF; dataBuf [ frameLen ] = checksum & 0x00FF;
frameLen++; frameLen++;
if ( UARTSend_Cbk != Protocol_NULL ) if ( UARTSend_Cbk != Protocol_NULL )
{ {
return UARTSend_Cbk(dataBuf, frameLen); return UARTSend_Cbk(dataBuf, frameLen);
......
...@@ -60,7 +60,7 @@ typedef struct ...@@ -60,7 +60,7 @@ typedef struct
} Protocol_Func_t; } Protocol_Func_t;
void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc); void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc);
void Protocol_Service(void);//10ms void Protocol_Service(void);
Protocol_uint32_t Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len); Protocol_uint32_t Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len); Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len);
......
...@@ -26,6 +26,19 @@ ...@@ -26,6 +26,19 @@
#include "MCU_Core_Protocol.h" #include "MCU_Core_Protocol.h"
#include "Protocol_Lib.h" #include "Protocol_Lib.h"
#include "app_Ble_User.h" #include "app_Ble_User.h"
#include "app_BT_User.h"
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#define TAG "Prot_User"
Protocol_User_Ctrl_Struct Prot_User;
#define UART_TX_MAX_DEPTH 1024UL //(2 * 1024UL) // 4K #define UART_TX_MAX_DEPTH 1024UL //(2 * 1024UL) // 4K
#define UART_RX_MAX_DEPTH (2 * 1024UL) // 4K #define UART_RX_MAX_DEPTH (2 * 1024UL) // 4K
...@@ -73,96 +86,46 @@ void Protocol_KL30_Wakeup_Init(void) ...@@ -73,96 +86,46 @@ void Protocol_KL30_Wakeup_Init(void)
Protocol_Init(mDataBufPtr, UART_DATA_BUF_LEN, &pFunc); Protocol_Init(mDataBufPtr, UART_DATA_BUF_LEN, &pFunc);
} }
void Send_UartID(Protocol_uint8_t ID)
void Protocol_Send_Service(void)
{ {
switch (ID) Protocol_uint32_t i = 0u;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t SendLen = 0u;
if ( UARTTxBuf.write_pos == UARTTxBuf.read_pos )
{ {
case BLE_START_STA: return;
Uart_ID10_process();
break;
case BLE_NAVIGATION:
Uart_ID01_process();
break;
case BLE_WEATHER:
Uart_ID02_process();
break;
// case BLE_LOCATION:
// Uart_ID03_process();
// break;
case BLE_STA:
Uart_ID12_process();
break;
default:
break;
} }
} if ( UARTTxBuf.write_pos > UARTTxBuf.read_pos )
void Ble_to_MCU(void)
{
Protocol_uint8_t ID = 0;
if (1)
{ {
ID = 0x10; DataLen = UARTTxBuf.write_pos - UARTTxBuf.read_pos;
} }
else else
{ {
DataLen = UART_TX_MAX_DEPTH - (UARTTxBuf.read_pos - UARTTxBuf.write_pos);
} }
//判断应该发送哪个ID的串口数据
Send_UartID(ID);
}
void Protocol_Send_Service(void) if ( DataLen > 255 )
{
Ble_to_MCU();
Protocol_uint32_t i = 0u;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t SendLen = 0u;
static const char *TX_TASK_TAG = "TX_TASK";
esp_log_level_set(TX_TASK_TAG, ESP_LOG_INFO);
if (1/*判断上一个是否发送成功*/)
{ {
if ( UARTTxBuf.write_pos == UARTTxBuf.read_pos ) SendLen = 255;
{ }
return; else
} {
SendLen = DataLen;
if ( UARTTxBuf.write_pos > UARTTxBuf.read_pos ) }
{
DataLen = UARTTxBuf.write_pos - UARTTxBuf.read_pos;
}
else
{
DataLen = UART_TX_MAX_DEPTH - (UARTTxBuf.read_pos - UARTTxBuf.write_pos);
}
if ( DataLen > 255 ) for ( i = 0u; i < SendLen; i++ )
{ {
SendLen = 255; UsartDataBuf [ i ] = UARTTxBuf.Tx_Buffer [ UARTTxBuf.read_pos ];
} UARTTxBuf.read_pos = (UARTTxBuf.read_pos + 1) % UART_TX_MAX_DEPTH;
else }
{
SendLen = DataLen;
}
for ( i = 0u; i < SendLen; i++ )
{
UsartDataBuf [ i ] = UARTTxBuf.Tx_Buffer [ UARTTxBuf.read_pos ];
UARTTxBuf.read_pos = (UARTTxBuf.read_pos + 1) % UART_TX_MAX_DEPTH;
}
bsp_Uart_Send_Data(UsartDataBuf, SendLen);
//memcpy(Uart_Data.data, UsartDataBuf, SendLen);
//int i = 0;
//for(i = 0;i < SendLen;i++)
// printf("data is %x !!!\r\n",UsartDataBuf[i]);
bsp_Uart_Send_Data(UsartDataBuf, SendLen);
//UART_Ch1_Send_Multiple_Byte(UsartDataBuf, SendLen);/*ESP32底层*/
}
} }
static Protocol_uint8_t Protocol_OpenUart(void) static Protocol_uint8_t Protocol_OpenUart(void)
...@@ -246,53 +209,69 @@ static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protoc ...@@ -246,53 +209,69 @@ static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protoc
return 0; return 0;
} }
uint8_t Ble_connect_flag = 0;
static void Protocol_UartHandle(const Protocol_Data_t *pData) static void Protocol_UartHandle(const Protocol_Data_t *pData)
{ {
//printf("ProcParse success22222222222!!\r\n"); if ( pData->CmdID == 0x20 )
Ble_connect_flag = 0;
if ( pData->CmdID == BLE_START_STA )
{
//Uart_ID10_process();//TX
}
else if ( pData->CmdID == MCU_REPLY )
{
Uart_ID20_process(pData);
Ble_connect_flag = 1;
}
else if(pData->CmdID == BLE_NAVIGATION )
{
//Uart_ID01_process();//TX
}
else if(pData->CmdID == BLE_WEATHER )
{
//Uart_ID02_process();
}
else if(pData->CmdID == BLE_LOCATION )
{ {
//Uart_ID03_process(); if(Prot_User.State < Prot_Start)
{
Prot_User.State = Prot_Start;
printf("Prot_Start \r\n");
}
} }
else if(pData->CmdID == BLE_STA ) else if(pData->CmdID == 0x03 )
{ {
// Uart_ID12_process();//TX if(Prot_User.State < Prot_Normal)
{
Prot_User.State = Prot_Normal;
printf("Prot_Normal \r\n");
}
if(Prot_User.State >= Prot_Start)
{
if(pData->DataLen == 33)
{
if(BT_User.HF_Ctrl != pData->Data[0])
{
BT_User.HF_Ctrl = pData->Data[0];
}
if(strncmp((const char *) ble_uerid, (const char *)&(pData->Data[1]), 32) != 0)
{
memcpy(( uint8_t * )ble_uerid, (uint8_t *)&(pData->Data[1]), 32);
}
esp_log_buffer_hex(TAG, ble_uerid, 32);
esp_log_buffer_hex(TAG, &(pData->Data[1]), 32);
if(Ble_User.UseridUpdate == 0)
{
bsp_Ble_Init();
printf("get uuid and init ble!!! \r\n");
}
Ble_User.UseridUpdate = 0xAA;
}
}
} }
else if((pData->CmdID & 0x3f) == MCU_TO_BLE_INFO ) else if((pData->CmdID & 0x3f) == 0x21 )
{ {
if(Prot_User.State >= Prot_Start)
if((pData->CmdID & 0xC0) == 0X40)
{ {
if(Wifi_OTA_Request == 0) if((pData->CmdID & 0xC0) == 0X40)
{ {
Wifi_OTA_Request = 1; if(Wifi_OTA_Request == 0)
{
Wifi_OTA_Request = 1;
printf("get ota req! \r\n");
}
} }
} }
//printf("ID21 IS in!!!\r\n");
// Uart_ID21_process();//RX
} }
else else
{ {
//非本协议数据,不处理
} }
} }
...@@ -314,3 +293,81 @@ void UART_Put(Protocol_uint16_t Data) ...@@ -314,3 +293,81 @@ void UART_Put(Protocol_uint16_t Data)
//printf("into UARTRxBuf!!!!\r\n"); //printf("into UARTRxBuf!!!!\r\n");
return; return;
} }
/**
* @brief Protocol协议应用层数据赋值和发送
*/
void Protocol_User_Ctrl_Init(void )
{
Prot_User.State = Prot_Idle;
Prot_User.TimeDelay = 0;
}
void Uart_Send_Id10_Pro(void )
{
uint8_t wtemp[1] = {1};
Protocol_Send(0x10, wtemp, 1);
}
void Uart_Send_Id12_Pro(void )
{
uint8_t ID12[1];
ID12[0] = Ble_User.Ble_Sts;
Protocol_Send(0x12, ID12, 1);
}
void Uart_Send_Id01_Pro(void)
{
uint8_t ID01[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
if(Ble_User.Navi_Updat)
{
ID01[0] = Ble_Navi_Data.Navi_Sts;
ID01[1] = Ble_Navi_Data.Navi_Turn;
ID01[2] = Ble_Navi_Data.Navi_Dte[0];
ID01[3] = Ble_Navi_Data.Navi_Dte[1];
ID01[4] = Ble_Navi_Data.Navi_Dte[2];
ID01[5] = Ble_Navi_Data.Navi_Dte[3];
}
Protocol_Send(0x01,ID01,6);
}
void Uart_Send_Id02_Pro(void)
{
uint8_t ID02[1] = {0x00};
ID02[0] = BT_User.Call_Sts;
Protocol_Send(0x02, ID02, 1);
}
void Prot_Send_Msg_Process(void )
{
if(Prot_User.State < Prot_Start)
{
Uart_Send_Id10_Pro();
// printf("send 0x10 \r\n");
}
if(Prot_User.State >= Prot_Start)
{
if(Prot_User.TimeDelay == 0)
{
Uart_Send_Id12_Pro();
Prot_User.TimeDelay++;
// printf("send 0x12 \r\n");
}
else
{
Uart_Send_Id01_Pro();
Uart_Send_Id02_Pro();
Prot_User.TimeDelay = 0;
// printf("send 0x01 0x02 \r\n");
}
}
}
...@@ -17,4 +17,23 @@ void Protocol_KL30_Wakeup_Init(void); ...@@ -17,4 +17,23 @@ void Protocol_KL30_Wakeup_Init(void);
void Protocol_Send_Service(void); // 10ms任务调用 void Protocol_Send_Service(void); // 10ms任务调用
void UART_Put(Protocol_uint16_t Data); void UART_Put(Protocol_uint16_t Data);
typedef enum
{
Prot_Idle = 0,
Prot_Starting,
Prot_Start,
Prot_Normal,
}Prot_User_State_Enum;
typedef struct
{
uint8_t State;
uint16_t TimeDelay;
}Protocol_User_Ctrl_Struct;
extern Protocol_User_Ctrl_Struct Prot_User;
void Protocol_User_Ctrl_Init(void );
void Prot_Send_Msg_Process(void );
#endif #endif
...@@ -11,13 +11,13 @@ extern esp_bd_addr_t peer_addr; ...@@ -11,13 +11,13 @@ extern esp_bd_addr_t peer_addr;
BT_User_Control_Struct BT_User; BT_User_Control_Struct BT_User;
#define BT_ReConn_T 35 #define BT_ReConn_T 350
void BT_User_Init(void ) void BT_User_Init(void )
{ {
BT_User.BT_Sts = BT_Idle; BT_User.BT_Sts = BT_Idle;
BT_User.Call_Sts = Call_Idle; BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 5; BT_User.ReconnTime = BT_ReConn_T - 50;
BT_User.HF_Ctrl = HF_Idle; BT_User.HF_Ctrl = HF_Idle;
} }
...@@ -25,7 +25,7 @@ void BT_Connect_Event_Pro(void ) ...@@ -25,7 +25,7 @@ void BT_Connect_Event_Pro(void )
{ {
BT_User.BT_Sts = BT_Conn; BT_User.BT_Sts = BT_Conn;
BT_User.Call_Sts = Call_Idle; BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 5; BT_User.ReconnTime = BT_ReConn_T - 50;
BT_User.HF_Ctrl = HF_Idle; BT_User.HF_Ctrl = HF_Idle;
printf("TB CONN\r\n"); printf("TB CONN\r\n");
} }
...@@ -35,33 +35,17 @@ void BT_DisConnect_Event_Pro(void ) ...@@ -35,33 +35,17 @@ void BT_DisConnect_Event_Pro(void )
{ {
BT_User.BT_Sts = BT_Idle; BT_User.BT_Sts = BT_Idle;
BT_User.Call_Sts = Call_Idle; BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 5; BT_User.ReconnTime = BT_ReConn_T - 50;
BT_User.HF_Ctrl = HF_Idle; BT_User.HF_Ctrl = HF_Idle;
printf("TB DISCONN\r\n"); printf("TB DISCONN\r\n");
} }
uint32_t test_time;
void BT_User_Process(void ) void BT_User_Process(void )
{ {
test_time++;
if(test_time >= 6)
{
test_time = 0;
}
// printf("in %ld times\r\n", test_time);
switch(BT_User.Call_Sts) switch(BT_User.Call_Sts)
{ {
case Call_OutCalling: case Call_OutCalling:
{ {
if(test_time >= 3)
{
// hf_reject_handler();
test_time = 0;
}
if(BT_User.HF_Ctrl == HF_Reject) if(BT_User.HF_Ctrl == HF_Reject)
{ {
hf_reject_handler(); hf_reject_handler();
...@@ -70,12 +54,6 @@ void BT_User_Process(void ) ...@@ -70,12 +54,6 @@ void BT_User_Process(void )
} }
case Call_IncomeCalling: case Call_IncomeCalling:
{ {
if(test_time >= 3)
{
// hf_answer_handler();
test_time = 0;
}
if(BT_User.HF_Ctrl == HF_Reject) if(BT_User.HF_Ctrl == HF_Reject)
{ {
hf_reject_handler(); hf_reject_handler();
...@@ -88,12 +66,6 @@ void BT_User_Process(void ) ...@@ -88,12 +66,6 @@ void BT_User_Process(void )
} }
case Call_InProcess: case Call_InProcess:
{ {
if(test_time >= 3)
{
// hf_reject_handler();
test_time = 0;
}
if(BT_User.HF_Ctrl == HF_Reject) if(BT_User.HF_Ctrl == HF_Reject)
{ {
hf_reject_handler(); hf_reject_handler();
...@@ -101,13 +73,18 @@ void BT_User_Process(void ) ...@@ -101,13 +73,18 @@ void BT_User_Process(void )
break; break;
} }
case Call_Idle:
{
break;
}
} }
BT_User.HF_Ctrl = HF_Idle;
if(BT_User.BT_Sts == BT_Idle) if(BT_User.BT_Sts == BT_Idle)
{ {
BT_User.ReconnTime++; BT_User.ReconnTime++;
printf("ReconnTime %d\r\n", BT_User.ReconnTime);
if(BT_User.ReconnTime >= BT_ReConn_T) if(BT_User.ReconnTime >= BT_ReConn_T)
{ {
printf("Connect Start..............................\n"); printf("Connect Start..............................\n");
......
...@@ -14,23 +14,23 @@ typedef enum ...@@ -14,23 +14,23 @@ typedef enum
typedef enum typedef enum
{ {
Call_Idle = 0, Call_Idle = 0,
Call_OutCalling,
Call_IncomeCalling, Call_IncomeCalling,
Call_OutCalling,
Call_InProcess, Call_InProcess,
}Call_Sts_Enum; }Call_Sts_Enum;
typedef enum typedef enum
{ {
HF_Idle = 0, HF_Idle = 0,
HF_Reject,
HF_Answer, HF_Answer,
HF_Reject,
}Call_HF_Ctrl_Enum; }Call_HF_Ctrl_Enum;
typedef struct typedef struct
{ {
uint8_t BT_Sts; uint8_t BT_Sts;
uint8_t Call_Sts; uint8_t Call_Sts;
uint8_t ReconnTime; uint16_t ReconnTime;
uint8_t HF_Ctrl; uint8_t HF_Ctrl;
}BT_User_Control_Struct; }BT_User_Control_Struct;
......
...@@ -401,29 +401,7 @@ void Ble_MsgRec_Navi_Analysis(void ) ...@@ -401,29 +401,7 @@ void Ble_MsgRec_Navi_Analysis(void )
void Ble_Rec_Msg_Analysis_Process(void ) void Ble_Rec_Msg_Analysis_Process(void )
{ {
if (pdTRUE == xSemaphoreTake(BleRecSuc_Semaphore, portMAX_DELAY))
{
if(RecCtrl.Sts == BleRec_Suc)
{
if(BleRecData.Msg.Cmd == EC_BTP_P2C_CLIENT_INFO)
{
Ble_Msg_Authr_RLY();
}
else if(BleRecData.Msg.Cmd == EC_BTP_P2C_CHECK_AUTH_RESULT)
{
Ble_MsgRec_Authr_Result_Analysis();
Ble_Msg_RequestNavi_RLY();
}
else if(BleRecData.Msg.Cmd == EC_BTP_P2C_HUD)
{
Ble_MsgRec_Navi_Analysis();
}
Ble_Clear_Tx_Buffer();
Ble_Clear_Rx_Buffer();
RecCtrl.Sts = BleRec_Idle;
}
}
} }
...@@ -467,7 +445,30 @@ void Ble_User_Task(void *pvParameter) ...@@ -467,7 +445,30 @@ void Ble_User_Task(void *pvParameter)
while (1) while (1)
{ {
Ble_Rec_Msg_Analysis_Process(); // Ble_Rec_Msg_Analysis_Process();
if (pdTRUE == xSemaphoreTake(BleRecSuc_Semaphore, portMAX_DELAY))
{
if(RecCtrl.Sts == BleRec_Suc)
{
if(BleRecData.Msg.Cmd == EC_BTP_P2C_CLIENT_INFO)
{
Ble_Msg_Authr_RLY();
}
else if(BleRecData.Msg.Cmd == EC_BTP_P2C_CHECK_AUTH_RESULT)
{
Ble_MsgRec_Authr_Result_Analysis();
Ble_Msg_RequestNavi_RLY();
}
else if(BleRecData.Msg.Cmd == EC_BTP_P2C_HUD)
{
Ble_MsgRec_Navi_Analysis();
}
Ble_Clear_Tx_Buffer();
Ble_Clear_Rx_Buffer();
RecCtrl.Sts = BleRec_Idle;
}
}
} }
vTaskDelete(NULL); vTaskDelete(NULL);
} }
...@@ -479,6 +480,7 @@ void Ble_User_Init(void ) ...@@ -479,6 +480,7 @@ void Ble_User_Init(void )
Ble_User.Ble_Sts = Ble_Idle; Ble_User.Ble_Sts = Ble_Idle;
Ble_User.Request_Navi = 0; Ble_User.Request_Navi = 0;
Ble_User.Navi_Updat = 0; Ble_User.Navi_Updat = 0;
Ble_User.UseridUpdate = 0;
RecCtrl.RecLen = 0; RecCtrl.RecLen = 0;
RecCtrl.TotalLen = 0; RecCtrl.TotalLen = 0;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
extern uint8_t ble_uerid[32];
typedef enum typedef enum
{ {
Ble_Idle = 0, Ble_Idle = 0,
...@@ -27,6 +27,7 @@ typedef struct ...@@ -27,6 +27,7 @@ typedef struct
uint8_t Ble_Sts; uint8_t Ble_Sts;
uint8_t Request_Navi; uint8_t Request_Navi;
uint8_t Navi_Updat; uint8_t Navi_Updat;
uint8_t UseridUpdate;
}Ble_User_Control_Struct; }Ble_User_Control_Struct;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "esp_console.h" #include "esp_console.h"
// #include "app_hf_msg_set.h" // #include "app_hf_msg_set.h"
#include "app_BT_User.h" #include "app_BT_User.h"
#include "gatts_table_creat_demo.h"
esp_bd_addr_t peer_addr = {0}; esp_bd_addr_t peer_addr = {0};
static char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; static char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
...@@ -253,7 +254,7 @@ static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param) ...@@ -253,7 +254,7 @@ static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param)
case BT_APP_EVT_STACK_UP: { case BT_APP_EVT_STACK_UP: {
/* set up device name */ /* set up device name */
char *dev_name = "ESP_HFP_HF"; char *dev_name = "ESP_HFP_HF";
esp_bt_dev_set_device_name(dev_name); esp_bt_dev_set_device_name((char *)BT_Device_Name);
/* register GAP callback function */ /* register GAP callback function */
esp_bt_gap_register_callback(esp_bt_gap_cb); esp_bt_gap_register_callback(esp_bt_gap_cb);
......
...@@ -74,29 +74,26 @@ void init_Uart(void) { ...@@ -74,29 +74,26 @@ void init_Uart(void) {
.source_clk = UART_SCLK_DEFAULT, .source_clk = UART_SCLK_DEFAULT,
}; };
// We won't use a buffer for sending data. // We won't use a buffer for sending data.
uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0); uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 200, 0, NULL, 0);
uart_param_config(UART_NUM_1, &uart_config); uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
} }
int bsp_Uart_Send_Data(uint8_t * data , unsigned int len) int bsp_Uart_Send_Data(uint8_t * data , unsigned int len)
{ {
// const int len = strlen(data); int txBytes = uart_write_bytes(UART_NUM_1, data, len);
const int txBytes = uart_write_bytes(UART_NUM_1, data, len); uart_wait_tx_idle_polling(UART_NUM_1);
// ESP_LOGI(logName, "Wrote %d bytes", txBytes);
return txBytes; return txBytes;
} }
static void rx_task(void *arg) static void Uart_Rx_Task(void *arg)
{ {
static const char *RX_TASK_TAG = "RX_TASK";
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1); uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
while (1) while (1)
{ {
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, portMAX_DELAY); const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 20);
if (rxBytes < 1000) if (rxBytes < 1000)
{ {
for (uint16_t i = 0; i < rxBytes; i++) for (uint16_t i = 0; i < rxBytes; i++)
...@@ -112,11 +109,16 @@ void bsp_Uart_Init(void ) ...@@ -112,11 +109,16 @@ void bsp_Uart_Init(void )
{ {
init_Uart(); init_Uart();
Protocol_KL30_Wakeup_Init(); Protocol_KL30_Wakeup_Init();
xTaskCreatePinnedToCore(rx_task, "Ble_User", 4096, NULL, 4, NULL, 1); xTaskCreatePinnedToCore(Uart_Rx_Task, "Ble_User", 4096, NULL, 4, NULL, 1);
} }
extern void simple_ota_main(void); extern void simple_ota_main(void);
void simple_ota_service(void) void simple_ota_service(void)
{ {
...@@ -136,7 +138,7 @@ void simple_ota_service(void) ...@@ -136,7 +138,7 @@ void simple_ota_service(void)
static uint8_t device_name[] = "QIANJIANGViva"; uint8_t BT_Device_Name[14] = "QianJiangViva";
#define GATTS_TABLE_TAG "GATTS_TABLE_DEMO" #define GATTS_TABLE_TAG "GATTS_TABLE_DEMO"
...@@ -145,7 +147,7 @@ static uint8_t device_name[] = "QIANJIANGViva"; ...@@ -145,7 +147,7 @@ static uint8_t device_name[] = "QIANJIANGViva";
#define PROFILE_APP_IDX 0 #define PROFILE_APP_IDX 0
#define ESP_APP_ID 0x55 #define ESP_APP_ID 0x55
#define SAMPLE_DEVICE_NAME "QIANJIANGViva" #define SAMPLE_DEVICE_NAME "QianJiangViva"
#define SVC_INST_ID 0 #define SVC_INST_ID 0
#define SVC_INST_ID1 1 #define SVC_INST_ID1 1
...@@ -645,7 +647,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ ...@@ -645,7 +647,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
{ {
switch (event) { switch (event) {
case ESP_GATTS_REG_EVT:{ case ESP_GATTS_REG_EVT:{
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name((const char *)device_name); esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name((const char *)BT_Device_Name);
if (set_dev_name_ret){ if (set_dev_name_ret){
ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret); ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
} }
...@@ -896,12 +898,14 @@ void Get_Mac_Init(void ) ...@@ -896,12 +898,14 @@ void Get_Mac_Init(void )
// ESP_LOGW(GATTS_TABLE_TAG, "BLE_MAC IS %s : ", // ESP_LOGW(GATTS_TABLE_TAG, "BLE_MAC IS %s : ",
// &raw_adv_data[11]); // &raw_adv_data[11]);
// ESP_LOGW(GATTS_TABLE_TAG, "BLE_MAC IS %s : ", // ESP_LOGW(GATTS_TABLE_TAG, "BLE_MAC IS %s : ",
// temp); // temp);
esp_log_buffer_hex(GATTS_TABLE_TAG, ble_mac, 6);
device_name[sizeof(device_name) - 5] = temp[0]; BT_Device_Name[sizeof(BT_Device_Name) - 5] = temp[0];
device_name[sizeof(device_name) - 4] = temp[1]; BT_Device_Name[sizeof(BT_Device_Name) - 4] = temp[1];
device_name[sizeof(device_name) - 3] = temp[2]; BT_Device_Name[sizeof(BT_Device_Name) - 3] = temp[2];
device_name[sizeof(device_name) - 2] = temp[3]; BT_Device_Name[sizeof(BT_Device_Name) - 2] = temp[3];
raw_adv_data[11] = ble_mac[0]; raw_adv_data[11] = ble_mac[0];
raw_adv_data[12] = ble_mac[1]; raw_adv_data[12] = ble_mac[1];
...@@ -924,7 +928,8 @@ void bsp_Ble_Init(void) ...@@ -924,7 +928,8 @@ void bsp_Ble_Init(void)
{ {
esp_err_t ret; esp_err_t ret;
Get_Mac_Init(); // Get_Mac_Init();
/* Initialize NVS. */ /* Initialize NVS. */
// ret = nvs_flash_init(); // ret = nvs_flash_init();
......
...@@ -75,6 +75,8 @@ int bsp_Ble_Gatts_Send_Indicate(uint8_t len, uint8_t *data); ...@@ -75,6 +75,8 @@ int bsp_Ble_Gatts_Send_Indicate(uint8_t len, uint8_t *data);
void simple_ota_service(void); void simple_ota_service(void);
extern uint8_t BT_Device_Name[14];
void Get_Mac_Init(void );
extern int bsp_Uart_Send_Data(uint8_t * data , unsigned int len); extern int bsp_Uart_Send_Data(uint8_t * data , unsigned int len);
#endif #endif
\ No newline at end of file
...@@ -45,14 +45,13 @@ static void Sys_Run_Tasks(void *arg) ...@@ -45,14 +45,13 @@ static void Sys_Run_Tasks(void *arg)
Sys_1ms_Cnt = 0; Sys_1ms_Cnt = 0;
} }
if(SYS_RUN_TASK_1MS)
{
}
if(SYS_RUN_TASK_10MS) if(SYS_RUN_TASK_10MS)
{ {
Protocol_Send_Service();
Protocol_Service();
BT_User_Process();
} }
if(SYS_RUN_TASK_20MS) if(SYS_RUN_TASK_20MS)
...@@ -62,7 +61,7 @@ static void Sys_Run_Tasks(void *arg) ...@@ -62,7 +61,7 @@ static void Sys_Run_Tasks(void *arg)
if(SYS_RUN_TASK_50MS) if(SYS_RUN_TASK_50MS)
{ {
Prot_Send_Msg_Process();
} }
if(SYS_RUN_TASK_100MS) if(SYS_RUN_TASK_100MS)
...@@ -72,10 +71,9 @@ static void Sys_Run_Tasks(void *arg) ...@@ -72,10 +71,9 @@ static void Sys_Run_Tasks(void *arg)
if(SYS_RUN_TASK_1000MS) if(SYS_RUN_TASK_1000MS)
{ {
BT_User_Process();
simple_ota_service();
Protocol_Send_Service();
simple_ota_service();
testcnt++; testcnt++;
if(testcnt >= 5) if(testcnt >= 5)
{ {
...@@ -92,18 +90,19 @@ static void Sys_Run_Tasks(void *arg) ...@@ -92,18 +90,19 @@ static void Sys_Run_Tasks(void *arg)
} }
} }
vTaskDelay(1); vTaskDelay(10);
} }
vTaskDelete(NULL); vTaskDelete(NULL);
} }
void app_main(void) void app_main(void)
{ {
Protocol_User_Ctrl_Init();
BT_User_Init(); BT_User_Init();
Ble_User_Init(); Ble_User_Init();
Get_Mac_Init();
bsp_BT_Init(); bsp_BT_Init();
bsp_Ble_Init(); // bsp_Ble_Init();
bsp_Uart_Init(); bsp_Uart_Init();
xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, NULL, 1); xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, NULL, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment