Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
QJ_500-7c
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
QJ_500-7c
Commits
991cbd06
Commit
991cbd06
authored
May 03, 2024
by
薛小虎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 整理与底板通信程序
parent
53a60fb7
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
266 additions
and
316 deletions
+266
-316
MCU_Core_Protocol.c
qianjiang/main/MCU_Core_Protocol.c
+0
-106
MCU_Core_Protocol.h
qianjiang/main/MCU_Core_Protocol.h
+0
-9
Protocol_Lib.c
qianjiang/main/Protocol_Lib.c
+2
-0
Protocol_Lib.h
qianjiang/main/Protocol_Lib.h
+1
-1
Protocol_User.c
qianjiang/main/Protocol_User.c
+165
-108
Protocol_User.h
qianjiang/main/Protocol_User.h
+19
-0
app_BT_User.c
qianjiang/main/app_BT_User.c
+10
-33
app_BT_User.h
qianjiang/main/app_BT_User.h
+3
-3
app_Ble_User.c
qianjiang/main/app_Ble_User.c
+26
-24
app_Ble_User.h
qianjiang/main/app_Ble_User.h
+2
-1
bt_app_main.c
qianjiang/main/bt_app_main.c
+2
-1
gatts_table_creat_demo.c
qianjiang/main/gatts_table_creat_demo.c
+23
-18
gatts_table_creat_demo.h
qianjiang/main/gatts_table_creat_demo.h
+2
-0
main_user.c
qianjiang/main/main_user.c
+11
-12
No files found.
qianjiang/main/MCU_Core_Protocol.c
View file @
991cbd06
...
...
@@ -8,112 +8,6 @@
#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
();
}
qianjiang/main/MCU_Core_Protocol.h
View file @
991cbd06
...
...
@@ -2,14 +2,5 @@
#define _MCU_CORE_PROTOCOL_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
qianjiang/main/Protocol_Lib.c
View file @
991cbd06
...
...
@@ -254,6 +254,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui
frameLen
++
;
}
// 校验码 Checksum
checksum
=
getCheckSum
(
dataBuf
+
2
,
frameLen
-
2
);
dataBuf
[
frameLen
]
=
(
checksum
>>
8
)
&
0x00FF
;
...
...
@@ -261,6 +262,7 @@ Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_ui
dataBuf
[
frameLen
]
=
checksum
&
0x00FF
;
frameLen
++
;
if
(
UARTSend_Cbk
!=
Protocol_NULL
)
{
return
UARTSend_Cbk
(
dataBuf
,
frameLen
);
...
...
qianjiang/main/Protocol_Lib.h
View file @
991cbd06
...
...
@@ -60,7 +60,7 @@ typedef struct
}
Protocol_Func_t
;
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_Send
(
const
Protocol_uint16_t
cmdID
,
const
Protocol_uint8_t
*
pData
,
Protocol_uint8_t
len
);
...
...
qianjiang/main/Protocol_User.c
View file @
991cbd06
...
...
@@ -26,6 +26,19 @@
#include "MCU_Core_Protocol.h"
#include "Protocol_Lib.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_RX_MAX_DEPTH (2 * 1024UL) // 4K
...
...
@@ -73,96 +86,46 @@ void Protocol_KL30_Wakeup_Init(void)
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
:
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
;
return
;
}
}
void
Ble_to_MCU
(
void
)
{
Protocol_uint8_t
ID
=
0
;
if
(
1
)
if
(
UARTTxBuf
.
write_pos
>
UARTTxBuf
.
read_pos
)
{
ID
=
0x10
;
DataLen
=
UARTTxBuf
.
write_pos
-
UARTTxBuf
.
read_pos
;
}
else
{
DataLen
=
UART_TX_MAX_DEPTH
-
(
UARTTxBuf
.
read_pos
-
UARTTxBuf
.
write_pos
);
}
//判断应该发送哪个ID的串口数据
Send_UartID
(
ID
);
}
void
Protocol_Send_Service
(
void
)
{
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
(
DataLen
>
255
)
{
if
(
UARTTxBuf
.
write_pos
==
UARTTxBuf
.
read_pos
)
{
return
;
}
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
);
}
SendLen
=
255
;
}
else
{
SendLen
=
DataLen
;
}
if
(
DataLen
>
255
)
{
SendLen
=
255
;
}
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
;
}
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
)
...
...
@@ -246,53 +209,69 @@ static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protoc
return
0
;
}
uint8_t
Ble_connect_flag
=
0
;
static
void
Protocol_UartHandle
(
const
Protocol_Data_t
*
pData
)
{
//printf("ProcParse success22222222222!!\r\n");
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
)
if
(
pData
->
CmdID
==
0x20
)
{
//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
((
pData
->
CmdID
&
0xC0
)
==
0X40
)
if
(
Prot_User
.
State
>=
Prot_Start
)
{
if
(
Wifi_OTA_Request
==
0
)
if
(
(
pData
->
CmdID
&
0xC0
)
==
0X4
0
)
{
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
{
//非本协议数据,不处理
}
}
...
...
@@ -314,3 +293,81 @@ void UART_Put(Protocol_uint16_t Data)
//printf("into UARTRxBuf!!!!\r\n");
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");
}
}
}
qianjiang/main/Protocol_User.h
View file @
991cbd06
...
...
@@ -17,4 +17,23 @@ void Protocol_KL30_Wakeup_Init(void);
void
Protocol_Send_Service
(
void
);
// 10ms任务调用
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
qianjiang/main/app_BT_User.c
View file @
991cbd06
...
...
@@ -11,13 +11,13 @@ extern esp_bd_addr_t peer_addr;
BT_User_Control_Struct
BT_User
;
#define BT_ReConn_T 35
#define BT_ReConn_T 35
0
void
BT_User_Init
(
void
)
{
BT_User
.
BT_Sts
=
BT_Idle
;
BT_User
.
Call_Sts
=
Call_Idle
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
0
;
BT_User
.
HF_Ctrl
=
HF_Idle
;
}
...
...
@@ -25,7 +25,7 @@ void BT_Connect_Event_Pro(void )
{
BT_User
.
BT_Sts
=
BT_Conn
;
BT_User
.
Call_Sts
=
Call_Idle
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
0
;
BT_User
.
HF_Ctrl
=
HF_Idle
;
printf
(
"TB CONN
\r\n
"
);
}
...
...
@@ -35,33 +35,17 @@ void BT_DisConnect_Event_Pro(void )
{
BT_User
.
BT_Sts
=
BT_Idle
;
BT_User
.
Call_Sts
=
Call_Idle
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
;
BT_User
.
ReconnTime
=
BT_ReConn_T
-
5
0
;
BT_User
.
HF_Ctrl
=
HF_Idle
;
printf
(
"TB DISCONN
\r\n
"
);
}
uint32_t
test_time
;
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
)
{
case
Call_OutCalling
:
{
if
(
test_time
>=
3
)
{
// hf_reject_handler();
test_time
=
0
;
}
if
(
BT_User
.
HF_Ctrl
==
HF_Reject
)
{
hf_reject_handler
();
...
...
@@ -70,12 +54,6 @@ void BT_User_Process(void )
}
case
Call_IncomeCalling
:
{
if
(
test_time
>=
3
)
{
// hf_answer_handler();
test_time
=
0
;
}
if
(
BT_User
.
HF_Ctrl
==
HF_Reject
)
{
hf_reject_handler
();
...
...
@@ -88,12 +66,6 @@ void BT_User_Process(void )
}
case
Call_InProcess
:
{
if
(
test_time
>=
3
)
{
// hf_reject_handler();
test_time
=
0
;
}
if
(
BT_User
.
HF_Ctrl
==
HF_Reject
)
{
hf_reject_handler
();
...
...
@@ -101,13 +73,18 @@ void BT_User_Process(void )
break
;
}
case
Call_Idle
:
{
break
;
}
}
BT_User
.
HF_Ctrl
=
HF_Idle
;
if
(
BT_User
.
BT_Sts
==
BT_Idle
)
{
BT_User
.
ReconnTime
++
;
printf
(
"ReconnTime %d
\r\n
"
,
BT_User
.
ReconnTime
);
if
(
BT_User
.
ReconnTime
>=
BT_ReConn_T
)
{
printf
(
"Connect Start..............................
\n
"
);
...
...
qianjiang/main/app_BT_User.h
View file @
991cbd06
...
...
@@ -14,23 +14,23 @@ typedef enum
typedef
enum
{
Call_Idle
=
0
,
Call_OutCalling
,
Call_IncomeCalling
,
Call_OutCalling
,
Call_InProcess
,
}
Call_Sts_Enum
;
typedef
enum
{
HF_Idle
=
0
,
HF_Reject
,
HF_Answer
,
HF_Reject
,
}
Call_HF_Ctrl_Enum
;
typedef
struct
{
uint8_t
BT_Sts
;
uint8_t
Call_Sts
;
uint
8
_t
ReconnTime
;
uint
16
_t
ReconnTime
;
uint8_t
HF_Ctrl
;
}
BT_User_Control_Struct
;
...
...
qianjiang/main/app_Ble_User.c
View file @
991cbd06
...
...
@@ -401,29 +401,7 @@ void Ble_MsgRec_Navi_Analysis(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)
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
);
}
...
...
@@ -479,6 +480,7 @@ void Ble_User_Init(void )
Ble_User
.
Ble_Sts
=
Ble_Idle
;
Ble_User
.
Request_Navi
=
0
;
Ble_User
.
Navi_Updat
=
0
;
Ble_User
.
UseridUpdate
=
0
;
RecCtrl
.
RecLen
=
0
;
RecCtrl
.
TotalLen
=
0
;
...
...
qianjiang/main/app_Ble_User.h
View file @
991cbd06
...
...
@@ -3,7 +3,7 @@
#include <stdlib.h>
extern
uint8_t
ble_uerid
[
32
];
typedef
enum
{
Ble_Idle
=
0
,
...
...
@@ -27,6 +27,7 @@ typedef struct
uint8_t
Ble_Sts
;
uint8_t
Request_Navi
;
uint8_t
Navi_Updat
;
uint8_t
UseridUpdate
;
}
Ble_User_Control_Struct
;
...
...
qianjiang/main/bt_app_main.c
View file @
991cbd06
...
...
@@ -26,6 +26,7 @@
#include "esp_console.h"
// #include "app_hf_msg_set.h"
#include "app_BT_User.h"
#include "gatts_table_creat_demo.h"
esp_bd_addr_t
peer_addr
=
{
0
};
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)
case
BT_APP_EVT_STACK_UP
:
{
/* set up device name */
char
*
dev_name
=
"ESP_HFP_HF"
;
esp_bt_dev_set_device_name
(
dev_n
ame
);
esp_bt_dev_set_device_name
(
(
char
*
)
BT_Device_N
ame
);
/* register GAP callback function */
esp_bt_gap_register_callback
(
esp_bt_gap_cb
);
...
...
qianjiang/main/gatts_table_creat_demo.c
View file @
991cbd06
...
...
@@ -74,29 +74,26 @@ void init_Uart(void) {
.
source_clk
=
UART_SCLK_DEFAULT
,
};
// 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
,
20
0
,
0
,
NULL
,
0
);
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
);
}
int
bsp_Uart_Send_Data
(
uint8_t
*
data
,
unsigned
int
len
)
{
// const int len = strlen(data);
const
int
txBytes
=
uart_write_bytes
(
UART_NUM_1
,
data
,
len
);
// ESP_LOGI(logName, "Wrote %d bytes", txBytes);
int
txBytes
=
uart_write_bytes
(
UART_NUM_1
,
data
,
len
);
uart_wait_tx_idle_polling
(
UART_NUM_1
);
return
txBytes
;
}
static
void
rx_t
ask
(
void
*
arg
)
static
void
Uart_Rx_T
ask
(
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
);
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
)
{
for
(
uint16_t
i
=
0
;
i
<
rxBytes
;
i
++
)
...
...
@@ -112,11 +109,16 @@ void bsp_Uart_Init(void )
{
init_Uart
();
Protocol_KL30_Wakeup_Init
();
xTaskCreatePinnedToCore
(
rx_t
ask
,
"Ble_User"
,
4096
,
NULL
,
4
,
NULL
,
1
);
xTaskCreatePinnedToCore
(
Uart_Rx_T
ask
,
"Ble_User"
,
4096
,
NULL
,
4
,
NULL
,
1
);
}
extern
void
simple_ota_main
(
void
);
void
simple_ota_service
(
void
)
{
...
...
@@ -136,7 +138,7 @@ void simple_ota_service(void)
static
uint8_t
device_name
[]
=
"QIANJIANG
Viva"
;
uint8_t
BT_Device_Name
[
14
]
=
"QianJiang
Viva"
;
#define GATTS_TABLE_TAG "GATTS_TABLE_DEMO"
...
...
@@ -145,7 +147,7 @@ static uint8_t device_name[] = "QIANJIANGViva";
#define PROFILE_APP_IDX 0
#define ESP_APP_ID 0x55
#define SAMPLE_DEVICE_NAME "Q
IANJIANG
Viva"
#define SAMPLE_DEVICE_NAME "Q
ianJiang
Viva"
#define SVC_INST_ID 0
#define SVC_INST_ID1 1
...
...
@@ -645,7 +647,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
{
switch
(
event
)
{
case
ESP_GATTS_REG_EVT
:{
esp_err_t
set_dev_name_ret
=
esp_ble_gap_set_device_name
((
const
char
*
)
device_n
ame
);
esp_err_t
set_dev_name_ret
=
esp_ble_gap_set_device_name
((
const
char
*
)
BT_Device_N
ame
);
if
(
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 )
// ESP_LOGW(GATTS_TABLE_TAG, "BLE_MAC IS %s : ",
// &raw_adv_data[11]);
// 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_n
ame
)
-
5
]
=
temp
[
0
];
device_name
[
sizeof
(
device_n
ame
)
-
4
]
=
temp
[
1
];
device_name
[
sizeof
(
device_n
ame
)
-
3
]
=
temp
[
2
];
device_name
[
sizeof
(
device_n
ame
)
-
2
]
=
temp
[
3
];
BT_Device_Name
[
sizeof
(
BT_Device_N
ame
)
-
5
]
=
temp
[
0
];
BT_Device_Name
[
sizeof
(
BT_Device_N
ame
)
-
4
]
=
temp
[
1
];
BT_Device_Name
[
sizeof
(
BT_Device_N
ame
)
-
3
]
=
temp
[
2
];
BT_Device_Name
[
sizeof
(
BT_Device_N
ame
)
-
2
]
=
temp
[
3
];
raw_adv_data
[
11
]
=
ble_mac
[
0
];
raw_adv_data
[
12
]
=
ble_mac
[
1
];
...
...
@@ -924,7 +928,8 @@ void bsp_Ble_Init(void)
{
esp_err_t
ret
;
Get_Mac_Init
();
// Get_Mac_Init();
/* Initialize NVS. */
// ret = nvs_flash_init();
...
...
qianjiang/main/gatts_table_creat_demo.h
View file @
991cbd06
...
...
@@ -75,6 +75,8 @@ int bsp_Ble_Gatts_Send_Indicate(uint8_t len, uint8_t *data);
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
);
#endif
\ No newline at end of file
qianjiang/main/main_user.c
View file @
991cbd06
...
...
@@ -45,14 +45,13 @@ static void Sys_Run_Tasks(void *arg)
Sys_1ms_Cnt
=
0
;
}
if
(
SYS_RUN_TASK_1MS
)
{
}
if
(
SYS_RUN_TASK_10MS
)
{
Protocol_Send_Service
();
Protocol_Service
();
BT_User_Process
();
}
if
(
SYS_RUN_TASK_20MS
)
...
...
@@ -62,7 +61,7 @@ static void Sys_Run_Tasks(void *arg)
if
(
SYS_RUN_TASK_50MS
)
{
Prot_Send_Msg_Process
();
}
if
(
SYS_RUN_TASK_100MS
)
...
...
@@ -72,10 +71,9 @@ static void Sys_Run_Tasks(void *arg)
if
(
SYS_RUN_TASK_1000MS
)
{
BT_User_Process
();
simple_ota_service
();
Protocol_Send_Service
();
simple_ota_service
();
testcnt
++
;
if
(
testcnt
>=
5
)
{
...
...
@@ -92,18 +90,19 @@ static void Sys_Run_Tasks(void *arg)
}
}
vTaskDelay
(
1
);
vTaskDelay
(
1
0
);
}
vTaskDelete
(
NULL
);
}
void
app_main
(
void
)
{
Protocol_User_Ctrl_Init
();
BT_User_Init
();
Ble_User_Init
();
Get_Mac_Init
();
bsp_BT_Init
();
bsp_Ble_Init
();
//
bsp_Ble_Init();
bsp_Uart_Init
();
xTaskCreatePinnedToCore
(
Sys_Run_Tasks
,
"Sys_Run_Tasks"
,
4096
,
NULL
,
3
,
NULL
,
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment