1. 解决频繁频繁掉线的问题:原因是因为ble
sdk需要一开始就初始化,配网的时候只是去控制其广播是否开启。不然会导致一直掉线
This commit is contained in:
parent
cb1ea6e364
commit
5ec8b9380c
|
@ -66,8 +66,6 @@ set(SOURCES
|
|||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/adapter/hilink_thread_adapter.c
|
||||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/adapter/hilink_ble_adapter.c
|
||||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/entry/hilink_entry.c
|
||||
# ${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/product/spotlight/spotlight_main.c
|
||||
# ${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/product/spotlight/device_module.c
|
||||
)
|
||||
|
||||
if (DEFINES MATCHES "SUPPORT_MINIMALIST_NETCFG" OR DEFINES MATCHES "SUPPORT_BLE_ANCILLAY_NETCFG")
|
||||
|
@ -87,7 +85,6 @@ set(PUBLIC_HEADER
|
|||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/include/
|
||||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/product/
|
||||
${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/adapter/include/
|
||||
# ${CMAKE_HILINK_SOURCE_DIR}/hilink_adapt/product/spotlight
|
||||
)
|
||||
|
||||
set(PRIVATE_HEADER
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
//static bool g_switch = 0;
|
||||
int sid_switch;
|
||||
static bool g_autoUpdate = 0;
|
||||
static int ble_adv_time = BLE_ADV_TIME;
|
||||
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;
|
||||
|
@ -276,6 +277,7 @@ static void HILINK_BT_StateChangeHandler(HILINK_BT_SdkStatus event, const void *
|
|||
|
||||
/* BLE配网广播控制:参数代表广播时间,0:停止;0xFFFFFFFF:一直广播,其他:广播指定时间后停止,单位秒 */
|
||||
(void)BLE_CfgNetAdvCtrl(ble_adv_time);
|
||||
ble_sdk_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,13 +432,21 @@ unsigned int GetWifiRecoveryType(void)
|
|||
{
|
||||
return (0x01 | 0x02);
|
||||
}
|
||||
|
||||
int start_hilink_ble_net_config(int32_t net_cfg_time_s)
|
||||
{
|
||||
int ret = 0;
|
||||
int hilink_entry_mode=hfget_hilink_mode();
|
||||
ble_adv_time = net_cfg_time_s;
|
||||
printf("hilink_entry_mode:%d, ble_adv_time:%d\r\n",hilink_entry_mode, ble_adv_time);
|
||||
if (ble_sdk_running) {
|
||||
BLE_CfgNetAdvCtrl(ble_adv_time);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int hilink_ble_main(void)
|
||||
{
|
||||
int ret = 0;
|
||||
hfdbg_set_level(1);
|
||||
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)
|
||||
{
|
||||
if(hfget_hilink_mode() == SMTLK_BLE_NARMAL)
|
||||
|
@ -491,6 +501,18 @@ int start_hilink_ble_net_config(int32_t net_cfg_time_s)
|
|||
ret = HILINK_SetNetConfigMode(HILINK_NETCONFIG_WIFI);
|
||||
}
|
||||
|
||||
|
||||
/* 修改任务属性 */
|
||||
HILINK_SdkAttr *sdkAttr = HILINK_GetSdkAttr();
|
||||
if (sdkAttr == NULL) {
|
||||
HILINK_SAL_NOTICE("sdkAttr is null");
|
||||
return -1;
|
||||
}
|
||||
sdkAttr->monitorTaskStackSize = 0x600; /* 示例代码 推荐栈大小为0x400 */
|
||||
sdkAttr->rebootHardware = HardReboot;
|
||||
sdkAttr->rebootSoftware = HardReboot;
|
||||
HILINK_SetSdkAttr(*sdkAttr);
|
||||
|
||||
/* 注册极简配网WIFI相关函数 */
|
||||
WiFiRecoveryApi wifiCb;
|
||||
wifiCb.getWifiRecoveryType = GetWifiRecoveryType;
|
||||
|
@ -505,23 +527,6 @@ int start_hilink_ble_net_config(int32_t net_cfg_time_s)
|
|||
}
|
||||
HILINK_SAL_NOTICE("RegWiFiRecoveryCallback finish!\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
int hilink_ble_main(void)
|
||||
{
|
||||
hfdbg_set_level(1);
|
||||
hfset_hilink_mode(SMTLK_BLE_FAST_CONNECT);
|
||||
/* 修改任务属性 */
|
||||
HILINK_SdkAttr *sdkAttr = HILINK_GetSdkAttr();
|
||||
if (sdkAttr == NULL) {
|
||||
HILINK_SAL_NOTICE("sdkAttr is null");
|
||||
return -1;
|
||||
}
|
||||
sdkAttr->monitorTaskStackSize = 0x600; /* 示例代码 推荐栈大小为0x400 */
|
||||
sdkAttr->rebootHardware = HardReboot;
|
||||
sdkAttr->rebootSoftware = HardReboot;
|
||||
HILINK_SetSdkAttr(*sdkAttr);
|
||||
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
if (HILINK_RegisterErrnoCallback(get_os_errno) != 0) {
|
||||
HILINK_SAL_NOTICE("reg errno cb err\r\n");
|
||||
|
|
|
@ -12,19 +12,16 @@
|
|||
#include "hal_reboot.h"
|
||||
#include "hilink_device.h"
|
||||
#include "hilink_network_adapter.h"
|
||||
#include "hsf.h"
|
||||
|
||||
#ifdef SUPPORT_QUICK_NETCFG
|
||||
#include "hilink_quick_netcfg_demo.h"
|
||||
#include "hilink_quick_netcfg_api.h"
|
||||
#endif
|
||||
extern unsigned char *HILINK_GetAutoAc(void);
|
||||
|
||||
static int GetAcV2Func(unsigned char *acKey, unsigned int acLen)
|
||||
{
|
||||
/* key文件在开发者平台获取 */
|
||||
e_printf("GetAcV2Func\r\n");
|
||||
memcpy(acKey, HILINK_GetAutoAc(), acLen);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static unsigned int GetWifiRecType(void)
|
||||
|
@ -87,7 +84,7 @@ int hilink_wifi_main(void)
|
|||
HILINK_SAL_NOTICE("HILINK_Main start error");
|
||||
return -1;
|
||||
}
|
||||
e_printf("HILINK_Main start success\r\n");
|
||||
|
||||
#ifdef SUPPORT_QUICK_NETCFG
|
||||
StartQuickNetCfg();
|
||||
#endif
|
||||
|
|
|
@ -16,54 +16,18 @@ extern "C" {
|
|||
* 与hilink sdk相同定义,双模组模式只需一份,已提供给第三方厂家,暂不按编程规范整改
|
||||
*/
|
||||
|
||||
#define SORONTEK_PRODUCT 1
|
||||
#define HIFLYING_PRODUCT 0
|
||||
#if SORONTEK_PRODUCT // EKKO add for device info, Reference from product json
|
||||
|
||||
#define ProductId "2Q4H"
|
||||
#define deviceTypeId "21D"
|
||||
#define manufacturerID "gub"
|
||||
#define deviceModel "SR-TH-020-10W"
|
||||
#define configName "SR_"
|
||||
#define configType "light"
|
||||
#define enterpriseEnglishName "SORONTEK" // EKKO: TODO: need check
|
||||
#define configName "SR_L"
|
||||
#define configType "ight"
|
||||
#define enterpriseEnglishName "SORONTEK"
|
||||
#define brandEn "SORONTEK"
|
||||
#define deviceName "LED嵌入式天花射灯"
|
||||
#define deviceName "SORONTEK智能双色温灯"
|
||||
#define productSeries ""
|
||||
#define MANUAFACTURER_ACKEY {\
|
||||
0x66, 0x22, 0x33, 0x5F, 0x75, 0x31, 0x29, 0x6A, 0x27, 0x34, 0x57, 0x44, 0x32, 0x42, 0x27, 0x59, \
|
||||
0xE1, 0xDE, 0x9C, 0xA6, 0xA6, 0x77, 0x54, 0x8C, 0xA9, 0xB0, 0x0D, 0xC7, 0xCB, 0x1B, 0x32, 0x2B, \
|
||||
0xB9, 0x4E, 0xEE, 0x97, 0xDC, 0x43, 0xFB, 0xF1, 0x86, 0xCC, 0xFD, 0x6E, 0x78, 0xA8, 0x36, 0x22}
|
||||
#elif HIFLYING_PRODUCT
|
||||
#define ProductId "2PAD"
|
||||
#define deviceTypeId "01D"
|
||||
#define manufacturerID "01C"
|
||||
#define deviceModel "hf-262-jjpw"
|
||||
#define configName "262"
|
||||
#define configType "HF"
|
||||
#define enterpriseEnglishName "HighFlying"
|
||||
#define brandEn "hiflying"
|
||||
#define deviceName "专用262认证测试设备"
|
||||
#define productSeries "262"
|
||||
#define MANUAFACTURER_ACKEY { \
|
||||
0x73,0x4A,0x68,0x4E,0x3B,0x77,0x2A,0x42,0x33,0x74,0x6D,0x50,0x3C,0x6F,0x2E,0x60,0x40,0xCA, \
|
||||
0x74,0x27,0x25,0xB7,0x1A,0x72,0x41,0xCD,0xAB,0xD4,0x04,0x55,0x7D,0xC4,0x2B,0x32,0x7E,0xB2, \
|
||||
0x39,0xB1,0xDC,0x28,0x46,0xBB,0x6A,0x77,0x86,0x3D,0xD8,0xE3 }
|
||||
#else
|
||||
#define ProductId "2PQP"
|
||||
#define deviceTypeId "112"
|
||||
#define manufacturerID "i0s"
|
||||
#define deviceModel "SamSLE001"
|
||||
#define configName "HuaweiSm"
|
||||
#define configType "art Home"
|
||||
#define enterpriseEnglishName "yuanxun"
|
||||
#define brandEn "YX"
|
||||
#define deviceName "SamSLETest"
|
||||
#define productSeries ""
|
||||
#define MANUAFACTURER_ACKEY { \
|
||||
0x66, 0x3F, 0x64, 0x78, 0x4B, 0x78, 0x3B, 0x26, 0x76, 0x78, 0x24, 0x56, 0x25, 0x2C, 0x57, 0x47, 0x6F, \
|
||||
0xC8, 0xE7, 0xD6, 0xC6, 0xF2, 0x7F, 0x03, 0x3A, 0x1C, 0x78, 0x05, 0x66, 0x24, 0x5F, 0x09, 0xCD, 0xAD, \
|
||||
0x30, 0x55, 0x2C, 0x19, 0x28, 0x34, 0x1A, 0xC3, 0x31, 0x49, 0x16, 0xC7, 0x45, 0x1B};
|
||||
#endif
|
||||
|
||||
#define DEVICE_HIVERSION "1.0.0"
|
||||
/* 设备固件版本号 */
|
||||
#define FIRMWARE_VER "1.0.0"
|
||||
|
|
|
@ -15,7 +15,24 @@
|
|||
#include "hsf.h"
|
||||
#include "hilink_entry.h"
|
||||
|
||||
// #undef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
extern void handle_device_online(void);
|
||||
extern void handle_device_unbind(void);
|
||||
extern void handle_device_offline(void);
|
||||
|
||||
extern int myhandle_put_brightness(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_cct(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_lightMode(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_switch(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_progressSwitch(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_progressSwitch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
// 声明外部函数
|
||||
extern int myhandle_put_cmd(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_get_cmd(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
|
||||
/*
|
||||
*
|
||||
* 服务信息定义
|
||||
|
@ -23,11 +40,16 @@
|
|||
* (2)与devicepartner平台物模型定义必须保持一致
|
||||
*/
|
||||
static const HILINK_SvcInfo SVC_INFO[] = {
|
||||
{ "brightness", "brightness" },
|
||||
{ "cct", "cct" },
|
||||
{ "mode", "lightMode" },
|
||||
{ "progressSwitch", "progressSwitch" },
|
||||
{ "switch", "switch" },
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
{ "checkSum", "checkSum" },
|
||||
// { "checkSum", "checkSum" },
|
||||
#endif
|
||||
};
|
||||
|
||||
int HILINK_GetDevInfo(HILINK_DevInfo *devinfo)
|
||||
{
|
||||
if (devinfo == NULL) {
|
||||
|
@ -125,22 +147,27 @@ int HILINK_GetSvcInfo(HILINK_SvcInfo *svcInfo[], unsigned int size)
|
|||
}
|
||||
return svcNum;
|
||||
}
|
||||
|
||||
/* AC参数 */
|
||||
unsigned char A_C[48] = MANUAFACTURER_ACKEY;
|
||||
unsigned char A_C[48] = {
|
||||
0x66, 0x22, 0x33, 0x5F, 0x75, 0x31, 0x29, 0x6A, 0x27, 0x34, 0x57, 0x44, 0x32, 0x42, 0x27, 0x59, 0xE1, \
|
||||
0xDE, 0x9C, 0xA6, 0xA6, 0x77, 0x54, 0x8C, 0xA9, 0xB0, 0x0D, 0xC7, 0xCB, 0x1B, 0x32, 0x2B, 0xB9, 0x4E, \
|
||||
0xEE, 0x97, 0xDC, 0x43, 0xFB, 0xF1, 0x86, 0xCC, 0xFD, 0x6E, 0x78, 0xA8, 0x36, 0x22};
|
||||
|
||||
/* 获取加密 AC 参数 */
|
||||
unsigned char *HILINK_GetAutoAc(void)
|
||||
{
|
||||
// e_printf("HILINK_GetAutoAc\r\n");
|
||||
return A_C;
|
||||
}
|
||||
|
||||
|
||||
extern int HILINK_HILINK_Printf(const char *format, ...);
|
||||
|
||||
#if 0 //EKKO REMOVE
|
||||
// 设备状态定义
|
||||
typedef struct{
|
||||
int brightness_brightness;
|
||||
int cct_colorTemperature;
|
||||
int lightMode_mode;
|
||||
int progressSwitch_fadeTime;
|
||||
int switch_on;
|
||||
}t_device_info;
|
||||
// 分配一个对象记录设备状态
|
||||
|
@ -192,10 +219,119 @@ int handle_get_switch(const char* svc_id, const char* in, unsigned int in_len,ch
|
|||
return 0;
|
||||
}
|
||||
// 服务处理信息注册
|
||||
|
||||
int handle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* brightness_item = cJSON_GetObjectItem(pJson, "brightness");
|
||||
if (brightness_item)
|
||||
g_device_info.brightness_brightness = brightness_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_brightness(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, "{\"brightness\":%d}", g_device_info.brightness_brightness);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* colorTemperature_item = cJSON_GetObjectItem(pJson, "colorTemperature");
|
||||
if (colorTemperature_item)
|
||||
g_device_info.cct_colorTemperature = colorTemperature_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_cct(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, "{\"colorTemperature\":%d}", g_device_info.cct_colorTemperature);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* mode_item = cJSON_GetObjectItem(pJson, "mode");
|
||||
if (mode_item)
|
||||
g_device_info.lightMode_mode = mode_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_lightMode(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, "{\"mode\":%d}", g_device_info.lightMode_mode);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_progressSwitch(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* fadeTime_item = cJSON_GetObjectItem(pJson, "fadeTime");
|
||||
if (fadeTime_item)
|
||||
g_device_info.progressSwitch_fadeTime = fadeTime_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_progressSwitch(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, "{\"fadeTime\":%d}", g_device_info.progressSwitch_fadeTime);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
#ifdef CONFIG_USE_CUSTOMER_SVC_INFO
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"switch", handle_put_switch, handle_get_switch},
|
||||
// 故障不支持 HILINK_PutCharState,配置 not_support_put
|
||||
{"brightness", myhandle_put_brightness, myhandle_get_brightness},
|
||||
{"cct", myhandle_put_cct, myhandle_get_cct},
|
||||
{"lightMode", myhandle_put_lightMode, myhandle_get_lightMode},
|
||||
{"progressSwitch", myhandle_put_progressSwitch, myhandle_get_progressSwitch},
|
||||
{"switch", myhandle_put_switch, myhandle_get_switch},
|
||||
};
|
||||
#else
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"brightness", handle_put_brightness, handle_get_brightness},
|
||||
{"cct", handle_put_cct, handle_get_cct},
|
||||
{"lightMode", handle_put_lightMode, handle_get_lightMode},
|
||||
{"progressSwitch", handle_put_progressSwitch, handle_get_progressSwitch},
|
||||
{"switch", handle_put_switch, handle_get_switch},
|
||||
};
|
||||
#endif // end of CONFIG_USE_CUSTOMER_SVC_INFO
|
||||
// 服务总数量
|
||||
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
|
||||
|
||||
|
@ -241,34 +377,21 @@ 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);
|
||||
}
|
||||
#endif
|
||||
// 声明外部函数
|
||||
extern int device_module_control(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int device_module_get_state(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern void handle_device_online(void);
|
||||
extern void handle_device_unbind(void);
|
||||
extern void handle_device_offline(void);
|
||||
//替换实现
|
||||
#define handle_get_cmd device_module_get_state
|
||||
#define handle_put_cmd device_module_control
|
||||
|
||||
// 快速上报函数,用于上报服务状态信息
|
||||
int fast_report(const char* svc_id)
|
||||
{
|
||||
// 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) {
|
||||
e_printf("[fast_report] 获取服务状态失败: %d\r\n", err);
|
||||
HILINK_Printf("get msg from %s failed \r\n", svc_id);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = HILINK_ReportCharState(svc_id, payload, len);
|
||||
e_printf("[fast_report] 服务[%s] 状态上报结果: %d, payload: %s\r\n", svc_id, err, payload);
|
||||
HILINK_Printf("report %s result is %d, payload:%s \r\n", svc_id, err, payload);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* 修改服务当前字段值
|
||||
* svcId为服务的ID,payload为接收到需要修改的Json格式的字段与其值,len为payload的长度
|
||||
|
@ -288,7 +411,7 @@ int HILINK_PutCharState(const char *svcId, const char *payload, unsigned int len
|
|||
cJSON *json = cJSON_Parse(payload);
|
||||
if (json == NULL) {
|
||||
e_printf("[HILINK_PutCharState] JSON解析失败\r\n");
|
||||
return -101;
|
||||
return -1;
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
|
||||
|
@ -397,6 +520,7 @@ void HILINK_NotifyDevStatus(int status)
|
|||
handle_device_offline();
|
||||
break;
|
||||
case HILINK_M2M_CLOUD_ONLINE:
|
||||
/* 设备连接云端成功,请在此处添加实现 */
|
||||
#if defined(SUPPORT_MINIMALIST_NETCFG) || defined(SUPPORT_BLE_ANCILLAY_NETCFG)
|
||||
BLE_CfgNetAdvUpdate(NULL);
|
||||
BLE_CfgNetAdvCtrl(0);
|
||||
|
@ -439,12 +563,12 @@ void HILINK_NotifyDevStatus(int status)
|
|||
/* 设备被注册,请在此处添加实现 */
|
||||
break;
|
||||
case HILINK_DEVICE_UNREGISTER:
|
||||
e_printf("[HILINK_NotifyDevStatus] 设备被解绑\r\n");
|
||||
/* 设备被解绑,请在此处添加实现 */
|
||||
handle_device_unbind();
|
||||
break;
|
||||
case HILINK_REVOKE_FLAG_SET:
|
||||
/* 设备被复位标记置位,请在此处添加实现 */
|
||||
handle_device_unbind(); // 处理设备解绑
|
||||
handle_device_unbind();
|
||||
break;
|
||||
case HILINK_NEGO_REG_INFO_FAIL:
|
||||
/* 设备协商配网信息失败 */
|
||||
|
@ -490,7 +614,7 @@ int HILINK_ProcessBeforeRestart(int flag)
|
|||
if (flag == 1) {
|
||||
/* 实现模组重启前的操作(如:保存系统状态等) */
|
||||
handle_device_unbind(); // 处理设备解绑
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 设备长时间离线触发模组重启,尝试恢复网络 */
|
||||
|
|
|
@ -57,11 +57,7 @@ typedef struct _HFUART
|
|||
}HFUART,*PHFUART;
|
||||
|
||||
|
||||
#if defined(DEBUG_LOG_ENABLE)
|
||||
#define HF_Debug( debug_level, format, ...) printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
void HSF_API HF_Debug(int debug_level, const char *format , ... );
|
||||
#endif
|
||||
|
||||
#define hfdbg_error(...) HF_Debug(DEBUG_ERROR,"[ %d error %s %d]",hfsys_get_time(),__FUNCTION__,__LINE__); \
|
||||
HF_Debug(DEBUG_ERROR,__VA_ARGS__)
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#ifdef HF_MCU_OTA
|
||||
#include "mcu_update.h"
|
||||
#endif
|
||||
|
||||
int g_module_id = HFM_TYPE_LPT262;
|
||||
const int hf_lpt_262_gpio_fid_to_pid_map_table[HFM_MAX_FUNC_CODE]=
|
||||
{
|
||||
|
@ -198,28 +197,26 @@ int hf_atcmd_appver(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
|||
}
|
||||
return -3;
|
||||
}
|
||||
int hf_atcmd_reset(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
extern int HILINK_RestoreFactorySettings(void);
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPOTLIGHT_UT
|
||||
extern int hf_atcmd_pwm(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_pwm_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_light(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_reset(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_reset_factory(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
#endif
|
||||
const hfat_cmd_t user_define_at_cmds_table[]=
|
||||
{
|
||||
{"APPVER", hf_atcmd_appver, "AT+APPVER: get version. \r\n",NULL},
|
||||
{"RESET", hf_atcmd_reset, "AT+RESET: reset. \r\n",NULL},
|
||||
#ifdef HF_MCU_OTA
|
||||
{"MCUOTA", hf_atcmd_mcu, "AT+MCUOTA: start mcu ota. \r\n",NULL},
|
||||
{"MCUVER", hf_atcmd_mcuver, "AT+MCUVER: get mcu version. \r\n",NULL},
|
||||
{"OTAWAITTIME", hf_atcmd_ota_wait_time, "AT+OTAWAITTIME: set/get uart send mcu ota time\r\n", NULL},
|
||||
#endif
|
||||
#ifdef CONFIG_SPOTLIGHT_UT
|
||||
{"RESET", hf_atcmd_reset, "AT+RESET: reset. \r\n",NULL},
|
||||
{"FACTORY", hf_atcmd_reset_factory, "AT+FACTORY: factory. \r\n",NULL},
|
||||
{"UTPWM", hf_atcmd_pwm, "AT+PWM=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", NULL},
|
||||
{"UTLIGHT", hf_atcmd_light, "AT+LIGHT=<brightness>,<cct>: Set brightness(0-1000) and CCT(2700-6000)\r\n", NULL},
|
||||
{"UTPWMQ", NULL, "AT+PWMQ=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", hf_atcmd_pwm_query},
|
||||
|
@ -240,7 +237,7 @@ int USER_FUNC user_app_main(void)
|
|||
HF_Debug(DEBUG_WARN,"init mcu ota fail!\r\n");
|
||||
#endif
|
||||
//See Wi-Fi Config tools APP for detailed usage of this thread, only debug mode open
|
||||
if(0 && hfdbg_get_level())
|
||||
if(hfdbg_get_level())
|
||||
{
|
||||
while(!hfnet_wifi_is_active())
|
||||
{
|
||||
|
@ -251,8 +248,7 @@ int USER_FUNC user_app_main(void)
|
|||
HF_Debug(DEBUG_WARN,"start assis fail\r\n");
|
||||
}
|
||||
}
|
||||
e_printf("start assis success!\r\n");
|
||||
// hfgpio_pwm_enable(HFGPIO_F_SPI_CLK, 1000, 50);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,6 @@
|
|||
#include "spotlight.h"
|
||||
#include "cJSON.h"
|
||||
// 服务处理函数定义
|
||||
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);
|
||||
// 服务注册信息定义
|
||||
typedef struct{
|
||||
// service id
|
||||
char* sid;
|
||||
// HILINK_PutCharState cmd function
|
||||
handle_put_func putFunc;
|
||||
// handle HILINK_GetCharState cmd function
|
||||
handle_get_func getFunc;
|
||||
} HANDLE_SVC_INFO;
|
||||
#include "hilink_device.h"
|
||||
|
||||
#define CHECK_JSON_ITEM(condition) if(condition) { \
|
||||
goto lab_end; \
|
||||
|
@ -38,7 +27,7 @@ static const scene_preset_t scene_presets[] = {
|
|||
#define SCENE_MODE_COUNT (sizeof(scene_presets) / sizeof(scene_presets[0]))
|
||||
|
||||
// 处理亮度控制
|
||||
static int handle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
|
@ -65,7 +54,7 @@ static int handle_put_brightness(const char* svc_id, const char* payload, unsign
|
|||
}
|
||||
|
||||
// 处理色温控制
|
||||
static int handle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
|
@ -92,7 +81,7 @@ static int handle_put_cct(const char* svc_id, const char* payload, unsigned int
|
|||
}
|
||||
|
||||
// 处理场景模式控制
|
||||
static int handle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
|
@ -119,7 +108,7 @@ static int handle_put_lightMode(const char* svc_id, const char* payload, unsigne
|
|||
}
|
||||
|
||||
// 处理开关控制
|
||||
static int handle_put_switch(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_switch(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
|
@ -142,7 +131,7 @@ static int handle_put_switch(const char* svc_id, const char* payload, unsigned i
|
|||
}
|
||||
|
||||
// 获取亮度状态
|
||||
static int handle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
|
@ -154,7 +143,7 @@ static int handle_get_brightness(const char* svc_id, const char* in, unsigned in
|
|||
}
|
||||
|
||||
// 获取色温状态
|
||||
static int handle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
|
@ -166,7 +155,7 @@ static int handle_get_cct(const char* svc_id, const char* in, unsigned int in_le
|
|||
}
|
||||
|
||||
// 获取场景模式状态
|
||||
static int handle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
|
@ -178,7 +167,7 @@ static int handle_get_lightMode(const char* svc_id, const char* in, unsigned int
|
|||
}
|
||||
|
||||
// 获取开关状态
|
||||
static int handle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
|
@ -190,107 +179,41 @@ static int handle_get_switch(const char* svc_id, const char* in, unsigned int in
|
|||
}
|
||||
|
||||
// 处理渐变时长控制
|
||||
static int handle_put_smooth_time(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_progressSwitch(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
e_printf("[handle_put_smooth_time] Received smooth time setting request: %s\n", payload);
|
||||
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
if (json == NULL) {
|
||||
e_printf("[handle_put_smooth_time] JSON parsing failed\n");
|
||||
e_printf("JSON parsing failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cJSON *item = cJSON_GetObjectItem(json, JSON_FIELD_FADE_TIME);
|
||||
if (item == NULL || !cJSON_IsNumber(item)) {
|
||||
e_printf("[handle_put_smooth_time] Invalid smooth time parameter\n");
|
||||
e_printf("Invalid progressSwitch parameter\n");
|
||||
cJSON_Delete(json);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int smooth_time = item->valueint;
|
||||
e_printf("[handle_put_smooth_time] Setting smooth time: %d s\n", smooth_time);
|
||||
ret = set_smooth_time(smooth_time);
|
||||
|
||||
cJSON_Delete(json);
|
||||
// e_printf("[handle_put_smooth_time] Smooth time setting completed\n");
|
||||
// e_printf("Smooth time setting completed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 获取渐变时长状态
|
||||
static int handle_get_smooth_time(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_progressSwitch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (NULL == *out) {
|
||||
e_printf("[handle_get_smooth_time] Memory allocation failed\n");
|
||||
e_printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_FADE_TIME, g_device_control.fade_time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 服务处理信息注册
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{SVC_ID_SWITCH, handle_put_switch, handle_get_switch},
|
||||
{SVC_ID_BRIGHTNESS, handle_put_brightness, handle_get_brightness},
|
||||
{SVC_ID_CCT, handle_put_cct, handle_get_cct},
|
||||
{SVC_ID_LIGHT_MODE, handle_put_lightMode, handle_get_lightMode},
|
||||
{SVC_ID_FADE_TIME, handle_put_smooth_time, handle_get_smooth_time},
|
||||
};
|
||||
|
||||
// 服务总数量
|
||||
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
|
||||
|
||||
// 辅助函数,用于查找服务注册信息
|
||||
static HANDLE_SVC_INFO* find_handle(const char* svc_id)
|
||||
{
|
||||
for(int i = 0; i < g_device_profile_count; i++) {
|
||||
HANDLE_SVC_INFO handle = g_device_profile[i];
|
||||
if(strcmp(handle.sid, svc_id) == 0) {
|
||||
return &g_device_profile[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 分发设备控制指令
|
||||
int device_module_control(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
e_printf("[device_module_control] Received control command: svc_id=%s, payload=%s\n", svc_id, payload);
|
||||
|
||||
HANDLE_SVC_INFO* handle = find_handle(svc_id);
|
||||
if(handle == NULL) {
|
||||
e_printf("[device_module_control] No service handler found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle_put_func function = handle->putFunc;
|
||||
if(function == NULL) {
|
||||
e_printf("[device_module_control] Service handler function is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = function(svc_id, payload, len);
|
||||
e_printf("[device_module_control] Control command processing completed, return value: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 分发获取状态指令
|
||||
int device_module_get_state(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
HANDLE_SVC_INFO* handle = find_handle(svc_id);
|
||||
if(handle == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle_get_func function = handle->getFunc;
|
||||
if(function == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return function(svc_id, in, in_len, out, out_len);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ typedef enum {
|
|||
#define SVC_ID_CCT "cct" // 色温控制
|
||||
#define SVC_ID_LIGHT_MODE "lightMode" // 场景模式控制
|
||||
#define SVC_ID_FADE_TIME "progressSwitch" // 渐变时长的控制
|
||||
#define SVC_ID_NET_INFO "netInfo" // 配网信息
|
||||
|
||||
// JSON字段名定义
|
||||
#define JSON_FIELD_ON "on" // 开关状态字段
|
||||
|
@ -37,20 +38,21 @@ typedef enum {
|
|||
|
||||
|
||||
// 当前亮度和色温状态
|
||||
typedef struct {
|
||||
typedef struct __attribute__((packed, aligned(1))) {
|
||||
// 物模型同步需要 持久化维持
|
||||
bool on; // 开关状态
|
||||
uint8_t on; // 开关状态
|
||||
lightMode_e elightMode;
|
||||
uint16_t brightness_local; // 当前亮度 (0-1000)
|
||||
uint16_t fade_time; // s
|
||||
uint16_t cct_local; // 当前色温 (2700-6500)
|
||||
// 持久化维持
|
||||
int32_t power_on_cnt; // 上电次数计数
|
||||
bool is_networked; // 是否已配网
|
||||
uint8_t is_networked; // 是否已配网
|
||||
uint8_t is_net_configured; // 设备是否曾经配网成功过
|
||||
//运行时的数据
|
||||
bool read_done; // 读取数据done
|
||||
uint16_t duty_cw; // 冷白LED占空比
|
||||
uint16_t duty_ww; // 暖白LED占空比
|
||||
uint8_t read_done; // 读取数据done
|
||||
} device_control_t;
|
||||
|
||||
// 色温范围定义
|
||||
|
@ -122,8 +124,8 @@ typedef struct {
|
|||
#define DEVICE_DATA_FLASH_SIZE 0x001000 // 使用一个页的大小
|
||||
|
||||
// 设备数据结构
|
||||
typedef struct {
|
||||
uint32_t checksum; // 校验和
|
||||
typedef struct __attribute__((packed, aligned(1))) {
|
||||
uint8_t checksum; // 校验和
|
||||
uint32_t magic; // 魔数,用于验证数据有效性
|
||||
uint32_t version; // 数据版本号
|
||||
device_control_t control; // 设备控制状态
|
||||
|
@ -159,6 +161,7 @@ typedef enum {
|
|||
.brightness_local = BRIGHTNESS_REMOTE2LOCAL(INIT_STA__BRIGHTNESS), \
|
||||
.fade_time = NET_CFG_DEFAULT_FADE_TIME, \
|
||||
.is_networked = false, \
|
||||
.is_net_configured = false, \
|
||||
.duty_cw = 0, \
|
||||
.duty_ww = 0, \
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@ static void check_net_cfg_power_on_keep_time(void);
|
|||
static void set_light2breathtimeout(void);
|
||||
static void set_light2net_cfg_done(void);
|
||||
static void start_breath_timer(void);
|
||||
static void report_switch_status(void);
|
||||
void calculate_pwm_duty(void);
|
||||
void update_pwm_output(void);
|
||||
|
||||
|
@ -35,7 +36,7 @@ void update_pwm_output(void);
|
|||
typedef void (*report_func_t)(void);
|
||||
static void start_report_task(report_func_t report_func);
|
||||
static void report_fade_complete_status(void);
|
||||
static uint32_t calculate_checksum(const device_data_t* data);
|
||||
static uint8_t calculate_checksum(const device_data_t* data);
|
||||
static bool write_device_data_to_addr(uint32_t addr, const device_data_t* data);;
|
||||
static void report_device_online_status(void);
|
||||
|
||||
|
@ -101,7 +102,7 @@ typedef struct {
|
|||
} print_limiter_t;
|
||||
|
||||
// 渐变控制相关变量
|
||||
static struct {
|
||||
static struct fade_ctx_t {
|
||||
// 渐变控制参数
|
||||
int32_t target_brightness;
|
||||
int32_t target_cct;
|
||||
|
@ -588,13 +589,13 @@ static void cancel_current_light_fade(void)
|
|||
}
|
||||
|
||||
// 计算校验和
|
||||
static uint32_t calculate_checksum(const device_data_t* data)
|
||||
static uint8_t calculate_checksum(const device_data_t* data)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
const uint32_t* ptr = (const uint32_t*)(((char*)data) + sizeof(data->checksum));
|
||||
uint8_t sum = 0;
|
||||
const uint8_t* ptr = (const uint8_t*)(((char*)data) + sizeof(data->checksum));
|
||||
size_t len = sizeof(device_data_t) - sizeof(data->checksum); // 减去checksum字段的大小
|
||||
|
||||
for (size_t i = 0; i < len / 4; i++) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
sum ^= ptr[i];
|
||||
}
|
||||
return sum;
|
||||
|
@ -613,7 +614,7 @@ static bool verify_device_data(const device_data_t* data)
|
|||
return false;
|
||||
}
|
||||
|
||||
uint32_t checksum = calculate_checksum(data);
|
||||
uint8_t checksum = calculate_checksum(data);
|
||||
if (checksum != data->checksum) {
|
||||
e_printf("check sum error:%x\n", data->version);
|
||||
return false;
|
||||
|
@ -678,9 +679,9 @@ void read_device_data(void)
|
|||
} else if (!main_valid && !backup_valid) { // 如果两个区域都无效,使用默认值
|
||||
e_printf("主数据和备份数据都无效,使用默认值\r\n");
|
||||
// 只打印g_device_control的当前值,不打印data.control
|
||||
// e_printf("读取完成状态: %d\r\n", g_device_control.read_done);
|
||||
e_printf("上电次数: %d\r\n", g_device_control.power_on_cnt);
|
||||
e_printf("配网状态: %d\r\n", g_device_control.is_networked);
|
||||
e_printf("是否是新设备: %d\r\n", !g_device_control.is_net_configured);
|
||||
e_printf("开关状态: %d\r\n", g_device_control.on);
|
||||
e_printf("灯光模式: %d\r\n", g_device_control.elightMode);
|
||||
e_printf("亮度: %d\r\n", g_device_control.brightness_local);
|
||||
|
@ -692,9 +693,9 @@ void read_device_data(void)
|
|||
}
|
||||
// 更新设备控制状态
|
||||
e_printf("设备状态恢复:\r\n");
|
||||
// e_printf("读取完成状态: %d => %d\r\n", g_device_control.read_done, data.control.read_done);
|
||||
e_printf("上电次数: %d => %d\r\n", g_device_control.power_on_cnt, data.control.power_on_cnt);
|
||||
e_printf("配网状态: %d => %d\r\n", g_device_control.is_networked, data.control.is_networked);
|
||||
e_printf("是否是新设备: %d => %d\r\n", !g_device_control.is_net_configured, !data.control.is_net_configured);
|
||||
e_printf("开关状态: %d => %d\r\n", g_device_control.on, data.control.on);
|
||||
e_printf("灯光模式: %d => %d\r\n", g_device_control.elightMode, data.control.elightMode);
|
||||
e_printf("亮度: %d => %d\r\n", g_device_control.brightness_local, data.control.brightness_local);
|
||||
|
@ -703,6 +704,7 @@ void read_device_data(void)
|
|||
e_printf("暖白LED: %d => %d\r\n", g_device_control.duty_ww, data.control.duty_ww);
|
||||
e_printf("渐变时间: %d => %d\r\n", g_device_control.fade_time, data.control.fade_time);
|
||||
|
||||
data.control.read_done = false;
|
||||
g_device_control = data.control;
|
||||
lab_exit:
|
||||
#endif
|
||||
|
@ -725,7 +727,8 @@ void save_device_data(void)
|
|||
last_control.fade_time != g_device_control.fade_time ||
|
||||
last_control.cct_local != g_device_control.cct_local ||
|
||||
last_control.power_on_cnt != g_device_control.power_on_cnt ||
|
||||
last_control.is_networked != g_device_control.is_networked;
|
||||
last_control.is_networked != g_device_control.is_networked ||
|
||||
last_control.is_net_configured != g_device_control.is_net_configured;
|
||||
|
||||
if (!need_save) {
|
||||
e_printf("No changes detected, skip saving\n");
|
||||
|
@ -834,20 +837,20 @@ static void stop_save_task(void)
|
|||
// 设置灯光状态(统一控制函数)
|
||||
int set_light(int32_t brightness_local, int32_t cct_local)
|
||||
{
|
||||
struct fade_ctx_t tmp_fade_ctx = fade_ctx;
|
||||
// 如果任一参数大于等于0,则更新对应值
|
||||
e_printf("ligMode:%d, local brightness: curr:%d, target:%d, local cct: curr:%d, target:%d\r\n",
|
||||
g_device_control.elightMode, g_device_control.brightness_local, brightness_local, g_device_control.cct_local, cct_local);
|
||||
|
||||
fade_ctx.current_brightness = g_device_control.brightness_local;
|
||||
fade_ctx.current_cct = g_device_control.cct_local;
|
||||
fade_ctx.target_brightness = fade_ctx.current_brightness ;
|
||||
fade_ctx.target_cct = fade_ctx.current_cct;
|
||||
tmp_fade_ctx.current_brightness = g_device_control.brightness_local;
|
||||
tmp_fade_ctx.current_cct = g_device_control.cct_local;
|
||||
tmp_fade_ctx.target_brightness = tmp_fade_ctx.current_brightness ;
|
||||
tmp_fade_ctx.target_cct = tmp_fade_ctx.current_cct;
|
||||
|
||||
if (brightness_local >= 0) {
|
||||
BRIGHTNESS_LITME_RANGE(brightness_local);
|
||||
|
||||
if (g_device_control.elightMode == LIGHT_MODE_CUSTOMER) {
|
||||
fade_ctx.target_brightness = brightness_local;
|
||||
tmp_fade_ctx.target_brightness = brightness_local;
|
||||
} else {
|
||||
g_device_control.brightness_local = brightness_local;
|
||||
}
|
||||
|
@ -857,7 +860,7 @@ int set_light(int32_t brightness_local, int32_t cct_local)
|
|||
CCT_LITME_RANGE(cct_local);
|
||||
|
||||
if (g_device_control.elightMode == LIGHT_MODE_CUSTOMER) {
|
||||
fade_ctx.target_cct = cct_local;
|
||||
tmp_fade_ctx.target_cct = cct_local;
|
||||
} else {
|
||||
g_device_control.cct_local = cct_local;
|
||||
}
|
||||
|
@ -867,8 +870,13 @@ int set_light(int32_t brightness_local, int32_t cct_local)
|
|||
{
|
||||
case LIGHT_MODE_CUSTOMER:
|
||||
if (g_device_control.fade_time) {
|
||||
fade_ctx.is_fading = true;
|
||||
fade_ctx.fade_completed = false;
|
||||
tmp_fade_ctx.is_fading = true;
|
||||
tmp_fade_ctx.fade_completed = false;
|
||||
// if(fade_ctx.is_fading) {
|
||||
// e_printf("fade is running, skip set_light\r\n");
|
||||
// return -111;
|
||||
// }
|
||||
fade_ctx = tmp_fade_ctx;
|
||||
// 计算渐变步长
|
||||
calculate_fade_steps();
|
||||
e_printf("start fade\r\n");
|
||||
|
@ -904,9 +912,6 @@ int set_switch(bool open)
|
|||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
uapi_gpio_set_val(SWITCH_PIN, open ? OPEN_LIGHT : CLOSE_LIGHT);
|
||||
|
||||
// 保存设备状态
|
||||
req_save_device_data();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -937,6 +942,7 @@ static void pwm_init(pin_t pin, pin_t pin1)
|
|||
// uint32_t pwm_base_period_ns = 1000 * 1000 * 1000 / (80 * 1000 * 1000);// 80MHZ
|
||||
// uint32_t pwm_target_period_ns = 1000 * 1000 * 1000 / PWM_FREQUENCY;
|
||||
pwm_period_cnt = ((80 * 1000 * 1000) / PWM_FREQUENCY);
|
||||
cfg_repeat.low_time = pwm_period_cnt;
|
||||
// 设置PWM组
|
||||
channel_id_cw = pin%8;
|
||||
channel_id_ww = pin1%8;
|
||||
|
@ -960,8 +966,8 @@ static void handle_network_status(void)
|
|||
g_device_control.power_on_cnt++;
|
||||
e_printf("现在是第 %d 次上电\r\n", g_device_control.power_on_cnt);
|
||||
// 检查是否需要进入配网状态
|
||||
if (g_device_control.power_on_cnt >= NET_CFG_ENTRY_CNT) {
|
||||
e_printf("进入配网状态,上电次数:%d\r\n", g_device_control.power_on_cnt);
|
||||
if ((!g_device_control.is_net_configured) || g_device_control.power_on_cnt >= NET_CFG_ENTRY_CNT) {
|
||||
e_printf("进入配网状态,上电次数:%d, is_new_device:%d\r\n", g_device_control.power_on_cnt, !g_device_control.is_net_configured);
|
||||
g_device_control.power_on_cnt = 0;//
|
||||
extern int start_hilink_ble_net_config(int32_t net_cfg_time_s);
|
||||
int ret = start_hilink_ble_net_config(NET_CFG_TOTAL_TIMEOUT/1000);
|
||||
|
@ -986,24 +992,31 @@ static void handle_network_status(void)
|
|||
// 设备上线时的状态上报
|
||||
static void report_device_online_status(void)
|
||||
{
|
||||
e_printf("[report_task] Starting to report all service status\r\n");
|
||||
e_printf("Starting to report all service status\r\n");
|
||||
fast_report(SVC_ID_SWITCH);
|
||||
fast_report(SVC_ID_BRIGHTNESS);
|
||||
fast_report(SVC_ID_CCT);
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
fast_report(SVC_ID_FADE_TIME);
|
||||
e_printf("[report_task] Status report completed\r\n");
|
||||
// fast_report(SVC_ID_NET_INFO);
|
||||
e_printf("Status report completed\r\n");
|
||||
}
|
||||
|
||||
// 渐变结束时的状态上报
|
||||
static void report_fade_complete_status(void)
|
||||
{
|
||||
req_save_device_data();
|
||||
e_printf("[report_task] Reporting fade complete status\r\n");
|
||||
e_printf("Reporting fade complete status\r\n");
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
fast_report(SVC_ID_BRIGHTNESS);
|
||||
fast_report(SVC_ID_CCT);
|
||||
e_printf("[report_task] Fade status report completed\r\n");
|
||||
e_printf("Fade status report completed\r\n");
|
||||
}
|
||||
// 渐变结束时的状态上报
|
||||
static void report_switch_status(void)
|
||||
{
|
||||
req_save_device_data();
|
||||
fast_report(SVC_ID_SWITCH);
|
||||
}
|
||||
|
||||
// 状态上报任务函数
|
||||
|
@ -1032,6 +1045,7 @@ static void start_report_task(report_func_t report_func)
|
|||
e_printf("[report_task] Previous task is still running, skip this report\r\n");
|
||||
return;
|
||||
}
|
||||
report_task_running = true; // 设置任务运行标志
|
||||
if (report_task_handle) {
|
||||
osal_kthread_destroy(report_task_handle, 0);
|
||||
report_task_handle = NULL;
|
||||
|
@ -1042,7 +1056,6 @@ static void start_report_task(report_func_t report_func)
|
|||
report_task_handle = osal_kthread_create((osal_kthread_handler)report_task, (void*)report_func, "ReportStaTask",
|
||||
REPORT_TASK_STACK_SIZE);
|
||||
if (report_task_handle != NULL) {
|
||||
report_task_running = true; // 设置任务运行标志
|
||||
osal_kthread_set_priority(report_task_handle, REPORT_TASK_PRIO);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
|
@ -1057,6 +1070,7 @@ void handle_device_online(void)
|
|||
return;
|
||||
}
|
||||
e_printf("device online!\r\n");
|
||||
g_device_control.is_net_configured = true;//设备上线后,认为设备已经配网成功,就取消标记为新设备,终生只存在这一次标记
|
||||
if (!g_device_control.is_networked) {
|
||||
e_printf("设备首次上线,记录配网状态\r\n");
|
||||
g_device_control.is_networked = true;
|
||||
|
@ -1081,6 +1095,7 @@ void handle_device_offline(void)
|
|||
device_online = 0;
|
||||
e_printf("device offline!\r\n");
|
||||
}
|
||||
bool g_reset_factory_flag = false;
|
||||
// 处理设备解绑
|
||||
void handle_device_unbind(void)
|
||||
{
|
||||
|
@ -1090,6 +1105,9 @@ void handle_device_unbind(void)
|
|||
g_device_control.power_on_cnt = 0; // 重置上电计数
|
||||
stop_spotlight_main_task();
|
||||
device_control_t tmp = DEFAULT_DEVICE_DATA;//恢复默认
|
||||
if (!g_reset_factory_flag) {
|
||||
tmp.is_net_configured = g_device_control.is_net_configured;
|
||||
}
|
||||
g_device_control = tmp;
|
||||
save_device_data();
|
||||
}
|
||||
|
|
|
@ -108,9 +108,17 @@ int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int
|
|||
g_device_control.duty_ww);
|
||||
return 0;
|
||||
}
|
||||
extern int HILINK_RestoreFactorySettings(void);
|
||||
int hf_atcmd_reset(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 注册AT指令
|
||||
const hfat_cmd_t spotlight_ut_cmds_table[] = {
|
||||
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
extern bool g_reset_factory_flag;
|
||||
int hf_atcmd_reset_factory(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
g_reset_factory_flag = true;
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
|
@ -265,7 +265,7 @@ target = {
|
|||
},
|
||||
'ws63-liteos-app-iot': {
|
||||
'base_target_name': 'target_ws63_app_rom_template',
|
||||
'liteos_kconfig': 'ws63_iot', # EKKO remove indie upgrade
|
||||
# 'liteos_kconfig': 'ws63_iot',
|
||||
'os': 'liteos',
|
||||
'defines': [
|
||||
"USE_CMSIS_OS",
|
||||
|
@ -308,11 +308,11 @@ target = {
|
|||
"SUPPORT_SOFTAP_NETCFG", # softAP配网
|
||||
"SUPPORT_BLE_ANCILLAY_NETCFG", # ble辅助配网
|
||||
# "SUPPORT_QUICK_NETCFG", # 快速配网
|
||||
# "CONFIG_SUPPORT_HILINK_INDIE_UPGRADE", # EKKO remove indie upgrade
|
||||
"CONFIG_SPOTLIGHT_UT",
|
||||
"CONFIG_SUPPORT_HILINK_INDIE_UPGRADE",
|
||||
"CONFIG_SPOTLIGHT_UT", #EKKO ADD
|
||||
"CONFIG_USE_CUSTOMER_SVC_INFO", #EKKO ADD
|
||||
"CONFIG_DHCPS_GW",
|
||||
"_HSF_",
|
||||
# "DEBUG_LOG_ENABLE", # EKKO ADD
|
||||
"CONFIG_PWM_USING_V150", #EKKO ADD
|
||||
# "ENABLE_BLE_SCAN" #open ble scan
|
||||
# "HF_MCU_OTA" #open mcu ota
|
||||
|
@ -357,10 +357,10 @@ target = {
|
|||
'cjson',
|
||||
'xo_trim_port',
|
||||
'hilink',
|
||||
# 'app_addr_map', # EKKO add for remove indie upgrade
|
||||
'hilinkdevicesdk', # EKKO remove indie upgrade
|
||||
'hilinkota', # EKKO remove indie upgrade
|
||||
'hilinkbtsdk', # EKKO remove indie upgrade
|
||||
'app_addr_map',
|
||||
# 'hilinkdevicesdk',
|
||||
# 'hilinkota',
|
||||
# 'hilinkbtsdk',
|
||||
'huks_sdk',
|
||||
'deviceauth',
|
||||
'little_fs', 'littlefs_adapt_ws63',
|
||||
|
|
|
@ -258,7 +258,6 @@ CONFIG_DRIVER_SUPPORT_PWM=y
|
|||
CONFIG_PWM_USING_V151=y
|
||||
# CONFIG_PWM_USING_V150 is not set
|
||||
CONFIG_PWM_GROUP_NUM=8
|
||||
CONFIG_PWM_CHANNEL_NUM=8
|
||||
# end of PWM Configuration
|
||||
# CONFIG_DRIVER_SUPPORT_HASH is not set
|
||||
# CONFIG_DRIVER_SUPPORT_MPU is not set
|
||||
|
|
|
@ -150,7 +150,7 @@ def all_build():
|
|||
exit(-1)
|
||||
shutil.rmtree(temp_dir)
|
||||
print("gen package.zip")
|
||||
file_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "package.py")
|
||||
file_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
os.system("cd " + file_dir + " && python3 package.py")
|
||||
|
||||
def sdk_build():
|
||||
|
|
BIN
output/SR_light-LPT262_hilink-20250602-1.0.0.fwpkg
Normal file
BIN
output/SR_light-LPT262_hilink-20250602-1.0.0.fwpkg
Normal file
Binary file not shown.
BIN
output/package(SR_light-LPT262_hilink-20250602-1.0.0).zip
Normal file
BIN
output/package(SR_light-LPT262_hilink-20250602-1.0.0).zip
Normal file
Binary file not shown.
|
@ -1,3 +1,4 @@
|
|||
python3 tools/pretool/ble_name_tool.py
|
||||
python3 tools/pretool/product_tool.py
|
||||
python3 tools/pretool/code_robot.py
|
||||
#!/bin/bash
|
||||
python3 ./tools/pretool/ble_name_tool.py
|
||||
python3 ./tools/pretool/product_tool.py
|
||||
python3 ./tools/pretool/code_robot.py
|
||||
|
|
24
tools/pretool/product_file/Product_2Q4H.json
Executable file
24
tools/pretool/product_file/Product_2Q4H.json
Executable file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"acKey":"6622335F7531296A2734574432422759E1DE9CA6A677548CA9B00DC7CB1B322BB94EEE97DC43FBF186CCFD6E78A83622",
|
||||
"accessType":"HARD",
|
||||
"brand":"硕镕智能",
|
||||
"brandEn":"SORONTEK",
|
||||
"desc":"firmwareVer:固件软件版本号; softwareVer:SDK版本号; hardwareVer:设备硬件版本号",
|
||||
"deviceModel":"SR-TH-020-10W",
|
||||
"deviceName":"SORONTEK智能双色温灯",
|
||||
"deviceTypeId":"21D",
|
||||
"deviceTypeName":"射灯",
|
||||
"deviceTypeNameEn":"Spot Lamp",
|
||||
"firmwareVer":null,
|
||||
"hardwareVer":"1.0.0",
|
||||
"manufacturerId":"gub",
|
||||
"manufacturerName":"中山市硕镕照明科技有限公司",
|
||||
"manufacturerNameEn":"SORONTEK",
|
||||
"os":"OpenHarmony",
|
||||
"osVersion":"4.1",
|
||||
"prodId":"2Q4H",
|
||||
"prodKey":"70c7daccd5d44813a43532f198221069",
|
||||
"productSeries":"",
|
||||
"protocolType":"WIFI+BLE+SLE",
|
||||
"softwareVer":"14.2.0.308"
|
||||
}
|
BIN
tools/pretool/product_file/Profile_2Q4H.xlsx
Executable file
BIN
tools/pretool/product_file/Profile_2Q4H.xlsx
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user