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
d138d8c4
Commit
d138d8c4
authored
Dec 09, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加场景使能功能
【提交人】陈伟灿
parent
e974af3d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133828 additions
and
133654 deletions
+133828
-133654
common/api/com_api.h
common/api/com_api.h
+2
-0
common/sqlite/sqlite3.c
common/sqlite/sqlite3.c
+133611
-133611
midware/midware/dm/kk_property_db.c
midware/midware/dm/kk_property_db.c
+10
-4
midware/midware/scene/kk_scene_db.c
midware/midware/scene/kk_scene_db.c
+80
-6
midware/midware/scene/kk_scene_db.h
midware/midware/scene/kk_scene_db.h
+7
-0
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+115
-30
midware/tsl/tsl_handle/kk_tsl_parse.c
midware/tsl/tsl_handle/kk_tsl_parse.c
+3
-3
No files found.
common/api/com_api.h
View file @
d138d8c4
...
@@ -29,6 +29,7 @@ typedef enum {
...
@@ -29,6 +29,7 @@ typedef enum {
}
ipc_type
;
}
ipc_type
;
#define MSG_COMMON_MSGID "msgId"
#define MSG_COMMON_MSGID "msgId"
#define MSG_COMMON_ARGS "args"
#define MSG_TYPE_STR "msgtype"
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_PRODUCT_CODE_STR "productCode"
...
@@ -94,6 +95,7 @@ typedef enum {
...
@@ -94,6 +95,7 @@ typedef enum {
#define MSG_KEYMODIFY_NOTIFICATION "KeyModifyNotification"
#define MSG_KEYMODIFY_NOTIFICATION "KeyModifyNotification"
/************************SCENE RELATION*************************/
/************************SCENE RELATION*************************/
#define MSG_SCENE_ENABLESCENE "enableScene"
#define MSG_SCENE_NEGATICE "negativeProperty"
#define MSG_SCENE_NEGATICE "negativeProperty"
#define MSG_SCENE_SUPPORT "sceneSupport"
#define MSG_SCENE_SUPPORT "sceneSupport"
#define MSG_SCENE_MSGID "msgId"
#define MSG_SCENE_MSGID "msgId"
...
...
common/sqlite/sqlite3.c
View file @
d138d8c4
This source diff could not be displayed because it is too large. You can
view the blob
instead.
midware/midware/dm/kk_property_db.c
View file @
d138d8c4
...
@@ -183,7 +183,8 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie
...
@@ -183,7 +183,8 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie
pDeviceCode
=
sqlite3_column_text
(
stmt
,
DB_DEVICECODE
);
pDeviceCode
=
sqlite3_column_text
(
stmt
,
DB_DEVICECODE
);
pIdentifier
=
sqlite3_column_text
(
stmt
,
DB_IDENTIFITER
);
pIdentifier
=
sqlite3_column_text
(
stmt
,
DB_IDENTIFITER
);
if
(
!
strcmp
(
deviceCode
,
pDeviceCode
)
&&!
strcmp
(
identifier
,
pIdentifier
))
if
(
!
strcmp
(
deviceCode
,
pDeviceCode
)
&&!
strcmp
(
identifier
,
pIdentifier
))
{
{
isExist
=
1
;
isExist
=
1
;
break
;
break
;
}
}
...
@@ -402,7 +403,8 @@ int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_pro
...
@@ -402,7 +403,8 @@ int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_pro
*返 回 值: 0:成功;其他:失败
*返 回 值: 0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
int
kk_property_db_update
(
const
char
*
deviceCode
)
int
kk_property_db_update
(
const
char
*
deviceCode
)
{
{
int
res
=
0
;
int
res
=
0
;
int
idx
=
0
;
int
idx
=
0
;
...
@@ -469,7 +471,10 @@ int kk_property_sync_values(const char *deviceCode)
...
@@ -469,7 +471,10 @@ int kk_property_sync_values(const char *deviceCode)
char
*
searchCmd
=
"select * from PropertiesInfo;"
;
char
*
searchCmd
=
"select * from PropertiesInfo;"
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_get_device_by_devicecode
(
deviceCode
,
&
node
);
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
searchCmd
,
deviceCode
);
sqlCmd
=
sqlite3_mprintf
(
searchCmd
,
deviceCode
);
...
@@ -563,7 +568,8 @@ static int _kk_check_lockkey_exist(const char* deviceCode,const char* keyId)
...
@@ -563,7 +568,8 @@ static int _kk_check_lockkey_exist(const char* deviceCode,const char* keyId)
pKeyId
=
sqlite3_column_text
(
stmt
,
DB_LOCKKEY_KEYID
);
pKeyId
=
sqlite3_column_text
(
stmt
,
DB_LOCKKEY_KEYID
);
if
(
!
strcmp
(
deviceCode
,
pDeviceCode
)
&&!
strcmp
(
pKeyId
,
keyId
))
if
(
!
strcmp
(
deviceCode
,
pDeviceCode
)
&&!
strcmp
(
pKeyId
,
keyId
))
{
{
isExist
=
1
;
isExist
=
1
;
break
;
break
;
}
}
...
...
midware/midware/scene/kk_scene_db.c
View file @
d138d8c4
...
@@ -28,10 +28,6 @@ extern sqlite3 *g_kk_pDb;
...
@@ -28,10 +28,6 @@ extern sqlite3 *g_kk_pDb;
函数实现
函数实现
*************************************************************/
*************************************************************/
int
kk_scene_db_init
(
void
)
int
kk_scene_db_init
(
void
)
{
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
@@ -143,6 +139,21 @@ int kk_scene_db_init(void)
...
@@ -143,6 +139,21 @@ int kk_scene_db_init(void)
sceneId varchar(255))"
;
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneEmbedTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneEmbedTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
/*invoke场景关联表*/
const
char
*
pSceneInvokeServiceTable
=
"CREATE TABLE IF NOT EXISTS SceneInvokeService( \
type varchar(255), \
identifier varchar(255), \
sceneId varchar(255), \
args varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneInvokeServiceTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
sqlite3_free
(
pcErr
);
...
@@ -162,7 +173,6 @@ int kk_scene_db_init(void)
...
@@ -162,7 +173,6 @@ int kk_scene_db_init(void)
*返 回 值: 0:成功;其他:失败
*返 回 值: 0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
int
kk_scene_update_scene_enable
(
int
enable
,
const
char
*
sceneId
)
int
kk_scene_update_scene_enable
(
int
enable
,
const
char
*
sceneId
)
{
{
char
*
sqlCmd
=
NULL
;
char
*
sqlCmd
=
NULL
;
...
@@ -430,6 +440,42 @@ int kk_scene_insert_scene_embed(int delay,const char* executeSceneId,const char*
...
@@ -430,6 +440,42 @@ int kk_scene_insert_scene_embed(int delay,const char* executeSceneId,const char*
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加invokeService场景信息到数据库
*输入参数:type:场景type
identifier: 场景identifier
args:参数
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_invokeService
(
const
char
*
type
,
const
char
*
identifier
,
const
char
*
args
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneInvokeService (type,identifier,sceneId,args) \
values ('%s','%s','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
identifier
,
sceneId
,
args
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
}
/************************************************************
/************************************************************
*功能描述: 添加场景执行动作到数据库
*功能描述: 添加场景执行动作到数据库
...
@@ -620,7 +666,35 @@ int kk_scene_delete_scene_embed(const char *sceneId)
...
@@ -620,7 +666,35 @@ int kk_scene_delete_scene_embed(const char *sceneId)
_kk_scene_unlock
();
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
/************************************************************
*功能描述: 从数据库删除invokeservice场景的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_invokeservice
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneInvokeService where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
/************************************************************
*功能描述: 从数据库删除场景执行动作的基本数据
*功能描述: 从数据库删除场景执行动作的基本数据
*输入参数: sceneId:场景Id
*输入参数: sceneId:场景Id
...
...
midware/midware/scene/kk_scene_db.h
View file @
d138d8c4
...
@@ -60,4 +60,11 @@ typedef enum{
...
@@ -60,4 +60,11 @@ typedef enum{
DB_SCENEMBED_SCENEID
,
DB_SCENEMBED_SCENEID
,
};
};
typedef
enum
{
DB_SCENEINVOKESERVICE_TYPE
=
0
,
DB_SCENEINVOKESERVICE_IDENTIFIER
,
DB_SCENEINVOKESERVICE_SCENEID
,
DB_SCENEINVOKESERVICE_args
,
};
#endif
#endif
midware/midware/scene/kk_scene_handle.c
View file @
d138d8c4
...
@@ -37,7 +37,7 @@ static kk_scene_action_t *p_kk_scene_action = NULL;
...
@@ -37,7 +37,7 @@ static kk_scene_action_t *p_kk_scene_action = NULL;
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
int
kk_scene_check_trigger_condition
(
const
char
*
sceneId
);
int
kk_scene_check_trigger_condition
(
const
char
*
sceneId
);
static
int
kk_scene_embed_find
(
const
char
*
sceneId
);
static
int
kk_scene_embed_find
(
const
char
*
sceneId
);
static
int
kk_scene_invokeService_find
(
const
char
*
sceneId
);
/*************************************************************
/*************************************************************
函数实现
函数实现
...
@@ -264,9 +264,7 @@ void *kk_scene_yield(void *args)
...
@@ -264,9 +264,7 @@ void *kk_scene_yield(void *args)
INFO_PRINT
(
"current_time %d
\n
"
,
current_time
);
INFO_PRINT
(
"current_time %d
\n
"
,
current_time
);
if
(
scene_timer_list
->
starttime
!=
0
&&
current_time
>=
scene_timer_list
->
starttime
){
if
(
scene_timer_list
->
starttime
!=
0
&&
current_time
>=
scene_timer_list
->
starttime
){
if
(
kk_scene_check_trigger_condition
(
scene_timer_list
->
sceneId
)
==
0
){
if
(
kk_scene_check_trigger_condition
(
scene_timer_list
->
sceneId
)
==
0
){
if
(
kk_scene_embed_find
(
scene_timer_list
->
sceneId
)
==
0
){
kk_scene_execute_action
(
scene_timer_list
->
sceneId
,
NULL
);
kk_scene_execute_action
(
scene_timer_list
->
sceneId
,
NULL
);
}
}
}
kk_scene_update_starttime
(
scene_timer_list
,
current_time
);
kk_scene_update_starttime
(
scene_timer_list
,
current_time
);
}
}
...
@@ -446,6 +444,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -446,6 +444,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_action
(
sceneId
,
isforword
);
kk_scene_delete_scene_action
(
sceneId
,
isforword
);
kk_scene_delete_scene_invokeservice
(
sceneId
);
}
}
/************************************************************
/************************************************************
...
@@ -560,6 +559,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -560,6 +559,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
char
*
out
=
cJSON_Print
(
root
);
char
*
out
=
cJSON_Print
(
root
);
printf
(
"kk_scene_muticontrol_info_send:%s
\n
"
,
out
);
printf
(
"kk_scene_muticontrol_info_send:%s
\n
"
,
out
);
kk_msg_execute_scene_set
(
out
,
gwdeviceCode
,
isUpdate
);
kk_msg_execute_scene_set
(
out
,
gwdeviceCode
,
isUpdate
);
cJSON_Delete
(
root
);
free
(
out
);
free
(
out
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -573,7 +573,6 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -573,7 +573,6 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
*返 回 值: 0:成功;其他:失败
*返 回 值: 0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
static
int
kk_scene_parse_trigger_detail
(
const
char
*
type
,
const
cJSON
*
item
,
const
char
*
sceneId
,
int
isAnd
)
static
int
kk_scene_parse_trigger_detail
(
const
char
*
type
,
const
cJSON
*
item
,
const
char
*
sceneId
,
int
isAnd
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -873,14 +872,22 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
...
@@ -873,14 +872,22 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
if
(
type
==
NULL
)
return
FAIL_RETURN
;
if
(
type
==
NULL
)
return
FAIL_RETURN
;
/*内嵌场景设置*/
/*内嵌场景设置*/
if
(
!
strcmp
(
type
->
valuestring
,
"action/scene"
))
if
(
!
strcmp
(
type
->
valuestring
,
"action/scene"
)){
{
cJSON
*
delay
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_DELAY
);
cJSON
*
delay
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_DELAY
);
if
(
delay
==
NULL
)
return
FAIL_RETURN
;
if
(
delay
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
exeucteSceneId
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_SCENEID
);
cJSON
*
exeucteSceneId
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_SCENEID
);
if
(
exeucteSceneId
==
NULL
)
return
FAIL_RETURN
;
if
(
exeucteSceneId
==
NULL
)
return
FAIL_RETURN
;
kk_scene_insert_scene_embed
(
delay
->
valueint
,
exeucteSceneId
->
valuestring
,
sceneId
);
kk_scene_insert_scene_embed
(
delay
->
valueint
,
exeucteSceneId
->
valuestring
,
sceneId
);
}
}
else
if
(
!
strcmp
(
type
->
valuestring
,
"action/thing/invokeService"
)){
//场景服务,包含场景使能等
cJSON
*
identifier
=
cJSON_GetObjectItem
(
item
,
MSG_INDENTIFIER_STR
);
if
(
identifier
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
arg
=
cJSON_GetObjectItem
(
item
,
MSG_COMMON_ARGS
);
if
(
arg
==
NULL
)
return
FAIL_RETURN
;
char
*
argStr
=
cJSON_PrintUnformatted
(
arg
);
kk_scene_insert_scene_invokeService
(
type
->
valuestring
,
identifier
->
valuestring
,
argStr
,
sceneId
);
free
(
argStr
);
}
else
else
{
{
propertySetType
=
1
;
propertySetType
=
1
;
...
@@ -943,39 +950,47 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
...
@@ -943,39 +950,47 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
*返 回 值: 0:成功;其他:失败
*返 回 值: 0:成功;其他:失败
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
int
kk_scene_parse_scene_muticontrol
(
const
cJSON
*
str
,
const
char
*
sceneId
,
int
isUpdate
){
int
kk_scene_parse_scene_muticontrol
(
const
cJSON
*
str
,
const
char
*
sceneId
,
int
isUpdate
){
int
res
=
0
;
int
res
=
0
;
cJSON
*
type
=
NULL
;
cJSON
*
type
=
NULL
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
epNum
=
NULL
;
cJSON
*
arrayParam
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
str
==
NULL
){
if
(
str
==
NULL
){
ERROR_PRINT
(
"kk_scene_parse_scene_muticontrol failed
\n
"
);
ERROR_PRINT
(
"kk_scene_parse_scene_muticontrol failed
\n
"
);
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
cJSON
*
array
=
cJSON_CreateArray
();
cJSON
*
action
=
cJSON_GetObjectItem
(
str
,
MSG_SCENE_ACTIONS
);
cJSON
*
action
=
cJSON_GetObjectItem
(
str
,
MSG_SCENE_ACTIONS
);
if
(
action
==
NULL
)
return
FAIL_RETURN
;
if
(
action
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
item
=
action
->
child
;
cJSON
*
item
=
action
->
child
;
while
(
item
!=
NULL
){
while
(
item
!=
NULL
){
cJSON
*
arrayParam
=
cJSON_CreateObject
();
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
if
(
type
==
NULL
)
return
FAIL_RETURN
;
if
(
type
==
NULL
)
return
FAIL_RETURN
;
if
(
!
strcmp
(
type
->
valuestring
,
"action/thing/group"
)){
if
(
!
strcmp
(
type
->
valuestring
,
"action/thing/group"
)){
cJSON_AddStringToObject
(
arrayParam
,
MSG_SCENE_TYPE
,
type
->
valuestring
);
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
);
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
cJSON_AddStringToObject
(
arrayParam
,
MSG_DEVICE_CODE_STR
,
deviceCode
->
valuestring
);
epNum
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_EPNUM
);
if
(
epNum
==
NULL
)
return
FAIL_RETURN
;
cJSON_AddNumberToObject
(
arrayParam
,
MSG_SCENE_EPNUM
,
atoi
(
epNum
->
valuestring
));
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
item
=
item
->
next
;
item
=
item
->
next
;
continue
;
continue
;
}
}
break
;
cJSON_AddItemToArray
(
array
,
arrayParam
);
//break;
}
}
item
=
item
->
next
;
item
=
item
->
next
;
}
}
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
0
,
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
0
,
""
,
""
,
0
,
sceneId
,
node
->
fatherDeviceCode
);
""
,
""
,
0
,
sceneId
,
node
->
fatherDeviceCode
);
kk_scene_muticontrol_info_send
(
a
ction
,
node
->
fatherDeviceCode
,
sceneId
,
isUpdate
);
kk_scene_muticontrol_info_send
(
a
rray
,
node
->
fatherDeviceCode
,
sceneId
,
isUpdate
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -1243,7 +1258,6 @@ static time_t kk_scene_creat_timer_starttime(int week,int starttime,time_t curre
...
@@ -1243,7 +1258,6 @@ static time_t kk_scene_creat_timer_starttime(int week,int starttime,time_t curre
*返 回 值:0:符合;其他:不符合
*返 回 值:0:符合;其他:不符合
*其他说明:
*其他说明:
*************************************************************/
*************************************************************/
int
kk_scene_check_trigger_condition
(
const
char
*
sceneId
)
int
kk_scene_check_trigger_condition
(
const
char
*
sceneId
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -1254,11 +1268,16 @@ int kk_scene_check_trigger_condition(const char *sceneId)
...
@@ -1254,11 +1268,16 @@ int kk_scene_check_trigger_condition(const char *sceneId)
char
*
compareValue
=
NULL
;
char
*
compareValue
=
NULL
;
int
propertyValueType
=
0
;
int
propertyValueType
=
0
;
int
conditionFlag
=
0
;
int
conditionFlag
=
0
;
int
sceneType
=
0
,
isEnable
=
0
;
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
char
currentValue
[
64
]
=
{
0
};
char
currentValue
[
64
]
=
{
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
();
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
isEnable
);
if
(
res
!=
SUCCESS_RETURN
||
isEnable
!=
1
){
INFO_PRINT
(
"kk_scene_check_trigger_condition isEnable:%d
\n
"
,
isEnable
);
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE sceneId = '%s' and isAnd = '%d'"
,
sceneId
,
1
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE sceneId = '%s' and isAnd = '%d'"
,
sceneId
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
...
@@ -1276,7 +1295,6 @@ int kk_scene_check_trigger_condition(const char *sceneId)
...
@@ -1276,7 +1295,6 @@ int kk_scene_check_trigger_condition(const char *sceneId)
if
(
res
!=
0
){
if
(
res
!=
0
){
break
;
break
;
}
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
...
@@ -1374,7 +1392,6 @@ int kk_scene_check_condition(const char *sceneId)
...
@@ -1374,7 +1392,6 @@ int kk_scene_check_condition(const char *sceneId)
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
/*如果没有设置条件,直接return success*/
/*如果没有设置条件,直接return success*/
if
(
conditionFlag
==
0
){
if
(
conditionFlag
==
0
){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
...
@@ -1653,14 +1670,20 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
...
@@ -1653,14 +1670,20 @@ int kk_scene_execute_action(const char* sceneId,char *msgId)
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
INFO_PRINT
(
"[%s][%d] kk_scene_execute_action now!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
INFO_PRINT
(
"[%s][%d] kk_scene_execute_action now!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
//嵌套场景处理
if
(
kk_scene_embed_find
(
sceneId
)){
kk_scene_execute_event_post
(
sceneId
,
msgId
);
return
0
;
}
//invokeService处理
if
(
kk_scene_invokeService_find
(
sceneId
)){
kk_scene_execute_event_post
(
sceneId
,
msgId
);
return
0
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
next:
next:
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
deviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
propertyName
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyValue
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
gwdeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
gwdeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
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
++
){
...
@@ -1678,15 +1701,17 @@ next:
...
@@ -1678,15 +1701,17 @@ next:
free
(
out
);
free
(
out
);
}
}
else
{
else
{
deviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
propertyName
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyValue
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
res
=
kk_scene_start_action
(
deviceCode
,
propertyName
,
propertyValue
,
delay
);
res
=
kk_scene_start_action
(
deviceCode
,
propertyName
,
propertyValue
,
delay
);
}
}
}
}
kk_scene_execute_event_post
(
sceneId
,
msgId
);
kk_scene_execute_event_post
(
sceneId
,
msgId
);
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
return
res
;
return
res
;
}
}
/************************************************************
/************************************************************
*功能描述:添加嵌套场景到队列
*功能描述:添加嵌套场景到队列
...
@@ -1742,10 +1767,11 @@ static int kk_scene_embed_find(const char *sceneId)
...
@@ -1742,10 +1767,11 @@ static int kk_scene_embed_find(const char *sceneId)
if
(
sceneId
==
NULL
){
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
INFO_PRINT
(
"kk_scene_embed_find:%s
\n
"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneEmbedInfo WHERE sceneId= '%s'"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneEmbedInfo WHERE sceneId= '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
INFO_PRINT
(
"kk_scene_embed_find:%s
\n
"
,
sceneId
);
find
=
1
;
find
=
1
;
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEEMBED_WEEK
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEEMBED_WEEK
);
executeSceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENEEMBED_EXECUTESCENEID
);
executeSceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENEEMBED_EXECUTESCENEID
);
...
@@ -1761,7 +1787,69 @@ static int kk_scene_embed_find(const char *sceneId)
...
@@ -1761,7 +1787,69 @@ static int kk_scene_embed_find(const char *sceneId)
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
return
find
;
return
find
;
}
}
/************************************************************
*功能描述:场景使能处理
*输入参数:args:使能参数
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_enableScene_handle
(
const
char
*
args
)
{
if
(
args
==
NULL
){
return
INVALID_PARAMETER
;
}
cJSON
*
json
=
cJSON_Parse
(
args
);
if
(
json
==
NULL
)
{
return
FAIL_RETURN
;
}
INFO_PRINT
(
"kk_scene_invokeService_find args:%s
\n
"
,
args
);
cJSON
*
sceneId
=
cJSON_GetObjectItem
(
json
,
MSG_SCENE_SCENEID
);
if
(
sceneId
==
NULL
)
goto
directReturn
;
cJSON
*
enable
=
cJSON_GetObjectItem
(
json
,
MSG_SCENE_ENABLE
);
if
(
sceneId
==
NULL
)
goto
directReturn
;
kk_scene_update_scene_enable
(
enable
->
valueint
,
sceneId
->
valuestring
);
cJSON_Delete
(
json
);
return
SUCCESS_RETURN
;
directReturn:
cJSON_Delete
(
json
);
return
FAIL_RETURN
;
}
/************************************************************
*功能描述:查找是否有invokeService
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_invokeService_find
(
const
char
*
sceneId
)
{
int
find
=
0
;
char
*
sqlCmd
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlite3_stmt
*
stmt
;
char
*
identifier
=
NULL
;
char
*
args
=
NULL
;
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneInvokeService WHERE sceneId= '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
find
=
1
;
INFO_PRINT
(
"kk_scene_invokeService_find:%s
\n
"
,
sceneId
);
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENEINVOKESERVICE_IDENTIFIER
);
//场景使能控制
if
(
!
strcmp
(
identifier
,
MSG_SCENE_ENABLESCENE
)){
args
=
sqlite3_column_text
(
stmt
,
DB_SCENEINVOKESERVICE_args
);
kk_scene_enableScene_handle
(
args
);
break
;
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
find
;
}
/************************************************************
/************************************************************
*功能描述:查找是否有场景触发
*功能描述:查找是否有场景触发
*输入参数:param:属性CJSON内容
*输入参数:param:属性CJSON内容
...
@@ -1788,7 +1876,6 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -1788,7 +1876,6 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE deviceCode= '%s'"
,
deviceCode
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE deviceCode= '%s'"
,
deviceCode
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_SCENEID
);
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_SCENEID
);
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
compareType
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
compareType
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
...
@@ -1807,9 +1894,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -1807,9 +1894,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
res
=
kk_scene_check_trigger_condition
(
sceneId
);
res
=
kk_scene_check_trigger_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
if
(
res
==
SUCCESS_RETURN
){
/*check是否时场景嵌套类型*/
/*check是否时场景嵌套类型*/
if
(
kk_scene_embed_find
(
sceneId
)
==
0
){
res
=
kk_scene_execute_action
(
sceneId
,
NULL
);
res
=
kk_scene_execute_action
(
sceneId
,
NULL
);
}
}
}
}
}
}
}
...
@@ -1853,12 +1938,12 @@ int kk_scene_execute_scene(const char *sceneId,const char *msgId)
...
@@ -1853,12 +1938,12 @@ int kk_scene_execute_scene(const char *sceneId,const char *msgId)
}
}
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
isEnable
);
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
isEnable
);
if
(
res
==
SUCCESS_RETURN
&&
sceneType
==
DB_SCENETYPE_SCENE
&&
isEnable
){
if
(
res
==
SUCCESS_RETURN
&&
sceneType
==
DB_SCENETYPE_SCENE
&&
isEnable
){
res
=
kk_scene_check_condition
(
sceneId
);
//
res = kk_scene_check_condition(sceneId);
if
(
res
==
SUCCESS_RETURN
){
//
if(res == SUCCESS_RETURN){
_kk_scene_lock
();
_kk_scene_lock
();
res
=
kk_scene_execute_action
(
sceneId
,
msgId
);
res
=
kk_scene_execute_action
(
sceneId
,
msgId
);
_kk_scene_unlock
();
_kk_scene_unlock
();
}
//
}
}
}
INFO_PRINT
(
"[%d]kk_scene_execute_scene called!!!
\n
"
,
__LINE__
);
INFO_PRINT
(
"[%d]kk_scene_execute_scene called!!!
\n
"
,
__LINE__
);
return
res
;
return
res
;
...
...
midware/tsl/tsl_handle/kk_tsl_parse.c
View file @
d138d8c4
...
@@ -631,7 +631,6 @@ static int _kk_tsl_events_parse(_IN_ kk_tsl_t *shadow, _IN_ lite_cjson_t *root)
...
@@ -631,7 +631,6 @@ static int _kk_tsl_events_parse(_IN_ kk_tsl_t *shadow, _IN_ lite_cjson_t *root)
}
else
{
}
else
{
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
INFO_PRINT
(
"event Number: %d
\n
"
);
if
(
lite_events
.
size
==
0
)
{
if
(
lite_events
.
size
==
0
)
{
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -1559,7 +1558,8 @@ int kk_tsl_assemble_property(_IN_ kk_tsl_t *shadow, _IN_ char *identifier, _IN_
...
@@ -1559,7 +1558,8 @@ int kk_tsl_assemble_property(_IN_ kk_tsl_t *shadow, _IN_ char *identifier, _IN_
for
(
index
=
0
;
index
<
shadow
->
event_number
;
index
++
)
{
for
(
index
=
0
;
index
<
shadow
->
event_number
;
index
++
)
{
property
=
shadow
->
events
+
index
;
property
=
shadow
->
events
+
index
;
if
(
strcmp
(
property
->
identifier
,
"property"
)
==
0
||
if
(
strcmp
(
property
->
identifier
,
"property"
)
==
0
||
strcmp
(
property
->
identifier
,
"post"
)
==
0
)
{
strcmp
(
property
->
identifier
,
"post"
)
==
0
)
{
for
(
indexE
=
0
;
indexE
<
property
->
output_data_number
;
indexE
++
){
for
(
indexE
=
0
;
indexE
<
property
->
output_data_number
;
indexE
++
){
output_data
=
property
->
output_datas
+
indexE
;
output_data
=
property
->
output_datas
+
indexE
;
if
((
strlen
(
output_data
->
identifier
)
==
identifier_len
)
&&
if
((
strlen
(
output_data
->
identifier
)
==
identifier_len
)
&&
...
@@ -1704,7 +1704,7 @@ static int _kk_tsl_heartbeat_parse(_OU_ int *heartbeat, _IN_ lite_cjson_t *root)
...
@@ -1704,7 +1704,7 @@ static int _kk_tsl_heartbeat_parse(_OU_ int *heartbeat, _IN_ lite_cjson_t *root)
if
(
res
!=
SUCCESS_RETURN
||
!
lite_cjson_is_string
(
&
lite_item_heartbeat
))
{
if
(
res
!=
SUCCESS_RETURN
||
!
lite_cjson_is_string
(
&
lite_item_heartbeat
))
{
return
JSON_PARSE_FAILED
;
return
JSON_PARSE_FAILED
;
}
}
*
heartbeat
=
atoi
(
lite_item_heartbeat
.
value
)
;
*
heartbeat
=
atoi
(
lite_item_heartbeat
.
value
)
*
2
+
120
;
//一般是心跳时间的2倍再加两分钟
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_tsl_create
(
_IN_
const
char
*
tsl
,
_IN_
int
tsl_len
,
_OU_
kk_tsl_t
**
shadow
,
_OU_
int
*
heartbeat
,
_OU_
int
*
isDormancyDev
)
int
kk_tsl_create
(
_IN_
const
char
*
tsl
,
_IN_
int
tsl_len
,
_OU_
kk_tsl_t
**
shadow
,
_OU_
int
*
heartbeat
,
_OU_
int
*
isDormancyDev
)
...
...
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