与APP协议通讯验证,并添加获取与修改wifi、ble设置命令

This commit is contained in:
OPTOC
2025-09-19 14:51:49 +08:00
parent 6f6438f544
commit 7df60a6505
8 changed files with 76 additions and 51 deletions

View File

@@ -40,8 +40,6 @@ nvs_handle g_nvs_hdl; // nvs 句柄
os_work_q_t g_work_q_hdl_low; // 低于 default_os_work_q_hdl 优先级的工作队列
static void _init_nvs(void);
static void _init_ws2812(void);
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event);
static void _vset_cb(sh_t *sh_hdl);
void work_app_main(void *arg)
@@ -85,31 +83,11 @@ static void _init_nvs(void)
}
}
static void _init_ws2812(void)
{
#if (CONFIG_LED_STRIP_MAX_LEDS)
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, CONFIG_LED_STRIP_MAX_LEDS);
#else
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, 10);
#endif
}
static void _vset_cb(sh_t *sh_hdl)
{
}
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event)
{
static const char *const stat_tab[] = {
[PRESS_UP] = "up",
[PRESS_DOWN] = "down",
[LONG_PRESS_HOLD] = "held",
};
if (event < __ARRAY_SIZE(stat_tab) && stat_tab[event])
{
SYS_LOG_DBG("button stat: %s", stat_tab[event]);
}
}
// 导出符号,供 linker script 使用
// #include "utils/sb_aes.h"

View File

@@ -380,7 +380,7 @@ int app_cfg_set_wifi_ap_ssid(const void *ssid)
return -1;
}
strncpy(s_cfg_app.app_config_wifi_para.wifi_ap_ssid, ssid, __ARRAY_SIZE(s_cfg_app.app_config_wifi_para.wifi_ap_ssid));
app_cfg_do_save(1000);
app_cfg_do_save(0);
return 0;
}
int app_cfg_set_wifi_ap_password(const void *password)
@@ -397,7 +397,7 @@ int app_cfg_set_wifi_ap_password(const void *password)
return -1;
}
strncpy(s_cfg_app.app_config_wifi_para.wifi_ap_password, password, __ARRAY_SIZE(s_cfg_app.app_config_wifi_para.wifi_ap_password));
app_cfg_do_save(1000);
app_cfg_do_save(0);
return 0;
}
int app_cfg_set_wifi_sta_ssid(const void *ssid)
@@ -414,7 +414,7 @@ int app_cfg_set_wifi_sta_ssid(const void *ssid)
return -1;
}
strncpy(s_cfg_app.app_config_wifi_para.wifi_sta_ssid, ssid, __ARRAY_SIZE(s_cfg_app.app_config_wifi_para.wifi_sta_ssid));
app_cfg_do_save(1000);
app_cfg_do_save(0);
return 0;
}
int app_cfg_set_wifi_sta_password(const void *password)
@@ -431,7 +431,7 @@ int app_cfg_set_wifi_sta_password(const void *password)
return -1;
}
strncpy(s_cfg_app.app_config_wifi_para.wifi_sta_password, password, __ARRAY_SIZE(s_cfg_app.app_config_wifi_para.wifi_sta_password));
app_cfg_do_save(1000);
app_cfg_do_save(0);
return 0;
}

View File

