claude 生成初步代码

This commit is contained in:
2025-07-06 19:21:42 +08:00
parent 18171d2ea4
commit 1046873661
15 changed files with 1656 additions and 212 deletions

View File

@ -94,6 +94,7 @@ set(PRIVATE_HEADER
${ROOT_DIR}/protocol/wifi/source/host/inc/liteOS
${ROOT_DIR}/open_source/mbedtls/mbedtls_v3.1.0/harden/src/internal_include
${ROOT_DIR}/include
${ROOT_DIR}/application/ws63/user_main/
)
# use this when you want to add ccflags like -include xxx

View File

@ -42,7 +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, ...);
@ -258,6 +258,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;
@ -275,7 +276,8 @@ static void HILINK_BT_StateChangeHandler(HILINK_BT_SdkStatus event, const void *
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;
}
}
@ -430,12 +432,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;
if (ble_sdk_running) {
e_printf("set ble adv time: %ds\n", ble_adv_time);
BLE_CfgNetAdvCtrl(ble_adv_time);
}
return 0;
}
int hilink_ble_main(void)
{
int ret = 0;
hfdbg_set_level(1);
hfset_hilink_mode(2);
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)
@ -454,6 +464,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);
@ -482,6 +493,7 @@ int hilink_ble_main(void)
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)
@ -528,6 +540,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

View File

