Commit 09e12432 authored by 尹佳钦's avatar 尹佳钦

新增群组功能(与网关侧待对接)

parent e5013c9e
...@@ -151,6 +151,19 @@ typedef struct { ...@@ -151,6 +151,19 @@ typedef struct {
#define KK_THING_SERVICE_GET_CCU_INFO "/thing/service/getCCUInfo" #define KK_THING_SERVICE_GET_CCU_INFO "/thing/service/getCCUInfo"
#define KK_THING_SERVICE_GET_CCU_INFO_REPLY "/thing/service/getCCUInfo_reply" #define KK_THING_SERVICE_GET_CCU_INFO_REPLY "/thing/service/getCCUInfo_reply"
#define KK_THING_SERVICE_ADDGROUP "/thing/service/addGroup"
#define KK_THING_SERVICE_ADDGROUP_REPLY "/thing/service/addGroup_reply"
#define KK_THING_SERVICE_UPDATEGROUP "/thing/service/updateGroup"
#define KK_THING_SERVICE_UPDATEGROUP_REPLY "/thing/service/updateGroup_reply"
#define KK_THING_SERVICE_DELETEGROUP "/thing/service/deleteGroup"
#define KK_THING_SERVICE_DELETEGROUP_REPLY "/thing/service/deleteGroup_reply"
#define KK_THING_SERVICE_QUERYGROUP "/thing/service/queryGroup"
#define KK_THING_SERVICE_QUERYGROUP_REPLY "/thing/service/queryGroup_reply"
#define KK_THING_SERVICE_EXCUTEGROUP "/thing/service/excuteGroup"
#define KK_THING_SERVICE_EXCUTEGROUP_REPLY "/thing/service/excuteGroup_reply"
void kk_sendData2app(void *info, void *payload,int isAsync); void kk_sendData2app(void *info, void *payload,int isAsync);
int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN], int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request); _OU_ dm_msg_request_t *request);
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#include "kk_product.h" #include "kk_product.h"
#include "kk_hal.h" #include "kk_hal.h"
#include "kk_history_db.h" #include "kk_history_db.h"
#include "kk_group_db.h"
#define IOTX_LINKKIT_KEY_ID "id" #define IOTX_LINKKIT_KEY_ID "id"
#define IOTX_LINKKIT_KEY_CODE "code" #define IOTX_LINKKIT_KEY_CODE "code"
#define IOTX_LINKKIT_KEY_DEVID "devid" #define IOTX_LINKKIT_KEY_DEVID "devid"
...@@ -1976,6 +1979,385 @@ static int _kk_cancel_warning_handle(char *deviceCode){ ...@@ -1976,6 +1979,385 @@ static int _kk_cancel_warning_handle(char *deviceCode){
kk_msg_execute_property_set(node->productCode,node->deviceCode,param,node->fatherDeviceCode); kk_msg_execute_property_set(node->productCode,node->deviceCode,param,node->fatherDeviceCode);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************
*功能描述:添加群组REPLY
*************************************************************/
static int kk_service_addGroup_reply(cJSON *root,cJSON *msgId,const char *groupId)
{
if(root == NULL || msgId == NULL || groupId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(root, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_ADDGROUP_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, productCode->valuestring);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "desc", "success");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
cJSON_AddStringToObject(payload, "method", "thing.service.addGroup_reply");
cJSON *paramInfo = cJSON_CreateObject();
cJSON_AddStringToObject(paramInfo, "groupId", groupId);
cJSON_AddItemToObject(payload, "params", paramInfo);
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:添加群组
*************************************************************/
static int kk_service_addGroup_handle(cJSON *root,cJSON *param,cJSON *msgId)
{
cJSON *groupName = NULL;
cJSON *ccuRoomId = NULL;
cJSON *didList = NULL;
cJSON *didListItem = NULL,*epNum = NULL,*deviceCode = NULL;
int i,didListCnt = 0;
char groupId[64] = {0};
HAL_GetTime_s(groupId);
groupName = cJSON_GetObjectItem(param, "groupName");
ccuRoomId = cJSON_GetObjectItem(param, "ccuRoomId");
didList = cJSON_GetObjectItem(param, "didList");
didListCnt = cJSON_GetArraySize(didList);
for(i=0;i<didListCnt;i++){
didListItem = cJSON_GetArrayItem(didList,i);
epNum = cJSON_GetObjectItem(didListItem, "epNum");
deviceCode = cJSON_GetObjectItem(didListItem, "deviceCode");
char *ptr = strrchr(deviceCode->valuestring,'_');
char *deviceCodeStr;
if(ptr==NULL){
deviceCodeStr = deviceCode->valuestring;
}else{
deviceCodeStr=ptr+1;
}
INFO_PRINT("epNum = %s,deviceCode = %s\n",epNum->valuestring,deviceCodeStr);
char parent[64];
memset(parent,0,sizeof(parent));
if(kk_subDev_find_fatherDeviceCode(deviceCodeStr,parent)==SUCCESS_RETURN){
INFO_PRINT("parent1 = %s\n",parent);
kk_group_db_insert(groupId,groupName->valuestring,ccuRoomId->valuestring,epNum->valuestring,deviceCodeStr,parent);
}else{
INFO_PRINT("not find parent.\n");
}
}
return kk_service_addGroup_reply(root,msgId,groupId);
}
/************************************************************
*功能描述:更新群组REPLY
*************************************************************/
static int kk_service_updateGroup_reply(cJSON *root,cJSON *msgId)
{
if(root == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(root, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_UPDATEGROUP_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, productCode->valuestring);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "desc", "success");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
cJSON_AddStringToObject(payload, "method", "thing.service.updateGroup_reply");
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:更新群组
*************************************************************/
static int kk_service_updateGroup_handle(cJSON *root,cJSON *param,cJSON *msgId)
{
cJSON *groupName = NULL;
cJSON *ccuRoomId = NULL;
cJSON *didList = NULL;
cJSON *didListItem = NULL,*epNum = NULL,*deviceCode = NULL;
int i,didListCnt = 0;
cJSON *groupId = NULL;
groupId = cJSON_GetObjectItem(param, "groupId");
groupName = cJSON_GetObjectItem(param, "groupName");
ccuRoomId = cJSON_GetObjectItem(param, "ccuRoomId");
didList = cJSON_GetObjectItem(param, "didList");
didListCnt = cJSON_GetArraySize(didList);
kk_group_db_delete(groupId->valuestring);
for(i=0;i<didListCnt;i++){
didListItem = cJSON_GetArrayItem(didList,i);
epNum = cJSON_GetObjectItem(didListItem, "epNum");
deviceCode = cJSON_GetObjectItem(didListItem, "deviceCode");
char *ptr = strrchr(deviceCode->valuestring,'_');
char *deviceCodeStr;
if(ptr==NULL){
deviceCodeStr = deviceCode->valuestring;
}else{
deviceCodeStr=ptr+1;
}
char parent[64];
memset(parent,0,sizeof(parent));
if(kk_subDev_find_fatherDeviceCode(deviceCodeStr,parent)==SUCCESS_RETURN){
INFO_PRINT("parent = %s\n",parent);
kk_group_db_insert(groupId->valuestring,groupName->valuestring,ccuRoomId->valuestring,epNum->valuestring,deviceCodeStr,parent);
}else{
INFO_PRINT("not find parent.\n");
}
}
return kk_service_updateGroup_reply(root,msgId);
}
/************************************************************
*功能描述:删除群组REPLY
*************************************************************/
static int kk_service_deleteGroup_reply(cJSON *root,cJSON *msgId)
{
if(root == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(root, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_DELETEGROUP_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, productCode->valuestring);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "desc", "success");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
cJSON_AddStringToObject(payload, "method", "thing.service.deleteGroup_reply");
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:删除群组
*************************************************************/
static int kk_service_deleteGroup_handle(cJSON *root,cJSON *param,cJSON *msgId)
{
cJSON *groupId = NULL;
groupId = cJSON_GetObjectItem(param, "groupId");
kk_group_db_delete(groupId->valuestring);
return kk_service_deleteGroup_reply(root,msgId);
}
/************************************************************
*功能描述:添加群组
*************************************************************/
static int kk_service_queryGroup_reply(cJSON *info_root,cJSON *msgId)
{
if(info_root == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(info_root, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_QUERYGROUP_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, productCode->valuestring);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "desc", "success");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
cJSON_AddStringToObject(payload, "method", "thing.service.queryGroup_reply");
cJSON *params = kk_group_db_query(0);
cJSON_AddItemToObject(payload, "params", params);
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return SUCCESS_RETURN;
}
static int kk_service_queryGroup_handle(cJSON *root,cJSON *msgId)
{
return kk_service_queryGroup_reply(root,msgId);
}
/************************************************************
*功能描述:执行群组REPLY
*************************************************************/
static int kk_service_executeGroup_reply(cJSON *root,cJSON *msgId)
{
if(root == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(root, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_EXCUTEGROUP_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, productCode->valuestring);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "desc", "success");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
cJSON_AddStringToObject(payload, "method", "thing.service.excuteGroup_reply");
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return SUCCESS_RETURN;
}
static int kk_service_executeGroup_send_to_gw(const char *groupId,cJSON *actions,const char *productCode,const char *deviceCode,char *fatherDeviceCode)
{
INFO_PRINT("kk_service_executeGroup_send_to_gw \n");
cJSON *root = cJSON_CreateObject();
cJSON *info = cJSON_CreateObject();
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(info,"msgtype","/thing/service/excuteGroup");
cJSON_AddStringToObject(info,"productCode",productCode);
cJSON_AddStringToObject(info,"deviceCode",deviceCode);
char msgId[MSG_MAX_LEN] = {0};
iotx_report_id(msgId);
cJSON_AddStringToObject(payload,"msgId",msgId);
cJSON_AddStringToObject(payload,"version","1.0");
char tm[33] = {0};
snprintf(tm,sizeof(tm),"%d",time(NULL));
cJSON_AddStringToObject(payload,"time",tm);
cJSON_AddStringToObject(payload,"method","thing.service.excuteGroup");
cJSON *params = cJSON_CreateObject();
cJSON_AddStringToObject(params,"groupId",groupId);
cJSON_AddItemToObject(params,"actions",actions);
cJSON_AddItemToObject(payload,"params",params);
cJSON_AddItemToObject(root,"info",info);
cJSON_AddItemToObject(root,"payload",payload);
char *data = cJSON_Print(root);
kk_sendData2gw(data,strlen(data), fatherDeviceCode);
cJSON_Delete(root);
free(data);
return 0;
}
/************************************************************
*功能描述:执行群组
*************************************************************/
static int kk_service_executeGroup_handle(cJSON *info_root,cJSON *param,cJSON *msgId)
{
cJSON *groupId = NULL;
cJSON *controlType = NULL;
cJSON *propertyValue = NULL;
INFO_PRINT("kk_service_executeGroup_handle \n");
groupId = cJSON_GetObjectItem(param, "groupId");
controlType = cJSON_GetObjectItem(param, "controlType");
propertyValue = cJSON_GetObjectItem(param, "propertyValue");
int type;
if(controlType->type==cJSON_String){
type = atoi(controlType->valuestring);
}else{
type = controlType->valueint;
}
char parent[64];
memset(parent,0,sizeof(parent));
cJSON *actions = kk_group_device_db_exe_act(groupId->valuestring,type,propertyValue->valueint,parent);
dm_mgr_dev_node_t *node = NULL;
if(strlen(parent)!=0&&dm_mgr_get_device_by_devicecode(parent, &node)==SUCCESS_RETURN){
kk_service_executeGroup_send_to_gw(groupId->valuestring,actions,node->productCode,node->deviceCode,parent);
}
return kk_service_executeGroup_reply(info_root,msgId);
}
/************************************************************ /************************************************************
*功能描述:收到云端数据后的回调处理 *功能描述:收到云端数据后的回调处理
*输入参数:type:数据类型 *输入参数:type:数据类型
...@@ -2385,6 +2767,35 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -2385,6 +2767,35 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR); cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR);
kk_service_getScreenInfo_handle(info_root,paramStr,msgId); kk_service_getScreenInfo_handle(info_root,paramStr,msgId);
} }
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_ADDGROUP) == 0){
INFO_PRINT("ADDGROUP \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR);
kk_service_addGroup_handle(info_root,paramStr,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_UPDATEGROUP) == 0){
INFO_PRINT("UPDATEGROUP \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR);
kk_service_updateGroup_handle(info_root,paramStr,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_DELETEGROUP) == 0){
INFO_PRINT("DELETEGROUP \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR);
kk_service_deleteGroup_handle(info_root,paramStr,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_QUERYGROUP) == 0){
INFO_PRINT("QUERYGROUP \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
kk_service_queryGroup_handle(info_root,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_EXCUTEGROUP) == 0){
INFO_PRINT("EXCUTEGROUP \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
cJSON *paramStr = cJSON_GetObjectItem(payload,MSG_PARAMS_STR);
kk_service_executeGroup_handle(info_root,paramStr,msgId);
}
else{ else{
INFO_PRINT("Error msgtype!!! \n"); INFO_PRINT("Error msgtype!!! \n");
} }
......
...@@ -1283,3 +1283,35 @@ int kk_get_screenDev_info(ScreenDevInfo_t *devInfo,char*serialId) ...@@ -1283,3 +1283,35 @@ int kk_get_screenDev_info(ScreenDevInfo_t *devInfo,char*serialId)
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
return 0; return 0;
} }
int kk_subDev_find_fatherDeviceCode(const char *deviceCode,char *fatherDeviceCode)
{
int res = 0;
sqlite3_stmt *stmt;
char *sqlCmd = NULL;
dm_mgr_dev_node_t *node = NULL;
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
const char *searchCmd = "select * from SubDeviceInfo WHERE deviceCode = '%s'";
if(deviceCode == NULL){
ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__);
return INVALID_PARAMETER;
}
sqlCmd = sqlite3_mprintf(searchCmd,deviceCode);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
char *parent = (char*)sqlite3_column_text(stmt, DB_SUB_FATHERDEVICECODE);
sprintf(fatherDeviceCode,"%s",parent);
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
return SUCCESS_RETURN;
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
return FAIL_RETURN;
}
...@@ -45,6 +45,7 @@ int kk_get_screenDev_info(ScreenDevInfo_t *devInfo,char*serialId); ...@@ -45,6 +45,7 @@ int kk_get_screenDev_info(ScreenDevInfo_t *devInfo,char*serialId);
int kk_subDev_getDeviceCodes_byProductType(DeviceCode_t *list,char *type); int kk_subDev_getDeviceCodes_byProductType(DeviceCode_t *list,char *type);
int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum); int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum);
int kk_subDev_update_fatherDeviceCode(char *fatherDeviceCode,const char *deviceCode); int kk_subDev_update_fatherDeviceCode(char *fatherDeviceCode,const char *deviceCode);
enum{ enum{
DB_SUB_IDX = 0, DB_SUB_IDX = 0,
DB_SUB_ONLINE, DB_SUB_ONLINE,
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "kk_hal.h" #include "kk_hal.h"
#include "kk_dm_msg.h" #include "kk_dm_msg.h"
#include "kk_linkkit.h" #include "kk_linkkit.h"
#include "kk_group_db.h"
extern sqlite3 *g_kk_pDb; extern sqlite3 *g_kk_pDb;
static int kk_check_multi_ep_num(char *deviceCode); static int kk_check_multi_ep_num(char *deviceCode);
...@@ -1045,8 +1047,13 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT ...@@ -1045,8 +1047,13 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
type = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_TYPE); type = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_TYPE);
if(strcmp(type,"action/thing/cluster")==0){
actionItem = cJSON_Parse(propertyName);
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_TYPE_STR, type);
cJSON_AddNumberToObject(actionItem,KK_SYNC_SCENE_PROPERTYVALUE_STR,atoi(propertyValue));
cJSON_AddNumberToObject(actionItem, KK_SYNC_SCENE_DELAY_STR, delay);
cJSON_AddItemToArray(actionArray, actionItem);
}else{
actionItem = cJSON_CreateObject(); actionItem = cJSON_CreateObject();
cJSON_AddStringToObject(actionItem, KK_SYNC_DEVICECODE_STR, deviceCode); cJSON_AddStringToObject(actionItem, KK_SYNC_DEVICECODE_STR, deviceCode);
...@@ -1086,6 +1093,9 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT ...@@ -1086,6 +1093,9 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
cJSON_AddItemToArray(actionArray, actionItem); cJSON_AddItemToArray(actionArray, actionItem);
} }
} }
}
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -1370,6 +1380,14 @@ static int kk_get_scenes_info(cJSON *data) ...@@ -1370,6 +1380,14 @@ static int kk_get_scenes_info(cJSON *data)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_get_group_info(cJSON *data)
{
cJSON *group = kk_group_db_query(1);
cJSON_AddItemToObject(data, "group", group);
return SUCCESS_RETURN;
}
/* /*
static int kk_get_ccu_properties(cJSON *property) static int kk_get_ccu_properties(cJSON *property)
{ {
...@@ -1425,6 +1443,7 @@ char *kk_sync_get_info() ...@@ -1425,6 +1443,7 @@ char *kk_sync_get_info()
kk_get_rooms_info(data); kk_get_rooms_info(data);
kk_get_devices_info(data); kk_get_devices_info(data);
kk_get_scenes_info(data); kk_get_scenes_info(data);
kk_get_group_info(data);
HAL_Get_ccuid(ccu_deviceCode); HAL_Get_ccuid(ccu_deviceCode);
kk_get_pid(ccu_productCode); kk_get_pid(ccu_productCode);
HAL_GetVersion(version); HAL_GetVersion(version);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "kk_area_handle.h" #include "kk_area_handle.h"
#include "kk_property_get_handle.h" #include "kk_property_get_handle.h"
#include "kk_motor_bind_db.h" #include "kk_motor_bind_db.h"
#include "kk_group_db.h"
int g_timezone = 8; int g_timezone = 8;
char * g_filerToPlatTable[] = char * g_filerToPlatTable[] =
...@@ -2086,6 +2087,7 @@ int main(const int argc, const char **argv) ...@@ -2086,6 +2087,7 @@ int main(const int argc, const char **argv)
kk_subDb_init(); kk_subDb_init();
kk_area_init(); kk_area_init();
kk_history_db_init(); kk_history_db_init();
kk_group_db_init();
kk_motor_bind_db_init(); kk_motor_bind_db_init();
kk_scene_init(); kk_scene_init();
g_timezone = HAL_Get_TimeZone(); g_timezone = HAL_Get_TimeZone();
......
...@@ -106,5 +106,4 @@ int kk_scene_update_productType(const char *sceneId,char *productType); ...@@ -106,5 +106,4 @@ int kk_scene_update_productType(const char *sceneId,char *productType);
int kk_scene_update_actionRoomId(const char *sceneId,char *roomId); int kk_scene_update_actionRoomId(const char *sceneId,char *roomId);
int kk_scene_update_device_active(char *deviceCode,int epNum,int value); 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_rebuild_device_active(char *deviceCode,int epNum);
#endif #endif
...@@ -1393,6 +1393,27 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat ...@@ -1393,6 +1393,27 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
argStr = cJSON_PrintUnformatted(arg); argStr = cJSON_PrintUnformatted(arg);
kk_scene_insert_scene_invokeService(typeStr,identifier->valuestring,argStr,sceneId); kk_scene_insert_scene_invokeService(typeStr,identifier->valuestring,argStr,sceneId);
free(argStr); free(argStr);
}else if(!strcmp(typeStr,"action/thing/cluster")){
propertyValue = cJSON_GetObjectItem(item,MSG_SCENE_PROPERTYVALUE);
if(propertyValue == NULL) return FAIL_RETURN;
delay = cJSON_GetObjectItem(item,MSG_SCENE_DELAY);
memset(propertyValueStr,0x0,sizeof(propertyValueStr));
snprintf(propertyValueStr,sizeof(propertyValueStr),"%d",propertyValue->valueint);
cJSON *groupId = cJSON_GetObjectItem(item,"groupId");
cJSON *controlType = cJSON_GetObjectItem(item,"controlType");
cJSON *temp = cJSON_CreateObject();
cJSON_AddStringToObject(temp,"groupId",groupId->valuestring);
cJSON_AddStringToObject(temp,"controlType",controlType->valuestring);
char *propertyNameStr = cJSON_PrintUnformatted(temp);
res = kk_scene_insert_scene_action(typeStr,"",0,
propertyNameStr,propertyValueStr,delay->valueint,sceneId,"");
free(propertyNameStr);
} }
else else
{ {
...@@ -2752,3 +2773,4 @@ int kk_scene_rebuild_device_active(char *deviceCode,int epNum) ...@@ -2752,3 +2773,4 @@ int kk_scene_rebuild_device_active(char *deviceCode,int epNum)
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
...@@ -87,6 +87,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac ...@@ -87,6 +87,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
int BodySensorTrigger_check(void); int BodySensorTrigger_check(void);
int bodySensor_find(const char *deviceCode,int ep); int bodySensor_find(const char *deviceCode,int ep);
int is_BodySensor_dev(const char *productCode); int is_BodySensor_dev(const char *productCode);
int kk_scene_rebuild_device_active(char *deviceCode,int epNum);
#endif #endif
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