Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiancetai
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
陈家乐
jiancetai
Commits
07f1cd03
Commit
07f1cd03
authored
Apr 30, 2025
by
梁百峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
feat:检测台ble检测
parent
32b8cc13
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
123 additions
and
30 deletions
+123
-30
CMakeLists.txt
CMakeLists.txt
+1
-1
Protocol_Lib.c
main/Protocol_Lib.c
+90
-12
Protocol_Lib.h
main/Protocol_Lib.h
+3
-3
Protocol_User.c
main/Protocol_User.c
+1
-1
gatts_table_creat_demo.c
main/gatts_table_creat_demo.c
+23
-11
gatts_table_creat_demo.h
main/gatts_table_creat_demo.h
+2
-0
main_user.c
main/main_user.c
+3
-2
No files found.
CMakeLists.txt
View file @
07f1cd03
...
@@ -6,4 +6,4 @@ cmake_minimum_required(VERSION 3.16)
...
@@ -6,4 +6,4 @@ cmake_minimum_required(VERSION 3.16)
set
(
EXTRA_COMPONENT_DIRS
"./source/wifi"
)
set
(
EXTRA_COMPONENT_DIRS
"./source/wifi"
)
include
(
$ENV{IDF_PATH}/tools/cmake/project.cmake
)
include
(
$ENV{IDF_PATH}/tools/cmake/project.cmake
)
project
(
TianYing100
)
project
(
yedeajiancetai
)
main/Protocol_Lib.c
View file @
07f1cd03
...
@@ -9,9 +9,24 @@
...
@@ -9,9 +9,24 @@
*/
*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include "Protocol_CRC16.h"
#include "Protocol_CRC16.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_main.h"
#include "gatts_table_creat_demo.h"
#include "gatts_table_creat_demo.h"
#include "esp_gatt_common_api.h"
// #include "bsp_UART.h"
#include <string.h>
// #include "CAN_CH0_CAN_Communication_Matrix.h"
static
UARTOpen
UARTOpen_Cbk
;
static
UARTOpen
UARTOpen_Cbk
;
static
UARTSend
UARTSend_Cbk
;
static
UARTSend
UARTSend_Cbk
;
static
UARTRead
UARTRead_Cbk
;
static
UARTRead
UARTRead_Cbk
;
...
@@ -21,6 +36,9 @@ static ProtocolSetData ProtocolSetData_Cbk;
...
@@ -21,6 +36,9 @@ static ProtocolSetData ProtocolSetData_Cbk;
static
Protocol_uint8_t
*
mDataBufPtr
=
Protocol_NULL
;
static
Protocol_uint8_t
*
mDataBufPtr
=
Protocol_NULL
;
static
Protocol_uint16_t
mDataBufLen
=
0
;
static
Protocol_uint16_t
mDataBufLen
=
0
;
static
Protocol_uint32_t
DataBufMaxLen
=
0
;
static
Protocol_uint32_t
DataBufMaxLen
=
0
;
Protocol_uint8_t
BarCode
[
256
]
=
{
0
};
Protocol_uint8_t
BarCode1
[
256
]
=
{
0
};
#define GATTC_TAG "Uart_get"
//#define DEBUG_PRO_DATA 0
//#define DEBUG_PRO_DATA 0
/**
/**
* @brief 初始化函数
* @brief 初始化函数
...
@@ -52,6 +70,38 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protoc
...
@@ -52,6 +70,38 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protoc
return
;
return
;
}
}
Protocol_uint8_t
first
=
0
;
void
BleDataGet
(
void
)
{
if
(
BarCode1
[
0
]
==
0x59
&&
BarCode1
[
1
]
==
0x44
&&
BarCode1
[
9
]
==
0x4B
&&
BarCode1
[
10
]
==
0x4A
)
{
printf
(
"bleget~~~
\n
"
);
memcpy
(
remote_device_name
,
&
BarCode1
[
2
],
6
);
printf
(
"remote_device_name:"
);
ESP_LOG_BUFFER_HEX
(
GATTC_TAG
,
remote_device_name
,
6
);
printf
(
"remote_device_name[0]:%x
\n
"
,
remote_device_name
[
0
]);
if
(
BarCode1
[
8
]
==
1
)
{
if
(
first
==
0
)
{
bsp_Ble_Init
();
first
=
1
;
}
}
else
{
if
(
first
==
1
)
{
esp_bluedroid_disable
();
esp_bluedroid_deinit
();
esp_bt_controller_disable
();
esp_bt_controller_deinit
();
first
=
0
;
}
}
}
}
/**
/**
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
...
@@ -64,31 +114,59 @@ void Protocol_Service(void)
...
@@ -64,31 +114,59 @@ void Protocol_Service(void)
{
{
int
len
=
0
;
int
len
=
0
;
int
num
=
0
;
int
num
=
0
;
int
i
=
0
;
int
j
=
0
;
Protocol_uint32_t
readNum
=
0
;
Protocol_uint32_t
readNum
=
0
;
if
(
UARTRead_Cbk
!=
Protocol_NULL
)
if
(
UARTRead_Cbk
!=
Protocol_NULL
)
{
{
readNum
=
UARTRead_Cbk
(
mDataBufPtr
+
mDataBufLen
,
256
-
mDataBufLen
);
readNum
=
UARTRead_Cbk
(
mDataBufPtr
+
mDataBufLen
,
256
-
mDataBufLen
);
if
(
readNum
>
0
)
if
(
readNum
>
0
)
{
{
mDataBufLen
+=
readNum
;
mDataBufLen
+=
readNum
;
while
(
mDataBufLen
)
{
memset
(
BarCode1
,
0
,
sizeof
(
BarCode1
));
for
(
i
=
0
;
i
<
mDataBufLen
;
i
++
)
{
if
(
i
>
5
)
{
if
((
mDataBufPtr
[
i
]
==
0x4A
)
&&
(
mDataBufPtr
[
i
-
1
]
==
0x4B
))
{
if
(
i
<
1
)
{
break
;
}
memset
(
BarCode1
,
0
,
sizeof
(
BarCode1
));
for
(
j
=
0
;
j
<
i
+
1
;
j
++
)
{
BarCode1
[
j
]
=
mDataBufPtr
[
j
];
}
break
;
ESP_LOG_BUFFER_HEX
(
GATTC_TAG
,
BarCode1
,
20
);
}
}
}
// 解析协议
// 解析协议
len
=
Protocol_Parse
(
mDataBufPtr
,
mDataBufLen
);
len
=
mDataBufLen
;
len
=
7
;
if
(
(
len
>
0
)
&&
(
len
<
mDataBufLen
)
)
if
(
(
len
>
0
)
&&
(
len
<
mDataBufLen
)
)
{
{
// 将未解析的数据移到头部
// 将未解析的数据移到头部
// Move unparsed data to the head
// Move unparsed data to the head
memcpy
(
mDataBufPtr
,
mDataBufPtr
+
len
,
mDataBufLen
-
len
);
memcpy
(
mDataBufPtr
,
mDataBufPtr
+
len
,
mDataBufLen
-
len
);
// memcpy(nowdata,mDataBufPtr + len,len);
// datacheck();
}
}
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
0
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
1
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
2
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
3
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
4
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
5
]);
printf
(
"get num~~~~~~~~~~~~~~%x
\n
"
,
mDataBufPtr
[
6
]);
mDataBufLen
-=
len
;
mDataBufLen
-=
len
;
}
BleDataGet
();
}
}
}
}
}
}
...
...
main/Protocol_Lib.h
View file @
07f1cd03
...
@@ -24,8 +24,8 @@ Platform_16Bit
...
@@ -24,8 +24,8 @@ Platform_16Bit
#define DATA_PACKAGE_MIN_LEN 7
/**< 0xEB 0x90 + 长度 + 数据包序号 + CMDID + CRC16_1 + CRC16_2 */
#define DATA_PACKAGE_MIN_LEN 7
/**< 0xEB 0x90 + 长度 + 数据包序号 + CMDID + CRC16_1 + CRC16_2 */
#define DATA_PACKAGE_FIXED_LEN 3
/**< 未计算在长度内的数据 0xEB 0x90 + 长度位 */
#define DATA_PACKAGE_FIXED_LEN 3
/**< 未计算在长度内的数据 0xEB 0x90 + 长度位 */
#define CMD_HEAD1 0x
EB
#define CMD_HEAD1 0x
59
#define CMD_HEAD2 0x
90
#define CMD_HEAD2 0x
44
/**@struct Protocol_Data_t
/**@struct Protocol_Data_t
* @brief 解析后的协议数据
* @brief 解析后的协议数据
...
@@ -63,5 +63,5 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t M
...
@@ -63,5 +63,5 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t M
void
Protocol_Service
(
void
);
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
);
extern
Protocol_uint8_t
first
;
#endif
#endif
main/Protocol_User.c
View file @
07f1cd03
...
@@ -300,7 +300,7 @@ void UART_Put(Protocol_uint16_t Data)
...
@@ -300,7 +300,7 @@ void UART_Put(Protocol_uint16_t Data)
UARTRxBuf
.
Rx_Buffer
[
UARTRxBuf
.
write_pos
]
=
Data
;
UARTRxBuf
.
Rx_Buffer
[
UARTRxBuf
.
write_pos
]
=
Data
;
UARTRxBuf
.
write_pos
=
(
UARTRxBuf
.
write_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
UARTRxBuf
.
write_pos
=
(
UARTRxBuf
.
write_pos
+
1
)
%
UART_RX_MAX_DEPTH
;
}
}
printf
(
"into UARTRxBuf!!!!
\r\n
"
);
//
printf("into UARTRxBuf!!!!\r\n");
return
;
return
;
}
}
...
...
main/gatts_table_creat_demo.c
View file @
07f1cd03
...
@@ -76,6 +76,7 @@ void init_Uart(void) {
...
@@ -76,6 +76,7 @@ void init_Uart(void) {
// 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
,
200
,
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
);
printf
(
"GPIO38
\n
"
);
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
);
}
}
...
@@ -140,6 +141,7 @@ void bsp_Uart_Init(void )
...
@@ -140,6 +141,7 @@ void bsp_Uart_Init(void )
{
{
init_Uart
();
init_Uart
();
Protocol_KL30_Wakeup_Init
();
Protocol_KL30_Wakeup_Init
();
printf
(
"uart init!!
\n
"
);
xTaskCreatePinnedToCore
(
Uart_Rx_Task
,
"bsp_Uart"
,
4096
,
NULL
,
4
,
NULL
,
1
);
xTaskCreatePinnedToCore
(
Uart_Rx_Task
,
"bsp_Uart"
,
4096
,
NULL
,
4
,
NULL
,
1
);
}
}
...
@@ -212,7 +214,7 @@ unsigned char write_char_data[] = {
...
@@ -212,7 +214,7 @@ unsigned char write_char_data[] = {
0x99
,
0xA2
,
0x9c
,
0x4B
,
0x4A
0x99
,
0xA2
,
0x9c
,
0x4B
,
0x4A
};
};
static
char
remote_device_name
[]
=
{
0x0A
,
0x8A
,
0x0A
,
0x0A
,
0x00
,
0x00
};
char
remote_device_name
[]
=
{
0x0A
,
0x8A
,
0x0A
,
0x0A
,
0x00
,
0x00
};
// static char remote_device_name[] = "YD0A0A0000";
// static char remote_device_name[] = "YD0A0A0000";
static
bool
connect
=
false
;
static
bool
connect
=
false
;
static
bool
get_server
=
false
;
static
bool
get_server
=
false
;
...
@@ -740,8 +742,16 @@ static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp
...
@@ -740,8 +742,16 @@ static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp
// char_value[i] = temp1[i];
// char_value[i] = temp1[i];
// }
// }
// }
// }
uint8_t
bledisconnectflag
=
0
;
void
ble_send
(
void
)
void
ble_send
(
void
)
{
{
// if(bledisconnectflag == 1)
// {
// // esp_ble_gattc_close(blesend,gl_profile_tab[PROFILE_A_APP_ID].conn_id);
// }
// else
// {
if
(
blesend
!=
0
)
if
(
blesend
!=
0
)
{
{
esp_ble_gattc_write_char
(
blesend
,
esp_ble_gattc_write_char
(
blesend
,
...
@@ -752,6 +762,8 @@ void ble_send(void)
...
@@ -752,6 +762,8 @@ void ble_send(void)
ESP_GATT_WRITE_TYPE_RSP
,
ESP_GATT_WRITE_TYPE_RSP
,
ESP_GATT_AUTH_REQ_NONE
);
ESP_GATT_AUTH_REQ_NONE
);
}
}
// }
}
}
void
bsp_Ble_Init
(
void
)
void
bsp_Ble_Init
(
void
)
...
...
main/gatts_table_creat_demo.h
View file @
07f1cd03
...
@@ -80,4 +80,6 @@ extern uint8_t BT_Device_Name[13];
...
@@ -80,4 +80,6 @@ extern uint8_t BT_Device_Name[13];
void
Get_Mac_Init
(
void
);
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
);
extern
void
ble_send
(
void
);
extern
void
ble_send
(
void
);
extern
char
remote_device_name
[];
extern
uint8_t
bledisconnectflag
;
#endif
#endif
main/main_user.c
View file @
07f1cd03
...
@@ -140,14 +140,15 @@ static void wifi_service_task(void *arg)
...
@@ -140,14 +140,15 @@ static void wifi_service_task(void *arg)
void
app_main
(
void
)
void
app_main
(
void
)
{
{
bsp_Uart_Init
();
Protocol_User_Ctrl_Init
();
Protocol_User_Ctrl_Init
();
// BT_User_Init();
// BT_User_Init();
Ble_User_Init
();
Ble_User_Init
();
bsp_Ble_Init
();
//
bsp_Ble_Init();
// Get_Mac_Init();
// Get_Mac_Init();
// bsp_BT_Init();
// bsp_BT_Init();
// bsp_Ble_Init();
// bsp_Ble_Init();
bsp_Uart_Init
();
//printf("KL30 INIT OVER~~~~~~\r\n");
//printf("KL30 INIT OVER~~~~~~\r\n");
...
...
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