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
6b2398fb
Commit
6b2398fb
authored
Oct 19, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加场景的iftt模式触发和定时触发逻辑
【提交人】陈伟灿
parent
92be3547
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
628 additions
and
187 deletions
+628
-187
midware/midware/area/kk_area_handle.c
midware/midware/area/kk_area_handle.c
+1
-1
midware/midware/dm/kk_dm_api.c
midware/midware/dm/kk_dm_api.c
+14
-1
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+1
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+12
-5
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+2
-1
midware/midware/midware.c
midware/midware/midware.c
+1
-1
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+553
-177
midware/midware/scene/kk_scene_handle.h
midware/midware/scene/kk_scene_handle.h
+24
-0
midware/tsl/tsl_handle/kk_tsl_api.c
midware/tsl/tsl_handle/kk_tsl_api.c
+19
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
+1
-0
No files found.
midware/midware/area/kk_area_handle.c
View file @
6b2398fb
...
@@ -208,7 +208,7 @@ int kk_room_dev_add(const char *roomId,const char *deviceCode,const char *epNum)
...
@@ -208,7 +208,7 @@ int kk_room_dev_add(const char *roomId,const char *deviceCode,const char *epNum)
if
(
_kk_check_dev_exist
(
deviceCode
)){
if
(
_kk_check_dev_exist
(
deviceCode
)){
sqlCmd
=
sqlite3_mprintf
(
"UPDATE AreaDevInfo SET roomId='%s', epNum='%s' \
sqlCmd
=
sqlite3_mprintf
(
"UPDATE AreaDevInfo SET roomId='%s', epNum='%s' \
WHERE deviceCode= '%s'"
,
deviceCode
);
WHERE deviceCode= '%s'"
,
roomId
,
epNum
,
deviceCode
);
}
}
else
{
else
{
...
...
midware/midware/dm/kk_dm_api.c
View file @
6b2398fb
...
@@ -373,4 +373,17 @@ void kk_dm_ota_send(void *data, int len){
...
@@ -373,4 +373,17 @@ void kk_dm_ota_send(void *data, int len){
}
}
}
}
int
kk_dm_get_property_type
(
const
char
*
deviceCode
,
const
char
*
key
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
deviceCode
==
NULL
){
return
FAIL_RETURN
;
}
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
return
kk_tsl_get_property_type
(
node
->
dev_shadow
,
key
);
}
midware/midware/dm/kk_dm_msg.c
View file @
6b2398fb
...
@@ -924,7 +924,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
...
@@ -924,7 +924,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
kk_property_db_update_value
(
deviceCode
,
property
->
identifier
,
tmpValue
);
kk_property_db_update_value
(
deviceCode
,
property
->
identifier
,
tmpValue
);
}
}
else
if
(
property
->
data_value
.
type
==
KK_TSL_DATA_TYPE_DOUBLE
){
else
if
(
property
->
data_value
.
type
==
KK_TSL_DATA_TYPE_DOUBLE
){
sprintf
(
tmpValue
,
"%
u
"
,
property
->
data_value
.
value_double
);
sprintf
(
tmpValue
,
"%
f
"
,
property
->
data_value
.
value_double
);
kk_property_db_update_value
(
deviceCode
,
property
->
identifier
,
tmpValue
);
kk_property_db_update_value
(
deviceCode
,
property
->
identifier
,
tmpValue
);
}
}
else
if
(
property
->
data_value
.
type
==
KK_TSL_DATA_TYPE_TEXT
||
else
if
(
property
->
data_value
.
type
==
KK_TSL_DATA_TYPE_TEXT
||
...
...
midware/midware/dm/kk_linkkit.c
View file @
6b2398fb
...
@@ -303,6 +303,7 @@ static int kk_service_deleteRoom_handle(cJSON *params)
...
@@ -303,6 +303,7 @@ static int kk_service_deleteRoom_handle(cJSON *params)
}
}
static
int
kk_service_addDeviceToRoom_handle
(
cJSON
*
params
)
static
int
kk_service_addDeviceToRoom_handle
(
cJSON
*
params
)
{
{
char
epNumStr
[
10
]
=
{
0
};
if
(
params
==
NULL
){
if
(
params
==
NULL
){
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
...
@@ -317,13 +318,17 @@ static int kk_service_addDeviceToRoom_handle(cJSON *params)
...
@@ -317,13 +318,17 @@ static int kk_service_addDeviceToRoom_handle(cJSON *params)
}
}
cJSON
*
epNum
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_EPNUM
);
cJSON
*
epNum
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_EPNUM
);
if
(
epNum
==
NULL
){
if
(
epNum
==
NULL
){
return
FAIL_RETURN
;
strcpy
(
epNumStr
,
"1"
);
}
else
{
strcpy
(
epNumStr
,
epNum
->
valuestring
);
}
}
kk_room_dev_add
(
roomId
->
valuestring
,
deviceCode
->
valuestring
,
epNum
->
valuestring
);
kk_room_dev_add
(
roomId
->
valuestring
,
deviceCode
->
valuestring
,
epNum
Str
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
static
int
kk_service_removeDeviceFromRoom_handle
(
cJSON
*
params
)
static
int
kk_service_removeDeviceFromRoom_handle
(
cJSON
*
params
)
{
{
char
epNumStr
[
10
]
=
{
0
};
if
(
params
==
NULL
){
if
(
params
==
NULL
){
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
...
@@ -334,9 +339,11 @@ static int kk_service_removeDeviceFromRoom_handle(cJSON *params)
...
@@ -334,9 +339,11 @@ static int kk_service_removeDeviceFromRoom_handle(cJSON *params)
}
}
cJSON
*
epNum
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_EPNUM
);
cJSON
*
epNum
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_EPNUM
);
if
(
epNum
==
NULL
){
if
(
epNum
==
NULL
){
return
FAIL_RETURN
;
strcpy
(
epNumStr
,
"1"
);
}
}
else
{
kk_room_dev_remove
(
deviceCode
->
valuestring
,
epNum
->
valuestring
);
strcpy
(
epNumStr
,
epNum
->
valuestring
);
}
kk_room_dev_remove
(
deviceCode
->
valuestring
,
epNumStr
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
static
int
kk_service_execute_action
(
cJSON
*
action
,
dm_mgr_dev_node_t
*
node
)
static
int
kk_service_execute_action
(
cJSON
*
action
,
dm_mgr_dev_node_t
*
node
)
...
...
midware/midware/dm/kk_sub_db.c
View file @
6b2398fb
...
@@ -24,6 +24,7 @@ typedef enum{
...
@@ -24,6 +24,7 @@ typedef enum{
DB_VERSION
,
DB_VERSION
,
DB_AUTH
,
DB_AUTH
,
DB_DEVTYPE
,
DB_DEVTYPE
,
DB_HEARTBEAT
,
DB_PRODUCTTYPE
DB_PRODUCTTYPE
};
};
...
@@ -265,7 +266,7 @@ int kk_subDev_update_productType(char *productType,const char *deviceCode)
...
@@ -265,7 +266,7 @@ int kk_subDev_update_productType(char *productType,const char *deviceCode)
//_kk_subDb_lock();
//_kk_subDb_lock();
sqlCmd
=
sqlite3_mprintf
(
"UPDATE SubDeviceInfo SET productType='%s' WHERE deviceCode= '%s'"
,
productType
,
deviceCode
);
sqlCmd
=
sqlite3_mprintf
(
"UPDATE SubDeviceInfo SET productType='%s' WHERE deviceCode= '%s'"
,
productType
,
deviceCode
);
INFO_PRINT
(
"kk_subDev_update_
offlin
e sqlCmd:%s
\n
"
,
sqlCmd
);
INFO_PRINT
(
"kk_subDev_update_
productTyp
e sqlCmd:%s
\n
"
,
sqlCmd
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
rc
!=
SQLITE_OK
){
if
(
rc
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
...
...
midware/midware/midware.c
View file @
6b2398fb
...
@@ -367,8 +367,8 @@ void kk_platMsg_handle(void* data, char* chalMark){
...
@@ -367,8 +367,8 @@ void kk_platMsg_handle(void* data, char* chalMark){
dm_mgr_get_device_shadow_by_devicecode
(
info_dcode
->
valuestring
,
&
dev_shadow
);
dm_mgr_get_device_shadow_by_devicecode
(
info_dcode
->
valuestring
,
&
dev_shadow
);
kk_tsl_property_set_by_shadow
(
dev_shadow
,
outstr
,
strlen
(
outstr
)
+
1
);
kk_tsl_property_set_by_shadow
(
dev_shadow
,
outstr
,
strlen
(
outstr
)
+
1
);
dm_msg_thing_property_post_by_identify
(
info_dcode
->
valuestring
,
jsonPay
);
dm_msg_thing_property_post_by_identify
(
info_dcode
->
valuestring
,
jsonPay
);
kk_scene_iftt_check
(
info_dcode
->
valuestring
,
jsonPay
);
free
(
outstr
);
free
(
outstr
);
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_TOPO_DELETE_MSG
)
!=
NULL
){
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_TOPO_DELETE_MSG
)
!=
NULL
){
INFO_PRINT
(
"kk_platMsg_handle data: handle delete
\n
"
);
INFO_PRINT
(
"kk_platMsg_handle data: handle delete
\n
"
);
devCode
=
cJSON_GetObjectItem
(
jsonPay
,
MSG_DEVICE_CODE_STR
);
devCode
=
cJSON_GetObjectItem
(
jsonPay
,
MSG_DEVICE_CODE_STR
);
...
...
midware/midware/scene/kk_scene_handle.c
View file @
6b2398fb
...
@@ -5,29 +5,63 @@
...
@@ -5,29 +5,63 @@
#include "kk_log.h"
#include "kk_log.h"
#include "kk_scene_handle.h"
#include "kk_scene_handle.h"
#include "cJSON.h"
#include "cJSON.h"
#include <time.h>
extern
sqlite3
*
g_kk_pDb
;
extern
sqlite3
*
g_kk_pDb
;
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
,
int
current
);
typedef
struct
{
typedef
struct
{
void
*
mutex
;
void
*
mutex
;
sqlite3
*
pDb
;
sqlite3
*
pDb
;
void
*
s_scene_thread
;
}
kk_scene_ctx_t
;
}
kk_scene_ctx_t
;
typedef
enum
{
typedef
enum
{
DB_
IDX
=
0
,
DB_
SCENETYPE_SCENE
=
0
,
DB_
ROOM_NAME
,
DB_
SCENETYPE_IFTT
,
DB_
ROOM_ID
,
DB_
SCENETYPE_TIMING
,
};
};
typedef
enum
{
typedef
enum
{
DB_DEV_IDX
=
0
,
DB_SCENEINFO_NAME
=
0
,
DB_DEV_ROOM_ID
,
DB_SCENEINFO_SCENETYPE
,
DB_DEV_DEVICECODE
,
DB_SCENEINFO_ENABLE
,
DB_DEV_EPNUM
,
DB_SCENEINFO_SCENEID
,
};
typedef
enum
{
DB_SCENETRIGGER_TYPE
=
0
,
DB_SCENETRIGGER_DEVICECODE
,
DB_SCENETRIGGER_EPNUM
,
DB_SCENETRIGGER_PROPERTYNAME
,
DB_SCENETRIGGER_COMPARETYPE
,
DB_SCENETRIGGER_COMPAREVALUE
,
DB_SCENETRIGGER_SCENEID
,
};
typedef
enum
{
DB_SCENECONDITION_TYPE
=
0
,
DB_SCENECONDITION_STARTTIME
,
DB_SCENECONDITION_ENDTIME
,
DB_SCENECONDITION_CROSSDAY
,
DB_SCENECONDITION_REPEATDAY
,
DB_SCENECONDITION_SCENEID
,
};
typedef
enum
{
DB_SCENEACTION_TYPE
=
0
,
DB_SCENEACTION_DEVICECODE
,
DB_SCENEACTION_EPNUM
,
DB_SCENEACTION_PROPERTYNAME
,
DB_SCENEACTION_PROPERTYVALUE
,
DB_SCENEACTION_DELAY
,
DB_SCENEACTION_SCENEID
,
};
};
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
,
NULL
};
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
static
kk_scene_ctx_t
*
_kk_scene_get_ctx
(
void
)
static
kk_scene_ctx_t
*
_kk_scene_get_ctx
(
void
)
{
{
...
@@ -156,11 +190,96 @@ static int kk_scene_tsl_load(void)
...
@@ -156,11 +190,96 @@ static int kk_scene_tsl_load(void)
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
static
int
kk_scene_check_able
(
char
*
sceneId
)
{
int
res
=
0
;
int
sceneType
=
0
;
int
enable
=
0
;
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
enable
);
if
(
res
==
SUCCESS_RETURN
&&
sceneType
==
DB_SCENETYPE_TIMING
&&
enable
==
1
){
return
SUCCESS_RETURN
;
}
return
FAIL_RETURN
;
}
static
int
kk_scene_timer_load
(
void
)
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlite3_stmt
*
stmt
;
char
*
sceneId
=
NULL
;
char
*
sqlCmd
=
"select * from SceneConditionInfo WHERE type = timeRange"
;
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENECONDITION_SCENEID
);
if
(
kk_scene_check_able
(
sceneId
)
==
SUCCESS_RETURN
){
int
starttime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
int
endtime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_ENDTIME
);
int
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
kk_scene_push_timer_info
(
starttime
,
endtime
,
repeatday
);
}
}
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
}
kk_tsl_t
*
kk_scene_shadow
(
void
)
kk_tsl_t
*
kk_scene_shadow
(
void
)
{
{
return
s_scene_shadow
;
return
s_scene_shadow
;
}
}
static
kk_scene_action_delay_t
*
p_delay_action_list
=
NULL
;
static
kk_scene_timer_list_t
*
p_scene_timer_list
=
NULL
;
void
*
kk_scene_yield
(
void
*
args
)
{
uint64_t
current_time
=
0
;
kk_scene_action_delay_t
*
actionDelayInfo
=
NULL
;
kk_scene_action_delay_t
*
pTemp
=
NULL
;
kk_scene_timer_list_t
*
scene_timer_list
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
while
(
1
)
{
current_time
=
HAL_GetTime
();
_kk_scene_lock
();
actionDelayInfo
=
p_delay_action_list
;
while
(
actionDelayInfo
){
if
(
current_time
>=
actionDelayInfo
->
starttime
){
kk_scene_send_action_msg
(
actionDelayInfo
->
action
);
if
(
actionDelayInfo
==
p_delay_action_list
){
pTemp
=
p_delay_action_list
;
p_delay_action_list
=
p_delay_action_list
->
next
;
free
(
pTemp
);
actionDelayInfo
=
p_delay_action_list
;
}
else
{
pTemp
->
next
=
actionDelayInfo
->
next
;
free
(
actionDelayInfo
);
actionDelayInfo
=
pTemp
->
next
;
}
}
else
{
pTemp
=
actionDelayInfo
;
actionDelayInfo
=
actionDelayInfo
->
next
;
}
}
/*******定时模式**********/
scene_timer_list
=
p_scene_timer_list
;
while
(
scene_timer_list
){
if
(
current_time
>=
scene_timer_list
->
starttime
&&
\
current_time
<=
scene_timer_list
->
endtime
){
kk_scene_execute_action
(
scene_timer_list
->
sceneId
);
kk_scene_update_starttime
(
scene_timer_list
,
scene_timer_list
->
starttime
,
current_time
);
}
scene_timer_list
=
scene_timer_list
->
next
;
}
_kk_scene_unlock
();
sleep
(
1
);
}
return
NULL
;
}
int
kk_scene_init
(
void
)
int
kk_scene_init
(
void
)
{
{
...
@@ -174,186 +293,27 @@ int kk_scene_init(void)
...
@@ -174,186 +293,27 @@ int kk_scene_init(void)
if
(
ctx
->
mutex
==
NULL
)
{
if
(
ctx
->
mutex
==
NULL
)
{
return
FAIL_RETURN
;
return
FAIL_RETURN
;
}
}
_kk_scene_db_init
();
_kk_scene_db_init
();
res
=
kk_scene_tsl_load
();
res
=
kk_scene_tsl_load
();
if
(
res
!=
SUCCESS_RETURN
){
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"[%s][%d]kk_scene_init FAIL!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
ERROR_PRINT
(
"[%s][%d]kk_scene_init FAIL!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
SUCCESS_RETURN
;
}
#if 0
uint64_t kk_room_add(const char *name)
{
int res = 0;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
char *sqlCmd = NULL;
char roomId[32] = {0};
char *zErrMsg = 0;
uint64_t u64RoomId = 0;
const char *insertCmd = "insert into AreaInfo (name, roomId) \
values ('%s','%s');";
_kk_area_lock();
ctx->roomNum++;
u64RoomId = get_unique_id();
sprintf(roomId,"%u",u64RoomId);
sqlCmd = sqlite3_mprintf(insertCmd,name,roomId);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("sub device insert data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return u64RoomId;
}
int kk_room_delete(const char *roomId)
{
int res = 0;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
char *sqlCmd = NULL;
char *zErrMsg = 0;
const char *deleteCmd = "delete from AreaInfo where roomId = '%s';";
_kk_area_lock();
sqlCmd = sqlite3_mprintf(deleteCmd,roomId);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("Table delete data successfully\n");
ctx->roomNum--;
}
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return SUCCESS_RETURN;
}
int kk_room_dev_add(const char *roomId,const char *deviceCode,const char *epNum)
{
int res = 0;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
char *sqlCmd = NULL;
char *zErrMsg = 0;
const char *insertCmd = "insert into AreaDevInfo (roomId, deviceCode, epNum) \
kk_scene_timer_load
();
values ('%s','%s','%s');";
_kk_area_lock();
sqlCmd = sqlite3_mprintf(insertCmd,roomId,deviceCode,epNum);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("sub device insert data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return SUCCESS_RETURN;
}
int kk_room_dev_remove(const char *deviceCode,const char *epNum)
res
=
pthread_create
(
&
ctx
->
s_scene_thread
,
NULL
,
kk_scene_yield
,
NULL
);
{
if
(
res
<
0
)
{
int res = 0
;
ERROR_PRINT
(
"HAL_ThreadCreate mid Failed
\n
"
)
;
kk_area_ctx_t *ctx = _kk_area_get_ctx(
);
//IOT_Linkkit_Close(mid_ctx->master_devid
);
char *sqlCmd = NULL
;
return
-
1
;
char *zErrMsg = 0;
}
const char *insertCmd = "delete from AreaDevInfo where deviceCode = '%s' and epNum = '%s';";
_kk_area_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,epNum);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("sub device insert data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_area_unlock();
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int kk_room_device_list_add(const char *deviceCode)
{
int len;
kk_dev_list_t *ptr,*pre;
ptr = pre = s_device_list;
if(deviceCode == NULL){
return FAIL_RETURN;
}
while(ptr!=NULL){
pre = ptr;
if(strcmp(ptr->deviceCode,deviceCode) == 0){
return SUCCESS_RETURN;
}
ptr = ptr->next;
}
ptr = (kk_dev_list_t*)malloc(sizeof(kk_dev_list_t));
memset(ptr,0,sizeof(kk_dev_list_t));
memcpy(ptr->deviceCode,deviceCode,strlen(deviceCode));
if(s_device_list==NULL){
s_device_list = ptr;
}else{
pre->next = ptr;
}
return SUCCESS_RETURN;
}
kk_dev_list_t* kk_get_room_deviceCode(const char* roomId)
{
sqlite3_stmt *stmt;
char *sqlCmd = NULL;
kk_area_ctx_t *ctx = _kk_area_get_ctx();
const char *searchCmd = "select * from AreaDevInfo;";
printf("");
_kk_area_lock();
sqlCmd = sqlite3_mprintf(searchCmd,roomId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
if(strcmp(sqlite3_column_text(stmt, DB_DEV_ROOM_ID),roomId) == 0){
kk_room_device_list_add(sqlite3_column_text(stmt, DB_DEV_DEVICECODE));
}
}
sqlite3_finalize(stmt);
_kk_area_unlock();
return s_device_list;
}
void kk_free_room_dev_list(void)
{
kk_dev_list_t *ptr = s_device_list;
kk_dev_list_t *ptmp = NULL;
while(ptr != NULL){
ptmp = ptr->next;
free(ptr);
ptr = NULL;
ptr = ptmp;
}
s_device_list = NULL;
}
#endif
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
)
{
{
int
res
=
0
;
int
res
=
0
;
...
@@ -615,8 +575,62 @@ static int kk_scene_parse_repeatday(cJSON *repeatday)
...
@@ -615,8 +575,62 @@ static int kk_scene_parse_repeatday(cJSON *repeatday)
return
weekflag
;
return
weekflag
;
}
}
void
kk_scene_remove_timer_info
(
char
*
sceneId
)
{
kk_scene_timer_list_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
_kk_scene_lock
();
ptemp
=
ptr
=
p_scene_timer_list
;
while
(
ptr
){
if
(
!
strcmp
(
ptr
->
sceneId
,
sceneId
)){
if
(
ptr
==
p_scene_timer_list
){
ptemp
=
p_scene_timer_list
;
p_scene_timer_list
=
p_scene_timer_list
->
next
;
free
(
ptemp
);
ptr
=
p_scene_timer_list
;
}
else
{
ptemp
->
next
=
ptr
->
next
;
free
(
ptr
);
ptr
=
ptemp
->
next
;
}
}
else
{
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
}
_kk_scene_unlock
();
}
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_lock
();
ptemp
=
ptr
=
p_scene_timer_list
;
while
(
ptr
){
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
malloc
(
sizeof
(
kk_scene_timer_list_t
));
if
(
ptr
==
NULL
)
{
_kk_scene_unlock
();
return
MEMORY_NOT_ENOUGH
;
}
memset
(
ptr
,
0x0
,
sizeof
(
kk_scene_timer_list_t
));
ptr
->
starttime
=
starttime
;
ptr
->
endtime
=
endtime
;
ptr
->
repeatday
=
repeatday
;
memcpy
(
ptr
->
sceneId
,
sceneId
,
strlen
(
sceneId
));
if
(
p_scene_timer_list
==
NULL
){
p_scene_timer_list
=
ptr
;
}
else
{
ptemp
->
next
=
ptr
;
}
_kk_scene_unlock
();
INFO_PRINT
(
"kk_scene_push_timer_info called!!!
\n
"
);
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
;
...
@@ -645,6 +659,9 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
...
@@ -645,6 +659,9 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
cJSON
*
repeatday
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_REPEATDAYS
);
cJSON
*
repeatday
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_REPEATDAYS
);
if
(
repeatday
==
NULL
)
return
FAIL_RETURN
;
if
(
repeatday
==
NULL
)
return
FAIL_RETURN
;
weekflag
=
kk_scene_parse_repeatday
(
repeatday
);
weekflag
=
kk_scene_parse_repeatday
(
repeatday
);
if
(
!
strcmp
(
"timeRange"
,
type
->
valuestring
)){
kk_scene_push_timer_info
(
startTime
->
valueint
,
endTime
->
valueint
,
weekflag
,
sceneId
);
}
res
=
kk_scene_insert_scene_condition
(
type
->
valuestring
,
startTime
->
valueint
,
endTime
->
valueint
,
res
=
kk_scene_insert_scene_condition
(
type
->
valuestring
,
startTime
->
valueint
,
endTime
->
valueint
,
crossday
->
valueint
,
weekflag
,
sceneId
);
crossday
->
valueint
,
weekflag
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
if
(
res
!=
SUCCESS_RETURN
){
...
@@ -684,7 +701,7 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId)
...
@@ -684,7 +701,7 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId)
if
(
propertyValue
==
NULL
)
return
FAIL_RETURN
;
if
(
propertyValue
==
NULL
)
return
FAIL_RETURN
;
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
;
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
epNum
->
valueint
,
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
epNum
->
valueint
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
delay
->
valueint
,
sceneId
);
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
delay
->
valueint
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
if
(
res
!=
SUCCESS_RETURN
){
...
@@ -745,6 +762,7 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
...
@@ -745,6 +762,7 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
}
}
static
void
kk_scenec_delete
(
char
*
sceneId
)
static
void
kk_scenec_delete
(
char
*
sceneId
)
{
{
kk_scene_remove_timer_info
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
...
@@ -771,4 +789,362 @@ int kk_scene_parse_deletescene(char *sceneId)
...
@@ -771,4 +789,362 @@ int kk_scene_parse_deletescene(char *sceneId)
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_get_scene_info
(
const
char
*
sceneId
,
int
*
sceneType
,
int
*
enable
)
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlite3_stmt
*
stmt
;
int
res
=
FAIL_RETURN
;
char
*
sqlCmd
=
NULL
;
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
*
sceneType
=
sqlite3_column_int
(
stmt
,
DB_SCENEINFO_SCENETYPE
);
*
enable
=
sqlite3_column_int
(
stmt
,
DB_SCENEINFO_ENABLE
);
res
=
SUCCESS_RETURN
;
}
sqlite3_finalize
(
stmt
);
return
res
;
}
static
char
kk_scene_date_to_week
(
time_t
t
)
{
struct
tm
*
p
=
localtime
(
&
t
);
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
)
{
char
curWeek
=
0
;
char
i
=
0
;
if
(
pInfo
==
NULL
){
return
FAIL_RETURN
;
}
/*only support once*/
if
(
pInfo
->
repeatday
==
0
){
pInfo
->
starttime
=
0
;
pInfo
->
endtime
=
0
;
return
SUCCESS_RETURN
;
}
else
{
curWeek
=
kk_scene_date_to_week
(
current
);
for
(
i
=
1
;
i
<
8
;
i
++
){
if
(
curWeek
==
0x40
){
//0x40 ==>01000000 ,sunday
curWeek
=
curWeek
>>
6
;
}
else
{
curWeek
=
curWeek
<<
1
;
}
if
(
curWeek
&
pInfo
->
repeatday
){
pInfo
->
starttime
=
pInfo
->
starttime
+
86400
*
i
;
pInfo
->
endtime
=
pInfo
->
endtime
+
86400
*
i
;
return
SUCCESS_RETURN
;
}
}
}
return
FAIL_RETURN
;
}
static
int
kk_scene_creat_new_starttime
(
time_t
starttime
,
time_t
current
)
{
struct
tm
*
s
=
localtime
(
&
starttime
);
struct
tm
*
c
=
localtime
(
&
current
);
c
->
tm_hour
=
s
->
tm_hour
;
c
->
tm_min
=
s
->
tm_min
;
c
->
tm_sec
=
s
->
tm_sec
;
return
mktime
(
c
);
}
int
kk_scene_check_condition
(
const
char
*
sceneId
)
{
int
res
=
FAIL_RETURN
;
char
*
sqlCmd
=
NULL
;
char
curWeek
=
0
;
char
repeatday
=
0
;
int
startTime
=
0
,
startTime_m
=
0
;
int
endTime
=
0
,
endTime_m
=
0
;
int
duration
=
0
;
sqlite3_stmt
*
stmt
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
uint64_t
current
=
HAL_GetTime
();
curWeek
=
kk_scene_date_to_week
(
current
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneConditionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_REPEATDAY
);
startTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
endTime
=
sqlite3_column_int
(
stmt
,
DB_SCENECONDITION_STARTTIME
);
duration
=
endTime
-
startTime
;
startTime_m
=
kk_scene_creat_new_starttime
(
startTime
,
current
);
/********check today is one of repeatday**************/
if
((
repeatday
>
0
)
&&
(
repeatday
&
(
curWeek
<<
1
))){
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
res
=
SUCCESS_RETURN
;
}
}
else
{
if
(
current
>=
startTime
&&
current
<=
(
startTime
+
duration
)){
res
=
SUCCESS_RETURN
;
}
}
}
sqlite3_finalize
(
stmt
);
return
res
;
}
static
int
kk_scene_check_value
(
const
char
*
compareType
,
const
char
*
compareValue
,
cJSON
*
item
,
int
valueType
)
{
int
res
=
FAIL_RETURN
;
int
type
=
0
;
int
ivalue
=
0
;
int
itemValue
=
0
;
double
dvalue
=
0
;
double
ditemValue
=
0
;
if
(
compareType
==
NULL
||
compareValue
==
NULL
||
item
==
NULL
){
ERROR_PRINT
(
"[%d]kk_scene_check_value fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
}
switch
(
valueType
){
case
KK_TSL_DATA_TYPE_INT
:
case
KK_TSL_DATA_TYPE_ENUM
:
case
KK_TSL_DATA_TYPE_BOOL
:
ivalue
=
atoi
(
compareValue
);
itemValue
=
item
->
valueint
;
break
;
case
KK_TSL_DATA_TYPE_FLOAT
:
case
KK_TSL_DATA_TYPE_DOUBLE
:
dvalue
=
atof
(
compareValue
);
ditemValue
=
item
->
valuedouble
;
type
=
1
;
break
;
case
KK_TSL_DATA_TYPE_TEXT
:
case
KK_TSL_DATA_TYPE_DATE
:
type
=
2
;
break
;
}
if
(
type
==
2
){
if
(
!
strcmp
(
compareType
,
"="
)
&&
!
strcmp
(
compareValue
,
item
->
valuestring
)){
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">"
)
&&
strcmp
(
item
->
valuestring
,
compareValue
)
>
0
){
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">="
)
&&
strcmp
(
item
->
valuestring
,
compareValue
)
>=
0
){
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<="
)
&&
strcmp
(
item
->
valuestring
,
compareValue
)
<=
0
){
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<"
)
&&
strcmp
(
item
->
valuestring
,
compareValue
)
<
0
){
res
=
0
;
}
}
else
if
(
type
==
1
){
if
(
!
strcmp
(
compareType
,
"="
)){
if
(
ditemValue
==
dvalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">"
)){
if
(
ditemValue
>
dvalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">="
)){
if
(
ditemValue
>=
dvalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<="
)){
if
(
ditemValue
<=
dvalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<"
)){
if
(
ditemValue
<
dvalue
)
res
=
0
;
}
}
else
{
if
(
!
strcmp
(
compareType
,
"="
)){
if
(
itemValue
==
ivalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">"
)){
if
(
itemValue
>
ivalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
">="
)){
if
(
itemValue
>=
ivalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<="
)){
if
(
itemValue
<=
ivalue
)
res
=
0
;
}
else
if
(
!
strcmp
(
compareType
,
"<"
)){
if
(
itemValue
<
ivalue
)
res
=
0
;
}
}
return
res
;
}
static
void
kk_scene_send_action_msg
(
kk_scene_action_info_t
*
pInfo
)
{
int
ivalue
=
0
;
double
dvalue
=
0
;
int
valueType
=
0
;
if
(
pInfo
==
NULL
){
return
;
}
cJSON
*
root
=
cJSON_CreateObject
();
valueType
=
kk_dm_get_property_type
(
pInfo
->
deviceCode
,
pInfo
->
propertyName
);
switch
(
valueType
){
case
KK_TSL_DATA_TYPE_INT
:
case
KK_TSL_DATA_TYPE_ENUM
:
case
KK_TSL_DATA_TYPE_BOOL
:
ivalue
=
atoi
(
pInfo
->
propertyValue
);
cJSON_AddNumberToObject
(
root
,
pInfo
->
propertyName
,
ivalue
);
break
;
case
KK_TSL_DATA_TYPE_FLOAT
:
case
KK_TSL_DATA_TYPE_DOUBLE
:
dvalue
=
atof
(
pInfo
->
propertyValue
);
cJSON_AddNumberToObject
(
root
,
pInfo
->
propertyName
,
dvalue
);
break
;
case
KK_TSL_DATA_TYPE_TEXT
:
case
KK_TSL_DATA_TYPE_DATE
:
cJSON_AddStringToObject
(
root
,
pInfo
->
propertyName
,
pInfo
->
propertyValue
);
break
;
}
char
*
out
=
cJSON_Print
(
root
);
kk_msg_execute_property_set
(
pInfo
->
productCode
,
pInfo
->
deviceCode
,
out
,
pInfo
->
fatherdeviceCode
);
cJSON_Delete
(
root
);
free
(
out
);
free
(
pInfo
);
return
;
}
static
int
kk_scene_start_action
(
const
char
*
deviceCode
,
const
char
*
propertyName
,
const
char
*
valueS
,
int
delay
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_scene_action_info_t
*
actionInfo
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
if
(
deviceCode
==
NULL
||
propertyName
==
NULL
||
valueS
==
NULL
){
ERROR_PRINT
(
"[%d]kk_scene_send_action fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
}
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
actionInfo
=
malloc
(
sizeof
(
kk_scene_action_info_t
));
if
(
actionInfo
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memcpy
(
actionInfo
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
memcpy
(
actionInfo
->
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
actionInfo
->
fatherdeviceCode
,
node
->
fatherDeviceCode
,
strlen
(
node
->
fatherDeviceCode
));
memcpy
(
actionInfo
->
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
actionInfo
->
propertyValue
,
valueS
,
strlen
(
valueS
));
if
(
delay
==
0
){
kk_scene_send_action_msg
(
actionInfo
);
}
else
{
_kk_scene_lock
();
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
ptemp
=
ptr
=
p_delay_action_list
;
while
(
ptr
){
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
malloc
(
sizeof
(
kk_scene_action_delay_t
));
if
(
ptr
==
NULL
)
{
_kk_scene_unlock
();
return
MEMORY_NOT_ENOUGH
;
}
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
ptr
->
action
=
actionInfo
;
if
(
p_delay_action_list
==
NULL
){
p_delay_action_list
=
ptr
;
}
else
{
ptemp
->
next
=
ptr
;
}
_kk_scene_unlock
();
}
return
SUCCESS_RETURN
;
}
int
kk_scene_execute_action
(
const
char
*
sceneId
)
{
int
res
=
FAIL_RETURN
;
char
*
deviceCode
=
NULL
;
char
*
propertyName
=
NULL
;
char
*
propertyValue
=
NULL
;
int
delay
=
0
;
char
*
sqlCmd
=
NULL
;
sqlite3_stmt
*
stmt
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
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
);
res
=
kk_scene_start_action
(
deviceCode
,
propertyName
,
propertyValue
,
delay
);
}
sqlite3_finalize
(
stmt
);
return
res
;
}
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
int
res
=
FAIL_RETURN
;
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
char
*
sceneId
=
NULL
;
char
*
identifier
=
NULL
;
char
*
compareType
=
NULL
;
char
*
compareValue
=
NULL
;
int
propertyValueType
=
0
;
int
sceneType
=
0
,
isEnable
=
0
;
sqlite3_stmt
*
stmt
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE deviceCode= '%s'"
,
deviceCode
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_SCENEID
);
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
compareType
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
compareValue
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPAREVALUE
);
res
=
kk_scene_get_scene_info
(
sceneId
,
&
sceneType
,
&
isEnable
);
if
(
res
==
SUCCESS_RETURN
&&
sceneType
==
DB_SCENETYPE_IFTT
&&
isEnable
){
cJSON
*
item
=
cJSON_GetObjectItem
(
param
,
identifier
);
if
(
item
!=
NULL
){
propertyValueType
=
kk_dm_get_property_type
(
deviceCode
,
identifier
);
res
=
kk_scene_check_value
(
compareType
,
compareValue
,
item
,
propertyValueType
);
if
(
res
==
SUCCESS_RETURN
){
INFO_PRINT
(
"[%d]kk_scene_check_condition enter!!!
\n
"
,
__LINE__
);
res
=
kk_scene_check_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
res
=
kk_scene_execute_action
(
sceneId
);
}
}
}
}
}
sqlite3_finalize
(
stmt
);
return
res
;
}
int
kk_scene_iftt_check
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
return
kk_scene_query_trigger_info
(
deviceCode
,
param
);
}
midware/midware/scene/kk_scene_handle.h
View file @
6b2398fb
...
@@ -4,6 +4,30 @@
...
@@ -4,6 +4,30 @@
#include "kk_tsl_common.h"
#include "kk_tsl_common.h"
typedef
struct
{
char
productCode
[
PRODUCT_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
char
fatherdeviceCode
[
DEVICE_CODE_MAXLEN
];
char
propertyName
[
32
];
char
propertyValue
[
32
];
}
kk_scene_action_info_t
;
typedef
struct
kk_action_list
{
int
starttime
;
kk_scene_action_info_t
*
action
;
struct
kk_action_list
*
next
;
}
kk_scene_action_delay_t
;
typedef
struct
kk_scene_timer_list
{
int
starttime
;
int
endtime
;
char
sceneId
[
32
];
int
repeatday
;
struct
kk_scene_timer_list
*
next
;
}
kk_scene_timer_list_t
;
int
kk_scene_init
(
void
);
int
kk_scene_init
(
void
);
#endif
#endif
...
...
midware/tsl/tsl_handle/kk_tsl_api.c
View file @
6b2398fb
...
@@ -571,7 +571,26 @@ int kk_tsl_api_init(void)
...
@@ -571,7 +571,26 @@ int kk_tsl_api_init(void)
}
}
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_tsl_get_property_type
(
_IN_
kk_tsl_t
*
dev_shadow
,
_IN_
char
*
key
)
{
int
res
=
0
;
void
*
data
=
NULL
;
kk_tsl_data_type_e
type
;
if
(
dev_shadow
==
NULL
||
key
==
NULL
)
{
return
INVALID_PARAMETER
;
}
res
=
_kk_msg_get_property_data
(
dev_shadow
,
key
,
strlen
(
key
),
&
data
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
res
=
kk_tsl_get_data_type
(
data
,
&
type
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
return
type
;
}
static
int
_kk_tsl_get_property_value
(
_IN_
kk_tsl_t
*
dev_shadow
,
_IN_
char
*
key
,
_IN_
int
key_len
,
_IN_
void
*
value
,
static
int
_kk_tsl_get_property_value
(
_IN_
kk_tsl_t
*
dev_shadow
,
_IN_
char
*
key
,
_IN_
int
key_len
,
_IN_
void
*
value
,
_IN_
char
**
value_str
)
_IN_
char
**
value_str
)
{
{
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
View file @
6b2398fb
...
@@ -26,6 +26,7 @@ int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char
...
@@ -26,6 +26,7 @@ int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
},
\
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
},
\
{(
rpc_function
*
)
kk_wlist_add
,
"/thing/service/addWhiteList"
},
\
{(
rpc_function
*
)
kk_wlist_add
,
"/thing/service/addWhiteList"
},
\
{(
rpc_function
*
)
kk_wlist_delete
,
"/thing/service/deleteWhiteList"
},
\
{(
rpc_function
*
)
kk_wlist_delete
,
"/thing/service/deleteWhiteList"
},
\
{(
rpc_function
*
)
kk_topo_change_operation
,
"/thing/topo/change"
},
\
...
...
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