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
4b30d68d
Commit
4b30d68d
authored
Oct 20, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】测试定时模式的场景并调整scene相关代码
【提交人】陈伟灿
parent
aa3d17c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
32 deletions
+98
-32
midware/midware/area/kk_area_handle.c
midware/midware/area/kk_area_handle.c
+3
-6
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+2
-5
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+93
-21
No files found.
midware/midware/area/kk_area_handle.c
View file @
4b30d68d
...
@@ -117,21 +117,18 @@ int kk_area_init(void)
...
@@ -117,21 +117,18 @@ int kk_area_init(void)
}
}
uint64_t
kk_room_add
(
const
char
*
name
)
int
kk_room_add
(
const
char
*
name
,
const
char
*
roomId
)
{
{
int
res
=
0
;
int
res
=
0
;
kk_area_ctx_t
*
ctx
=
_kk_area_get_ctx
();
kk_area_ctx_t
*
ctx
=
_kk_area_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
sqlCmd
=
NULL
;
char
roomId
[
32
]
=
{
0
};
char
*
zErrMsg
=
0
;
char
*
zErrMsg
=
0
;
uint64_t
u64RoomId
=
0
;
const
char
*
insertCmd
=
"insert into AreaInfo (name, roomId) \
const
char
*
insertCmd
=
"insert into AreaInfo (name, roomId) \
values ('%s','%s');"
;
values ('%s','%s');"
;
_kk_area_lock
();
_kk_area_lock
();
ctx
->
roomNum
++
;
ctx
->
roomNum
++
;
u64RoomId
=
get_unique_id
();
HAL_GetTimeMs
(
roomId
);
sprintf
(
roomId
,
"%u"
,
u64RoomId
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
roomId
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
roomId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
...
@@ -143,7 +140,7 @@ uint64_t kk_room_add(const char *name)
...
@@ -143,7 +140,7 @@ uint64_t kk_room_add(const char *name)
}
}
sqlite3_free
(
sqlCmd
);
sqlite3_free
(
sqlCmd
);
_kk_area_unlock
();
_kk_area_unlock
();
return
u64RoomId
;
return
SUCCESS_RETURN
;
}
}
int
kk_room_delete
(
const
char
*
roomId
)
int
kk_room_delete
(
const
char
*
roomId
)
...
...
midware/midware/dm/kk_linkkit.c
View file @
4b30d68d
...
@@ -281,8 +281,7 @@ static int kk_service_addRoom_handle(const char *deviceCode, cJSON *params)
...
@@ -281,8 +281,7 @@ static int kk_service_addRoom_handle(const char *deviceCode, cJSON *params)
if
(
roomInfoStr
==
NULL
){
if
(
roomInfoStr
==
NULL
){
return
FAIL_RETURN
;
return
FAIL_RETURN
;
}
}
uint64_t
id
=
kk_room_add
(
roomInfoStr
->
valuestring
);
kk_room_add
(
roomInfoStr
->
valuestring
,
roomId
);
sprintf
(
roomId
,
"%u"
,
id
);
kk_tsl_set_value
(
kk_tsl_set_event_output_value
,
node
->
dev_shadow
,
MSG_AREA_ADDROOM_NOTIFICATION_ROOMID
,
NULL
,
roomId
);
kk_tsl_set_value
(
kk_tsl_set_event_output_value
,
node
->
dev_shadow
,
MSG_AREA_ADDROOM_NOTIFICATION_ROOMID
,
NULL
,
roomId
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
...
@@ -519,7 +518,6 @@ static int kk_service_getLockKeylist_handle(const char *deviceCode)
...
@@ -519,7 +518,6 @@ static int kk_service_getLockKeylist_handle(const char *deviceCode)
static
int
kk_service_addKey_handle
(
const
char
*
deviceCode
,
cJSON
*
param
)
static
int
kk_service_addKey_handle
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
{
char
keyId
[
32
]
=
{
0
};
char
keyId
[
32
]
=
{
0
};
uint64_t
u64KeyId
=
0
;
int
res
=
0
;
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
deviceCode
==
NULL
||
param
==
NULL
){
if
(
deviceCode
==
NULL
||
param
==
NULL
){
...
@@ -543,8 +541,7 @@ static int kk_service_addKey_handle(const char *deviceCode,cJSON *param)
...
@@ -543,8 +541,7 @@ static int kk_service_addKey_handle(const char *deviceCode,cJSON *param)
if
(
KeyEffectiveTime
==
NULL
)
return
FAIL_RETURN
;;
if
(
KeyEffectiveTime
==
NULL
)
return
FAIL_RETURN
;;
cJSON
*
KeyExpiryTime
=
cJSON_GetObjectItem
(
param
,
MSG_KEYADD_KEYEXPIRE
);
cJSON
*
KeyExpiryTime
=
cJSON_GetObjectItem
(
param
,
MSG_KEYADD_KEYEXPIRE
);
if
(
KeyExpiryTime
==
NULL
)
return
FAIL_RETURN
;;
if
(
KeyExpiryTime
==
NULL
)
return
FAIL_RETURN
;;
u64KeyId
=
get_unique_id
();
HAL_GetTimeMs
(
keyId
);
sprintf
(
keyId
,
"%u"
,
u64KeyId
);
kk_property_update_lockkeys
(
deviceCode
,
keyId
,
KeyType
->
valueint
,
KeyRole
->
valueint
,
IsValid
->
valueint
,
kk_property_update_lockkeys
(
deviceCode
,
keyId
,
KeyType
->
valueint
,
KeyRole
->
valueint
,
IsValid
->
valueint
,
KeyName
->
valuestring
,
KeyEffectiveTime
->
valueint
,
KeyExpiryTime
->
valueint
);
KeyName
->
valuestring
,
KeyEffectiveTime
->
valueint
,
KeyExpiryTime
->
valueint
);
kk_tsl_set_value
(
kk_tsl_set_event_output_value
,
node
->
dev_shadow
,
MSG_KEYADD_NOTIFICATION_KEYID
,
NULL
,
keyId
);
kk_tsl_set_value
(
kk_tsl_set_event_output_value
,
node
->
dev_shadow
,
MSG_KEYADD_NOTIFICATION_KEYID
,
NULL
,
keyId
);
...
...
midware/midware/scene/kk_scene_handle.c
View file @
4b30d68d
...
@@ -78,7 +78,7 @@ static void _kk_scene_lock(void)
...
@@ -78,7 +78,7 @@ static void _kk_scene_lock(void)
static
void
_kk_scene_unlock
(
void
)
static
void
_kk_scene_unlock
(
void
)
{
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
if
(
ctx
->
mutex
)
{
if
(
ctx
->
mutex
)
{
HAL_MutexUnlock
(
ctx
->
mutex
);
HAL_MutexUnlock
(
ctx
->
mutex
);
}
}
...
@@ -210,15 +210,17 @@ static int kk_scene_timer_load(void)
...
@@ -210,15 +210,17 @@ static int kk_scene_timer_load(void)
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
char
*
sceneId
=
NULL
;
char
*
sceneId
=
NULL
;
char
*
sqlCmd
=
"select * from SceneConditionInfo WHERE type =
timeRange
"
;
char
*
sqlCmd
=
"select * from SceneConditionInfo WHERE type =
'timeRange'
"
;
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_SCENECONDITION_SCENEID
);
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENECONDITION_SCENEID
);
if
(
kk_scene_check_able
(
sceneId
)
==
SUCCESS_RETURN
){
if
(
kk_scene_check_able
(
sceneId
)
==
SUCCESS_RETURN
){
int
starttime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
int
starttime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
int
endtime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_ENDTIME
);
int
endtime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_ENDTIME
);
int
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
int
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
kk_scene_push_timer_info
(
starttime
,
endtime
,
repeatday
);
kk_scene_push_timer_info
(
starttime
,
endtime
,
repeatday
,
sceneId
);
}
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
...
@@ -231,6 +233,7 @@ kk_tsl_t * kk_scene_shadow(void)
...
@@ -231,6 +233,7 @@ kk_tsl_t * kk_scene_shadow(void)
}
}
static
kk_scene_action_delay_t
*
p_delay_action_list
=
NULL
;
static
kk_scene_action_delay_t
*
p_delay_action_list
=
NULL
;
static
kk_scene_timer_list_t
*
p_scene_timer_list
=
NULL
;
static
kk_scene_timer_list_t
*
p_scene_timer_list
=
NULL
;
extern
uint64_t
s_start_time
;
void
*
kk_scene_yield
(
void
*
args
)
void
*
kk_scene_yield
(
void
*
args
)
{
{
...
@@ -241,10 +244,20 @@ void *kk_scene_yield(void *args)
...
@@ -241,10 +244,20 @@ void *kk_scene_yield(void *args)
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
while
(
1
)
{
while
(
1
)
{
current_time
=
HAL_GetTime
();
current_time
=
HAL_GetTime
();
/****系统起来15s后开始定时处理****/
if
((
HAL_UptimeMs
()
-
s_start_time
)
<=
15000
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
sleep
(
1
);
continue
;
}
_kk_scene_lock
();
_kk_scene_lock
();
actionDelayInfo
=
p_delay_action_list
;
actionDelayInfo
=
p_delay_action_list
;
while
(
actionDelayInfo
){
while
(
actionDelayInfo
){
INFO_PRINT
(
"[%s][%d] current_time:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
current_time
);
INFO_PRINT
(
"[%s][%d] actionDelayInfo->starttime:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
actionDelayInfo
->
starttime
);
if
(
current_time
>=
actionDelayInfo
->
starttime
){
if
(
current_time
>=
actionDelayInfo
->
starttime
){
INFO_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_scene_send_action_msg
(
actionDelayInfo
->
action
);
kk_scene_send_action_msg
(
actionDelayInfo
->
action
);
if
(
actionDelayInfo
==
p_delay_action_list
){
if
(
actionDelayInfo
==
p_delay_action_list
){
pTemp
=
p_delay_action_list
;
pTemp
=
p_delay_action_list
;
...
@@ -263,9 +276,15 @@ void *kk_scene_yield(void *args)
...
@@ -263,9 +276,15 @@ void *kk_scene_yield(void *args)
actionDelayInfo
=
actionDelayInfo
->
next
;
actionDelayInfo
=
actionDelayInfo
->
next
;
}
}
}
}
_kk_scene_unlock
();
_kk_scene_lock
();
/*******定时模式**********/
/*******定时模式**********/
scene_timer_list
=
p_scene_timer_list
;
scene_timer_list
=
p_scene_timer_list
;
while
(
scene_timer_list
){
while
(
scene_timer_list
){
INFO_PRINT
(
"--------scene_timer_list->starttime:%d
\n
"
,
scene_timer_list
->
starttime
);
INFO_PRINT
(
"--------current_time %d
\n
"
,
current_time
);
INFO_PRINT
(
"--------scene_timer_list->end:%d
\n
"
,
scene_timer_list
->
endtime
);
if
(
current_time
>=
scene_timer_list
->
starttime
&&
\
if
(
current_time
>=
scene_timer_list
->
starttime
&&
\
current_time
<=
scene_timer_list
->
endtime
){
current_time
<=
scene_timer_list
->
endtime
){
kk_scene_execute_action
(
scene_timer_list
->
sceneId
);
kk_scene_execute_action
(
scene_timer_list
->
sceneId
);
...
@@ -273,7 +292,6 @@ void *kk_scene_yield(void *args)
...
@@ -273,7 +292,6 @@ void *kk_scene_yield(void *args)
}
}
scene_timer_list
=
scene_timer_list
->
next
;
scene_timer_list
=
scene_timer_list
->
next
;
}
}
_kk_scene_unlock
();
_kk_scene_unlock
();
sleep
(
1
);
sleep
(
1
);
}
}
...
@@ -286,8 +304,6 @@ int kk_scene_init(void)
...
@@ -286,8 +304,6 @@ int kk_scene_init(void)
int
res
=
0
;
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
/* Create Mutex */
/* Create Mutex */
ctx
->
mutex
=
HAL_MutexCreate
();
ctx
->
mutex
=
HAL_MutexCreate
();
if
(
ctx
->
mutex
==
NULL
)
{
if
(
ctx
->
mutex
==
NULL
)
{
...
@@ -313,6 +329,28 @@ int kk_scene_init(void)
...
@@ -313,6 +329,28 @@ int kk_scene_init(void)
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_update_scene_enable
(
int
enable
,
const
char
*
sceneId
)
{
char
*
sqlCmd
=
NULL
;
int
len
=
0
;
int
rc
=
0
;
char
*
zErrMsg
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
//_kk_subDb_lock();
sqlCmd
=
sqlite3_mprintf
(
"UPDATE SceneInfo SET enable=%d WHERE sceneId= '%s'"
,
enable
,
sceneId
);
INFO_PRINT
(
"kk_scene_update_scene_enable,sqlCmd:%s
\n
"
,
sqlCmd
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
rc
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
}
else
{
//INFO_PRINT("Table updata data successfully\n");
}
sqlite3_free
(
sqlCmd
);
//_kk_subDb_unlock();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_insert_scene_info
(
const
char
*
name
,
const
char
*
sceneType
,
const
char
*
enable
,
const
char
*
sceneId
)
static
int
kk_scene_insert_scene_info
(
const
char
*
name
,
const
char
*
sceneType
,
const
char
*
enable
,
const
char
*
sceneId
)
{
{
...
@@ -605,6 +643,9 @@ void kk_scene_remove_timer_info(char *sceneId)
...
@@ -605,6 +643,9 @@ void kk_scene_remove_timer_info(char *sceneId)
int
kk_scene_push_timer_info
(
int
starttime
,
int
endtime
,
int
repeatday
,
char
*
sceneId
)
int
kk_scene_push_timer_info
(
int
starttime
,
int
endtime
,
int
repeatday
,
char
*
sceneId
)
{
{
kk_scene_timer_list_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
kk_scene_timer_list_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
_kk_scene_lock
();
_kk_scene_lock
();
ptemp
=
ptr
=
p_scene_timer_list
;
ptemp
=
ptr
=
p_scene_timer_list
;
while
(
ptr
){
while
(
ptr
){
...
@@ -629,8 +670,8 @@ int kk_scene_push_timer_info(int starttime,int endtime,int repeatday,char *scene
...
@@ -629,8 +670,8 @@ int kk_scene_push_timer_info(int starttime,int endtime,int repeatday,char *scene
_kk_scene_unlock
();
_kk_scene_unlock
();
INFO_PRINT
(
"kk_scene_push_timer_info called!!!
\n
"
);
INFO_PRINT
(
"kk_scene_push_timer_info called!!!
\n
"
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_parse_scene_condition
(
const
cJSON
*
str
,
const
char
*
sceneId
)
int
kk_scene_parse_scene_condition
(
const
cJSON
*
str
,
const
char
*
sceneId
)
{
{
char
weekflag
=
0
;
char
weekflag
=
0
;
...
@@ -760,7 +801,7 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
...
@@ -760,7 +801,7 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
static
void
kk_scene
c
_delete
(
char
*
sceneId
)
static
void
kk_scene_delete
(
char
*
sceneId
)
{
{
kk_scene_remove_timer_info
(
sceneId
);
kk_scene_remove_timer_info
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
...
@@ -775,7 +816,7 @@ int kk_scene_parse_updatescene(const cJSON* arg,char *sceneId)
...
@@ -775,7 +816,7 @@ int kk_scene_parse_updatescene(const cJSON* arg,char *sceneId)
ERROR_PRINT
(
"[%d]kk_scene_parse_addscene fail!!!
\n
"
,
__LINE__
);
ERROR_PRINT
(
"[%d]kk_scene_parse_addscene fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
kk_scene
c
_delete
(
sceneId
);
kk_scene_delete
(
sceneId
);
return
kk_scene_parse_addscene
(
arg
,
sceneId
,
1
);
return
kk_scene_parse_addscene
(
arg
,
sceneId
,
1
);
}
}
int
kk_scene_parse_deletescene
(
char
*
sceneId
)
int
kk_scene_parse_deletescene
(
char
*
sceneId
)
...
@@ -785,7 +826,7 @@ int kk_scene_parse_deletescene(char *sceneId)
...
@@ -785,7 +826,7 @@ int kk_scene_parse_deletescene(char *sceneId)
ERROR_PRINT
(
"[%d]kk_scene_parse_deletescene fail!!!
\n
"
,
__LINE__
);
ERROR_PRINT
(
"[%d]kk_scene_parse_deletescene fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
kk_scene
c
_delete
(
sceneId
);
kk_scene_delete
(
sceneId
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -820,7 +861,8 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
...
@@ -820,7 +861,8 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
/*only support once*/
/*only support once*/
if
(
pInfo
->
repeatday
==
0
){
if
(
pInfo
->
repeatday
==
0
){
pInfo
->
starttime
=
0
;
pInfo
->
starttime
=
0
;
pInfo
->
endtime
=
0
;
pInfo
->
endtime
=
0
;
kk_scene_update_scene_enable
(
0
,
pInfo
->
sceneId
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
else
{
}
else
{
curWeek
=
kk_scene_date_to_week
(
current
);
curWeek
=
kk_scene_date_to_week
(
current
);
...
@@ -872,11 +914,11 @@ int kk_scene_check_condition(const char *sceneId)
...
@@ -872,11 +914,11 @@ int kk_scene_check_condition(const char *sceneId)
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
startTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
startTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
endTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_
START
TIME
);
endTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_
END
TIME
);
duration
=
endTime
-
startTime
;
duration
=
endTime
-
startTime
;
startTime_m
=
kk_scene_creat_new_starttime
(
startTime
,
current
);
startTime_m
=
kk_scene_creat_new_starttime
(
startTime
,
current
);
/********check today is one of repeatday**************/
/********check today is one of repeatday**************/
if
((
repeatday
>
0
)
&&
(
repeatday
&
(
curWeek
<<
1
))){
if
((
repeatday
>
0
)
&&
(
repeatday
&
(
1
<<
(
curWeek
-
1
)
))){
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
...
@@ -995,8 +1037,13 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -995,8 +1037,13 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
if
(
pInfo
==
NULL
){
if
(
pInfo
==
NULL
){
return
;
return
;
}
}
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
root
=
cJSON_CreateObject
();
valueType
=
kk_dm_get_property_type
(
pInfo
->
deviceCode
,
pInfo
->
propertyName
);
valueType
=
kk_dm_get_property_type
(
pInfo
->
deviceCode
,
pInfo
->
propertyName
);
if
(
valueType
<
0
){
ERROR_PRINT
(
"[%d]kk_scene_send_action_msg valueType < 0!!!
\n
"
,
__LINE__
);
return
0
;
}
switch
(
valueType
){
switch
(
valueType
){
case
KK_TSL_DATA_TYPE_INT
:
case
KK_TSL_DATA_TYPE_INT
:
case
KK_TSL_DATA_TYPE_ENUM
:
case
KK_TSL_DATA_TYPE_ENUM
:
...
@@ -1026,7 +1073,8 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -1026,7 +1073,8 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
static
int
kk_scene_start_action
(
const
char
*
deviceCode
,
const
char
*
propertyName
,
const
char
*
valueS
,
int
delay
)
static
int
kk_scene_start_action
(
const
char
*
deviceCode
,
const
char
*
propertyName
,
const
char
*
valueS
,
int
delay
)
{
{
int
res
=
0
;
int
res
=
0
;
INFO_PRINT
(
"[%s][%d]kk_scene_start_action called
\n
"
,
__FUNCTION__
,
__LINE__
);
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_scene_action_info_t
*
actionInfo
=
NULL
;
kk_scene_action_info_t
*
actionInfo
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
@@ -1043,16 +1091,17 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
...
@@ -1043,16 +1091,17 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
if
(
actionInfo
==
NULL
)
{
if
(
actionInfo
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
return
MEMORY_NOT_ENOUGH
;
}
}
memset
(
actionInfo
,
0x0
,
sizeof
(
kk_scene_action_info_t
));
memcpy
(
actionInfo
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
memcpy
(
actionInfo
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
memcpy
(
actionInfo
->
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
actionInfo
->
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
actionInfo
->
fatherdeviceCode
,
node
->
fatherDeviceCode
,
strlen
(
node
->
fatherDeviceCode
));
memcpy
(
actionInfo
->
fatherdeviceCode
,
node
->
fatherDeviceCode
,
strlen
(
node
->
fatherDeviceCode
));
memcpy
(
actionInfo
->
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
actionInfo
->
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
actionInfo
->
propertyValue
,
valueS
,
strlen
(
valueS
));
memcpy
(
actionInfo
->
propertyValue
,
valueS
,
strlen
(
valueS
));
if
(
delay
==
0
){
if
(
delay
==
0
){
INFO_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_scene_send_action_msg
(
actionInfo
);
kk_scene_send_action_msg
(
actionInfo
);
}
else
{
}
else
{
_kk_scene_lock
(
);
INFO_PRINT
(
"[%s][%d]delay:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
delay
);
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
ptemp
=
ptr
=
p_delay_action_list
;
ptemp
=
ptr
=
p_delay_action_list
;
while
(
ptr
){
while
(
ptr
){
...
@@ -1061,9 +1110,9 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
...
@@ -1061,9 +1110,9 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
}
}
ptr
=
malloc
(
sizeof
(
kk_scene_action_delay_t
));
ptr
=
malloc
(
sizeof
(
kk_scene_action_delay_t
));
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
_kk_scene_unlock
();
return
MEMORY_NOT_ENOUGH
;
return
MEMORY_NOT_ENOUGH
;
}
}
memset
(
ptr
,
0x0
,
sizeof
(
kk_scene_action_delay_t
));
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
ptr
->
action
=
actionInfo
;
ptr
->
action
=
actionInfo
;
if
(
p_delay_action_list
==
NULL
){
if
(
p_delay_action_list
==
NULL
){
...
@@ -1071,7 +1120,6 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
...
@@ -1071,7 +1120,6 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
}
else
{
}
else
{
ptemp
->
next
=
ptr
;
ptemp
->
next
=
ptr
;
}
}
_kk_scene_unlock
();
}
}
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
...
@@ -1132,7 +1180,9 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -1132,7 +1180,9 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
INFO_PRINT
(
"[%d]kk_scene_check_condition enter!!!
\n
"
,
__LINE__
);
INFO_PRINT
(
"[%d]kk_scene_check_condition enter!!!
\n
"
,
__LINE__
);
res
=
kk_scene_check_condition
(
sceneId
);
res
=
kk_scene_check_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
if
(
res
==
SUCCESS_RETURN
){
_kk_scene_lock
();
res
=
kk_scene_execute_action
(
sceneId
);
res
=
kk_scene_execute_action
(
sceneId
);
_kk_scene_unlock
();
}
}
}
}
}
}
...
@@ -1148,3 +1198,25 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
...
@@ -1148,3 +1198,25 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
return
kk_scene_query_trigger_info
(
deviceCode
,
param
);
return
kk_scene_query_trigger_info
(
deviceCode
,
param
);
}
}
int
kk_scene_execute_scene
(
const
char
*
sceneId
)
{
int
res
=
0
;
int
sceneType
=
0
;
int
isEnable
=
0
;
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
isEnable
);
if
(
res
==
SUCCESS_RETURN
&&
sceneType
==
DB_SCENETYPE_SCENE
&&
isEnable
){
res
=
kk_scene_check_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
_kk_scene_lock
();
res
=
kk_scene_execute_action
(
sceneId
);
_kk_scene_unlock
();
}
}
INFO_PRINT
(
"[%d]kk_scene_execute_scene called!!!
\n
"
,
__LINE__
);
return
res
;
}
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