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

【修改内容】增加已有场景打开全屋或者某房间所有灯, 再配置新的灯控设备到该家庭或者某房间,执行该场景观察之前添加的灯控和新添加的灯控是否都执行

【提交人】陈伟灿
parent 741f9a18
1.4.8
\ No newline at end of file
1.4.9
\ No newline at end of file
......@@ -354,9 +354,9 @@ cJSON * msg_convert_value(cJSON *d_type,cJSON *s_type,cJSON *value)
}
pVal = cJSON_Print(value);
//pVal = cJSON_Print(value);
//debug_log(LOG_DEBUG_LEVEL,"[convert]type:%s->%s,val=%s.\n",s_type->valuestring,d_type->valuestring,pVal);
free(pVal);
//free(pVal);
......
......@@ -447,7 +447,7 @@ int kk_topo_delete_handle(cJSON *payload,cJSON *buf)
cJSON_AddItemToObject(rootData,"payload",cJSON_Parse(payload11));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), node->fatherDeviceCode);//send to gw itself
kk_scene_update_device_active(deviceCode,-1,0);
kk_scene_delete_action_by_deviceCode(deviceCode);
kk_scene_rebuild_device_active(deviceCode,-1);
dm_mgr_subdev_delete(deviceCode);
free(pnewout);
......@@ -791,6 +791,7 @@ static int kk_service_addDeviceToRoom_handle(cJSON *params)
if(res != SUCCESS_RETURN){
return DEVICE_CTRL_FAIL;
}
kk_scene_productType_handle(node->productType);
return NO_ERROR;
}
/************************************************************
......
......@@ -794,11 +794,8 @@ int kk_subDev_check_scene_support(const char *deviceCode)
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
typedef struct{
char *type;
char *maptype;
}productype_map_s;
static productype_map_s producTypeMap[] = {
productype_map_s producTypeMap[] = {
{"CURTAIN","curtain"},
{"WINDOW","actuator"},
{"LIGHT","switch"},
......
......@@ -24,6 +24,10 @@ typedef struct {
char keyRole[8];
char keyName[32];
} LockKeyInfo_t;
typedef struct{
char *type;
char *maptype;
}productype_map_s;
int kk_subDb_init(void);
int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \
char deviceCode[DEVICE_CODE_MAXLEN],char fatherMac[DEVICE_MAC_MAXLEN],char mac[DEVICE_MAC_MAXLEN], char version[DEVICE_VERSION_MAXLEN],int heartbeat);
......@@ -56,7 +60,8 @@ int kk_LockUser_insert_db(char *keyId,char *keyType,char*keyRole,char *keyName,c
int kk_get_LockUser_list(LockKeyInfo_t *list,const char *deviceCode);
int kk_delete_LockUser_info(const char *deviceCode);
int kk_delete_LockUser_info_byId(const char *id);
int kk_get_product_type_table_size(void);
extern productype_map_s producTypeMap[];
enum{
DB_SUB_IDX = 0,
DB_SUB_ONLINE,
......
......@@ -741,7 +741,6 @@ int kk_scene_insert_scene_action(const char* type,const char* deviceCode,int epN
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
char *sqlCmd = NULL;
char *zErrMsg = 0;
printf("----->kk_scene_insert_scene_action\n");
const char *insertCmd = "insert into SceneActionInfo (type, deviceCode,epNum,propertyName,propertyValue,delay,sceneId,gwdeviceCode,active) \
values ('%s','%s','%d','%s','%s','%d','%s','%s','%d');";
......@@ -1071,7 +1070,36 @@ int kk_scene_delete_scene_action(const char *sceneId,int isforword)
_kk_scene_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述: 从数据库删除场景执行动作的基本数据
*输入参数: sceneId:场景Id
isforword:1,updateScene;0,addScene;
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_scene_delete_action_by_deviceCode(const char *deviceCode)
{
int res = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
char *sqlCmd = NULL;
char *zErrMsg = 0;
const char *deleteCmd = "delete from SceneActionInfo where deviceCode = '%s';";
_kk_scene_lock();
sqlCmd = sqlite3_mprintf(deleteCmd,deviceCode);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
sqlite3_free(sqlCmd);
_kk_scene_unlock();
return FAIL_RETURN;
}
sqlite3_free(sqlCmd);
_kk_scene_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述: 添加场景信息到数据库
*输入参数: name:场景名称
......
......@@ -119,4 +119,5 @@ int kk_scene_update_device_active(char *deviceCode,int epNum,int value);
int kk_scene_rebuild_device_active(char *deviceCode,int epNum);
int kk_scene_delete_scene_protype(const char *sceneId);
int kk_scene_insert_sceneProType_info(const char* roomId,char *propertyName,char *propertyValue,const char* sceneId,char *productType,int delay);
int kk_scene_delete_action_by_deviceCode(const char *deviceCode);
#endif
......@@ -465,7 +465,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
*************************************************************/
int kk_scene_delete_send_to_gw(const char *sceneId)
{
char gwdevice[5][DEVICE_CODE_MAXLEN] = {0};
char gwdevice[GATEWAY_SUPPORT_MAX][DEVICE_CODE_MAXLEN] = {0};
sqlite3_stmt *stmt;
char *sqlCmd = NULL;
char *gwdeviceCode = NULL;
......@@ -1471,9 +1471,6 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
memset(propertyValueStr,0x0,sizeof(propertyValueStr));
snprintf(propertyValueStr,sizeof(propertyValueStr),"%d",propertyValue->valueint);
cJSON *groupId = cJSON_GetObjectItem(item,"groupId");
cJSON *controlType = cJSON_GetObjectItem(item,"controlType");
......@@ -1521,7 +1518,6 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
str,typeStr,idelay);
free(str);
}
}
else{
deviceCode = cJSON_GetObjectItem(item,MSG_DEVICE_CODE_STR);
......@@ -2412,7 +2408,7 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
int delay = 0;
char *sqlCmd = NULL;
dm_mgr_dev_node_t *node = NULL;
char gwdevice[5][DEVICE_CODE_MAXLEN] = {0};
char gwdevice[GATEWAY_SUPPORT_MAX][DEVICE_CODE_MAXLEN] = {0};
int idx=0,num = 0;
sqlite3_stmt *stmt;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
......@@ -3044,3 +3040,54 @@ int kk_scene_rebuild_device_active(char *deviceCode,int epNum)
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_scene_productType_handle(char *productType)
{
int k = 0;
int size = 0;
char type[64] = {0};
int exist = 0;
sqlite3_stmt *stmt;
int res = FAIL_RETURN;
char *sqlCmd = NULL;
char *pSceneId = NULL;
char *pRoomId = NULL;
char *pPropertyName = NULL;
char *pPropertyValue = NULL;
int idelay = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
if(productType == NULL){
return -1;
}
size = kk_get_product_type_table_size();
for(k = 0; k < size; k++){
if(!strcmp(productType,producTypeMap[k].maptype)){
memcpy(type,producTypeMap[k].type,strlen(producTypeMap[k].type));
exist = 1;
break;
}
}
if(exist == 0){//无对应的type
return -1;
}
sqlCmd = sqlite3_mprintf("select * from SceneProTypeInfo WHERE productType = '%s'",type);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pSceneId = (char*)sqlite3_column_text(stmt, DB_SCENEPROTYPE_SCENEID);
pRoomId = (char*)sqlite3_column_text(stmt, DB_SCENEPROTYPE_ROOMID);
pPropertyName = (char*)sqlite3_column_text(stmt, DB_SCENEPROTYPE_PROPERTYNAME);
pPropertyValue = (char*)sqlite3_column_text(stmt, DB_SCENEPROTYPE_PROPERTYVALUE);
idelay = sqlite3_column_int(stmt,DB_SCENEPROTYPE_DELAY);
kk_scene_delete_scene_action(pSceneId,1);
usleep(50*1000);
kk_subDev_set_action_by_productType(type,pRoomId,pSceneId,pPropertyName,
pPropertyValue,"action/thing/setProperty",idelay);
kk_scene_action_info_send(0);
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
return 0;
}
\ No newline at end of file
......@@ -88,6 +88,6 @@ int BodySensorTrigger_check(void);
int bodySensor_find(const char *deviceCode,int ep);
int is_BodySensor_dev(const char *productCode);
int kk_scene_rebuild_device_active(char *deviceCode,int epNum);
int kk_scene_productType_handle(char *productType);
#endif
......@@ -28,7 +28,7 @@
#define DEVICE_PROPERTY_NAME_MAX (64+1)
#define DEVICE_PROPERTY_VALUE_MAX (255+1)
#define DEVICE_PROPERTY_NUM_MAX (16)
#define GATEWAY_SUPPORT_MAX (16)
#define KK_TSL_KEY_SCHEMA "schema"
#define KK_TSL_KEY_LINK "link"
#define KK_TSL_KEY_PRODUCTTYPE "productType"
......
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