diff --git a/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h b/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h index a413ae2..a41e8ce 100755 --- a/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h +++ b/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h @@ -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" /* 设备软件版本号 */ diff --git a/application/samples/wifi/ohos_connect/hilink_adapt/product/hilink_device.c b/application/samples/wifi/ohos_connect/hilink_adapt/product/hilink_device.c index 3980e2f..ec0fcc5 100755 --- a/application/samples/wifi/ohos_connect/hilink_adapt/product/hilink_device.c +++ b/application/samples/wifi/ohos_connect/hilink_adapt/product/hilink_device.c @@ -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()) { // 蓝牙模式下通过蓝牙上报 diff --git a/application/ws63/user_main/switch_panel/switch_panel.h b/application/ws63/user_main/switch_panel/switch_panel.h index 729da6b..8d05a09 100644 --- a/application/ws63/user_main/switch_panel/switch_panel.h +++ b/application/ws63/user_main/switch_panel/switch_panel.h @@ -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; diff --git a/application/ws63/user_main/switch_panel/switch_panel_ble.c b/application/ws63/user_main/switch_panel/switch_panel_ble.c index 77001cb..630c414 100755 --- a/application/ws63/user_main/switch_panel/switch_panel_ble.c +++ b/application/ws63/user_main/switch_panel/switch_panel_ble.c @@ -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); diff --git a/application/ws63/user_main/switch_panel/switch_panel_hilink.c b/application/ws63/user_main/switch_panel/switch_panel_hilink.c index d314312..4c19284 100644 --- a/application/ws63/user_main/switch_panel/switch_panel_hilink.c +++ b/application/ws63/user_main/switch_panel/switch_panel_hilink.c @@ -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; diff --git a/application/ws63/user_main/switch_panel/switch_panel_main.c b/application/ws63/user_main/switch_panel/switch_panel_main.c index 05029f8..8ed546b 100644 --- a/application/ws63/user_main/switch_panel/switch_panel_main.c +++ b/application/ws63/user_main/switch_panel/switch_panel_main.c @@ -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"); diff --git a/output/LPT262_hilink-SR_Switch-20250722-1.0.1-初始版本.fwpkg b/output/LPT262_hilink-SR_Switch-20250722-1.0.1-初始版本.fwpkg new file mode 100644 index 0000000..92d7f66 Binary files /dev/null and b/output/LPT262_hilink-SR_Switch-20250722-1.0.1-初始版本.fwpkg differ diff --git a/output/package(SR_Switch-LPT262_hilink-20250722-1.0.1-初始版本).zip b/output/package(SR_Switch-LPT262_hilink-20250722-1.0.1-初始版本).zip new file mode 100644 index 0000000..bc6154c Binary files /dev/null and b/output/package(SR_Switch-LPT262_hilink-20250722-1.0.1-初始版本).zip differ