Commit 07f1cd03 authored by 梁百峰's avatar 梁百峰

feat:检测台ble检测

parent 32b8cc13
......@@ -6,4 +6,4 @@ cmake_minimum_required(VERSION 3.16)
set(EXTRA_COMPONENT_DIRS "./source/wifi")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(TianYing100)
project(yedeajiancetai)
......@@ -9,9 +9,24 @@
*/
#include <stdio.h>
#include <string.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 "esp_gatt_common_api.h"
// #include "bsp_UART.h"
#include <string.h>
// #include "CAN_CH0_CAN_Communication_Matrix.h"
static UARTOpen UARTOpen_Cbk;
static UARTSend UARTSend_Cbk;
static UARTRead UARTRead_Cbk;
......@@ -21,6 +36,9 @@ static ProtocolSetData ProtocolSetData_Cbk;
static Protocol_uint8_t *mDataBufPtr = Protocol_NULL;
static Protocol_uint16_t mDataBufLen = 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
/**
* @brief 初始化函数
......@@ -52,6 +70,38 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protoc
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 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
......@@ -64,31 +114,59 @@ void Protocol_Service(void)
{
int len = 0;
int num =0;
int i = 0;
int j = 0;
Protocol_uint32_t readNum = 0;
if ( UARTRead_Cbk != Protocol_NULL )
{
readNum = UARTRead_Cbk(mDataBufPtr + mDataBufLen, 256 - mDataBufLen);
if ( readNum > 0 )
if (readNum > 0)
{
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 = 7;
len = mDataBufLen;
if ( (len > 0) && (len < mDataBufLen) )
{
// 将未解析的数据移到头部
// Move unparsed data to the head
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;
}
BleDataGet();
}
}
}
......
......@@ -24,8 +24,8 @@ Platform_16Bit
#define DATA_PACKAGE_MIN_LEN 7 /**< 0xEB 0x90 + 长度 + 数据包序号 + CMDID + CRC16_1 + CRC16_2 */
#define DATA_PACKAGE_FIXED_LEN 3 /**< 未计算在长度内的数据 0xEB 0x90 + 长度位 */
#define CMD_HEAD1 0xEB
#define CMD_HEAD2 0x90
#define CMD_HEAD1 0x59
#define CMD_HEAD2 0x44
/**@struct Protocol_Data_t
* @brief 解析后的协议数据
......@@ -63,5 +63,5 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t M
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);
extern Protocol_uint8_t first;
#endif
......@@ -300,7 +300,7 @@ void UART_Put(Protocol_uint16_t Data)
UARTRxBuf.Rx_Buffer [ UARTRxBuf.write_pos ] = Data;
UARTRxBuf.write_pos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
}
printf("into UARTRxBuf!!!!\r\n");
// printf("into UARTRxBuf!!!!\r\n");
return;
}
......
......@@ -76,6 +76,7 @@ void init_Uart(void) {
// We won't use a buffer for sending data.
uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 200, 0, NULL, 0);
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);
}
......@@ -140,6 +141,7 @@ void bsp_Uart_Init(void )
{
init_Uart();
Protocol_KL30_Wakeup_Init();
printf("uart init!!\n");
xTaskCreatePinnedToCore(Uart_Rx_Task, "bsp_Uart", 4096, NULL, 4, NULL, 1);
}
......@@ -212,7 +214,7 @@ unsigned char write_char_data[] = {
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 bool connect = 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
// char_value[i] = temp1[i];
// }
// }
uint8_t bledisconnectflag = 0;
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)
{
esp_ble_gattc_write_char( blesend,
......@@ -752,6 +762,8 @@ void ble_send(void)
ESP_GATT_WRITE_TYPE_RSP,
ESP_GATT_AUTH_REQ_NONE);
}
// }
}
void bsp_Ble_Init(void)
......
......@@ -80,4 +80,6 @@ extern uint8_t BT_Device_Name[13];
void Get_Mac_Init(void );
extern int bsp_Uart_Send_Data(uint8_t * data , unsigned int len);
extern void ble_send(void);
extern char remote_device_name[];
extern uint8_t bledisconnectflag;
#endif
......@@ -140,14 +140,15 @@ static void wifi_service_task(void *arg)
void app_main(void)
{
bsp_Uart_Init();
Protocol_User_Ctrl_Init();
// BT_User_Init();
Ble_User_Init();
bsp_Ble_Init();
// bsp_Ble_Init();
// Get_Mac_Init();
// bsp_BT_Init();
// bsp_Ble_Init();
bsp_Uart_Init();
//printf("KL30 INIT OVER~~~~~~\r\n");
......
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