Commit cacd37c7 authored by chen.weican's avatar chen.weican

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

【提交人】陈伟灿
parent f03a7faf
......@@ -469,7 +469,15 @@ int dm_mgr_check_heartbeat_timeout(time_t timestamp)
if(search_node->hb_timeout == 0){
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){
dm_mgr_set_dev_onoffline(search_node,1);
}
......
......@@ -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[] DM_READ_ONLY =
"{\"deviceCode\":\"%s\"}";
"{\"deviceCode\":\"%s\",\"ccuCode\":\"%s\"}";
int dm_msg_status_online(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
char timestamp[DM_UTILS_UINT64_STRLEN] = {0};
char ccuid[32] = {0};
if (request == NULL ||
deviceCode == NULL || productCode == NULL ||
......@@ -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());
/* dm_log_debug("Time Stamp: %s", timestamp); */
HAL_Get_ccuid(ccuid);
/* Params */
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);
if (params == NULL) {
return DM_MEMORY_NOT_ENOUGH;
}
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_len = strlen(request->params);
......@@ -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[] DM_READ_ONLY =
"{\"deviceCode\":\"%s\"}";
"{\"deviceCode\":\"%s\",\"ccuCode\":\"%s\"}";
int dm_msg_status_offline(_IN_ char productCode[PRODUCT_CODE_MAXLEN],
_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_msg_request_t *request)
{
char *params = NULL;
int params_len = 0;
char timestamp[DM_UTILS_UINT64_STRLEN] = {0};
char ccuid[32] = {0};
if (request == NULL ||
deviceCode == NULL || productCode == NULL ||
......@@ -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());
/* dm_log_debug("Time Stamp: %s", timestamp); */
HAL_Get_ccuid(ccuid);
/* Params */
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);
if (params == NULL) {
return DM_MEMORY_NOT_ENOUGH;
}
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_len = strlen(request->params);
......
......@@ -548,6 +548,26 @@ int kk_subDev_check_scene_support(const char *deviceCode)
*返 回 值: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 res = 0;
......@@ -562,25 +582,28 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
kk_tsl_data_t *property = NULL;
int k = 0,count = 0;
char typeArray[10][32] = {0};
int size = 0;
if(productType == NULL){
ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__);
return INVALID_PARAMETER;
}
INFO_PRINT("kk_subDev_set_action_by_productType called!!!\n");
if(!strcmp(productType,"CURTAIN")){
memcpy(typeArray[0],"curtain",strlen("curtain"));
count = 1;
}
else if(!strcmp(productType,"LIGHT")){
memcpy(typeArray[0],"switch",strlen("switch"));
memcpy(typeArray[1],"light",strlen("light"));
count = 2;
}
else{
INFO_PRINT("kk_subDev_set_action_by_productType wrong type!!!\n");
size = kk_get_product_type_table_size();
//printf("---------------------------->size:%d\n",size);
for(k = 0; k < size; k++){
//printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
if(!strcmp(productType,producTypeMap[k].type)){
memcpy(typeArray[count],producTypeMap[k].maptype,strlen(producTypeMap[k].maptype));
//printf("---------------------------->producTypeMap[k].maptype:%s\n",producTypeMap[k].maptype);
count++;
if(count >= 10){
break;
}
}
}
for(k = 0; k < count; k++){
//printf("---------------------------->typeArray[k]:%s\n",typeArray[k]);
sqlCmd = sqlite3_mprintf(searchCmd,typeArray[k]); //curtain type
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//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
else{
gw_support_scene = 0;
}
if(!strcmp(typeArray[k],"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
if(strstr(property->identifier,"PowerSwitch") != NULL){
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
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;
}
//if(!strcmp(typeArray[k],"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
if(strstr(property->identifier,propertyName) != NULL){
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
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;
}
}
}
}
//}
#if 0
else{
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
......@@ -641,6 +665,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
continue;
}
}
#endif
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
......
......@@ -617,7 +617,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
if (chalMark != NULL){
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){
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