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
72f8954b
Commit
72f8954b
authored
Sep 22, 2020
by
陈伟灿
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cwc' into 'master'
【修改内容】增加批量删除和批量添加的功能接口和相关逻辑处理,以备后用 See merge request chenweican/k-sdk!22
parents
35084464
be4b4048
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
353 additions
and
8 deletions
+353
-8
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+33
-3
application/kcloud/mqtt_api.c
application/kcloud/mqtt_api.c
+1
-1
common/api/com_api.h
common/api/com_api.h
+3
-0
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+3
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+30
-0
midware/midware/midware.c
midware/midware/midware.c
+23
-0
platform/zigbee/app/builder/Z3GatewayHost/Makefile
platform/zigbee/app/builder/Z3GatewayHost/Makefile
+1
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.c
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.c
+10
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.h
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.h
+6
-2
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_topo_batch_handle.c
...igbee/app/builder/Z3GatewayHost/ZB/kk_topo_batch_handle.c
+242
-0
platform/zigbee/protocol/zigbee/app/framework/util/af-main-host.c
.../zigbee/protocol/zigbee/app/framework/util/af-main-host.c
+1
-1
No files found.
application/kcloud/kcloud_data_handle.c
View file @
72f8954b
...
@@ -21,8 +21,13 @@
...
@@ -21,8 +21,13 @@
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
#define KK_FILTER_STATUS_ONLINE "/thing/status/online"
#define KK_FILTER_STATUS_ONLINE "/thing/status/online"
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_FILTER_STATUS_OFFLINE "/thing/status/offline"
#define KK_FILTER_STATUS_OFFLINE "/thing/status/offline"
#define KK_FILTER_STATUS_OFFLINE_REPLY "/thing/status/offline_reply"
#define KK_FILTER_STATUS_OFFLINE_REPLY "/thing/status/offline_reply"
#define KK_FILTER_TOPO_BATCH_ADD "/thing/topo/batch_add"
#define KK_FILTER_TOPO_BATCH_ADD_REPLY "/thing/topo/batch_add_reply"
#define KK_FILTER_TOPO_BATCH_DELETE "/thing/topo/batch_delete"
#define KK_FILTER_TOPO_BATCH_DELETE_REPLY "/thing/topo/batch_delete_reply"
#define KK_FILTER_TOPO_CHANEG_REPLY "/thing/topo/change_reply"
#define KK_FILTER_TOPO_CHANEG_REPLY "/thing/topo/change_reply"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
...
@@ -122,7 +127,6 @@ int _kk_sendto_cloud(cJSON *root)
...
@@ -122,7 +127,6 @@ int _kk_sendto_cloud(cJSON *root)
{
{
cJSON
*
info
,
*
pData
;
cJSON
*
info
,
*
pData
;
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
cJSON
*
msgTypeStr
=
NULL
;
cJSON
*
msgTypeStr
=
NULL
;
info
=
cJSON_GetObjectItem
(
root
,
MSG_INFO_STR
);
info
=
cJSON_GetObjectItem
(
root
,
MSG_INFO_STR
);
if
(
info
==
NULL
){
if
(
info
==
NULL
){
...
@@ -148,6 +152,24 @@ int _kk_sendto_cloud(cJSON *root)
...
@@ -148,6 +152,24 @@ int _kk_sendto_cloud(cJSON *root)
return
RETURN_SUCCESS
;
return
RETURN_SUCCESS
;
}
}
else
if
(
strstr
(
msgTypeStr
->
valuestring
,
KK_FILTER_TOPO_BATCH_DELETE
)
!=
NULL
){
cJSON
*
params
=
NULL
;
params
=
cJSON_GetObjectItem
(
pData
,
MSG_PARAMS_STR
);
if
(
params
!=
NULL
){
cJSON
*
devices
=
cJSON_GetObjectItem
(
params
,
MSG_TOPO_CHANGE_DEVICES_STR
);
if
(
devices
!=
NULL
){
cJSON
*
item
=
devices
->
child
;
while
(
item
!=
NULL
){
char
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
char
*
productCode
=
cJSON_GetObjectItem
(
item
,
MSG_PRODUCT_CODE_STR
)
->
valuestring
;
KK_Subdev_UnSubscribe_By_DeviceCode
(
deviceCode
,
productCode
);
item
=
item
->
next
;
}
}
}
free
(
topic
);
return
RETURN_SUCCESS
;
}
else
if
(
strstr
(
msgTypeStr
->
valuestring
,
KK_CLOUDSTATE_MSG
)
!=
NULL
){
else
if
(
strstr
(
msgTypeStr
->
valuestring
,
KK_CLOUDSTATE_MSG
)
!=
NULL
){
KK_Send_CloudState
(
kk_get_cloud_status
());
KK_Send_CloudState
(
kk_get_cloud_status
());
free
(
topic
);
free
(
topic
);
...
@@ -224,6 +246,14 @@ static int _check_invalid_topic(const char* topic)
...
@@ -224,6 +246,14 @@ static int _check_invalid_topic(const char* topic)
strstr
(
topic
,
KK_FILTER_STATUS_OFFLINE_REPLY
)
==
NULL
){
strstr
(
topic
,
KK_FILTER_STATUS_OFFLINE_REPLY
)
==
NULL
){
return
1
;
return
1
;
}
}
else
if
(
strstr
(
topic
,
KK_FILTER_TOPO_BATCH_ADD
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_TOPO_BATCH_ADD_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_TOPO_BATCH_DELETE
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_TOPO_BATCH_DELETE_REPLY
)
==
NULL
){
return
1
;
}
return
0
;
return
0
;
}
}
...
...
application/kcloud/mqtt_api.c
View file @
72f8954b
...
@@ -152,7 +152,7 @@ static void onOptSuccess(void* context, MQTTAsync_successData* response)
...
@@ -152,7 +152,7 @@ static void onOptSuccess(void* context, MQTTAsync_successData* response)
}
}
else
if
(
strcmp
((
char
*
)
context
,
OPT_SUB
)
==
0
)
else
if
(
strcmp
((
char
*
)
context
,
OPT_SUB
)
==
0
)
{
{
INFO_PRINT
(
"MQTTAsync_subscribe success,return token:%d
\n
"
,
response
->
token
);
//
INFO_PRINT("MQTTAsync_subscribe success,return token:%d \n",response->token);
}
}
else
if
(
strcmp
((
char
*
)
context
,
OPT_UNSUB
)
==
0
)
else
if
(
strcmp
((
char
*
)
context
,
OPT_UNSUB
)
==
0
)
{
{
...
...
common/api/com_api.h
View file @
72f8954b
...
@@ -39,6 +39,9 @@ typedef enum {
...
@@ -39,6 +39,9 @@ typedef enum {
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
#define MSG_DEVICE_MAC "mac"
#define MSG_DEVICE_PARENTCODE "parentCode"
typedef
void
ipc_cb
(
void
*
data
,
int
len
,
char
*
chalMark
);
typedef
void
ipc_cb
(
void
*
data
,
int
len
,
char
*
chalMark
);
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
,
char
*
chalMark
,
char
*
ip
);
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
,
char
*
chalMark
,
char
*
ip
);
...
...
midware/midware/dm/kk_dm_msg.h
View file @
72f8954b
...
@@ -50,9 +50,11 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
...
@@ -50,9 +50,11 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_TOPO_BATCH_ADD_MSG "/thing/topo/batch_add"
#define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
#define KK_THING_TOPO_CHANGE_MSG "/thing/topo/change"
#define KK_THING_TOPO_BATCH_DELETE_MSG "/thing/topo/batch_delete"
#define KK_THING_TOPO_CHANGE_MSG "/thing/topo/change"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
...
...
midware/midware/dm/kk_linkkit.c
View file @
72f8954b
...
@@ -1764,4 +1764,34 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d
...
@@ -1764,4 +1764,34 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
kk_mid_subdev_batch_add
(
char
productCode
[
PRODUCT_CODE_MAXLEN
],
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
mac
[
DEVICE_MAC_MAXLEN
],
char
fatherDeviceCode
[
DEVICE_CODE_MAXLEN
]){
int
res
=
0
;
int
devid
=
0
;
res
=
dm_mgr_subdev_create
(
KK_DM_DEVICE_SUBDEV
,
productCode
,
deviceCode
,
mac
,
fatherDeviceCode
,
0
,
&
devid
);
if
(
res
!=
SUCCESS_RETURN
&&
TSL_ALREADY_EXIST
!=
res
)
{
ERROR_PRINT
(
"subdev create Failed
\n
"
);
return
FAIL_RETURN
;
}
INFO_PRINT
(
"subdev open susseed, devid = %d
\n
"
,
devid
);
if
(
TSL_ALREADY_EXIST
==
res
){
//todo
}
else
{
res
=
kk_subDev_insert_db
(
KK_DM_DEVICE_SUBDEV
,
productCode
,
deviceCode
,
fatherDeviceCode
,
mac
,
"1.1.0"
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
}
res
=
_iotx_linkkit_subdev_login
(
devid
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
_iotx_linkkit_mutex_unlock
();
return
SUCCESS_RETURN
;
}
midware/midware/midware.c
View file @
72f8954b
...
@@ -220,6 +220,19 @@ void kk_platMsg_handle(void* data, char* chalMark){
...
@@ -220,6 +220,19 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_mid_subdev_add
(
KK_DM_DEVICE_SUBDEV
,
proCode
->
valuestring
,
devCode
->
valuestring
,
mac
->
valuestring
,
info_dcode
->
valuestring
);
kk_mid_subdev_add
(
KK_DM_DEVICE_SUBDEV
,
proCode
->
valuestring
,
devCode
->
valuestring
,
mac
->
valuestring
,
info_dcode
->
valuestring
);
}
}
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_TOPO_BATCH_ADD_MSG
)
!=
NULL
){
kk_ipc_send
(
IPC_MID2APP
,
data
,
strlen
(
data
));
cJSON
*
devices
=
cJSON_GetObjectItem
(
jsonPay
,
MSG_TOPO_CHANGE_DEVICES_STR
);
cJSON
*
item
=
devices
->
child
;
while
(
item
!=
NULL
){
char
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
char
*
productCode
=
cJSON_GetObjectItem
(
item
,
MSG_PRODUCT_CODE_STR
)
->
valuestring
;
char
*
mac_s
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_MAC
)
->
valuestring
;
char
*
fatherMac
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_PARENTCODE
)
->
valuestring
;
kk_mid_subdev_batch_add
(
productCode
,
deviceCode
,
mac_s
,
fatherMac
);
item
=
item
->
next
;
}
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_PROPERTY_POST
)
!=
NULL
){
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_PROPERTY_POST
)
!=
NULL
){
INFO_PRINT
(
"save property and send to cloud
\n
"
);
INFO_PRINT
(
"save property and send to cloud
\n
"
);
char
*
outstr
=
cJSON_Print
(
payload
);
char
*
outstr
=
cJSON_Print
(
payload
);
...
@@ -235,6 +248,16 @@ void kk_platMsg_handle(void* data, char* chalMark){
...
@@ -235,6 +248,16 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_ipc_send
(
IPC_MID2APP
,
data
,
strlen
(
data
)
+
1
);
kk_ipc_send
(
IPC_MID2APP
,
data
,
strlen
(
data
)
+
1
);
dm_mgr_subdev_delete
(
devCode
->
valuestring
);
dm_mgr_subdev_delete
(
devCode
->
valuestring
);
}
else
if
(
strstr
(
msgType
->
valuestring
,
KK_THING_TOPO_BATCH_DELETE_MSG
)
!=
NULL
){
kk_ipc_send
(
IPC_MID2APP
,
data
,
strlen
(
data
));
cJSON
*
devices
=
cJSON_GetObjectItem
(
jsonPay
,
MSG_TOPO_CHANGE_DEVICES_STR
);
cJSON
*
item
=
devices
->
child
;
while
(
item
!=
NULL
){
char
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
dm_mgr_subdev_delete
(
deviceCode
);
item
=
item
->
next
;
}
}
else
{
}
else
{
INFO_PRINT
(
"kk_platMsg_handle data: don't handle it [%s]
\n
"
,
data
);
INFO_PRINT
(
"kk_platMsg_handle data: don't handle it [%s]
\n
"
,
data
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/Makefile
View file @
72f8954b
...
@@ -292,6 +292,7 @@ APPLICATION_FILES= \
...
@@ -292,6 +292,7 @@ APPLICATION_FILES= \
./ZB/kk_rgb_hsl_convert.c
\
./ZB/kk_rgb_hsl_convert.c
\
./ZB/kk_color_space.c
\
./ZB/kk_color_space.c
\
./ZB/sub_device_manage.c
\
./ZB/sub_device_manage.c
\
./ZB/kk_topo_batch_handle.c
\
./kk_test.c
\
./kk_test.c
\
./rpc_api/src/rpc_common.c
\
./rpc_api/src/rpc_common.c
\
./rpc_api/src/rpc_onoff.c
\
./rpc_api/src/rpc_onoff.c
\
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.c
View file @
72f8954b
...
@@ -42,6 +42,16 @@ static void kk_msg_report(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
...
@@ -42,6 +42,16 @@ static void kk_msg_report(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
rpc_cJSON_Delete
(
root
);
rpc_cJSON_Delete
(
root
);
}
}
void
kk_msg_report_batch_joined
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_msg_report
(
data
,
KK_REPORT_DEVICE_BATCH_JOINED_TYPE
,
KK_REPORT_DEVICE_BATCH_JOINED_METHOD
,
mac
);
}
void
kk_msg_report_batch_leave
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_msg_report
(
data
,
KK_REPORT_DEVICE_BATCH_LEFT_TYPE
,
KK_REPORT_DEVICE_BATCH_LEAVE_METHOD
,
mac
);
}
static
void
kk_msg_report_joined
(
cJSON
*
data
,
EmberEUI64
mac
)
static
void
kk_msg_report_joined
(
cJSON
*
data
,
EmberEUI64
mac
)
{
{
kk_msg_report
(
data
,
KK_REPORT_DEVICE_JOINED_TYPE
,
KK_REPORT_DEVICE_JOINED_METHOD
,
mac
);
kk_msg_report
(
data
,
KK_REPORT_DEVICE_JOINED_TYPE
,
KK_REPORT_DEVICE_JOINED_METHOD
,
mac
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_msg_report.h
View file @
72f8954b
...
@@ -10,14 +10,18 @@
...
@@ -10,14 +10,18 @@
#define KK_IPC_VERSION "1.0"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_BATCH_JOINED_METHOD "thing.topo.batchAdd"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_DEVICE_BATCH_LEAVE_METHOD "thing.topo.batchDelete"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define KK_REPORT_DEVICE_BATCH_JOINED_TYPE "/thing/topo/batch_add"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_DEVICE_BATCH_LEFT_TYPE "/thing/topo/batch_delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define GW2CCU_PROTOCOL "tcp"
#define GW2CCU_PROTOCOL "tcp"
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_topo_batch_handle.c
0 → 100644
View file @
72f8954b
#include <stdio.h>
#include "klist.h"
#include "kk_tsl_common.h"
#include ".././jsonrpc/jsonrpc-c.h"
#include ".././jsonrpc/rpccJSON.h"
#include "kk_zb_com.h"
typedef
struct
{
char
productCode
[
PRODUCT_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
char
mac
[
DEVICE_MAC_MAXLEN
];
struct
list_head
linked_list
;
}
kk_topo_dev_node_t
;
typedef
struct
{
void
*
mutex
;
void
*
semaphore
;
int
num
;
void
*
g_batch_handle_thread
;
struct
list_head
dev_add_list
;
struct
list_head
dev_del_list
;
}
kk_topo_batch_handle_ctx
;
static
kk_topo_batch_handle_ctx
g_kk_topo_batch_handle
=
{
0
};
static
kk_topo_batch_handle_ctx
*
_kk_topo_batch_handle_ctx
(
void
)
{
return
&
g_kk_topo_batch_handle
;
}
static
void
_kk_topo_batch_handle_mutex_lock
(
void
)
{
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
if
(
ctx
->
mutex
)
{
HAL_MutexLock
(
ctx
->
mutex
);
}
}
static
void
_kk_topo_batch_handle_mutex_unlock
(
void
)
{
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
if
(
ctx
->
mutex
)
{
HAL_MutexUnlock
(
ctx
->
mutex
);
}
}
void
kk_topo_batch_handle_semaphone_post
(
void
)
{
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
if
(
ctx
->
semaphore
){
HAL_SemaphorePost
(
ctx
->
semaphore
);
}
}
#define PLATFORM_WAIT_INFINITE (~0)
int
kk_topo_batch_handle_semaphone_wait
(
void
)
{
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
if
(
ctx
->
semaphore
){
HAL_SemaphoreWait
(
ctx
->
semaphore
,
PLATFORM_WAIT_INFINITE
);
}
return
0
;
}
void
*
kk_topo_batch_handle
(
void
*
args
)
{
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
cJSON
*
root_add
=
NULL
;
cJSON
*
root_del
=
NULL
;
cJSON
*
array_add
=
NULL
;
cJSON
*
device
=
NULL
;
cJSON
*
array_del
=
NULL
;
kk_topo_dev_node_t
*
node
=
NULL
;
EmberEUI64
gwEui64
=
{
0
};
char
gw_macString
[
17
]
=
{
0
};
emberAfGetEui64
(
gwEui64
);
rpc_eui64ToString
(
gwEui64
,
gw_macString
);
while
(
1
)
{
if
(
!
kk_topo_batch_handle_semaphone_wait
()){
array_add
=
rpc_cJSON_CreateArray
();
if
(
array_add
==
NULL
){
continue
;
}
root_add
=
rpc_cJSON_CreateObject
();
if
(
root_add
==
NULL
){
continue
;
}
array_del
=
rpc_cJSON_CreateArray
();
if
(
array_del
==
NULL
){
continue
;
}
root_del
=
rpc_cJSON_CreateObject
();
if
(
root_del
==
NULL
){
continue
;
}
if
(
!
list_empty
(
&
ctx
->
dev_add_list
)){
while
(
!
list_empty
(
&
ctx
->
dev_add_list
)){
device
=
rpc_cJSON_CreateObject
();
_kk_topo_batch_handle_mutex_lock
();
node
=
list_first_entry
(
&
ctx
->
dev_add_list
,
kk_topo_dev_node_t
,
linked_list
);
if
(
node
!=
NULL
){
rpc_cJSON_AddStringToObject
(
device
,
"productCode"
,
node
->
productCode
);
rpc_cJSON_AddStringToObject
(
device
,
"deviceCode"
,
node
->
deviceCode
);
rpc_cJSON_AddStringToObject
(
device
,
"mac"
,
node
->
mac
);
rpc_cJSON_AddStringToObject
(
device
,
"parentCode"
,
gw_macString
);
rpc_cJSON_AddItemToArray
(
array_add
,
device
);
list_del
(
&
node
->
linked_list
);
free
(
node
);
node
=
NULL
;
}
_kk_topo_batch_handle_mutex_unlock
();
}
rpc_cJSON_AddItemToObject
(
root_add
,
"devices"
,
array_add
);
kk_msg_report_batch_joined
(
root_add
,
gwEui64
);
}
if
(
!
list_empty
(
&
ctx
->
dev_del_list
)){
while
(
!
list_empty
(
&
ctx
->
dev_del_list
)){
device
=
rpc_cJSON_CreateObject
();
_kk_topo_batch_handle_mutex_lock
();
node
=
list_first_entry
(
&
ctx
->
dev_del_list
,
kk_topo_dev_node_t
,
linked_list
);
if
(
node
!=
NULL
){
rpc_cJSON_AddStringToObject
(
device
,
"productCode"
,
node
->
productCode
);
rpc_cJSON_AddStringToObject
(
device
,
"deviceCode"
,
node
->
deviceCode
);
rpc_cJSON_AddItemToArray
(
array_del
,
device
);
list_del
(
&
node
->
linked_list
);
free
(
node
);
node
=
NULL
;
}
_kk_topo_batch_handle_mutex_unlock
();
}
rpc_cJSON_AddItemToObject
(
root_del
,
"devices"
,
array_del
);
kk_msg_report_batch_leave
(
root_del
,
gwEui64
);
}
}
}
return
NULL
;
}
int
kk_topo_batch_handle_init
(
void
)
{
int
res
=
0
;
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
ctx
->
mutex
=
HAL_MutexCreate
();
if
(
ctx
->
mutex
==
NULL
)
{
return
FAIL_RETURN
;
}
INIT_LIST_HEAD
(
&
ctx
->
dev_add_list
);
INIT_LIST_HEAD
(
&
ctx
->
dev_del_list
);
ctx
->
semaphore
=
HAL_SemaphoreCreate
();
if
(
ctx
->
semaphore
==
NULL
)
{
return
FAIL_RETURN
;
}
res
=
pthread_create
(
&
ctx
->
g_batch_handle_thread
,
NULL
,
kk_topo_batch_handle
,
NULL
);
if
(
res
<
0
)
{
printf
(
"HAL_ThreadCreate kk_topo_batch_handle Failed
\n
"
);
//IOT_Linkkit_Close(mid_ctx->master_devid);
return
-
1
;
}
return
SUCCESS_RETURN
;
}
static
int
_kk_topo_batch_check_exist
(
const
char
*
deviceCode
)
{
kk_topo_dev_node_t
*
search_node
=
NULL
;
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
if
(
deviceCode
==
NULL
){
return
INVALID_PARAMETER
;
}
list_for_each_entry
(
search_node
,
&
ctx
->
dev_add_list
,
linked_list
,
kk_topo_dev_node_t
)
{
if
(
(
strlen
(
search_node
->
deviceCode
)
==
strlen
(
deviceCode
))
&&
(
memcmp
(
search_node
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
))
==
0
))
{
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
return
SUCCESS_RETURN
;
}
}
return
FAIL_RETURN
;
}
int
_kk_topo_batch_handle_add_dev
(
const
char
*
productCode
,
const
char
*
deviceCode
,
const
char
*
macString
)
{
kk_topo_dev_node_t
*
node
=
NULL
;
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
int
res
=
0
;
if
(
productCode
==
NULL
||
deviceCode
==
NULL
||
macString
==
NULL
)
{
return
INVALID_PARAMETER
;
}
//rpc_eui64ToString(device_mac,macString);
if
(
_kk_topo_batch_check_exist
(
deviceCode
)
==
SUCCESS_RETURN
){
return
SUCCESS_RETURN
;
}
node
=
malloc
(
sizeof
(
kk_topo_dev_node_t
));
if
(
node
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
_kk_topo_batch_handle_mutex_lock
();
memset
(
node
,
0
,
sizeof
(
kk_topo_dev_node_t
)
);
memcpy
(
node
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
memcpy
(
node
->
productCode
,
productCode
,
strlen
(
productCode
));
memcpy
(
node
->
mac
,
macString
,
strlen
(
macString
));
INIT_LIST_HEAD
(
&
node
->
linked_list
);
list_add_tail
(
&
node
->
linked_list
,
&
ctx
->
dev_add_list
);
_kk_topo_batch_handle_mutex_unlock
();
return
SUCCESS_RETURN
;
}
int
_kk_topo_batch_handle_del_dev
(
const
char
*
productCode
,
const
char
*
deviceCode
)
{
kk_topo_dev_node_t
*
node
=
NULL
;
kk_topo_batch_handle_ctx
*
ctx
=
_kk_topo_batch_handle_ctx
();
int
res
=
0
;
if
(
productCode
==
NULL
||
deviceCode
==
NULL
)
{
return
INVALID_PARAMETER
;
}
node
=
malloc
(
sizeof
(
kk_topo_dev_node_t
));
if
(
node
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
_kk_topo_batch_handle_mutex_lock
();
memset
(
node
,
0
,
sizeof
(
kk_topo_dev_node_t
)
);
memcpy
(
node
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
memcpy
(
node
->
productCode
,
productCode
,
strlen
(
productCode
));
INIT_LIST_HEAD
(
&
node
->
linked_list
);
list_add_tail
(
&
node
->
linked_list
,
&
ctx
->
dev_del_list
);
_kk_topo_batch_handle_mutex_unlock
();
return
SUCCESS_RETURN
;
}
platform/zigbee/protocol/zigbee/app/framework/util/af-main-host.c
View file @
72f8954b
...
@@ -544,7 +544,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
...
@@ -544,7 +544,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
emberAfPrintBigEndianEui64
(
eui64
);
emberAfPrintBigEndianEui64
(
eui64
);
kk_network_check
();
kk_network_check
();
kk_topo_batch_handle_init
();
kk_device_gateway_add
(
eui64
);
kk_device_gateway_add
(
eui64
);
pthread_t
tid
;
pthread_t
tid
;
...
...
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