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
74c4facd
Commit
74c4facd
authored
Feb 22, 2022
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,增加mqtt遗嘱消息;2,增加房间图标的同步
【提交人】陈伟灿
parent
cfa43aa9
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
355 additions
and
89 deletions
+355
-89
application/kcloud/mqtt_api.c
application/kcloud/mqtt_api.c
+72
-3
common/api/com_api.h
common/api/com_api.h
+1
-0
midware/midware/area/kk_area_handle.c
midware/midware/area/kk_area_handle.c
+33
-7
midware/midware/area/kk_area_handle.h
midware/midware/area/kk_area_handle.h
+2
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+11
-3
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+10
-10
midware/midware/dm/kk_sync_data.c
midware/midware/dm/kk_sync_data.c
+63
-23
midware/midware/dm/kk_sync_data.h
midware/midware/dm/kk_sync_data.h
+1
-0
midware/midware/group/kk_group_db.c
midware/midware/group/kk_group_db.c
+15
-13
midware/midware/group/kk_group_handle.c
midware/midware/group/kk_group_handle.c
+1
-1
midware/midware/midware.c
midware/midware/midware.c
+4
-0
midware/midware/scene/kk_scene_db.c
midware/midware/scene/kk_scene_db.c
+99
-10
midware/midware/scene/kk_scene_db.h
midware/midware/scene/kk_scene_db.h
+18
-6
midware/midware/scene/kk_scene_handle.c
midware/midware/scene/kk_scene_handle.c
+25
-12
nx5_soc_gw/smarthome_z3gw_a133
nx5_soc_gw/smarthome_z3gw_a133
+0
-0
No files found.
application/kcloud/mqtt_api.c
View file @
74c4facd
...
...
@@ -5,12 +5,30 @@
#include "com_api.h"
#include "kk_product.h"
#include "kk_hal.h"
#include "cJSON.h"
static
const
char
*
OPT_SEND
=
"MQTTAsync_sendMessage"
;
static
const
char
*
OPT_SUB
=
"MQTTAsync_subscribe"
;
static
const
char
*
OPT_UNSUB
=
"MQTTAsync_unsubscribe"
;
static
MQTTAsync
s_Client
;
static
int
s_mqttStop
=
0
;
static
int
s_cloudStatus
=
DEVICE_OFFLINE
;
static
char
*
kk_will_message_create
(
char
*
ccuid
,
cJSON
*
payload
)
{
char
msgId
[
64
]
=
{
0
};
char
timestamp
[
16
]
=
{
0
};
sprintf
(
msgId
,
"6c0645c4-f6d6-b11e-%lld"
,
HAL_GetTime_ms
());
sprintf
(
timestamp
,
"%lld"
,
HAL_GetTime_ms
());
cJSON_AddStringToObject
(
payload
,
"msgId"
,
msgId
);
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
cJSON_AddStringToObject
(
payload
,
"time"
,
timestamp
);
cJSON_AddStringToObject
(
payload
,
"method"
,
"thing.status.offline"
);
cJSON
*
param
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
param
,
"deviceCode"
,
ccuid
);
cJSON_AddStringToObject
(
param
,
"ccuCode"
,
ccuid
);
cJSON_AddItemToObject
(
payload
,
"params"
,
param
);
return
cJSON_Print
(
payload
);
}
int
KK_Send_CloudState
(
int
state
);
int
kk_get_cloud_status
(
void
){
return
s_cloudStatus
;
...
...
@@ -38,22 +56,37 @@ static void connlost(void *context, char *cause)
KK_Send_CloudState
(
s_cloudStatus
);
return
;
}
char
topicBuf
[
256
]
=
{
0
};
char
*
message
=
NULL
;
MQTTAsync
client
=
(
MQTTAsync
)
context
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
will_opts
=
MQTTAsync_willOptions_initializer
;
int
rc
;
char
ccuid
[
32
]
=
{
0
};
char
pid
[
32
]
=
{
0
};
KK_Get_ccuid
(
ccuid
);
kk_cloud_get_pid
(
pid
);
sprintf
(
topicBuf
,
"biz/newkk/%s/%s/thing/status/offline"
,
pid
,
ccuid
);
INFO_PRINT
(
"
\n
Connection lost
\n
"
);
INFO_PRINT
(
"cause: %s
\n
"
,
cause
);
s_cloudStatus
=
DEVICE_OFFLINE
;
kk_write_disconnect_flag
();
KK_Send_CloudState
(
s_cloudStatus
);
cJSON
*
willPayload
=
cJSON_CreateObject
();
message
=
kk_will_message_create
(
ccuid
,
willPayload
);
conn_opts
.
keepAliveInterval
=
20
;
conn_opts
.
cleansession
=
1
;
will_opts
.
retained
=
0
;
//retained = 1 时, broker会一直保留消息,这里不需要,使用默认的0就行
will_opts
.
topicName
=
topicBuf
;
will_opts
.
message
=
message
;
conn_opts
.
will
=
&
will_opts
;
if
((
rc
=
MQTTAsync_connect
(
client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
ERROR_PRINT
(
"Failed to start connect, return code %d
\n
"
,
rc
);
s_mqttStop
=
1
;
}
free
(
message
);
cJSON_Delete
(
willPayload
);
}
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
...
...
@@ -213,13 +246,18 @@ void KK_Get_MqttClient(MQTTAsync *pClient)
}
extern
char
g_clientId
[
64
];
extern
char
s_ServerIp
[
16
];
MQTTAsync
KK_MQTT_Connect
(
void
)
{
int
rc
=
0
;
char
temp_address
[
128
]
=
{
0
};
FILE
*
fp
;
char
topicBuf
[
256
]
=
{
0
};
char
*
message
=
NULL
;
MQTTAsync_createOptions
opts
=
MQTTAsync_createOptions_initializer
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
will_opts
=
MQTTAsync_willOptions_initializer
;
MQTTAsync_setTraceCallback
(
mqttTraceCallback
);
opts
.
MQTTVersion
=
MQTTVERSION_3_1_1
;
char
mac
[
16
]
=
{
0
};
...
...
@@ -236,6 +274,9 @@ MQTTAsync KK_MQTT_Connect(void)
KK_Get_ccuid
(
ccuid
);
kk_cloud_get_pid
(
pid
);
sprintf
(
usrname
,
"%s.%s"
,
ccuid
,
pid
);
sprintf
(
topicBuf
,
"biz/newkk/%s/%s/thing/status/offline"
,
pid
,
ccuid
);
INFO_PRINT
(
"topicBuf:%s
\n
"
,
topicBuf
);
INFO_PRINT
(
"cliendid:%s,usrname:%s
\n
"
,
g_clientId
,
usrname
);
INFO_PRINT
(
"------------>token:%s
\n
"
,
token
);
sprintf
(
temp_address
,
"tcp://%s:1983"
,
s_ServerIp
);
...
...
@@ -247,7 +288,8 @@ MQTTAsync KK_MQTT_Connect(void)
}
/*Set the mqtt callback*/
mqtt_set_callbacks
();
cJSON
*
willPayload
=
cJSON_CreateObject
();
message
=
kk_will_message_create
(
ccuid
,
willPayload
);
conn_opts
.
keepAliveInterval
=
30
;
conn_opts
.
connectTimeout
=
CONNECT_TIMEOUT
;
conn_opts
.
automaticReconnect
=
AUTO_CONN
;
...
...
@@ -261,11 +303,19 @@ MQTTAsync KK_MQTT_Connect(void)
conn_opts
.
onSuccess
=
onConnect
;
conn_opts
.
onFailure
=
onConnectFailure
;
conn_opts
.
context
=
s_Client
;
will_opts
.
retained
=
0
;
//retained = 1 时, broker会一直保留消息,这里不需要,使用默认的0就行
will_opts
.
topicName
=
topicBuf
;
will_opts
.
message
=
message
;
conn_opts
.
will
=
&
will_opts
;
if
((
rc
=
MQTTAsync_connect
(
s_Client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
ERROR_PRINT
(
"Failed to start connect, return code %d
\n
"
,
rc
);
free
(
message
);
cJSON_Delete
(
willPayload
);
return
NULL
;
}
cJSON_Delete
(
willPayload
);
free
(
message
);
return
s_Client
;
}
MQTTAsync
KK_MQTT_Connect_ex
(
char
*
usrname
,
char
*
pwd
,
char
*
cliendId
,
char
*
host
,
char
*
port
)
...
...
@@ -273,8 +323,17 @@ MQTTAsync KK_MQTT_Connect_ex(char *usrname,char*pwd,char*cliendId,char*host,char
int
rc
=
0
;
char
temp_address
[
256
]
=
{
0
};
FILE
*
fp
;
char
topicBuf
[
256
]
=
{
0
};
char
*
message
=
NULL
;
char
ccuid
[
32
]
=
{
0
};
char
pid
[
32
]
=
{
0
};
KK_Get_ccuid
(
ccuid
);
kk_cloud_get_pid
(
pid
);
sprintf
(
topicBuf
,
"biz/newkk/%s/%s/thing/status/offline"
,
pid
,
ccuid
);
INFO_PRINT
(
"topicBuf:%s
\n
"
,
topicBuf
);
MQTTAsync_createOptions
opts
=
MQTTAsync_createOptions_initializer
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
will_opts
=
MQTTAsync_willOptions_initializer
;
MQTTAsync_setTraceCallback
(
mqttTraceCallback
);
opts
.
MQTTVersion
=
MQTTVERSION_3_1_1
;
sprintf
(
temp_address
,
"tcp://%s:%s"
,
host
,
port
);
...
...
@@ -286,7 +345,9 @@ MQTTAsync KK_MQTT_Connect_ex(char *usrname,char*pwd,char*cliendId,char*host,char
}
/*Set the mqtt callback*/
mqtt_set_callbacks
();
cJSON
*
willPayload
=
cJSON_CreateObject
();
message
=
kk_will_message_create
(
ccuid
,
willPayload
);
INFO_PRINT
(
"will message:%s
\n
"
,
message
);
conn_opts
.
keepAliveInterval
=
30
;
conn_opts
.
connectTimeout
=
CONNECT_TIMEOUT
;
conn_opts
.
automaticReconnect
=
AUTO_CONN
;
...
...
@@ -300,11 +361,19 @@ MQTTAsync KK_MQTT_Connect_ex(char *usrname,char*pwd,char*cliendId,char*host,char
conn_opts
.
onSuccess
=
onConnect
;
conn_opts
.
onFailure
=
onConnectFailure
;
conn_opts
.
context
=
s_Client
;
will_opts
.
retained
=
0
;
//retained = 1 时, broker会一直保留消息,这里不需要,使用默认的0就行
will_opts
.
topicName
=
topicBuf
;
will_opts
.
message
=
message
;
conn_opts
.
will
=
&
will_opts
;
if
((
rc
=
MQTTAsync_connect
(
s_Client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
ERROR_PRINT
(
"Failed to start connect, return code %d
\n
"
,
rc
);
free
(
message
);
cJSON_Delete
(
willPayload
);
return
NULL
;
}
free
(
message
);
cJSON_Delete
(
willPayload
);
return
s_Client
;
}
int
KK_MQTT_SubTopic
(
char
*
topicName
)
...
...
common/api/com_api.h
View file @
74c4facd
...
...
@@ -77,6 +77,7 @@ typedef enum {
#define MSG_ONLINE_STATUS_STR "onlineStatus"
#define MSG_AREA_ROOM_FLOORS "floors"
#define MSG_AREA_ROOM_FLOOR_ID "floorId"
#define MSG_AREA_ROOM_ICON "roomIcon"
#define MSG_AREA_ROOM_FLOOR_ROOMS "rooms"
/************************LOCK KEY*************************/
#define MSG_KEYDELETE_NOTIFICATION_KEYID "KeyDeletedNotification.KeyID"
...
...
midware/midware/area/kk_area_handle.c
View file @
74c4facd
...
...
@@ -57,7 +57,8 @@ static int _kk_area_db_init(void)
roomId varchar(256), \
armingstate INTEGER, \
floorId varchar(256), \
floorName varchar(256))"
;
floorName varchar(256), \
roomIcon varchar(256))"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pAreaTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
{
...
...
@@ -144,19 +145,19 @@ static int kk_check_room_exist(const char *roomId)
return
isExist
;
}
static
int
_kk_room_add
(
const
char
*
name
,
const
char
*
roomId
)
static
int
_kk_room_add
(
const
char
*
name
,
const
char
*
roomId
,
const
char
*
icon
)
{
int
res
=
0
;
kk_area_ctx_t
*
ctx
=
_kk_area_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into AreaInfo (name, roomId,armingstate,floorId,floorName) \
values ('%s','%s','%d','%s','%s');"
;
const
char
*
insertCmd
=
"insert into AreaInfo (name, roomId,armingstate,floorId,floorName
,roomIcon
) \
values ('%s','%s','%d','%s','%s'
,'%s'
);"
;
_kk_area_lock
();
ctx
->
roomNum
++
;
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
roomId
,
-
1
,
"0"
,
"默认"
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
name
,
roomId
,
-
1
,
"0"
,
"默认"
,
icon
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
...
...
@@ -191,6 +192,30 @@ static int _kk_room_update(const char *name,const char *roomId)
_kk_area_unlock
();
return
SUCCESS_RETURN
;
}
static
int
_kk_roomIcon_update
(
const
char
*
roomIcon
,
const
char
*
roomId
)
{
int
res
=
0
;
kk_area_ctx_t
*
ctx
=
_kk_area_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
if
(
roomIcon
==
NULL
){
return
FAIL_RETURN
;
}
sqlCmd
=
sqlite3_mprintf
(
"UPDATE AreaInfo SET roomIcon='%s' WHERE roomId= '%s'"
,
roomIcon
,
roomId
);
_kk_area_lock
();
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
;
}
static
int
_kk_room_dev_update
(
const
char
*
name
,
const
char
*
roomId
)
{
int
res
=
0
;
...
...
@@ -213,15 +238,16 @@ static int _kk_room_dev_update(const char *name,const char *roomId)
_kk_area_unlock
();
return
SUCCESS_RETURN
;
}
int
kk_room_add
(
const
char
*
name
,
const
char
*
roomId
)
int
kk_room_add
(
const
char
*
name
,
const
char
*
roomId
,
const
char
*
icon
)
{
if
(
kk_check_room_exist
(
roomId
)){
printf
(
"name=%s,room id=%s
\n
"
,
name
,
roomId
);
_kk_room_dev_update
(
name
,
roomId
);
_kk_room_update
(
name
,
roomId
);
_kk_roomIcon_update
(
icon
,
roomId
);
return
0
;
}
else
{
return
_kk_room_add
(
name
,
roomId
);
return
_kk_room_add
(
name
,
roomId
,
icon
);
}
}
...
...
midware/midware/area/kk_area_handle.h
View file @
74c4facd
...
...
@@ -19,6 +19,7 @@ enum{
DB_ROOM_ARMING
,
DB_ROOM_FLOORID
,
DB_ROOM_FLOORNAME
,
DB_ROOM_ROOMICON
,
};
enum
{
...
...
@@ -35,7 +36,7 @@ enum{
DB_FLOOR_ID
,
};
int
kk_room_delete
(
const
char
*
roomId
);
int
kk_room_add
(
const
char
*
name
,
const
char
*
roomId
);
int
kk_room_add
(
const
char
*
name
,
const
char
*
roomId
,
const
char
*
icon
);
int
kk_area_init
(
void
);
int
kk_room_dev_add
(
const
char
*
roomId
,
const
char
*
roomName
,
const
char
*
deviceCode
,
const
char
*
epNum
,
const
char
*
devName
);
int
kk_room_dev_remove
(
const
char
*
deviceCode
,
const
char
*
epNum
);
...
...
midware/midware/dm/kk_linkkit.c
View file @
74c4facd
...
...
@@ -534,9 +534,13 @@ static int kk_service_addRoom_handle(const char *deviceCode, cJSON *params,cJSON
if
(
floorId
==
NULL
){
//return FAIL_RETURN;
}
cJSON
*
icon
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_ICON
);
if
(
icon
==
NULL
){
return
FAIL_RETURN
;
}
//memcpy(roomId,roomIdStr->valuestring,strlen(roomIdStr->valuestring));
HAL_GetTime_s
((
char
*
)
roomId
);
kk_room_add
(
roomInfoStr
->
valuestring
,
roomId
);
kk_room_add
(
roomInfoStr
->
valuestring
,
roomId
,
icon
->
valuestring
);
kk_service_addRoom_reply
(
inforoot
,
msgid
,
roomId
,
0
);
kk_tsl_set_value
(
kk_tsl_set_event_output_value
,
node
->
dev_shadow
,
MSG_AREA_ADDROOM_NOTIFICATION_ROOMID
,
NULL
,
roomId
);
if
(
floorId
!=
NULL
){
...
...
@@ -646,9 +650,13 @@ static int kk_service_updateRoom_handle(const char *deviceCode, cJSON *params,cJ
if
(
roomInfoStr
==
NULL
||
roomIdStr
==
NULL
){
return
FAIL_RETURN
;
}
cJSON
*
icon
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_ICON
);
if
(
icon
==
NULL
){
return
FAIL_RETURN
;
}
//memcpy(roomId,roomIdStr->valuestring,strlen(roomIdStr->valuestring));
//INFO_PRINT(" update room 111!!! %s.%s\n",roomInfoStr->valuestring,roomIdStr->valuestring);
kk_room_add
(
roomInfoStr
->
valuestring
,
roomIdStr
->
valuestring
);
kk_room_add
(
roomInfoStr
->
valuestring
,
roomIdStr
->
valuestring
,
icon
->
valuestring
);
cJSON
*
floorId
=
cJSON_GetObjectItem
(
params
,
MSG_AREA_ROOM_FLOOR_ID
);
if
(
floorId
==
NULL
){
kk_service_addRoom_reply
(
inforoot
,
msgid
,
roomIdStr
->
valuestring
,
1
);
...
...
@@ -1964,7 +1972,7 @@ static int kk_service_bindScene_handle(cJSON *params,char *deviceCodeStr)
if
(
deviceCode
==
NULL
)
return
FAIL_RETURN
;
res
=
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
1
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
0
,
sceneId
,
deviceCode
->
valuestring
);
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
0
,
sceneId
,
deviceCode
->
valuestring
,
1
);
kk_scene_insert_panel_scene_info
(
bindType
->
valueint
,
btnId
,
deviceCodeStr
,
sceneId
,
"-1"
,
""
);
item
=
item
->
next
;
}
...
...
midware/midware/dm/kk_sub_db.c
View file @
74c4facd
...
...
@@ -659,7 +659,7 @@ static int _kk_indoor_air_info_handle(char* deviceCode,char* propertyName,char*
kk_scene_action_add
(
gwDeviceCode
,
sceneId
,
info
);
if
(
insert
){
res
=
kk_scene_insert_scene_action
(
type
,
deviceCode
,
info
.
epNum
,
propertyName
,
propertyValue
,
info
.
delay
,
sceneId
,
gwDeviceCode
);
propertyName
,
propertyValue
,
info
.
delay
,
sceneId
,
gwDeviceCode
,
2
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_subDev_set_action_by_productType fail!!!
\n
"
);
}
...
...
@@ -732,7 +732,7 @@ static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *property
if
(
strcmp
(
propertyName
,
"CustomAction"
)
==
0
){
kk_indoor_air_action_add
(
propertyValue
,
deviceCode
,
delay
,
gwDeviceCode
,
sceneId
,
type
,
eplist
[
i
]);
kk_scene_insert_scene_action
(
type
,
deviceCode
,
eplist
[
i
],
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
);
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
}
else
{
_kk_indoor_air_info_handle
(
deviceCode
,
propertyName
,
propertyValue
,
eplist
[
i
],
delay
,
gwDeviceCode
,
sceneId
,
type
,
1
);
}
...
...
@@ -757,7 +757,7 @@ static int _kk_airConditon_handle(char* deviceCode, char *sceneId, char *propert
if
(
strcmp
(
propertyName
,
"CustomAction"
)
==
0
){
kk_indoor_air_action_add
(
propertyValue
,
deviceCode
,
delay
,
gwDeviceCode
,
sceneId
,
type
,
1
);
kk_scene_insert_scene_action
(
type
,
deviceCode
,
1
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
);
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwDeviceCode
,
2
);
}
else
{
_kk_indoor_air_info_handle
(
deviceCode
,
propertyName
,
propertyValue
,
1
,
delay
,
gwDeviceCode
,
sceneId
,
type
,
1
);
}
...
...
@@ -905,7 +905,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *room
devIsExsit
=
1
;
kk_scene_action_add
(
node
->
fatherDeviceCode
,
sceneId
,
info
);
res
=
kk_scene_insert_scene_action
(
type
,
node
->
deviceCode
,
info
.
epNum
,
property
->
identifier
,
propertyValue
,
info
.
delay
,
sceneId
,
node
->
fatherDeviceCode
);
property
->
identifier
,
propertyValue
,
info
.
delay
,
sceneId
,
node
->
fatherDeviceCode
,
2
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_subDev_set_action_by_productType fail!!!
\n
"
);
//return res;
...
...
@@ -915,13 +915,13 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *room
}
}
if
(
devIsExsit
==
0
){
//设置场景,但是又没有对应的设备需要插入一条无效action用于记录propertyName,同步需要
res
=
kk_scene_insert_scene_action
(
type
,
""
,
1
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
""
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_subDev_set_action_by_productType fail!!!
\n
"
);
//
res = kk_scene_insert_scene_action(type,"",1,
//
propertyName,propertyValue,delay,sceneId,"");
//
if(res != SUCCESS_RETURN){
//
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue
;
}
//
continue;
//
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
...
...
midware/midware/dm/kk_sync_data.c
View file @
74c4facd
...
...
@@ -30,7 +30,7 @@
extern
sqlite3
*
g_kk_pDb
;
static
int
kk_check_multi_ep_num
(
char
*
deviceCode
);
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
char
*
productType
,
char
*
actionRoomId
);
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
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
);
...
...
@@ -168,6 +168,7 @@ static int kk_get_rooms_info(cJSON *data)
sqlite3_stmt
*
stmt
;
char
*
roomId
=
NULL
;
char
*
roomName
=
NULL
;
char
*
roomIcon
=
NULL
;
//int valueType = 0;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
data
==
NULL
){
...
...
@@ -185,8 +186,10 @@ static int kk_get_rooms_info(cJSON *data)
roomItem
=
cJSON_CreateObject
();
roomId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_ROOM_ID
);
roomName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_ROOM_NAME
);
roomIcon
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_ROOM_ROOMICON
);
cJSON_AddStringToObject
(
roomItem
,
KK_SYNC_ROOMID_STR
,
roomId
);
cJSON_AddStringToObject
(
roomItem
,
KK_SYNC_NANE_STR
,
roomName
);
cJSON_AddStringToObject
(
roomItem
,
KK_SYNC_ROOMICON
,
roomIcon
);
roomDevicesArray
=
kk_get_room_devices
(
roomId
);
cJSON_AddItemToObject
(
roomItem
,
KK_SYNC_DEVICES_STR
,
roomDevicesArray
);
...
...
@@ -1017,8 +1020,55 @@ static int kk_get_panel_scenes_actions_info(cJSON *actionItem,char * id)
}
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
char
*
productType
,
char
*
actionRoomId
)
static
int
kk_get_scenes_actions_productTypeinfo
(
cJSON
*
actionArray
,
char
*
id
,
char
*
deviceCode
)
{
char
*
sqlCmd
=
NULL
;
sqlite3_stmt
*
stmt
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
char
*
propertyName
=
NULL
;
char
*
propertyValue
=
NULL
;
char
*
productType
=
NULL
;
char
*
roomId
=
NULL
;
int
delay
=
0
;
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneProTypeInfo where sceneId = '%s'"
,
id
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
cJSON
*
actionItem
;
actionItem
=
cJSON_CreateObject
();
delay
=
sqlite3_column_int
(
stmt
,
DB_SCENEPROTYPE_DELAY
);
propertyName
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEPROTYPE_PROPERTYNAME
);
propertyValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEPROTYPE_PROPERTYVALUE
);
productType
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEPROTYPE_PROTYPE
);
roomId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEPROTYPE_ROOMID
);
if
(
strstr
(
propertyValue
,
"{"
)
!=
NULL
&&
strstr
(
propertyValue
,
"}"
)
!=
NULL
){
cJSON
*
prtyObj
=
cJSON_Parse
(
propertyValue
);
if
(
prtyObj
!=
NULL
){
cJSON_AddItemToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYVALUE_STR
,
prtyObj
);
}
else
{
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYVALUE_STR
,
propertyValue
);
}
}
else
{
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYVALUE_STR
,
propertyValue
);
}
char
*
propertiesbuf
[
64
]
=
{
0
};
int
num
=
0
;
kk_split
(
propertyName
,
"_"
,
propertiesbuf
,
&
num
);
if
(
num
==
2
){
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYNAME_STR
,
propertiesbuf
[
0
]);
}
else
{
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYNAME_STR
,
propertyName
);
}
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_TYPE_STR
,
"action/thing/setProperty"
);
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
,
1
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PRODUCTTYPE
,
productType
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_ROOMID_STR
,
roomId
);
cJSON_AddItemToArray
(
actionArray
,
actionItem
);
}
return
0
;
}
static
int
kk_get_scenes_actions_info
(
cJSON
*
actionArray
,
char
*
id
,
char
*
productType
)
{
char
*
sqlCmd
=
NULL
;
//char *zErrMsg = 0;
...
...
@@ -1032,9 +1082,12 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
char
*
type
=
NULL
;
int
delay
=
0
,
epNum
=
0
,
scene_id
=
0
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
actionArray
==
NULL
||
productType
==
NULL
||
actionRoomId
==
NULL
){
if
(
actionArray
==
NULL
||
productType
==
NULL
){
return
FAIL_RETURN
;
}
if
(
strcmp
(
productType
,
""
)
!=
0
){
kk_get_scenes_actions_productTypeinfo
(
actionArray
,
id
,
""
);
}
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
){
...
...
@@ -1082,20 +1135,11 @@ static int kk_get_scenes_actions_info(cJSON *actionArray,char* id,char *productT
}
else
{
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PROPERTYVALUE_STR
,
propertyValue
);
}
if
(
strcmp
(
productType
,
""
)
!=
0
){
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_SCENE_PRODUCTTYPE
,
productType
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_ROOMID_STR
,
actionRoomId
);
cJSON_AddItemToArray
(
actionArray
,
actionItem
);
break
;
}
else
{
kk_get_roomId_by_scene_id
(
scene_id
,
room_id
);
cJSON_AddStringToObject
(
actionItem
,
KK_SYNC_ROOMID_STR
,
room_id
);
cJSON_AddItemToArray
(
actionArray
,
actionItem
);
}
}
}
sqlite3_free
(
sqlCmd
);
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
...
...
@@ -1196,7 +1240,7 @@ static int kk_get_scenes_trigger_info(cJSON *triggerObj,char *sceneId)
cJSON_AddItemToArray
(
triggerAry
,
conditionItem
);
}
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo where sceneId = %s
"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo where sceneId = %s
and active = %d"
,
sceneId
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
...
...
@@ -1291,7 +1335,7 @@ static int kk_get_scenes_condition_info(cJSON *conditionObj,char *sceneId)
int
epNum
=
0
;
int
isAnd
;
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo where sceneId = %s
"
,
sceneId
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo where sceneId = %s
and active = %d"
,
sceneId
,
1
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
...
...
@@ -1334,7 +1378,6 @@ static int kk_get_scenes_info(cJSON *data)
char
*
roomId
=
NULL
;
char
*
sceneId
=
NULL
;
char
*
productType
=
NULL
;
char
*
actionRoomId
=
NULL
;
kk_sync_ctx_t
*
ctx
=
_kk_sync_get_ctx
();
if
(
data
==
NULL
){
return
FAIL_RETURN
;
...
...
@@ -1357,11 +1400,10 @@ static int kk_get_scenes_info(cJSON *data)
sceneId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEINFO_SCENEID
);
roomId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEINFO_ROOMID
);
productType
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEINFO_PRODUCTTYPE
);
actionRoomId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENEINFO_ACTIONROOMID
);
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
,
sceneId
,
productType
,
actionRoomId
);
kk_get_scenes_actions_info
(
actionArray
,
sceneId
,
productType
);
cJSON_AddItemToObject
(
sceneArrayItem
,
KK_SYNC_SCENE_ACTIONS_STR
,
actionArray
);
cJSON
*
triggerObj
=
cJSON_CreateObject
();
kk_get_scenes_trigger_info
(
triggerObj
,
sceneId
);
...
...
@@ -1379,7 +1421,6 @@ static int kk_get_scenes_info(cJSON *data)
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
static
int
kk_get_group_info
(
cJSON
*
data
)
{
cJSON
*
group
=
kk_group_db_query
(
1
);
...
...
@@ -1387,7 +1428,6 @@ static int kk_get_group_info(cJSON *data)
return
SUCCESS_RETURN
;
}
/*
static int kk_get_ccu_properties(cJSON *property)
{
...
...
midware/midware/dm/kk_sync_data.h
View file @
74c4facd
...
...
@@ -8,6 +8,7 @@
#define KK_SYNC_DEVICES_STR "devices"
#define KK_SYNC_DEVICECODE_STR "deviceCode"
#define KK_SYNC_NANE_STR "name"
#define KK_SYNC_ROOMICON "roomIcon"
#define KK_SYNC_SCENEID_STR "sceneId"
#define KK_SYNC_SCENE_STR "scenes"
#define KK_SYNC_VERSION_STR "firmwareVersion"
...
...
midware/midware/group/kk_group_db.c
View file @
74c4facd
...
...
@@ -112,6 +112,7 @@ int kk_group_db_init(void)
INFO_PRINT
(
"kk_group_db_init db Database opened
\n
"
);
kk_group_info_db_init
();
kk_group_device_db_init
();
return
0
;
}
static
int
kk_group_info_db_check
(
const
char
*
groupId
)
...
...
@@ -330,12 +331,12 @@ static cJSON *kk_group_device_db_query(const char *groupId,int isSync)
didListItem
=
cJSON_CreateObject
();
if
(
isSync
!=
0
){
cJSON_AddNumberToObject
(
didListItem
,
"epNum"
,
atoi
(
epnum
));
cJSON_AddNumberToObject
(
didListItem
,
"epNum"
,
atoi
(
(
char
*
)
epnum
));
}
else
{
cJSON_AddStringToObject
(
didListItem
,
"epNum"
,
epnum
);
cJSON_AddStringToObject
(
didListItem
,
"epNum"
,
(
char
*
)
epnum
);
}
cJSON_AddStringToObject
(
didListItem
,
"deviceCode"
,
deviceCode
);
cJSON_AddStringToObject
(
didListItem
,
"deviceCode"
,
(
char
*
)
deviceCode
);
cJSON_AddItemToArray
(
didListAry
,
didListItem
);
}
sqlite3_finalize
(
stmt
);
...
...
@@ -369,15 +370,15 @@ cJSON *kk_group_db_query(int isSync)
groupName
=
sqlite3_column_text
(
stmt
,
GROUP_INFO_DB_NAME
);
ccuRoomId
=
sqlite3_column_text
(
stmt
,
GROUP_INFO_DB_CCUROOMID
);
INFO_PRINT
(
"groupId=%s,groupName=%s,ccuRoomId=%s
\n
"
,
groupId
,
groupName
,
ccuRoomId
);
didListAry
=
kk_group_device_db_query
(
groupId
,
isSync
);
didListAry
=
kk_group_device_db_query
(
(
const
char
*
)
groupId
,
isSync
);
groupListItem
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
groupListItem
,
"groupId"
,
groupId
);
cJSON_AddStringToObject
(
groupListItem
,
"groupName"
,
groupName
);
cJSON_AddStringToObject
(
groupListItem
,
"groupId"
,
(
char
*
)
groupId
);
cJSON_AddStringToObject
(
groupListItem
,
"groupName"
,
(
char
*
)
groupName
);
if
(
isSync
!=
0
){
cJSON_AddStringToObject
(
groupListItem
,
"roomId"
,
ccuRoomId
);
cJSON_AddStringToObject
(
groupListItem
,
"roomId"
,
(
char
*
)
ccuRoomId
);
}
else
{
cJSON_AddStringToObject
(
groupListItem
,
"ccuRoomId"
,
ccuRoomId
);
cJSON_AddStringToObject
(
groupListItem
,
"ccuRoomId"
,
(
char
*
)
ccuRoomId
);
}
cJSON_AddItemToObject
(
groupListItem
,
"didList"
,
didListAry
);
...
...
@@ -396,6 +397,7 @@ cJSON *kk_group_device_db_exe_act(const char *groupId,int controlType,int proper
char
*
sqlCmd
=
NULL
;
const
unsigned
char
*
epnum
=
NULL
;
const
unsigned
char
*
deviceCode
=
NULL
;
const
unsigned
char
*
fatherDeviceCode
=
NULL
;
kk_group_ctx_t
*
ctx
=
_kk_group_get_ctx
();
cJSON
*
actionsAry
=
cJSON_CreateArray
();
...
...
@@ -411,14 +413,14 @@ cJSON *kk_group_device_db_exe_act(const char *groupId,int controlType,int proper
INFO_PRINT
(
"groupId=%s,epnum=%s,deviceCode=%s
\n
"
,
groupId
,
epnum
,
deviceCode
);
if
(
strlen
(
parent
)
==
0
){
const
char
*
fatherDeviceCode
=
sqlite3_column_text
(
stmt
,
GROUP_DEVICE_DB_PARENT_DEVICECODE
);
fatherDeviceCode
=
sqlite3_column_text
(
stmt
,
GROUP_DEVICE_DB_PARENT_DEVICECODE
);
sprintf
(
parent
,
"%s"
,
fatherDeviceCode
);
}
actionItem
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
actionItem
,
"type"
,
"action/thing/cluster"
);
cJSON_AddStringToObject
(
actionItem
,
"epNum"
,
epnum
);
cJSON_AddStringToObject
(
actionItem
,
"deviceCode"
,
deviceCode
);
cJSON_AddStringToObject
(
actionItem
,
"epNum"
,
(
char
*
)
epnum
);
cJSON_AddStringToObject
(
actionItem
,
"deviceCode"
,
(
char
*
)
deviceCode
);
char
buf
[
64
];
memset
(
buf
,
0
,
sizeof
(
buf
));
...
...
@@ -446,7 +448,7 @@ int kk_group_device_db_find_parent(const char *groupId,char *parent)
{
sqlite3_stmt
*
stmt
;
char
*
sqlCmd
=
NULL
;
const
unsigned
char
*
fatherDeviceCode
=
NULL
;
kk_group_ctx_t
*
ctx
=
_kk_group_get_ctx
();
...
...
@@ -455,7 +457,7 @@ int kk_group_device_db_find_parent(const char *groupId,char *parent)
INFO_PRINT
(
"Table searchCmd:%s
\n
"
,
sqlCmd
);
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
const
char
*
fatherDeviceCode
=
sqlite3_column_text
(
stmt
,
GROUP_DEVICE_DB_PARENT_DEVICECODE
);
fatherDeviceCode
=
sqlite3_column_text
(
stmt
,
GROUP_DEVICE_DB_PARENT_DEVICECODE
);
sprintf
(
parent
,
"%s"
,
fatherDeviceCode
);
break
;
}
...
...
midware/midware/group/kk_group_handle.c
View file @
74c4facd
...
...
@@ -38,7 +38,7 @@ static int kk_service_group_msg_send_to_gw(const char *type,cJSON *params,const
cJSON_AddStringToObject
(
payload
,
"version"
,
"1.0"
);
char
tm
[
33
]
=
{
0
};
snprintf
(
tm
,
sizeof
(
tm
),
"%d"
,
time
(
NULL
));
snprintf
(
tm
,
sizeof
(
tm
),
"%
l
d"
,
time
(
NULL
));
cJSON_AddStringToObject
(
payload
,
"time"
,
tm
);
memset
(
buff
,
0
,
sizeof
(
buff
));
...
...
midware/midware/midware.c
View file @
74c4facd
...
...
@@ -800,6 +800,10 @@ int kk_dm_device_subdev_filter(char *data)
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
struct
kk_motor_bind_info
*
info
=
(
struct
kk_motor_bind_info
*
)
malloc
(
sizeof
(
struct
kk_motor_bind_info
)
*
KK_MOTOR_BIND_INFO_MAX
);
if
(
info
==
NULL
){
return
-
1
;
}
memset
(
info
,
0x0
,
sizeof
(
struct
kk_motor_bind_info
)
*
KK_MOTOR_BIND_INFO_MAX
);
int
info_size
=
kk_service_query_bind_motor
(
deviceCode
,
paramStr
,
info
,
KK_MOTOR_BIND_INFO_MAX
);
cJSON
*
ary
=
cJSON_CreateArray
();
...
...
midware/midware/scene/kk_scene_db.c
View file @
74c4facd
...
...
@@ -72,7 +72,8 @@ int kk_scene_db_init(void)
compareType varchar(255), \
compareValue varchar(255), \
sceneId varchar(255), \
isAnd INTEGER)"
;
isAnd INTEGER, \
active INTEGER)"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneTriggerTable
,
NULL
,
NULL
,
&
pcErr
)
!=
SQLITE_OK
)
...
...
@@ -182,6 +183,23 @@ int kk_scene_db_init(void)
_kk_scene_unlock
();
return
FAIL_RETURN
;
}
const
char
*
pSceneProTypeInfo
=
"CREATE TABLE IF NOT EXISTS SceneProTypeInfo( \
sceneId varchar(255), \
roomId varchar(255), \
propertyName varchar(255), \
propertyValue varchar(255), \
productType varchar(255), \
delay INTEGER)"
;
if
(
sqlite3_exec
(
ctx
->
pDb
,
pSceneProTypeInfo
,
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
;
}
#if 0
printf("-------------------------------eee-----------------------akdkkkkkkkkkkkkkkkkkkkk---\n");
sqlite3_stmt *stmt;
...
...
@@ -535,11 +553,11 @@ int kk_scene_insert_scene_trigger(const char* type,const char* deviceCode,int ep
return
SUCCESS_RETURN
;
}
const
char
*
insertCmd
=
"insert into SceneTriggerInfo (type, deviceCode,epNum,propertyName,compareType,compareValue,sceneId,isAnd) \
values ('%s','%s','%d','%s','%s','%s','%s','%d');"
;
const
char
*
insertCmd
=
"insert into SceneTriggerInfo (type, deviceCode,epNum,propertyName,compareType,compareValue,sceneId,isAnd
,active
) \
values ('%s','%s','%d','%s','%s','%s','%s','%d'
,'%d'
);"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
compareType
,
compareValue
,
sceneId
,
isAnd
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
compareType
,
compareValue
,
sceneId
,
isAnd
,
1
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
...
...
@@ -717,7 +735,7 @@ int kk_scene_insert_scene_invokeService(const char* type,const char* identifier,
*************************************************************/
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
)
const
char
*
propertyValue
,
int
delay
,
const
char
*
sceneId
,
const
char
*
gwdeviceCode
,
int
act
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
...
@@ -728,7 +746,7 @@ int kk_scene_insert_scene_action(const char* type,const char* deviceCode,int epN
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
,
1
);
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
type
,
deviceCode
,
epNum
,
propertyName
,
propertyValue
,
delay
,
sceneId
,
gwdeviceCode
,
act
);
res
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
res
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
...
...
@@ -764,8 +782,14 @@ int kk_scene_update_device_active(char *deviceCode,int epNum,int value)
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
);
sqlCmd
=
sqlite3_mprintf
(
"UPDATE SceneTriggerInfo SET active='%d' WHERE deviceCode = '%s' and epNum= '%d'"
,
value
,
deviceCode
,
epNum
);
rc
=
sqlite3_exec
(
ctx
->
pDb
,
sqlCmd
,
NULL
,
NULL
,
&
zErrMsg
);
if
(
rc
!=
SQLITE_OK
){
ERROR_PRINT
(
"SQL error: %s
\n
"
,
zErrMsg
);
sqlite3_free
(
zErrMsg
);
}
sqlite3_free
(
sqlCmd
);
_kk_scene_unlock
();
...
...
@@ -890,6 +914,36 @@ int kk_scene_delete_scene_condition(const char *sceneId)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 从数据库删除场景触发的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_delete_scene_protype
(
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 SceneProTypeInfo 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
;
}
/************************************************************
*功能描述: 从数据库删除定时场景的基本数据
*输入参数: sceneId:场景Id
*输出参数: 无
...
...
@@ -1011,5 +1065,40 @@ int kk_scene_delete_scene_action(const char *sceneId,int isforword)
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述: 添加场景信息到数据库
*输入参数: name:场景名称
enable: 1,使能;0,不使能
sceneType:场景类型
sceneId:场景Id
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_scene_insert_sceneProType_info
(
const
char
*
roomId
,
char
*
propertyName
,
char
*
propertyValue
,
const
char
*
sceneId
,
char
*
productType
,
int
delay
)
{
int
res
=
0
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
char
*
sqlCmd
=
NULL
;
char
*
zErrMsg
=
0
;
const
char
*
insertCmd
=
"insert into SceneProTypeInfo (sceneId,roomId,propertyName,propertyValue,productType,delay) \
values ('%s','%s','%s','%s','%s','%d');"
;
_kk_scene_lock
();
sqlCmd
=
sqlite3_mprintf
(
insertCmd
,
sceneId
,
roomId
,
propertyName
,
propertyValue
,
productType
,
delay
);
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
View file @
74c4facd
...
...
@@ -28,6 +28,7 @@ enum{
DB_SCENETRIGGER_COMPAREVALUE
,
DB_SCENETRIGGER_SCENEID
,
DB_SCENETRIGGER_ISAND
,
DB_SCENETRIGGER_ACTIVE
,
};
enum
{
...
...
@@ -79,6 +80,15 @@ enum{
DB_QUICKPANEL_ROOMID
,
DB_QUICKPANEL_PRODUCTTYPE
,
};
enum
{
DB_SCENEPROTYPE_SCENEID
=
0
,
DB_SCENEPROTYPE_ROOMID
,
DB_SCENEPROTYPE_PROPERTYNAME
,
DB_SCENEPROTYPE_PROPERTYVALUE
,
DB_SCENEPROTYPE_PROTYPE
,
DB_SCENEPROTYPE_DELAY
,
};
int
kk_scene_delete_scene_timing
(
const
char
*
sceneId
);
int
kk_scene_delete_scene_condition
(
const
char
*
sceneId
);
int
kk_scene_delete_scene_trigger
(
const
char
*
sceneId
);
...
...
@@ -87,13 +97,13 @@ int kk_scene_delete_scene_info(const char *sceneId);
int
kk_scene_delete_scene_invokeservice
(
const
char
*
sceneId
);
int
kk_scene_delete_scene_action
(
const
char
*
sceneId
,
int
isforword
);
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
);
const
char
*
propertyValue
,
int
delay
,
const
char
*
sceneId
,
const
char
*
gwdeviceCode
,
int
act
);
int
kk_scene_insert_scene_invokeService
(
const
char
*
type
,
const
char
*
identifier
,
const
char
*
args
,
const
char
*
sceneId
);
int
kk_scene_insert_scene_embed
(
int
delay
,
const
char
*
executeSceneId
,
const
char
*
sceneId
);
int
kk_scene_insert_scene_timer
(
time_t
startTime
,
char
weekflag
,
const
char
*
sceneId
);
int
kk_scene_insert_scene_condition
(
const
char
*
type
,
int
startTime
,
int
endTime
,
int
crossDay
,
char
repeat_days
,
const
char
*
sceneId
);
int
kk_scene_insert_scene_trigger
(
const
char
*
type
,
const
char
*
deviceCode
,
int
epNum
,
const
char
*
propertyName
,
int
kk_scene_insert_scene_trigger
(
const
char
*
type
,
const
char
*
deviceCode
,
int
epNum
,
const
char
*
propertyName
,
const
char
*
compareType
,
const
char
*
compareValue
,
const
char
*
sceneId
,
int
isAnd
);
int
kk_scene_insert_scene_info
(
const
char
*
roomId
,
const
char
*
sceneName
,
int
sceneType
,
int
enable
,
const
char
*
sceneId
,
char
*
productType
,
char
*
actionRoomId
);
int
kk_scene_update_scene_enable
(
int
enable
,
const
char
*
sceneId
);
...
...
@@ -106,4 +116,6 @@ int kk_scene_update_productType(const char *sceneId,char *productType);
int
kk_scene_update_actionRoomId
(
const
char
*
sceneId
,
char
*
roomId
);
int
kk_scene_update_device_active
(
char
*
deviceCode
,
int
epNum
,
int
value
);
int
kk_scene_rebuild_device_active
(
char
*
deviceCode
,
int
epNum
);
int
kk_scene_delete_scene_protype
(
const
char
*
sceneId
);
int
kk_scene_insert_sceneProType_info
(
const
char
*
roomId
,
char
*
propertyName
,
char
*
propertyValue
,
const
char
*
sceneId
,
char
*
productType
,
int
delay
);
#endif
midware/midware/scene/kk_scene_handle.c
View file @
74c4facd
...
...
@@ -449,6 +449,7 @@ int kk_scene_action_add(const char *gwdeviceCode,const char *sceneId,kk_scene_ac
kk_scene_delete_scene_info
(
sceneId
);
kk_scene_delete_scene_trigger
(
sceneId
);
kk_scene_delete_scene_condition
(
sceneId
);
kk_scene_delete_scene_protype
(
sceneId
);
kk_scene_delete_scene_action
(
sceneId
,
isforword
);
kk_scene_delete_scene_invokeservice
(
sceneId
);
}
...
...
@@ -1412,7 +1413,7 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
char
*
propertyNameStr
=
cJSON_PrintUnformatted
(
temp
);
res
=
kk_scene_insert_scene_action
(
typeStr
,
""
,
0
,
propertyNameStr
,
propertyValueStr
,
delay
->
valueint
,
sceneId
,
""
);
propertyNameStr
,
propertyValueStr
,
delay
->
valueint
,
sceneId
,
""
,
1
);
free
(
propertyNameStr
);
}
else
...
...
@@ -1429,15 +1430,23 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
roomId
=
cJSON_GetObjectItem
(
item
,
MSG_AREA_ROOM_ROOMID
);
}
delay
=
cJSON_GetObjectItem
(
item
,
MSG_SCENE_DELAY
);
kk_scene_update_productType
((
char
*
)
sceneId
,
productType
->
valuestring
);
kk_scene_update_actionRoomId
((
char
*
)
sceneId
,
roomId
->
valuestring
);
if
(
delay
==
NULL
)
return
FAIL_RETURN
;
int
idelay
=
delay
->
valueint
;
kk_scene_update_productType
(
sceneId
,
productType
->
valuestring
);
if
(
propertyValue
->
type
==
cJSON_String
){
kk_scene_insert_sceneProType_info
((
char
*
)
roomId
->
valuestring
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,(
char
*
)
sceneId
,
productType
->
valuestring
,
idelay
);
kk_subDev_set_action_by_productType
(
productType
->
valuestring
,
roomId
->
valuestring
,
sceneId
,
propertyName
->
valuestring
,
propertyValue
->
valuestring
,
typeStr
,
idelay
);
}
else
{
}
else
if
(
propertyValue
->
type
==
cJSON_Number
){
char
buf2char
[
16
]
=
{
0
};
sprintf
(
buf2char
,
"%d"
,
propertyValue
->
valueint
);
kk_scene_insert_sceneProType_info
((
char
*
)
roomId
->
valuestring
,
propertyName
->
valuestring
,
buf2char
,(
char
*
)
sceneId
,
productType
->
valuestring
,
idelay
);
kk_subDev_set_action_by_productType
(
productType
->
valuestring
,
roomId
->
valuestring
,
sceneId
,
propertyName
->
valuestring
,
buf2char
,
typeStr
,
idelay
);
}
else
if
(
propertyValue
->
type
==
cJSON_Object
){
char
*
str
=
cJSON_PrintUnformatted
(
propertyValue
);
kk_scene_insert_sceneProType_info
((
char
*
)
roomId
->
valuestring
,
propertyName
->
valuestring
,
str
,(
char
*
)
sceneId
,
productType
->
valuestring
,
idelay
);
kk_subDev_set_action_by_productType
(
productType
->
valuestring
,
roomId
->
valuestring
,
sceneId
,
propertyName
->
valuestring
,
str
,
typeStr
,
idelay
);
free
(
str
);
...
...
@@ -1510,11 +1519,11 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
}
//printf("---------------------------------DEBUG CWC[%s][%d]\n",__FUNCTION__,__LINE__);
res
=
kk_scene_insert_scene_action
(
typeStr
,
node
->
deviceCode
,
iepnum
,
info
.
propertyName
,
propertyValueStr
,
idelay
,
sceneId
,
node
->
fatherDeviceCode
);
info
.
propertyName
,
propertyValueStr
,
idelay
,
sceneId
,
node
->
fatherDeviceCode
,
1
);
}
else
{
res
=
kk_scene_insert_scene_action
(
typeStr
,
node
->
deviceCode
,
iepnum
,
propertyName
->
valuestring
,
propertyValueStr
,
idelay
,
sceneId
,
node
->
fatherDeviceCode
);
propertyName
->
valuestring
,
propertyValueStr
,
idelay
,
sceneId
,
node
->
fatherDeviceCode
,
1
);
}
if
(
res
!=
SUCCESS_RETURN
){
...
...
@@ -1576,7 +1585,7 @@ int kk_scene_parse_scene_muticontrol(const cJSON* str,const char *sceneId,int is
cJSON_AddItemToArray
(
array
,
arrayParam
);
//break;
kk_scene_insert_scene_action
(
type
->
valuestring
,
deviceCode
->
valuestring
,
atoi
(
epNum
->
valuestring
),
""
,
""
,
0
,
sceneId
,
node
->
fatherDeviceCode
);
""
,
""
,
0
,
sceneId
,
node
->
fatherDeviceCode
,
1
);
}
item
=
item
->
next
;
...
...
@@ -1905,6 +1914,7 @@ int kk_scene_check_trigger_condition(const char *sceneId)
char
*
compareValue
=
NULL
;
int
conditionFlag
=
0
;
int
sceneType
=
0
,
isEnable
=
0
;
int
active
=
0
;
sqlite3_stmt
*
stmt
;
char
currentValue
[
64
]
=
{
0
};
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
...
...
@@ -1917,11 +1927,15 @@ int kk_scene_check_trigger_condition(const char *sceneId)
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
conditionFlag
=
1
;
pdeviceCode
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_DEVICECODE
);
identifier
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_PROPERTYNAME
);
compareType
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPARETYPE
);
compareValue
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_COMPAREVALUE
);
active
=
sqlite3_column_int
(
stmt
,
DB_SCENETRIGGER_ACTIVE
);
if
(
active
==
0
){
//限制条件的设备被移除的情况下,相当于没有此条限制条件
res
=
SUCCESS_RETURN
;
continue
;
}
kk_property_db_get_value_directly
(
pdeviceCode
,
identifier
,
currentValue
);
INFO_PRINT
(
"currentValue:%s
\n
"
,
currentValue
);
...
...
@@ -2507,7 +2521,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlite3_stmt
*
stmt
;
kk_scene_ctx_t
*
ctx
=
_kk_scene_get_ctx
();
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE deviceCode= '%s'
"
,
deviceCode
);
sqlCmd
=
sqlite3_mprintf
(
"select * from SceneTriggerInfo WHERE deviceCode= '%s'
and active = '%d'"
,
deviceCode
,
1
);
//actice判断设备是否移入待分配
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
sceneId
=
(
char
*
)
sqlite3_column_text
(
stmt
,
DB_SCENETRIGGER_SCENEID
);
...
...
@@ -2773,4 +2787,3 @@ int kk_scene_rebuild_device_active(char *deviceCode,int epNum)
sqlite3_finalize
(
stmt
);
return
SUCCESS_RETURN
;
}
\ No newline at end of file
nx5_soc_gw/smarthome_z3gw_a133
View file @
74c4facd
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