Commit 06b76807 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】增加根据设备类型设置场景

See merge request chenweican/k-sdk!101
parents f03a7faf cacd37c7
...@@ -469,7 +469,15 @@ int dm_mgr_check_heartbeat_timeout(time_t timestamp) ...@@ -469,7 +469,15 @@ int dm_mgr_check_heartbeat_timeout(time_t timestamp)
if(search_node->hb_timeout == 0){ if(search_node->hb_timeout == 0){
search_node->hb_timeout = DEFAULT_HEARTBEAT_TIMEOUT; search_node->hb_timeout = DEFAULT_HEARTBEAT_TIMEOUT;
} }
if((timestamp - search_node->timestamp) >= search_node->hb_timeout/*search_node->hb_timeout*/){ if(search_node->devid == KK_DM_DEVICE_CCU_DEVICEID){
continue;
}
//printf("[%s][%d]search_node->productCode:%s\n",__FUNCTION__,__LINE__,search_node->productCode);
//printf("[%s][%d]search_node->hb_timeout:%d\n",__FUNCTION__,__LINE__,search_node->hb_timeout);
//printf("[%s][%d]search_node->isOffline:%d\n",__FUNCTION__,__LINE__,search_node->isOffline);
//printf("[%s][%d]search_node->timestamp:%d\n",__FUNCTION__,__LINE__,search_node->timestamp);
//printf("[%s][%d]timestamp:%d\n",__FUNCTION__,__LINE__,timestamp);
if((timestamp - search_node->timestamp) >= search_node->hb_timeout){
if(search_node->isOffline != KK_DEV_OFFLINE){ if(search_node->isOffline != KK_DEV_OFFLINE){
dm_mgr_set_dev_onoffline(search_node,1); dm_mgr_set_dev_onoffline(search_node,1);
} }
......
...@@ -295,13 +295,14 @@ int dm_msg_status_cloud(_IN_ char productCode[PRODUCT_CODE_MAXLEN], ...@@ -295,13 +295,14 @@ int dm_msg_status_cloud(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
} }
const char DM_MSG_COMBINE_STATUS_ONLINE_METHOD[] DM_READ_ONLY = "thing.status.online"; const char DM_MSG_COMBINE_STATUS_ONLINE_METHOD[] DM_READ_ONLY = "thing.status.online";
const char DM_MSG_COMBINE_STATUS_ONLINE[] DM_READ_ONLY = const char DM_MSG_COMBINE_STATUS_ONLINE[] DM_READ_ONLY =
"{\"deviceCode\":\"%s\"}"; "{\"deviceCode\":\"%s\",\"ccuCode\":\"%s\"}";
int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN], int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request) _IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{ {
char *params = NULL; char *params = NULL;
int params_len = 0; int params_len = 0;
char timestamp[DM_UTILS_UINT64_STRLEN] = {0}; char timestamp[DM_UTILS_UINT64_STRLEN] = {0};
char ccuid[32] = {0};
if (request == NULL || if (request == NULL ||
deviceCode == NULL || productCode == NULL || deviceCode == NULL || productCode == NULL ||
...@@ -315,17 +316,18 @@ int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN], ...@@ -315,17 +316,18 @@ int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
HAL_Snprintf(timestamp, DM_UTILS_UINT64_STRLEN, "%d", HAL_GetTime()); HAL_Snprintf(timestamp, DM_UTILS_UINT64_STRLEN, "%d", HAL_GetTime());
/* dm_log_debug("Time Stamp: %s", timestamp); */ /* dm_log_debug("Time Stamp: %s", timestamp); */
HAL_Get_ccuid(ccuid);
/* Params */ /* Params */
request->method = (char *)DM_MSG_COMBINE_STATUS_ONLINE_METHOD; request->method = (char *)DM_MSG_COMBINE_STATUS_ONLINE_METHOD;
params_len = strlen(DM_MSG_COMBINE_STATUS_ONLINE) + strlen(deviceCode) + 1; params_len = strlen(DM_MSG_COMBINE_STATUS_ONLINE) + strlen(deviceCode)+strlen(ccuid) + 1;
params = malloc(params_len); params = malloc(params_len);
if (params == NULL) { if (params == NULL) {
return DM_MEMORY_NOT_ENOUGH; return DM_MEMORY_NOT_ENOUGH;
} }
memset(params, 0, params_len); memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_STATUS_ONLINE,deviceCode);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_STATUS_ONLINE,deviceCode,ccuid);
request->params = params; request->params = params;
request->params_len = strlen(request->params); request->params_len = strlen(request->params);
...@@ -335,13 +337,14 @@ int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN], ...@@ -335,13 +337,14 @@ int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
const char DM_MSG_COMBINE_STATUS_OFFLINE_METHOD[] DM_READ_ONLY = "thing.status.offline"; const char DM_MSG_COMBINE_STATUS_OFFLINE_METHOD[] DM_READ_ONLY = "thing.status.offline";
const char DM_MSG_COMBINE_STATUS_OFFLINE[] DM_READ_ONLY = const char DM_MSG_COMBINE_STATUS_OFFLINE[] DM_READ_ONLY =
"{\"deviceCode\":\"%s\"}"; "{\"deviceCode\":\"%s\",\"ccuCode\":\"%s\"}";
int dm_msg_status_offline(_IN_ char productCode[PRODUCT_CODE_MAXLEN], int dm_msg_status_offline(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request) _IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{ {
char *params = NULL; char *params = NULL;
int params_len = 0; int params_len = 0;
char timestamp[DM_UTILS_UINT64_STRLEN] = {0}; char timestamp[DM_UTILS_UINT64_STRLEN] = {0};
char ccuid[32] = {0};
if (request == NULL || if (request == NULL ||
deviceCode == NULL || productCode == NULL || deviceCode == NULL || productCode == NULL ||
...@@ -355,17 +358,18 @@ int dm_msg_status_offline(_IN_ char productCode[PRODUCT_CODE_MAXLEN], ...@@ -355,17 +358,18 @@ int dm_msg_status_offline(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
HAL_Snprintf(timestamp, DM_UTILS_UINT64_STRLEN, "%d", HAL_GetTime()); HAL_Snprintf(timestamp, DM_UTILS_UINT64_STRLEN, "%d", HAL_GetTime());
/* dm_log_debug("Time Stamp: %s", timestamp); */ /* dm_log_debug("Time Stamp: %s", timestamp); */
HAL_Get_ccuid(ccuid);
/* Params */ /* Params */
request->method = (char *)DM_MSG_COMBINE_STATUS_OFFLINE_METHOD; request->method = (char *)DM_MSG_COMBINE_STATUS_OFFLINE_METHOD;
params_len = strlen(DM_MSG_COMBINE_STATUS_OFFLINE) + strlen(deviceCode) + 1; params_len = strlen(DM_MSG_COMBINE_STATUS_OFFLINE) + strlen(deviceCode)+ strlen(ccuid) + 1;
params = malloc(params_len); params = malloc(params_len);
if (params == NULL) { if (params == NULL) {
return DM_MEMORY_NOT_ENOUGH; return DM_MEMORY_NOT_ENOUGH;
} }
memset(params, 0, params_len); memset(params, 0, params_len);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_STATUS_OFFLINE,deviceCode);
HAL_Snprintf(params, params_len, DM_MSG_COMBINE_STATUS_OFFLINE,deviceCode,ccuid);
request->params = params; request->params = params;
request->params_len = strlen(request->params); request->params_len = strlen(request->params);
......
...@@ -548,6 +548,26 @@ int kk_subDev_check_scene_support(const char *deviceCode) ...@@ -548,6 +548,26 @@ int kk_subDev_check_scene_support(const char *deviceCode)
*返 回 值:0:成功;其他:失败 *返 回 值:0:成功;其他:失败
*其他说明: *其他说明:
*************************************************************/ *************************************************************/
typedef struct{
char *type;
char *maptype;
}productype_map_s;
static productype_map_s producTypeMap[] = {
{"CURTAIN","curtain"},
{"WINDOW","actuator"},
{"LIGHT","switch"},
{"LIGHT_STRIP","colorDimmableLight"},
{"LIGHT_DIMMER","lightPanel"},
{"SOCKET","outlet"},
{"AC_IndoorUnit","air"},
{"FLOOR_HEATING","floorHeating"},
{"FRESH_AIR","airConditioning"},
{"AIR_SWITCH","airSwitch"},
};
int kk_get_product_type_table_size(void)
{
return sizeof(producTypeMap)/sizeof(productype_map_s);
}
int kk_subDev_set_action_by_productType(const char *productType,const char *sceneId,const char *propertyName,const char *propertyValue,const char *type) int kk_subDev_set_action_by_productType(const char *productType,const char *sceneId,const char *propertyName,const char *propertyValue,const char *type)
{ {
int res = 0; int res = 0;
...@@ -562,25 +582,28 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen ...@@ -562,25 +582,28 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
kk_tsl_data_t *property = NULL; kk_tsl_data_t *property = NULL;
int k = 0,count = 0; int k = 0,count = 0;
char typeArray[10][32] = {0}; char typeArray[10][32] = {0};
int size = 0;
if(productType == NULL){ if(productType == NULL){
ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__); ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
INFO_PRINT("kk_subDev_set_action_by_productType called!!!\n"); INFO_PRINT("kk_subDev_set_action_by_productType called!!!\n");
if(!strcmp(productType,"CURTAIN")){ size = kk_get_product_type_table_size();
memcpy(typeArray[0],"curtain",strlen("curtain")); //printf("---------------------------->size:%d\n",size);
count = 1; for(k = 0; k < size; k++){
} //printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
else if(!strcmp(productType,"LIGHT")){ if(!strcmp(productType,producTypeMap[k].type)){
memcpy(typeArray[0],"switch",strlen("switch")); memcpy(typeArray[count],producTypeMap[k].maptype,strlen(producTypeMap[k].maptype));
memcpy(typeArray[1],"light",strlen("light")); //printf("---------------------------->producTypeMap[k].maptype:%s\n",producTypeMap[k].maptype);
count = 2; count++;
} if(count >= 10){
else{ break;
INFO_PRINT("kk_subDev_set_action_by_productType wrong type!!!\n"); }
}
} }
for(k = 0; k < count; k++){ for(k = 0; k < count; k++){
//printf("---------------------------->typeArray[k]:%s\n",typeArray[k]);
sqlCmd = sqlite3_mprintf(searchCmd,typeArray[k]); //curtain type sqlCmd = sqlite3_mprintf(searchCmd,typeArray[k]); //curtain type
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt)); //INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
...@@ -596,33 +619,34 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen ...@@ -596,33 +619,34 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
else{ else{
gw_support_scene = 0; gw_support_scene = 0;
} }
if(!strcmp(typeArray[k],"switch")){ //if(!strcmp(typeArray[k],"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){ for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx); property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){ if(property == NULL){
continue; continue;
} }
if(strstr(property->identifier,"PowerSwitch") != NULL){ if(strstr(property->identifier,propertyName) != NULL){
if(gw_support_scene){ if(gw_support_scene){
kk_scene_action_detail_t info = {0}; kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode)); memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier)); memcpy(info.propertyName,property->identifier,strlen(property->identifier));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue)); memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1; info.epNum = 1;
info.delay = 0; info.delay = 0;
kk_scene_action_add(node->fatherDeviceCode,sceneId,info); kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
}
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
property->identifier,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
} }
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
property->identifier,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
} }
}
} //}
#if 0
else{ else{
if(gw_support_scene){ if(gw_support_scene){
kk_scene_action_detail_t info = {0}; kk_scene_action_detail_t info = {0};
...@@ -641,6 +665,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen ...@@ -641,6 +665,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
continue; continue;
} }
} }
#endif
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
......
...@@ -617,7 +617,9 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -617,7 +617,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
if (chalMark != NULL){ if (chalMark != NULL){
dm_mgr_update_timestamp_by_devicecode(chalMark,HAL_Uptimes()); dm_mgr_update_timestamp_by_devicecode(chalMark,HAL_Uptimes());
} }
dm_mgr_update_timestamp_by_devicecode(info_dcode->valuestring,HAL_Uptimes()); if(strcmp(msgType->valuestring,"/thing/service/property/get_reply") != 0){
dm_mgr_update_timestamp_by_devicecode(info_dcode->valuestring,HAL_Uptimes());
}
if (strcmp(msgType->valuestring, KK_THING_TOPO_ADD_MSG)==0){ if (strcmp(msgType->valuestring, KK_THING_TOPO_ADD_MSG)==0){
jsonPay = cJSON_GetObjectItem(payload, MSG_PARAMS_STR); jsonPay = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
......
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