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
b512d951
Commit
b512d951
authored
Jan 24, 2022
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,修改已创建的场景,设备移动到待分配后,场景仍然执行
【提交人】陈伟灿
parent
271cd502
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
220 additions
and
57 deletions
+220
-57
application/klansdk/kk_data_handle.c
application/klansdk/kk_data_handle.c
+1
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+64
-7
midware/midware/dm/kk_sync_data.c
midware/midware/dm/kk_sync_data.c
+20
-43
midware/midware/scene/kk_scene_db.c
midware/midware/scene/kk_scene_db.c
+34
-5
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+101
-1
nx5_soc_gw/smarthome_z3gw_a133
nx5_soc_gw/smarthome_z3gw_a133
+0
-0
No files found.
application/klansdk/kk_data_handle.c
View file @
b512d951
...
...
@@ -26,7 +26,7 @@
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
char
*
strrpl
(
char
*
in
,
char
*
out
,
int
outlen
,
char
*
src
,
char
*
dst
)
static
char
*
strrpl
(
char
*
in
,
char
*
out
,
int
outlen
,
char
*
src
,
char
*
dst
)
{
char
*
p
=
in
;
unsigned
int
len
=
outlen
-
1
;
...
...
midware/midware/dm/kk_linkkit.c
View file @
b512d951
...
...
@@ -138,7 +138,46 @@ static void _iotx_linkkit_upstream_mutex_unlock(void)
HAL_MutexUnlock
(
ctx
->
upstream_mutex
);
}
}
static
char
*
kk_strrpl
(
char
*
in
,
char
*
out
,
int
outlen
,
char
*
src
,
char
*
dst
)
{
char
*
p
=
in
;
unsigned
int
len
=
outlen
-
1
;
// 这几段检查参数合法性
if
((
NULL
==
src
)
||
(
NULL
==
dst
)
||
(
NULL
==
in
)
||
(
NULL
==
out
))
{
return
NULL
;
}
if
((
strcmp
(
in
,
""
)
==
0
)
||
(
strcmp
(
src
,
""
)
==
0
))
{
return
NULL
;
}
if
(
outlen
<=
0
)
{
return
NULL
;
}
while
((
*
p
!=
'\0'
)
&&
(
len
>
0
))
{
if
(
strncmp
(
p
,
src
,
strlen
(
src
))
!=
0
)
{
int
n
=
strlen
(
out
);
out
[
n
]
=
*
p
;
out
[
n
+
1
]
=
'\0'
;
p
++
;
len
--
;
}
else
{
strcat
(
out
,
dst
);
p
+=
strlen
(
src
);
len
-=
strlen
(
dst
);
}
}
return
out
;
}
/************************************************************
*功能描述:添加topo关系时添加消息同步队列
*输入参数:msgid:消息Id
...
...
@@ -429,20 +468,25 @@ static int kk_service_addRoom_reply(cJSON *param,cJSON *msgId,char *roomid,int t
return
FAIL_RETURN
;
}
cJSON
*
info
=
cJSON_CreateObject
();
cJSON
*
payload
=
cJSON_CreateObject
();
if
(
type
==
0
){
cJSON_AddStringToObject
(
info
,
MSG_TYPE_STR
,
KK_THING_SERVICE_ADDROOM_REPLY
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.addRoom_reply"
);
}
else
{
cJSON_AddStringToObject
(
info
,
MSG_TYPE_STR
,
KK_THING_SERVICE_UPDATEROOMNAME_REPLY
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.updateRoomName_reply"
);
}
cJSON_AddStringToObject
(
info
,
MSG_DEVICE_CODE_STR
,
deviceCode
->
valuestring
);
cJSON_AddStringToObject
(
info
,
MSG_PRODUCT_CODE_STR
,
productCode
->
valuestring
);
char
*
infff
=
cJSON_Print
(
info
);
cJSON
*
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"desc"
,
"success"
);
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON
*
Item
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
Item
,
"roomId"
,
roomid
);
cJSON_AddItemToObject
(
payload
,
"params"
,
Item
);
...
...
@@ -502,6 +546,7 @@ int kk_service_common_reply(cJSON *param,cJSON *msgId,char *msgType)
int
res
=
0
;
int
i
=
0
,
num
=
0
;
SensorType_t
*
pList
=
NULL
;
char
method
[
128
]
=
{
0
};
char
version
[
VERSION_MAXLEN
]
=
{
0
};
if
(
param
==
NULL
||
msgId
==
NULL
){
return
INVALID_PARAMETER
;
...
...
@@ -514,6 +559,7 @@ int kk_service_common_reply(cJSON *param,cJSON *msgId,char *msgType)
if
(
productCode
==
NULL
){
return
FAIL_RETURN
;
}
kk_strrpl
(
msgType
+
1
,
method
,
sizeof
(
method
),
"/"
,
"."
);
cJSON
*
info
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
info
,
MSG_TYPE_STR
,
msgType
);
cJSON_AddStringToObject
(
info
,
MSG_DEVICE_CODE_STR
,
deviceCode
->
valuestring
);
...
...
@@ -524,6 +570,7 @@ int kk_service_common_reply(cJSON *param,cJSON *msgId,char *msgType)
cJSON_AddStringToObject
(
payload
,
"desc"
,
"success"
);
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"method"
,
method
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON
*
Item
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
payload
,
"params"
,
Item
);
...
...
@@ -540,6 +587,7 @@ int kk_service_common_reply_ex(cJSON *param,cJSON *msgId,char *msgType,cJSON *It
{
int
res
=
0
;
int
i
=
0
,
num
=
0
;
char
method
[
128
]
=
{
0
};
SensorType_t
*
pList
=
NULL
;
if
(
param
==
NULL
||
msgId
==
NULL
){
return
INVALID_PARAMETER
;
...
...
@@ -552,6 +600,7 @@ int kk_service_common_reply_ex(cJSON *param,cJSON *msgId,char *msgType,cJSON *It
if
(
productCode
==
NULL
){
return
FAIL_RETURN
;
}
kk_strrpl
(
msgType
+
1
,
method
,
sizeof
(
method
),
"/"
,
"."
);
cJSON
*
info
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
info
,
MSG_TYPE_STR
,
msgType
);
cJSON_AddStringToObject
(
info
,
MSG_DEVICE_CODE_STR
,
deviceCode
->
valuestring
);
...
...
@@ -563,7 +612,7 @@ int kk_service_common_reply_ex(cJSON *param,cJSON *msgId,char *msgType,cJSON *It
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
method
);
cJSON_AddItemToObject
(
payload
,
"params"
,
Item
);
char
*
payload11
=
cJSON_Print
(
payload
);
kk_sendData2app
(
infff
,
payload11
,
0
);
...
...
@@ -642,6 +691,7 @@ static int kk_service_deleteRoom_reply(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.deleteRoom_reply"
);
cJSON
*
Item
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
payload
,
"params"
,
Item
);
char
*
payload11
=
cJSON_Print
(
payload
);
...
...
@@ -720,7 +770,8 @@ static int kk_service_addDeviceToRoom_handle(cJSON *params)
strcpy
(
epNumStr
,
epNum
->
valuestring
);
}
kk_room_dev_add
(
roomId
->
valuestring
,
room_name
->
valuestring
,
deviceCode
->
valuestring
,
epNumStr
,
dev_name
->
valuestring
);
//kk_scene_update_device_active(deviceCode->valuestring,atoi(epNumStr),1);
//kk_scene_rebuild_device_active(deviceCode->valuestring,atoi(epNumStr));
//内机默认添加到跟网关同个房间
if
(
strcmp
(
node
->
productType
,
KK_DM_AIR_GATEWAY_TYPE
)
==
0
&&
isAirGwFlag
==
1
){
int
eplist
[
64
]
=
{
0
};
...
...
@@ -790,6 +841,8 @@ static int kk_service_removeDeviceFromRoom_handle(cJSON *params)
strcpy
(
epNumStr
,
epNum
->
valuestring
);
}
kk_room_dev_remove
(
deviceCode
->
valuestring
,
epNumStr
);
kk_scene_update_device_active
(
deviceCode
->
valuestring
,
atoi
(
epNumStr
),
0
);
kk_scene_rebuild_device_active
(
deviceCode
->
valuestring
,
atoi
(
epNumStr
));
return
SUCCESS_RETURN
;
}
...
...
@@ -963,6 +1016,7 @@ static int kk_service_addFloor_reply(cJSON *root,cJSON *msgId,char *floorId,char
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.addFloor_reply"
);
cJSON
*
paramInfo
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
paramInfo
,
"floorId"
,
floorId
);
cJSON_AddStringToObject
(
paramInfo
,
"name"
,
name
);
...
...
@@ -1048,6 +1102,7 @@ static int kk_service_getFloor_handle(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.getAllFloors_reply"
);
cJSON
*
paramInfo
=
cJSON_CreateObject
();
cJSON
*
floorIdsAry
=
cJSON_CreateArray
();
while
(
pFloorList
!=
NULL
){
...
...
@@ -1101,6 +1156,7 @@ static int kk_service_addScreen_handle_reply(cJSON *param,cJSON *msgId,char *ser
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.clientReport_reply"
);
cJSON
*
paramInfo
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
paramInfo
,
"serialId"
,
serialId
);
...
...
@@ -1307,7 +1363,7 @@ static int kk_service_getScreenList_handle(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.getMooreList_reply"
);
pList
=
(
ScreenDevInfo_t
*
)
malloc
(
sizeof
(
ScreenDevInfo_t
)
*
KK_DEVICE_SCREEN_MAX_SUPPORT
);
if
(
pList
==
NULL
){
ERROR_PRINT
(
"MALLOC ERROR!!!"
);
...
...
@@ -1381,7 +1437,7 @@ static int kk_service_getScreenInfo_handle(cJSON *inforoot,cJSON *param,cJSON *m
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.getClientInfo_reply"
);
cJSON
*
paramInfo
=
cJSON_CreateObject
();
kk_get_screenDev_info
(
&
pInfo
,
serialid
->
valuestring
);
{
...
...
@@ -1570,6 +1626,7 @@ static int kk_service_getGuardSensors_handle(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.getGuardSensors_reply"
);
cJSON
*
paramArray
=
cJSON_CreateArray
();
num
=
dm_mgr_get_deviceNum_by_productType
(
"sensor"
);
pList
=
(
SensorType_t
*
)
malloc
(
sizeof
(
SensorType_t
)
*
num
);
...
...
@@ -1635,7 +1692,7 @@ static int kk_service_getCCUVersion_handle(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.getCCUVersion_reply"
);
cJSON
*
Item
=
cJSON_CreateObject
();
HAL_GetVersion
(
version
);
cJSON_AddStringToObject
(
Item
,
"currentDbVersion"
,
"1.0"
);
...
...
@@ -1688,7 +1745,7 @@ static int kk_service_upgrade_reply(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"code"
,
"0"
);
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
->
valuestring
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.service.upgrade_reply"
);
cJSON
*
Item
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
payload
,
"params"
,
Item
);
char
*
payload11
=
cJSON_Print
(
payload
);
...
...
midware/midware/dm/kk_sync_data.c
View file @
b512d951
...
...
@@ -28,11 +28,11 @@
extern
sqlite3
*
g_kk_pDb
;
static
int
kk_check_multi_ep_num
(
char
*
deviceCode
);
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
int
id
,
char
*
productType
,
char
*
actionRoomId
);
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
char
*
productType
,
char
*
actionRoomId
);
static
int
kk_get_panel_scenes_actions_info
(
cJSON
*
actionArray
,
int
id
);
static
int
kk_get_panel_scenes_info
(
cJSON
*
actionItem
,
int
id
);
static
int
kk_get_panel_scenes_allRoom_info
(
cJSON
*
actionItem
,
int
id
,
char
*
roomId
,
char
*
productType
);
static
int
kk_get_panel_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
);
static
int
kk_get_panel_scenes_info
(
cJSON
*
actionItem
,
char
*
id
);
static
int
kk_get_panel_scenes_allRoom_info
(
cJSON
*
actionItem
,
char
*
id
,
char
*
roomId
,
char
*
productType
);
typedef
struct
{
void
*
mutex
;
sqlite3
*
pDb
;
...
...
@@ -678,13 +678,13 @@ static int kk_get_panelConfig_info(cJSON *decvies,char *deviceCode)
bindType
=
(
int
)
sqlite3_column_int
(
stmt
,
DB_QUICKPANEL_BINDTYPE
);
if
(
bindType
==
1
){
kk_get_panel_scenes_info
(
action
,
atoi
(
sceneId
)
);
kk_get_panel_scenes_info
(
action
,
sceneId
);
}
else
if
(
bindType
==
3
){
roomId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_QUICKPANEL_ROOMID
);
productType
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_QUICKPANEL_PRODUCTTYPE
);
kk_get_panel_scenes_allRoom_info
(
action
,
atoi
(
sceneId
)
,
roomId
,
productType
);
kk_get_panel_scenes_allRoom_info
(
action
,
sceneId
,
roomId
,
productType
);
}
else
{
kk_get_panel_scenes_actions_info
(
action
,
atoi
(
sceneId
)
);
kk_get_panel_scenes_actions_info
(
action
,
sceneId
);
}
cJSON_AddItemToObject
(
item
,
"action"
,
action
);
...
...
@@ -878,7 +878,7 @@ int kk_get_roomId_by_scene_id(int scene_id,char *roomId)
return
res
;
}
static
int
kk_get_panel_scenes_info
(
cJSON
*
actionItem
,
int
id
)
static
int
kk_get_panel_scenes_info
(
cJSON
*
actionItem
,
char
*
id
)
{
char
*
sqlCmd
=
NULL
;
//char *zErrMsg = 0;
...
...
@@ -891,15 +891,14 @@ static int kk_get_panel_scenes_info(cJSON *actionItem,int id)
if
(
actionItem
==
NULL
){
return
FAIL_RETURN
;
}
const
char
*
selectCmd
=
"select * from SceneInfo WHERE sceneId = '%
d
';"
;
const
char
*
selectCmd
=
"select * from SceneInfo WHERE sceneId = '%
s
';"
;
sqlCmd
=
sqlite3_mprintf
(
selectCmd
,
id
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
scenetype
=
sqlite3_column_int
(
stmt
,
DB_SCENEINFO_SCENETYPE
);
sprintf
(
sceneIdStr
,
"%d"
,
id
);
cJSON_AddNumberToObject
(
actionItem
,
"bindType"
,
1
);
cJSON_AddStringToObject
(
actionItem
,
"type"
,
"action/scene"
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENEID_STR
,
sceneIdStr
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENEID_STR
,
id
);
cJSON_AddNumberToObject
(
actionItem
,
KK_SYNC_SCENE_SCENETYPE_STR
,
scenetype
);
break
;
}
...
...
@@ -908,7 +907,7 @@ static int kk_get_panel_scenes_info(cJSON *actionItem,int id)
return
SUCCESS_RETURN
;
}
static
int
kk_get_panel_scenes_allRoom_info
(
cJSON
*
actionItem
,
int
id
,
char
*
roomId
,
char
*
productType
)
static
int
kk_get_panel_scenes_allRoom_info
(
cJSON
*
actionItem
,
char
*
id
,
char
*
roomId
,
char
*
productType
)
{
char
*
sqlCmd
=
NULL
;
//char *zErrMsg = 0;
...
...
@@ -917,21 +916,15 @@ static int kk_get_panel_scenes_allRoom_info(cJSON *actionItem,int id,char *roomI
char
*
propertyName
=
NULL
;
char
*
propertyValue
=
NULL
;
char
*
type
=
NULL
;
int
delay
=
0
,
epNum
=
0
,
scene_id
=
0
;
int
delay
=
0
,
epNum
=
0
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
actionItem
==
NULL
){
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
"
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
where sceneId = '%s'"
,
id
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
scene_id
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_SCENEID
);
if
(
id
!=
scene_id
){
continue
;
}
deviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
epNum
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_EPNUM
);
...
...
@@ -962,7 +955,7 @@ static int kk_get_panel_scenes_allRoom_info(cJSON *actionItem,int id,char *roomI
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
static
int
kk_get_panel_scenes_actions_info
(
cJSON
*
actionItem
,
int
id
)
static
int
kk_get_panel_scenes_actions_info
(
cJSON
*
actionItem
,
char
*
id
)
{
char
*
sqlCmd
=
NULL
;
//char *zErrMsg = 0;
...
...
@@ -973,31 +966,21 @@ static int kk_get_panel_scenes_actions_info(cJSON *actionItem,int id)
char
roomIdStr
[
32
]
=
{
0
};
char
*
type
=
NULL
;
int
delay
=
0
,
epNum
=
0
,
scene_id
=
0
;
int
delay
=
0
,
epNum
=
0
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
actionItem
==
NULL
){
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
"
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
where sceneId = '%s' and active = '%d'"
,
id
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
scene_id
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_SCENEID
);
if
(
id
!=
scene_id
){
continue
;
}
deviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
epNum
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_EPNUM
);
propertyName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
type
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_TYPE
);
kk_get_roomId_by_deviceCode
(
deviceCode
,
"1"
,
roomIdStr
,
sizeof
(
roomIdStr
));
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_DEVICECODE_STR
,
deviceCode
);
cJSON_AddNumberToObject
(
actionItem
,
KK_SYNC_SCENE_DELAY_STR
,
delay
);
cJSON_AddNumberToObject
(
actionItem
,
KK_SYNC_SCENE_EPNUM_STR
,
epNum
);
...
...
@@ -1033,7 +1016,7 @@ static int kk_get_panel_scenes_actions_info(cJSON *actionItem,int id)
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
int
id
,
char
*
productType
,
char
*
actionRoomId
)
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
char
*
productType
,
char
*
actionRoomId
)
{
char
*
sqlCmd
=
NULL
;
//char *zErrMsg = 0;
...
...
@@ -1047,19 +1030,13 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,int id,char *productTyp
char
*
type
=
NULL
;
int
delay
=
0
,
epNum
=
0
,
scene_id
=
0
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
actionArray
==
NULL
){
if
(
actionArray
==
NULL
||
productType
==
NULL
||
actionRoomId
==
NULL
){
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
"
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo
where sceneId = '%s' and active = '%d'"
,
id
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
cJSON
*
actionItem
;
scene_id
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_SCENEID
);
if
(
id
!=
scene_id
){
continue
;
}
deviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
epNum
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_EPNUM
);
...
...
@@ -1374,7 +1351,7 @@ static int kk_get_scenes_info(cJSON *data)
cJSON_AddStringToObject
(
sceneArrayItem
,
KK_SYNC_ROOMID_STR
,
roomId
);
cJSON_AddStringToObject
(
sceneArrayItem
,
KK_SYNC_SCENEID_STR
,
sceneId
);
cJSON
*
actionArray
=
cJSON_CreateArray
();
kk_get_scenes_actions_info
(
actionArray
,
atoi
(
sceneId
)
,
productType
,
actionRoomId
);
kk_get_scenes_actions_info
(
actionArray
,
sceneId
,
productType
,
actionRoomId
);
cJSON_AddItemToObject
(
sceneArrayItem
,
KK_SYNC_SCENE_ACTIONS_STR
,
actionArray
);
cJSON
*
triggerObj
=
cJSON_CreateObject
();
kk_get_scenes_trigger_info
(
triggerObj
,
sceneId
);
...
...
midware/midware/scene/kk_scene_db.c
View file @
b512d951
...
...
@@ -110,7 +110,8 @@ int kk_scene_db_init(void)
propertyValue varchar(255), \
delay INTEGER, \
sceneId varchar(255),\
gwdeviceCode varchar(255))"
;
gwdeviceCode varchar(255),\
active INTEGER)"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneActionTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
...
...
@@ -589,7 +590,6 @@ int kk_scene_insert_scene_condition(const char* type,int startTime,int endTime,i
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
...
...
@@ -724,11 +724,11 @@ int kk_scene_insert_scene_action(const char* type,const char* deviceCode,int epN
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
printf
(
"----->kk_scene_insert_scene_action
\n
"
);
const
char
*
insertCmd
=
"insert into SceneActionInfo (type, deviceCode,epNum,propertyName,propertyValue,delay,sceneId,gwdeviceCode) \
values ('%s','%s','%d','%s','%s','%d','%s','%s');"
;
const
char
*
insertCmd
=
"insert into SceneActionInfo (type, deviceCode,epNum,propertyName,propertyValue,delay,sceneId,gwdeviceCode
,active
) \
values ('%s','%s','%d','%s','%s','%d','%s','%s'
,'%d'
);"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwdeviceCode
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwdeviceCode
,
1
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
...
...
@@ -741,8 +741,37 @@ int kk_scene_insert_scene_action(const char* type,const char* deviceCode,int epN
_kk_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:更新场景设备使能
*输入参数:sceneId:场景Id
productType:类型
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_update_device_active
(
char
*
deviceCode
,
int
epNum
,
int
value
)
{
char
*
sqlCmd
=
NULL
;
int
rc
=
0
;
char
*
zErrMsg
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
"UPDATE SceneActionInfo SET active='%d' WHERE deviceCode = '%s' and epNum= '%d'"
,
value
,
deviceCode
,
epNum
);
INFO_PRINT
(
"kk_scene_update_device_active 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_scene_unlock
();
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除情景面板的基本数据
*输入参数: sceneId:场景Id
...
...
midware/midware/scene/kk_scene_handle.c
View file @
b512d951
...
...
@@ -1473,7 +1473,11 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
memcpy
(
info
.
propertyName
,
propertyName
->
valuestring
,
strlen
(
propertyName
->
valuestring
));
}
}
else
{
memcpy
(
info
.
propertyName
,
propertyName
->
valuestring
,
strlen
(
propertyName
->
valuestring
));
if
(
iepnum
>
1
&&
strstr
(
propertyName
->
valuestring
,
"_"
)
==
NULL
){
sprintf
(
info
.
propertyName
,
"%s_%d"
,
propertyName
->
valuestring
,
iepnum
);
}
else
{
memcpy
(
info
.
propertyName
,
propertyName
->
valuestring
,
strlen
(
propertyName
->
valuestring
));
}
}
memcpy
(
info
.
propertyValue
,
propertyValueStr
,
strlen
(
propertyValueStr
));
info
.
epNum
=
iepnum
;
...
...
@@ -2633,3 +2637,99 @@ int kk_scene_execute_quickpanel(const char *buttonId,char *deviceCode)
return
res
;
}
/************************************************************
*功能描述:获取场景Id
*输入参数:sceneId:场景Id
productType:类型
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
_kk_rebuild_device_active
(
char
*
sceneid
)
{
char
*
sqlCmd
=
NULL
;
sqlite3_stmt
*
stmt
;
char
*
pDeviceCode
=
NULL
;
char
*
pSceneType
=
NULL
;
char
*
gwDeviceCode
=
NULL
;
int
epNum
=
0
;
int
isMuti
=
0
;
int
count
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE sceneid = '%s' and active = '%d'"
,
sceneid
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
cJSON
*
array
=
cJSON_CreateArray
();
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
count
++
;
pSceneType
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_TYPE
);
pDeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_DEVICECODE
);
epNum
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_EPNUM
);
gwDeviceCode
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_GWDEVICECODE
);
if
(
strcmp
(
pSceneType
,
"action/thing/group"
)
==
0
){
cJSON
*
arrayParam
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
arrayParam
,
MSG_SCENE_TYPE
,
pSceneType
);
cJSON_AddStringToObject
(
arrayParam
,
MSG_DEVICE_CODE_STR
,
pDeviceCode
);
cJSON_AddStringToObject
(
arrayParam
,
MSG_SCENE_EPNUM
,
epNum
);
isMuti
=
1
;
cJSON_AddItemToArray
(
array
,
arrayParam
);
}
else
{
kk_scene_action_detail_t
info
=
{
0
};
char
*
propertyName
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYNAME
);
char
*
propertyValueStr
=
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_PROPERTYVALUE
);
int
idelay
=
sqlite3_column_int
(
stmt
,
DB_SCENEACTION_DELAY
);
memcpy
(
info
.
deviceCode
,
pDeviceCode
,
strlen
(
pDeviceCode
));
memcpy
(
info
.
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
info
.
propertyValue
,
propertyValueStr
,
strlen
(
propertyValueStr
));
info
.
epNum
=
epNum
;
info
.
delay
=
idelay
;
isMuti
=
0
;
if
(
strcmp
(
propertyName
,
"LightStripSpecialAction"
)
!=
0
){
kk_scene_action_add
(
gwDeviceCode
,
sceneid
,
info
);
}
else
{
if
(
strstr
(
propertyValueStr
,
"{"
)
!=
NULL
&&
strstr
(
propertyValueStr
,
"}"
)
!=
NULL
){
cJSON
*
propertyValueJson
=
cJSON_Parse
(
propertyValueStr
);
if
(
propertyValueJson
==
NULL
)
{
ERROR_PRINT
(
"cJSON_Parse ERROR!!!"
);
return
FAIL_RETURN
;
}
_kk_scene_LightStripSpecialAction_handle
(
propertyValueJson
,
pDeviceCode
,
epNum
,
idelay
,(
char
*
)
sceneid
,
gwDeviceCode
);
cJSON_Delete
(
propertyValueJson
);
}
}
}
}
if
(
count
==
0
){
//全部移到待分配
kk_scene_delete_send_to_gw
(
sceneid
);
}
else
{
if
(
isMuti
){
kk_scene_muticontrol_info_send
(
array
,
gwDeviceCode
,
sceneid
,
1
);
}
else
{
kk_scene_action_info_send
(
1
);
}
}
sqlite3_free
(
sqlCmd
);
sqlite3_finalize
(
stmt
);
return
0
;
}
int
kk_scene_rebuild_device_active
(
char
*
deviceCode
,
int
epNum
)
{
char
*
sqlCmd
=
NULL
;
int
rc
=
0
;
sqlite3_stmt
*
stmt
;
char
*
zErrMsg
=
0
;
char
*
scene_id
=
NULL
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneActionInfo WHERE deviceCode = '%s' and epNum= '%d'"
,
deviceCode
,
epNum
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
scene_id
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEACTION_SCENEID
);
_kk_rebuild_device_active
(
scene_id
);
usleep
(
100
*
1000
);
}
sqlite3_free
(
sqlCmd
);
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
\ No newline at end of file
nx5_soc_gw/smarthome_z3gw_a133
View file @
b512d951
No preview for this file type
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