Commit a2e830ab authored by 李茂军's avatar 李茂军

feat:串口打开wifi

parent 5a96e48d
# Embed the server root certificate into the final binary
# Embed the server root certificate into the final binary "simple_ota_example.c"
idf_build_get_property(project_dir PROJECT_DIR)
idf_component_register(SRCS "app_BT_User.c" "bt_app_main.c" "bt_app_hf.c" "bt_app_core.c" "gatts_table_creat_demo.c"
"simple_ota_example.c"
"Protocol_CRC16.c"
"Protocol_Lib.c"
"Protocol_User.c"
......
......@@ -209,6 +209,8 @@ static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protoc
return 0;
}
extern void wifiServiceStart(void);
uint32_t SwitchMode=0;
static void Protocol_UartHandle(const Protocol_Data_t *pData)//esp接收底板数据
{
if ( pData->CmdID == 0x20 )//收到底板发送的数据后,传状态
......@@ -268,7 +270,9 @@ static void Protocol_UartHandle(const Protocol_Data_t *pData)//esp接收底板
if(Wifi_OTA_Request == 0)
{
Wifi_OTA_Request = 1;
printf("get ota req! \r\n");
printf("收到进入OTA指令 \r\n");
SwitchMode=1;
wifiServiceStart();
}
// }
}
......
......@@ -26,5 +26,104 @@ extern Protocol_User_Ctrl_Struct Prot_User;
void Protocol_User_Ctrl_Init(void );
void Prot_Send_Msg_Process(void );
#define UPGRADE_N32G031
#ifdef UPGRADE_N32G031
#define CMD_SET_BR 0x01//设置串口波特率
#define CMD_GET_INF 0x10//读取芯片型号索引、BOOT 版本号、芯片 ID
#define CMD_FLASH_ERASE 0x30//擦除 FLASH
#define CMD_FLASH_DWNLD 0x31//下载用户程序到 FLASH
#define CMD_DATA_CRC_CHECK 0x32//CRC 校验下载用户程
#define CMD_OPT_RW 0x40//读取/配置选项字节(包含了读保护等级、FLASH 页写保护、Data0/1 配置等)
#define CMD_SYS_RESET 0x50//系统复位
#define CMD_APP_GO 0x51//跳转到用户区执行程序
typedef struct
{
Protocol_uint8_t CMDH; //宏定义所包含的
Protocol_uint8_t CMDL;
Protocol_uint16_t LEN; //不关心发送的端格式
Protocol_uint8_t PAR[4];//需要处理好段格式
Protocol_uint8_t DAT[160];//补充的数据直接补充好再传到下层
}UpdateProtocolStructure;//上层协议数据结构
typedef struct
{
Protocol_uint8_t CMDH ;
Protocol_uint8_t CMDL ;
Protocol_uint8_t LEN[2];
union
{
Protocol_uint8_t DAT[128];
struct
{
Protocol_uint8_t unused_0 :8;
Protocol_uint8_t BootVer :8;
Protocol_uint8_t BootCmdVer :8;
Protocol_uint8_t UCID [16];
Protocol_uint8_t ChipID_UID [12];
Protocol_uint8_t DBGMCU_IDCODE[4];
Protocol_uint8_t Other [16];
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}Chipinf;
struct
{
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}Erase;
struct
{
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}download;
struct
{
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}verification;
struct
{
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}reset;
struct
{
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}appgo;
struct
{
struct Protocol_Lib
{
Protocol_uint8_t RDP ;
Protocol_uint8_t nRDP ;
Protocol_uint8_t USER ;
Protocol_uint8_t nUSER ;
Protocol_uint8_t Data0;
Protocol_uint8_t nData0;
Protocol_uint8_t Data1;
Protocol_uint8_t nData1;
Protocol_uint8_t WRP0;
Protocol_uint8_t nWRP0;
Protocol_uint8_t WRP1;
Protocol_uint8_t nWRP1;
Protocol_uint8_t RDP2;
Protocol_uint8_t nRDP2;
Protocol_uint8_t Reserved;
Protocol_uint8_t nReserved;
}optionbyte;
Protocol_uint8_t CR1 :8;
Protocol_uint8_t CR2 :8;
}flashOpt;
}dat;
}N32G031_ACK_Structure;//下层应答协议
extern N32G031_ACK_Structure N32G031_ACK;
Protocol_uint32_t UpdateN32G031Protocol_Send(UpdateProtocolStructure SendPd);
Protocol_uint32_t UpdateN32G031Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
#endif
#endif
......@@ -503,6 +503,8 @@ void Ble_User_Task(void *pvParameter)
vTaskDelete(NULL);
}
TaskHandle_t Ble_User_Task_hdl=NULL;
void Ble_User_Init(void )
{
BleRecSuc_Semaphore = xSemaphoreCreateBinary();
......@@ -529,6 +531,5 @@ void Ble_User_Init(void )
Ble_Clear_Rx_Buffer();
xTaskCreatePinnedToCore(Ble_User_Task, "Ble_User", 4096, NULL, 10, NULL, 0);
xTaskCreatePinnedToCore(Ble_User_Task, "Ble_User", 4096, NULL, 10, Ble_User_Task_hdl, 0);
}
......@@ -19,8 +19,8 @@ static void bt_app_task_handler(void *arg);
static bool bt_app_send_msg(bt_app_msg_t *msg);
static void bt_app_work_dispatched(bt_app_msg_t *msg);
static QueueHandle_t bt_app_task_queue = NULL;
static TaskHandle_t bt_app_task_handle = NULL;
QueueHandle_t bt_app_task_queue = NULL;
TaskHandle_t bt_app_task_handle = NULL;
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
{
......
......@@ -104,12 +104,12 @@ static void Uart_Rx_Task(void *arg)
}
free(data);
}
TaskHandle_t Uart_Rx_Taskhdl;
void bsp_Uart_Init(void )
{
init_Uart();
Protocol_KL30_Wakeup_Init();
xTaskCreatePinnedToCore(Uart_Rx_Task, "Ble_User", 4096, NULL, 4, NULL, 1);
xTaskCreatePinnedToCore(Uart_Rx_Task, "Ble_User", 4096, NULL, 4, Uart_Rx_Taskhdl, 1);
}
......@@ -119,16 +119,16 @@ void bsp_Uart_Init(void )
extern void simple_ota_main(void);
void simple_ota_service(void)
{
if(Wifi_OTA_Request == 1)
{
Wifi_OTA_Request = 2;
simple_ota_main();
vTaskDelay(portMAX_DELAY);
}
}
// extern void simple_ota_main(void);
// void simple_ota_service(void)
// {
// if(Wifi_OTA_Request == 1)
// {
// Wifi_OTA_Request = 2;
// simple_ota_main();
// vTaskDelay(portMAX_DELAY);
// }
// }
......
......@@ -73,7 +73,7 @@ void bsp_Uart_Init(void );
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];
......
......@@ -86,7 +86,7 @@ static void Sys_Run_Tasks(void *arg)
if(SYS_RUN_TASK_1000MS)
{
simple_ota_service();
// simple_ota_service();
testcnt++;
if(testcnt >= 10)
......@@ -120,32 +120,46 @@ static void Sys_Run_Tasks(void *arg)
vTaskDelay(1);
}
vTaskDelete(NULL);
// vTaskDelete(NULL);
}
TaskHandle_t wifi_service_hdl;
TaskHandle_t wifi_service_hdl=NULL;
extern uint32_t SwitchMode;
extern void wifiServiceStart(void);
static void wifi_service_task(void *arg)
{
while (1)
{
// if(SwitchMode == 1)
// {
// delele_tasks();
// SwitchMode=2;
// }
wifi_service_timer();
wifi_service();
vTaskDelay(pdMS_TO_TICKS(100));
}
}
TaskHandle_t Sys_Run_Taskshdl=NULL;
void app_main(void)
{
Protocol_User_Ctrl_Init();
// BT_User_Init();
// Ble_User_Init();
// Get_Mac_Init();
// bsp_BT_Init();
// bsp_Ble_Init();
BT_User_Init();
Ble_User_Init();
Get_Mac_Init();
bsp_BT_Init();
bsp_Ble_Init();
bsp_Uart_Init();
// printf("KL30 INIT OVER~~~~~~\r\n");
// xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, NULL, 1);
printf("KL30 INIT OVER~~~~~~\r\n");
xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, Sys_Run_Taskshdl, 1);
xTaskCreatePinnedToCore(wifi_service_task, "wifi_service_task", 4096, NULL, 5, &wifi_service_hdl, 1);
}
void delele_tasks(void)
{
vTaskSuspend(Sys_Run_Taskshdl);
vTaskSuspend(Ble_User_Task_hdl);
bt_app_task_shut_down( );
vTaskDelay(pdMS_TO_TICKS(100));
}
#ifndef _MAIN_USER_H_
#define _MAIN_USER_H_
extern TaskHandle_t Ble_User_Task_hdl;
extern TaskHandle_t Sys_Run_Taskshdl;
extern TaskHandle_t Uart_Rx_Taskhdl;
extern void bt_app_task_shut_down(void);
extern void delateBleUser_Task(void);
#endif
\ No newline at end of file
This diff is collapsed.
......@@ -5,9 +5,9 @@
#include "driver/uart.h"
#include "esp_wifi.h"
#include "wifi_service.h"
#include "main_user.h"
static const char *TAG = "wifi_service";
extern void delele_tasks(void);
/*****************************************************
* 首次启动HTTP服务器后, 如果一直没有STA设备加入
* 就不能触发STA disconnect事件,也就不会自动关闭HTTP服务器
......@@ -15,7 +15,7 @@ static const char *TAG = "wifi_service";
******************************************************/
static unsigned char http_server_stop_counter = 0;
static unsigned char softap_service_stop_flag = 0;
static unsigned short wifi_service_stop_timer = 0;
static unsigned short wifi_service_stop_timer = 0;
wifi_service_t wifi_service_info;
void wifi_service_init(void)
......@@ -31,11 +31,7 @@ void wifi_service_init(void)
void wifi_service_timer(void)
{
if(wifi_service_info.status == WIFI_SERVICE_STOP)
{
// 开启WiFi服务
wifi_service_info.status = WIFI_SERVICE_INIT;
}
if (wifi_service_info.status == WIFI_SERVICE_START)
{
if (wifi_service_stop_timer < 300)
......@@ -61,11 +57,11 @@ void wifi_service(void)
if (wifi_service_info.status == WIFI_SERVICE_INIT) // 收到指令: WiFi服务初始化
{
wifi_service_info.status = WIFI_SERVICE_START;
ESP_LOGI(TAG, "---- 关闭CAN总线, 卸载LIN driver, 开启WiFi服务...");
ESP_LOGI(TAG, "---- 开启WiFi服务...\n");
// Bsp_Can_Sleep_Init();
// uart_driver_delete(UART_NUM_1);
// delele_tasks();
softap_service_start();
}
else
......@@ -121,3 +117,12 @@ void wifi_service(void)
}
}
}
void wifiServiceStart(void)
{
if(wifi_service_info.status == WIFI_SERVICE_STOP)
{
// 开启WiFi服务
wifi_service_info.status = WIFI_SERVICE_INIT;
}
}
\ No newline at end of file
......@@ -26,5 +26,5 @@ void wifi_service(void);
extern void Bsp_Can_Sleep_Init(void);
extern void Bsp_Can_Wakeup_Init(void);
extern void bsp_Uart1_Init(void);
extern void wifiServiceStart(void);
#endif
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