1. 修复本地控制无法修改开关名字的问题

2. 启动后默认启动本地离线控制
This commit is contained in:
2025-07-22 21:52:46 +08:00
parent 6cd2908eaf
commit 2a5be3af4b
8 changed files with 18 additions and 33 deletions

View File

@ -30,7 +30,7 @@ extern "C" {
#define DEVICE_HIVERSION "1.0.0"
/* 设备固件版本号 */
#define FIRMWARE_VER "1.0.0"
#define FIRMWARE_VER "1.0.1"
/* 设备硬件版本号 */
#define HARDWARE_VER "1.0.0"
/* 设备软件版本号 */

View File

@ -343,10 +343,6 @@ int handle_get_cmd(const char* svc_id, const char* in, unsigned int in_len, char
// 支持蓝牙和云端双模式上报
int fast_report(const char* svc_id)
{
// 引入外部的蓝牙控制函数
extern bool switch_panel_ble_is_enabled(void);
extern int switch_panel_ble_fast_report(const char *svc_id);
// 检查当前是否处于蓝牙控制模式
if (switch_panel_ble_is_enabled()) {
// 蓝牙模式下通过蓝牙上报

View File

@ -118,6 +118,7 @@ typedef struct {
bool config_led_blink_state; // 配网LED闪烁状态
bool factory_test_running; // 产测是否运行中
uint32_t last_save_time; // 上次保存时间
bool is_online;
uint32_t reserved[16]; // 保留字段
} device_runtime_state_t;

View File

@ -39,15 +39,13 @@ static void ble_report_switch_state(int switch_id) {
char buff[128] = {0};
char svc_id[16] = {0};
char switch_name[16] = {0};
snprintf_s(svc_id, sizeof(svc_id), sizeof(svc_id) - 1, "switch%d", switch_id + 1);
snprintf_s(switch_name, sizeof(switch_name), sizeof(switch_name) - 1, "开关%d", switch_id + 1);
int ret = snprintf_s(buff, sizeof(buff), sizeof(buff) - 1,
SWITCH_BLE_NAME_REPORT,
g_persistent_state.switches[switch_id].switch_on ? 1 : 0,
switch_name,
g_persistent_state.switches[switch_id].name,
svc_id);
if (ret <= 0) {
e_printf("[BLE] 开关%d状态格式化失败: %d\r\n", switch_id + 1, ret);
@ -113,18 +111,15 @@ static int ble_handle_switch_control(const char *svc_id, cJSON *dataItem) {
e_printf("[BLE] 未知的开关ID: %s\r\n", svc_id);
return -1;
}
cJSON *onItem = cJSON_GetObjectItem(dataItem, "on");
if (onItem == NULL || !cJSON_IsNumber(onItem)) {
e_printf("[BLE] 开关%d控制指令格式错误\r\n", switch_id + 1);
return -1;
cJSON* on_item = cJSON_GetObjectItem(dataItem, "on");
if (on_item) {
update_switch_state(switch_id, cJSON_GetNumberValue(on_item));
}
cJSON* name_item = cJSON_GetObjectItem(dataItem, "name");
if (name_item) {
set_switch_name(switch_id, cJSON_GetStringValue(name_item));
}
bool new_state = (onItem->valueint != 0);
e_printf("[BLE] 接收到开关%d控制指令: %s\r\n", switch_id + 1, new_state ? "" : "");
// 调用现有的开关控制函数
update_switch_state(switch_id, new_state);
// 通过蓝牙上报状态确认
ble_report_switch_state(switch_id);

View File

@ -16,7 +16,7 @@ static int handle_put_switch_common(int switch_id, const char* svc_id,
// 处理设备上线事件
void handle_device_online(void) {
e_printf("设备上线\r\n");
g_runtime_state.is_online = true;
// 检查是否是新绑定的设备
bool was_unbound = !g_persistent_state.is_bound;
@ -51,7 +51,6 @@ void handle_device_online(void) {
e_printf("已恢复默认状态总开关关闭所有子开关关闭LED黄灯面板背光开启\r\n");
}
// 设备上线时禁用蓝牙模式,启用云端模式
extern void switch_panel_ble_disable(void);
switch_panel_ble_disable();
// 同步所有状态到云端
@ -64,12 +63,9 @@ void handle_device_online(void) {
// 处理设备下线事件
void handle_device_offline(void) {
e_printf("设备下线\r\n");
g_runtime_state.is_online = false;
// 设备下线时启用蓝牙模式,支持本地控制
extern void switch_panel_ble_enable(void);
switch_panel_ble_enable();
// 设备下线时保持现有状态,不做特殊处理
}
// 处理设备解绑事件
@ -249,11 +245,6 @@ static int handle_get_switch_common(int switch_id, const char* svc_id,
//====================== HiLink 事件扩展函数 ======================
// 检查设备是否在线
bool is_device_online(void) {
return g_persistent_state.is_bound;
}
// 获取设备当前模式
system_mode_t get_current_mode(void) {
return g_runtime_state.mode;

View File

@ -862,9 +862,11 @@ int switch_panel_main(void) {
}
} else {
e_printf("设备已绑定,正常运行\r\n");
// 设备已绑定时禁用蓝牙模式,使用云端控制
extern void switch_panel_ble_disable(void);
switch_panel_ble_disable();
if (!g_runtime_state.is_online)
{
switch_panel_ble_enable();
start_hilink_ble_net_config(0xFFFFFFFF);
}
}
e_printf("SORONTEK智能面板初始化完成\r\n");