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

20210816

parents 5bba8740 a869b387
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#define GUARD_STATUS_ARMING_LEAVE_HOME "ARMING_LEAVE_HOME" #define GUARD_STATUS_ARMING_LEAVE_HOME "ARMING_LEAVE_HOME"
#define GUARD_STATUS_DISARMING "DISARMING" #define GUARD_STATUS_DISARMING "DISARMING"
#define GUARD_STATUS_ARMING_IN_HOME "ARMING_IN_HOME" #define GUARD_STATUS_ARMING_IN_HOME "ARMING_IN_HOME"
#define ARMING_STATUS_GUARD_ZONE "ARMING_CUSTOM_GUARD_ZONE"
#define EMPTY_STR "" #define EMPTY_STR ""
......
...@@ -441,7 +441,7 @@ int is_arming_status_notify(cJSON *payload) ...@@ -441,7 +441,7 @@ int is_arming_status_notify(cJSON *payload)
cJSON *params = NULL; cJSON *params = NULL;
cJSON *ArmingState = NULL; cJSON *ArmingState = NULL;
if((params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR))!=NULL){ if((params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR))!=NULL){
if((ArmingState = cJSON_GetObjectItem(payload, "ArmingState"))!=NULL){ if((ArmingState = cJSON_GetObjectItem(params, "ArmingState"))!=NULL){
if(ArmingState->type==cJSON_String && if(ArmingState->type==cJSON_String &&
ArmingState->valuestring!=NULL){ ArmingState->valuestring!=NULL){
return atoi(ArmingState->valuestring); return atoi(ArmingState->valuestring);
...@@ -487,9 +487,11 @@ void KK_Data_FromMid(void* str,int len) ...@@ -487,9 +487,11 @@ void KK_Data_FromMid(void* str,int len)
if (strstr(msgtype->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){ if (strstr(msgtype->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){
kk_parse_syncinfo(payload); kk_parse_syncinfo(payload);
kk_create_syncinfo_to_sdk(payload); kk_create_syncinfo_to_sdk(payload);
}else if(strstr(msgtype->valuestring,"/thing/event/property/post")!= NULL){ }
else if(strstr(msgtype->valuestring,"/thing/event/property/post")!= NULL){
if(is_ccu_msg(productCode,deviceCode)){ if(is_ccu_msg(productCode,deviceCode)){
int type; int type;
if((type = is_arming_status_notify(payload))!=-1){ if((type = is_arming_status_notify(payload))!=-1){
arming_status_notify(type); arming_status_notify(type);
...@@ -497,8 +499,6 @@ void KK_Data_FromMid(void* str,int len) ...@@ -497,8 +499,6 @@ void KK_Data_FromMid(void* str,int len)
}else{ }else{
property_post_deal(deviceCode->valuestring,payload); property_post_deal(deviceCode->valuestring,payload);
} }
}else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){ }else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){
device_delete_sync(payload); device_delete_sync(payload);
}else if(strstr(msgtype->valuestring,"/thing/status/online")!= NULL){ }else if(strstr(msgtype->valuestring,"/thing/status/online")!= NULL){
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
/*******获取同步数据json*******/ /*******获取同步数据json*******/
static cJSON *kk_get_sync_data(cJSON *payload) static cJSON *kk_get_sync_data(cJSON *payload)
{ {
cJSON *data = cJSON_GetObjectItem(payload,DATA_STR); return cJSON_GetObjectItem(payload,DATA_STR);
return cJSON_GetObjectItem(data,DATA_STR);
} }
...@@ -663,65 +662,94 @@ typedef struct{ ...@@ -663,65 +662,94 @@ typedef struct{
char *nodeId; char *nodeId;
char *sensor_type; char *sensor_type;
}SYN_GUARD_SENSORS; }SYN_GUARD_SENSORS;
static cJSON *_kk_guard_sensors_build(int num,SYN_GUARD_SENSORS *sensors) static int _kk_guard_sensors_build(cJSON *guard_sensors,int num,SYN_GUARD_SENSORS *sensors)
{ {
int i; int i;
cJSON *item; SYN_GUARD_SENSORS *pSensor;
cJSON *guard_sensors = cJSON_CreateArray();
SYN_GUARD_SENSORS *pSensor = sensors; if(num<=0 || sensors==NULL){
return -1;
}
pSensor = sensors;
for(i=0;i<num;i++,pSensor++){ for(i=0;i<num;i++,pSensor++){
item = cJSON_CreateObject(); cJSON *item = cJSON_CreateObject();
cJSON_AddStringToObject(item,"nodeid",(pSensor->nodeId)?pSensor->nodeId:"-1"); cJSON_AddStringToObject(item,"nodeid",(pSensor->nodeId)?pSensor->nodeId:"-1");
cJSON_AddStringToObject(item,"sensor_type",(pSensor->sensor_type)?pSensor->sensor_type:"0"); cJSON_AddStringToObject(item,"sensor_type",(pSensor->sensor_type)?pSensor->sensor_type:"0");
cJSON_AddItemToArray(guard_sensors,item); cJSON_AddItemToArray(guard_sensors,item);
} }
return guard_sensors; return 0;
} }
static cJSON *_kk_guard_custom_zone_build(int num,char *roomId)
{
int i;
cJSON *custom_guard_zone = cJSON_CreateArray();
char *pRoomId = roomId;
for(i=0;i<num;i++,pRoomId++){
cJSON_AddItemToArray(custom_guard_zone,cJSON_CreateString(pRoomId));
}
return custom_guard_zone;
}
int kk_sync_guard_to_sdk(cJSON *root,cJSON *data)
cJSON *kk_sync_guard_to_sdk(cJSON *root,cJSON *data)
{ {
char modeStr[8] = {0}; char *armingStr = NULL;
cJSON *guard = cJSON_CreateObject(); cJSON *guard = cJSON_CreateObject();
cJSON *custom_guard_zone; cJSON *custom_guard_zone = cJSON_CreateArray();
cJSON *guard_sensors; cJSON *guard_sensors = cJSON_CreateArray();
//todo 撤防布防
int guardMode = 0; cJSON *properties = cJSON_GetObjectItem(data,"properties");
snprintf(modeStr,sizeof(modeStr),"%d",guardMode); cJSON *ArmingState = NULL,*RoomIdsAry = NULL;
cJSON_AddStringToObject(guard, "arming_status", modeStr); cJSON_AddStringToObject(guard, "arming_status", "1");
cJSON_AddItemToObject(guard,"custom_guard_zone",custom_guard_zone);
cJSON_AddItemToObject(guard,"guard_sensors",guard_sensors);
SYN_GUARD_SENSORS sensors; cJSON_AddItemToObject(root, "guard", guard);
sensors.nodeId = malloc(10);
memset(sensors.nodeId,0,10);
memcpy(sensors.nodeId,"1234",strlen("1234"));
sensors.sensor_type = malloc(10);
memset(sensors.sensor_type,0,10);
memcpy(sensors.sensor_type,"5678",strlen("5678"));
guard_sensors = _kk_guard_sensors_build(1,&sensors); if(properties==NULL||properties->type!=cJSON_Object){
char roomId[12] = "abcd"; return -1;
custom_guard_zone = _kk_guard_custom_zone_build(1,roomId); }
cJSON_AddItemToObject(guard, "custom_guard_zone", custom_guard_zone);
cJSON_AddItemToObject(guard, "guard_sensors", guard_sensors);
cJSON_AddItemToObject(root, "guard", guard); ArmingState = cJSON_GetObjectItem(properties,"ArmingState");
if(ArmingState==NULL||ArmingState->type!=cJSON_Number){
return -1;
}
/*
"0": "离家布防",
"1": "撤防",
"2": "在家布防",
"3": "区域布防"
*/
//1:离家布防,2:撤防,3:在家布防,4:自定义防区布防。
if(ArmingState->valueint==0){
armingStr = "1";
}else if(ArmingState->valueint==2){
armingStr = "3";
}else if(ArmingState->valueint==3){
armingStr = "4";
}else {
armingStr = "2";
}
cJSON_ReplaceItemInObject(guard, "arming_status", cJSON_CreateString(armingStr));
if(ArmingState->valueint == 3){
int i,num;
cJSON *item = NULL;
char roomIdStr[16] = {0};
RoomIdsAry = cJSON_GetObjectItem(properties,"RoomIds");
if(RoomIdsAry==NULL||RoomIdsAry->type!=cJSON_Array){
return -1;
}
num = cJSON_GetArraySize(RoomIdsAry);
for(i=0;i<num;i++){
item = cJSON_GetArrayItem(RoomIdsAry,i);
if(item->type!=cJSON_Number){
continue ;
}
memset(roomIdStr,0,sizeof(roomIdStr));
snprintf(roomIdStr,sizeof(roomIdStr),"%d",item->valueint);
cJSON_AddItemToArray(custom_guard_zone,cJSON_CreateString(roomIdStr));
}
}
//新中控同步接口未有安防类传感器列表,故只保留实现接口,未具体实现转换
_kk_guard_sensors_build(guard_sensors,-1,NULL);
return 0;
} }
...@@ -1039,36 +1067,43 @@ int kk_create_syncinfo_to_sdk(cJSON *payload) ...@@ -1039,36 +1067,43 @@ int kk_create_syncinfo_to_sdk(cJSON *payload)
cJSON_AddStringToObject(ccu_link_status, "link_type", "broadband_net"); cJSON_AddStringToObject(ccu_link_status, "link_type", "broadband_net");
cJSON_AddItemToObject(root, "ccu_link_status", ccu_link_status); cJSON_AddItemToObject(root, "ccu_link_status", ccu_link_status);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cnwise_music_controllers = cJSON_CreateArray(); cnwise_music_controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "cnwise_music_controllers", cnwise_music_controllers); cJSON_AddItemToObject(root, "cnwise_music_controllers", cnwise_music_controllers);
code_lib_controllers = cJSON_CreateArray(); code_lib_controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "code_lib_controllers", code_lib_controllers); cJSON_AddItemToObject(root, "code_lib_controllers", code_lib_controllers);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
controllers = cJSON_CreateArray(); controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "controllers", controllers); cJSON_AddItemToObject(root, "controllers", controllers);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_devices_status_to_sdk(root); kk_sync_devices_status_to_sdk(root);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_devices_to_sdk(root,data); kk_sync_devices_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_rooms_to_sdk(root,data); kk_sync_rooms_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_scence_to_sdk(root,data); kk_sync_scence_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_gw_version_to_sdk(root,data); kk_sync_gw_version_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_ccu_version_to_sdk(root,data); kk_sync_ccu_version_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_guard_to_sdk(root,data); kk_sync_guard_to_sdk(root,data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_central_ac_to_sdk(root,data); kk_sync_central_ac_to_sdk(root,data);
kk_sync_central_ac_indoorunits_to_sdk(root,data); kk_sync_central_ac_indoorunits_to_sdk(root,data);
......
...@@ -507,10 +507,14 @@ int arming_status_notify(int type) ...@@ -507,10 +507,14 @@ int arming_status_notify(int type)
msg = old_ccu_msg_build(WILDCARD_CHARACTER_STR,GUARD_STATUS_DISARMING,SUCCESS_STR,WILDCARD_CHARACTER_STR); msg = old_ccu_msg_build(WILDCARD_CHARACTER_STR,GUARD_STATUS_DISARMING,SUCCESS_STR,WILDCARD_CHARACTER_STR);
}else if(type==2){ }else if(type==2){
msg = old_ccu_msg_build(WILDCARD_CHARACTER_STR,GUARD_STATUS_ARMING_IN_HOME,SUCCESS_STR,WILDCARD_CHARACTER_STR); msg = old_ccu_msg_build(WILDCARD_CHARACTER_STR,GUARD_STATUS_ARMING_IN_HOME,SUCCESS_STR,WILDCARD_CHARACTER_STR);
}else if(type==3){
msg = old_ccu_msg_build(WILDCARD_CHARACTER_STR,ARMING_STATUS_GUARD_ZONE,SUCCESS_STR,WILDCARD_CHARACTER_STR);
}else{ }else{
printf("[unkown arming type]!!!\n"); printf("[unkown arming type]!!!\n");
return -1; return -1;
} }
send_msg_to_module(msg); send_msg_to_module(msg);
cJSON_Delete(msg); cJSON_Delete(msg);
return 0; return 0;
......
...@@ -55,7 +55,8 @@ static int _kk_area_db_init(void) ...@@ -55,7 +55,8 @@ static int _kk_area_db_init(void)
const char *pAreaTable = "CREATE TABLE IF NOT EXISTS AreaInfo( \ const char *pAreaTable = "CREATE TABLE IF NOT EXISTS AreaInfo( \
idx INTEGER PRIMARY KEY, \ idx INTEGER PRIMARY KEY, \
name varchar(256), \ name varchar(256), \
roomId varchar(256))"; roomId varchar(256), \
armingstate INTEGER)";
if (sqlite3_exec(ctx->pDb, pAreaTable, NULL, NULL, &pcErr) != SQLITE_OK) if (sqlite3_exec(ctx->pDb, pAreaTable, NULL, NULL, &pcErr) != SQLITE_OK)
{ {
...@@ -103,7 +104,6 @@ int kk_area_init(void) ...@@ -103,7 +104,6 @@ int kk_area_init(void)
} }
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_check_room_exist(const char *roomId) static int kk_check_room_exist(const char *roomId)
{ {
int isExist = 0; int isExist = 0;
...@@ -200,7 +200,6 @@ static int _kk_room_dev_update(const char *name,const char *roomId) ...@@ -200,7 +200,6 @@ static int _kk_room_dev_update(const char *name,const char *roomId)
_kk_area_unlock(); _kk_area_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_room_add(const char *name,const char *roomId) int kk_room_add(const char *name,const char *roomId)
{ {
if(kk_check_room_exist(roomId)){ if(kk_check_room_exist(roomId)){
...@@ -211,9 +210,28 @@ int kk_room_add(const char *name,const char *roomId) ...@@ -211,9 +210,28 @@ int kk_room_add(const char *name,const char *roomId)
}else{ }else{
return _kk_room_add(name,roomId); return _kk_room_add(name,roomId);
} }
}
}
int kk_room_update_armingstate(int state,const char *roomid)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
_kk_area_lock();
sqlCmd = sqlite3_mprintf("UPDATE AreaInfo SET armingstate=%d WHERE roomId= '%s'",state,roomid);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table updata data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return SUCCESS_RETURN;
}
int kk_room_delete(const char *roomId) int kk_room_delete(const char *roomId)
{ {
int res = 0; int res = 0;
...@@ -240,37 +258,6 @@ int kk_room_delete(const char *roomId) ...@@ -240,37 +258,6 @@ int kk_room_delete(const char *roomId)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_get_device_name(const char* deviceCode,const char *epNum,char *devName,int size)
{
int isGet = 0;
sqlite3_stmt *stmt;
char *pDeviceCode = NULL;
char *pEpNum = NULL;
char *pDevName = NULL;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaDevInfo;";
_kk_area_lock();
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = (char*)sqlite3_column_text(stmt, DB_DEV_DEVICECODE);
pEpNum = (char*)sqlite3_column_text(stmt, DB_DEV_EPNUM);
if(!strcmp(deviceCode,pDeviceCode) && !strcmp(pEpNum,epNum))
{
pDevName = (char*)sqlite3_column_text(stmt, DB_DEV_DEV_NAME);
memset(devName,0,size);
snprintf(devName,size,"%s",pDevName);
isGet = 1;
}
}
//INFO_PRINT("\n");
sqlite3_finalize(stmt);
_kk_area_unlock();
return isGet;
}
static int _kk_check_dev_exist(const char* deviceCode,const char *epNum) static int _kk_check_dev_exist(const char* deviceCode,const char *epNum)
{ {
int isExist = 0; int isExist = 0;
...@@ -328,7 +315,101 @@ int kk_room_dev_add(const char *roomId,const char *roomName,const char *deviceCo ...@@ -328,7 +315,101 @@ int kk_room_dev_add(const char *roomId,const char *roomName,const char *deviceCo
_kk_area_unlock(); _kk_area_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_room_reset_armingstate(void)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
_kk_area_lock();
sqlCmd = sqlite3_mprintf("UPDATE AreaInfo SET armingstate=%d ",0);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table updata data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return SUCCESS_RETURN;
}
int kk_get_room_armingstate(const char* roomId)
{
sqlite3_stmt *stmt;
int state = 0;
char *sqlCmd = NULL;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaInfo where roomId = '%s';";
_kk_area_lock();
sqlCmd = sqlite3_mprintf(searchCmd,roomId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
state = sqlite3_column_int(stmt, DB_ROOM_ARMING);
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
_kk_area_unlock();
return state;
}
int kk_get_roomId_by_deviceCode(const char* deviceCode,const char *epNum,char *roomId,int size)
{
int isGet = 0;
sqlite3_stmt *stmt;
char *pDeviceCode = NULL;
char *pEpNum = NULL;
char *pRoomId = NULL;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaDevInfo;";
_kk_area_lock();
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = (char*)sqlite3_column_text(stmt, DB_DEV_DEVICECODE);
pEpNum = (char*)sqlite3_column_text(stmt, DB_DEV_EPNUM);
if(!strcmp(deviceCode,pDeviceCode) && !strcmp(pEpNum,epNum))
{
pRoomId = (char*)sqlite3_column_text(stmt, DB_DEV_ROOM_ID);
memset(roomId,0,size);
snprintf(roomId,size,"%s",pRoomId);
isGet = 1;
}
}
//INFO_PRINT("\n");
sqlite3_finalize(stmt);
_kk_area_unlock();
return isGet;
}
int kk_get_device_name(const char* deviceCode,const char *epNum,char *devName,int size)
{
int isGet = 0;
sqlite3_stmt *stmt;
char *pDeviceCode = NULL;
char *pEpNum = NULL;
char *pDevName = NULL;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaDevInfo;";
_kk_area_lock();
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = (char*)sqlite3_column_text(stmt, DB_DEV_DEVICECODE);
pEpNum = (char*)sqlite3_column_text(stmt, DB_DEV_EPNUM);
if(!strcmp(deviceCode,pDeviceCode) && !strcmp(pEpNum,epNum))
{
pDevName = (char*)sqlite3_column_text(stmt, DB_DEV_DEV_NAME);
memset(devName,0,size);
snprintf(devName,size,"%s",pDevName);
isGet = 1;
}
}
//INFO_PRINT("\n");
sqlite3_finalize(stmt);
_kk_area_unlock();
return isGet;
}
int kk_room_dev_remove(const char *deviceCode,const char *epNum) int kk_room_dev_remove(const char *deviceCode,const char *epNum)
{ {
int res = 0; int res = 0;
...@@ -396,6 +477,7 @@ cJSON *kk_get_roomIds_ary(void) ...@@ -396,6 +477,7 @@ cJSON *kk_get_roomIds_ary(void)
int isExist = 0; int isExist = 0;
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
char *proomId = NULL; char *proomId = NULL;
int armingstate= 0;
cJSON *roomIdsAry = cJSON_CreateArray(); cJSON *roomIdsAry = cJSON_CreateArray();
kk_area_ctx_t *ctx = _kk_area_get_ctx(); kk_area_ctx_t *ctx = _kk_area_get_ctx();
...@@ -405,10 +487,14 @@ cJSON *kk_get_roomIds_ary(void) ...@@ -405,10 +487,14 @@ cJSON *kk_get_roomIds_ary(void)
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
armingstate = (int)sqlite3_column_int(stmt, DB_ROOM_ARMING);
if(armingstate!=0){
proomId = (char*)sqlite3_column_text(stmt, DB_ROOM_ID); proomId = (char*)sqlite3_column_text(stmt, DB_ROOM_ID);
cJSON_AddItemToArray(roomIdsAry,cJSON_CreateNumber(atoi(proomId))); cJSON_AddItemToArray(roomIdsAry,cJSON_CreateNumber(atoi(proomId)));
} }
}
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
_kk_area_unlock(); _kk_area_unlock();
......
...@@ -11,6 +11,7 @@ enum{ ...@@ -11,6 +11,7 @@ enum{
DB_ROOM_IDX = 0, DB_ROOM_IDX = 0,
DB_ROOM_NAME, DB_ROOM_NAME,
DB_ROOM_ID, DB_ROOM_ID,
DB_ROOM_ARMING,
}; };
enum{ enum{
...@@ -30,7 +31,10 @@ int kk_room_device_list_add(const char *deviceCode); ...@@ -30,7 +31,10 @@ int kk_room_device_list_add(const char *deviceCode);
kk_dev_list_t* kk_get_room_deviceCode(const char* roomId); kk_dev_list_t* kk_get_room_deviceCode(const char* roomId);
void kk_free_room_dev_list(void); void kk_free_room_dev_list(void);
int kk_get_device_name(const char* deviceCode,const char *epNum,char *devName,int size); int kk_get_device_name(const char* deviceCode,const char *epNum,char *devName,int size);
cJSON *kk_get_roomIds_ary(void); int kk_room_update_armingstate(int state,const char *roomid);
int kk_get_room_armingstate(const char* roomId);
int kk_get_roomId_by_deviceCode(const char* deviceCode,const char *epNum,char *roomId,int size);
#endif #endif
...@@ -392,24 +392,19 @@ int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _O ...@@ -392,24 +392,19 @@ int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _O
return FAIL_RETURN; return FAIL_RETURN;
} }
int dm_mgr_get_device_by_productType(_IN_ char *productType, _OU_ dm_mgr_dev_node_t **node) int dm_mgr_get_deviceNum_by_productType(_IN_ char *productType)
{ {
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL; dm_mgr_dev_node_t *search_node = NULL;
int num = 0;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
if ((strlen(search_node->deviceCode) == strlen(productType)) && if ((strlen(search_node->productType) == strlen(productType)) &&
(memcmp(search_node->deviceCode, productType, strlen(productType)) == 0)) { (memcmp(search_node->productType, productType, strlen(productType)) == 0)) {
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */ /* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if (node) { num++;
*node = search_node;
} }
return SUCCESS_RETURN;
} }
} return num;
ERROR_PRINT("Device Not Found, productType: %s\n", productType);
return FAIL_RETURN;
} }
int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],time_t timestamp) int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],time_t timestamp)
......
...@@ -88,7 +88,7 @@ int dm_mgr_search_device_by_pkdn( _IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ ...@@ -88,7 +88,7 @@ int dm_mgr_search_device_by_pkdn( _IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_
int dm_mgr_get_devicetype_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ int* deviceType); int dm_mgr_get_devicetype_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ int* deviceType);
int dm_mgr_get_device_shadow_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ kk_tsl_t **shadow); int dm_mgr_get_device_shadow_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ kk_tsl_t **shadow);
int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node); int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node);
int dm_mgr_get_device_by_productType(_IN_ char *productType, _OU_ dm_mgr_dev_node_t **node); int dm_mgr_get_deviceNum_by_productType(_IN_ char *productType);
int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],time_t timestamp); int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],time_t timestamp);
int dm_mgr_set_dev_onoffline(dm_mgr_dev_node_t *node,int isOffline); int dm_mgr_set_dev_onoffline(dm_mgr_dev_node_t *node,int isOffline);
int dm_mgr_check_heartbeat_timeout(time_t timestamp); int dm_mgr_check_heartbeat_timeout(time_t timestamp);
......
...@@ -19,6 +19,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){ ...@@ -19,6 +19,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){
cJSON_AddItemToObject(root, "info", infoObj); cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj); cJSON_AddItemToObject(root, "payload",payloadObj);
buf = cJSON_Print(root); buf = cJSON_Print(root);
cJSON_Minify(buf);
if(isAsync){ if(isAsync){
dm_queue_msg_insert4(buf); dm_queue_msg_insert4(buf);
...@@ -635,6 +636,69 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response ...@@ -635,6 +636,69 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
const char DM_MSG_SYNC_RESPONSE_WITH_DATA[]= "{\"msgId\":\"%.*s\",\"code\":%d,\"params\":%.*s}";
int dm_msg_sync_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response_t *response,
_IN_ char *data, _IN_ int data_len, _IN_ void *user_data)
{
int res = 0, payload_len = 0,res_info_len = 0;
char *uri = NULL, *payload = NULL;
lite_cjson_t lite;
char *res_info = NULL;
if (request == NULL || response == NULL || data == NULL || data_len <= 0) {
return INVALID_PARAMETER;
}
/* Response Payload */
payload_len = strlen(DM_MSG_SYNC_RESPONSE_WITH_DATA) + request->id.value_length + DM_UTILS_UINT32_STRLEN + data_len + 1;
payload = malloc(payload_len);
if (payload == NULL) {
free(uri);
return MEMORY_NOT_ENOUGH;
}
memset(payload, 0, payload_len);
snprintf(payload, payload_len, DM_MSG_SYNC_RESPONSE_WITH_DATA,
request->id.value_length, request->id.value, response->code, data_len, data);
res_info_len = strlen(DM_MSG_INFO)+10+strlen(response->productCode)+strlen(response->deviceCode)+strlen(response->msgTypeStr)+1;
res_info = malloc(res_info_len);
if (res_info == NULL) {
free(payload);
return MEMORY_NOT_ENOUGH;
}
memset(res_info, 0, res_info_len);
snprintf(res_info, res_info_len, DM_MSG_INFO, response->msgTypeStr,response->productCode, response->deviceCode);
memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(payload, payload_len, &lite);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("Wrong JSON Format, URI: %s, Payload: %s", uri, payload);
free(uri);
free(payload);
return FAIL_RETURN;
}
memset(&lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(res_info, res_info_len, &lite);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("Wrong JSON Format, Payload: %d", res_info_len);
free(res_info);
free(payload);
return FAIL_RETURN;
}
//dm_client_publish(uri, (unsigned char *)payload, strlen(payload), NULL);
kk_sendData2app(res_info, payload,0);
free(res_info);
free(payload);
return SUCCESS_RETURN;
}
int dm_msg_response_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ dm_msg_response_payload_t *response) int dm_msg_response_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ dm_msg_response_payload_t *response)
{ {
lite_cjson_t lite, lite_message; lite_cjson_t lite, lite_message;
...@@ -727,6 +791,50 @@ int dm_msg_thing_syncinfo_reply(void){ ...@@ -727,6 +791,50 @@ int dm_msg_thing_syncinfo_reply(void){
free(info); free(info);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int dm_msg_thing_syncdeviceinfo_reply(cJSON *msgId){
kk_msg_request_payload_t request;
kk_msg_response_t response;
dm_mgr_dev_node_t *node = NULL;
char *info = NULL;
int res = 0;
memset(&request, 0, sizeof(kk_msg_request_payload_t));
memset(&response, 0, sizeof(kk_msg_response_t));
if(msgId!=NULL && msgId->type==cJSON_String){
request.id.value_length = strlen(msgId->valuestring);
request.id.value = msgId->valuestring;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
res = dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//res = dm_msg_request_parse((char *)payload, payload_len, &request);
//if (res < SUCCESS_RETURN) {
//ERROR_PRINT("dm_msg_request_parse failed");
//return res ;
//}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
response.msgTypeStr = KK_THING_SERVICE_SYNCDEVICEINFO_REPLY;
memcpy(response.productCode, node->productCode, strlen( node->productCode));
memcpy(response.deviceCode, node->deviceCode, strlen(node->deviceCode));
response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
info = kk_sync_get_info();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
dm_msg_sync_response(&request, &response, info, strlen(info), NULL);
free(info);
return SUCCESS_RETURN;
}
const char DM_URI_THING_SERVICE_PROPERTY_SET_REPLY[] = "/thing/service/property/set_reply"; const char DM_URI_THING_SERVICE_PROPERTY_SET_REPLY[] = "/thing/service/property/set_reply";
int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *payload, unsigned int payload_len, int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *payload, unsigned int payload_len,
......
...@@ -81,8 +81,15 @@ const char DM_MSG_INFO[] DM_READ_ONLY; ...@@ -81,8 +81,15 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_METHOD_EXECUTESCENE "thing.service.executeScene" #define KK_THING_METHOD_EXECUTESCENE "thing.service.executeScene"
#define KK_THING_METHOD_ADDSCENC "thing.service.addScene" #define KK_THING_METHOD_ADDSCENC "thing.service.addScene"
#define KK_THING_SERVICE_SYNCINFO "/thing/service/syncinfo" #define KK_THING_SERVICE_SYNCINFO "/thing/service/syncinfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO "/thing/service/syncDeviceInfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO_REPLY "/thing/service/syncDeviceInfo_reply"
#define KK_THING_SERVICE_SYNCINFO_REPLY "/thing/service/syncinfo_reply" #define KK_THING_SERVICE_SYNCINFO_REPLY "/thing/service/syncinfo_reply"
#define KK_THING_EVENT_MESSAGE "/thing/event/" #define KK_THING_EVENT_MESSAGE "/thing/event/"
#define KK_THING_SERVICE_GETGUARDSENSORS "/thing/service/getGuardSensors"
#define KK_THING_EVENT_POST "/post" #define KK_THING_EVENT_POST "/post"
void kk_sendData2app(void *info, void *payload,int isAsync); void kk_sendData2app(void *info, void *payload,int isAsync);
......
...@@ -365,8 +365,10 @@ static int kk_service_addRoom_handle(const char *deviceCode, cJSON *params) ...@@ -365,8 +365,10 @@ static int kk_service_addRoom_handle(const char *deviceCode, cJSON *params)
if(roomInfoStr == NULL){ if(roomInfoStr == NULL){
return FAIL_RETURN; return FAIL_RETURN;
} }
memcpy(roomId,roomIdStr->valuestring,strlen(roomIdStr->valuestring));
kk_room_add(roomInfoStr->valuestring,roomIdStr->valuestring); HAL_GetTime_s((char*)roomId);
kk_room_add(roomInfoStr->valuestring,roomId);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_AREA_ADDROOM_NOTIFICATION_ROOMID,NULL,roomId); kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_AREA_ADDROOM_NOTIFICATION_ROOMID,NULL,roomId);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
...@@ -861,6 +863,67 @@ static int kk_service_executeScene_handle(cJSON *param,cJSON *msgId) ...@@ -861,6 +863,67 @@ static int kk_service_executeScene_handle(cJSON *param,cJSON *msgId)
return res; return res;
} }
/************************************************************ /************************************************************
*功能描述:获取主机下安防设备及对应等级
*输入参数:params:云端下发数据,包含场景Id等
msgId:消息Id
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
static int kk_service_getGuardSensors_handle(cJSON *param,cJSON *msgId)
{
int res = 0;
int i = 0,num = 0;
SensorType_t *pList = NULL;
if(param == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *deviceCode = cJSON_GetObjectItem(param, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
}
cJSON *productCode = cJSON_GetObjectItem(param, MSG_PRODUCT_CODE_STR);
if(productCode == NULL){
return FAIL_RETURN;
}
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/service/getGuardSensors_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 *paramArray = cJSON_CreateArray();
num = dm_mgr_get_deviceNum_by_productType("sensor");
pList = (SensorType_t*)malloc(sizeof(SensorType_t)*num);
if(pList == NULL){
ERROR_PRINT("MALLOC ERROR!!!");
return -1;
}
memset(pList,0x0, sizeof(SensorType_t)*num);
kk_subDev_getSensors_reply(pList);
for(i = 0; i < num; i++){
cJSON *Item = cJSON_CreateObject();
cJSON_AddNumberToObject(Item, "SensorType", pList[i].SensorType);
cJSON_AddStringToObject(Item, "DeviceCode", pList[i].deviceCode);
cJSON_AddItemToArray(paramArray, Item);
}
char *paramArray22=cJSON_Print(paramArray);
cJSON_AddItemToObject(payload, "params", paramArray);
char *payload11=cJSON_Print(payload);
kk_sendData2app(infff,payload11,0);
free(payload11);
free(infff);
free(pList);
cJSON_Delete(payload);
cJSON_Delete(info);
return res;
}
/************************************************************
*功能描述:收到云端数据后的回调处理 *功能描述:收到云端数据后的回调处理
*输入参数:type:数据类型 *输入参数:type:数据类型
data:具体数据 data:具体数据
...@@ -877,6 +940,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -877,6 +940,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON *payload,*typeJson; cJSON *payload,*typeJson;
char *payload_Str = NULL; char *payload_Str = NULL;
cJSON *deviceCode = NULL; cJSON *deviceCode = NULL;
cJSON *msgId = NULL;
json=cJSON_Parse(data); json=cJSON_Parse(data);
printf("_iotx_linkkit_event_callback\n"); printf("_iotx_linkkit_event_callback\n");
...@@ -895,6 +959,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -895,6 +959,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR); deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL) return; if(deviceCode == NULL) return;
msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
if (strstr(typeJson->valuestring,KK_REGISTER_TOPIC_REPLY)){ if (strstr(typeJson->valuestring,KK_REGISTER_TOPIC_REPLY)){
INFO_PRINT(" topic:register_reply \n"); INFO_PRINT(" topic:register_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
...@@ -937,6 +1003,20 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -937,6 +1003,20 @@ 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);
cJSON *state = cJSON_GetObjectItem(paramStr, KK_TSL_CCU_ARMINGSTATE_IDENTIFIER); cJSON *state = cJSON_GetObjectItem(paramStr, KK_TSL_CCU_ARMINGSTATE_IDENTIFIER);
if(state != NULL){ if(state != NULL){
cJSON *RoomIds = cJSON_GetObjectItem(paramStr, "RoomIds");
if(RoomIds != NULL){
kk_room_reset_armingstate();
int array_size = cJSON_GetArraySize ( RoomIds );
for( int iCnt = 0 ; iCnt < array_size ; iCnt ++ ){
cJSON * pSub = cJSON_GetArrayItem(RoomIds, iCnt);
if(NULL == pSub ){continue ; }
char roomId[16] = {0};
sprintf(roomId,"%d",pSub->valueint);
INFO_PRINT("id [%d] : %s\n",iCnt,roomId);
kk_room_update_armingstate(1,roomId);
}
}
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node); dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,NULL,state->valuestring); res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,NULL,state->valuestring);
if(res != SUCCESS_RETURN) if(res != SUCCESS_RETURN)
...@@ -1040,6 +1120,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -1040,6 +1120,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID); cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
kk_service_executeScene_handle(paramStr,msgId); kk_service_executeScene_handle(paramStr,msgId);
} }
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_GETGUARDSENSORS) == 0){
INFO_PRINT("get guardgensors \n");
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_COMMON_MSGID);
kk_service_getGuardSensors_handle(info_root,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_NEGATIVE) == 0){ else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_NEGATIVE) == 0){
INFO_PRINT("negative service \n"); INFO_PRINT("negative service \n");
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR); cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
...@@ -1066,6 +1151,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -1066,6 +1151,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_SYNCINFO) == 0){ else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_SYNCINFO) == 0){
INFO_PRINT("SYNCINFO service \n"); INFO_PRINT("SYNCINFO service \n");
dm_msg_thing_syncinfo_reply(); dm_msg_thing_syncinfo_reply();
}else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_SYNCDEVICEINFO) == 0){
INFO_PRINT("SYNCDEVICEINFO service \n");
dm_msg_thing_syncdeviceinfo_reply(msgId);
} }
else{ else{
INFO_PRINT("Error msgtype!!! \n"); INFO_PRINT("Error msgtype!!! \n");
......
...@@ -648,6 +648,51 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen ...@@ -648,6 +648,51 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************
*功能描述:更新设备注册标记
*输入参数:deviceCode:设备deviceCode
isAuth:1,已注册;0,未注册
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_subDev_getSensors_reply(SensorType_t*list)
{
char *sqlCmd = NULL;
int rc = 0;
const char *searchCmd = "select * from SubDeviceInfo WHERE productType= '%s'";
char *zErrMsg = 0;
sqlite3_stmt *stmt;
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
char *pDeviceCode = NULL;
dm_mgr_dev_node_t *node = NULL;
int currentValue = 0;
int count = 0;
//printf("kk_subDev_getSensors_reply----------------------start\n");
_kk_subDb_lock();
sqlCmd = sqlite3_mprintf(searchCmd,"sensor");
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
//printf("kk_subDev_getSensors_reply----------------------num\n");
pDeviceCode = (char*)sqlite3_column_text(stmt, DB_SUB_DEVICECODE);
rc = dm_mgr_get_device_by_devicecode(pDeviceCode,&node);
if (rc != SUCCESS_RETURN) {
ERROR_PRINT("ERROR res:%d\n",rc);
continue;
}
//printf("pDeviceCode:%s\n",pDeviceCode);
kk_property_db_get_value(pDeviceCode,"SensorType",&currentValue);
//printf("currentValue:%d\n",currentValue);
memcpy(list[count].deviceCode,pDeviceCode,strlen(pDeviceCode));
list[count].SensorType = currentValue;
count++;
}
//printf("kk_subDev_getSensors_reply----------------------end\n");
sqlite3_finalize(stmt);
_kk_subDb_unlock();
sqlite3_free(sqlCmd);
return SUCCESS_RETURN;
}
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
#define _KK_SUBDEV_DB_H_ #define _KK_SUBDEV_DB_H_
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
typedef struct {
char deviceCode[DEVICE_CODE_MAXLEN];
int SensorType;
} SensorType_t;
int kk_subDb_init(void); int kk_subDb_init(void);
int kk_subDev_insert_db(int devType,char productCode[PRODUCT_CODE_MAXLEN], \ 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); char deviceCode[DEVICE_CODE_MAXLEN],char fatherMac[DEVICE_MAC_MAXLEN],char mac[DEVICE_MAC_MAXLEN], char version[DEVICE_VERSION_MAXLEN],int heartbeat);
...@@ -18,6 +22,7 @@ int kk_subDev_send_property_get(const char *fatherDeviceCode); ...@@ -18,6 +22,7 @@ int kk_subDev_send_property_get(const char *fatherDeviceCode);
int kk_subDev_check_scene_support(const char *deviceCode); int kk_subDev_check_scene_support(const char *deviceCode);
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 kk_subDev_update_offline(int isOffline,const char *deviceCode); int kk_subDev_update_offline(int isOffline,const char *deviceCode);
int kk_subDev_getSensors_reply(SensorType_t*list);
enum{ enum{
DB_SUB_IDX = 0, DB_SUB_IDX = 0,
DB_SUB_ONLINE, DB_SUB_ONLINE,
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "kk_hal.h" #include "kk_hal.h"
extern sqlite3 *g_kk_pDb; extern sqlite3 *g_kk_pDb;
static int kk_check_multi_ep_num(char *deviceCode);
typedef struct { typedef struct {
void *mutex; void *mutex;
sqlite3 *pDb; sqlite3 *pDb;
...@@ -87,10 +89,16 @@ static cJSON * kk_get_room_devices(const char *roomId) ...@@ -87,10 +89,16 @@ static cJSON * kk_get_room_devices(const char *roomId)
cJSON *dev = cJSON_CreateObject(); cJSON *dev = cJSON_CreateObject();
char devName[64] = {0}; char devName[64] = {0};
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); epNum = (char*)sqlite3_column_text(stmt, DB_DEV_EPNUM);
cJSON_AddStringToObject(dev,KK_SYNC_DEVICECODE_STR,deviceCode); if(kk_check_multi_ep_num(deviceCode)){
cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum); cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum);
}
cJSON_AddStringToObject(dev,KK_SYNC_DEVICECODE_STR,deviceCode);
//cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum);
kk_get_device_name(deviceCode,epNum,devName,sizeof(devName)); kk_get_device_name(deviceCode,epNum,devName,sizeof(devName));
cJSON_AddStringToObject(dev,"name",devName); cJSON_AddStringToObject(dev,"name",devName);
...@@ -102,6 +110,7 @@ static cJSON * kk_get_room_devices(const char *roomId) ...@@ -102,6 +110,7 @@ static cJSON * kk_get_room_devices(const char *roomId)
return devs; return devs;
} }
static cJSON * kk_get_room_sences(const char *roomId) static cJSON * kk_get_room_sences(const char *roomId)
{ {
const char *selectCmd = "select * from SceneInfo where roomId = '%s';"; const char *selectCmd = "select * from SceneInfo where roomId = '%s';";
...@@ -263,7 +272,11 @@ static cJSON *kk_get_ccu_properties_info(cJSON *data) ...@@ -263,7 +272,11 @@ static cJSON *kk_get_ccu_properties_info(cJSON *data)
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE); valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
if(!strcmp(propertyStr,"ArmingState")){
cJSON_AddNumberToObject(property, propertyStr, atoi(valueStr));
}else{
cJSON_AddStringToObject(property, propertyStr, valueStr); cJSON_AddStringToObject(property, propertyStr, valueStr);
}
}else if(valueType == KK_TSL_DATA_TYPE_INT|| }else if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM|| valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){ valueType == KK_TSL_DATA_TYPE_BOOL){
...@@ -293,6 +306,7 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType) ...@@ -293,6 +306,7 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType)
char *propertyStr = NULL; char *propertyStr = NULL;
char *valueStr = NULL; char *valueStr = NULL;
int valueType = 0; int valueType = 0;
char *ptr = NULL;
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
if(deviceCode == NULL){ if(deviceCode == NULL){
return NULL; return NULL;
...@@ -309,24 +323,35 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType) ...@@ -309,24 +323,35 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType)
valueType = sqlite3_column_int(stmt, DB_VALUETYPE); valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE); valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertyStr, valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
cJSON_AddNumberToObject(propertyItem, propertyStr, atoi(valueStr));
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr));
}
char *propertiesbuf[64] = {0}; char *propertiesbuf[64] = {0};
int num = 0; int num = 0;
split(propertyStr,"_",propertiesbuf,&num); split(propertyStr,"_",propertiesbuf,&num);
if(num==2){ if(num==2){
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(propertyItem, "epNum",propertiesbuf[1]); cJSON_AddStringToObject(propertyItem, "epNum",propertiesbuf[1]);
if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertiesbuf[0], valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
cJSON_AddNumberToObject(propertyItem, propertiesbuf[0], atoi(valueStr));
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertiesbuf[0], atof(valueStr));
}
}else{ }else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(propertyItem, "epNum","1"); cJSON_AddStringToObject(propertyItem, "epNum","1");
if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertyStr, valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
cJSON_AddNumberToObject(propertyItem, propertyStr, atoi(valueStr));
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr));
}
} }
cJSON_AddItemToArray(eps,propertyItem); cJSON_AddItemToArray(eps,propertyItem);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
...@@ -405,16 +430,15 @@ static int kk_get_sub_devices_info(cJSON *gwdevicesItem,char *deviceCode) ...@@ -405,16 +430,15 @@ static int kk_get_sub_devices_info(cJSON *gwdevicesItem,char *deviceCode)
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_VERSION_STR, subVersion); cJSON_AddStringToObject(subdevicesItem, KK_SYNC_VERSION_STR, subVersion);
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_MAC_STR, subDeviceCode); cJSON_AddStringToObject(subdevicesItem, KK_SYNC_MAC_STR, subDeviceCode);
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_ONLINE_STR, subIsline); cJSON_AddNumberToObject(subdevicesItem, KK_SYNC_ONLINE_STR, (strcmp(subIsline,"0")==0)?1:0);
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_PRODUCTCODE_STR, subProductCode); cJSON_AddStringToObject(subdevicesItem, KK_SYNC_PRODUCTCODE_STR, subProductCode);
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_SN_STR, ""); cJSON_AddStringToObject(subdevicesItem, KK_SYNC_SN_STR, "");
cJSON_AddStringToObject(subdevicesItem, KK_SYNC_STATUS_STR, "启动"); cJSON_AddNumberToObject(subdevicesItem, KK_SYNC_STATUS_STR, 1);
if(kk_check_multi_ep_num(subDeviceCode)){ if(kk_check_multi_ep_num(subDeviceCode)){
printf("[%s][%d]--->$1\n",__FUNCTION__,__LINE__);
properties=kk_get_properties_info(subDeviceCode,KK_DM_DEVICE_SUBDEV); properties=kk_get_properties_info(subDeviceCode,KK_DM_DEVICE_SUBDEV);
}else{ }else{
printf("[%s][%d]--->$2\n",__FUNCTION__,__LINE__);
properties=kk_get_properties_info_obj(subDeviceCode); properties=kk_get_properties_info_obj(subDeviceCode);
} }
...@@ -461,10 +485,10 @@ static int kk_get_gw_devices_info(cJSON *gwdevices) ...@@ -461,10 +485,10 @@ static int kk_get_gw_devices_info(cJSON *gwdevices)
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_VERSION_STR, gw_version); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_VERSION_STR, gw_version);
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_MAC_STR, gw_deviceCode); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_MAC_STR, gw_deviceCode);
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_NANE_STR, "GW"); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_NANE_STR, "GW");
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_ONLINE_STR, gw_isline); cJSON_AddNumberToObject(gwdevicesItem, KK_SYNC_ONLINE_STR, (strcmp(gw_isline,"0")==0)?1:0);
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_PRODUCTCODE_STR, gw_productCode); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_PRODUCTCODE_STR, gw_productCode);
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_SN_STR, ""); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_SN_STR, "");
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_STATUS_STR, "启动"); cJSON_AddNumberToObject(gwdevicesItem, KK_SYNC_STATUS_STR, 1);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_gw_properties_info(gwdevicesItem); kk_get_gw_properties_info(gwdevicesItem);
...@@ -557,7 +581,17 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,int id) ...@@ -557,7 +581,17 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,int id)
cJSON_AddStringToObject(actionItem, KK_SYNC_DEVICECODE_STR, deviceCode); cJSON_AddStringToObject(actionItem, KK_SYNC_DEVICECODE_STR, deviceCode);
cJSON_AddNumberToObject(actionItem, KK_SYNC_SCENE_DELAY_STR, delay); cJSON_AddNumberToObject(actionItem, KK_SYNC_SCENE_DELAY_STR, delay);
cJSON_AddNumberToObject(actionItem, KK_SYNC_SCENE_EPNUM_STR, epNum); cJSON_AddNumberToObject(actionItem, KK_SYNC_SCENE_EPNUM_STR, epNum);
char *propertiesbuf[64] = {0};
int num = 0;
split(propertyName,"_",propertiesbuf,&num);
if(num==2){
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYNAME_STR, propertiesbuf[0]);
}else{
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYNAME_STR, propertyName); cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYNAME_STR, propertyName);
}
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_TYPE_STR, type); cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_TYPE_STR, type);
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, propertyValue); cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, propertyValue);
cJSON_AddStringToObject(actionItem, KK_SYNC_ROOMID_STR, room_name); cJSON_AddStringToObject(actionItem, KK_SYNC_ROOMID_STR, room_name);
...@@ -587,7 +621,7 @@ static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId) ...@@ -587,7 +621,7 @@ static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId)
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_CreateArray(); cJSON *triggerItem = cJSON_CreateObject();
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);
...@@ -609,6 +643,10 @@ static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId) ...@@ -609,6 +643,10 @@ static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId)
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId) static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId)
{ {
char *sqlCmd = NULL; char *sqlCmd = NULL;
...@@ -619,6 +657,9 @@ static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId) ...@@ -619,6 +657,9 @@ static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId)
int crossDay = 0; int crossDay = 0;
int repeat = 0; int repeat = 0;
int week;
int time;
cJSON *conditionAry; cJSON *conditionAry;
kk_sync_ctx_t *ctx = _kk_sync_get_ctx(); kk_sync_ctx_t *ctx = _kk_sync_get_ctx();
...@@ -640,6 +681,21 @@ static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId) ...@@ -640,6 +681,21 @@ static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId)
cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_REPEATDAY_STR, repeat); cJSON_AddNumberToObject(conditionItem, KK_SYNC_SCENE_REPEATDAY_STR, repeat);
cJSON_AddItemToArray(conditionAry, conditionItem); cJSON_AddItemToArray(conditionAry, conditionItem);
} }
sqlCmd = sqlite3_mprintf("select * from SceneTimerInfo where sceneId = %s",sceneId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
cJSON *conditionItem = cJSON_CreateObject();
week = sqlite3_column_int(stmt, DB_SCENETIMER_WEEK);
time = sqlite3_column_int(stmt, DB_SCENETIMER_TIME);
cJSON_AddNumberToObject(conditionItem, "week", week);
cJSON_AddNumberToObject(conditionItem, "time", time);
cJSON_AddItemToArray(conditionAry, conditionItem);
}
cJSON_AddItemToObject(conditionObj, "items",conditionAry); cJSON_AddItemToObject(conditionObj, "items",conditionAry);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
...@@ -665,9 +721,9 @@ static int kk_get_scenes_info(cJSON *data) ...@@ -665,9 +721,9 @@ static int kk_get_scenes_info(cJSON *data)
cJSON *sceneArrayItem = cJSON_CreateObject(); cJSON *sceneArrayItem = cJSON_CreateObject();
enable = sqlite3_column_int(stmt, DB_SCENEINFO_ENABLE); enable = sqlite3_column_int(stmt, DB_SCENEINFO_ENABLE);
if(enable == 1){ if(enable == 1){
cJSON_AddStringToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, "启动"); cJSON_AddNumberToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, 1);
}else{ }else{
cJSON_AddStringToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, "禁用"); cJSON_AddNumberToObject(sceneArrayItem, KK_SYNC_SCENE_ENABLE_STR, 0);
} }
type = sqlite3_column_int(stmt, DB_SCENEINFO_SCENETYPE); type = sqlite3_column_int(stmt, DB_SCENEINFO_SCENETYPE);
...@@ -742,10 +798,9 @@ char *kk_sync_get_info() ...@@ -742,10 +798,9 @@ char *kk_sync_get_info()
char ccu_productCode[PRODUCT_CODE_MAXLEN] = {0}; char ccu_productCode[PRODUCT_CODE_MAXLEN] = {0};
char version[32] = {0}; char version[32] = {0};
char cloudstatus_str[16] = {0}; char cloudstatus_str[16] = {0};
cJSON *root=cJSON_CreateObject();
cJSON_AddStringToObject(root,KK_SYNC_CODE_STR,"0");
cJSON *data = cJSON_CreateObject(); cJSON *data = cJSON_CreateObject();
cJSON_AddItemToObject(root, KK_SYNC_DATA_STR, data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_rooms_info(data); kk_get_rooms_info(data);
...@@ -754,7 +809,8 @@ char *kk_sync_get_info() ...@@ -754,7 +809,8 @@ char *kk_sync_get_info()
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_scenes_info(data); kk_get_scenes_info(data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
HAL_GetDevice_Code(ccu_deviceCode); //HAL_GetDevice_Code(ccu_deviceCode);
HAL_Get_ccuid(ccu_deviceCode);
HAL_GetProduct_Code(ccu_productCode); HAL_GetProduct_Code(ccu_productCode);
HAL_GetVersion(version); HAL_GetVersion(version);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
...@@ -769,10 +825,9 @@ char *kk_sync_get_info() ...@@ -769,10 +825,9 @@ char *kk_sync_get_info()
kk_get_ccu_properties_info(data); kk_get_ccu_properties_info(data);
out=cJSON_Print(data);
out=cJSON_Print(root);
printf("kk_sync_get_info:%s\n",out); printf("kk_sync_get_info:%s\n",out);
cJSON_Delete(root); cJSON_Delete(data);
//free(out); //free(out);
return out; return out;
} }
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#define KK_SYNC_SCENE_ACTIONS_STR "actions" #define KK_SYNC_SCENE_ACTIONS_STR "actions"
#define KK_SYNC_SCENE_ENABLE_STR "enable" #define KK_SYNC_SCENE_ENABLE_STR "enable"
#define KK_SYNC_SCENE_SCENETYPE_STR "sceneType" #define KK_SYNC_SCENE_SCENETYPE_STR "sceneType"
#define KK_SYNC_SCENE_TRIGGER_STR "trigger" #define KK_SYNC_SCENE_TRIGGER_STR "triggers"
#define KK_SYNC_SCENE_ITEMS_STR "items" #define KK_SYNC_SCENE_ITEMS_STR "items"
#define KK_SYNC_SCENE_CONDITION_STR "condition" #define KK_SYNC_SCENE_CONDITION_STR "conditions"
#define KK_SYNC_SCENE_COMPARETYPE_STR "compareType" #define KK_SYNC_SCENE_COMPARETYPE_STR "compareType"
#define KK_SYNC_SCENE_COMPAREValue_STR "compareValue" #define KK_SYNC_SCENE_COMPAREValue_STR "compareValue"
#define KK_SYNC_SCENE_STARTTIME_STR "startTime" #define KK_SYNC_SCENE_STARTTIME_STR "startTime"
......
...@@ -200,6 +200,7 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -200,6 +200,7 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
int value = 0; int value = 0;
char *propertiesbuf[64] = {0}; char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0}; char propertiesTmp[64] = {0};
res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node); res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res); ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
...@@ -207,6 +208,22 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -207,6 +208,22 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
} }
params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR); params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(params != NULL){ if(params != NULL){
//传感器安防等级设置
if(strcmp(node->productType ,"sensor") == 0){
cJSON* sensorType = cJSON_GetObjectItem(params, "SensorType");
if(sensorType != NULL){
int level = sensorType->valueint;
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,"SensorType",&level,NULL);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT(" error res:%d\n",res);
}
char tmpValue[16] = {0};
sprintf(tmpValue,"%d",level);
kk_property_db_update_value(deviceCode,"SensorType",tmpValue);
return SUCCESS_RETURN;
}
}
epNum = cJSON_GetObjectItem(params, "epNum"); epNum = cJSON_GetObjectItem(params, "epNum");
if(epNum != NULL){ if(epNum != NULL){
epNumInt = atoi(epNum->valuestring); epNumInt = atoi(epNum->valuestring);
...@@ -497,6 +514,73 @@ void gw2mid_cb(void* data, int len, char* chalMark){ ...@@ -497,6 +514,73 @@ void gw2mid_cb(void* data, int len, char* chalMark){
*返 回 值: 无 *返 回 值: 无
*其他说明: *其他说明:
*************************************************************/ *************************************************************/
static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier)
{
int currentValue = 0;
char armingstate[16] = {0};
int ret = 0;
if(node == NULL || identifier == NULL){
return -1;
}
kk_property_db_get_value(node->deviceCode,"SensorType",&currentValue);
kk_property_db_get_value(s_ccuid,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,armingstate);
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/alarmNotify");
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, node->deviceCode);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, node->productCode);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "method", "thing.event.alarmNotify");
cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "identifier", "alarmNotify");
cJSON_AddStringToObject(payload, "msgId", "1");
//char timerStr[16] = {0};
//HAL_GetTime_s(timerStr);
cJSON_AddNumberToObject(payload, "time", time(NULL));
cJSON *param = cJSON_CreateObject();
if(strcmp(identifier,"BatteryAlarm") == 0){
cJSON_AddStringToObject(param, "LowBatteryState", "1");
}else{
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
}
cJSON_AddItemToObject(payload, "params", param);
char *payload11=cJSON_Print(payload);
if(currentValue == 2)//24小时警戒
{
kk_sendData2app(infff,payload11,0);
}
else if(currentValue == 1 && atoi(armingstate) == 0) //离家布防
{
kk_sendData2app(infff,payload11,0);
}
else if(currentValue == 0 && atoi(armingstate) == 2) //在家布防
{
kk_sendData2app(infff,payload11,0);
}
else if(atoi(armingstate) == 3 && currentValue == 0 )
{
char roomId[16] = {0};
ret = kk_get_roomId_by_deviceCode(node->deviceCode,"1",roomId,sizeof(roomId));
INFO_PRINT("roomId: [%s] \n",roomId);
if(ret == 1){
int state = kk_get_room_armingstate(roomId);
INFO_PRINT("state: [%d] \n",state);
if(state){
kk_sendData2app(infff,payload11,0);
}
}
}
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
void kk_platMsg_handle(void* data, char* chalMark){ void kk_platMsg_handle(void* data, char* chalMark){
int res = 0; int res = 0;
cJSON *json; cJSON *json;
...@@ -537,7 +621,10 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -537,7 +621,10 @@ void kk_platMsg_handle(void* data, char* chalMark){
if(jsonPay == NULL) goto error; if(jsonPay == NULL) goto error;
proCode = cJSON_GetObjectItem(jsonPay, MSG_PRODUCT_CODE_STR); proCode = cJSON_GetObjectItem(jsonPay, MSG_PRODUCT_CODE_STR);
devCode = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR); devCode = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
mac = cJSON_GetObjectItem(jsonPay, "mac"); //mac = cJSON_GetObjectItem(jsonPay, "mac");
mac = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
if (proCode == NULL || devCode == NULL || mac == NULL){ if (proCode == NULL || devCode == NULL || mac == NULL){
ERROR_PRINT("productCode, deviceCode mac params are error\n"); ERROR_PRINT("productCode, deviceCode mac params are error\n");
goto error; goto error;
...@@ -641,39 +728,6 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -641,39 +728,6 @@ void kk_platMsg_handle(void* data, char* chalMark){
for(index = 0; index < eventItem->output_data_number;index++){ for(index = 0; index < eventItem->output_data_number;index++){
itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier); itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier);
itemData = eventItem->output_datas + index; itemData = eventItem->output_datas + index;
#if 0
if(itemStr != NULL){
memset(tmpStr,0x0,sizeof(tmpStr));
sprintf(tmpStr,"%s.%s",eventItem->identifier,itemData->identifier);
if(itemData->data_value.type == KK_TSL_DATA_TYPE_INT||
itemData->data_value.type == KK_TSL_DATA_TYPE_ENUM||
itemData->data_value.type == KK_TSL_DATA_TYPE_BOOL){
sprintf(valueBuf,"%d",itemStr->valueint);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,tmpStr,&itemStr->valueint,NULL);
}
else if(itemData->data_value.type == KK_TSL_DATA_TYPE_FLOAT ||
itemData->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(valueBuf,"%f",itemStr->valuedouble);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,tmpStr,&itemStr->valuedouble,NULL);
}
else if(itemData->data_value.type == KK_TSL_DATA_TYPE_TEXT ||
itemData->data_value.type == KK_TSL_DATA_TYPE_DATE){
sprintf(valueBuf,"%s",itemStr->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,tmpStr,NULL,itemStr->valuestring);
}
INFO_PRINT("kk_platMsg_handle data: event post\n");
if(sensorDev){
kk_history_insert_sensor_info(info_dcode->valuestring,eventItem->identifier,valueBuf,HAL_GetTime());
}
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier);
kk_scene_iftt_check(info_dcode->valuestring,jsonPay);
}
else
#endif
cJSON * itemDataIdentifier = cJSON_GetObjectItem(jsonPay, itemData->identifier); cJSON * itemDataIdentifier = cJSON_GetObjectItem(jsonPay, itemData->identifier);
if(itemDataIdentifier != NULL){ if(itemDataIdentifier != NULL){
memset(tmpStr,0x0,sizeof(tmpStr)); memset(tmpStr,0x0,sizeof(tmpStr));
...@@ -697,6 +751,7 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -697,6 +751,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
} }
if(sensorDev){ if(sensorDev){
kk_history_insert_sensor_info(info_dcode->valuestring,eventItem->identifier,valueBuf,HAL_GetTime()); kk_history_insert_sensor_info(info_dcode->valuestring,eventItem->identifier,valueBuf,HAL_GetTime());
kk_alarm_notify_handle(node,eventItem->identifier);//告警信息处理
} }
INFO_PRINT("kk_platMsg_handle data: event post\n"); INFO_PRINT("kk_platMsg_handle data: event post\n");
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL); dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
......
...@@ -222,7 +222,7 @@ else ...@@ -222,7 +222,7 @@ else
cp -rf $(TOP_DIR)/common/ev/libev.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/ev/libev.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib
endif endif
cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/build/exe/Z3GatewayHost $(TOP_DIR)/$(releaseDir)/ #cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/build/exe/Z3GatewayHost $(TOP_DIR)/$(releaseDir)/
fromdos $(releaseDir)/*.sh fromdos $(releaseDir)/*.sh
echo $(PWD) echo $(PWD)
......
...@@ -104,13 +104,13 @@ done ...@@ -104,13 +104,13 @@ done
\$(Q)mkdir -p \$\$(dirname \$@) \$(Q)mkdir -p \$\$(dirname \$@)
\$(Q)S=\$\$(echo \$@|sed 's,${OUTPUT_DIR},${TOP_DIR},1'); \\ \$(Q)S=\$\$(echo \$@|sed 's,${OUTPUT_DIR},${TOP_DIR},1'); \\
if echo \$\${S//.o/.c} | grep -q 'mbedtls\|HAL_\|hal-impl'; then \\ if echo \$\${S//.o/.c} | grep -q 'mbedtls\|HAL_\|hal-impl'; then \\
${CC} -c -fPIC\\ ${CC} -std=c99 -c -fPIC\\
-o \$@ \\ -o \$@ \\
\$(filter-out -ansi,\$(CFLAGS)) \\ \$(filter-out -ansi,\$(CFLAGS)) \\
\$(IFLAGS) \\ \$(IFLAGS) \\
\$\${S//.o/.c}; \\ \$\${S//.o/.c}; \\
else \\ else \\
${CC} -c -fPIC\\ ${CC} -std=c99 -c -fPIC\\
-o \$@ \\ -o \$@ \\
\$(CFLAGS) \\ \$(CFLAGS) \\
\$(IFLAGS) \\ \$(IFLAGS) \\
...@@ -181,7 +181,7 @@ done) ...@@ -181,7 +181,7 @@ done)
\$(Q)mkdir -p \$\$(dirname \$@) \$(Q)mkdir -p \$\$(dirname \$@)
\$(Q)\$(call Brief_Log,"SO",\$\$(basename \$@),"...") \$(Q)\$(call Brief_Log,"SO",\$\$(basename \$@),"...")
\$(Q)${CC} -fPIC -shared \$^ -o \$@ \$(Q)${CC} -std=c99 -fPIC -shared \$^ -o \$@
EOB EOB
done done
......
...@@ -11,7 +11,7 @@ CONFIG_LIB_EXPORT ?= static ...@@ -11,7 +11,7 @@ CONFIG_LIB_EXPORT ?= static
# Default CFLAGS setting # Default CFLAGS setting
# #
CFLAGS += -ansi CFLAGS += -ansi
CFLAGS += -Wdeclaration-after-statement CFLAGS += -Wno-unused-result
CFLAGS += -DFORCE_SSL_VERIFY CFLAGS += -DFORCE_SSL_VERIFY
# Default INCLUDE list # Default INCLUDE list
......
...@@ -63,6 +63,21 @@ ...@@ -63,6 +63,21 @@
} }
} }
}, },
{
"identifier": "SensorType",
"name": "安防等级",
"accessMode": "rw",
"required": true,
"dataType": {
"type": "enum",
"specs": {
"0": "在家安防",
"1": "室外安防",
"2": "24小时警戒",
"3": "无警戒"
}
}
},
{ {
"identifier": "Battery", "identifier": "Battery",
"name": "电池电量", "name": "电池电量",
......
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