@@ -94,8 +94,8 @@ static void ble_server_connect_handler(ble_server_status_t status)
static void _sb_manufacturer_encode(uint8_t manufacturer_data[20])
{
memset(manufacturer_data, 0, 20);
manufacturer_data[0] = 'K';
manufacturer_data[1] = 'Y';
manufacturer_data[0] = 0x59;
manufacturer_data[1] = 0x00;
manufacturer_data[2] = PRODUCT0;
manufacturer_data[3] = PRODUCT1;
manufacturer_data[4] = VERSIONS;
@@ -145,7 +145,7 @@ static void wifi_event_handler(bool is_connect, sb_data_port_t *port)
}
SYS_LOG_INF("wifi connect");
}else{
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
if(res == DEVICE_PC_ERROR)
{
SYS_LOG_ERR("wifi pc device choice error");

View File

@@ -151,7 +151,7 @@ void mavlik_packet_processing(mavlink_device_t* mavlink_device, mavlink_message_
{
//printf("MAVLINK_MSG_ID_ATTITUDE\n");
mavlink_msg_attitude_decode(message, &(mavlink_device->current_messages.attitude));
printf("pitch %f roll %f yaw %f\n", mavlink_device->current_messages.attitude.pitch * 180 / 3.1415926, mavlink_device->current_messages.attitude.roll * 180 / 3.1415926, mavlink_device->current_messages.attitude.yaw * 180 / 3.1415926);
// printf("pitch %f roll %f yaw %f\n", mavlink_device->current_messages.attitude.pitch * 180 / 3.1415926, mavlink_device->current_messages.attitude.roll * 180 / 3.1415926, mavlink_device->current_messages.attitude.yaw * 180 / 3.1415926);
break;
}

View File

@@ -213,7 +213,13 @@ int resend_send_data(resend_device_t *resend_device, uint8_t cmd, void* data, ui
resend_device->tx_frame.retry_cnt ++;
// 接收数据
resend_recv_data(resend_device, timeout);
uint16_t timeout_lat = timeout + 1;
while(timeout_lat --)
{
if(resend_recv_data(resend_device, 0) > 0)
break;
os_thread_sleep(1);
}
// 超过允许的等待次数
if(resend_device->tx_frame.retry_cnt > RESEND_MAX_RETRY_CNT)
{
@@ -232,26 +238,20 @@ int resend_parse_data(resend_device_t *resend_device)
{
switch(resend_device->rx_frame.cmd){
case RESEND_CMD_DATA:
for (size_t i = 0; i < resend_device->rx_frame.len; i++)
{
printf("%02X ", resend_device->rx_frame.payload[i]);
}
printf("\r\n");
break;
case RESEND_CMD_ACK:
printf("ACK\n");
resend_device->status.ack_flag = 0;
break;
case RESEND_CMD_GET_STATUS:
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
resend_device->handle_flag = RESEND_CMD_GET_STATUS;
break;
case RESEND_CMD_STATUS:
case RESEND_CMD_PARAM:
resend_set(resend_device);
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
break;
case RESEND_CMD_SET_STATUS:
case RESEND_CMD_GET_PARAM:
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
resend_device->handle_flag = RESEND_CMD_GET_PARAM;
break;
case RESEND_CMD_SET_PARAM:
break;
case RESEND_CMD_DATA_ACK:
for (size_t i = 0; i < resend_device->rx_frame.len; i++)

View File

@@ -4,7 +4,10 @@
#include <stdint.h>
#include <string.h>
#include "resend_crc.h"
#include "os/os.h"
#include "os/os_common.h"
#include "console.h"
#include "shell/sh_vset.h"
// 帧数据量
#define RESEND_HEADER_SIZE 2
#define RESEND_CMD_SIZE 1
@@ -25,9 +28,9 @@ typedef enum
{
RESEND_CMD_DATA = 0x01,
RESEND_CMD_ACK = 0x02,
RESEND_CMD_GET_STATUS = 0x03,
RESEND_CMD_STATUS = 0x04,
RESEND_CMD_SET_STATUS = 0x05,
RESEND_CMD_PARAM = 0x03,
RESEND_CMD_GET_PARAM = 0x04,
RESEND_CMD_SET_PARAM = 0x05,
RESEND_CMD_DATA_ACK = 0x06,

View File

@@ -99,24 +99,42 @@ void app_thread(void* arg)
{
while (true)
{
switch(0)
switch(sertrf.resend_device.handle_flag)
{
case 0:
case RESEND_CMD_GET_PARAM:
sertrf_stauct_t sertrf_stauct;
strcpy(sertrf_stauct.ble_name, g_cfg_app->device_name_ble);
strcpy(sertrf_stauct.wifi_ap_ssid, g_cfg_app->app_config_wifi_para.wifi_ap_ssid);
strcpy(sertrf_stauct.wifi_ap_password, g_cfg_app->app_config_wifi_para.wifi_ap_password);
strcpy(sertrf_stauct.wifi_sta_ssid, g_cfg_app->app_config_wifi_para.wifi_sta_ssid);
strcpy(sertrf_stauct.wifi_sta_password, g_cfg_app->app_config_wifi_para.wifi_sta_password);
resend_send_data(&sertrf.resend_device, RESEND_CMD_GET_PARAM, &sertrf_stauct, sizeof(sertrf_stauct_t), 100);
sertrf.resend_device.handle_flag = 0;//标志位清零
break;
case 1:
break;
default:
break;
}
resend_recv_data(&sertrf.resend_device,0);
resend_recv_data(&sertrf.resend_device, 0);
// static uint8_t count = 0;
// count++;
// if(count > 100)
// {
// // resend_send_cmd(&sertrf.resend_device, RESEND_CMD_ACK, 0);
// resend_send_data(&sertrf.resend_device, RESEND_CMD_GET_PARAM, NULL, 0, 0);
// // count = 0;
// }
// uint32_t app_size = app_device_get_rx_length(&sertrf.device);
// if(app_size > 0)
// {
// uint8_t data[app_size];
// app_device_read(&sertrf.device, data, app_size,0);
// // printf("data:%d:%s\n", app_size,data);
// printf("data:%d:%s\n", app_size,data);
// }
os_thread_sleep(1);
}
@@ -263,6 +281,22 @@ void resend_user_parse(void *resend_device)
resend_device_t* resend_parse = (resend_device_t*)resend_device;
switch(resend_parse->rx_frame.cmd)
{
case RESEND_CMD_SET_PARAM:
if(sizeof(sertrf_stauct_t) != resend_parse->rx_frame.len)
{
printf("RESEND_CMD_SET_PARAM len error\r\n");
}
sertrf_stauct_t* sertrf_stauct = (sertrf_stauct_t*)resend_parse->rx_frame.payload;
app_cfg_set_device_name_ble(sertrf_stauct->ble_name, strlen(sertrf_stauct->ble_name));
app_cfg_set_wifi_ap_ssid(sertrf_stauct->wifi_ap_ssid);
app_cfg_set_wifi_ap_password(sertrf_stauct->wifi_ap_password);
app_cfg_set_wifi_sta_ssid(sertrf_stauct->wifi_sta_ssid);
app_cfg_set_wifi_sta_password(sertrf_stauct->wifi_sta_password);
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
os_thread_sleep(1000);
esp_restart();
break;
case RESEND_CMD_OTA_START:
{
if(!sertrf.resend_device.status.resend_flag)

View File

@@ -6,6 +6,8 @@
#include "protocol/p_protocol.h"
#include "protocol/resend_protl.h"
#include "ota_u.h"
#include "../../config/app_config.h"
typedef struct
{
device_t device;
@@ -20,6 +22,14 @@ typedef struct
}sertrf_t;
typedef struct
{
char ble_name[32];
char wifi_ap_ssid[32];
char wifi_ap_password[32];
char wifi_sta_ssid[32];
char wifi_sta_password[32];
}sertrf_stauct_t;
/**
* @brief 模块初始化
*/