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
4d8ccef0
Commit
4d8ccef0
authored
Nov 09, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,增加取反服务调用;2,增加休眠设备的解析
【提交人】陈伟灿
parent
3daecc29
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
634 additions
and
67 deletions
+634
-67
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+3
-3
common/api/com_api.c
common/api/com_api.c
+2
-2
common/api/com_api.h
common/api/com_api.h
+1
-0
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+1
-1
midware/midware/dm/kk_dm_mng.h
midware/midware/dm/kk_dm_mng.h
+1
-0
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+0
-1
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+1
-0
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+28
-2
midware/midware/dm/kk_property_db.c
midware/midware/dm/kk_property_db.c
+25
-0
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+6
-5
midware/midware/midware.c
midware/midware/midware.c
+5
-2
midware/midware/scene/kk_scene_db.c
midware/midware/scene/kk_scene_db.c
+159
-5
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+368
-44
midware/tsl/tsl_handle/kk_tsl_common.h
midware/tsl/tsl_handle/kk_tsl_common.h
+1
-0
midware/tsl/tsl_handle/kk_tsl_parse.c
midware/tsl/tsl_handle/kk_tsl_parse.c
+33
-2
No files found.
application/kcloud/kcloud_data_handle.c
View file @
4d8ccef0
...
...
@@ -43,14 +43,14 @@ const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"
static
char
*
s_split_product
[]
=
{
"85"
,
//三路面板
"
3002"
,
//双路面板
"
97"
,
//双路面板
"3003"
//三路面板
};
static
int
kk_check_need_split
(
cJSON
*
info
)
{
return
0
;
//暂时不用拆分处理
#if
0
//
return 0;//暂时不用拆分处理
#if
1
cJSON
*
productCode
=
NULL
;
int
i
=
0
;
int
num
=
sizeof
(
s_split_product
)
/
sizeof
(
char
*
);
...
...
common/api/com_api.c
View file @
4d8ccef0
...
...
@@ -58,7 +58,7 @@ static char* _parse_data_by_subscribe(char* data, int len, int *outLen, void** c
static
void
watcher_cb
(
struct
ev_loop
*
loop
,
struct
ev_io
*
w
,
int
revents
)
{
INFO_PRINT
(
"watcher_cb !!
\n
"
);
//
INFO_PRINT("watcher_cb !! \n");
//void *user_data = ev_userdata(loop);
Bloop_ctrl_t
*
loop_ctrl
=
(
Bloop_ctrl_t
*
)
w
->
data
;
uint8_t
*
dat
=
NULL
;
...
...
@@ -77,7 +77,7 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents)
return
;
}
INFO_PRINT
(
"watcher_cb:%s
recived
\r\n\r
\n
"
,
(
char
*
)
dat
);
INFO_PRINT
(
"watcher_cb:%s
\n
"
,
(
char
*
)
dat
);
loop_ctrl
->
isconnect
=
1
;
//if sub, need filter sbuscribe str
if
(
IPC_PLAT2MID
==
loop_ctrl
->
type
||
IPC_MID2PLAT
==
loop_ctrl
->
type
){
...
...
common/api/com_api.h
View file @
4d8ccef0
...
...
@@ -93,6 +93,7 @@ typedef enum {
#define MSG_KEYMODIFY_NOTIFICATION "KeyModifyNotification"
/************************SCENE RELATION*************************/
#define MSG_SCENE_NEGATICE "negativeProperty"
#define MSG_SCENE_SUPPORT "sceneSupport"
#define MSG_SCENE_MSGID "msgId"
#define MSG_SCENE_NAME "name"
...
...
midware/midware/dm/kk_dm_mng.c
View file @
4d8ccef0
...
...
@@ -265,7 +265,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA
{
int
heartbeat
=
0
;
kk_msg_parse_productType
(
tsl_str
,
node
->
productType
);
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
node
->
dev_shadow
,
&
heartbeat
);
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
node
->
dev_shadow
,
&
heartbeat
,
&
node
->
dormancyDev
);
free
(
tsl_str
);
if
(
res
!=
0
){
return
FAIL_RETURN
;
...
...
midware/midware/dm/kk_dm_mng.h
View file @
4d8ccef0
...
...
@@ -31,6 +31,7 @@ typedef struct {
char
isOffline
;
int
hb_timeout
;
//heartbeat time
time_t
timestamp
;
char
dormancyDev
;
//1,休眠设备;0,不是
struct
list_head
linked_list
;
}
dm_mgr_dev_node_t
;
...
...
midware/midware/dm/kk_dm_msg.c
View file @
4d8ccef0
...
...
@@ -546,7 +546,6 @@ int dm_msg_request (_IN_ dm_msg_request_t *request,_IN_ int isAsync)
if
(
payload
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
printf
(
"[%s][%d]----request->msgid:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
request
->
msgid
);
memset
(
payload
,
0
,
payload_len
);
snprintf
(
payload
,
payload_len
,
DM_MSG_REQUEST
,
request
->
msgid
,
DM_MSG_VERSION
,
request
->
params
,
HAL_GetTime
(),
request
->
method
);
...
...
midware/midware/dm/kk_dm_msg.h
View file @
4d8ccef0
...
...
@@ -74,6 +74,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_UPDATESCENC "/thing/service/updateScene"
#define KK_THING_SERVICE_PROPERTY_GET_REPLY "/thing/service/property/get_reply"
#define KK_THING_SERVICE_EXECUTESCENE "/thing/service/executeScene"
#define KK_THING_SERVICE_NEGATIVE "/thing/service/negativeProperty"
#define KK_THING_METHOD_DELETESCENC "thing.service.deleteScene"
#define KK_THING_METHOD_UPDATESCENC "thing.service.updateScene"
#define KK_THING_METHOD_EXECUTESCENE "thing.service.executeScene"
...
...
midware/midware/dm/kk_linkkit.c
View file @
4d8ccef0
...
...
@@ -848,6 +848,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
kk_service_executeRoom_handle
(
paramStr
);
}
#if 0
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_SETLOCALTIMER) == 0){
INFO_PRINT(" setlocaltimer \n");
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
...
...
@@ -888,7 +889,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
kk_service_deleteKey_handle(deviceCode->valuestring,paramStr);
}
}
#endif
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_ADDSCENC
)
==
0
){
INFO_PRINT
(
" add scene
\n
"
);
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
...
...
@@ -912,7 +914,31 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
cJSON
*
msgId
=
cJSON_GetObjectItem
(
payload
,
MSG_SCENE_MSGID
);
kk_service_executeScene_handle
(
deviceCode
->
valuestring
,
paramStr
,
msgId
);
}
}
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_NEGATIVE
)
==
0
){
INFO_PRINT
(
"negative service
\n
"
);
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
if
(
paramStr
!=
NULL
){
cJSON
*
identifierStr
=
cJSON_GetObjectItem
(
paramStr
,
MSG_SCENE_NEGATICE
);
if
(
identifierStr
!=
NULL
){
int
value_
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_property_db_get_value
(
deviceCode
->
valuestring
,
identifierStr
->
valuestring
,
4
,
&
value_
);
value_
=
!
value_
;
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
directReturn
;
}
cJSON
*
root_
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
root_
,
identifierStr
->
valuestring
,
value_
);
char
*
out_
=
cJSON_Print
(
root_
);
kk_msg_execute_property_set
(
node
->
productCode
,
node
->
deviceCode
,
out_
,
node
->
fatherDeviceCode
);
cJSON_Delete
(
root_
);
free
(
out_
);
}
}
}
else
{
INFO_PRINT
(
"Error msgtype!!!
\n
"
);
...
...
midware/midware/dm/kk_property_db.c
View file @
4d8ccef0
...
...
@@ -205,6 +205,31 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co
return
SUCCESS_RETURN
;
}
int
kk_property_db_get_value_directly
(
const
char
*
deviceCode
,
const
char
*
identifier
,
char
*
value
)
{
char
*
sqlCmd
=
NULL
;
int
rc
=
0
;
char
*
zErrMsg
=
0
;
sqlite3_stmt
*
stmt
;
char
*
valueStr
=
NULL
;
kk_property_db_ctx_t
*
ctx
=
_kk_property_db_get_ctx
();
_kk_property_db_lock
();
sqlCmd
=
sqlite3_mprintf
(
"select * from PropertiesInfo WHERE deviceCode= '%s' and identifier = '%s'"
,
deviceCode
,
identifier
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
valueStr
=
sqlite3_column_text
(
stmt
,
DB_VALUE
);
printf
(
"valueStr:%s
\n
"
,
valueStr
);
memcpy
(
value
,
valueStr
,
strlen
(
valueStr
));
printf
(
"value:%s
\n
"
,
value
);
}
sqlite3_free
(
sqlCmd
);
_kk_property_db_unlock
();
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
int
kk_property_db_get_value
(
const
char
*
deviceCode
,
const
char
*
identifier
,
void
*
value
)
{
char
*
sqlCmd
=
NULL
;
...
...
midware/midware/dm/kk_sub_db.c
View file @
4d8ccef0
...
...
@@ -385,9 +385,10 @@ int kk_subDev_send_property_get(const char *fatherDeviceCode)
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
continue
;
}
//if(!strcmp(pDeviceCode,"842E14FFFE9A26CA")){
//continue;
//}
/*休眠设备,不需要下发获取属性*/
if
(
node
->
dormancyDev
){
continue
;
}
/*发送之前先置为KK_DEV_UNKNOW*/
node
->
isOffline
=
KK_DEV_UNKNOW
;
kk_msg_execute_property_get
(
node
);
...
...
@@ -422,12 +423,12 @@ int kk_subDev_check_scene_support(const char *deviceCode)
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
pDeviceCode
=
sqlite3_column_text
(
stmt
,
DB_DEVICECODE
);
if
(
!
strcmp
(
deviceCode
,
pDeviceCode
))
{
return
1
;
res
=
1
;
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
0
;
return
res
;
}
int
kk_subDev_set_action_by_productType
(
const
char
*
productType
,
const
char
*
sceneId
,
const
char
*
propertyName
,
const
char
*
propertyValue
,
const
char
*
type
)
...
...
midware/midware/midware.c
View file @
4d8ccef0
...
...
@@ -30,6 +30,7 @@ char * g_filerToPlatTable[] =
{
KK_LOGIN_TOPIC_REPLY
},
{
KK_THING_SERVICE_PROPERTY_GET
},
{
KK_THING_CLOUDSTATE_MSG
},
#if 0
{KK_THING_SERVICE_SETLOCALTIMER},
{KK_THING_SERVICE_GETLOCALTIMER},
{KK_THING_SERVICE_SETCOUNTDOWN},
...
...
@@ -37,9 +38,11 @@ char * g_filerToPlatTable[] =
{KK_THING_SERVICE_ADDKEY},
{KK_THING_SERVICE_DELETEKEY},
{KK_THING_SERVICE_MODIFYKEY},
#endif
{
KK_THING_SERVICE_ADDSCENC
},
{
KK_THING_SERVICE_UPDATESCENC
},
{
KK_THING_SERVICE_DELETESCENC
},
{
KK_THING_SERVICE_DELETESCENC
},
{
KK_THING_SERVICE_NEGATIVE
},
};
static
int
_kk_filter_to_plat
(
const
char
*
msgtype
)
{
...
...
@@ -522,7 +525,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
}
}
else
{
INFO_PRINT
(
"kk_platMsg_handle data: don't handle it
[%s]
\n
"
,
data
);
INFO_PRINT
(
"kk_platMsg_handle data: don't handle it
\n
"
);
}
error:
...
...
midware/midware/scene/kk_scene_db.c
View file @
4d8ccef0
/************************************************************
*版权所有 (C)2020,公司(或个人)名称
*
*文件名称: kk_scene.db.c
*内容摘要: 场景功能数据库处理
*其他说明:
*当前版本:
*************************************************************/
/*************************************************************
头文件引用
*************************************************************/
#include <stdio.h>
#include "kk_tsl_api.h"
#include "sqlite3.h"
#include "kk_log.h"
#include "kk_scene_handle.h"
/*************************************************************
全局变量定义
*************************************************************/
extern
sqlite3
*
g_kk_pDb
;
/*************************************************************
函数实现
*************************************************************/
int
kk_scene_db_init
(
void
)
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
pcErr
;
/************************************************************
*功能描述: 场景数据库初始化
*输入参数: 无
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
//eUtils_LockLock(&sLock);
_kk_scene_lock
();
...
...
@@ -107,7 +139,7 @@ int kk_scene_db_init(void)
executeSceneId varchar(255), \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pScene
Timer
Table
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
if
(
sqlite3_exec
(
ctx
->
pDb
,
pScene
Embed
Table
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
...
...
@@ -119,6 +151,14 @@ int kk_scene_db_init(void)
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 场景使能位更新
*输入参数: sceneId:场景Id
enable: 1,使能;0,不使能
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_update_scene_enable
(
int
enable
,
const
char
*
sceneId
)
{
...
...
@@ -143,6 +183,17 @@ int kk_scene_update_scene_enable(int enable,const char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加场景信息到数据库
*输入参数: name:场景名称
enable: 1,使能;0,不使能
sceneType:场景类型
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_info
(
const
char
*
name
,
const
char
*
sceneType
,
const
char
*
enable
,
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -197,6 +248,20 @@ static int kk_scene_check_trigger_exist(const char* type,const char* deviceCode,
}
#endif
/************************************************************
*功能描述: 添加场景触发信息到数据库
*输入参数: type:类型
deviceCode:设备deviceCode
epNum: 设备路数
propertyName:属性名称
compareType:比对符号
compareValue:value值
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_trigger
(
const
char
*
type
,
const
char
*
deviceCode
,
const
char
*
epNum
,
const
char
*
propertyName
,
const
char
*
compareType
,
const
char
*
compareValue
,
const
char
*
sceneId
)
{
...
...
@@ -224,6 +289,18 @@ int kk_scene_insert_scene_trigger(const char* type,const char* deviceCode,const
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加场景时间触发条件到数据库
*输入参数: type:类型
startTime:开始时间
endTime:结束时间
crossDay:是否跨天
repeat_days: 重复星期
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_condition
(
const
char
*
type
,
int
startTime
,
int
endTime
,
int
crossDay
,
char
repeat_days
,
const
char
*
sceneId
)
...
...
@@ -253,6 +330,15 @@ int kk_scene_insert_scene_condition(const char* type,int startTime,int endTime,i
}
/************************************************************
*功能描述: 添加定时场景信息到数据库
*输入参数:startTime:开始时间
weekflag: 重复星期
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_timer
(
time_t
startTime
,
char
weekflag
,
const
char
*
sceneId
)
{
...
...
@@ -280,6 +366,15 @@ int kk_scene_insert_scene_timer(time_t startTime,char weekflag,const char* scene
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加嵌套场景信息到数据库
*输入参数:executeSceneId:要执行的场景Id
delay: 延迟时间
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_embed
(
int
delay
,
const
char
*
executeSceneId
,
const
char
*
sceneId
)
{
...
...
@@ -307,6 +402,20 @@ int kk_scene_insert_scene_embed(int delay,const char* executeSceneId,const char*
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加场景执行动作到数据库
*输入参数:type:类型
deviceCode:设备deviceCode
epNum: 设备路数
propertyName:属性名称
delay:延迟时间
compareValue:value值
sceneId:场景Id
gwdeviceCode:网关deviceCode
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_scene_action
(
const
char
*
type
,
const
char
*
deviceCode
,
int
epNum
,
const
char
*
propertyName
,
const
char
*
propertyValue
,
int
delay
,
const
char
*
sceneId
,
const
char
*
gwdeviceCode
)
...
...
@@ -335,6 +444,14 @@ int kk_scene_insert_scene_action(const char* type,const char* deviceCode,int epN
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除场景的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_info
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -357,6 +474,14 @@ int kk_scene_delete_scene_info(const char *sceneId)
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除场景触发的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_trigger
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -379,6 +504,13 @@ int kk_scene_delete_scene_trigger(const char *sceneId)
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除场景触发条件的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_condition
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -401,7 +533,13 @@ int kk_scene_delete_scene_condition(const char *sceneId)
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除定时场景的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_timing
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -424,7 +562,13 @@ int kk_scene_delete_scene_timing(const char *sceneId)
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除嵌套场景的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_embed
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -448,8 +592,16 @@ int kk_scene_delete_scene_embed(const char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除场景执行动作的基本数据
*输入参数: sceneId:场景Id
isforword:1,updateScene;0,addScene;
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_action
(
const
char
*
sceneId
)
int
kk_scene_delete_scene_action
(
const
char
*
sceneId
,
int
isforword
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
...
@@ -457,7 +609,9 @@ int kk_scene_delete_scene_action(const char *sceneId)
char
*
zErrMsg
=
0
;
sqlite3_stmt
*
stmt
;
kk_scene_delete_send_to_gw
(
sceneId
);
if
(
isforword
){
kk_scene_delete_send_to_gw
(
sceneId
);
}
const
char
*
deleteCmd
=
"delete from SceneActionInfo where sceneId = '%s';"
;
_kk_scene_lock
();
...
...
midware/midware/scene/kk_scene_handle.c
View file @
4d8ccef0
/******************************************************************************/
/* */
/* 文件名: 版本 */
/* */
/* kk_scene_handle.c V1.0 */
/* */
/* 功能描述: */
/* 该文件包含了和场景设置服务相关的代码 */
/* */
/* 更改记录: */
/* */
/* 日期 作者 摘要 */
/* */
/* */
/* */
/******************************************************************************/
/************************************************************
*版权所有 (C)2020,公司(或个人)名称
*
*文件名称: kk_scene_handle.c
*内容摘要: 场景功能数据解析和逻辑处理
*其他说明:
*当前版本:
*************************************************************/
/*************************************************************
头文件引用
*************************************************************/
#include <stdio.h>
#include "kk_tsl_api.h"
...
...
@@ -25,9 +20,13 @@
#include <time.h>
/*************************************************************
全局变量定义
*************************************************************/
extern
int
g_timezone
;
static
void
kk_scene_send_action_msg
(
kk_scene_action_info_t
*
pInfo
);
static
int
kk_scene_update_starttime
(
kk_scene_timer_list_t
*
pInfo
,
int
starttime
,
in
t
current
);
static
int
kk_scene_update_starttime
(
kk_scene_timer_list_t
*
pInfo
,
time_
t
current
);
static
time_t
kk_scene_creat_timer_starttime
(
int
week
,
int
starttime
,
time_t
current
);
static
int
kk_scene_parse_repeatday
(
cJSON
*
repeatday
);
static
kk_scene_action_delay_t
*
p_delay_action_list
=
NULL
;
...
...
@@ -37,6 +36,9 @@ extern uint64_t s_start_time;
static
kk_scene_action_t
*
p_kk_scene_action
=
NULL
;
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
/*************************************************************
函数实现
*************************************************************/
static
int
kk_scene_check_value_ex
(
const
char
*
compareType
,
const
char
*
compareValue1
,
const
char
*
compareValue2
)
{
...
...
@@ -137,6 +139,12 @@ static int kk_scene_timer_check_able(char *sceneId)
}
return
FAIL_RETURN
;
}
/******************************************************************************/
/* 函 数 名: kk_scene_timer_load */
/* 描 述: 时场景定时信息加载 */
/* 输入参数: 无 */
/* 返 回 值: 返回'0'表示成功,其它返回值表示出错号 */
/******************************************************************************/
static
int
kk_scene_timer_load
(
void
)
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
...
@@ -163,7 +171,13 @@ kk_tsl_t * kk_scene_shadow(void)
return
s_scene_shadow
;
}
/************************************************************
*功能描述: 定时场景和延时功能的处理
*输入参数: args传入参数
*输出参数: 无
*返 回 值: 无
*其他说明:
*************************************************************/
void
*
kk_scene_yield
(
void
*
args
)
{
time_t
current_time
=
0
;
...
...
@@ -246,7 +260,7 @@ void *kk_scene_yield(void *args)
INFO_PRINT
(
"current_time %d
\n
"
,
current_time
);
if
(
scene_timer_list
->
starttime
!=
0
&&
current_time
>=
scene_timer_list
->
starttime
){
kk_scene_execute_action
(
scene_timer_list
->
sceneId
);
kk_scene_update_starttime
(
scene_timer_list
,
scene_timer_list
->
starttime
,
current_time
);
kk_scene_update_starttime
(
scene_timer_list
,
current_time
);
}
scene_timer_list
=
scene_timer_list
->
next
;
}
...
...
@@ -257,6 +271,14 @@ void *kk_scene_yield(void *args)
return
NULL
;
}
/************************************************************
*功能描述: 场景模块的初始化,包括数据库的初始化
*输入参数: 无
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_init
(
void
)
{
int
res
=
0
;
...
...
@@ -286,6 +308,7 @@ int kk_scene_init(void)
return
SUCCESS_RETURN
;
}
static
int
kk_scene_action_info_add
(
kk_scene_action_info_ex_t
**
head
,
kk_scene_action_detail_t
detail
)
{
int
len
;
...
...
@@ -315,6 +338,15 @@ static int kk_scene_action_info_add(kk_scene_action_info_ex_t **head,kk_scene_ac
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加场景action到action队列
*输入参数: gwdeviceCode:网关devieCode;
sceneId:场景Id;
detail:具体action内容
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_action_add
(
const
char
*
gwdeviceCode
,
const
char
*
sceneId
,
kk_scene_action_detail_t
detail
)
{
int
len
;
...
...
@@ -352,6 +384,13 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:释放action队列
*输入参数:无
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_action_free
(
void
)
{
int
len
;
...
...
@@ -378,6 +417,33 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:删除数据库中的场景数据
*输入参数:sceneId:要删除的场景Id;
isforword:是否要往网关转发删除消息,1:转发;0:不转发
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
static
void
kk_scene_delete
(
char
*
sceneId
,
int
isforword
)
{
kk_scene_remove_timer_info
(
sceneId
);
kk_scene_delete_scene_timing
(
sceneId
);
kk_scene_delete_scene_embed
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_action
(
sceneId
,
isforword
);
}
/************************************************************
*功能描述:发送删除消息给网关
*输入参数:sceneId:要删除的场景Id;
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_send_to_gw
(
const
char
*
sceneId
)
{
char
gwdevice
[][
DEVICE_CODE_MAXLEN
]
=
{
0
};
...
...
@@ -418,6 +484,13 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
res
;
}
/************************************************************
*功能描述:发送场景action信息给网关,在添加场景时调用
*输入参数:isUpdate:1,updateScene;0,addScene
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_action_info_send
(
int
isUpdate
)
{
...
...
@@ -455,6 +528,16 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:发送场景多控信息给网关,在添加场景时调用
*输入参数:action:具体内容;
gwdeviceCode:对应网关deviceCode;
sceneId:场景Id
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_muticontrol_info_send
(
cJSON
*
action
,
const
char
*
gwdeviceCode
,
const
char
*
sceneId
)
{
if
(
action
==
NULL
||
gwdeviceCode
==
NULL
||
sceneId
==
NULL
){
...
...
@@ -470,6 +553,15 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
free
(
out
);
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析场景触发条件的具体内容,解析后保存到数据库
*输入参数:type:触发类型;
item:触发内容的CJSON字串;
sceneId:场景Id
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_parse_trigger_detail
(
const
char
*
type
,
const
cJSON
*
item
,
const
char
*
sceneId
)
{
...
...
@@ -495,7 +587,14 @@ static int kk_scene_parse_trigger_detail(const char *type,const cJSON *item,cons
return
res
;
}
/************************************************************
*功能描述:解析场景触发条件
*输入参数:str:触发内容的CJSON字串;
sceneId:场景Id
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_scene_trigger
(
const
cJSON
*
str
,
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
@@ -535,6 +634,15 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
INFO_PRINT
(
"kk_scene_parse_scene_trigger success!!!
\n
"
);
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析重复星期
*输入参数:repeatday:重复星期的CJSON内容;
*输出参数:无
*返 回 值: 重复星期内容,每位代表一个星期,最低位代表星期一
weekflag 01111111 ---> week 7 6 5 4 3 2 1
*其他说明:
*************************************************************/
static
int
kk_scene_parse_repeatday
(
cJSON
*
repeatday
)
{
/***weekflag 01111111 ---> week 7 6 5 4 3 2 1*/
...
...
@@ -559,6 +667,14 @@ static int kk_scene_parse_repeatday(cJSON *repeatday)
return
weekflag
;
}
/************************************************************
*功能描述:移除定时信息
*输入参数:sceneId:对应场景Id;
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
kk_scene_remove_timer_info
(
char
*
sceneId
)
{
kk_scene_timer_list_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
...
...
@@ -586,6 +702,16 @@ void kk_scene_remove_timer_info(char *sceneId)
_kk_scene_unlock
();
}
/************************************************************
*功能描述:添加定时信息到队列
*输入参数:sceneId:对应场景Id;
starttime:开始时间(Unix时间戳)
repeatday:重复星期
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_push_timer_info
(
time_t
starttime
,
int
repeatday
,
char
*
sceneId
)
{
kk_scene_timer_list_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
...
...
@@ -617,6 +743,15 @@ int kk_scene_push_timer_info(time_t starttime,int repeatday,char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析触发条件
*输入参数:sceneId:对应场景Id;
str:触发条件的CJSON字串
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_scene_condition
(
const
cJSON
*
str
,
const
char
*
sceneId
)
{
char
weekflag
=
0
;
...
...
@@ -663,6 +798,16 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析执行动作
*输入参数:sceneId:对应场景Id;
str:执行动作的CJSON字串
isUpdate:1,updateScene;0,addScene
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_scene_action
(
const
cJSON
*
str
,
const
char
*
sceneId
,
int
isUpdate
)
{
int
res
=
0
;
...
...
@@ -680,7 +825,7 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
if
(
type
==
NULL
)
return
FAIL_RETURN
;
/*内嵌场景设置*/
if
(
type
->
valuestring
==
"action/scene"
)
if
(
!
strcmp
(
type
->
valuestring
,
"action/scene"
)
)
{
cJSON
*
delay
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_DELAY
);
if
(
delay
==
NULL
)
return
FAIL_RETURN
;
...
...
@@ -740,6 +885,15 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
}
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析多控
*输入参数:sceneId:对应场景Id;
str:多控的CJSON字串
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_scene_muticontrol
(
const
cJSON
*
str
,
const
char
*
sceneId
)
{
...
...
@@ -773,6 +927,15 @@ int kk_scene_parse_scene_muticontrol(const cJSON* str,const char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:解析添加场景的消息
*输入参数:sceneId:对应场景Id;
args:场景的CJSON字串
isUpdate:1,updateScene;0,addScene
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_addscene
(
const
cJSON
*
args
,
char
*
sceneId
,
int
isUpdate
)
{
...
...
@@ -817,21 +980,23 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
res
=
kk_scene_parse_scene_action
(
args
,
sceneId
,
isUpdate
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_scene_parse_scene_action failed
\n
"
);
kk_scene_delete
(
sceneId
,
0
);
return
FAIL_RETURN
;
}
}
return
SUCCESS_RETURN
;
}
static
void
kk_scene_delete
(
char
*
sceneId
)
{
kk_scene_remove_timer_info
(
sceneId
);
kk_scene_delete_scene_timing
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_action
(
sceneId
);
}
/************************************************************
*功能描述:解析场景更新的消息
*输入参数:sceneId:对应场景Id;
args:场景的CJSON字串
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_updatescene
(
const
cJSON
*
arg
,
char
*
sceneId
)
{
...
...
@@ -839,9 +1004,17 @@ int kk_scene_parse_updatescene(const cJSON* arg,char *sceneId)
ERROR_PRINT
(
"[%d]kk_scene_parse_addscene fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
}
kk_scene_delete
(
sceneId
);
kk_scene_delete
(
sceneId
,
0
);
return
kk_scene_parse_addscene
(
arg
,
sceneId
,
1
);
}
/************************************************************
*功能描述:解析删除场景的消息
*输入参数:sceneId:对应场景Id;
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_parse_deletescene
(
char
*
sceneId
)
{
...
...
@@ -849,9 +1022,17 @@ int kk_scene_parse_deletescene(char *sceneId)
ERROR_PRINT
(
"[%d]kk_scene_parse_deletescene fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
}
kk_scene_delete
(
sceneId
);
kk_scene_delete
(
sceneId
,
1
);
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:从数据库获取场景信息
*输入参数:sceneId:对应场景Id;
*输出参数:sceneType:场景类型
enable:场景是否使能
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_get_scene_info
(
const
char
*
sceneId
,
int
*
sceneType
,
int
*
enable
)
{
...
...
@@ -870,13 +1051,29 @@ int kk_scene_get_scene_info(const char* sceneId,int *sceneType,int *enable)
sqlite3_free
(
sqlCmd
);
return
res
;
}
/************************************************************
*功能描述:通过时间获取星期
*输入参数:t:当前时间
*输出参数:无
*返 回 值: 1-7,代表星期一~星期七
*其他说明:
*************************************************************/
static
char
kk_scene_date_to_week
(
time_t
t
)
{
struct
tm
*
p
=
localtime
(
&
t
);
INFO_PRINT
(
"kk_scene_date_to_week t p->tm_wday:%d
\n
"
,
p
->
tm_wday
);
return
((
p
->
tm_wday
==
0
)
?
7
:
p
->
tm_wday
);
}
static
int
kk_scene_update_starttime
(
kk_scene_timer_list_t
*
pInfo
,
int
starttime
,
int
current
)
/************************************************************
*功能描述:更新开始时间
*输入参数:pInfo:定时场景队列
current:当前时间
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_update_starttime
(
kk_scene_timer_list_t
*
pInfo
,
time_t
current
)
{
char
curWeek
=
0
;
char
i
=
0
;
...
...
@@ -908,17 +1105,26 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
}
/************************************************************
*功能描述:创建新的开始时间
*输入参数:starttime:开始时间(一天内的秒数)
current:当前时间
*输出参数:无
*返 回 值:新的开始时间(Unix时间戳)
*其他说明:
*************************************************************/
static
time_t
kk_scene_creat_new_starttime
(
time_t
starttime
,
time_t
current
)
{
int
hour
,
min
,
sec
;
time_t
newTime
=
0
;
printf
(
"[%d]startTime :%d
\n
"
,
__LINE__
,
starttime
);
INFO_PRINT
(
"[%d]startTime :%d
\n
"
,
__LINE__
,
starttime
);
hour
=
starttime
/
3600
;
min
=
starttime
%
3600
/
60
;
printf
(
"[hour:%d][min:%d]
\n
"
,
hour
,
min
);
INFO_PRINT
(
"[hour:%d][min:%d]
\n
"
,
hour
,
min
);
struct
tm
*
c
=
localtime
(
&
current
);
c
->
tm_hour
=
hour
;
c
->
tm_min
=
min
;
...
...
@@ -927,6 +1133,16 @@ static time_t kk_scene_creat_new_starttime(time_t starttime,time_t current)
INFO_PRINT
(
"kk_scene_creat_new_starttime:%ld
\n
"
,
newTime
);
return
newTime
;
}
/************************************************************
*功能描述:创建新的定时开始时间
*输入参数:starttime:开始时间(一天内的秒数)
current:当前时间
week:重复星期
*输出参数:无
*返 回 值:新的开始时间(Unix时间戳)
*其他说明:
*************************************************************/
static
time_t
kk_scene_creat_timer_starttime
(
int
week
,
int
starttime
,
time_t
current
)
{
int
hour
,
min
,
sec
;
...
...
@@ -961,6 +1177,14 @@ static time_t kk_scene_creat_timer_starttime(int week,int starttime,time_t curre
}
}
/************************************************************
*功能描述:判断属性限制条件
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:符合;其他:不符合
*其他说明:
*************************************************************/
int
kk_scene_check_trigger_condition
(
const
char
*
sceneId
)
{
int
res
=
FAIL_RETURN
;
...
...
@@ -987,7 +1211,7 @@ int kk_scene_check_trigger_condition(const char *sceneId)
compareValue
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPAREVALUE
);
kk_property_db_get_value_directly
(
pdeviceCode
,
identifier
,
currentValue
);
printf
(
"currentValue:%s
\n
"
,
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
){
...
...
@@ -1006,7 +1230,13 @@ int kk_scene_check_trigger_condition(const char *sceneId)
return
res
;
}
/************************************************************
*功能描述:判断时间限制条件
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:符合;其他:不符合
*其他说明:
*************************************************************/
int
kk_scene_check_condition
(
const
char
*
sceneId
)
{
int
res
=
FAIL_RETURN
;
...
...
@@ -1035,10 +1265,17 @@ int kk_scene_check_condition(const char *sceneId)
startTime
=
(
startTime
-
86400
)
>=
0
?
(
startTime
-
86400
)
:
startTime
;
endTime
=
endTime
+
g_timezone
*
3600
;
endTime
=
(
endTime
-
86400
)
>=
0
?
(
endTime
-
86400
)
:
endTime
;
duration
=
endTime
-
startTime
;
INFO_PRINT
(
"[endTime:%d][startTime:%d]
\n
"
,
endTime
,
startTime
);
if
(
endTime
<
startTime
){
duration
=
86400
-
(
startTime
-
endTime
);
crossDay
=
1
;
}
else
{
duration
=
endTime
-
startTime
;
crossDay
=
0
;
}
startTime_m
=
kk_scene_creat_new_starttime
(
startTime
,
current
);
INFO_PRINT
(
"current:%ld,startTime_m:%ld,repeatday:%d
\n
"
,
current
,
startTime_m
,
repeatday
);
INFO_PRINT
(
"current:%ld,startTime_m:%ld,repeatday:%d
,duration:%d
\n
"
,
current
,
startTime_m
,
repeatday
,
duration
);
/********check today is one of repeatday**************/
if
((
repeatday
>
0
)
&&
(
repeatday
&
(
1
<<
(
curWeek
-
1
)))){
if
(
crossDay
&&
current
<
startTime_m
){
...
...
@@ -1088,6 +1325,17 @@ int kk_scene_check_condition(const char *sceneId)
}
/************************************************************
*功能描述:判断value值是否符合条件
*输入参数:compareType:比对符号
compareValue:比对值
item:当前值的CJSON字串
valueType:比对值的数据类型
*输出参数:无
*返 回 值:0:符合;其他:不符合
*其他说明:
*************************************************************/
static
int
kk_scene_check_value
(
const
char
*
compareType
,
const
char
*
compareValue
,
cJSON
*
item
,
int
valueType
)
{
int
res
=
FAIL_RETURN
;
...
...
@@ -1184,6 +1432,14 @@ static int kk_scene_check_value(const char * compareType,const char * compareVal
return
res
;
}
/************************************************************
*功能描述:发送action内容到网关,此函数只有不支持内场景的网关用到
*输入参数:pInfo:action内容
*输出参数:无
*返 回 值:无
*其他说明:
*************************************************************/
static
void
kk_scene_send_action_msg
(
kk_scene_action_info_t
*
pInfo
)
{
int
ivalue
=
0
;
...
...
@@ -1198,7 +1454,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
if
(
valueType
<
0
){
ERROR_PRINT
(
"[%d]kk_scene_send_action_msg valueType < 0!!!
\n
"
,
__LINE__
);
free
(
pInfo
);
return
0
;
return
;
}
switch
(
valueType
){
case
KK_TSL_DATA_TYPE_INT
:
...
...
@@ -1225,6 +1481,15 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
free
(
pInfo
);
return
;
}
/************************************************************
*功能描述:添加action到队列,此函数只有不支持内场景的网关用到
*输入参数:actionInfo:action内容
delay:需要延时的秒数
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_push_action_list
(
kk_scene_action_info_t
*
actionInfo
,
int
delay
)
{
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
...
...
@@ -1251,6 +1516,17 @@ static int kk_scene_push_action_list(kk_scene_action_info_t *actionInfo,int dela
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:开始执行action,此函数只有不支持内场景的网关用到
*输入参数:deviceCode:deviceCode
propertyName:identifier属性名称
valueS:value值
delay:需要延时的秒数
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_start_action
(
const
char
*
deviceCode
,
const
char
*
propertyName
,
const
char
*
valueS
,
int
delay
)
{
int
res
=
0
;
...
...
@@ -1288,6 +1564,14 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
}
/************************************************************
*功能描述:触发完成并符合条件后调用此函数执行场景
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_execute_action
(
const
char
*
sceneId
)
{
int
res
=
FAIL_RETURN
;
...
...
@@ -1335,6 +1619,14 @@ next:
return
res
;
}
/************************************************************
*功能描述:添加嵌套场景到队列
*输入参数:sceneId:场景Id
delay:延时时间
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_push_embed_list
(
int
delay
,
const
char
*
sceneId
)
{
if
(
sceneId
==
NULL
){
...
...
@@ -1363,6 +1655,13 @@ static int kk_scene_push_embed_list(int delay,const char* sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:查找是否有场景嵌套
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_scene_embed_find
(
const
char
*
sceneId
)
{
int
find
=
0
;
...
...
@@ -1374,6 +1673,7 @@ static int kk_scene_embed_find(const char *sceneId)
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
INFO_PRINT
(
"kk_scene_embed_find:%s
\n
"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneEmbedInfo WHERE sceneId= '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
...
...
@@ -1393,6 +1693,14 @@ static int kk_scene_embed_find(const char *sceneId)
return
find
;
}
/************************************************************
*功能描述:查找是否有场景触发
*输入参数:param:属性CJSON内容
deviceCode:对应设备的deviceCode
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
int
res
=
FAIL_RETURN
;
...
...
@@ -1427,7 +1735,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
if
(
res
==
SUCCESS_RETURN
){
res
=
kk_scene_check_trigger_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
/*check是否时
内嵌场景
*/
/*check是否时
场景嵌套类型
*/
if
(
kk_scene_embed_find
(
sceneId
)
==
0
){
res
=
kk_scene_execute_action
(
sceneId
);
}
...
...
@@ -1442,12 +1750,28 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlite3_free
(
sqlCmd
);
return
res
;
}
/************************************************************
*功能描述:IFTT场景检测
*输入参数:param:属性CJSON内容
deviceCode:对应设备的deviceCode
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_iftt_check
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
printf
(
"[%s][%d] deviceCode:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
deviceCode
);
INFO_PRINT
(
"deviceCode:%s
\n
"
,
deviceCode
);
return
kk_scene_query_trigger_info
(
deviceCode
,
param
);
}
/************************************************************
*功能描述:手动场景执行
*输入参数:sceneId:场景Id
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_execute_scene
(
const
char
*
sceneId
)
{
int
res
=
0
;
...
...
midware/tsl/tsl_handle/kk_tsl_common.h
View file @
4d8ccef0
...
...
@@ -58,6 +58,7 @@
#define KK_TSL_KEY_SIZE "size"
#define KK_TSL_KEY_ITEM "item"
#define KK_TSL_KEY_HEARTBEAT "heartbeat"
#define KK_TSL_KEY_SLEEPTIME "sleepTime"
#define KK_MSG_KEY_DELIMITER '.'
#define KK_URI_SERVICE_DELIMITER '/'
...
...
midware/tsl/tsl_handle/kk_tsl_parse.c
View file @
4d8ccef0
...
...
@@ -1646,7 +1646,37 @@ int kk_tsl_assemble_service_output(_IN_ kk_tsl_t *shadow, _IN_ char *identifier,
return
SUCCESS_RETURN
;
}
/******************************************************************************/
/* 函 数 名: _kk_tsl_sleeptime_parse */
/* 描 述: 解析是否是休眠设备 */
/* 输入参数: root: 物模型字串 */
/* 返 回 值: 返回0表示否,1表示是 */
/******************************************************************************/
static
int
_kk_tsl_sleeptime_parse
(
_IN_
lite_cjson_t
*
root
)
{
int
res
=
0
;
lite_cjson_t
lite_item
;
lite_cjson_t
lite_item_sleeptime
;
//Parse Identifier (Mandatory)
memset
(
&
lite_item
,
0
,
sizeof
(
lite_cjson_t
));
res
=
lite_cjson_object_item
(
root
,
KK_TSL_KEY_PROFILE
,
strlen
(
KK_TSL_KEY_PROFILE
),
&
lite_item
);
if
(
res
!=
SUCCESS_RETURN
||
!
lite_cjson_is_object
(
&
lite_item
))
{
return
0
;
}
res
=
lite_cjson_object_item
(
&
lite_item
,
KK_TSL_KEY_SLEEPTIME
,
strlen
(
KK_TSL_KEY_SLEEPTIME
),
&
lite_item_sleeptime
);
if
(
res
!=
SUCCESS_RETURN
||
!
lite_cjson_is_string
(
&
lite_item_sleeptime
))
{
return
0
;
}
return
1
;
}
/******************************************************************************/
/* 函 数 名: _kk_tsl_heartbeat_parse */
/* 描 述: 解析心跳时间 */
/* 输入参数: root: 物模型字串 */
/* 输出参数: heartbeat: 心跳时间 */
/* 返 回 值: 返回0表示成功,其他表示失败 */
/******************************************************************************/
static
int
_kk_tsl_heartbeat_parse
(
_OU_
int
*
heartbeat
,
_IN_
lite_cjson_t
*
root
)
{
int
res
=
0
;
...
...
@@ -1666,7 +1696,7 @@ static int _kk_tsl_heartbeat_parse(_OU_ int *heartbeat, _IN_ lite_cjson_t *root)
*
heartbeat
=
atoi
(
lite_item_heartbeat
.
value
);
return
SUCCESS_RETURN
;
}
int
kk_tsl_create
(
_IN_
const
char
*
tsl
,
_IN_
int
tsl_len
,
_OU_
kk_tsl_t
**
shadow
,
_OU_
int
*
heartbeat
)
int
kk_tsl_create
(
_IN_
const
char
*
tsl
,
_IN_
int
tsl_len
,
_OU_
kk_tsl_t
**
shadow
,
_OU_
int
*
heartbeat
,
_OU_
int
*
isDormancyDev
)
{
int
res
=
0
;
lite_cjson_t
lite_root
;
...
...
@@ -1689,6 +1719,7 @@ int kk_tsl_create(_IN_ const char *tsl, _IN_ int tsl_len, _OU_ kk_tsl_t **shadow
free
(
*
shadow
);
return
JSON_PARSE_FAILED
;
}
*
isDormancyDev
=
_kk_tsl_sleeptime_parse
(
&
lite_root
);
// Parse heartbeat time
_kk_tsl_heartbeat_parse
(
heartbeat
,
&
lite_root
);
...
...
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