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
90820df2
Commit
90820df2
authored
Nov 09, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加场景嵌套功能
【提交人】陈伟灿
parent
32ba1614
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
904 additions
and
582 deletions
+904
-582
midware/midware/scene/kk_scene_db.c
midware/midware/scene/kk_scene_db.c
+479
-0
midware/midware/scene/kk_scene_db.h
midware/midware/scene/kk_scene_db.h
+63
-0
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+348
-564
midware/midware/scene/kk_scene_handle.h
midware/midware/scene/kk_scene_handle.h
+14
-0
tools/board/config.alios.mk3080
tools/board/config.alios.mk3080
+0
-18
No files found.
midware/midware/scene/kk_scene_db.c
0 → 100644
View file @
90820df2
#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
;
//eUtils_LockLock(&sLock);
_kk_scene_lock
();
ctx
->
pDb
=
g_kk_pDb
;
INFO_PRINT
(
"scene db Database opened
\n
"
);
const
char
*
pSceneTable
=
"CREATE TABLE IF NOT EXISTS SceneInfo( \
name varchar(255), \
sceneType INTEGER, \
enable INTEGER, \
sceneId varchar(255) UNIQUE)"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneTriggerTable
=
"CREATE TABLE IF NOT EXISTS SceneTriggerInfo( \
type varchar(255), \
deviceCode varchar(255), \
epNum INTEGER, \
propertyName varchar(255), \
compareType varchar(255), \
compareValue varchar(255), \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTriggerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneConditionTable
=
"CREATE TABLE IF NOT EXISTS SceneConditionInfo( \
type varchar(255), \
startTime INTEGER, \
endTime INTEGER, \
crossDay INTEGER, \
repeat_days INTEGER, \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneConditionTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneActionTable
=
"CREATE TABLE IF NOT EXISTS SceneActionInfo( \
type varchar(255), \
deviceCode varchar(255), \
epNum INTEGER, \
propertyName varchar(255), \
propertyValue varchar(255), \
delay INTEGER, \
sceneId varchar(255),\
gwdeviceCode varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneActionTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneTimerTable
=
"CREATE TABLE IF NOT EXISTS SceneTimerInfo( \
week INTEGER, \
time INTEGER, \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTimerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
/*内嵌场景关联表*/
const
char
*
pSceneEmbedTable
=
"CREATE TABLE IF NOT EXISTS SceneEmbedInfo( \
delay INTEGER, \
executeSceneId varchar(255), \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTimerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
_kk_scene_unlock
();
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
;
}
int
kk_scene_insert_scene_info
(
const
char
*
name
,
const
char
*
sceneType
,
const
char
*
enable
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneInfo (name, sceneType,enable,sceneId) \
values ('%s','%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
sceneType
,
enable
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
#if 0
static int kk_scene_check_trigger_exist(const char* type,const char* deviceCode,const char* epNum,const char* propertyName,
const char* compareType,const char* compareValue,const char* sceneId)
{
int res = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
const char *selectCmd = "select * from SceneTriggerInfo WHERE deviceCode = '%s' and propertyName = '%s';";
_kk_scene_lock();
sqlCmd = sqlite3_mprintf(selectCmd,,deviceCode,propertyName);
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);
sqlite3_free(sqlCmd);
_kk_scene_unlock();
return SUCCESS_RETURN;
}
#endif
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
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneTriggerInfo (type, deviceCode,epNum,propertyName,compareType,compareValue,sceneId) \
values ('%s','%s','%d','%s','%s','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
compareType
,
compareValue
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_insert_scene_condition
(
const
char
*
type
,
int
startTime
,
int
endTime
,
int
crossDay
,
char
repeat_days
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneConditionInfo (type, startTime,endTime,crossDay,repeat_days,sceneId) \
values ('%s','%d','%d','%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
startTime
,
endTime
,
crossDay
,
repeat_days
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_insert_scene_timer
(
time_t
startTime
,
char
weekflag
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneTimerInfo (week,time,sceneId) \
values ('%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
weekflag
,
startTime
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_insert_scene_embed
(
int
delay
,
const
char
*
executeSceneId
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneEmbedInfo (delay,executeSceneId,sceneId) \
values ('%d','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
delay
,
executeSceneId
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
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
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneActionInfo (type, deviceCode,epNum,propertyName,propertyValue,delay,sceneId,gwdeviceCode) \
values ('%s','%s','%d','%s','%s','%d','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwdeviceCode
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_info
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_trigger
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneTriggerInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_condition
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneConditionInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_timing
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneTimerInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_embed
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneEmbedInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_action
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
sqlite3_stmt
*
stmt
;
kk_scene_delete_send_to_gw
(
sceneId
);
const
char
*
deleteCmd
=
"delete from SceneActionInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
midware/midware/scene/kk_scene_db.h
0 → 100644
View file @
90820df2
#ifndef __KK_SCENE_DB_H__
#define __KK_SCENE_DB_H__
typedef
enum
{
DB_SCENETYPE_SCENE
=
0
,
DB_SCENETYPE_IFTT
,
DB_SCENETYPE_TIMING
,
DB_SCENETYPE_MUTICONTROL
,
};
typedef
enum
{
DB_SCENEINFO_NAME
=
0
,
DB_SCENEINFO_SCENETYPE
,
DB_SCENEINFO_ENABLE
,
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
,
//DB_SCENETRIGGER_TRIGGERFLAG,
};
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
,
DB_SCENEACTION_GWDEVICECODE
,
};
typedef
enum
{
DB_SCENETIMER_WEEK
=
0
,
DB_SCENETIMER_TIME
,
DB_SCENETIMER_SCENEID
,
};
typedef
enum
{
DB_SCENEEMBED_WEEK
=
0
,
DB_SCENEEMBED_EXECUTESCENEID
,
DB_SCENEMBED_SCENEID
,
};
#endif
midware/midware/scene/kk_scene_handle.c
View file @
90820df2
/******************************************************************************/
/* */
/* 文件名: 版本 */
/* */
/* kk_scene_handle.c V1.0 */
/* */
/* 功能描述: */
/* 该文件包含了和场景设置服务相关的代码 */
/* */
/* 更改记录: */
/* */
/* 日期 作者 摘要 */
/* */
/* */
/* */
/******************************************************************************/
#include <stdio.h>
#include <stdio.h>
#include "kk_tsl_api.h"
#include "kk_tsl_api.h"
#include "kk_dm_mng.h"
#include "kk_dm_mng.h"
#include "sqlite3.h"
#include "kk_log.h"
#include "kk_scene_handle.h"
#include "kk_scene_handle.h"
#include "kk_scene_db.h"
#include "cJSON.h"
#include "cJSON.h"
#include <time.h>
#include <time.h>
extern
int
g_timezone
;
extern
int
g_timezone
;
extern
sqlite3
*
g_kk_pDb
;
static
void
kk_scene_send_action_msg
(
kk_scene_action_info_t
*
pInfo
);
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
);
static
int
kk_scene_update_starttime
(
kk_scene_timer_list_t
*
pInfo
,
int
starttime
,
int
current
);
static
time_t
kk_scene_creat_timer_starttime
(
int
week
,
int
starttime
,
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
int
kk_scene_parse_repeatday
(
cJSON
*
repeatday
);
static
kk_scene_action_delay_t
*
p_delay_action_list
=
NULL
;
static
kk_scene_embed_delay_t
*
p_delay_embed_list
=
NULL
;
typedef
struct
{
static
kk_scene_timer_list_t
*
p_scene_timer_list
=
NULL
;
void
*
mutex
;
extern
uint64_t
s_start_time
;
sqlite3
*
pDb
;
void
*
s_scene_thread
;
}
kk_scene_ctx_t
;
typedef
enum
{
DB_SCENETYPE_SCENE
=
0
,
DB_SCENETYPE_IFTT
,
DB_SCENETYPE_TIMING
,
};
typedef
enum
{
DB_SCENEINFO_NAME
=
0
,
DB_SCENEINFO_SCENETYPE
,
DB_SCENEINFO_ENABLE
,
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
,
DB_SCENEACTION_GWDEVICECODE
,
};
typedef
enum
{
DB_SCENETIMER_WEEK
=
0
,
DB_SCENETIMER_TIME
,
DB_SCENETIMER_SCENEID
,
};
static
kk_scene_action_t
*
p_kk_scene_action
=
NULL
;
static
kk_scene_action_t
*
p_kk_scene_action
=
NULL
;
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
static
kk_scene_ctx_t
s_kk_scene_ctx
=
{
NULL
};
static
int
kk_scene_check_value_ex
(
const
char
*
compareType
,
const
char
*
compareValue1
,
const
char
*
compareValue2
)
static
int
kk_scene_check_value_ex
(
const
char
*
compareType
,
const
char
*
compareValue1
,
const
char
*
compareValue2
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -92,8 +51,9 @@ static int kk_scene_check_value_ex(const char * compareType,const char * compare
...
@@ -92,8 +51,9 @@ static int kk_scene_check_value_ex(const char * compareType,const char * compare
ERROR_PRINT
(
"[%d]kk_scene_check_value fail!!!
\n
"
,
__LINE__
);
ERROR_PRINT
(
"[%d]kk_scene_check_value fail!!!
\n
"
,
__LINE__
);
return
INVALID_PARAMETER
;
return
INVALID_PARAMETER
;
}
}
printf
(
"[%s][%d]compareValue1:%s,compareValue2:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
compareValue1
,
compareValue2
);
if
(
!
strcmp
(
compareType
,
"="
)
&&
!
strcmp
(
compareValue1
,
compareValue2
)){
if
(
!
strcmp
(
compareType
,
"="
)
&&
!
strcmp
(
compareValue1
,
compareValue2
)){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
res
=
0
;
res
=
0
;
}
}
else
if
(
!
strcmp
(
compareType
,
">"
)
&&
strcmp
(
compareValue1
,
compareValue2
)
>
0
){
else
if
(
!
strcmp
(
compareType
,
">"
)
&&
strcmp
(
compareValue1
,
compareValue2
)
>
0
){
...
@@ -114,11 +74,11 @@ static int kk_scene_check_value_ex(const char * compareType,const char * compare
...
@@ -114,11 +74,11 @@ static int kk_scene_check_value_ex(const char * compareType,const char * compare
}
}
static
kk_scene_ctx_t
*
_kk_scene_get_ctx
(
void
)
kk_scene_ctx_t
*
_kk_scene_get_ctx
(
void
)
{
{
return
&
s_kk_scene_ctx
;
return
&
s_kk_scene_ctx
;
}
}
static
void
_kk_scene_lock
(
void
)
void
_kk_scene_lock
(
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
)
{
...
@@ -126,7 +86,7 @@ static void _kk_scene_lock(void)
...
@@ -126,7 +86,7 @@ static void _kk_scene_lock(void)
}
}
}
}
static
void
_kk_scene_unlock
(
void
)
void
_kk_scene_unlock
(
void
)
{
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
@@ -135,106 +95,7 @@ static void _kk_scene_unlock(void)
...
@@ -135,106 +95,7 @@ static void _kk_scene_unlock(void)
}
}
}
}
static
int
_kk_scene_db_init
(
void
)
{
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
pcErr
;
//eUtils_LockLock(&sLock);
_kk_scene_lock
();
ctx
->
pDb
=
g_kk_pDb
;
INFO_PRINT
(
"scene db Database opened
\n
"
);
const
char
*
pSceneTable
=
"CREATE TABLE IF NOT EXISTS SceneInfo( \
name varchar(255), \
sceneType INTEGER, \
enable INTEGER, \
sceneId varchar(255) UNIQUE)"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneTriggerTable
=
"CREATE TABLE IF NOT EXISTS SceneTriggerInfo( \
type varchar(255), \
deviceCode varchar(255), \
epNum INTEGER, \
propertyName varchar(255), \
compareType varchar(255), \
compareValue varchar(255), \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTriggerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneConditionTable
=
"CREATE TABLE IF NOT EXISTS SceneConditionInfo( \
type varchar(255), \
startTime INTEGER, \
endTime INTEGER, \
crossDay INTEGER, \
repeat_days INTEGER, \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneConditionTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneActionTable
=
"CREATE TABLE IF NOT EXISTS SceneActionInfo( \
type varchar(255), \
deviceCode varchar(255), \
epNum INTEGER, \
propertyName varchar(255), \
propertyValue varchar(255), \
delay INTEGER, \
sceneId varchar(255),\
gwdeviceCode varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneActionTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneTimerTable
=
"CREATE TABLE IF NOT EXISTS SceneTimerInfo( \
week INTEGER, \
time INTEGER, \
sceneId varchar(255))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTimerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
ERROR_PRINT
(
"Error creating table (%s)
\n
"
,
pcErr
);
sqlite3_free
(
pcErr
);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
#define KK_DEVICE_TSL_TYPE (0x08)
#define KK_DEVICE_TSL_TYPE (0x08)
static
kk_tsl_t
*
s_scene_shadow
=
NULL
;
static
kk_tsl_t
*
s_scene_shadow
=
NULL
;
...
@@ -243,21 +104,26 @@ static int kk_scene_tsl_load(void)
...
@@ -243,21 +104,26 @@ static int kk_scene_tsl_load(void)
int
res
=
0
;
int
res
=
0
;
char
*
tsl_str
=
NULL
;
char
*
tsl_str
=
NULL
;
int
heartTime
=
0
;
int
heartTime
=
0
;
char
isDormancyDev
=
0
;
tsl_str
=
kk_load_json
(
"15"
,
KK_DEVICE_TSL_TYPE
);
tsl_str
=
kk_load_json
(
"15"
,
KK_DEVICE_TSL_TYPE
);
if
(
tsl_str
!=
NULL
)
if
(
tsl_str
!=
NULL
)
{
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
s_scene_shadow
,
&
heartTime
,
&
isDormancyDev
);
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
s_scene_shadow
,
&
heartTime
);
free
(
tsl_str
);
free
(
tsl_str
);
if
(
res
!=
0
){
if
(
res
!=
0
){
return
FAIL_RETURN
;
return
FAIL_RETURN
;
}
}
}
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
static
int
kk_scene_check_able
(
char
*
sceneId
)
/******************************************************************************/
/* 函 数 名: kk_scene_timer_check_able */
/* 描 述: check定时场景是否有效 */
/* 输入参数: mina_recmsg: 接收到的命令 */
/* 返 回 值: 返回'0'表示成功,其它返回值表示出错号 */
/******************************************************************************/
static
int
kk_scene_timer_check_able
(
char
*
sceneId
)
{
{
int
res
=
0
;
int
res
=
0
;
int
sceneType
=
0
;
int
sceneType
=
0
;
...
@@ -276,18 +142,19 @@ static int kk_scene_timer_load(void)
...
@@ -276,18 +142,19 @@ 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 SceneTimerInfo
WHERE type = 'timeRange'
"
;
char
*
sqlCmd
=
"select * from SceneTimerInfo
;
"
;
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_SCENETIMER_SCENEID
);
sceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENETIMER_SCENEID
);
if
(
kk_scene_check_able
(
sceneId
)
==
SUCCESS_RETURN
){
if
(
kk_scene_
timer_
check_able
(
sceneId
)
==
SUCCESS_RETURN
){
int
starttime
=
sqlite3_column_int
(
stmt
,
DB_SCENETIMER_TIME
);
int
starttime
=
sqlite3_column_int
(
stmt
,
DB_SCENETIMER_TIME
);
int
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENETIMER_WEEK
);
int
repeatday
=
sqlite3_column_int
(
stmt
,
DB_SCENETIMER_WEEK
);
kk_scene_push_timer_info
(
starttime
,
repeatday
,
sceneId
);
kk_scene_push_timer_info
(
starttime
,
repeatday
,
sceneId
);
}
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -295,27 +162,27 @@ kk_tsl_t * kk_scene_shadow(void)
...
@@ -295,27 +162,27 @@ 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
;
extern
uint64_t
s_start_time
;
void
*
kk_scene_yield
(
void
*
args
)
void
*
kk_scene_yield
(
void
*
args
)
{
{
time_t
current_time
=
0
;
time_t
current_time
=
0
;
kk_scene_action_delay_t
*
actionDelayInfo
=
NULL
;
kk_scene_action_delay_t
*
actionDelayInfo
=
NULL
;
kk_scene_action_delay_t
*
pTemp
=
NULL
;
kk_scene_action_delay_t
*
pTemp
=
NULL
;
kk_scene_embed_delay_t
*
embedDelayInfo
=
NULL
;
kk_scene_embed_delay_t
*
pTempEmbed
=
NULL
;
kk_scene_timer_list_t
*
scene_timer_list
=
NULL
;
kk_scene_timer_list_t
*
scene_timer_list
=
NULL
;
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后开始定时处理****/
/****系统起来15s后开始定时处理****/
if
((
HAL_UptimeMs
()
-
s_start_time
)
<=
15000
){
if
((
HAL_UptimeMs
()
-
s_start_time
)
<=
15000
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
sleep
(
1
);
sleep
(
1
);
continue
;
continue
;
}
}
_kk_scene_lock
();
_kk_scene_lock
();
/*处理action delay*/
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] current_time:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
current_time
);
...
@@ -341,13 +208,42 @@ void *kk_scene_yield(void *args)
...
@@ -341,13 +208,42 @@ void *kk_scene_yield(void *args)
}
}
}
}
_kk_scene_unlock
();
_kk_scene_unlock
();
sleep
(
1
);
_kk_scene_lock
();
_kk_scene_lock
();
/*处理场景嵌套delay*/
embedDelayInfo
=
p_delay_embed_list
;
while
(
embedDelayInfo
){
INFO_PRINT
(
"[%s][%d] current_time:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
current_time
);
INFO_PRINT
(
"[%s][%d] embedDelayInfo->starttime:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
embedDelayInfo
->
starttime
);
if
(
current_time
>=
embedDelayInfo
->
starttime
){
kk_scene_execute_action
(
embedDelayInfo
->
executeSceneId
);
if
(
embedDelayInfo
==
p_delay_embed_list
){
pTempEmbed
=
p_delay_embed_list
;
p_delay_embed_list
=
p_delay_embed_list
->
next
;
free
(
pTempEmbed
);
embedDelayInfo
=
p_delay_embed_list
;
}
else
{
pTempEmbed
->
next
=
embedDelayInfo
->
next
;
free
(
embedDelayInfo
);
embedDelayInfo
=
pTempEmbed
->
next
;
}
}
else
{
pTempEmbed
=
embedDelayInfo
;
embedDelayInfo
=
embedDelayInfo
->
next
;
}
}
_kk_scene_unlock
();
sleep
(
1
);
/*******定时模式**********/
/*******定时模式**********/
_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
(
"scene_timer_list->starttime:%d
\n
"
,
scene_timer_list
->
starttime
);
//
INFO_PRINT("current_time %d\n",current_time);
INFO_PRINT
(
"current_time %d
\n
"
,
current_time
);
if
(
scene_timer_list
->
starttime
!=
0
&&
current_time
>=
scene_timer_list
->
starttime
){
if
(
scene_timer_list
->
starttime
!=
0
&&
current_time
>=
scene_timer_list
->
starttime
){
kk_scene_execute_action
(
scene_timer_list
->
sceneId
);
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
,
scene_timer_list
->
starttime
,
current_time
);
...
@@ -372,7 +268,7 @@ int kk_scene_init(void)
...
@@ -372,7 +268,7 @@ int kk_scene_init(void)
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
){
...
@@ -380,7 +276,6 @@ int kk_scene_init(void)
...
@@ -380,7 +276,6 @@ int kk_scene_init(void)
}
}
kk_scene_timer_load
();
kk_scene_timer_load
();
res
=
pthread_create
(
&
ctx
->
s_scene_thread
,
NULL
,
kk_scene_yield
,
NULL
);
res
=
pthread_create
(
&
ctx
->
s_scene_thread
,
NULL
,
kk_scene_yield
,
NULL
);
if
(
res
<
0
)
{
if
(
res
<
0
)
{
ERROR_PRINT
(
"HAL_ThreadCreate mid Failed
\n
"
);
ERROR_PRINT
(
"HAL_ThreadCreate mid Failed
\n
"
);
...
@@ -391,140 +286,6 @@ int kk_scene_init(void)
...
@@ -391,140 +286,6 @@ 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
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneInfo (name, sceneType,enable,sceneId) \
values ('%s','%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
sceneType
,
enable
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
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
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneTriggerInfo (type, deviceCode,epNum,propertyName,compareType,compareValue,sceneId) \
values ('%s','%s','%d','%s','%s','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
compareType
,
compareValue
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_insert_scene_condition
(
const
char
*
type
,
int
startTime
,
int
endTime
,
int
crossDay
,
char
repeat_days
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneConditionInfo (type, startTime,endTime,crossDay,repeat_days,sceneId) \
values ('%s','%d','%d','%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
startTime
,
endTime
,
crossDay
,
repeat_days
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_insert_scene_timer
(
char
weekflag
,
int
startTime
,
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneTimerInfo (week,time,sceneId) \
values ('%d','%d','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
weekflag
,
startTime
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_action_info_add
(
kk_scene_action_info_ex_t
**
head
,
kk_scene_action_detail_t
detail
)
static
int
kk_scene_action_info_add
(
kk_scene_action_info_ex_t
**
head
,
kk_scene_action_detail_t
detail
)
{
{
int
len
;
int
len
;
...
@@ -617,6 +378,46 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -617,6 +378,46 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_delete_send_to_gw
(
const
char
*
sceneId
)
{
char
gwdevice
[][
DEVICE_CODE_MAXLEN
]
=
{
0
};
sqlite3_stmt
*
stmt
;
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
char
*
gwdeviceCode
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
int
idx
=
0
,
num
=
0
;
int
res
=
0
;
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
next:
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
gwdeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
if
(
kk_subDev_check_scene_support
(
gwdeviceCode
)
==
1
){
for
(
idx
=
0
;
idx
<
num
;
idx
++
){
/*此网关已经发送过*/
if
(
!
strcmp
(
gwdevice
[
idx
],
gwdeviceCode
)){
INFO_PRINT
(
"kk_scene_delete_send_to_gw repeat,ignore!!!
\n
"
);
goto
next
;
}
}
memcpy
(
gwdevice
[
num
],
gwdeviceCode
,
strlen
(
gwdeviceCode
));
num
++
;
cJSON
*
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
MSG_SCENE_SCENEID
,
sceneId
);
char
*
out
=
cJSON_Print
(
root
);
res
=
kk_msg_execute_scene_delete
(
out
,
gwdeviceCode
);
cJSON_Delete
(
root
);
free
(
out
);
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
res
;
}
int
kk_scene_action_info_send
(
int
isUpdate
)
int
kk_scene_action_info_send
(
int
isUpdate
)
{
{
...
@@ -654,154 +455,22 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
...
@@ -654,154 +455,22 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_insert_scene_action
(
const
char
*
type
,
const
char
*
deviceCode
,
int
epNum
,
const
char
*
propertyName
,
int
kk_scene_muticontrol_info_send
(
cJSON
*
action
,
const
char
*
gwdeviceCode
,
const
char
*
sceneId
)
const
char
*
propertyValue
,
int
delay
,
const
char
*
sceneId
,
const
char
*
gwdeviceCode
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneActionInfo (type, deviceCode,epNum,propertyName,propertyValue,delay,sceneId,gwdeviceCode) \
values ('%s','%s','%d','%s','%s','%d','%s','%s');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwdeviceCode
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_info
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_trigger
(
const
char
*
sceneId
)
{
{
int
res
=
0
;
if
(
action
==
NULL
||
gwdeviceCode
==
NULL
||
sceneId
==
NULL
){
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
return
INVALID_PARAMETER
;
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneTriggerInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_scene_delete_scene_condition
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
deleteCmd
=
"delete from SceneConditionInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
}
sqlite3_free
(
sqlCmd
);
cJSON
*
root
=
cJSON_CreateObject
();
_kk_scene_unlock
();
cJSON_AddStringToObject
(
root
,
MSG_SCENE_SCENEID
,
sceneId
);
cJSON_AddStringToObject
(
root
,
MSG_SCENE_ACTIONS
,
action
->
valuestring
);
char
*
out
=
cJSON_Print
(
root
);
printf
(
"kk_scene_muticontrol_info_send:%s
\n
"
,
out
);
kk_msg_execute_scene_set
(
out
,
gwdeviceCode
);
cJSON_Delete
(
root
);
free
(
out
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_scene_delete_scene_action
(
const
char
*
sceneId
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
char
*
gwdeviceCode
=
NULL
;
char
gwdevice
[][
DEVICE_CODE_MAXLEN
]
=
{
0
};
int
idx
=
0
,
num
=
0
;
sqlite3_stmt
*
stmt
;
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneId = '%s'"
,
sceneId
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
next:
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
gwdeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
if
(
kk_subDev_check_scene_support
(
gwdeviceCode
)
==
1
){
for
(
idx
=
0
;
idx
<
num
;
idx
++
){
if
(
!
strcmp
(
gwdevice
[
idx
],
gwdeviceCode
)){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
goto
next
;
}
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
memcpy
(
gwdevice
[
num
],
gwdeviceCode
,
strlen
(
gwdeviceCode
));
num
++
;
cJSON
*
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
MSG_SCENE_SCENEID
,
sceneId
);
char
*
out
=
cJSON_Print
(
root
);
res
=
kk_msg_execute_scene_delete
(
out
,
gwdeviceCode
);
cJSON_Delete
(
root
);
free
(
out
);
}
}
sqlite3_finalize
(
stmt
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
const
char
*
deleteCmd
=
"delete from SceneActionInfo where sceneId = '%s';"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
deleteCmd
,
sceneId
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_parse_trigger_detail
(
const
char
*
type
,
const
cJSON
*
item
,
const
char
*
sceneId
)
static
int
kk_scene_parse_trigger_detail
(
const
char
*
type
,
const
cJSON
*
item
,
const
char
*
sceneId
)
{
{
int
res
=
FAIL_RETURN
;
int
res
=
FAIL_RETURN
;
...
@@ -982,7 +651,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
...
@@ -982,7 +651,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
return
res
;
return
res
;
}
}
}
}
else
if
(
!
strcmp
(
"
trigger/thing
/property"
,
type
->
valuestring
)){
else
if
(
!
strcmp
(
"
condition
/property"
,
type
->
valuestring
)){
kk_scene_parse_trigger_detail
(
type
->
valuestring
,
item
,
sceneId
);
kk_scene_parse_trigger_detail
(
type
->
valuestring
,
item
,
sceneId
);
}
}
else
{
else
{
...
@@ -997,6 +666,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
...
@@ -997,6 +666,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
int
kk_scene_parse_scene_action
(
const
cJSON
*
str
,
const
char
*
sceneId
,
int
isUpdate
)
int
kk_scene_parse_scene_action
(
const
cJSON
*
str
,
const
char
*
sceneId
,
int
isUpdate
)
{
{
int
res
=
0
;
int
res
=
0
;
int
propertySetType
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
str
==
NULL
||
sceneId
==
NULL
){
if
(
str
==
NULL
||
sceneId
==
NULL
){
ERROR_PRINT
(
"kk_scene_parse_scene_action failed
\n
"
);
ERROR_PRINT
(
"kk_scene_parse_scene_action failed
\n
"
);
...
@@ -1008,52 +678,98 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
...
@@ -1008,52 +678,98 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
cJSON
*
item
=
action
->
child
;
cJSON
*
item
=
action
->
child
;
while
(
item
!=
NULL
){
while
(
item
!=
NULL
){
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
if
(
type
==
NULL
)
return
FAIL_RETURN
;
if
(
type
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
propertyName
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_PROPERTYNAME
);
/*内嵌场景设置*/
if
(
propertyName
==
NULL
)
return
FAIL_RETURN
;
if
(
type
->
valuestring
==
"action/scene"
)
cJSON
*
propertyValue
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_PROPERTYVALUE
);
{
if
(
propertyValue
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
productType
=
cJSON_GetObjectItem
(
item
,
MSG_PRODUCT_TYPE_STR
);
if
(
productType
!=
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_subDev_set_action_by_productType
(
productType
->
valuestring
,
sceneId
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
type
->
valuestring
);
}
else
{
cJSON
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
epNum
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_EPNUM
);
if
(
epNum
==
NULL
)
return
FAIL_RETURN
;
epNum
=
epNum
->
valueint
;
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
;
delay
=
delay
->
valueint
;
cJSON
*
exeucteSceneId
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_SCENEID
);
if
(
exeucteSceneId
==
NULL
)
return
FAIL_RETURN
;
kk_scene_insert_scene_embed
(
delay
->
valueint
,
exeucteSceneId
->
valuestring
,
sceneId
);
}
else
{
propertySetType
=
1
;
cJSON
*
propertyName
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_PROPERTYNAME
);
if
(
propertyName
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
propertyValue
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_PROPERTYVALUE
);
if
(
propertyValue
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
productType
=
cJSON_GetObjectItem
(
item
,
MSG_PRODUCT_TYPE_STR
);
if
(
productType
!=
NULL
){
kk_subDev_set_action_by_productType
(
productType
->
valuestring
,
sceneId
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
type
->
valuestring
);
}
else
{
cJSON
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
epNum
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_EPNUM
);
if
(
epNum
==
NULL
)
return
FAIL_RETURN
;
epNum
=
epNum
->
valueint
;
cJSON
*
delay
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_DELAY
);
if
(
delay
==
NULL
)
return
FAIL_RETURN
;
delay
=
delay
->
valueint
;
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
item
=
item
->
next
;
continue
;
}
if
(
kk_subDev_check_scene_support
(
node
->
fatherDeviceCode
)
==
1
){
kk_scene_action_detail_t
info
=
{
0
};
memcpy
(
info
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
memcpy
(
info
.
propertyName
,
propertyName
->
valuestring
,
strlen
(
propertyName
->
valuestring
));
memcpy
(
info
.
propertyValue
,
propertyValue
->
valuestring
,
strlen
(
propertyValue
->
valuestring
));
info
.
epNum
=
epNum
;
info
.
delay
=
delay
;
kk_scene_action_add
(
node
->
fatherDeviceCode
,
sceneId
,
info
);
}
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
node
->
deviceCode
,
epNum
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
delay
,
sceneId
,
node
->
fatherDeviceCode
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_scene_insert_scene_action fail!!!
\n
"
);
return
res
;
}
}
}
item
=
item
->
next
;
}
if
(
propertySetType
){
kk_scene_action_info_send
(
isUpdate
);
}
return
SUCCESS_RETURN
;
}
int
kk_scene_parse_scene_muticontrol
(
const
cJSON
*
str
,
const
char
*
sceneId
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
if
(
str
==
NULL
){
ERROR_PRINT
(
"kk_scene_parse_scene_muticontrol failed
\n
"
);
return
INVALID_PARAMETER
;
}
cJSON
*
action
=
cJSON_GetObjectItem
(
str
,
MSG_SCENE_ACTIONS
);
if
(
action
==
NULL
)
return
FAIL_RETURN
;
cJSON
*
item
=
action
->
child
;
while
(
item
!=
NULL
){
cJSON
*
type
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_TYPE
);
if
(
type
==
NULL
)
return
FAIL_RETURN
;
if
(
!
strcmp
(
type
->
valuestring
,
"action/thing/group"
)){
cJSON
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
res
=
dm_mgr_get_device_by_devicecode
(
deviceCode
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
item
=
item
->
next
;
item
=
item
->
next
;
continue
;
continue
;
}
}
if
(
kk_subDev_check_scene_support
(
node
->
fatherDeviceCode
)
==
1
){
break
;
kk_scene_action_detail_t
info
=
{
0
};
memcpy
(
info
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
memcpy
(
info
.
propertyName
,
propertyName
->
valuestring
,
strlen
(
propertyName
->
valuestring
));
memcpy
(
info
.
propertyValue
,
propertyValue
->
valuestring
,
strlen
(
propertyValue
->
valuestring
));
info
.
epNum
=
epNum
;
info
.
delay
=
delay
;
kk_scene_action_add
(
node
->
fatherDeviceCode
,
sceneId
,
info
);
}
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
node
->
deviceCode
,
epNum
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
delay
,
sceneId
,
node
->
fatherDeviceCode
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_scene_insert_scene_action fail!!!
\n
"
);
return
res
;
}
}
}
item
=
item
->
next
;
item
=
item
->
next
;
}
}
kk_scene_
action_info_send
(
isUpdate
);
kk_scene_
muticontrol_info_send
(
action
,
node
->
fatherDeviceCode
,
sceneId
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
...
@@ -1076,36 +792,41 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
...
@@ -1076,36 +792,41 @@ int kk_scene_parse_addscene(const cJSON* args,char *sceneId,int isUpdate)
if
(
!
isUpdate
){
if
(
!
isUpdate
){
HAL_GetTime_s
(
sceneId
);
//use time to create the sceneId
HAL_GetTime_s
(
sceneId
);
//use time to create the sceneId
}
}
//sprintf(sceneId,"%lld",u64SceneKeyId);
/*多控直接下发给网关处理*/
if
(
enable
->
valueint
==
1
&&
sceneType
->
valueint
==
DB_SCENETYPE_MUTICONTROL
){
res
=
kk_scene_insert_scene_info
(
name
->
valuestring
,
sceneType
->
valueint
,
enable
->
valueint
,
sceneId
);
kk_scene_parse_scene_muticontrol
(
args
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_scene_insert_scene_info fail!!!
\n
"
);
return
res
;
}
res
=
kk_scene_parse_scene_trigger
(
args
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_scene_parse_scene_trigger failed
\n
"
);
return
FAIL_RETURN
;
}
}
res
=
kk_scene_parse_scene_condition
(
args
,
sceneId
);
else
{
if
(
res
!=
SUCCESS_RETURN
){
res
=
kk_scene_insert_scene_info
(
name
->
valuestring
,
sceneType
->
valueint
,
enable
->
valueint
,
sceneId
);
ERROR_PRINT
(
"kk_scene_parse_scene_condition failed
\n
"
);
if
(
res
!=
SUCCESS_RETURN
){
//return FAIL_RETURN;
INFO_PRINT
(
"kk_scene_insert_scene_info fail!!!
\n
"
);
}
return
res
;
}
res
=
kk_scene_parse_scene_action
(
args
,
sceneId
,
isUpdate
);
res
=
kk_scene_parse_scene_trigger
(
args
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_scene_parse_scene_action failed
\n
"
);
ERROR_PRINT
(
"kk_scene_parse_scene_trigger failed
\n
"
);
return
FAIL_RETURN
;
return
FAIL_RETURN
;
}
}
res
=
kk_scene_parse_scene_condition
(
args
,
sceneId
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_scene_parse_scene_condition failed
\n
"
);
//return FAIL_RETURN;
}
res
=
kk_scene_parse_scene_action
(
args
,
sceneId
,
isUpdate
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_scene_parse_scene_action failed
\n
"
);
return
FAIL_RETURN
;
}
}
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
static
void
kk_scene_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_timing
(
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
);
...
@@ -1146,6 +867,7 @@ int kk_scene_get_scene_info(const char* sceneId,int *sceneType,int *enable)
...
@@ -1146,6 +867,7 @@ int kk_scene_get_scene_info(const char* sceneId,int *sceneType,int *enable)
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
res
;
return
res
;
}
}
static
char
kk_scene_date_to_week
(
time_t
t
)
static
char
kk_scene_date_to_week
(
time_t
t
)
...
@@ -1250,11 +972,11 @@ int kk_scene_check_trigger_condition(const char *sceneId)
...
@@ -1250,11 +972,11 @@ int kk_scene_check_trigger_condition(const char *sceneId)
int
propertyValueType
=
0
;
int
propertyValueType
=
0
;
int
conditionFlag
=
0
;
int
conditionFlag
=
0
;
sqlite3_stmt
*
stmt
;
sqlite3_stmt
*
stmt
;
char
*
currentValue
=
NULL
;
char
currentValue
[
64
]
=
{
0
}
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE sceneId = '%s' and type = '%s'"
,
sceneId
,
"condition"
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE sceneId = '%s' and type = '%s'"
,
sceneId
,
"condition
/property
"
);
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
){
conditionFlag
=
1
;
conditionFlag
=
1
;
...
@@ -1263,27 +985,24 @@ int kk_scene_check_trigger_condition(const char *sceneId)
...
@@ -1263,27 +985,24 @@ int kk_scene_check_trigger_condition(const char *sceneId)
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
identifier
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
compareType
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
compareType
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
compareValue
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPAREVALUE
);
compareValue
=
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPAREVALUE
);
propertyValueType
=
kk_dm_get_property_type
(
pdeviceCode
,
identifier
);
res
=
dm_mgr_get_device_by_devicecode
(
pdeviceCode
,
&
node
);
kk_property_db_get_value_directly
(
pdeviceCode
,
identifier
,
currentValue
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"currentValue:%s
\n
"
,
currentValue
);
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
continue
;
}
res
=
kk_tsl_get_value
(
kk_tsl_get_property_value
,
node
->
dev_shadow
,
identifier
,
NULL
,
&
currentValue
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
continue
;
}
res
=
kk_scene_check_value_ex
(
compareType
,
currentValue
,
compareValue
);
res
=
kk_scene_check_value_ex
(
compareType
,
currentValue
,
compareValue
);
free
(
currentValue
);
INFO_PRINT
(
"kk_scene_check_value_ex:res:%d
\n
"
,
res
);
currentValue
=
NULL
;
if
(
res
!=
0
){
break
;
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
/*如果没有设置条件,直接return success*/
/*如果没有设置条件,直接return success*/
if
(
conditionFlag
==
0
){
if
(
conditionFlag
==
0
){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
INFO_PRINT
(
"kk_scene_check_trigger_condition:res:%d
\n
"
,
res
);
return
res
;
return
res
;
}
}
...
@@ -1348,7 +1067,6 @@ int kk_scene_check_condition(const char *sceneId)
...
@@ -1348,7 +1067,6 @@ int kk_scene_check_condition(const char *sceneId)
}
}
}
}
else
{
else
{
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
if
(
current
>=
startTime_m
&&
current
<=
(
startTime_m
+
duration
)){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
...
@@ -1359,13 +1077,13 @@ int kk_scene_check_condition(const char *sceneId)
...
@@ -1359,13 +1077,13 @@ int kk_scene_check_condition(const char *sceneId)
}
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
/*如果没有设置条件,直接return success*/
/*如果没有设置条件,直接return success*/
if
(
conditionFlag
==
0
){
if
(
conditionFlag
==
0
){
res
=
SUCCESS_RETURN
;
res
=
SUCCESS_RETURN
;
}
}
INFO_PRINT
(
"kk_scene_check_condition:res:%d
\n
"
,
res
);
return
res
;
return
res
;
}
}
...
@@ -1479,6 +1197,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -1479,6 +1197,7 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
valueType
=
kk_dm_get_property_type
(
pInfo
->
deviceCode
,
pInfo
->
propertyName
);
valueType
=
kk_dm_get_property_type
(
pInfo
->
deviceCode
,
pInfo
->
propertyName
);
if
(
valueType
<
0
){
if
(
valueType
<
0
){
ERROR_PRINT
(
"[%d]kk_scene_send_action_msg valueType < 0!!!
\n
"
,
__LINE__
);
ERROR_PRINT
(
"[%d]kk_scene_send_action_msg valueType < 0!!!
\n
"
,
__LINE__
);
free
(
pInfo
);
return
0
;
return
0
;
}
}
switch
(
valueType
){
switch
(
valueType
){
...
@@ -1506,7 +1225,32 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
...
@@ -1506,7 +1225,32 @@ static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo)
free
(
pInfo
);
free
(
pInfo
);
return
;
return
;
}
}
static
int
kk_scene_push_action_list
(
kk_scene_action_info_t
*
actionInfo
,
int
delay
)
{
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
if
(
actionInfo
==
NULL
){
return
INVALID_PARAMETER
;
}
ptemp
=
ptr
=
p_delay_action_list
;
while
(
ptr
){
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
malloc
(
sizeof
(
kk_scene_action_delay_t
));
if
(
ptr
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
ptr
,
0x0
,
sizeof
(
kk_scene_action_delay_t
));
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
ptr
->
action
=
actionInfo
;
if
(
p_delay_action_list
==
NULL
){
p_delay_action_list
=
ptr
;
}
else
{
ptemp
->
next
=
ptr
;
}
return
SUCCESS_RETURN
;
}
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
;
...
@@ -1535,28 +1279,10 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
...
@@ -1535,28 +1279,10 @@ static int kk_scene_start_action(const char *deviceCode,const char *propertyName
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
{
INFO_PRINT
(
"[%s][%d]delay:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
delay
);
INFO_PRINT
(
"[%s][%d]delay:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
delay
);
kk_scene_action_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
kk_scene_push_action_list
(
actionInfo
,
delay
);
ptemp
=
ptr
=
p_delay_action_list
;
while
(
ptr
){
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
malloc
(
sizeof
(
kk_scene_action_delay_t
));
if
(
ptr
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
ptr
,
0x0
,
sizeof
(
kk_scene_action_delay_t
));
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
ptr
->
action
=
actionInfo
;
if
(
p_delay_action_list
==
NULL
){
p_delay_action_list
=
ptr
;
}
else
{
ptemp
->
next
=
ptr
;
}
}
}
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
...
@@ -1605,10 +1331,67 @@ next:
...
@@ -1605,10 +1331,67 @@ next:
}
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
res
;
return
res
;
}
}
static
int
kk_scene_push_embed_list
(
int
delay
,
const
char
*
sceneId
)
{
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
kk_scene_embed_delay_t
*
ptr
=
NULL
,
*
ptemp
=
NULL
;
_kk_scene_lock
();
ptemp
=
ptr
=
p_delay_embed_list
;
while
(
ptr
){
ptemp
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
malloc
(
sizeof
(
kk_scene_embed_delay_t
));
if
(
ptr
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
ptr
,
0x0
,
sizeof
(
kk_scene_embed_delay_t
));
ptr
->
starttime
=
HAL_GetTime
()
+
delay
;
memcpy
(
ptr
->
executeSceneId
,
sceneId
,
strlen
(
sceneId
));
if
(
p_delay_embed_list
==
NULL
){
p_delay_embed_list
=
ptr
;
}
else
{
ptemp
->
next
=
ptr
;
}
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
static
int
kk_scene_embed_find
(
const
char
*
sceneId
)
{
int
find
=
0
;
char
*
sqlCmd
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlite3_stmt
*
stmt
;
int
delay
=
0
;
char
*
executeSceneId
=
NULL
;
if
(
sceneId
==
NULL
){
return
INVALID_PARAMETER
;
}
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
){
find
=
1
;
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEEMBED_WEEK
);
executeSceneId
=
sqlite3_column_text
(
stmt
,
DB_SCENEEMBED_EXECUTESCENEID
);
/*如果有延时,加入到队列*/
if
(
delay
>
0
){
kk_scene_push_embed_list
(
delay
,
executeSceneId
);
}
else
{
kk_scene_execute_action
(
executeSceneId
);
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
find
;
}
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
int
kk_scene_query_trigger_info
(
const
char
*
deviceCode
,
cJSON
*
param
)
{
{
...
@@ -1644,9 +1427,10 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -1644,9 +1427,10 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
if
(
res
==
SUCCESS_RETURN
){
if
(
res
==
SUCCESS_RETURN
){
res
=
kk_scene_check_trigger_condition
(
sceneId
);
res
=
kk_scene_check_trigger_condition
(
sceneId
);
if
(
res
==
SUCCESS_RETURN
){
if
(
res
==
SUCCESS_RETURN
){
_kk_scene_lock
();
/*check是否时内嵌场景*/
res
=
kk_scene_execute_action
(
sceneId
);
if
(
kk_scene_embed_find
(
sceneId
)
==
0
){
_kk_scene_unlock
();
res
=
kk_scene_execute_action
(
sceneId
);
}
}
}
}
}
}
}
...
@@ -1655,7 +1439,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
...
@@ -1655,7 +1439,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
}
}
sqlite3_finalize
(
stmt
);
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
return
res
;
return
res
;
}
}
int
kk_scene_iftt_check
(
const
char
*
deviceCode
,
cJSON
*
param
)
int
kk_scene_iftt_check
(
const
char
*
deviceCode
,
cJSON
*
param
)
...
...
midware/midware/scene/kk_scene_handle.h
View file @
90820df2
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#define __KK_SCENE_H__
#define __KK_SCENE_H__
#include "kk_tsl_common.h"
#include "kk_tsl_common.h"
#include "sqlite3.h"
#include "kk_log.h"
typedef
struct
kk_scene_action_detail
{
typedef
struct
kk_scene_action_detail
{
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
...
@@ -38,12 +40,24 @@ typedef struct kk_action_list{
...
@@ -38,12 +40,24 @@ typedef struct kk_action_list{
struct
kk_action_list
*
next
;
struct
kk_action_list
*
next
;
}
kk_scene_action_delay_t
;
}
kk_scene_action_delay_t
;
typedef
struct
kk_embedscene_list
{
time_t
starttime
;
char
executeSceneId
[
32
];
struct
kk_embedscene_list
*
next
;
}
kk_scene_embed_delay_t
;
typedef
struct
kk_scene_timer_list
{
typedef
struct
kk_scene_timer_list
{
time_t
starttime
;
time_t
starttime
;
char
sceneId
[
32
];
char
sceneId
[
32
];
int
repeatday
;
int
repeatday
;
struct
kk_scene_timer_list
*
next
;
struct
kk_scene_timer_list
*
next
;
}
kk_scene_timer_list_t
;
}
kk_scene_timer_list_t
;
typedef
struct
{
void
*
mutex
;
sqlite3
*
pDb
;
void
*
s_scene_thread
;
}
kk_scene_ctx_t
;
int
kk_scene_init
(
void
);
int
kk_scene_init
(
void
);
...
...
tools/board/config.alios.mk3080
deleted
100644 → 0
View file @
32ba1614
CONFIG_ENV_CFLAGS += \
-mcpu=cortex-m4 -march=armv7-m -mthumb \
-mthumb-interwork -mlittle-endian \
-fno-short-enums \
-DCONFIG_PLATFORM_8711B -DM3 -w \
CONFIG_ENV_CFLAGS += \
-Os \
-DCONFIG_HTTP_AUTH_TIMEOUT=500 \
-DCONFIG_MID_HTTP_TIMEOUT=500 \
-DCONFIG_GUIDER_AUTH_TIMEOUT=500 \
-DCONFIG_MQTT_TX_MAXLEN=640 \
-DCONFIG_MQTT_RX_MAXLEN=1200 \
CONFIG_external_libs/mbedtls :=
CONFIG_tests :=
CROSS_PREFIX := arm-none-eabi-
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