1. 增加本地离线控制功能
2. 优化代码逻辑加入很多异步操作 3. 适配switch相关物模型
This commit is contained in:
@ -42,6 +42,7 @@
|
||||
//static bool g_switch = 0;
|
||||
int sid_switch;
|
||||
static bool g_autoUpdate = 0;
|
||||
static int ble_adv_time = 0;
|
||||
static HILINK_BT_DevInfo g_btDevInfo = {0};
|
||||
extern int set_get_ble_mac(void);
|
||||
extern int HILINK_Printf(const char *format, ...);
|
||||
@ -255,6 +256,7 @@ static void ReporFwvCheckSum(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ble_sdk_running = 0;
|
||||
static void HILINK_BT_StateChangeHandler(HILINK_BT_SdkStatus event, const void *param)
|
||||
{
|
||||
(void)param;
|
||||
@ -269,10 +271,12 @@ static void HILINK_BT_StateChangeHandler(HILINK_BT_SdkStatus event, const void *
|
||||
HILINK_SAL_ERROR("set addr err\n");
|
||||
}
|
||||
/* 设置蓝牙广播格式,包括靠近发现、碰一碰等,下一次发送广播生效 */
|
||||
BLE_SetAdvType(BLE_ADV_NEARBY_V0);
|
||||
BLE_SetAdvType(BLE_ADV_LOCAL_NAME);
|
||||
|
||||
/* BLE配网广播控制:参数代表广播时间,0:停止;0xFFFFFFFF:一直广播,其他:广播指定时间后停止,单位秒 */
|
||||
(void)BLE_CfgNetAdvCtrl(BLE_ADV_TIME);
|
||||
(void)BLE_CfgNetAdvCtrl(ble_adv_time);
|
||||
ble_sdk_running = 1;
|
||||
e_printf("callback set ble adv time: %ds\n", ble_adv_time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,6 +312,18 @@ static int BleHandleCustomDataGet(const char *sid)
|
||||
// 参考链接 https://device.harmonyos.com/cn/docs/devicepartner/DevicePartner-Guides/device-development-ble-specifications-control-0000001482432154
|
||||
static int BleHandleCustomData(const char *buff, unsigned int len)
|
||||
{
|
||||
// 添加四开关面板的蓝牙处理
|
||||
extern int switch_panel_ble_handle_custom_data(const char *buff, unsigned int len);
|
||||
|
||||
// 优先使用四开关面板的蓝牙处理逻辑
|
||||
int panel_result = switch_panel_ble_handle_custom_data(buff, len);
|
||||
if (panel_result == 0) {
|
||||
// 四开关面板成功处理了该指令
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 如果面板处理失败,回退到原有的处理逻辑
|
||||
HILINK_SAL_NOTICE("开关面板处理失败,使用默认处理逻辑\r\n");
|
||||
if (strcmp((char *)buff, "{}") == 0) {
|
||||
/* 上报全量数据 */
|
||||
ReporSwitchStatus();
|
||||
@ -424,10 +440,20 @@ unsigned int GetWifiRecoveryType(void)
|
||||
{
|
||||
return (0x01 | 0x02);
|
||||
}
|
||||
int start_hilink_ble_net_config(int32_t net_cfg_time_s)
|
||||
{
|
||||
ble_adv_time = net_cfg_time_s;
|
||||
e_printf("set ble adv time: %ds\n", ble_adv_time);
|
||||
if (ble_sdk_running) {
|
||||
BLE_CfgNetAdvCtrl(ble_adv_time);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hilink_ble_main(void)
|
||||
{
|
||||
int ret = 0;
|
||||
hfset_hilink_mode(SMTLK_BLE_FAST_CONNECT);
|
||||
int hilink_entry_mode=hfget_hilink_mode();
|
||||
printf("hilink_entry_mode:%d\r\n",hilink_entry_mode);
|
||||
if(hilink_entry_mode != SMTLK_SOFTAP)
|
||||
@ -448,6 +474,7 @@ int hilink_ble_main(void)
|
||||
HILINK_EnableSle();
|
||||
HILINK_EnablePrescan();
|
||||
HILINK_SetProtType(17);
|
||||
e_printf("SMTLK_BLE_FAST_CONNECT\r\n");
|
||||
}
|
||||
|
||||
ret = HILINK_SetNetConfigMode(HILINK_NETCONFIG_OTHER);
|
||||
@ -457,25 +484,27 @@ int hilink_ble_main(void)
|
||||
ret = BLE_SetAdvNameMpp(mpp, sizeof(mpp));
|
||||
if (ret != 0) {
|
||||
HILINK_SAL_NOTICE("set adv name mpp failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 注册SDK状态接收函数,可在初始化完成后发送广播 */
|
||||
ret = HILINK_BT_SetSdkEventCallback(HILINK_BT_StateChangeHandler);
|
||||
if (ret != 0) {
|
||||
/* 注册SDK状态接收函数,可在初始化完成后发送广播 */
|
||||
ret = HILINK_BT_SetSdkEventCallback(HILINK_BT_StateChangeHandler);
|
||||
if (ret != 0) {
|
||||
HILINK_SAL_NOTICE("set event callback failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 设置广播方式为靠近发现 */
|
||||
BLE_SetAdvType(BLE_ADV_NEARBY_V0);
|
||||
/* 设置广播方式为靠近发现 */
|
||||
BLE_SetAdvType(BLE_ADV_LOCAL_NAME);
|
||||
|
||||
/* 初始化ble sdk */
|
||||
ret = BLE_CfgNetInit(&g_bleInitParam, &g_bleCfgNetCb);
|
||||
if (ret != 0) {
|
||||
/* 初始化ble sdk */
|
||||
ret = BLE_CfgNetInit(&g_bleInitParam, &g_bleCfgNetCb);
|
||||
if (ret != 0) {
|
||||
HILINK_SAL_NOTICE("ble sdk init fail\r\n");
|
||||
return -1;
|
||||
}
|
||||
e_printf("ble sdk init success\r\n");
|
||||
//set_get_ble_mac();
|
||||
}
|
||||
else if(hilink_entry_mode == SMTLK_SOFTAP)
|
||||
{
|
||||
@ -520,6 +549,16 @@ int hilink_ble_main(void)
|
||||
HILINK_SAL_NOTICE("HILINK_Main start error");
|
||||
return -1;
|
||||
}
|
||||
e_printf("HILINK_Main start success\r\n");
|
||||
hf_set_hilink_main_runing();
|
||||
// HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
// EKKO remove indie upgrade
|
||||
int hilink_indie_upgrade_main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -17,15 +17,15 @@ extern "C" {
|
||||
*/
|
||||
|
||||
|
||||
#define ProductId "2Q4S"
|
||||
#define deviceTypeId "21S"
|
||||
#define ProductId "2Q4G"
|
||||
#define deviceTypeId "201"
|
||||
#define manufacturerID "gub"
|
||||
#define deviceModel "SR-SW-020-10S"
|
||||
#define deviceModel "S15"
|
||||
#define configName "SR_S"
|
||||
#define configType "witch"
|
||||
#define enterpriseEnglishName "SORONTEK"
|
||||
#define brandEn "SORONTEK"
|
||||
#define deviceName "SORONTEK智能开关面板"
|
||||
#define deviceName "SORONTEK智能面板"
|
||||
#define productSeries ""
|
||||
|
||||
#define DEVICE_HIVERSION "1.0.0"
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "hilink_device.h"
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
#include "hilink_entry.h"
|
||||
|
||||
#endif
|
||||
extern void handle_device_online(void);
|
||||
extern void handle_device_unbind(void);
|
||||
extern void handle_device_offline(void);
|
||||
@ -40,7 +40,7 @@ static const HILINK_SvcInfo SVC_INFO[] = {
|
||||
{ "switch", "switch" },
|
||||
{ "switch", "switch4" },
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
//{ "checkSum", "checkSum" },
|
||||
{ "checkSum", "checkSum" },
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -177,14 +177,124 @@ int not_support_put(const char* svc_id, const char* payload, unsigned int len)
|
||||
HILINK_Printf("sid:%s NOT SUPPORT PUT function \r\n", svc_id);
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
// 服务处理函数
|
||||
|
||||
int handle_put_switch3(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* on_item = cJSON_GetObjectItem(pJson, "on");
|
||||
if (on_item)
|
||||
g_device_info.switch3_on = on_item->valueint;
|
||||
cJSON* name_item = cJSON_GetObjectItem(pJson, "name");
|
||||
if (name_item)
|
||||
g_device_info.switch3_name = name_item->valueint;
|
||||
HILINK_Printf("%s:%d svcId:%s, payload:%s\r\n", __FUNCTION__, __LINE__, svc_id, payload);
|
||||
cJSON_Delete(pJson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_get_switch3(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 64;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (*out == NULL)
|
||||
return -1;
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"on\":%d, \"name\":%d}", g_device_info.switch3_on, g_device_info.switch3_name);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_switch2(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* on_item = cJSON_GetObjectItem(pJson, "on");
|
||||
if (on_item)
|
||||
g_device_info.switch2_on = on_item->valueint;
|
||||
cJSON* name_item = cJSON_GetObjectItem(pJson, "name");
|
||||
if (name_item)
|
||||
g_device_info.switch2_name = name_item->valueint;
|
||||
HILINK_Printf("%s:%d svcId:%s, payload:%s\r\n", __FUNCTION__, __LINE__, svc_id, payload);
|
||||
cJSON_Delete(pJson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_get_switch2(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 64;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (*out == NULL)
|
||||
return -1;
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"on\":%d, \"name\":%d}", g_device_info.switch2_on, g_device_info.switch2_name);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_switch1(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* on_item = cJSON_GetObjectItem(pJson, "on");
|
||||
if (on_item)
|
||||
g_device_info.switch1_on = on_item->valueint;
|
||||
cJSON* name_item = cJSON_GetObjectItem(pJson, "name");
|
||||
if (name_item)
|
||||
g_device_info.switch1_name = name_item->valueint;
|
||||
HILINK_Printf("%s:%d svcId:%s, payload:%s\r\n", __FUNCTION__, __LINE__, svc_id, payload);
|
||||
cJSON_Delete(pJson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_get_switch1(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 64;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (*out == NULL)
|
||||
return -1;
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"on\":%d, \"name\":%d}", g_device_info.switch1_on, g_device_info.switch1_name);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_switch4(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* on_item = cJSON_GetObjectItem(pJson, "on");
|
||||
if (on_item)
|
||||
g_device_info.switch4_on = on_item->valueint;
|
||||
cJSON* name_item = cJSON_GetObjectItem(pJson, "name");
|
||||
if (name_item)
|
||||
g_device_info.switch4_name = name_item->valueint;
|
||||
HILINK_Printf("%s:%d svcId:%s, payload:%s\r\n", __FUNCTION__, __LINE__, svc_id, payload);
|
||||
cJSON_Delete(pJson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_get_switch4(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 64;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (*out == NULL)
|
||||
return -1;
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"on\":%d, \"name\":%d}", g_device_info.switch4_on, g_device_info.switch4_name);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"switch3", handle_put_switch3, handle_get_switch3},
|
||||
{"switch2", handle_put_switch2, handle_get_switch2},
|
||||
{"switch1", handle_put_switch1, handle_get_switch1},
|
||||
{"switch", handle_put_switch, handle_get_switch},
|
||||
{"switch1", handle_put_switch1, handle_get_switch1},
|
||||
{"switch2", handle_put_switch2, handle_get_switch2},
|
||||
{"switch3", handle_put_switch3, handle_get_switch3},
|
||||
{"switch4", handle_put_switch4, handle_get_switch4},
|
||||
// 故障不支持 HILINK_PutCharState,配置 not_support_put
|
||||
{"switch4", handle_put_switch4, handle_get_switch4},
|
||||
};
|
||||
// 服务总数量
|
||||
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
|
||||
@ -233,14 +343,29 @@ 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()) {
|
||||
// 蓝牙模式下通过蓝牙上报
|
||||
e_printf("[FAST_REPORT] 蓝牙模式上报: %s\r\n", svc_id);
|
||||
return switch_panel_ble_fast_report(svc_id);
|
||||
}
|
||||
|
||||
// 云端模式下通过HiLink上报
|
||||
e_printf("[FAST_REPORT] 云端模式上报: %s\r\n", svc_id);
|
||||
|
||||
char* payload = NULL;
|
||||
int len;
|
||||
int err = handle_get_cmd(svc_id, NULL, 0, &payload, (unsigned int *)&len);
|
||||
if(err != 0) {
|
||||
HILINK_Printf("get msg from %s failed \r\n", svc_id);
|
||||
return err;
|
||||
HILINK_Printf("get msg from %s failed \r\n", svc_id);
|
||||
return err;
|
||||
}
|
||||
err = HILINK_ReportCharState(svc_id, payload, len);
|
||||
HILINK_Printf("report %s result is %d, payload:%s \r\n", svc_id, err, payload);
|
||||
@ -255,9 +380,10 @@ int fast_report(const char* svc_id)
|
||||
*/
|
||||
int HILINK_PutCharState(const char *svcId, const char *payload, unsigned int len)
|
||||
{
|
||||
e_printf("[HILINK_PutCharState] 收到控制指令: svcId=%s, payload=%s\r\n", svcId, payload);
|
||||
e_printf("收到控制指令: svcId=%s, payload=%s\r\n", svcId, payload);
|
||||
|
||||
if ((svcId == NULL) || (payload == NULL)) {
|
||||
e_printf("参数无效\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -268,7 +394,7 @@ int HILINK_PutCharState(const char *svcId, const char *payload, unsigned int len
|
||||
cJSON_Delete(json);
|
||||
|
||||
int err = handle_put_cmd(svcId, payload, len);
|
||||
e_printf("[HILINK_PutCharState] 控制指令处理完成,返回值: %d\r\n", err);
|
||||
e_printf("控制指令处理完成,返回值: %d\r\n", err);
|
||||
return err;
|
||||
}
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
|
Reference in New Issue
Block a user