Commit fcafb8ee authored by 尹佳钦's avatar 尹佳钦

20210804

parent 042c495e
...@@ -249,11 +249,14 @@ int kk_zb_devs_hw_ack_all(int sockfd) ...@@ -249,11 +249,14 @@ int kk_zb_devs_hw_ack_all(int sockfd)
cJSON *array = cJSON_CreateArray(); cJSON *array = cJSON_CreateArray();
cJSON *item; cJSON *item;
_kk_map_dev_mutex_lock();
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if((item = kk_zb_dev_hw_info_build(search_node->deviceCode,search_node->productCode,search_node->online_status,NULL,NULL))!=NULL){ if((item = kk_zb_dev_hw_info_build(search_node->deviceCode,search_node->productCode,search_node->online_status,NULL,NULL))!=NULL){
cJSON_AddItemToArray(array,item); cJSON_AddItemToArray(array,item);
} }
} }
_kk_map_dev_mutex_unlock();
_kk_zb_devs_hw_ack(sockfd,array); _kk_zb_devs_hw_ack(sockfd,array);
return -1; return -1;
} }
...@@ -266,6 +269,7 @@ int kk_zb_dev_hw_info_build_by_deviceCode(int sockfd,const char *deviceCode) ...@@ -266,6 +269,7 @@ int kk_zb_dev_hw_info_build_by_deviceCode(int sockfd,const char *deviceCode)
unsigned char online_status = 0; unsigned char online_status = 0;
int pid =-1; int pid =-1;
_kk_map_dev_mutex_lock();
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) && if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) { (memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
...@@ -275,6 +279,7 @@ int kk_zb_dev_hw_info_build_by_deviceCode(int sockfd,const char *deviceCode) ...@@ -275,6 +279,7 @@ int kk_zb_dev_hw_info_build_by_deviceCode(int sockfd,const char *deviceCode)
return item; return item;
} }
} }
_kk_map_dev_mutex_unlock();
return NULL; return NULL;
} }
......
...@@ -18,14 +18,14 @@ kk_map_dev_ctx *_kk_map_dev_ctx(void) ...@@ -18,14 +18,14 @@ kk_map_dev_ctx *_kk_map_dev_ctx(void)
return &g_map_dev_mgr; return &g_map_dev_mgr;
} }
static void _kk_map_dev_mutex_lock(void) void _kk_map_dev_mutex_lock(void)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if (ctx->mutex) { if (ctx->mutex) {
kk_MutexLock(ctx->mutex); kk_MutexLock(ctx->mutex);
} }
} }
static void _kk_map_dev_mutex_unlock(void) void _kk_map_dev_mutex_unlock(void)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if (ctx->mutex) { if (ctx->mutex) {
...@@ -53,7 +53,6 @@ void kk_map_dev_deinit(void) ...@@ -53,7 +53,6 @@ void kk_map_dev_deinit(void)
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[lock]_kk_map_dev_mutex_lock\n");
_kk_map_dev_mutex_lock(); _kk_map_dev_mutex_lock();
list_for_each_entry_safe(node,n,&ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry_safe(node,n,&ctx->dev_list, linked_list, kk_map_dev_node_t) {
...@@ -74,7 +73,6 @@ void kk_map_dev_deinit(void) ...@@ -74,7 +73,6 @@ void kk_map_dev_deinit(void)
} }
} }
printf("[unlock]_kk_map_dev_mutex_lock\n");
_kk_map_dev_mutex_unlock(); _kk_map_dev_mutex_unlock();
} }
...@@ -87,6 +85,7 @@ static kk_map_dev_node_t *kk_map_dev_node_create(const char *deviceCode,const ch ...@@ -87,6 +85,7 @@ static kk_map_dev_node_t *kk_map_dev_node_create(const char *deviceCode,const ch
cJSON *newccu = NULL,*oldccu = NULL,*channel = NULL,*optype = NULL; cJSON *newccu = NULL,*oldccu = NULL,*channel = NULL,*optype = NULL;
cJSON *syn_type = NULL,*syn_opcode = NULL; cJSON *syn_type = NULL,*syn_opcode = NULL;
printf("kk_map_dev_node_create\n");
node = malloc(sizeof(kk_map_dev_node_t)); node = malloc(sizeof(kk_map_dev_node_t));
if (node == NULL) { if (node == NULL) {
return NULL; return NULL;
...@@ -410,17 +409,21 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node) ...@@ -410,17 +409,21 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node)
kk_map_dev_node_t *n = NULL; kk_map_dev_node_t *n = NULL;
//list_for_each_entry_safe //list_for_each_entry_safe
printf("[QAQ] kk_map_dev_search_by_deviceCode\n");
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
printf("+++\n");
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) && if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) { (memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
/* dm_log_debug("Device Found, devid: %d", devid); */ /* dm_log_debug("Device Found, devid: %d", devid); */
if (node) { if (node) {
*node = search_node; *node = search_node;
} }
printf("[find]%s\n",search_node->deviceCode);
return 0; return 0;
} }
} }
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode); ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return -1; return -1;
} }
......
...@@ -64,6 +64,7 @@ int main(int argc, char* argv[]) ...@@ -64,6 +64,7 @@ int main(int argc, char* argv[])
char *ppp; char *ppp;
open("kk_lan",LOG_PID,LOG_USER); open("kk_lan",LOG_PID,LOG_USER);
kk_lan_ccuid_init();
/*set the callback to get the device date to cloud*/ /*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromMid,NULL,NULL); kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromMid,NULL,NULL);
......
...@@ -305,6 +305,8 @@ int kk_sync_devices_to_sdk(cJSON *root) ...@@ -305,6 +305,8 @@ int kk_sync_devices_to_sdk(cJSON *root)
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
cJSON *devices = cJSON_CreateArray(); cJSON *devices = cJSON_CreateArray();
_kk_map_dev_mutex_lock();
list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if (node != NULL) { if (node != NULL) {
for(idx = 1; idx <= node->channelNum; idx++){ for(idx = 1; idx <= node->channelNum; idx++){
...@@ -332,6 +334,7 @@ int kk_sync_devices_to_sdk(cJSON *root) ...@@ -332,6 +334,7 @@ int kk_sync_devices_to_sdk(cJSON *root)
} }
} }
} }
_kk_map_dev_mutex_unlock();
cJSON_AddItemToObject(root, DEVICES_STRING, devices); cJSON_AddItemToObject(root, DEVICES_STRING, devices);
return 0; return 0;
} }
...@@ -344,7 +347,6 @@ cJSON *_kk_sync_devicestatus_arg_build(kk_map_dev_node_t *node) ...@@ -344,7 +347,6 @@ cJSON *_kk_sync_devicestatus_arg_build(kk_map_dev_node_t *node)
cJSON *newccu,*oldccu; cJSON *newccu,*oldccu;
cJSON *arg = cJSON_CreateObject(); cJSON *arg = cJSON_CreateObject();
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if(node == NULL ||node->syn_type!=1||node->syn_opcode==NULL){ if(node == NULL ||node->syn_type!=1||node->syn_opcode==NULL){
return arg; return arg;
...@@ -409,7 +411,6 @@ static int _kk_sync_devices_status_arg_str(kk_map_dev_node_t *node,cJSON *devSta ...@@ -409,7 +411,6 @@ static int _kk_sync_devices_status_arg_str(kk_map_dev_node_t *node,cJSON *devSta
cJSON *newccu = NULL,*oldccu = NULL; cJSON *newccu = NULL,*oldccu = NULL;
cJSON *dev_status = NULL; cJSON *dev_status = NULL;
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if(node == NULL ||devStatusAry==NULL||index==NULL){ if(node == NULL ||devStatusAry==NULL||index==NULL){
return -1; return -1;
...@@ -503,6 +504,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root) ...@@ -503,6 +504,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root)
cJSON *devStatusAry = cJSON_CreateArray(); cJSON *devStatusAry = cJSON_CreateArray();
_kk_map_dev_mutex_lock();
list_for_each_entry_safe(node,n, &ctx->dev_list, linked_list, kk_map_dev_node_t){ list_for_each_entry_safe(node,n, &ctx->dev_list, linked_list, kk_map_dev_node_t){
if(node->syn_type==1){ if(node->syn_type==1){
...@@ -513,7 +515,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root) ...@@ -513,7 +515,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root)
} }
} }
_kk_map_dev_mutex_unlock();
cJSON_AddItemToObject(root, DEVICE_STATUS_STRING, devStatusAry); cJSON_AddItemToObject(root, DEVICE_STATUS_STRING, devStatusAry);
...@@ -972,9 +974,11 @@ int kk_create_syncinfo_to_sdk(cJSON *payload) ...@@ -972,9 +974,11 @@ int kk_create_syncinfo_to_sdk(cJSON *payload)
printf("kk_sync_devices_status_to_sdk\n");
kk_sync_devices_status_to_sdk(root); kk_sync_devices_status_to_sdk(root);
printf("kk_sync_devices_to_sdk\n");
kk_sync_devices_to_sdk(root); kk_sync_devices_to_sdk(root);
printf("kk_get_sync_data\n");
cJSON *data = kk_get_sync_data(payload); cJSON *data = kk_get_sync_data(payload);
kk_sync_rooms_to_sdk(root,data); kk_sync_rooms_to_sdk(root,data);
......
...@@ -138,7 +138,6 @@ cJSON *kk_devicestatus_build(kk_map_dev_node_t *node) ...@@ -138,7 +138,6 @@ cJSON *kk_devicestatus_build(kk_map_dev_node_t *node)
cJSON *newccu,*oldccu; cJSON *newccu,*oldccu;
cJSON *dev_status; cJSON *dev_status;
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
printf("@@@@kk_devicestatus_build\n"); printf("@@@@kk_devicestatus_build\n");
if (node == NULL ||node->syn_opcode==NULL){ if (node == NULL ||node->syn_opcode==NULL){
...@@ -263,6 +262,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS ...@@ -263,6 +262,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS
cJSON *val; cJSON *val;
cJSON *item_size; cJSON *item_size;
cJSON *channel; cJSON *channel;
cJSON *epNum=NULL;
cJSON *opcode; cJSON *opcode;
...@@ -278,6 +278,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS ...@@ -278,6 +278,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS
newccu = devNode->newccu; newccu = devNode->newccu;
item_size = cJSON_GetArraySize(oldccu); item_size = cJSON_GetArraySize(oldccu);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
for(i=0;i<item_size;i++){ for(i=0;i<item_size;i++){
o_item = cJSON_GetArrayItem(oldccu,i); o_item = cJSON_GetArrayItem(oldccu,i);
...@@ -287,7 +288,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS ...@@ -287,7 +288,7 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS
n_id = cJSON_GetObjectItem(params,o_id_map->valuestring); n_id = cJSON_GetObjectItem(params,o_id_map->valuestring);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(n_id!=NULL){ if(n_id!=NULL){
n_dataType = cJSON_GetObjectItem(n_item,"dataType"); n_dataType = cJSON_GetObjectItem(n_item,"dataType");
...@@ -298,6 +299,16 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS ...@@ -298,6 +299,16 @@ cJSON * attr_report_conver(const char *deviceCode,kk_map_dev_node_t *devNode,cJS
channel = cJSON_GetObjectItem(o_item,"channel"); channel = cJSON_GetObjectItem(o_item,"channel");
epNum = cJSON_GetObjectItem(params,"epNum");
if(channel==NULL||epNum==NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue;
}
if(strlen(channel->valuestring)!=strlen(epNum->valuestring) ||
strcmp(channel->valuestring,epNum->valuestring)!=0){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue;
}
ch = atoi(channel->valuestring); ch = atoi(channel->valuestring);
nodeId = kk_lan_db_node_get(deviceCode,ch); nodeId = kk_lan_db_node_get(deviceCode,ch);
...@@ -465,6 +476,7 @@ void property_syn_deal(const char *deviceCode,cJSON *properties) ...@@ -465,6 +476,7 @@ void property_syn_deal(const char *deviceCode,cJSON *properties)
kk_map_dev_node_t *dev; kk_map_dev_node_t *dev;
if(kk_map_dev_search_by_deviceCode(deviceCode, &dev)==0){ if(kk_map_dev_search_by_deviceCode(deviceCode, &dev)==0){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
attr_report_conver(deviceCode,dev,properties); attr_report_conver(deviceCode,dev,properties);
} }
} }
......
...@@ -72,12 +72,12 @@ int kk_sync_init(void) ...@@ -72,12 +72,12 @@ int kk_sync_init(void)
static cJSON * kk_get_room_devices(const char *roomId) static cJSON * kk_get_room_devices(const char *roomId)
{ {
const char *selectCmd = "select * from AreaDevInfo WHERE roomId = '%s' and epNum = 1;"; const char *selectCmd = "select * from AreaDevInfo WHERE roomId = '%s';";
char *sqlCmd = NULL; char *sqlCmd = NULL;
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
char *deviceCode = NULL; char *deviceCode = NULL;
char *epNum = NULL;
cJSON *devs = cJSON_CreateArray(); cJSON *devs = cJSON_CreateArray();
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
...@@ -86,7 +86,11 @@ static cJSON * kk_get_room_devices(const char *roomId) ...@@ -86,7 +86,11 @@ static cJSON * kk_get_room_devices(const char *roomId)
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
cJSON *dev = cJSON_CreateObject(); cJSON *dev = cJSON_CreateObject();
deviceCode = (char*)sqlite3_column_text(stmt, DB_DEV_DEVICECODE); deviceCode = (char*)sqlite3_column_text(stmt, DB_DEV_DEVICECODE);
epNum = (char*)sqlite3_column_text(stmt, DB_DEV_EPNUM);
cJSON_AddStringToObject(dev,KK_SYNC_DEVICECODE_STR,deviceCode); cJSON_AddStringToObject(dev,KK_SYNC_DEVICECODE_STR,deviceCode);
cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum);
cJSON_AddItemToArray(devs, dev); cJSON_AddItemToArray(devs, dev);
} }
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
...@@ -102,7 +106,7 @@ static cJSON * kk_get_room_sences(const char *roomId) ...@@ -102,7 +106,7 @@ static cJSON * kk_get_room_sences(const char *roomId)
char *sqlCmd = NULL; char *sqlCmd = NULL;
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
char *sceneId = NULL; char *sceneId = NULL;
char *sceneType = NULL;
cJSON *scenes = cJSON_CreateArray(); cJSON *scenes = cJSON_CreateArray();
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
...@@ -111,13 +115,14 @@ static cJSON * kk_get_room_sences(const char *roomId) ...@@ -111,13 +115,14 @@ static cJSON * kk_get_room_sences(const char *roomId)
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
cJSON *scene = cJSON_CreateObject(); cJSON *scene = cJSON_CreateObject();
sceneId = (char*)sqlite3_column_text(stmt, DB_SCENEINFO_SCENEID); sceneId = (char*)sqlite3_column_text(stmt, DB_SCENEINFO_SCENEID);
sceneType = (char*)sqlite3_column_text(stmt, DB_SCENEINFO_SCENETYPE);
cJSON_AddStringToObject(scene,KK_SYNC_SCENEID_STR,sceneId); cJSON_AddStringToObject(scene,KK_SYNC_SCENEID_STR,sceneId);
cJSON_AddStringToObject(scene,KK_SYNC_SCENE_SCENETYPE_STR,sceneType);
cJSON_AddItemToArray(scenes, scene); cJSON_AddItemToArray(scenes, scene);
} }
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return scenes; return scenes;
} }
...@@ -178,8 +183,10 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj) ...@@ -178,8 +183,10 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj)
return FAIL_RETURN; return FAIL_RETURN;
} }
cJSON *propertyItem = cJSON_CreateObject(); cJSON *propertyItem = cJSON_CreateObject();
cJSON *eps = cJSON_CreateArray();
sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE deviceCode = '%s' ",deviceCode); sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE deviceCode = '%s' ",deviceCode);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER); propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE); valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
...@@ -194,8 +201,19 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj) ...@@ -194,8 +201,19 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj)
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){ }else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr)); cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr));
} }
char *propertiesbuf[64] = {0};
int num = 0;
//split(propertyStr,"_",propertiesbuf,&num);
if(num==2){
cJSON_AddStringToObject(propertyItem, "epNum",propertiesbuf[1]);
}else{
cJSON_AddStringToObject(propertyItem, "epNum","1");
}
cJSON_AddItemToArray(eps,propertyItem);
} }
cJSON_AddItemToObject(obj, KK_SYNC_PROPERTY_STR, propertyItem);
cJSON_AddItemToObject(obj, KK_SYNC_PROPERTY_STR, eps);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -376,7 +394,7 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,int id) ...@@ -376,7 +394,7 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,int id)
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_get_scenes_trigger_info(cJSON *triggerArray,char *sceneId) static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId)
{ {
char *sqlCmd = NULL; char *sqlCmd = NULL;
//char *zErrMsg = 0; //char *zErrMsg = 0;
...@@ -385,16 +403,18 @@ static int kk_get_scenes_trigger_info(cJSON *triggerArray,char *sceneId) ...@@ -385,16 +403,18 @@ static int kk_get_scenes_trigger_info(cJSON *triggerArray,char *sceneId)
char *propertyName = NULL; char *propertyName = NULL;
char *compareType = NULL; char *compareType = NULL;
char *compareValue = NULL; char *compareValue = NULL;
cJSON *triggerAry;
//char *type = NULL; //char *type = NULL;
int epNum = 0; int epNum = 0;
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
if(triggerArray == NULL || sceneId == NULL){ if(triggerObj == NULL || sceneId == NULL){
return FAIL_RETURN; return FAIL_RETURN;
} }
triggerAry = cJSON_CreateArray();
sqlCmd = sqlite3_mprintf("select * from SceneTriggerInfo where sceneId = %s",sceneId); sqlCmd = sqlite3_mprintf("select * from SceneTriggerInfo where sceneId = %s",sceneId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
cJSON *triggerItem = cJSON_CreateObject(); cJSON *triggerItem = cJSON_CreateArray();
deviceCode = (char*)sqlite3_column_text(stmt, DB_SCENETRIGGER_DEVICECODE); deviceCode = (char*)sqlite3_column_text(stmt, DB_SCENETRIGGER_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENETRIGGER_EPNUM); epNum = sqlite3_column_int(stmt, DB_SCENETRIGGER_EPNUM);
propertyName = (char*)sqlite3_column_text(stmt, DB_SCENETRIGGER_PROPERTYNAME); propertyName = (char*)sqlite3_column_text(stmt, DB_SCENETRIGGER_PROPERTYNAME);
...@@ -406,13 +426,17 @@ static int kk_get_scenes_trigger_info(cJSON *triggerArray,char *sceneId) ...@@ -406,13 +426,17 @@ static int kk_get_scenes_trigger_info(cJSON *triggerArray,char *sceneId)
cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_PROPERTYNAME_STR, (char*)propertyName); cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_PROPERTYNAME_STR, (char*)propertyName);
cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_COMPARETYPE_STR, (char*)compareType); cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_COMPARETYPE_STR, (char*)compareType);
cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_COMPAREValue_STR, (char*)compareValue); cJSON_AddStringToObject(triggerItem, KK_SYNC_SCENE_COMPAREValue_STR, (char*)compareValue);
cJSON_AddItemToArray(triggerArray, triggerItem); cJSON_AddItemToArray(triggerAry, triggerItem);
} }
cJSON_AddItemToObject(triggerObj, "items",triggerAry);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_get_scenes_condition_info(cJSON *conditionArray,char *sceneId) static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId)
{ {
char *sqlCmd = NULL; char *sqlCmd = NULL;
//char *zErrMsg = 0; //char *zErrMsg = 0;
...@@ -422,10 +446,13 @@ static int kk_get_scenes_condition_info(cJSON *conditionArray,char *sceneId) ...@@ -422,10 +446,13 @@ static int kk_get_scenes_condition_info(cJSON *conditionArray,char *sceneId)
int crossDay = 0; int crossDay = 0;
int repeat = 0; int repeat = 0;
cJSON *conditionAry;
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
if(conditionArray == NULL || sceneId == NULL){ if(conditionObj == NULL || sceneId == NULL){
return FAIL_RETURN; return FAIL_RETURN;
} }
conditionAry = cJSON_CreateArray();
sqlCmd = sqlite3_mprintf("select * from SceneConditionInfo where sceneId = %s",sceneId); sqlCmd = sqlite3_mprintf("select * from SceneConditionInfo where sceneId = %s",sceneId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
...@@ -438,8 +465,10 @@ static int kk_get_scenes_condition_info(cJSON *conditionArray,char *sceneId) ...@@ -438,8 +465,10 @@ static int kk_get_scenes_condition_info(cJSON *conditionArray,char *sceneId)
cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_ENDTIME_STR, endtime); cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_ENDTIME_STR, endtime);
cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_CROSSDAY_STR, crossDay); cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_CROSSDAY_STR, crossDay);
cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_REPEATDAY_STR, repeat); cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_REPEATDAY_STR, repeat);
cJSON_AddItemToArray(conditionArray, conditionItem); cJSON_AddItemToArray(conditionAry, conditionItem);
} }
cJSON_AddItemToObject(conditionObj, "items",conditionAry);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -477,12 +506,12 @@ static int kk_get_scenes_info(cJSON *data) ...@@ -477,12 +506,12 @@ static int kk_get_scenes_info(cJSON *data)
cJSON *actionArray = cJSON_CreateArray(); cJSON *actionArray = cJSON_CreateArray();
kk_get_scenes_actions_info(actionArray,atoi(sceneId)); kk_get_scenes_actions_info(actionArray,atoi(sceneId));
cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_ACTIONS_STR, actionArray); cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_ACTIONS_STR, actionArray);
cJSON *triggerArray = cJSON_CreateArray(); cJSON *triggerObj = cJSON_CreateObject();
kk_get_scenes_trigger_info(triggerArray,sceneId); kk_get_scenes_trigger_info(triggerObj,sceneId);
cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_TRIGGER_STR, triggerArray); cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_TRIGGER_STR, triggerObj);
cJSON *conditionArray = cJSON_CreateArray(); cJSON *conditionObj = cJSON_CreateObject();
kk_get_scenes_condition_info(conditionArray,sceneId); kk_get_scenes_condition_info(conditionObj,sceneId);
cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_CONDITION_STR, conditionArray); cJSON_AddItemToObject(sceneArrayItem, KK_SYNC_SCENE_CONDITION_STR, conditionObj);
cJSON_AddItemToArray(sceneArray, sceneArrayItem); cJSON_AddItemToArray(sceneArray, sceneArrayItem);
} }
cJSON_AddItemToObject(data, KK_SYNC_SCENE_STR, sceneArray); cJSON_AddItemToObject(data, KK_SYNC_SCENE_STR, sceneArray);
...@@ -549,10 +578,9 @@ char *kk_sync_get_info() ...@@ -549,10 +578,9 @@ char *kk_sync_get_info()
kk_get_scenes_info(data); kk_get_scenes_info(data);
HAL_GetDevice_Code(ccu_deviceCode); HAL_GetDevice_Code(ccu_deviceCode);
HAL_GetProduct_Code(ccu_productCode); HAL_GetProduct_Code(ccu_productCode);
HAL_GetVersion(version); HAL_GetVersion(version);
cJSON_AddStringToObject(data, KK_SYNC_DEVICECODE_STR,ccu_deviceCode); cJSON_AddStringToObject(data, KK_SYNC_DEVICECODE_STR,ccu_deviceCode);
cJSON_AddStringToObject(data, KK_SYNC_NANE_STR, "newccu"); cJSON_AddStringToObject(data, KK_SYNC_NANE_STR, "newccu");
sprintf(cloudstatus_str, "%d", kk_get_cloudstatus()); sprintf(cloudstatus_str, "%d", kk_get_cloudstatus());
......
...@@ -164,7 +164,7 @@ void kk_sendData2gw(void* data, int len, char* chalMark){ ...@@ -164,7 +164,7 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
kk_print_long_data(data,newLen); kk_print_long_data(data,newLen);
INFO_PRINT("start to send data to gw end\n"); INFO_PRINT("start to send data to gw end\n");
} }
static void split(char *src,const char *separator,char **dest,int *num) { void split(char *src,const char *separator,char **dest,int *num) {
char *pNext; char *pNext;
int count = 0; int count = 0;
if (src == NULL || strlen(src) == 0) if (src == NULL || strlen(src) == 0)
......
{
"productCode":"3020",
"operateType":"2001",
"channel":1,
"syn_type":1,
"syn_opcode":"STATUS",
"newccu":[
{
"identifier":"PowerSwitch",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},
{
"identifier":"Power",
"opcodemap":"GET_DEV_POWER",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
},
{
"identifier":"Electric",
"opcodemap":"GET_ELECTRICAL",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
},
{
"identifier":"",
"opcodemap":"STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[],
"value": 1
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"PowerSwitch",
"dataType":"map",
"channel":"1",
"valueRange":["OFF","ON"],
"syn":"switch",
"synType":"map"
},
{
"opcode":"GET_DEV_POWER",
"identifiermap":"Power",
"dataType":"string_double",
"channel":"1",
"valueRange":[],
"syn":"",
"synType":"dummy"
},
{
"opcode":"GET_ELECTRICAL",
"identifiermap":"Electric",
"dataType":"string_double",
"channel":"1",
"valueRange":[],
"syn":"",
"synType":"dummy"
},
{
"opcode":"STATUS",
"identifiermap":"",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"syn":"light_switch",
"synType":"bool"
}
]
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"channel":2, "channel":2,
"newccu":[ "newccu":[
{ {
"identifier":"PowerSwitch_1", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"value": 0 "value": 0
}, },
{ {
"identifier":"PowerSwitch_2", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"2", "channel":"2",
...@@ -23,14 +23,14 @@ ...@@ -23,14 +23,14 @@
"oldccu":[ "oldccu":[
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch_1", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
}, },
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch_2", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"2", "channel":"2",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
......
{
"productCode":"3027",
"operateType":"1003",
"channel":2,
"newccu":[
{
"identifier":"OperationMode",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1,2],
"value": 2
},
{
"identifier":"OperationMode",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"2",
"valueRange":[0,1,2],
"value": 2
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"OperationMode",
"dataType":"map",
"channel":"1",
"valueRange":["CLOSE","OPEN","STOP"]
},
{
"opcode":"SWITCH",
"identifiermap":"OperationMode",
"dataType":"map",
"channel":"2",
"valueRange":["CLOSE","OPEN","STOP"]
}
]
}
\ No newline at end of file
{
"productCode":"3032",
"operateType":"14002",
"channel":1,
"syn_type":1,
"syn_opcode":"CHOPIN_FRESH_AIR_STATUS",
"newccu":[
{
"identifier":"PowerSwitch",
"opcodemap":"FRESH_AIR_SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"WorkMode",
"opcodemap":"FRESH_AIR_RUN_MODEL",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 1
},{
"identifier":"WindSpeed",
"opcodemap":"FRESH_AIR_SPEED_SET",
"dataType":"int",
"channel":"1",
"valueRange":[0,1,2,3],
"value": 1
},{
"identifier":"ChildLockState",
"opcodemap":"FRESH_AIR_SET_LOCK_STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"TimingOffTime",
"opcodemap":"FRESH_AIR_SET_TIME_OFF",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"StrainerUsageTime",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"StrainerAlarmTime",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"CurrentTemperature",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
}
],
"oldccu":[
{
"opcode":"FRESH_AIR_SWITCH",
"identifiermap":"PowerSwitch",
"dataType":"map",
"channel":"1",
"valueRange":["OFF","ON"],
"syn":"on",
"synType":"bool"
},{
"opcode":"FRESH_AIR_RUN_MODEL",
"identifiermap":"WorkMode",
"dataType":"map",
"channel":"1",
"valueRange":["AUTO","MANUAL"],
"syn":"runModel",
"synType":"map"
},{
"opcode":"FRESH_AIR_SPEED_SET",
"identifiermap":"WindSpeed",
"dataType":"map",
"channel":"1",
"valueRange":["STOP","LOW","MID","HIGH"],
"syn":"speed",
"synType":"int"
},{
"opcode":"FRESH_AIR_SET_LOCK_STATUS",
"identifiermap":"ChildLockState",
"dataType":"bool",
"channel":"1",
"valueRange":[],
"syn":"ChildLockState",
"synType":"double"
},{
"opcode":"FRESH_AIR_SET_TIME_OFF",
"identifiermap":"TimingOffTime",
"dataType":"string_time",
"channel":"1",
"valueRange":[],
"syn":"time_off",
"synType":"string_time"
},{
"opcode":"CHOPIN_FRESH_AIR_STATUS ",
"identifiermap":"StrainerUsageTime",
"dataType":"int",
"channel":"1",
"valueRange":[],
"syn":"filterScreenWorkTime",
"synType":"int"
},{
"opcode":"CHOPIN_FRESH_AIR_STATUS",
"identifiermap":"StrainerAlarmTime",
"dataType":"int",
"channel":"1",
"valueRange":[],
"syn":"filterScreenAlarmTime",
"synType":"int"
},{
"opcode":"CHOPIN_FRESH_AIR_STATUS",
"identifiermap":"CurrentTemperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"cur_temperature",
"synType":"double"
}
]
}
{
"productCode":"3034",
"operateType":"15003",
"channel":1,
"syn_type":1,
"syn_opcode":"FAN_COIL_STATUS",
"newccu":[
{
"identifier":"PowerSwitch",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"WorkMode",
"opcodemap":"FAN_COIL_SET_RUN_MODEL",
"dataType":"int",
"channel":"1",
"valueRange":[1,2,3,4],
"value": 1
},{
"identifier":"WindSpeed",
"opcodemap":"FAN_COIL_SET_FUN_SPEED",
"dataType":"int",
"channel":"1",
"valueRange":[1,2,3,4],
"value": 1
},{
"identifier":"TargetTemperature",
"opcodemap":"FAN_COIL_SET_TEMPERATURE",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 16
},{
"identifier":"TimingOffTime",
"opcodemap":"FAN_COIL_SET_DELAY_SWITCH_TASK",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"ChildLockState",
"opcodemap":"FAN_COIL_SET_LOCK_STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"CurrentTemperature",
"opcodemap":"room_temperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 22
},{
"identifier":"smart_model_id",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"smart_model_time_index",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"system_time",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": "1970-01-01 00:00:00"
},{
"identifier":"week_day",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"total_work_time",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"timing_boot",
"opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": {
"enable ": false,
"time": "00:00"
}
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"PowerSwitch",
"dataType":"map",
"channel":"1",
"valueRange":["OFF","ON"],
"syn":"on",
"synType":"bool"
},{
"opcode":"FAN_COIL_SET_RUN_MODEL",
"identifiermap":"WorkMode",
"dataType":"map",
"channel":"1",
"valueRange":["COLD","HOT","WIND","DEHUMIDIFICATION"],
"syn":"run_model",
"synType":"map"
},{
"opcode":"FAN_COIL_SET_FUN_SPEED",
"identifiermap":"WindSpeed",
"dataType":"map",
"channel":"1",
"valueRange":["AUTO","HIGH","MID","LOW"],
"syn":"fan_speed",
"synType":"map"
},{
"opcode":"FAN_COIL_SET_TEMPERATURE",
"identifiermap":"TargetTemperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"setting_temperature",
"synType":"double"
},{
"opcode":"FAN_COIL_SET_DELAY_SWITCH_TASK",
"identifiermap":"TimingOffTime",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"timing_shutdown",
"synType":"timing_shutdown"
},{
"opcode":"FAN_COIL_SET_LOCK_STATUS",
"identifiermap":"ChildLockState",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"",
"synType":"dummy"
},{
"opcode":"room_temperature",
"identifiermap":"CurrentTemperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"room_temperature",
"synType":"double"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"smart_model_id",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"smart_model_id",
"synType":"double"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"smart_model_time_index",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"smart_model_time_index",
"synType":"double"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"system_time",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"system_time",
"synType":"map"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"week_day",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"week_day",
"synType":"int"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"total_work_time",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"total_work_time",
"synType":"int"
},{
"opcode":"FAN_COIL_STATUS",
"identifiermap":"timing_boot",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"timing_boot",
"synType":"def"
}
]
}
{
"productCode":"3051",
"operateType":"3499",
"channel":1,
"syn_type":1,
"syn_opcode":"DOOR_CONTACT_STATUS",
"newccu":[
{
"identifier":"ContactState",
"opcodemap":"DOOR_CONTACT_NOTIFY",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},
{
"identifier":"Battery",
"opcodemap":"POWER_NOTIFY",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 0
}
],
"oldccu":[
{
"opcode":"DOOR_CONTACT_NOTIFY",
"identifiermap":"ContactState",
"dataType":"map",
"channel":"1",
"valueRange":["CLOSE","OPEN"],
"syn":"status",
"synType":"map"
},
{
"opcode":"POWER_NOTIFY",
"identifiermap":"Battery",
"dataType":"string_double",
"channel":"1",
"valueRange":[],
"syn":"power",
"synType":"string_double"
}
]
}
\ No newline at end of file
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