@ -17,17 +17,17 @@ extern "C" {
*/
#define ProductId "2Q4G"
#define deviceTypeId "201"
#define ProductId "2Q4S"
#define deviceTypeId "21S"
#define manufacturerID "gub"
#define deviceModel "S15"
#define deviceModel "SR-SW-020-10S"
#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"
/* 设备固件版本号 */
#define FIRMWARE_VER "1.0.0"
@ -51,4 +51,4 @@ extern "C" {
#endif
#endif
#endif /* DEVICE_PROFILE_H */
#endif /* DEVICE_PROFILE_H */

View File

@ -15,12 +15,20 @@
#include "hsf.h"
#include "hilink_entry.h"
extern void handle_device_online(void);
extern void handle_device_unbind(void);
extern void handle_device_offline(void);
// 声明外部函数
#include "switch_panel/switch_panel.h"
/*
*
* 服务信息定义
* 注意:(1)适配格式{svcType svcId}
* (2)与devicepartner平台物模型定义必须保持一致
*/
// 四开关面板服务信息定义
static const HILINK_SvcInfo SVC_INFO[] = {
{ "switch", "switch3" },
{ "switch", "switch2" },
@ -31,6 +39,7 @@ static const HILINK_SvcInfo SVC_INFO[] = {
// { "checkSum", "checkSum" },
#endif
};
int HILINK_GetDevInfo(HILINK_DevInfo *devinfo)
{
if (devinfo == NULL) {
@ -126,9 +135,9 @@ int HILINK_GetSvcInfo(HILINK_SvcInfo *svcInfo[], unsigned int size)
return -1;
}
}
e_printf("HILINK_GetSvcInfo svcNum:%d\r\n", svcNum);
return svcNum;
}
/* AC参数 */
unsigned char A_C[48] = {
0x66, 0x22, 0x33, 0x5F, 0x75, 0x31, 0x29, 0x6A, 0x27, 0x34, 0x57, 0x44, 0x32, 0x42, 0x27, 0x59, 0xE1, \
@ -145,21 +154,6 @@ unsigned char *HILINK_GetAutoAc(void)
extern int HILINK_HILINK_Printf(const char *format, ...);
// 设备状态定义
typedef struct{
int switch3_on;
int switch3_name;
int switch2_on;
int switch2_name;
int switch1_on;
int switch1_name;
int switch_on;
int switch4_on;
int switch4_name;
}t_device_info;
// 分配一个对象记录设备状态
static t_device_info g_device_info = {0};
// 服务处理函数定义
typedef int (*handle_put_func)(const char* svc_id, const char* payload, unsigned int len);
typedef int (*handle_get_func)(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
@ -178,148 +172,13 @@ 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;
}
// 处理从 HILINK_PutCharState 传递过来的信息
int handle_put_switch(const char* svc_id, const char* payload, unsigned int len)
{
cJSON* pJson = cJSON_Parse(payload);
if (pJson == NULL){
HILINK_Printf("JSON parse failed in PUT cmd: ID-%s \r\n", svc_id);
return -1;
}
cJSON* item = cJSON_GetObjectItem(pJson, "on");
if (item != NULL)
g_device_info.switch_on = item->valueint;
if (pJson != NULL)
cJSON_Delete(pJson);
HILINK_Printf("handle func:%s, sid:%s \r\n", __FUNCTION__, svc_id);
return 0;
}
// 处理从 HILINK_GetCharState 传递过来的信息
int handle_get_switch(const char* svc_id, const char* in, unsigned int in_len,char** out, unsigned int* out_len)
{
*out_len = 20;
*out = (char*)malloc(*out_len);
if (NULL == *out)
return -1;
*out_len = sprintf_s(*out, *out_len, "{\"on\":%d}", g_device_info.switch_on);
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n",__FUNCTION__ , __LINE__,svc_id, *out);
return 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;
}
// 服务处理函数
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},
{"switch4", handle_put_switch4, handle_get_switch4},
{"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},
};
// 服务总数量
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
@ -366,6 +225,7 @@ int handle_get_cmd(const char* svc_id, const char* in, unsigned int in_len, char
}
return function(svc_id, in, in_len, out,out_len);
}
// 快速上报函数,用于上报服务状态信息
int fast_report(const char* svc_id)
{
@ -377,7 +237,7 @@ int fast_report(const char* svc_id)
return err;
}
err = HILINK_ReportCharState(svc_id, payload, len);
HILINK_Printf("report %s result is %d \r\n", svc_id, err);
HILINK_Printf("report %s result is %d, payload:%s \r\n", svc_id, err, payload);
return err;
}
/*
@ -389,7 +249,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);
if ((svcId == NULL) || (payload == NULL)) {
e_printf("[HILINK_PutCharState] 参数无效\r\n");
return -1;
}
@ -397,8 +260,11 @@ int HILINK_PutCharState(const char *svcId, const char *payload, unsigned int len
if (json == NULL) {
return -1;
}
int err = handle_put_cmd(svcId, payload, len);
return err;
cJSON_Delete(json);
int err = handle_put_cmd(svcId, payload, len);
e_printf("[HILINK_PutCharState] 控制指令处理完成,返回值: %d\r\n", err);
return err;
}
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
static int GetFwvCheckSum(char **out, unsigned int *outLen)
@ -498,6 +364,7 @@ void HILINK_NotifyDevStatus(int status)
BLE_CfgNetAdvCtrl(0);
(void)BLE_CfgNetAdvCtrl(0xFFFFFFFF);
#endif
handle_device_offline();
break;
case HILINK_M2M_CLOUD_ONLINE:
/* 设备连接云端成功,请在此处添加实现 */
@ -506,6 +373,8 @@ void HILINK_NotifyDevStatus(int status)
BLE_CfgNetAdvCtrl(0);
(void)BLE_CfgNetAdvCtrl(0xFFFFFFFF);
#endif
/* 设备连接云端成功,请在此处添加实现 */
handle_device_online(); // 处理设备上线
break;
case HILINK_M2M_LONG_OFFLINE:
/* 设备与云端连接长时间断开,请在此处添加实现 */
@ -542,9 +411,11 @@ void HILINK_NotifyDevStatus(int status)
break;
case HILINK_DEVICE_UNREGISTER:
/* 设备被解绑,请在此处添加实现 */
handle_device_unbind();
break;
case HILINK_REVOKE_FLAG_SET:
/* 设备被复位标记置位,请在此处添加实现 */
handle_device_unbind();
break;
case HILINK_NEGO_REG_INFO_FAIL:
/* 设备协商配网信息失败 */
@ -589,6 +460,7 @@ int HILINK_ProcessBeforeRestart(int flag)
/* APP删除设备触发模组重启 */
if (flag == 1) {
/* 实现模组重启前的操作(如:保存系统状态等) */
handle_device_unbind(); // 处理设备解绑
return 1;
}