Commit 798605dc authored by chen.weican's avatar chen.weican

【修改内容】1,调整zigbee端组网打开指令的接收处理

【提交人】陈伟灿
parent 160d09e6
...@@ -91,10 +91,7 @@ void *kk_heartbeat_yield(void *args) ...@@ -91,10 +91,7 @@ void *kk_heartbeat_yield(void *args)
while (ctx->hearbeat_thread_running) { while (ctx->hearbeat_thread_running) {
current_time = HAL_UptimeMs(); current_time = HAL_UptimeMs();
_kk_heartbeat_lock(); _kk_heartbeat_lock();
if(dm_mgr_check_heartbeat_timeout(current_time) == DEVICE_HEARTBEAT_TIMEOUT){ dm_mgr_check_heartbeat_timeout(current_time);
INFO_PRINT("dev timeout,send offline\n");
}
_kk_heartbeat_unlock(); _kk_heartbeat_unlock();
sleep(30); sleep(30);
} }
......
...@@ -298,7 +298,7 @@ int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLE ...@@ -298,7 +298,7 @@ int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLE
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode); ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return FAIL_RETURN; return FAIL_RETURN;
} }
#define TEST_TIMEOUT 60000 // one minute #define TEST_TIMEOUT 600000 // ten minutes
int dm_mgr_check_heartbeat_timeout(uint64_t timestamp) int dm_mgr_check_heartbeat_timeout(uint64_t timestamp)
{ {
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
...@@ -306,19 +306,29 @@ int dm_mgr_check_heartbeat_timeout(uint64_t timestamp) ...@@ -306,19 +306,29 @@ int dm_mgr_check_heartbeat_timeout(uint64_t timestamp)
_dm_mgr_mutex_lock(); _dm_mgr_mutex_lock();
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
printf("search_node->devid--------->%d\n",search_node->devid);
printf("search_node->dev_type--------->%d\n",search_node->dev_type);
if(search_node->dev_type == KK_DM_DEVICE_CCU){ if(search_node->dev_type == KK_DM_DEVICE_CCU){
continue; continue;
} }
if((timestamp - search_node->timestamp) >= TEST_TIMEOUT/*search_node->hb_timeout*/){ if((timestamp - search_node->timestamp) >= TEST_TIMEOUT/*search_node->hb_timeout*/){
if(search_node->isOffline == 0){
INFO_PRINT("---------->dev timeout,send offline\n"); INFO_PRINT("---------->dev timeout,send offline\n");
printf("search_node->devid--------->%d\n",search_node->devid); search_node->isOffline = 1;
iotx_dm_dev_offline(search_node->devid); iotx_dm_dev_offline(search_node->devid);
kk_subDev_update_online(search_node->isOffline,search_node->deviceCode);
}
//_dm_mgr_mutex_unlock(); //_dm_mgr_mutex_unlock();
//return DEVICE_HEARTBEAT_TIMEOUT; //return DEVICE_HEARTBEAT_TIMEOUT;
} }
else{
if(search_node->isOffline == 1){//need send online
INFO_PRINT("---------->dev online again,send online\n");
search_node->isOffline = 0;
iotx_dm_dev_online(search_node->devid);
kk_subDev_update_online(search_node->isOffline,search_node->deviceCode);
}
}
} }
_dm_mgr_mutex_unlock(); _dm_mgr_mutex_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
......
...@@ -24,6 +24,7 @@ typedef struct { ...@@ -24,6 +24,7 @@ typedef struct {
char productCode[PRODUCT_CODE_MAXLEN]; char productCode[PRODUCT_CODE_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN]; char deviceCode[DEVICE_CODE_MAXLEN];
char fatherDeviceCode[DEVICE_CODE_MAXLEN]; char fatherDeviceCode[DEVICE_CODE_MAXLEN];
char isOffline;
int hb_timeout; //heartbeat time int hb_timeout; //heartbeat time
uint64_t timestamp; uint64_t timestamp;
struct list_head linked_list; struct list_head linked_list;
......
...@@ -63,7 +63,7 @@ static int kk_subDev_db_Init(void) ...@@ -63,7 +63,7 @@ static int kk_subDev_db_Init(void)
{ {
const char *pSubDevTable = "CREATE TABLE IF NOT EXISTS SubDeviceInfo( \ const char *pSubDevTable = "CREATE TABLE IF NOT EXISTS SubDeviceInfo( \
idx INTEGER, \ idx INTEGER, \
isOnline INTEGER, \ isOffline INTEGER, \
productCode varchar(33), \ productCode varchar(33), \
deviceCode varchar(33), \ deviceCode varchar(33), \
mac varchar(17), \ mac varchar(17), \
...@@ -175,7 +175,7 @@ static int _kk_check_subDev_exist(const char* deviceCode) ...@@ -175,7 +175,7 @@ static int _kk_check_subDev_exist(const char* deviceCode)
int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \ int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \
char deviceCode[DEVICE_CODE_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN],char mac[DEVICE_MAC_MAXLEN],char version[DEVICE_VERSION_MAXLEN]) char deviceCode[DEVICE_CODE_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN],char mac[DEVICE_MAC_MAXLEN],char version[DEVICE_VERSION_MAXLEN])
{ {
const char *insertCmd = "insert into SubDeviceInfo (idx,isOnline,productCode,deviceCode,mac,fatherDeviceCode,version,isAuth,devType) \ const char *insertCmd = "insert into SubDeviceInfo (idx,isOffline,productCode,deviceCode,mac,fatherDeviceCode,version,isAuth,devType) \
values ('%d','%d', '%s','%s','%s','%s','%s','%d','%d');"; values ('%d','%d', '%s','%s','%s','%s','%s','%d','%d');";
char *sqlCmd = NULL; char *sqlCmd = NULL;
int rc = 0; int rc = 0;
...@@ -227,7 +227,7 @@ int kk_subDev_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN]) ...@@ -227,7 +227,7 @@ int kk_subDev_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN])
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_subDev_update_online(int isOnline,const char *deviceCode) int kk_subDev_update_offline(int isOffline,const char *deviceCode)
{ {
char *sqlCmd = NULL; char *sqlCmd = NULL;
int len =0; int len =0;
...@@ -236,8 +236,8 @@ int kk_subDev_update_online(int isOnline,const char *deviceCode) ...@@ -236,8 +236,8 @@ int kk_subDev_update_online(int isOnline,const char *deviceCode)
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx(); kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
_kk_subDb_lock(); _kk_subDb_lock();
sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isOnline=%d WHERE deviceCode=%s",isOnline,deviceCode); sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isOffline=%d WHERE deviceCode=%s",isOffline,deviceCode);
INFO_PRINT("kk_subDev_update_online sqlCmd:%s\n",sqlCmd); INFO_PRINT("kk_subDev_update_offline sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg); ERROR_PRINT("SQL error: %s\n", zErrMsg);
...@@ -259,7 +259,7 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode) ...@@ -259,7 +259,7 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode)
_kk_subDb_lock(); _kk_subDb_lock();
sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isAuth=%d WHERE deviceCode=%s",isAuth,deviceCode); sqlCmd = sqlite3_mprintf("UPDATE SubDeviceInfo SET isAuth=%d WHERE deviceCode=%s",isAuth,deviceCode);
INFO_PRINT("kk_subDev_update_online sqlCmd:%s\n",sqlCmd); INFO_PRINT("kk_subDev_update_auth sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg); ERROR_PRINT("SQL error: %s\n", zErrMsg);
......
...@@ -93,6 +93,7 @@ static void _sub_dev_mutex_unlock(void) ...@@ -93,6 +93,7 @@ static void _sub_dev_mutex_unlock(void)
int kk_tsl_init(void) int kk_tsl_init(void)
{ {
int res = 0; int res = 0;
EmberEUI64 testMac = {0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11};
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx(); kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
ctx->mutex = _sub_MutexCreate(); ctx->mutex = _sub_MutexCreate();
if (ctx->mutex == NULL) { if (ctx->mutex == NULL) {
...@@ -100,7 +101,7 @@ int kk_tsl_init(void) ...@@ -100,7 +101,7 @@ int kk_tsl_init(void)
} }
ctx->sub_devid = 1; ctx->sub_devid = 1;
INIT_LIST_HEAD(&ctx->dev_list); INIT_LIST_HEAD(&ctx->dev_list);
//kk_sub_tsl_add("112233445566","a1h88DsZIaY"); kk_sub_tsl_add(testMac,"2");
//usleep(1000000); //usleep(1000000);
//kk_test(); //kk_test();
return SUCCESS_RETURN; return SUCCESS_RETURN;
......
...@@ -285,7 +285,13 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac) ...@@ -285,7 +285,13 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity); propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].Identity);
if(propertyItem != NULL) if(propertyItem != NULL)
{ {
int value = rpc_get_u8(propertyItem->valuestring); int value = 0;
if(propertyItem->type != cJSON_Number){
value = rpc_get_u8(propertyItem->valuestring);
}else{
value = propertyItem->valueint;
}
res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,&value); res = g_tsl_zigbee_map[pCtrlIdx].zigbee_ctrl[index].zigbee_set(ctx,mac->valuestring,&value);
if(res < 0){ if(res < 0){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
...@@ -301,12 +307,12 @@ error_return: ...@@ -301,12 +307,12 @@ error_return:
return rpc_cJSON_CreateNull(); return rpc_cJSON_CreateNull();
} }
cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id) int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,void* data)
{ {
cJSON * OpenOrClose;
EmberStatus status; EmberStatus status;
uint8_t isEnable; uint8_t isEnable = *(uint8_t*)data;
#if 0
if(params == NULL){ if(params == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return; goto error_return;
...@@ -318,7 +324,7 @@ cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id) ...@@ -318,7 +324,7 @@ cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id)
} }
isEnable = rpc_get_u8(OpenOrClose->valuestring); isEnable = rpc_get_u8(OpenOrClose->valuestring);
#endif
if(isEnable == 0){ if(isEnable == 0){
status = nwkPermitJoinCMD(FALSE); status = nwkPermitJoinCMD(FALSE);
emberAfCorePrintln("Disable Permit join\r\n"); emberAfCorePrintln("Disable Permit join\r\n");
...@@ -326,15 +332,14 @@ cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id) ...@@ -326,15 +332,14 @@ cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id)
status = nwkPermitJoinCMD(TRUE); status = nwkPermitJoinCMD(TRUE);
emberAfCorePrintln("Enable Permit join 180s\r\n"); emberAfCorePrintln("Enable Permit join 180s\r\n");
}else{ }else{
emberAfCorePrintln("item type error[%d]\r\n",OpenOrClose->type);
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return; goto error_return;
} }
return rpc_cJSON_CreateNumber(status); return status;
error_return: error_return:
return rpc_cJSON_CreateNull(); return -1;
} }
......
...@@ -21,12 +21,13 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac); ...@@ -21,12 +21,13 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac); cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
int lightStatusSet(jrpc_context * ctx,const char *mac,void* data); int lightStatusSet(jrpc_context * ctx,const char *mac,void* data);
int rpc_nwkPermitJoin(jrpc_context * ctx,const char *mac,void* data);
#define RPC_KK_TEST_FUNCTION_TABLE \ #define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)rpc_Control,"/thing/service/property/set"},\ {(rpc_function*)rpc_Control,"/thing/service/property/set"},\
{(rpc_function*)rpc_Control,KK_READ_ATTRIBUTE_METHOD},\ {(rpc_function*)rpc_Control,KK_READ_ATTRIBUTE_METHOD}
{(rpc_function*)rpc_nwkPermitJoin,"/thing/service/NetChannelState/set"}
......
...@@ -12,10 +12,10 @@ kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = { ...@@ -12,10 +12,10 @@ kk_tsl_zigbee_map_t g_tsl_zigbee_map [] = {
} }
}, },
{ {
"testtype", "2",
4, 4,
{ {
{KK_TSL_DATA_TYPE_TEXT,"test1",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"NetChannelState",rpc_nwkPermitJoin,0,0},
{KK_TSL_DATA_TYPE_TEXT,"test12",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"test12",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test123",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"test123",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
{KK_TSL_DATA_TYPE_TEXT,"test1234",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID}, {KK_TSL_DATA_TYPE_TEXT,"test1234",lightStatusSet,ZCL_ON_OFF_CLUSTER_ID,ZCL_ON_OFF_ATTRIBUTE_ID},
......
...@@ -33,7 +33,6 @@ void nwkClearJoiningLinkKeyCMD(void); ...@@ -33,7 +33,6 @@ void nwkClearJoiningLinkKeyCMD(void);
cJSON *rpc_nwkGetInfo(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_nwkGetInfo(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkFormCMD(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_nwkFormCMD(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkStar(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_nwkStar(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkLeave(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_nwkLeave(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkLeaveRequest(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_nwkLeaveRequest(jrpc_context * ctx, cJSON * params, cJSON *id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment