Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
f0d7f555
Commit
f0d7f555
authored
Mar 03, 2022
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,增加告警处理;2,增加虚拟灯的多控逻辑
【提交人】陈伟灿
parent
4c1e24be
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
850 additions
and
229 deletions
+850
-229
VERSION
VERSION
+1
-1
application/klansdk/kk_data_handle.c
application/klansdk/kk_data_handle.c
+44
-1
application/klansdk/kk_findccu_handle.h
application/klansdk/kk_findccu_handle.h
+1
-0
application/klansdk/kk_lan_main.c
application/klansdk/kk_lan_main.c
+48
-1
application/klansdk/kk_opcode.h
application/klansdk/kk_opcode.h
+3
-0
midware/midware/area/kk_area_handle.c
midware/midware/area/kk_area_handle.c
+0
-24
midware/midware/dm/kk_alarm_handle.c
midware/midware/dm/kk_alarm_handle.c
+174
-0
midware/midware/dm/kk_alarm_handle.h
midware/midware/dm/kk_alarm_handle.h
+7
-0
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+24
-1
midware/midware/dm/kk_dm_mng.h
midware/midware/dm/kk_dm_mng.h
+1
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+7
-1
midware/midware/dm/kk_property_db.c
midware/midware/dm/kk_property_db.c
+1
-1
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+43
-13
midware/midware/dm/kk_sub_db.h
midware/midware/dm/kk_sub_db.h
+1
-1
midware/midware/dm/kk_sync_data.c
midware/midware/dm/kk_sync_data.c
+11
-3
midware/midware/midware.c
midware/midware/midware.c
+82
-132
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+230
-41
midware/midware/scene/kk_scene_pollution_check.c
midware/midware/scene/kk_scene_pollution_check.c
+140
-0
midware/midware/scene/kk_scene_pollution_check.h
midware/midware/scene/kk_scene_pollution_check.h
+24
-0
nx5_soc_gw/smarthome_z3gw_a133
nx5_soc_gw/smarthome_z3gw_a133
+0
-0
tsl/product_3070.json
tsl/product_3070.json
+8
-8
No files found.
VERSION
View file @
f0d7f555
1.4.4
1.4.5
\ No newline at end of file
\ No newline at end of file
application/klansdk/kk_data_handle.c
View file @
f0d7f555
...
@@ -209,7 +209,47 @@ static int kk_loginccu_ack(cJSON *arg,int sockfd)
...
@@ -209,7 +209,47 @@ static int kk_loginccu_ack(cJSON *arg,int sockfd)
}
}
return
0
;
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信息
//构建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
)
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)
...
@@ -372,6 +412,9 @@ int kk_data_handle(cJSON *json,int sockfd)
if
(
strcmp
(
opcode
->
valuestring
,
LOGIN_OPCODE
)
==
0
){
if
(
strcmp
(
opcode
->
valuestring
,
LOGIN_OPCODE
)
==
0
){
arg
=
cJSON_GetObjectItem
(
json
,
ARG_STRING
);
arg
=
cJSON_GetObjectItem
(
json
,
ARG_STRING
);
kk_loginccu_ack
(
arg
,
sockfd
);
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
){
}
else
if
(
strcmp
(
opcode
->
valuestring
,
HEARTBEAT_OPCODE
)
==
0
){
kk_heartbeat_ack
(
sockfd
);
kk_heartbeat_ack
(
sockfd
);
}
else
if
(
strcmp
(
opcode
->
valuestring
,
SYNC_OPCODE
)
==
0
){
}
else
if
(
strcmp
(
opcode
->
valuestring
,
SYNC_OPCODE
)
==
0
){
...
...
application/klansdk/kk_findccu_handle.h
View file @
f0d7f555
...
@@ -18,4 +18,5 @@
...
@@ -18,4 +18,5 @@
int
kk_lan_get_ccuid
(
_OU_
char
*
device_code
);
int
kk_lan_get_ccuid
(
_OU_
char
*
device_code
);
int
kk_findccu_handle_init
(
void
);
int
kk_findccu_handle_init
(
void
);
int
kk_lan_get_pid
(
_OU_
char
*
productId
);
int
kk_lan_get_pid
(
_OU_
char
*
productId
);
int
kk_lan_get_key
(
char
*
key
);
#endif
#endif
\ No newline at end of file
application/klansdk/kk_lan_main.c
View file @
f0d7f555
...
@@ -51,6 +51,53 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
...
@@ -51,6 +51,53 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
strncpy
(
s_ccuid
,
device_code
,
len
);
strncpy
(
s_ccuid
,
device_code
,
len
);
return
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
};
char
s_pid
[
PRODUCT_CODE_LEN
]
=
{
0
};
static
int
kk_lan_pid_init
(
void
)
static
int
kk_lan_pid_init
(
void
)
{
{
...
@@ -211,7 +258,7 @@ int main(int argc, char* argv[])
...
@@ -211,7 +258,7 @@ int main(int argc, char* argv[])
#endif
#endif
kk_lan_pid_init
();
kk_lan_pid_init
();
kk_lan_ccuid_init
();
kk_lan_ccuid_init
();
kk_lan_key_init
();
/*set the callback to get the device date to cloud*/
/*set the callback to get the device date to cloud*/
kk_ipc_init
(
IPC_APP2MID
,(
ipc_cb
*
)
KK_Data_FromMid
,
NULL
,
NULL
);
kk_ipc_init
(
IPC_APP2MID
,(
ipc_cb
*
)
KK_Data_FromMid
,
NULL
,
NULL
);
kk_findccu_handle_init
();
kk_findccu_handle_init
();
...
...
application/klansdk/kk_opcode.h
View file @
f0d7f555
...
@@ -19,12 +19,15 @@
...
@@ -19,12 +19,15 @@
#define OPCODE_STRING "opcode"
#define OPCODE_STRING "opcode"
#define ARG_STRING "arg"
#define ARG_STRING "arg"
#define ZKID_STRING "zkid"
#define ZKID_STRING "zkid"
#define DEVICEID_STRING "device_id"
#define OPEARTETYPE_STRING "operateType"
#define OPEARTETYPE_STRING "operateType"
#define NEWCCU_STRING "newccu"
#define NEWCCU_STRING "newccu"
#define OLDCCU_STRING "oldccu"
#define OLDCCU_STRING "oldccu"
#define ACCESSKEY "access_key"
#define FINDCCU_OPCODE "FIND_CCU"
#define FINDCCU_OPCODE "FIND_CCU"
#define LOGIN_OPCODE "LOGIN"
#define LOGIN_OPCODE "LOGIN"
#define LOGIN_ACCESSKEY_OPCODE "LOGIN_ACCESSKEY"
#define HEARTBEAT_OPCODE "CCU_HB"
#define HEARTBEAT_OPCODE "CCU_HB"
#define SYNC_OPCODE "SYNC_INFO"
#define SYNC_OPCODE "SYNC_INFO"
#define GET_ZB_DEVS_HW_INFO_OPCODE "GET_ZIGBEE_DEVS_HW_INFO"
#define GET_ZB_DEVS_HW_INFO_OPCODE "GET_ZIGBEE_DEVS_HW_INFO"
...
...
midware/midware/area/kk_area_handle.c
View file @
f0d7f555
...
@@ -870,30 +870,6 @@ cJSON *kk_get_roomIds_ary(void)
...
@@ -870,30 +870,6 @@ cJSON *kk_get_roomIds_ary(void)
_kk_area_unlock
();
_kk_area_unlock
();
return
roomIdsAry
;
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
)
kk_dev_list_t
*
kk_get_room_deviceCode
(
const
char
*
roomId
)
{
{
...
...
midware/midware/dm/kk_alarm_handle.c
0 → 100644
View file @
f0d7f555
#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
midware/midware/dm/kk_alarm_handle.h
0 → 100644
View file @
f0d7f555
#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
midware/midware/dm/kk_dm_mng.c
View file @
f0d7f555
...
@@ -1905,4 +1905,27 @@ cJSON *dm_mgr_get_ccu_info(void)
...
@@ -1905,4 +1905,27 @@ cJSON *dm_mgr_get_ccu_info(void)
return
root
;
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
;
}
midware/midware/dm/kk_dm_mng.h
View file @
f0d7f555
...
@@ -129,5 +129,5 @@ void dm_mgr_resubscribe(void);
...
@@ -129,5 +129,5 @@ void dm_mgr_resubscribe(void);
int
kk_get_pid
(
char
*
productId
);
int
kk_get_pid
(
char
*
productId
);
int
dm_mgr_ccu_heartbeat_cloud
(
_IN_
int
devid
);
int
dm_mgr_ccu_heartbeat_cloud
(
_IN_
int
devid
);
cJSON
*
dm_mgr_get_ccu_info
(
void
);
cJSON
*
dm_mgr_get_ccu_info
(
void
);
int
kk_is_mutiEp_device
(
const
char
*
deviceCode
);
#endif
#endif
midware/midware/dm/kk_linkkit.c
View file @
f0d7f555
...
@@ -2171,7 +2171,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
...
@@ -2171,7 +2171,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON
*
pSub
=
cJSON_GetArrayItem
(
RoomIds
,
iCnt
);
cJSON
*
pSub
=
cJSON_GetArrayItem
(
RoomIds
,
iCnt
);
if
(
NULL
==
pSub
){
continue
;
}
if
(
NULL
==
pSub
){
continue
;
}
char
roomId
[
16
]
=
{
0
};
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
);
INFO_PRINT
(
"id [%d] : %s
\n
"
,
iCnt
,
roomId
);
kk_room_update_armingstate
(
1
,
roomId
);
kk_room_update_armingstate
(
1
,
roomId
);
}
}
...
@@ -2665,6 +2669,7 @@ int _iotx_linkkit_slave_register(int devid)
...
@@ -2665,6 +2669,7 @@ int _iotx_linkkit_slave_register(int devid)
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
#if 0
/************************************************************
/************************************************************
*功能描述:子设备删除处理,
*功能描述:子设备删除处理,
*输入参数:devid:设备ID
*输入参数:devid:设备ID
...
@@ -2729,6 +2734,7 @@ static int _iotx_linkkit_subdev_delete_topo(int devid)
...
@@ -2729,6 +2734,7 @@ static int _iotx_linkkit_subdev_delete_topo(int devid)
return SUCCESS_RETURN;
return SUCCESS_RETURN;
}
}
#endif
/************************************************************
/************************************************************
*功能描述:主模块释放处理
*功能描述:主模块释放处理
*输入参数:无
*输入参数:无
...
...
midware/midware/dm/kk_property_db.c
View file @
f0d7f555
...
@@ -1011,7 +1011,7 @@ int kk_property_db_get_value_directly(const char *deviceCode,const char *identif
...
@@ -1011,7 +1011,7 @@ int kk_property_db_get_value_directly(const char *deviceCode,const char *identif
//int rc = 0;
//int rc = 0;
//char *zErrMsg = 0;
//char *zErrMsg = 0;
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
char
*
valueStr
=
NULL
;
char
*
valueStr
=
""
;
kk_property_db_ctx_t
*
ctx
=
_kk_property_db_get_ctx
();
kk_property_db_ctx_t
*
ctx
=
_kk_property_db_get_ctx
();
_kk_property_db_lock
();
_kk_property_db_lock
();
...
...
midware/midware/dm/kk_sub_db.c
View file @
f0d7f555
...
@@ -812,9 +812,10 @@ static int _kk_indoor_air_info_handle(char* deviceCode,char* propertyName,char*
...
@@ -812,9 +812,10 @@ static int _kk_indoor_air_info_handle(char* deviceCode,char* propertyName,char*
}
}
return
res
;
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
};
char
data
[
32
]
=
{
0
};
cJSON
*
json
=
cJSON_Parse
(
propertyValue
);
cJSON
*
json
=
cJSON_Parse
(
propertyValue
);
if
(
json
==
NULL
)
{
if
(
json
==
NULL
)
{
return
-
1
;
return
-
1
;
...
@@ -827,8 +828,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
...
@@ -827,8 +828,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}
else
{
}
else
{
sprintf
(
data
,
"%f"
,
Temperature
->
valuedouble
);
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"
);
cJSON
*
WindSpeed
=
cJSON_GetObjectItem
(
json
,
"WindSpeed"
);
if
(
WindSpeed
==
NULL
)
{
cJSON_Delete
(
json
);
return
-
1
;}
if
(
WindSpeed
==
NULL
)
{
cJSON_Delete
(
json
);
return
-
1
;}
memset
(
data
,
0x0
,
sizeof
(
data
));
memset
(
data
,
0x0
,
sizeof
(
data
));
...
@@ -837,8 +842,13 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
...
@@ -837,8 +842,13 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}
else
{
}
else
{
sprintf
(
data
,
"%d"
,
WindSpeed
->
valueint
);
sprintf
(
data
,
"%d"
,
WindSpeed
->
valueint
);
}
}
if
(
mutiDev
){
_kk_indoor_air_info_handle
(
deviceCode
,
"WindSpeed"
,
data
,
epnum
,
delay
,
gwDeviceCode
,
sceneId
,
type
,
0
);
_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"
);
cJSON
*
WorkMode
=
cJSON_GetObjectItem
(
json
,
"WorkMode"
);
if
(
WorkMode
==
NULL
){
cJSON_Delete
(
json
);
return
-
1
;}
if
(
WorkMode
==
NULL
){
cJSON_Delete
(
json
);
return
-
1
;}
memset
(
data
,
0x0
,
sizeof
(
data
));
memset
(
data
,
0x0
,
sizeof
(
data
));
...
@@ -847,8 +857,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
...
@@ -847,8 +857,12 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
}
else
{
}
else
{
sprintf
(
data
,
"%d"
,
WorkMode
->
valueint
);
sprintf
(
data
,
"%d"
,
WorkMode
->
valueint
);
}
}
if
(
mutiDev
){
_kk_indoor_air_info_handle
(
deviceCode
,
"WorkMode"
,
data
,
epnum
,
delay
,
gwDeviceCode
,
sceneId
,
type
,
0
);
_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
);
cJSON_Delete
(
json
);
return
0
;
return
0
;
}
}
...
@@ -876,7 +890,7 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
...
@@ -876,7 +890,7 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
}
}
}
}
if
(
strcmp
(
propertyName
,
"CustomAction"
)
==
0
){
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
],
kk_scene_insert_scene_action
(
type
,
deviceCode
,
eplist
[
i
],
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
}
else
{
}
else
{
...
@@ -885,9 +899,10 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
...
@@ -885,9 +899,10 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
}
}
return
0
;
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
res
=
0
;
int
mutiDev
=
0
;
int
allRoom
=
(
strcmp
(
roomId
,
"-1"
)
==
0
)
?
1
:
0
;
int
allRoom
=
(
strcmp
(
roomId
,
"-1"
)
==
0
)
?
1
:
0
;
if
(
allRoom
==
1
){
if
(
allRoom
==
1
){
if
(
kk_check_dev_exist_inRoom
(
deviceCode
,
"1"
)
==
0
){
if
(
kk_check_dev_exist_inRoom
(
deviceCode
,
"1"
)
==
0
){
...
@@ -900,15 +915,30 @@ static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propert
...
@@ -900,15 +915,30 @@ static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propert
return
-
1
;;
return
-
1
;;
}
}
}
}
if
(
strcmp
(
productCode
,
"3095"
)
==
0
||
strcmp
(
productCode
,
"3098"
)
==
0
){
//空调多合一 或者 风机盘管多合一
mutiDev
=
1
;
}
if
(
strcmp
(
propertyName
,
"CustomAction"
)
==
0
){
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
,
kk_scene_insert_scene_action
(
type
,
deviceCode
,
1
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
}
else
{
}
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
)
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
...
@@ -943,7 +973,7 @@ static int _kk_air_switch_handle(char* deviceCode, char *sceneId, char *property
cJSON_Delete(json);
cJSON_Delete(json);
#endif
#endif
}
else
{
}
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
;
return
0
;
...
@@ -1002,7 +1032,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *room
...
@@ -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
){
//空调线控器和风机盘管
else
if
(
strcmp
(
typeArray
[
k
],
"airConditioning"
)
==
0
||
strcmp
(
typeArray
[
k
],
"fanCoil"
)
==
0
){
//空调线控器和风机盘管
devIsExsit
=
1
;
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
;
continue
;
}
}
for
(
idx
=
0
;
idx
<
node
->
dev_shadow
->
property_number
;
idx
++
){
for
(
idx
=
0
;
idx
<
node
->
dev_shadow
->
property_number
;
idx
++
){
...
...
midware/midware/dm/kk_sub_db.h
View file @
f0d7f555
...
@@ -49,7 +49,7 @@ int kk_screenDev_delete_by_serialId(char *serialId);
...
@@ -49,7 +49,7 @@ int kk_screenDev_delete_by_serialId(char *serialId);
int
kk_get_screenDev_list
(
ScreenDevInfo_t
*
list
);
int
kk_get_screenDev_list
(
ScreenDevInfo_t
*
list
);
int
kk_get_screenDev_info
(
ScreenDevInfo_t
*
devInfo
,
char
*
serialId
);
int
kk_get_screenDev_info
(
ScreenDevInfo_t
*
devInfo
,
char
*
serialId
);
int
kk_subDev_getDeviceCodes_byProductType
(
DeviceCode_t
*
list
,
char
*
type
);
int
kk_subDev_getDeviceCodes_byProductType
(
DeviceCode_t
*
list
,
char
*
type
);
int
kk_indoor_air_action_add
(
char
*
propertyValue
,
char
*
deviceCode
,
int
delay
,
char
*
gwDeviceCode
,
char
*
sceneId
,
char
*
type
,
int
epnum
);
int
kk_indoor_air_action_add
(
char
*
propertyValue
,
char
*
deviceCode
,
int
delay
,
char
*
gwDeviceCode
,
char
*
sceneId
,
char
*
type
,
int
epnum
,
int
mutiDev
);
int
kk_subDev_update_fatherDeviceCode
(
char
*
fatherDeviceCode
,
const
char
*
deviceCode
);
int
kk_subDev_update_fatherDeviceCode
(
char
*
fatherDeviceCode
,
const
char
*
deviceCode
);
int
kk_subDev_find_fatherDeviceCode
(
const
char
*
deviceCode
,
char
*
fatherDeviceCode
);
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
);
int
kk_LockUser_insert_db
(
char
*
keyId
,
char
*
keyType
,
char
*
keyRole
,
char
*
keyName
,
char
*
deviceCode
);
...
...
midware/midware/dm/kk_sync_data.c
View file @
f0d7f555
...
@@ -601,7 +601,7 @@ static cJSON * kk_get_properties_info_obj(char *deviceCode)
...
@@ -601,7 +601,7 @@ static cJSON * kk_get_properties_info_obj(char *deviceCode)
propertyStr
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_IDENTIFITER
);
propertyStr
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_IDENTIFITER
);
valueType
=
sqlite3_column_int
(
stmt
,
DB_VALUETYPE
);
valueType
=
sqlite3_column_int
(
stmt
,
DB_VALUETYPE
);
valueStr
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_VALUE
);
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__);
//printf("[%s][%d]\n",__FUNCTION__,__LINE__);
char
*
propertiesbuf
[
DEVICE_PROPERTY_NAME_MAX
]
=
{
0
};
char
*
propertiesbuf
[
DEVICE_PROPERTY_NAME_MAX
]
=
{
0
};
kk_split
(
propertyStr
,
"."
,
propertiesbuf
,
&
num
);
kk_split
(
propertyStr
,
"."
,
propertiesbuf
,
&
num
);
...
@@ -949,9 +949,18 @@ static int kk_get_panel_scenes_allRoom_info(cJSON *actionItem,char* id,char *roo
...
@@ -949,9 +949,18 @@ static int kk_get_panel_scenes_allRoom_info(cJSON *actionItem,char* id,char *roo
}
else
{
}
else
{
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYNAME_STR
,
propertyName
);
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_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_ROOMID_STR
,
roomId
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PRODUCTTYPE
,
productType
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PRODUCTTYPE
,
productType
);
break
;
break
;
...
@@ -1098,7 +1107,6 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
...
@@ -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
);
propertyName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
type
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_TYPE
);
type
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_TYPE
);
if
(
strcmp
(
type
,
"action/thing/cluster"
)
==
0
){
if
(
strcmp
(
type
,
"action/thing/cluster"
)
==
0
){
actionItem
=
cJSON_Parse
(
propertyName
);
actionItem
=
cJSON_Parse
(
propertyName
);
...
...
midware/midware/midware.c
View file @
f0d7f555
...
@@ -35,7 +35,6 @@
...
@@ -35,7 +35,6 @@
#include "kk_dm_heartbeat.h"
#include "kk_dm_heartbeat.h"
#include "kk_sub_db.h"
#include "kk_sub_db.h"
#include "kk_hal.h"
#include "kk_hal.h"
#include "kk_history_db.h"
#include "kk_scene_handle.h"
#include "kk_scene_handle.h"
#include "dm_ota.h"
#include "dm_ota.h"
#include "ccu_ver.h"
#include "ccu_ver.h"
...
@@ -43,6 +42,8 @@
...
@@ -43,6 +42,8 @@
#include "kk_property_get_handle.h"
#include "kk_property_get_handle.h"
#include "kk_motor_bind_db.h"
#include "kk_motor_bind_db.h"
#include "kk_group_db.h"
#include "kk_group_db.h"
#include "kk_alarm_handle.h"
#include "kk_history_db.h"
int
g_timezone
=
8
;
int
g_timezone
=
8
;
char
*
g_filerToPlatTable
[]
=
char
*
g_filerToPlatTable
[]
=
...
@@ -272,6 +273,8 @@ void split(char *src,const char *separator,char **dest,int *num) {
...
@@ -272,6 +273,8 @@ void split(char *src,const char *separator,char **dest,int *num) {
}
}
*
num
=
count
;
*
num
=
count
;
}
}
/************************************************************
/************************************************************
*功能描述:属性参数校验
*功能描述:属性参数校验
*输入参数:payload:消息内容
*输入参数:payload:消息内容
...
@@ -851,7 +854,47 @@ static int kk_get_ccu_info_reply(cJSON *param,char *msgType)
...
@@ -851,7 +854,47 @@ static int kk_get_ccu_info_reply(cJSON *param,char *msgType)
return
res
;
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
*功能描述:nanomsg数据回调,app to mid
...
@@ -948,17 +991,39 @@ void mid_cb(void* data, int len){
...
@@ -948,17 +991,39 @@ void mid_cb(void* data, int len){
cJSON_Delete
(
json
);
cJSON_Delete
(
json
);
return
;
return
;
}
}
cJSON
*
rootData
=
cJSON_CreateObject
();
if
(
gw_node
->
isOffline
==
KK_DEV_OFFLINE
){
char
*
info_rootS
=
cJSON_Print
(
info_root
);
ERROR_PRINT
(
"do not handle the device is offline:%s
\n
"
,
deviceCode
->
valuestring
);
char
*
payloadS
=
cJSON_Print
(
payload
);
cJSON_Delete
(
json
);
cJSON_AddItemToObject
(
rootData
,
MSG_INFO_STR
,
cJSON_Parse
(
info_rootS
));
return
;
cJSON_AddItemToObject
(
rootData
,
MSG_PAYLOAD_STR
,
cJSON_Parse
(
payloadS
));
}
char
*
pnewout
=
cJSON_Print
(
rootData
);
if
(
strcmp
(
gw_node
->
productType
,
KK_DM_AIR_SWITCH_GATEWAY_TYPE
)
==
0
){
kk_sendData2gw
(
pnewout
,
strlen
(
pnewout
),
gw_node
->
fatherDeviceCode
);
//send to sub device
res
=
_kk_handle_airswitch_property
(
gw_node
->
fatherDeviceCode
,
info_root
,
payload
);
//空开epnum 传的是数组,无语
cJSON_Delete
(
rootData
);
if
(
res
!=
0
){
free
(
info_rootS
);
cJSON
*
rootData
=
cJSON_CreateObject
();
free
(
payloadS
);
char
*
info_rootS
=
cJSON_Print
(
info_root
);
free
(
pnewout
);
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
{
else
{
...
@@ -1028,124 +1093,7 @@ void gw2mid_cb(void* data, int len, char* chalMark){
...
@@ -1028,124 +1093,7 @@ void gw2mid_cb(void* data, int len, char* chalMark){
mid2p_cb
(
data
,
len
,
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
)
static
int
kk_subDevice_property_save
(
cJSON
*
payload
,
char
*
deviceCode
,
int
type
)
{
{
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
...
@@ -1623,8 +1571,10 @@ void kk_platMsg_handle(void* data, char* chalMark){
...
@@ -1623,8 +1571,10 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_alarm_notify_handle
(
node
,
itemData
->
identifier
,
valueBuf
);
//告警信息处理
kk_alarm_notify_handle
(
node
,
itemData
->
identifier
,
valueBuf
);
//告警信息处理
}
}
if
(
pack
==
0
){
if
(
pack
==
0
){
INFO_PRINT
(
"kk_platMsg_handle data: event post
\n
"
);
INFO_PRINT
(
"kk_platMsg_handle data: event post,eventItem->identifier:%s
\n
"
,
eventItem
->
identifier
);
dm_msg_thing_event_post
(
info_dcode
->
valuestring
,
eventItem
->
identifier
,
NULL
);
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
);
kk_scene_iftt_check
(
info_dcode
->
valuestring
,
jsonPay
);
}
}
}
}
...
...
midware/midware/scene/kk_scene_handle.c
View file @
f0d7f555
...
@@ -24,8 +24,10 @@
...
@@ -24,8 +24,10 @@
#include "kk_hal.h"
#include "kk_hal.h"
#include "kk_log.h"
#include "kk_log.h"
#include "kk_linkkit.h"
#include "kk_linkkit.h"
#include "kk_tsl_common.h"
#include "kk_dm_mng.h"
#include <time.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
...
@@ -509,14 +511,17 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
*返 回 值: 0:成功;其他:失败
*返 回 值: 0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
int
kk_scene_action_info_send
(
int
isUpdate
)
int
kk_scene_action_info_send
(
int
isUpdate
)
{
{
int
mutiEp
=
0
;
cJSON
*
root
;
cJSON
*
root
;
cJSON
*
array
;
cJSON
*
array
;
cJSON
*
info
;
cJSON
*
info
;
char
*
out
;
char
*
out
;
cJSON
*
prtyObj
=
NULL
;
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_t
*
ptr
=
p_kk_scene_action
;
kk_scene_action_info_ex_t
*
ptmp
=
NULL
;
kk_scene_action_info_ex_t
*
ptmp
=
NULL
;
if
(
ptr
==
NULL
){
if
(
ptr
==
NULL
){
...
@@ -530,7 +535,18 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -530,7 +535,18 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
while
(
ptr
->
actionInfo
){
while
(
ptr
->
actionInfo
){
info
=
cJSON_CreateObject
();
info
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
info
,
MSG_DEVICE_CODE_STR
,
ptr
->
actionInfo
->
info
.
deviceCode
);
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
){
if
(
strstr
(
ptr
->
actionInfo
->
info
.
propertyValue
,
"{"
)
!=
NULL
&&
strstr
(
ptr
->
actionInfo
->
info
.
propertyValue
,
"}"
)
!=
NULL
){
//prtyObj = cJSON_Parse(ptr->actionInfo->info.propertyValue);
//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,
...
@@ -1005,7 +1021,7 @@ static int kk_scene_parse_trigger_event_type(const char *type,const cJSON *item,
ep
=
atoi
(
epNum
->
valuestring
);
ep
=
atoi
(
epNum
->
valuestring
);
}
}
}
}
propertyName
=
cJSON_GetObjectItem
(
item
,
"identifier"
);
propertyName
=
cJSON_GetObjectItem
(
item
,
"identifier"
);
//门锁场景
if
(
propertyName
==
NULL
)
return
FAIL_RETURN
;
if
(
propertyName
==
NULL
)
return
FAIL_RETURN
;
compares
=
cJSON_GetObjectItem
(
item
,
"compares"
);
compares
=
cJSON_GetObjectItem
(
item
,
"compares"
);
if
(
compares
==
NULL
)
return
FAIL_RETURN
;
if
(
compares
==
NULL
)
return
FAIL_RETURN
;
...
@@ -1553,7 +1569,11 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
...
@@ -1553,7 +1569,11 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
info
.
delay
=
idelay
;
info
.
delay
=
idelay
;
if
(
strcmp
(
propertyName
->
valuestring
,
"LightStripSpecialAction"
)
!=
0
){
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__);
//printf("---------------------------------DEBUG CWC[%s][%d]\n",__FUNCTION__,__LINE__);
res
=
kk_scene_insert_scene_action
(
typeStr
,
node
->
deviceCode
,
iepnum
,
res
=
kk_scene_insert_scene_action
(
typeStr
,
node
->
deviceCode
,
iepnum
,
...
@@ -1975,13 +1995,28 @@ int kk_scene_check_trigger_condition(const char *sceneId)
...
@@ -1975,13 +1995,28 @@ int kk_scene_check_trigger_condition(const char *sceneId)
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
continue
;
continue
;
}
}
if
(
strcmp
(
identifier
,
"Grade"
)
==
0
){
//空气污染等级判断
kk_property_db_get_value_directly
(
pdeviceCode
,
identifier
,
currentValue
);
if
(
kk_pollution_condition_check
(
pdeviceCode
,
atoi
(
compareValue
))
==
1
){
INFO_PRINT
(
"currentValue:%s
\n
"
,
currentValue
);
res
=
0
;
res
=
kk_scene_check_value_ex
(
compareType
,
currentValue
,
compareValue
);
}
else
{
INFO_PRINT
(
"kk_scene_check_value_ex:res:%d
\n
"
,
res
);
res
=
-
1
;
if
(
res
!=
0
){
break
;
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
);
sqlite3_finalize
(
stmt
);
...
@@ -2072,8 +2107,7 @@ int kk_scene_check_condition(const char *sceneId)
...
@@ -2072,8 +2107,7 @@ int kk_scene_check_condition(const char *sceneId)
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
else
else
{
{
INFO_PRINT
(
"time not match current:%ld,startTime_m:%ld
\n
"
,
current
,
startTime_m
);
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)
...
@@ -2208,6 +2242,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
int
ivalue
=
0
;
int
ivalue
=
0
;
double
dvalue
=
0
;
double
dvalue
=
0
;
int
valueType
=
0
;
int
valueType
=
0
;
char
valueBuf
[
16
]
=
{
0
};
if
(
pInfo
==
NULL
){
if
(
pInfo
==
NULL
){
return
;
return
;
}
}
...
@@ -2234,6 +2269,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -2234,6 +2269,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
ivalue
=
atoi
(
pInfo
->
propertyValue
);
ivalue
=
atoi
(
pInfo
->
propertyValue
);
}
}
cJSON_AddNumberToObject
(
root
,
pInfo
->
propertyName
,
ivalue
);
cJSON_AddNumberToObject
(
root
,
pInfo
->
propertyName
,
ivalue
);
break
;
break
;
case
KK_TSL_DATA_TYPE_FLOAT
:
case
KK_TSL_DATA_TYPE_FLOAT
:
case
KK_TSL_DATA_TYPE_DOUBLE
:
case
KK_TSL_DATA_TYPE_DOUBLE
:
...
@@ -2245,7 +2281,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -2245,7 +2281,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
cJSON_AddStringToObject
(
root
,
pInfo
->
propertyName
,
pInfo
->
propertyValue
);
cJSON_AddStringToObject
(
root
,
pInfo
->
propertyName
,
pInfo
->
propertyValue
);
break
;
break
;
}
}
//cJSON_AddStringToObject(root,"epNum","2");
char
*
out
=
cJSON_Print
(
root
);
char
*
out
=
cJSON_Print
(
root
);
kk_msg_execute_property_set
(
pInfo
->
productCode
,
pInfo
->
deviceCode
,
out
,
pInfo
->
fatherdeviceCode
);
kk_msg_execute_property_set
(
pInfo
->
productCode
,
pInfo
->
deviceCode
,
out
,
pInfo
->
fatherdeviceCode
);
cJSON_Delete
(
root
);
cJSON_Delete
(
root
);
...
@@ -2353,7 +2389,7 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
...
@@ -2353,7 +2389,7 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
char
*
gwdeviceCode
=
NULL
;
char
*
gwdeviceCode
=
NULL
;
int
delay
=
0
;
int
delay
=
0
;
char
*
sqlCmd
=
NULL
;
char
*
sqlCmd
=
NULL
;
//
dm_mgr_dev_node_t
*
node
=
NULL
;
char
gwdevice
[
5
][
DEVICE_CODE_MAXLEN
]
=
{
0
};
char
gwdevice
[
5
][
DEVICE_CODE_MAXLEN
]
=
{
0
};
int
idx
=
0
,
num
=
0
;
int
idx
=
0
,
num
=
0
;
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
...
@@ -2374,12 +2410,25 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
...
@@ -2374,12 +2410,25 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
next:
next:
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
gwdeviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
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
){
if
(
kk_subDev_check_scene_support
(
gwdeviceCode
)
==
1
){
for
(
idx
=
0
;
idx
<
num
;
idx
++
){
for
(
idx
=
0
;
idx
<
num
;
idx
++
){
if
(
!
strcmp
(
gwdevice
[
idx
],
gwdeviceCode
)){
if
(
!
strcmp
(
gwdevice
[
idx
],
gwdeviceCode
)){
goto
next
;
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
));
memcpy
(
gwdevice
[
num
],
gwdeviceCode
,
strlen
(
gwdeviceCode
));
num
++
;
num
++
;
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
root
=
cJSON_CreateObject
();
...
@@ -2390,7 +2439,7 @@ next:
...
@@ -2390,7 +2439,7 @@ next:
free
(
out
);
free
(
out
);
}
}
else
{
else
{
deviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
propertyName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
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
...
@@ -2583,6 +2632,24 @@ static int _kk_check_lock_trigger_info(char *proName,char *value,char *keyId,cha
}
}
return
FAIL_RETURN
;
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内容
*输入参数:param:属性CJSON内容
...
@@ -2591,6 +2658,7 @@ static int _kk_check_lock_trigger_info(char *proName,char *value,char *keyId,cha
...
@@ -2591,6 +2658,7 @@ static int _kk_check_lock_trigger_info(char *proName,char *value,char *keyId,cha
*返 回 值:0:成功;其他:失败
*返 回 值:0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
extern
kk_pmGrade_t
g_pm25GradeMap
[];
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -2639,30 +2707,27 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -2639,30 +2707,27 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
if
(
LockOpenTrigger
==
1
){
if
(
LockOpenTrigger
==
1
){
res
=
_kk_check_lock_trigger_info
(
identifier
,
compareValue
,
KeyID
->
valuestring
,
keyRoleBuf
,
keyTypeBuf
);
res
=
_kk_check_lock_trigger_info
(
identifier
,
compareValue
,
KeyID
->
valuestring
,
keyRoleBuf
,
keyTypeBuf
);
if
(
res
==
SUCCESS_RETURN
){
if
(
res
==
SUCCESS_RETURN
){
INFO_PRINT
(
"[%d]kk_scene_check_condition enter!!!
\n
"
,
__LINE__
);
res
=
kk_trigger_execute
(
sceneId
);
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
);
}
}
}
}
}
else
{
}
else
{
cJSON
*
item
=
cJSON_GetObjectItem
(
param
,
identifier
);
if
(
strcmp
(
identifier
,
"Grade"
)
==
0
){
//空气污染等级判断
if
(
item
!=
NULL
){
if
(
kk_pollution_check
(
param
,
atoi
(
compareValue
))
==
1
){
propertyValueType
=
kk_dm_get_property_type
(
deviceCode
,
identifier
);
res
=
kk_trigger_execute
(
sceneId
);
res
=
kk_scene_check_value
(
compareType
,
compareValue
,
item
,
propertyValueType
);
}
if
(
res
==
SUCCESS_RETURN
){
}
else
if
(
strcmp
(
identifier
,
"PM2.5Grade"
)
==
0
){
INFO_PRINT
(
"[%d]kk_scene_check_condition enter!!!
\n
"
,
__LINE__
);
cJSON
*
item
=
cJSON_GetObjectItem
(
param
,
"PM2.5"
);
res
=
kk_scene_check_condition
(
sceneId
);
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
){
if
(
res
==
SUCCESS_RETURN
){
res
=
kk_scene_check_trigger_condition
(
sceneId
);
res
=
kk_trigger_execute
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
/*check是否时场景嵌套类型*/
res
=
kk_scene_execute_action
(
sceneId
,
NULL
);
}
}
}
}
}
}
}
...
@@ -2674,7 +2739,127 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -2674,7 +2739,127 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
return
res
;
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场景检测
*功能描述:IFTT场景检测
*输入参数:param:属性CJSON内容
*输入参数:param:属性CJSON内容
...
@@ -2687,6 +2872,7 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
...
@@ -2687,6 +2872,7 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
{
{
INFO_PRINT
(
"deviceCode:%s
\n
"
,
deviceCode
);
INFO_PRINT
(
"deviceCode:%s
\n
"
,
deviceCode
);
BodySensorTrigger_report
(
deviceCode
,
1
,
param
);
BodySensorTrigger_report
(
deviceCode
,
1
,
param
);
_kk_virtual_mutictrl_check
(
deviceCode
,
param
);
//虚拟灯的多控检测
return
kk_scene_query_trigger_info
(
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)
...
@@ -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
)
static
int
kk_quickpanel_pro_get
(
const
char
*
sceneId
,
char
*
propertyValue
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -2811,6 +2996,7 @@ static int _kk_rebuild_device_active(char *sceneid)
...
@@ -2811,6 +2996,7 @@ static int _kk_rebuild_device_active(char *sceneid)
int
isMuti
=
0
;
int
isMuti
=
0
;
int
count
=
0
;
int
count
=
0
;
int
res
=
0
;
int
res
=
0
;
int
mutiDev
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
@@ -2864,7 +3050,10 @@ static int _kk_rebuild_device_active(char *sceneid)
...
@@ -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
if
(
strcmp
(
node
->
productType
,
KK_DM_AIR_GATEWAY_TYPE
)
==
0
||
strcmp
(
node
->
productType
,
"airConditioning"
)
==
0
||
strcmp
(
node
->
productType
,
"fanCoil"
)
==
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
{
}
else
{
...
...
midware/midware/scene/kk_scene_pollution_check.c
0 → 100644
View file @
f0d7f555
#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
midware/midware/scene/kk_scene_pollution_check.h
0 → 100644
View file @
f0d7f555
#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
nx5_soc_gw/smarthome_z3gw_a133
View file @
f0d7f555
No preview for this file type
tsl/product_3070.json
View file @
f0d7f555
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
"identifier"
:
"ModuleType"
,
"identifier"
:
"ModuleType"
,
"dataType"
:{
"dataType"
:{
"specs"
:{
"specs"
:{
"
0
"
:
"常闭"
,
"
1
"
:
"常闭"
,
"
1
"
:
"常开"
"
2
"
:
"常开"
},
},
"type"
:
"enum"
"type"
:
"enum"
},
},
...
@@ -51,8 +51,8 @@
...
@@ -51,8 +51,8 @@
"dataType"
:
{
"dataType"
:
{
"type"
:
"enum"
,
"type"
:
"enum"
,
"specs"
:
{
"specs"
:
{
"
0
"
:
"常闭"
,
"
1
"
:
"常闭"
,
"
1
"
:
"常开"
"
2
"
:
"常开"
}
}
}
}
}
}
...
@@ -91,8 +91,8 @@
...
@@ -91,8 +91,8 @@
"dataType"
:
{
"dataType"
:
{
"type"
:
"enum"
,
"type"
:
"enum"
,
"specs"
:
{
"specs"
:
{
"
0
"
:
"常闭"
,
"
1
"
:
"常闭"
,
"
1
"
:
"常开"
"
2
"
:
"常开"
}
}
}
}
},
},
...
@@ -132,8 +132,8 @@
...
@@ -132,8 +132,8 @@
"dataType"
:
{
"dataType"
:
{
"type"
:
"enum"
,
"type"
:
"enum"
,
"specs"
:
{
"specs"
:
{
"
0
"
:
"常闭"
,
"
1
"
:
"常闭"
,
"
1
"
:
"常开"
"
2
"
:
"常开"
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment