Commit 652f80d7 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】1,增加告警处理;2,增加虚拟灯的多控逻辑

See merge request chenweican/k-sdk!199
parents d509ae71 f0d7f555
1.4.4
\ No newline at end of file
1.4.5
\ No newline at end of file
......@@ -209,7 +209,47 @@ static int kk_loginccu_ack(cJSON *arg,int sockfd)
}
return 0;
}
static int kk_loginccu_ack_accesskey(cJSON *arg,int sockfd)
{
cJSON *deviceId;
cJSON *accesskey;
cJSON *root;
cJSON *args;
char *out = NULL;
char *tmpBuf = NULL;
if(arg == NULL){
return -1;
}
char ccuid[32] = {0};
char key[128] = {0};
kk_lan_get_ccuid(ccuid);
kk_lan_get_key(key);
deviceId = cJSON_GetObjectItem(arg, DEVICEID_STRING);
accesskey = cJSON_GetObjectItem(arg, ACCESSKEY);
if(deviceId != NULL && accesskey != NULL){
if(strstr(ccuid,deviceId->valuestring) != NULL && strcmp(key,accesskey->valuestring) == 0){
root=cJSON_CreateObject();
if(root){
args = cJSON_CreateObject();
if(args){
cJSON_AddItemToObject(root, "arg", args);
cJSON_AddStringToObject(args, "error_code", "0");
cJSON_AddStringToObject(args, "seq", "2");
//cJSON_AddStringToObject(args, "zkid", deviceId->valuestring);
}
cJSON_AddStringToObject(root, "nodeid", "*");
cJSON_AddStringToObject(root, "opcode", LOGIN_OPCODE);
cJSON_AddStringToObject(root, "status", "success");
kk_send_ack(root,sockfd);
}
cJSON_Delete(root);
}
}else{
ERROR_PRINT("data error...\n");
return -1;
}
return 0;
}
//构建hw信息
static cJSON *kk_zb_dev_hw_info_build(const char *deviceCode,const char *productCode,int online,const char *hw_ver,const char *sw_ver)
{
......@@ -372,6 +412,9 @@ int kk_data_handle(cJSON *json,int sockfd)
if(strcmp(opcode->valuestring,LOGIN_OPCODE) == 0){
arg = cJSON_GetObjectItem(json, ARG_STRING);
kk_loginccu_ack(arg,sockfd);
}else if(strcmp(opcode->valuestring,LOGIN_ACCESSKEY_OPCODE) == 0){
arg = cJSON_GetObjectItem(json, ARG_STRING);
kk_loginccu_ack_accesskey(arg,sockfd);
}else if(strcmp(opcode->valuestring,HEARTBEAT_OPCODE) == 0){
kk_heartbeat_ack(sockfd);
}else if(strcmp(opcode->valuestring,SYNC_OPCODE) == 0){
......
......@@ -18,4 +18,5 @@
int kk_lan_get_ccuid(_OU_ char *device_code);
int kk_findccu_handle_init(void);
int kk_lan_get_pid(_OU_ char *productId);
int kk_lan_get_key(char *key);
#endif
\ No newline at end of file
......@@ -51,6 +51,53 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
strncpy(s_ccuid, device_code, len);
return len;
}
char s_key[128] = {0};
static int kk_lan_key_init(void)
{
char key[128] = {0};
int key_len = 0;
#ifdef CONFIG_A133_PLATFORM
char *pstart = NULL;
char *pEnd = NULL;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)key,sizeof(key),&key_len);
INFO_PRINT("---productSecret:%s\n",key);
if(key_len > 0 && key_len <= 128){
pstart = key;
pEnd = strstr(key,"key_");
if(pEnd != NULL){
memcpy(s_key,pEnd+4,key_len-(pEnd-pstart+4));
if (s_key[key_len-(pEnd-pstart+4) -1] == '\n'){
s_key[key_len-(pEnd-pstart+4) -1] = '\0';
INFO_PRINT("kk_cloud_key_init remove entry\n");
}
INFO_PRINT("kk_cloud_key_init s_key:%s\n",s_key);
}else{
//_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
INFO_PRINT("kk_cloud_key_init error\n");
return -1;
}
}else{
//_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
INFO_PRINT("kk_cloud_key_init error\n");
return -1;
}
#else
HAL_Execel_cmd(GET_KEY_CMD,(char *)key,sizeof(key),&key_len);
if(key_len > 0 && key_len <= 128){
memcpy(s_key,key,key_len-1);
INFO_PRINT("s_key:%s\n",s_key);
}else{
return -1;
}
#endif
return 0;
}
int kk_lan_get_key(char *key)
{
strncpy(key, s_key, strlen(s_key));
printf("kk_lan_get_key:%s\n",s_key);
return strlen(s_key);
}
char s_pid[PRODUCT_CODE_LEN] = {0};
static int kk_lan_pid_init(void)
{
......@@ -211,7 +258,7 @@ int main(int argc, char* argv[])
#endif
kk_lan_pid_init();
kk_lan_ccuid_init();
kk_lan_key_init();
/*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromMid,NULL,NULL);
kk_findccu_handle_init();
......
......@@ -19,12 +19,15 @@
#define OPCODE_STRING "opcode"
#define ARG_STRING "arg"
#define ZKID_STRING "zkid"
#define DEVICEID_STRING "device_id"
#define OPEARTETYPE_STRING "operateType"
#define NEWCCU_STRING "newccu"
#define OLDCCU_STRING "oldccu"
#define ACCESSKEY "access_key"
#define FINDCCU_OPCODE "FIND_CCU"
#define LOGIN_OPCODE "LOGIN"
#define LOGIN_ACCESSKEY_OPCODE "LOGIN_ACCESSKEY"
#define HEARTBEAT_OPCODE "CCU_HB"
#define SYNC_OPCODE "SYNC_INFO"
#define GET_ZB_DEVS_HW_INFO_OPCODE "GET_ZIGBEE_DEVS_HW_INFO"
......
......@@ -870,30 +870,6 @@ cJSON *kk_get_roomIds_ary(void)
_kk_area_unlock();
return roomIdsAry;
}
cJSON *kk_get_roomIds_ary_by_floorid(char *floorid)
{
int isExist = 0;
sqlite3_stmt *stmt;
char *proomId = NULL;
int armingstate= 0;
cJSON *roomIdsAry = cJSON_CreateArray();
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaInfo whre;";
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
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);
cJSON_AddItemToArray(roomIdsAry,cJSON_CreateNumber(atoi(proomId)));
}
}
sqlite3_finalize(stmt);
return roomIdsAry;
}
kk_dev_list_t* kk_get_room_deviceCode(const char* roomId)
{
......
#include "cJSON.h"
#include "kk_product.h"
#include "kk_tsl_common.h"
#include "kk_tsl_api.h"
#include "kk_dm_api.h"
#include "kk_dm_msg.h"
#include "kk_dm_mng.h"
#include "kk_alarm_handle.h"
#include "kk_property_db.h"
#include "kk_history_db.h"
#include "kk_area_handle.h"
enum{
CCU_ARMING_LEAVE_STATE = 0, //离家布防
CCU_ARMING_NO_STATE, //撤防
CCU_ARMING_HOME_STATE, //在家布防
CCU_ARMING_AREA_STATE, //区域布防
};
enum{
SUB_ARMING_HOME_STATE = 0, //在家安防
SUB_ARMING_OUTHOME_STATE, //室外安防
SUB_ARMING_ALL_STATE, //24小时警戒
SUB_ARMING_NO_STATE, //无警戒
};
extern int HAL_Get_ccuid(_OU_ char *device_code);
char *CommonAlarmStateDevice[] =
{
(char *){"SmokeSensorState"},
(char *){"GasSensorState"},
(char *){"WaterSensorState"},
(char *){"SosState"},
(char *){"AlarmState"},
};
int kk_is_CommonAlarmState(char * identifier)
{
int cnt = 0;
int num = sizeof(CommonAlarmStateDevice)/sizeof(char *);
for(cnt = 0; cnt < num; cnt++){
if(strcmp(identifier,CommonAlarmStateDevice[cnt]) == 0){
return 1;
}
}
return 0;
}
/************************************************************
*功能描述:告警消息处理
*输入参数:data:从gw 层发来的数据
chalMark:网关通道,一般用mac
*输出参数:无
*返 回 值: 无
*其他说明:
安防等级:
0: 在家安防
1: 室外安防
2: 24小时警戒
3: 无警戒
主机安防:
0:离家布防
1:撤防
2:在家布防
3:区域布防
*************************************************************/
int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueBuf)
{
char ccuid[32] = {0};
int currentValue = 0;
char armingstate[16] = {0};
int ret = 0;
int needSave = 0;
if(node == NULL || identifier == NULL){
return -1;
}
HAL_Get_ccuid(ccuid);
kk_property_db_get_value(node->deviceCode,"SensorType",&currentValue);
INFO_PRINT("------------------------->currentValue:%d\n",currentValue);
INFO_PRINT("------------------------->armingstate:%d\n",atoi(armingstate));
INFO_PRINT("------------------------->valueBuf:%s\n",valueBuf);
INFO_PRINT("------------------------->identifier:%s\n",identifier);
kk_property_db_get_value(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");
char msgId[64] = {0};
iotx_report_id(msgId);
cJSON_AddStringToObject(payload, "msgId", msgId);
//char timerStr[16] = {0};
//HAL_GetTime_s(timerStr);
cJSON_AddNumberToObject(payload, "time", HAL_GetTime_ms());
cJSON *param = cJSON_CreateObject();
if(strcmp(identifier,"BatteryAlarm") == 0){
cJSON_AddStringToObject(param, "LowBatteryState", "1");
//needSave = 1;
}else if(strcmp(identifier,"DismantleState") == 0){
if(atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "DismantleState", valueBuf);
}else{
cJSON_Delete(param);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
//needSave = 1;
}//else if(kk_is_CommonAlarmState(identifier) == 1){
//cJSON_AddStringToObject(param, "CommonAlarmState", valueBuf);
// }
else{
if(atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
}else{
cJSON_Delete(param);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
//needSave = 1;
}
cJSON_AddItemToObject(payload, "params", param);
char *payload11=cJSON_Print(payload);
if(currentValue == SUB_ARMING_ALL_STATE)//24小时警戒
{
INFO_PRINT("payload11: %s\n",payload11);
kk_sendData2app(infff,payload11,0);
goto end;
}
else if(currentValue != SUB_ARMING_NO_STATE && atoi(armingstate) == CCU_ARMING_LEAVE_STATE) //离家布防
{
INFO_PRINT("payload11: %s\n",payload11);
kk_sendData2app(infff,payload11,0);
}
else if((currentValue == SUB_ARMING_OUTHOME_STATE||currentValue == SUB_ARMING_ALL_STATE) && atoi(armingstate) == CCU_ARMING_HOME_STATE) //在家布防
{
INFO_PRINT("payload11: %s\n",payload11);
kk_sendData2app(infff,payload11,0);
}
else if(atoi(armingstate) == CCU_ARMING_AREA_STATE)
{
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 == 1){
if(currentValue != SUB_ARMING_NO_STATE){
INFO_PRINT("payload11: %s\n",payload11);
kk_sendData2app(infff,payload11,0);
}
}else{
if(currentValue == SUB_ARMING_OUTHOME_STATE||currentValue == SUB_ARMING_ALL_STATE){
INFO_PRINT("payload11: %s\n",payload11);
kk_sendData2app(infff,payload11,0);
}
}
}
}
end:
needSave = 0;
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
\ No newline at end of file
#ifndef _KK_ALARM_NOTIFY_H_
#define _KK_ALARM_NOTIFY_H_
#include "kk_hal.h"
#include "kk_log.h"
int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueBuf);
#endif
\ No newline at end of file
......@@ -1905,4 +1905,27 @@ cJSON *dm_mgr_get_ccu_info(void)
return root;
}
int kk_is_mutiEp_device(const char *deviceCode)
{
int res = 0;
int idx = 0;
kk_tsl_data_t *property = NULL;
dm_mgr_dev_node_t *node = NULL;
res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node);
if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
if(strstr(property->identifier,"_") != NULL){
return 1;
}else{
return 0;
}
}
return 0;
}
......@@ -129,5 +129,5 @@ void dm_mgr_resubscribe(void);
int kk_get_pid(char *productId);
int dm_mgr_ccu_heartbeat_cloud(_IN_ int devid);
cJSON *dm_mgr_get_ccu_info(void);
int kk_is_mutiEp_device(const char *deviceCode);
#endif
......@@ -2171,7 +2171,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON * pSub = cJSON_GetArrayItem(RoomIds, iCnt);
if(NULL == pSub ){continue ; }
char roomId[16] = {0};
sprintf(roomId,"%d",pSub->valueint);
if(pSub->type == cJSON_String){
strcpy(roomId,pSub->valuestring);
}else{
sprintf(roomId,"%d",pSub->valueint);
}
INFO_PRINT("id [%d] : %s\n",iCnt,roomId);
kk_room_update_armingstate(1,roomId);
}
......@@ -2665,6 +2669,7 @@ int _iotx_linkkit_slave_register(int devid)
return SUCCESS_RETURN;
}
#if 0
/************************************************************
*功能描述:子设备删除处理,
*输入参数:devid:设备ID
......@@ -2729,6 +2734,7 @@ static int _iotx_linkkit_subdev_delete_topo(int devid)
return SUCCESS_RETURN;
}
#endif
/************************************************************
*功能描述:主模块释放处理
*输入参数:无
......
......@@ -1011,7 +1011,7 @@ int kk_property_db_get_value_directly(const char *deviceCode,const char *identif
//int rc = 0;
//char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
char *valueStr = "";
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
......
......@@ -812,9 +812,10 @@ static int _kk_indoor_air_info_handle(char* deviceCode,char* propertyName,char*
}
return res;
}
int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum)
int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum,int mutiDev)
{
char data[32] = {0};
cJSON* json = cJSON_Parse(propertyValue);
if (json == NULL) {
return -1;
......@@ -827,8 +828,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}else{
sprintf(data,"%f",Temperature->valuedouble);
}
if(mutiDev){
_kk_indoor_air_info_handle(deviceCode,"Temperature_1",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}else{
_kk_indoor_air_info_handle(deviceCode,"Temperature",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}
_kk_indoor_air_info_handle(deviceCode,"Temperature",data,epnum,delay,gwDeviceCode,sceneId,type,0);
cJSON* WindSpeed = cJSON_GetObjectItem(json, "WindSpeed");
if(WindSpeed == NULL) { cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
......@@ -837,8 +842,13 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}else{
sprintf(data,"%d",WindSpeed->valueint);
}
_kk_indoor_air_info_handle(deviceCode,"WindSpeed",data,epnum,delay,gwDeviceCode,sceneId,type,0);
if(mutiDev){
_kk_indoor_air_info_handle(deviceCode,"WindSpeed_1",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}else{
_kk_indoor_air_info_handle(deviceCode,"WindSpeed",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}
cJSON* WorkMode = cJSON_GetObjectItem(json, "WorkMode");
if(WorkMode == NULL){ cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
......@@ -847,8 +857,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}else{
sprintf(data,"%d",WorkMode->valueint);
}
_kk_indoor_air_info_handle(deviceCode,"WorkMode",data,epnum,delay,gwDeviceCode,sceneId,type,0);
if(mutiDev){
_kk_indoor_air_info_handle(deviceCode,"WorkMode_1",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}else{
_kk_indoor_air_info_handle(deviceCode,"WorkMode",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}
cJSON_Delete(json);
return 0;
}
......@@ -876,7 +890,7 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
}
}
if(strcmp(propertyName,"CustomAction") == 0){
kk_indoor_air_action_add(propertyValue,deviceCode,delay,gwDeviceCode,sceneId,type,eplist[i]);
kk_indoor_air_action_add(propertyValue,deviceCode,delay,gwDeviceCode,sceneId,type,eplist[i],0);
kk_scene_insert_scene_action(type,deviceCode,eplist[i],
propertyName,propertyValue,delay,sceneId,gwDeviceCode,2);
}else{
......@@ -885,9 +899,10 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
}
return 0;
}
static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propertyName, char *propertyValue, char *type,int delay, char*gwDeviceCode,char *roomId)
static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propertyName, char *propertyValue, char *type,int delay, char*gwDeviceCode,char *roomId,char*productCode)
{
int res = 0;
int mutiDev = 0;
int allRoom = (strcmp(roomId,"-1")==0)?1:0;
if(allRoom == 1){
if(kk_check_dev_exist_inRoom(deviceCode,"1") == 0){
......@@ -900,15 +915,30 @@ static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propert
return -1;;
}
}
if(strcmp(productCode,"3095") == 0 || strcmp(productCode,"3098") == 0){//空调多合一 或者 风机盘管多合一
mutiDev = 1;
}
if(strcmp(propertyName,"CustomAction") == 0){
kk_indoor_air_action_add(propertyValue,deviceCode,delay,gwDeviceCode,sceneId,type,1);
kk_indoor_air_action_add(propertyValue,deviceCode,delay,gwDeviceCode,sceneId,type,1,mutiDev);
kk_scene_insert_scene_action(type,deviceCode,1,
propertyName,propertyValue,delay,sceneId,gwDeviceCode,2);
}else{
_kk_indoor_air_info_handle(deviceCode,propertyName,propertyValue,1,delay,gwDeviceCode,sceneId,type,1);
if(mutiDev){
char propertyNameBuf[64] = {0};
sprintf(propertyNameBuf,"%s_%d",propertyName,1);
_kk_indoor_air_info_handle(deviceCode,propertyNameBuf,propertyValue,1,delay,gwDeviceCode,sceneId,type,1);
//res = kk_scene_insert_scene_action(type,deviceCode,1,
//propertyName,propertyValue,delay,sceneId,gwDeviceCode,2);
//if(res != SUCCESS_RETURN){
//INFO_PRINT("_kk_airConditon_handle fail!!!\n");
//}
}else{
_kk_indoor_air_info_handle(deviceCode,propertyName,propertyValue,1,delay,gwDeviceCode,sceneId,type,1);
}
}
return 0;
return res;
}
static int _kk_air_switch_handle(char* deviceCode, char *sceneId, char *propertyName, char *propertyValue, char *type,int delay, char*gwDeviceCode)
{
......@@ -943,7 +973,7 @@ static int _kk_air_switch_handle(char* deviceCode, char *sceneId, char *property
cJSON_Delete(json);
#endif
}else{
//_kk_indoor_air_info_handle(deviceCode,propertyName,propertyValue,eplist[i],delay,gwDeviceCode,sceneId,type,1);
_kk_indoor_air_info_handle(deviceCode,propertyName,propertyValue,eplist[i],delay,gwDeviceCode,sceneId,type,1);
}
}
return 0;
......@@ -1002,7 +1032,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *room
}
else if(strcmp(typeArray[k],"airConditioning") == 0 || strcmp(typeArray[k],"fanCoil") == 0){//空调线控器和风机盘管
devIsExsit = 1;
_kk_airConditon_handle(pDeviceCode,(char*)sceneId,(char*)propertyName,(char*)propertyValue,(char*)type,delay,node->fatherDeviceCode,(char*)roomId);
_kk_airConditon_handle(pDeviceCode,(char*)sceneId,(char*)propertyName,(char*)propertyValue,(char*)type,delay,node->fatherDeviceCode,(char*)roomId,node->productCode);
continue;
}
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
......
......@@ -49,7 +49,7 @@ int kk_screenDev_delete_by_serialId(char *serialId);
int kk_get_screenDev_list(ScreenDevInfo_t*list);
int kk_get_screenDev_info(ScreenDevInfo_t *devInfo,char*serialId);
int kk_subDev_getDeviceCodes_byProductType(DeviceCode_t *list,char *type);
int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum);
int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char*gwDeviceCode,char *sceneId,char *type,int epnum,int mutiDev);
int kk_subDev_update_fatherDeviceCode(char *fatherDeviceCode,const char *deviceCode);
int kk_subDev_find_fatherDeviceCode(const char *deviceCode,char *fatherDeviceCode);
int kk_LockUser_insert_db(char *keyId,char *keyType,char*keyRole,char *keyName,char* deviceCode);
......
......@@ -601,7 +601,7 @@ static cJSON * kk_get_properties_info_obj(char *deviceCode)
propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
if(strstr(propertyStr,".") != NULL){
if(strstr(propertyStr,".") != NULL && strcmp(propertyStr,"PM2.5") != 0){
//printf("[%s][%d]\n",__FUNCTION__,__LINE__);
char *propertiesbuf[DEVICE_PROPERTY_NAME_MAX] = {0};
kk_split(propertyStr,".",propertiesbuf,&num);
......@@ -949,9 +949,18 @@ static int kk_get_panel_scenes_allRoom_info(cJSON *actionItem,char* id,char *roo
}else{
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYNAME_STR, propertyName);
}
if(strstr(propertyValue,"{")!=NULL && strstr(propertyValue,"}")!=NULL){
cJSON* prtyObj = cJSON_Parse(propertyValue);
if(prtyObj != NULL){
cJSON_AddItemToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, prtyObj);
}else{
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, propertyValue);
}
}else{
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, propertyValue);
}
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_TYPE_STR, type);
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PROPERTYVALUE_STR, propertyValue);
cJSON_AddStringToObject(actionItem, KK_SYNC_ROOMID_STR, roomId);
cJSON_AddStringToObject(actionItem, KK_SYNC_SCENE_PRODUCTTYPE, productType);
break;
......@@ -1098,7 +1107,6 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
propertyName = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_PROPERTYNAME);
propertyValue = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_PROPERTYVALUE);
type = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_TYPE);
if(strcmp(type,"action/thing/cluster")==0){
actionItem = cJSON_Parse(propertyName);
......
......@@ -35,7 +35,6 @@
#include "kk_dm_heartbeat.h"
#include "kk_sub_db.h"
#include "kk_hal.h"
#include "kk_history_db.h"
#include "kk_scene_handle.h"
#include "dm_ota.h"
#include "ccu_ver.h"
......@@ -43,6 +42,8 @@
#include "kk_property_get_handle.h"
#include "kk_motor_bind_db.h"
#include "kk_group_db.h"
#include "kk_alarm_handle.h"
#include "kk_history_db.h"
int g_timezone = 8;
char * g_filerToPlatTable[] =
......@@ -272,6 +273,8 @@ void split(char *src,const char *separator,char **dest,int *num) {
}
*num = count;
}
/************************************************************
*功能描述:属性参数校验
*输入参数:payload:消息内容
......@@ -851,7 +854,47 @@ static int kk_get_ccu_info_reply(cJSON *param,char *msgType)
return res;
}
static int _kk_handle_airswitch_property(char *fatherDeviceCode,cJSON *info_root,cJSON *payload)
{
cJSON *params = NULL;
cJSON *epNums = NULL;
cJSON * pSub = NULL;
char epStr[4] = {0};
int i = 0;
if(payload == NULL){
return INVALID_PARAMETER;
}
params = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(params == NULL){
return FAIL_RETURN;
}
epNums = cJSON_GetObjectItem(params, "epNums");
if(epNums == NULL || epNums->type != cJSON_Array){
return FAIL_RETURN;
}
int array_size = cJSON_GetArraySize (epNums);
for(i = 0; i < array_size; i++){
memset(epStr,0x0,sizeof(epStr));
pSub = cJSON_GetArrayItem(epNums, i);
if(pSub == NULL){continue;}
sprintf(epStr,"%d",pSub->valueint);
cJSON * rootData=cJSON_CreateObject();
cJSON_DeleteItemFromObject(params,"epNums");
cJSON_DeleteItemFromObject(params,"epNum");
cJSON_AddStringToObject(params,"epNum",epStr);
char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload);
cJSON_AddItemToObject(rootData,MSG_INFO_STR, cJSON_Parse(info_rootS));
cJSON_AddItemToObject(rootData,MSG_PAYLOAD_STR, cJSON_Parse(payloadS));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), fatherDeviceCode);//send to sub device
cJSON_Delete(rootData);
free(info_rootS);
free(payloadS);
free(pnewout);
}
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:nanomsg数据回调,app to mid
......@@ -948,17 +991,39 @@ void mid_cb(void* data, int len){
cJSON_Delete(json);
return;
}
cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload);
cJSON_AddItemToObject(rootData,MSG_INFO_STR, cJSON_Parse(info_rootS));
cJSON_AddItemToObject(rootData,MSG_PAYLOAD_STR, cJSON_Parse(payloadS));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), gw_node->fatherDeviceCode);//send to sub device
cJSON_Delete(rootData);
free(info_rootS);
free(payloadS);
free(pnewout);
if(gw_node->isOffline == KK_DEV_OFFLINE){
ERROR_PRINT("do not handle the device is offline:%s\n",deviceCode->valuestring);
cJSON_Delete(json);
return;
}
if(strcmp(gw_node->productType,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){
res = _kk_handle_airswitch_property(gw_node->fatherDeviceCode,info_root,payload);//空开epnum 传的是数组,无语
if(res != 0){
cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload);
cJSON_AddItemToObject(rootData,MSG_INFO_STR, cJSON_Parse(info_rootS));
cJSON_AddItemToObject(rootData,MSG_PAYLOAD_STR, cJSON_Parse(payloadS));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), gw_node->fatherDeviceCode);//send to sub device
cJSON_Delete(rootData);
free(info_rootS);
free(payloadS);
free(pnewout);
}
}else{
cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload);
cJSON_AddItemToObject(rootData,MSG_INFO_STR, cJSON_Parse(info_rootS));
cJSON_AddItemToObject(rootData,MSG_PAYLOAD_STR, cJSON_Parse(payloadS));
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), gw_node->fatherDeviceCode);//send to sub device
cJSON_Delete(rootData);
free(info_rootS);
free(payloadS);
free(pnewout);
}
}
}
else{
......@@ -1028,124 +1093,7 @@ void gw2mid_cb(void* data, int len, char* chalMark){
mid2p_cb(data,len,chalMark);
}
}
/************************************************************
*功能描述:midware收到gw数据的具体处理
*输入参数:data:从gw 层发来的数据
chalMark:网关通道,一般用mac
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueBuf)
{
int currentValue = 0;
char armingstate[16] = {0};
int ret = 0;
int needSave = 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");
char msgId[64] = {0};
iotx_report_id(msgId);
cJSON_AddStringToObject(payload, "msgId", msgId);
//char timerStr[16] = {0};
//HAL_GetTime_s(timerStr);
cJSON_AddNumberToObject(payload, "time", HAL_GetTime_ms());
cJSON *param = cJSON_CreateObject();
if(strcmp(identifier,"BatteryAlarm") == 0){
cJSON_AddStringToObject(param, "LowBatteryState", "1");
//needSave = 1;
}else if(strcmp(identifier,"DismantleState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "DismantleState", "1");
//needSave = 1;
}else if(strcmp(identifier,"SmokeSensorState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
//needSave = 1;
}else if(strcmp(identifier,"GasSensorState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
//needSave = 1;
}else if(strcmp(identifier,"WaterSensorState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
//needSave = 1;
}else if(strcmp(identifier,"SosState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
//needSave = 1;
}else if(strcmp(identifier,"DismantleState") == 0 && atoi(valueBuf) == 0){
cJSON_AddStringToObject(param, "DismantleState", "0");
}
else if(strcmp(identifier,"SmokeSensorState") == 0 && atoi(valueBuf) == 0){
cJSON_AddStringToObject(param, "CommonAlarmState", "0");
}
else if(strcmp(identifier,"GasSensorState") == 0 && atoi(valueBuf) == 0){
cJSON_AddStringToObject(param, "CommonAlarmState", "0");
}
else if(strcmp(identifier,"WaterSensorState") == 0 && atoi(valueBuf) == 0){
cJSON_AddStringToObject(param, "CommonAlarmState", "0");
}
else if(strcmp(identifier,"SosState") == 0 && atoi(valueBuf) == 0){
cJSON_AddStringToObject(param, "CommonAlarmState", "0");
}
else{
cJSON_AddStringToObject(param, "CommonAlarmState", "1");
//needSave = 1;
}
cJSON_AddItemToObject(payload, "params", param);
char *payload11=cJSON_Print(payload);
if(currentValue == 2)//24小时警戒
{
kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
}
else if(currentValue == 1 && atoi(armingstate) == 0) //离家布防
{
kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
}
else if(currentValue == 0 && atoi(armingstate) == 2) //在家布防
{
kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
}
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);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
}
}
}
needSave = 0;
free(payload11);
free(infff);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type)
{
dm_mgr_dev_node_t *node = NULL;
......@@ -1623,8 +1571,10 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_alarm_notify_handle(node,itemData->identifier,valueBuf);//告警信息处理
}
if(pack==0){
INFO_PRINT("kk_platMsg_handle data: event post\n");
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
INFO_PRINT("kk_platMsg_handle data: event post,eventItem->identifier:%s\n",eventItem->identifier);
if(strcmp(eventItem->identifier,"TamperAlarm") != 0){//TamperAlarm不需要上报,否则APP显示会有问题
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
}
kk_scene_iftt_check(info_dcode->valuestring,jsonPay);
}
}
......
......@@ -24,8 +24,10 @@
#include "kk_hal.h"
#include "kk_log.h"
#include "kk_linkkit.h"
#include "kk_tsl_common.h"
#include "kk_dm_mng.h"
#include <time.h>
#include "kk_scene_pollution_check.h"
/*************************************************************
全局变量定义
......@@ -509,14 +511,17 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_scene_action_info_send(int isUpdate)
int kk_scene_action_info_send(int isUpdate)
{
int mutiEp = 0;
cJSON *root;
cJSON *array;
cJSON *info;
char *out;
cJSON *prtyObj = NULL;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
char propertyNameBuf[64] = {0};
kk_scene_action_t *ptr = p_kk_scene_action;
kk_scene_action_info_ex_t *ptmp = NULL;
if(ptr == NULL){
......@@ -530,7 +535,18 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
while(ptr->actionInfo){
info=cJSON_CreateObject();
cJSON_AddStringToObject(info,MSG_DEVICE_CODE_STR,ptr->actionInfo->info.deviceCode);
cJSON_AddStringToObject(info,MSG_SCENE_PROPERTYNAME,ptr->actionInfo->info.propertyName);
if(strcmp(ptr->actionInfo->info.propertyName,"ColorTemperature") == 0){
mutiEp = kk_is_mutiEp_device((const char*)ptr->actionInfo->info.deviceCode);
if(mutiEp){
memset(propertyNameBuf,0x0,sizeof(propertyNameBuf));
sprintf(propertyNameBuf,"%s_%d",ptr->actionInfo->info.propertyName,ptr->actionInfo->info.epNum);
cJSON_AddStringToObject(info,MSG_SCENE_PROPERTYNAME,propertyNameBuf);
}else{
cJSON_AddStringToObject(info,MSG_SCENE_PROPERTYNAME,ptr->actionInfo->info.propertyName);
}
}else{
cJSON_AddStringToObject(info,MSG_SCENE_PROPERTYNAME,ptr->actionInfo->info.propertyName);
}
if(strstr(ptr->actionInfo->info.propertyValue,"{")!=NULL &&strstr(ptr->actionInfo->info.propertyValue,"}")!=NULL ){
//prtyObj = cJSON_Parse(ptr->actionInfo->info.propertyValue);
......@@ -1005,7 +1021,7 @@ static int kk_scene_parse_trigger_event_type(const char *type,const cJSON *item,
ep = atoi(epNum->valuestring);
}
}
propertyName = cJSON_GetObjectItem(item,"identifier");
propertyName = cJSON_GetObjectItem(item,"identifier"); //门锁场景
if(propertyName == NULL) return FAIL_RETURN;
compares = cJSON_GetObjectItem(item,"compares");
if(compares == NULL) return FAIL_RETURN;
......@@ -1553,7 +1569,11 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
info.delay = idelay;
if(strcmp(propertyName->valuestring,"LightStripSpecialAction") != 0){
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
if(strcmp(node->productCode,"5004") == 0 && strcmp(propertyValueStr,"2") == 0){
//虚拟灯取反由中控逻辑来处理,不需要下发给网关
}else{
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
}
}
//printf("---------------------------------DEBUG CWC[%s][%d]\n",__FUNCTION__,__LINE__);
res = kk_scene_insert_scene_action(typeStr,node->deviceCode,iepnum,
......@@ -1975,13 +1995,28 @@ int kk_scene_check_trigger_condition(const char *sceneId)
res = SUCCESS_RETURN;
continue;
}
kk_property_db_get_value_directly(pdeviceCode,identifier,currentValue);
INFO_PRINT("currentValue:%s\n",currentValue);
res = kk_scene_check_value_ex(compareType,currentValue,compareValue);
INFO_PRINT("kk_scene_check_value_ex:res:%d\n",res);
if(res != 0){
break;
if(strcmp(identifier,"Grade") == 0){//空气污染等级判断
if(kk_pollution_condition_check(pdeviceCode,atoi(compareValue)) == 1){
res = 0;
}else{
res = -1;
break;
}
}else if(strcmp(identifier,"PM2.5Grade") == 0){//PM2.5 判断处理
if(kk_pm25_condition_check(pdeviceCode) == atoi(compareValue)){
res = 0;
}else{
res = -1;
break;
}
}else{
kk_property_db_get_value_directly(pdeviceCode,identifier,currentValue);
INFO_PRINT("currentValue:%s\n",currentValue);
res = kk_scene_check_value_ex(compareType,currentValue,compareValue);
INFO_PRINT("kk_scene_check_value_ex:res:%d\n",res);
if(res != 0){
break;
}
}
}
sqlite3_finalize(stmt);
......@@ -2072,8 +2107,7 @@ int kk_scene_check_condition(const char *sceneId)
if(current >= startTime_m && current <= (startTime_m + duration)){
res = SUCCESS_RETURN;
}
else
{
else{
INFO_PRINT("time not match current:%ld,startTime_m:%ld\n",current,startTime_m);
}
}
......@@ -2208,6 +2242,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
int ivalue = 0;
double dvalue = 0;
int valueType = 0;
char valueBuf[16] = {0};
if(pInfo == NULL){
return;
}
......@@ -2234,6 +2269,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
ivalue = atoi(pInfo->propertyValue);
}
cJSON_AddNumberToObject(root,pInfo->propertyName,ivalue);
break;
case KK_TSL_DATA_TYPE_FLOAT:
case KK_TSL_DATA_TYPE_DOUBLE:
......@@ -2245,7 +2281,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
cJSON_AddStringToObject(root,pInfo->propertyName,pInfo->propertyValue);
break;
}
//cJSON_AddStringToObject(root,"epNum","2");
char *out=cJSON_Print(root);
kk_msg_execute_property_set(pInfo->productCode,pInfo->deviceCode,out,pInfo->fatherdeviceCode);
cJSON_Delete(root);
......@@ -2353,7 +2389,7 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
char *gwdeviceCode = NULL;
int delay = 0;
char *sqlCmd = NULL;
//
dm_mgr_dev_node_t *node = NULL;
char gwdevice[5][DEVICE_CODE_MAXLEN] = {0};
int idx=0,num = 0;
sqlite3_stmt *stmt;
......@@ -2374,12 +2410,25 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
next:
while(sqlite3_step(stmt) == SQLITE_ROW){
gwdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_GWDEVICECODE);
deviceCode = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_DEVICECODE);
if(kk_subDev_check_scene_support(gwdeviceCode) == 1){
for(idx = 0; idx < num;idx++){
if(!strcmp(gwdevice[idx],gwdeviceCode)){
goto next;
}
}
res = dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
if (res == SUCCESS_RETURN) {
if(strcmp(node->productCode,"5004") == 0){//虚拟灯
propertyValue = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_PROPERTYVALUE);
if(strcmp(propertyValue,"2") == 0){//取反操作
propertyName = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_PROPERTYNAME);
delay = sqlite3_column_int(stmt,DB_SCENEACTION_DELAY);
res = kk_scene_start_action(deviceCode,propertyName,"10",delay);
}
}
}
memcpy(gwdevice[num],gwdeviceCode,strlen(gwdeviceCode));
num++;
cJSON *root=cJSON_CreateObject();
......@@ -2390,7 +2439,7 @@ next:
free(out);
}
else{
deviceCode = (char*)sqlite3_column_text(stmt, DB_SCENEACTION_DEVICECODE);
propertyName = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_PROPERTYNAME);
propertyValue = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_PROPERTYVALUE);
delay = sqlite3_column_int(stmt,DB_SCENEACTION_DELAY);
......@@ -2583,6 +2632,24 @@ static int _kk_check_lock_trigger_info(char *proName,char *value,char *keyId,cha
}
return FAIL_RETURN;
}
static int kk_trigger_execute(char *sceneId)
{
int res = 0;
if(sceneId == NULL){
return -1;
}
INFO_PRINT("[%d]kk_scene_check_condition enter!!!\n",__LINE__);
res = kk_scene_check_condition(sceneId);
if(res == SUCCESS_RETURN){
res = kk_scene_check_trigger_condition(sceneId);
if(res == SUCCESS_RETURN){
/*check是否时场景嵌套类型*/
res = kk_scene_execute_action(sceneId,NULL);
}
}
return res;
}
/************************************************************
*功能描述:查找是否有场景触发
*输入参数:param:属性CJSON内容
......@@ -2591,6 +2658,7 @@ static int _kk_check_lock_trigger_info(char *proName,char *value,char *keyId,cha
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
extern kk_pmGrade_t g_pm25GradeMap[];
int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
{
int res = FAIL_RETURN;
......@@ -2639,30 +2707,27 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
if(LockOpenTrigger == 1){
res = _kk_check_lock_trigger_info(identifier,compareValue,KeyID->valuestring,keyRoleBuf,keyTypeBuf);
if(res == SUCCESS_RETURN){
INFO_PRINT("[%d]kk_scene_check_condition enter!!!\n",__LINE__);
res = kk_scene_check_condition(sceneId);
if(res == SUCCESS_RETURN){
res = kk_scene_check_trigger_condition(sceneId);
if(res == SUCCESS_RETURN){
/*check是否时场景嵌套类型*/
res = kk_scene_execute_action(sceneId,NULL);
}
}
res = kk_trigger_execute(sceneId);
}
}else{
cJSON *item = cJSON_GetObjectItem(param,identifier);
if(item != NULL){
propertyValueType = kk_dm_get_property_type(deviceCode,identifier);
res = kk_scene_check_value(compareType,compareValue,item,propertyValueType);
if(res == SUCCESS_RETURN){
INFO_PRINT("[%d]kk_scene_check_condition enter!!!\n",__LINE__);
res = kk_scene_check_condition(sceneId);
if(strcmp(identifier,"Grade") == 0){//空气污染等级判断
if(kk_pollution_check(param,atoi(compareValue)) == 1){
res = kk_trigger_execute(sceneId);
}
}else if(strcmp(identifier,"PM2.5Grade") == 0){
cJSON *item = cJSON_GetObjectItem(param,"PM2.5");
if(item != NULL){
if(kk_pollution_level_check(g_pm25GradeMap[0].levelMap,item->valueint,5) == atoi(compareValue)){
res = kk_trigger_execute(sceneId);
}
}
}else{
cJSON *item = cJSON_GetObjectItem(param,identifier);
if(item != NULL){
propertyValueType = kk_dm_get_property_type(deviceCode,identifier);
res = kk_scene_check_value(compareType,compareValue,item,propertyValueType);
if(res == SUCCESS_RETURN){
res = kk_scene_check_trigger_condition(sceneId);
if(res == SUCCESS_RETURN){
/*check是否时场景嵌套类型*/
res = kk_scene_execute_action(sceneId,NULL);
}
res = kk_trigger_execute(sceneId);
}
}
}
......@@ -2674,7 +2739,127 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlite3_free(sqlCmd);
return res;
}
static int _kk_virtual_mutictrl_ctrl(char *sceneId,int val,char *deviceCode,int ep)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *pdeviceCode = NULL;
int res = 0;
int epNum = 0;
dm_mgr_dev_node_t *node = NULL;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(pdeviceCode,deviceCode) == 0 && ep == epNum){
continue;
}
res = dm_mgr_get_device_by_devicecode((char*)pdeviceCode, &node);
//if (res != SUCCESS_RETURN || strcmp(node->productCode,"5004") != 0) {
//continue;
//}
cJSON *param = cJSON_CreateObject();
if(kk_is_mutiEp_device(pdeviceCode) == 1){
if(epNum == 1){
cJSON_AddNumberToObject(param, "PowerSwitch_1", val);
}else if(epNum == 2){
cJSON_AddNumberToObject(param, "PowerSwitch_2", val);
}else if(epNum == 3){
cJSON_AddNumberToObject(param, "PowerSwitch_3", val);
}else if(epNum == 4){
cJSON_AddNumberToObject(param, "PowerSwitch_4", val);
}else{
cJSON_Delete(param);
continue;
}
}else{
cJSON_AddNumberToObject(param, "PowerSwitch", val);
}
char *paramstr=cJSON_Print(param);
kk_msg_execute_property_set(node->productCode,node->deviceCode,paramstr,node->fatherDeviceCode);
free(paramstr);
cJSON_Delete(param);
}
return SUCCESS_RETURN;
}
void split(char *src,const char *separator,char **dest,int *num);
static int _kk_virtual_mutictrl_check(const char*deviceCode,cJSON *param)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *type = NULL;
char *sceneId = NULL;
int res = 0,idx = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int value = -1;
char scene_id_bak[64][16] = {0};
int i = 0,count = 0;
int repeat = 0;
int ep = 0,epNum = 0;
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
int num = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
res = dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL || strstr(property->identifier,"PowerSwitch") == NULL){
continue;
}
propertyItem = cJSON_GetObjectItem(param, property->identifier);
if(propertyItem != NULL){
if(strstr(property->identifier,"_") != NULL){
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
ep = atoi(propertiesbuf[1]);
}else{
ep = 1;
}
}else{
ep = 1;
}
value = propertyItem->valueint;
break;
}
}
if(value == -1){
return FAIL_RETURN;
}
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE deviceCode= '%s' and active = '%d'",deviceCode,1);//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
repeat = 0;
type = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_TYPE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(type,"action/thing/group") != 0 || epNum != ep){
continue;
}
sceneId = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_SCENEID);
for(i = 0; i < count; i++){//检测同个设备在同个场景中设置不同的动作,只需rebuild一次
if(strcmp(scene_id_bak[i],sceneId) == 0){
repeat = 1;
break;
}
}
if(repeat){
continue;
}
_kk_virtual_mutictrl_ctrl(sceneId,value,(char*)deviceCode,ep);
if(count < 64){
memcpy(scene_id_bak[count],sceneId,strlen(sceneId));
count++;
}
}
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:IFTT场景检测
*输入参数:param:属性CJSON内容
......@@ -2687,6 +2872,7 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
{
INFO_PRINT("deviceCode:%s\n",deviceCode);
BodySensorTrigger_report(deviceCode,1,param);
_kk_virtual_mutictrl_check(deviceCode,param);//虚拟灯的多控检测
return kk_scene_query_trigger_info(deviceCode,param);
}
......@@ -2742,7 +2928,6 @@ void kk_scene_execute_event_post(const char* sceneId,const char *msgId)
}
}
static int kk_quickpanel_pro_get(const char* sceneId,char *propertyValue)
{
int res = FAIL_RETURN;
......@@ -2811,6 +2996,7 @@ static int _kk_rebuild_device_active(char *sceneid)
int isMuti = 0;
int count = 0;
int res = 0;
int mutiDev = 0;
dm_mgr_dev_node_t *node = NULL;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
......@@ -2864,7 +3050,10 @@ static int _kk_rebuild_device_active(char *sceneid)
}
if(strcmp(node->productType,KK_DM_AIR_GATEWAY_TYPE) == 0 || strcmp(node->productType,"airConditioning") == 0
||strcmp(node->productType,"fanCoil") == 0){
kk_indoor_air_action_add(propertyValueStr,pDeviceCode,idelay,(char*)gwDeviceCode,sceneid,"action/thing/setProperty",epNum);
if(strcmp(node->productCode,"3095") == 0 || strcmp(node->productCode,"3098") == 0){//空调多合一 或者 风机盘管多合一
mutiDev = 1;
}
kk_indoor_air_action_add(propertyValueStr,pDeviceCode,idelay,(char*)gwDeviceCode,sceneid,"action/thing/setProperty",epNum,mutiDev);
}
}
}else{
......
#include <stdio.h>
#include "sqlite3.h"
#include "kk_log.h"
#include "kk_hal.h"
#include "kk_scene_pollution_check.h"
#include "kk_property_db.h"
kk_pmGrade_t g_pm25GradeMap[] =
{
{
{
{0,35,10},{36,75,1},{76,150,2},{151,250,3},{251,999,4}
}
},
};
kk_pollution_t g_pollutionMap[] =
{
{
"CO2",
{
{0,1500,1},{1501,2500,2},{2501,3500,3},{3501,9999,4}
}
},
{
"PM2.5",
{
{0,75,1},{76,150,2},{151,250,3},{251,999,4}
}
},
{
"HCHO",
{
{0,40,1},{41,80,2},{81,150,3},{151,999,4}
}
},
{
"TVOC",
{
{0,40,1},{41,80,2},{81,150,3},{151,999,4}
}
},
};
int kk_pollution_level_check(kk_pollution_level_t levelMap[],int val,int num)
{
int i = 0;
for(i = 0; i < num; i++){
if(val > levelMap[i].min && val <= levelMap[i].max){
return levelMap[i].level;
}
}
return -1;
}
int kk_pollution_check(cJSON *param,int grade)
{
int i = 0;
int num = 0;
int ret = 0;
cJSON *item = NULL;
if(param == NULL){
return -1;
}
num = sizeof(g_pollutionMap)/sizeof(kk_pollution_t);
for(i = 0; i < num; i++){
item = cJSON_GetObjectItem(param,g_pollutionMap[i].identifier);
if(item == NULL){
continue;
}
if(item->type != cJSON_Number){
continue;
}
ret = kk_pollution_level_check(g_pollutionMap[i].levelMap,item->valueint,4);
if(ret != -1){
if(grade == 1){
if(ret == 1){
continue;
}else{
return 0;
}
}else{
if(grade == ret){
return 1;
}
}
}
}
if(grade == 1 && ret == 1){
return 1;
}
return 0;
}
int kk_pollution_condition_check(char *deviceCode,int grade)
{
int num = 0;
int i = 0;
int ret = 0;
char currentValue[64] = {0};
num = sizeof(g_pollutionMap)/sizeof(kk_pollution_t);
for(i = 0; i < num; i++){
printf("------------->g_pollutionMap[i].identifier:%s\n",g_pollutionMap[i].identifier);
memset(currentValue,0x0,sizeof(currentValue));
kk_property_db_get_value_directly(deviceCode,g_pollutionMap[i].identifier,currentValue);
if(strcmp(currentValue,"") == 0){
continue;
}
printf("------------->currentValue:%s\n",currentValue);
ret = kk_pollution_level_check(g_pollutionMap[i].levelMap,atoi(currentValue),4);
printf("------------->ret:%d\n",ret);
if(ret != -1){
if(grade == 1){
if(ret == 1){
continue;
}else{
return 0;
}
}else{
if(grade == ret){
return 1;
}
}
}
}
if(grade == 1 && ret == 1){
return 1;
}
return 0;
}
int kk_pm25_condition_check(char *deviceCode)
{
int num = 0;
int i = 0;
int ret = 0;
char currentValue[64] = {0};
kk_property_db_get_value_directly(deviceCode,"PM2.5",currentValue);
if(strcmp(currentValue,"") == 0){
return 0;
}
return kk_pollution_level_check(g_pm25GradeMap[i].levelMap,atoi(currentValue),5);
}
\ No newline at end of file
#ifndef __KK_SCENE_POLLUTION_H__
#define __KK_SCENE_POLLUTION_H__
#include "cJSON.h"
typedef struct
{
int min;
int max;
int level;
}kk_pollution_level_t;
typedef struct
{
char *identifier;
kk_pollution_level_t levelMap[4];
}kk_pollution_t;
typedef struct
{
kk_pollution_level_t levelMap[5];
}kk_pmGrade_t;
int kk_pollution_level_check(kk_pollution_level_t levelMap[],int val,int num);
int kk_pollution_check(cJSON *param,int grade);
int kk_pollution_condition_check(char *deviceCode,int grade);
int kk_pm25_condition_check(char *deviceCode);
#endif
\ No newline at end of file
......@@ -18,8 +18,8 @@
"identifier":"ModuleType",
"dataType":{
"specs":{
"0": "常闭",
"1": "常开"
"1": "常闭",
"2": "常开"
},
"type":"enum"
},
......@@ -51,8 +51,8 @@
"dataType": {
"type": "enum",
"specs": {
"0": "常闭",
"1": "常开"
"1": "常闭",
"2": "常开"
}
}
}
......@@ -91,8 +91,8 @@
"dataType": {
"type": "enum",
"specs": {
"0": "常闭",
"1": "常开"
"1": "常闭",
"2": "常开"
}
}
},
......@@ -132,8 +132,8 @@
"dataType": {
"type": "enum",
"specs": {
"0": "常闭",
"1": "常开"
"1": "常闭",
"2": "常开"
}
}
}
......
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