Commit 62d8090d authored by wangxuhui's avatar wangxuhui

Merge branch 'xxh' into 'develop'

添加app蓝牙时间获取和发送给底板的功能

See merge request !3
parents 25df911a cb7463d2
......@@ -318,7 +318,7 @@ void Uart_Send_Id10_Pro(void )
void Uart_Send_Id12_Pro(void )
{
uint8_t ID12[15] = {0};
uint8_t ID12[17] = {0};
ID12[0] |= (uint8_t)(BT_User.BT_Sts << 4);
ID12[0] |= Ble_User.Ble_Sts;
unsigned int i = 0;
......@@ -326,7 +326,12 @@ void Uart_Send_Id12_Pro(void )
{
ID12[ i + 1 ] = BT_Device_Name[ i ];
}
Protocol_Send(0x12, ID12, 15);
ID12[15] = Get_Ble_Time_Hour();
ID12[16] = Get_Ble_Time_Minute();
// printf("hour = %d, minute = %d\n", ID12[15], ID12[16]);
Protocol_Send(0x12, ID12, 17);
}
void Uart_Send_Id01_Pro(void)
......
......@@ -11,11 +11,12 @@
#include "MCU_Core_Protocol.h"
#include "Protocol_User.h"
#include "main_user.h"
#include "esp_log.h"
#define TAG "APP_BLE_USER"
app_Ble_Time_Info_Struct BleTime;
app_Ble_User_Data_Union BleRecData;
app_Ble_User_Data_Union BleTransData;
app_Ble_Rec_Data_Ctrl_Struct RecCtrl;
......@@ -37,6 +38,19 @@ Ble_User_Control_Struct Ble_User;
Ble_Navi_Info_Struct Ble_Navi_Data;
uint8_t Char_To_Dec(uint8_t input, uint8_t *output)
{
uint8_t i = 0;
if(input < '0' || input >'9')
{
return 0;
}
*output = input - 0x30;
return 1;
}
uint8_t tp_Ble_Crc(uint8_t *data, uint32_t len )
{
uint8_t val = 0;
......@@ -321,8 +335,9 @@ void Ble_MsgRec_Authr_Result_Analysis(void )
{
Ble_User.Ble_Sts = Ble_Authr;
Ble_User.Request_Navi = 1;
Ble_User.u8Time_Req_Sw = 1;
// printf("Authr suc\n");
ESP_LOGE("BLE USER","Authr suc\n");
}
}
......@@ -384,12 +399,57 @@ void Ble_Msg_RequestNavi_RLY(void )
}
Ble_User.Request_Navi = 0;
}
}
void Ble_Msg_RequestTime(void )
{
uint8_t total_frame = 0;
uint8_t trans_len = 0;
if(Ble_User.u8Time_Req_Sw == 1 && Ble_User.Ble_Sts >= Ble_Authr)
{
BleTransData.Msg.FrameHeader = 0x24;
BleTransData.Msg.Cmd = 0x55;
BleTransData.Msg.Lenth = 4;
if((BleTransData.Msg.Lenth+1) % 20 == 0)
{
total_frame = (BleTransData.Msg.Lenth+1) / 20;
}
else
{
total_frame = (BleTransData.Msg.Lenth+1) / 20 + 1;
}
BleTransData.Data[BleTransData.Msg.Lenth - 1] = tp_Ble_Crc(BleTransData.Data, BleTransData.Msg.Lenth - 1);
BleTransData.Data[BleTransData.Msg.Lenth] = 0x0A;
for(uint8_t i = 0; i < total_frame; i++)
{
if(((BleTransData.Msg.Lenth+1) - 20*i) >= 20)
{
trans_len = 20;
}
else
{
trans_len = (BleTransData.Msg.Lenth+1) - 20*i;
}
bsp_Ble_Gatts_Send_Indicate( trans_len, &BleTransData.Data[i*20]);
}
}
}
void Ble_MsgRec_Navi_Analysis(void )
{
uint32_t aaa = 0;
......@@ -425,6 +485,56 @@ void Ble_MsgRec_Navi_Analysis(void )
Ble_User.Navi_T = 0;
}
//11 12 hour
//14 15 min
void Ble_MsgRec_Time_Analysis(void )
{
uint8_t wtemp[4] = {0};
Char_To_Dec(BleRecData.Msg.Param[11], &wtemp[0]);
Char_To_Dec(BleRecData.Msg.Param[12], &wtemp[1]);
BleTime.u8Hour = wtemp[0] * 10 + wtemp[1];
Char_To_Dec(BleRecData.Msg.Param[14], &wtemp[2]);
Char_To_Dec(BleRecData.Msg.Param[15], &wtemp[3]);
BleTime.u8Minute = wtemp[2] * 10 + wtemp[3];
Ble_User.u8Time_Updat = 1;
Ble_User.u8Time_T = 0;
// printf("hour = %d, minute = %d\n", BleTime.u8Hour, BleTime.u8Minute);
}
uint8_t Get_Ble_Time_Hour(void )
{
uint8_t ret = 0xff;
if(Ble_User.u8Time_Updat == 1)
{
if(BleTime.u8Hour < 24)
{
ret = BleTime.u8Hour;
}
}
return ret;
}
uint8_t Get_Ble_Time_Minute(void )
{
uint8_t ret = 0xff;
if(Ble_User.u8Time_Updat == 1)
{
if(BleTime.u8Minute < 60)
{
ret = BleTime.u8Minute;
}
}
return ret;
}
void Ble_MsgRec_Navi_Timeout(void )
{
if(Ble_User.Navi_Updat)
......@@ -440,26 +550,41 @@ void Ble_MsgRec_Navi_Timeout(void )
{
Ble_User.Navi_T = 0;
}
}
void Ble_Rec_Msg_Analysis_Process(void )
{
if(Ble_User.u8Time_Updat)
{
Ble_User.u8Time_T++;
if(Ble_User.u8Time_T >= 50)
{
Ble_User.u8Time_Updat = 0;
Ble_User.u8Time_T = 0;
ESP_LOGE("BLE USER", "time update timeout");
}
}
else
{
Ble_User.u8Time_T = 0;
}
}
void Ble_Connect_Event_Pro(void )
{
Ble_User.Ble_Sts = Ble_Conn;
Ble_User.Request_Navi = 0;
Ble_User.Navi_Updat = 0;
Ble_User.Navi_T = 0;
Ble_User.u8Time_Updat = 0;
Ble_User.u8Time_T = 0;
Ble_User.u8Time_Req_Sw = 0;
Ble_Clear_Tx_Buffer();
Ble_Clear_Rx_Buffer();
}
......@@ -469,6 +594,8 @@ void Ble_DisConnect_Event_Pro(void )
Ble_User.Request_Navi = 0;
Ble_User.Navi_Updat = 0;
Ble_User.Navi_T = 0;
Ble_User.u8Time_Updat = 0;
Ble_User.u8Time_T = 0;
RecCtrl.RecLen = 0;
RecCtrl.TotalLen = 0;
......@@ -484,6 +611,8 @@ void Ble_DisConnect_Event_Pro(void )
Ble_Clear_Tx_Buffer();
Ble_Clear_Rx_Buffer();
Ble_User.u8Time_Req_Sw = 0;
}
......@@ -492,7 +621,6 @@ void Ble_User_Task(void *pvParameter)
while (1)
{
// Ble_Rec_Msg_Analysis_Process();
if (pdTRUE == xSemaphoreTake(BleRecSuc_Semaphore, portMAX_DELAY))
{
if(RecCtrl.Sts == BleRec_Suc)
......@@ -510,6 +638,10 @@ void Ble_User_Task(void *pvParameter)
{
Ble_MsgRec_Navi_Analysis();
}
else if(EC_BTP_TIME_SYN == BleRecData.Msg.Cmd)
{
Ble_MsgRec_Time_Analysis();
}
Ble_Clear_Tx_Buffer();
Ble_Clear_Rx_Buffer();
......@@ -520,6 +652,17 @@ void Ble_User_Task(void *pvParameter)
vTaskDelete(NULL);
}
void Ble_User_Task_Cyc(void *pvParameter)
{
while (1)
{
Ble_Msg_RequestTime();
vTaskDelay(800);
}
vTaskDelete(NULL);
}
void Ble_User_Init(void )
{
BleRecSuc_Semaphore = xSemaphoreCreateBinary();
......@@ -547,5 +690,7 @@ void Ble_User_Init(void )
xTaskCreatePinnedToCore(Ble_User_Task, "Ble_User", 4096, NULL, 10, NULL, 0);
xTaskCreatePinnedToCore(Ble_User_Task_Cyc, "Ble_User_Cyc", 4096, NULL, 9, NULL, 0);
}
......@@ -29,9 +29,14 @@ typedef struct
uint8_t Navi_Updat;
uint8_t Navi_T;
uint8_t UseridUpdate;
uint8_t u8Time_Req_Sw;
uint8_t u8Time_Updat;
uint8_t u8Time_T;
}Ble_User_Control_Struct;
typedef struct
{
uint8_t Navi_Sts;
......@@ -41,6 +46,15 @@ typedef struct
typedef struct
{
uint8_t u8Hour;
uint8_t u8Minute;
}app_Ble_Time_Info_Struct;
typedef union
{
struct
......@@ -215,9 +229,10 @@ void Get_Ble_Raw_Data(uint8_t *data, uint32_t len);
*/
#define EC_BTP_P2C_HUD 0x14
#define EC_BTP_TIME_SYN 0x55
void Ble_Rec_Msg_Analysis_Process(void );
void Ble_Connect_Event_Pro(void );
void Ble_DisConnect_Event_Pro(void );
......@@ -225,4 +240,9 @@ void Ble_User_Init(void );
void Ble_Msg_RequestNavi_RLY(void );
void Ble_MsgRec_Navi_Timeout(void );
uint8_t Get_Ble_Time_Hour(void );
uint8_t Get_Ble_Time_Minute(void );
void Ble_Msg_RequestTime(void );
#endif
\ No newline at end of file
......@@ -496,28 +496,24 @@ int bsp_Ble_Gatts_Send_Indicate( uint8_t len, uint8_t *data)
if(Ble_User.Ble_Sts != Ble_Idle)
{
// if(en)
while(retry -- )
{
while(retry -- )
if(err != ESP_OK)
{
if(err != ESP_OK)
{
err = esp_ble_gatts_send_indicate(heart_rate_profile_tab[0].gatts_if,
heart_rate_profile_tab[0].conn_id,
heart_rate_handle_table2[IDX_CHAR_VAL_A2],
len, data, false);
}
else
{
break;
}
err = esp_ble_gatts_send_indicate(heart_rate_profile_tab[0].gatts_if,
heart_rate_profile_tab[0].conn_id,
heart_rate_handle_table2[IDX_CHAR_VAL_A2],
len, data, false);
}
if(err != ESP_OK)
else
{
printf("ble trans fail!!\r\n");
break;
}
}
if(err != ESP_OK)
{
ESP_LOGE("GATTS", "ble trans fail!!");
}
}
......
......@@ -29,7 +29,7 @@
#include "bt_app_hf.h"
static const float Inter_SW = 1.0;
static const float Inter_SW = 1.01;
#define TAG "MAIN_USER"
extern esp_bd_addr_t peer_addr;
......@@ -138,7 +138,7 @@ void app_main(void)
bsp_Uart_Init();
// printf("KL30 INIT OVER~~~~~~\r\n");
printf("internal sw = %f\n", Inter_SW);
ESP_LOGE("MAIN", "Internal Sw = %f", Inter_SW);
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