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
490a67cf
Commit
490a67cf
authored
Sep 11, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】添加APP端主动删除子设备的消息处理
【提交人】陈伟灿
parent
4edd1128
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
861 additions
and
760 deletions
+861
-760
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+34
-2
application/kcloud/kcloud_main.c
application/kcloud/kcloud_main.c
+74
-76
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+217
-209
common/api/com_api.h
common/api/com_api.h
+52
-50
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+60
-59
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+31
-1
midware/midware/midware.c
midware/midware/midware.c
+0
-9
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
+277
-244
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
+36
-34
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
+80
-76
platform/zigbee/app/builder/Z3GatewayHost/libapi_com.so
platform/zigbee/app/builder/Z3GatewayHost/libapi_com.so
+0
-0
No files found.
application/kcloud/kcloud_data_handle.c
View file @
490a67cf
...
@@ -22,9 +22,11 @@
...
@@ -22,9 +22,11 @@
#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_CHANEG_REPLY "/thing/topo/change_reply"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_CLOUDSTATE_MSG_REPLY "/thing/ccu/cloudstate_reply"
#define KK_CLOUDSTATE_MSG_REPLY "/thing/ccu/cloudstate_reply"
#define KK_TOPO_CHANGE_MSG_STR "/thing/topo/change"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
#define KK_TOPIC_SERVICE_DELIMITER '/'
#define KK_TOPIC_SERVICE_DELIMITER '/'
...
@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic)
...
@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic)
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
return
1
;
return
1
;
}
}
else
if
(
strstr
(
topic
,
KK_FILTER_TOPO_CHANEG_REPLY
)
!=
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
return
1
;
...
@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
...
@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
return
RETURN_SUCCESS
;
return
RETURN_SUCCESS
;
}
}
static
int
_kk_topo_change_handle
(
cJSON
*
payload
)
{
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
if
(
paramStr
==
NULL
){
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
RETURN_FAIL
;
}
cJSON
*
state
=
cJSON_GetObjectItem
(
paramStr
,
MSG_TOPO_CHANGE_TYPE_STR
);
if
(
state
!=
NULL
&&
state
->
valueint
==
1
){
cJSON
*
deviceArray
=
cJSON_GetObjectItem
(
paramStr
,
MSG_TOPO_CHANGE_DEVICES_STR
);
if
(
deviceArray
==
NULL
){
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
RETURN_FAIL
;
}
cJSON
*
item
=
deviceArray
->
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
;
}
}
return
RETURN_SUCCESS
;
}
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
{
{
cJSON
*
root
;
cJSON
*
root
;
...
@@ -301,17 +330,20 @@ static char * _kk_data_create(const char *topic,const char *data)
...
@@ -301,17 +330,20 @@ static char * _kk_data_create(const char *topic,const char *data)
cJSON
*
infoObj
=
cJSON_Parse
(
infoStr
);
cJSON
*
infoObj
=
cJSON_Parse
(
infoStr
);
cJSON
*
payloadObj
=
cJSON_Parse
(
data
);
cJSON
*
payloadObj
=
cJSON_Parse
(
data
);
cJSON_AddItemToObject
(
root
,
MSG_INFO_STR
,
infoObj
);
cJSON_AddItemToObject
(
root
,
MSG_INFO_STR
,
infoObj
);
cJSON_AddItemToObject
(
root
,
MSG_PAYLOAD_STR
,
payloadObj
);
cJSON_AddItemToObject
(
root
,
MSG_PAYLOAD_STR
,
payloadObj
);
if
(
strstr
(
topic
,
KK_TOPO_CHANGE_MSG_STR
)){
_kk_topo_change_handle
(
payloadObj
);
}
out
=
cJSON_Print
(
root
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
cJSON_Delete
(
root
);
free
(
msgStr
);
free
(
msgStr
);
free
(
infoStr
);
free
(
infoStr
);
INFO_PRINT
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
INFO_PRINT
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
}
const
char
DM_MSG_CLOUDSTATE
[]
=
"{
\"
msgId
\"
:
\"
1
\"
,
\"
version
\"
:
\"
1.0
\"
,
\"
params
\"
:{
\"
IOTCloudState
\"
:
\"
%d
\"
},
\"
method
\"
:
\"
thing.ccu.cloudstate_reply
\"
}"
;
const
char
DM_MSG_CLOUDSTATE
[]
=
"{
\"
msgId
\"
:
\"
1
\"
,
\"
version
\"
:
\"
1.0
\"
,
\"
params
\"
:{
\"
IOTCloudState
\"
:
\"
%d
\"
},
\"
method
\"
:
\"
thing.ccu.cloudstate_reply
\"
}"
;
int
KK_Send_CloudState
(
int
state
)
int
KK_Send_CloudState
(
int
state
)
{
{
char
*
infoStr
=
NULL
;
char
*
infoStr
=
NULL
;
...
...
application/kcloud/kcloud_main.c
View file @
490a67cf
/*******************************************************************************
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
* Copyright (c) 2012, 2020 IBM Corp.
*
*
* All rights reserved. This program and the accompanying materials
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
*
* The Eclipse Public License is available at
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
* Contributors:
* Ian Craggs - initial contribution
* Ian Craggs - initial contribution
*******************************************************************************/
*******************************************************************************/
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <pthread.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "com_api.h"
#include "kk_product.h"
#include "kk_product.h"
static
int
mqtt_start
(
void
)
static
int
mqtt_start
(
void
)
{
{
int
count
=
0
;
int
count
=
0
;
MQTTAsync
mqttClient
;
MQTTAsync
mqttClient
;
int
rc
=
0
;
int
rc
=
0
;
mqttClient
=
KK_MQTT_Connect
();
mqttClient
=
KK_MQTT_Connect
();
if
(
mqttClient
==
NULL
)
if
(
mqttClient
==
NULL
)
{
{
WARNING_PRINT
(
"KK_MQTT_Connect FAIL!!!
\n
"
);
WARNING_PRINT
(
"KK_MQTT_Connect FAIL!!!
\n
"
);
}
}
else
else
{
{
INFO_PRINT
(
"Waiting for publication of %s
\n
"
INFO_PRINT
(
"Waiting for publication of %s
\n
"
"on topic %s for client with ClientID: %s
\n
"
,
"on topic %s for client with ClientID: %s
\n
"
,
PAYLOAD
,
TOPIC
,
CLIENTID
);
PAYLOAD
,
TOPIC
,
CLIENTID
);
}
}
while
(
1
)
while
(
1
)
{
{
usleep
(
100000L
);
usleep
(
100000L
);
count
++
;
count
++
;
if
(
count
>
50
)
if
(
count
>
50
)
{
{
count
=
0
;
count
=
0
;
//INFO_PRINT("i am send now\n");
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
}
}
}
INFO_PRINT
(
"MQTTAsync_destroy
\n
"
);
INFO_PRINT
(
"MQTTAsync_destroy
\n
"
);
MQTTAsync_destroy
(
&
mqttClient
);
MQTTAsync_destroy
(
&
mqttClient
);
return
rc
;
return
rc
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
rc
=
0
;
int
rc
=
0
;
//KK_Data_Hdl_Init();
//KK_Data_Hdl_Init();
kk_zlog_init
(
"kcloud"
);
kk_zlog_init
(
"kcloud"
);
/*set the callback to get the device date to cloud*/
/*set the callback to get the device date to cloud*/
HAL_SetProduct_Type
(
PRODUCT_TPYE
);
kk_ipc_init
(
IPC_APP2MID
,
KK_Data_FromDev
,
NULL
,
NULL
);
HAL_SetProduct_Code
(
PRODUCT_CODE
);
rc
=
mqtt_start
();
kk_ipc_init
(
IPC_APP2MID
,
KK_Data_FromDev
,
NULL
,
NULL
);
rc
=
mqtt_start
();
return
rc
;
}
return
rc
;
}
application/kcloud/kk_topic_mng.c
View file @
490a67cf
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "kk_product.h"
#include "kk_product.h"
#include "cJSON.h"
#include "cJSON.h"
#include "com_api.h"
#include "com_api.h"
#include "kk_log.h"
#include "kk_log.h"
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/kk/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/kk/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/kk/%s/%s"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/kk/%s/%s"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/kk/%s/%s/#"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/kk/%s/%s/#"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
int
KK_Subdev_Subscribe
(
const
cJSON
*
root
)
int
KK_Subdev_Subscribe
(
const
cJSON
*
root
)
{
{
int
res
=
0
;
int
res
=
0
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
productCode
=
NULL
;
cJSON
*
productCode
=
NULL
;
cJSON
*
data
=
NULL
;
cJSON
*
data
=
NULL
;
cJSON
*
cmd
=
NULL
;
cJSON
*
cmd
=
NULL
;
int
url_len
=
0
;
int
url_len
=
0
;
data
=
cJSON_GetObjectItem
(
root
,
"data"
);
data
=
cJSON_GetObjectItem
(
root
,
"data"
);
if
(
data
==
NULL
){
if
(
data
==
NULL
){
return
-
1
;
return
-
1
;
}
}
deviceCode
=
cJSON_GetObjectItem
(
data
,
MSG_DEVICE_CODE_STR
);
deviceCode
=
cJSON_GetObjectItem
(
data
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
if
(
deviceCode
==
NULL
){
return
-
1
;
return
-
1
;
}
}
productCode
=
cJSON_GetObjectItem
(
data
,
MSG_PRODUCT_CODE_STR
);
productCode
=
cJSON_GetObjectItem
(
data
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
if
(
productCode
==
NULL
){
return
-
1
;
return
-
1
;
}
}
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
char
*
url
=
malloc
(
url_len
);
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
if
(
url
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
memset
(
url
,
0
,
url_len
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
free
(
url
);
return
res
;
return
res
;
}
}
static
int
_kk_client_subscribe
(
char
productCode
[
PRODUCT_CODE_LEN
],
char
deviceCode
[
DEVICE_CODE_LEN
])
static
int
_kk_client_subscribe
(
char
productCode
[
PRODUCT_CODE_LEN
],
char
deviceCode
[
DEVICE_CODE_LEN
])
{
{
int
res
=
0
,
index
=
0
,
fail_count
=
0
;
int
res
=
0
,
index
=
0
,
fail_count
=
0
;
int
url_len
=
0
;
int
url_len
=
0
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
char
*
url
=
malloc
(
url_len
);
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
if
(
url
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
memset
(
url
,
0
,
url_len
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
,
deviceCode
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
free
(
url
);
return
res
;
return
res
;
}
}
int
KK_Client_Gateway_Subscribe
(
void
)
int
KK_Client_Gateway_Subscribe
(
void
)
{
{
char
productCode
[
PRODUCT_CODE_LEN
]
=
{
0
};
char
productCode
[
PRODUCT_CODE_LEN
]
=
{
0
};
char
deviceCode
[
MAC_ADDR_LEN
]
=
{
0
};
char
deviceCode
[
MAC_ADDR_LEN
]
=
{
0
};
HAL_GetProduct_Code
(
productCode
);
HAL_GetProduct_Code
(
productCode
);
HAL_Get_mac
(
deviceCode
);
HAL_Get_mac
(
deviceCode
);
return
_kk_client_subscribe
(
productCode
,
"CCU_66666"
);
return
_kk_client_subscribe
(
productCode
,
"CCU_66666"
);
}
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_code
,
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_code
,
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
{
{
int
service_name_len
=
0
;
int
service_name_len
=
0
;
if
(
name
==
NULL
||
product_code
==
NULL
||
device_code
==
NULL
||
if
(
name
==
NULL
||
product_code
==
NULL
||
device_code
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
return
-
1
;
}
}
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
+
strlen
(
name
)
+
1
;
+
strlen
(
name
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
if
(
*
topic
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
memset
(
*
topic
,
0
,
service_name_len
);
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_code
,
device_code
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_code
,
device_code
);
if
(
name
!=
NULL
)
{
if
(
name
!=
NULL
)
{
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
}
}
return
0
;
return
0
;
}
}
static
int
_kk_utils_topic_ota
(
_IN_
char
*
str
,
_OU_
char
**
topic
)
static
int
_kk_utils_topic_ota
(
_IN_
char
*
str
,
_OU_
char
**
topic
)
{
{
int
service_name_len
=
0
;
int
service_name_len
=
0
;
if
(
str
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
if
(
str
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
return
-
1
;
}
}
service_name_len
=
strlen
(
str
)
+
1
;
service_name_len
=
strlen
(
str
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
if
(
*
topic
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
memset
(
*
topic
,
0
,
service_name_len
);
memset
(
*
topic
,
0
,
service_name_len
);
memcpy
(
*
topic
,
str
,
service_name_len
);
memcpy
(
*
topic
,
str
,
service_name_len
);
return
0
;
return
0
;
}
}
int
KK_Subdev_UnSubscribe
(
cJSON
*
payload
)
{
int
KK_Subdev_UnSubscribe_By_DeviceCode
(
const
char
*
deviceCode
,
const
char
*
productCode
)
cJSON
*
params
,
*
productCode
,
*
deviceCode
;
{
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
int
topic_len
=
0
;
int
topic_len
=
0
;
if
(
payload
==
NULL
){
topic_len
=
strlen
(
KK_URI_SYS_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
goto
errorreturn
;
topic
=
malloc
(
topic_len
);
}
if
(
topic
==
NULL
)
{
params
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
return
-
1
;
if
(
params
==
NULL
){
}
goto
errorreturn
;
memset
(
topic
,
0
,
topic_len
);
}
snprintf
(
topic
,
topic_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
productCode
=
cJSON_GetObjectItem
(
params
,
MSG_PRODUCT_CODE_STR
);
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
if
(
productCode
==
NULL
){
KK_MQTT_UnsubTopic
(
topic
);
goto
errorreturn
;
free
(
topic
);
}
return
0
;
deviceCode
=
cJSON_GetObjectItem
(
params
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
}
goto
errorreturn
;
int
KK_Subdev_UnSubscribe
(
cJSON
*
payload
)
}
{
cJSON
*
params
,
*
productCode
,
*
deviceCode
;
topic_len
=
strlen
(
KK_URI_SYS_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
topic
=
malloc
(
topic_len
);
if
(
payload
==
NULL
){
if
(
topic
==
NULL
)
{
goto
errorreturn
;
goto
errorreturn
;
}
}
params
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
memset
(
topic
,
0
,
topic_len
);
if
(
params
==
NULL
){
snprintf
(
topic
,
topic_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
goto
errorreturn
;
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
}
KK_MQTT_UnsubTopic
(
topic
);
productCode
=
cJSON_GetObjectItem
(
params
,
MSG_PRODUCT_CODE_STR
);
free
(
topic
);
if
(
productCode
==
NULL
){
return
0
;
goto
errorreturn
;
errorreturn:
}
return
-
1
;
deviceCode
=
cJSON_GetObjectItem
(
params
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
}
goto
errorreturn
;
char
*
KK_Make_Topic
(
cJSON
*
info
)
}
{
KK_Subdev_UnSubscribe_By_DeviceCode
(
deviceCode
->
valuestring
,
productCode
->
valuestring
);
cJSON
*
type
,
*
product_code
,
*
device_code
;
char
*
topic
=
NULL
;
return
0
;
//root=cJSON_Parse((char*)info->valuestring);
errorreturn:
return
-
1
;
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
if
(
type
==
NULL
){
}
goto
errorreturn
;
char
*
KK_Make_Topic
(
cJSON
*
info
)
}
{
cJSON
*
type
,
*
product_code
,
*
device_code
;
product_code
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_CODE_STR
);
char
*
topic
=
NULL
;
if
(
product_code
==
NULL
){
//root=cJSON_Parse((char*)info->valuestring);
goto
errorreturn
;
}
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
device_code
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
if
(
type
==
NULL
){
if
(
device_code
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)
||
strstr
(
type
->
valuestring
,
"/ota/device/progress"
)){
product_code
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_CODE_STR
);
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
if
(
product_code
==
NULL
){
}
goto
errorreturn
;
else
{
}
_kk_utils_topic
(
type
->
valuestring
,
product_code
->
valuestring
,
device_code
->
valuestring
,
&
topic
);
device_code
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
}
if
(
device_code
==
NULL
){
goto
errorreturn
;
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
}
return
topic
;
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)
||
strstr
(
type
->
valuestring
,
"/ota/device/progress"
)){
errorreturn:
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
return
NULL
;
}
else
{
}
_kk_utils_topic
(
type
->
valuestring
,
product_code
->
valuestring
,
device_code
->
valuestring
,
&
topic
);
}
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
return
topic
;
errorreturn:
return
NULL
;
}
common/api/com_api.h
View file @
490a67cf
/*
/*
* Copyright (C) 2020-2020 ikonke
* Copyright (C) 2020-2020 ikonke
*/
*/
#ifndef _KK_COM_API_H_
#ifndef _KK_COM_API_H_
#define _KK_COM_API_H_
#define _KK_COM_API_H_
#if defined(__cplusplus)
#if defined(__cplusplus)
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include "ev.h"
#include "ev.h"
#include "nn.h"
#include "nn.h"
#include "pair.h"
#include "pair.h"
#include "pubsub.h"
#include "pubsub.h"
#include "pipeline.h"
#include "pipeline.h"
//=====kk======================
//=====kk======================
typedef
enum
{
typedef
enum
{
IPC_APP2MID
=
0
,
IPC_APP2MID
=
0
,
IPC_MID2APP
,
IPC_MID2APP
,
IPC_MID2PLAT
,
IPC_MID2PLAT
,
IPC_PLAT2MID
,
IPC_PLAT2MID
,
IPC_UNDEF
IPC_UNDEF
}
ipc_type
;
}
ipc_type
;
#define MSG_TYPE_STR "msgtype"
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params"
#define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
typedef
void
ipc_cb
(
void
*
data
,
int
len
,
char
*
chalMark
);
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
,
char
*
chalMark
,
char
*
ip
);
int
kk_ipc_deinit
(
ipc_type
type
);
typedef
void
ipc_cb
(
void
*
data
,
int
len
,
char
*
chalMark
);
int
kk_ipc_send
(
ipc_type
type
,
void
*
data
,
int
len
);
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
,
char
*
chalMark
,
char
*
ip
);
int
kk_ipc_send_ex
(
ipc_type
type
,
void
*
data
,
int
len
,
char
*
chalMark
);
int
kk_ipc_deinit
(
ipc_type
type
);
int
kk_ipc_send
(
ipc_type
type
,
void
*
data
,
int
len
);
#if defined(__cplusplus)
int
kk_ipc_send_ex
(
ipc_type
type
,
void
*
data
,
int
len
,
char
*
chalMark
);
}
#endif
#if defined(__cplusplus)
#endif
}
#endif
#endif
midware/midware/dm/kk_dm_msg.h
View file @
490a67cf
#ifndef __KK_DM_MSG__
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
#include "../tsl_handle/lite-cjson.h"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
typedef
struct
{
typedef
struct
{
lite_cjson_t
id
;
lite_cjson_t
id
;
lite_cjson_t
code
;
lite_cjson_t
code
;
lite_cjson_t
data
;
lite_cjson_t
data
;
lite_cjson_t
message
;
lite_cjson_t
message
;
}
dm_msg_response_payload_t
;
}
dm_msg_response_payload_t
;
#ifndef DM_READ_ONLY
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
#define DM_READ_ONLY
#endif
#endif
#define DM_MSG_VERSION "1.0"
#define DM_MSG_VERSION "1.0"
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
;
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#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_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"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
#endif
#endif
midware/midware/dm/kk_linkkit.c
View file @
490a67cf
...
@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){
...
@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){
return
s_CloudStatusRecv
;
return
s_CloudStatusRecv
;
}
}
static
int
_iotx_linkkit_delete_handle
(
cJSON
*
payload
)
{
if
(
payload
==
NULL
){
return
FAIL_RETURN
;
}
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
cJSON
*
state
=
cJSON_GetObjectItem
(
paramStr
,
MSG_TOPO_CHANGE_TYPE_STR
);
if
(
state
!=
NULL
&&
state
->
valueint
==
1
){
cJSON
*
deviceArray
=
cJSON_GetObjectItem
(
paramStr
,
MSG_TOPO_CHANGE_DEVICES_STR
);
if
(
deviceArray
==
NULL
){
return
FAIL_RETURN
;
}
cJSON
*
item
=
deviceArray
->
child
;
while
(
item
!=
NULL
){
char
*
deviceCode
=
cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
dm_mgr_subdev_delete
(
deviceCode
);
item
=
item
->
next
;
}
}
return
SUCCESS_RETURN
;
}
static
void
_iotx_linkkit_event_callback
(
iotx_dm_event_types_t
type
,
char
*
data
)
static
void
_iotx_linkkit_event_callback
(
iotx_dm_event_types_t
type
,
char
*
data
)
{
{
INFO_PRINT
(
"_iotx_linkkit_event_callback ================== [%s]
\n
"
,
data
);
INFO_PRINT
(
"_iotx_linkkit_event_callback ================== [%s]
\n
"
,
data
);
...
@@ -331,7 +356,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
...
@@ -331,7 +356,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
INFO_PRINT
(
"ota upgrade...
\n
"
);
INFO_PRINT
(
"ota upgrade...
\n
"
);
kk_dm_ota_send
(
data
,
strlen
(
data
)
+
1
);
kk_dm_ota_send
(
data
,
strlen
(
data
)
+
1
);
}
else
{
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_THING_TOPO_CHANGE_MSG
)){
INFO_PRINT
(
" topo change
\n
"
);
_iotx_linkkit_delete_handle
(
payload
);
}
else
{
INFO_PRINT
(
"Error 222222222222222
\n
"
);
INFO_PRINT
(
"Error 222222222222222
\n
"
);
}
}
...
...
midware/midware/midware.c
View file @
490a67cf
...
@@ -618,14 +618,6 @@ void *ccu_property_monitor(void *args)
...
@@ -618,14 +618,6 @@ void *ccu_property_monitor(void *args)
}
}
static
int
kk_set_product_info
(
void
)
{
HAL_SetProduct_Type
(
PRODUCT_TPYE
);
HAL_SetProduct_Code
(
PRODUCT_CODE
);
return
0
;
}
int
main
(
const
int
argc
,
const
char
**
argv
)
int
main
(
const
int
argc
,
const
char
**
argv
)
{
{
...
@@ -638,7 +630,6 @@ int main(const int argc, const char **argv)
...
@@ -638,7 +630,6 @@ int main(const int argc, const char **argv)
kk_zlog_init
(
"midware"
);
kk_zlog_init
(
"midware"
);
memset
(
mid_ctx
,
0
,
sizeof
(
mid_ctx_t
));
memset
(
mid_ctx
,
0
,
sizeof
(
mid_ctx_t
));
kk_set_product_info
();
kk_tsl_api_init
();
kk_tsl_api_init
();
kk_ipc_init
(
IPC_MID2APP
,
mid_cb
,
NULL
,
NULL
);
kk_ipc_init
(
IPC_MID2APP
,
mid_cb
,
NULL
,
NULL
);
kk_ipc_init
(
IPC_MID2PLAT
,
mid2p_cb
,
NULL
,
"*"
);
kk_ipc_init
(
IPC_MID2PLAT
,
mid2p_cb
,
NULL
,
"*"
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
View file @
490a67cf
#include "kk_tsl_property_set.h"
#include "kk_tsl_property_set.h"
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
//cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
cJSON
*
kk_topo_change_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
{
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
;
int
res
=
0
;
cJSON
*
changeTypeStr
=
NULL
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
UTIL_LOG_INFO
(
"
\n
********************kk_topo_change_operation********************
\n
"
);
int
index
=
0
;
zigbee_property_set
*
func
;
if
(
params
==
NULL
){
int
num
;
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
uint8_t
findFlag
=
0xff
;
goto
error_return
;
cJSON
*
propertyItem
=
NULL
;
}
else
{
EmberEUI64
eui64
;
changeTypeStr
=
rpc_cJSON_GetObjectItem
(
params
,
MSG_TOPO_CHANGE_TYPE_STR
);
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
if
(
changeTypeStr
!=
NULL
&&
changeTypeStr
->
valueint
==
1
){
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
cJSON
*
deviceArray
=
rpc_cJSON_GetObjectItem
(
params
,
MSG_TOPO_CHANGE_DEVICES_STR
);
if
(
deviceArray
==
NULL
){
if
(
params
==
NULL
){
goto
error_return
;
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
}
goto
error_return
;
cJSON
*
item
=
deviceArray
->
child
;
}
else
{
while
(
item
!=
NULL
){
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
char
*
deviceCode
=
rpc_cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
item
=
item
->
next
;
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
}
goto
error_return
;
}
}
num
=
kk_get_tsl_num
();
for
(
index
=
0
;
index
<
num
;
index
++
){
}
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map
[
index
].
Identity
);
return
rpc_cJSON_CreateNumber
(
res
);
if
(
propertyItem
!=
NULL
){
error_return:
findFlag
=
1
;
return
rpc_cJSON_CreateNull
();
break
;
}
}
}
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
if
(
findFlag
==
0xff
){
{
num
=
kk_get_tsl_glb_num
();
sub_dev_node_t
*
node
=
NULL
;
for
(
index
=
0
;
index
<
num
;
index
++
){
int
res
=
0
;
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
rpc_nwk_info_s
info
;
if
(
propertyItem
!=
NULL
){
EmberStatus
status
;
findFlag
=
2
;
int
index
=
0
;
break
;
zigbee_property_set
*
func
;
}
int
num
;
}
uint8_t
findFlag
=
0xff
;
}
cJSON
*
propertyItem
=
NULL
;
EmberEUI64
eui64
;
if
(
findFlag
!=
0xff
)
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
{
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
int
value
=
0
;
if
(
propertyItem
->
type
!=
cJSON_Number
){
if
(
params
==
NULL
){
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
}
else
{
goto
error_return
;
value
=
propertyItem
->
valueint
;
}
else
{
}
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
goto
error_return
;
}
}
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
num
=
kk_get_tsl_num
();
emberAfDebugPrint
(
"mac:"
);
for
(
index
=
0
;
index
<
num
;
index
++
){
emberAfPrintBigEndianEui64
(
eui64
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map
[
index
].
Identity
);
emberAfDebugPrintln
(
",node:0x%04X"
,
nodeId
);
if
(
propertyItem
!=
NULL
){
if
(
findFlag
==
1
)
findFlag
=
1
;
res
=
g_tsl_zigbee_map
[
index
].
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map
[
index
].
endpoint
,
&
value
);
break
;
else
if
(
findFlag
==
2
)
}
res
=
g_tsl_zigbee_map_glb
[
index
].
map
.
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map_glb
[
index
].
map
.
endpoint
,
&
value
);
}
if
(
findFlag
==
0xff
){
if
(
res
<
0
)
num
=
kk_get_tsl_glb_num
();
{
for
(
index
=
0
;
index
<
num
;
index
++
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
goto
error_return
;
if
(
propertyItem
!=
NULL
){
}
findFlag
=
2
;
else
{
break
;
return
rpc_cJSON_CreateNumber
(
res
);
}
}
}
}
}
if
(
findFlag
!=
0xff
)
}
{
error_return:
int
value
=
0
;
return
rpc_cJSON_CreateNull
();
if
(
propertyItem
->
type
!=
cJSON_Number
){
}
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
}
else
{
value
=
propertyItem
->
valueint
;
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
}
{
uint8_t
Onoff
=
0
;
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
EmberStatus
status
=
0
;
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
Onoff
=
*
(
uint8_t
*
)
data
;
}
emberAfAppPrintln
(
"[tsl set:OnOff],Onoff=0x%02x"
,
Onoff
);
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
emberAfDebugPrint
(
"mac:"
);
if
(
ctx
)
emberAfPrintBigEndianEui64
(
eui64
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
emberAfDebugPrintln
(
",node:0x%04X"
,
nodeId
);
goto
error_return
;
if
(
findFlag
==
1
)
}
res
=
g_tsl_zigbee_map
[
index
].
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map
[
index
].
endpoint
,
&
value
);
else
if
(
findFlag
==
2
)
if
(
Onoff
==
1
){
res
=
g_tsl_zigbee_map_glb
[
index
].
map
.
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map_glb
[
index
].
map
.
endpoint
,
&
value
);
status
=
zclOnOff_On
(
node
,
ep
);
emberAfAppPrintln
(
"On"
);
if
(
res
<
0
)
}
else
if
(
Onoff
==
0
){
{
status
=
zclOnOff_Off
(
node
,
ep
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
emberAfAppPrintln
(
"Off"
);
goto
error_return
;
}
else
{
}
if
(
ctx
)
else
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
return
rpc_cJSON_CreateNumber
(
res
);
goto
error_return
;
}
}
}
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
return
status
;
}
error_return:
error_return:
return
-
1
;
return
rpc_cJSON_CreateNull
();
}
}
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
int
kk_tsl_set_windowCovering_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
{
uint8_t
Onoff
=
0
;
uint8_t
Operation
=
0
;
EmberStatus
status
=
0
;
EmberStatus
status
=
0
;
Onoff
=
*
(
uint8_t
*
)
data
;
Operation
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:OnOff],Onoff=0x%02x"
,
Onoff
);
emberAfAppPrintln
(
"[tsl set:Window Covering Operation Mode],mode=0x%02x"
,
Operation
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
ctx
)
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
goto
error_return
;
}
}
if
(
Onoff
==
1
){
if
(
Operation
==
0
){
status
=
zclOnOff_On
(
node
,
ep
);
status
=
WindowCover_UpOpen
(
node
,
ep
);
emberAfAppPrintln
(
"On"
);
emberAfAppPrintln
(
"Up/Open"
);
}
else
if
(
Onoff
==
0
){
}
else
if
(
Operation
==
1
){
status
=
zclOnOff_Off
(
node
,
ep
);
status
=
WindowCover_DownClose
(
node
,
ep
);
emberAfAppPrintln
(
"Off"
);
emberAfAppPrintln
(
"Down/Close"
);
}
else
{
}
else
if
(
Operation
==
2
){
if
(
ctx
)
status
=
WindowCover_Stop
(
node
,
ep
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
emberAfAppPrintln
(
"Stop"
);
goto
error_return
;
}
else
{
}
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
goto
error_return
;
return
status
;
}
error_return:
return
-
1
;
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
return
status
;
}
error_return:
return
-
1
;
}
int
kk_tsl_set_windowCovering_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
kk_tsl_set_windowCovering_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
uint8_t
Operation
=
0
;
{
EmberStatus
status
=
0
;
uint8_t
mode
=
0
;
uint8_t
WCmode
=
0
;
Operation
=
*
(
uint8_t
*
)
data
;
EmberStatus
status
=
0
;
emberAfAppPrintln
(
"[tsl set:Window Covering Operation Mode],mode=0x%02x"
,
Operation
);
mode
=
*
(
uint8_t
*
)
data
;
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
emberAfAppPrintln
(
"[tsl set:Window Covering Run Mode],mode=0x%02x"
,
mode
);
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
if
(
mode
==
WC_calibration_mode
){
goto
error_return
;
WCmode
|=
BIT
(
1
);
}
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
if
(
Operation
==
0
){
ZCL_MODE_ATTRIBUTE_ID
,
status
=
WindowCover_UpOpen
(
node
,
ep
);
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
emberAfAppPrintln
(
"Up/Open"
);
1
,
}
else
if
(
Operation
==
1
){
WCmode
,
status
=
WindowCover_DownClose
(
node
,
ep
);
true
);
emberAfAppPrintln
(
"Down/Close"
);
emberAfAppPrintln
(
"Calibration Mode"
);
}
else
if
(
Operation
==
2
){
}
else
if
(
mode
==
WC_reversed_dir
){
status
=
WindowCover_Stop
(
node
,
ep
);
WCmode
|=
BIT
(
0
);
emberAfAppPrintln
(
"Stop"
);
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
}
else
{
ZCL_MODE_ATTRIBUTE_ID
,
if
(
ctx
)
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
1
,
goto
error_return
;
WCmode
,
}
true
);
emberAfAppPrintln
(
"Dir:reversed"
);
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
}
else
if
(
mode
==
WC_normal_dir
){
return
status
;
WCmode
=
0
;
error_return:
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
return
-
1
;
ZCL_MODE_ATTRIBUTE_ID
,
}
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
1
,
int
kk_tsl_set_windowCovering_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
WCmode
,
{
true
);
uint8_t
mode
=
0
;
emberAfAppPrintln
(
"Dir:Normal"
);
uint8_t
WCmode
=
0
;
}
else
{
EmberStatus
status
=
0
;
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
mode
=
*
(
uint8_t
*
)
data
;
goto
error_return
;
emberAfAppPrintln
(
"[tsl set:Window Covering Run Mode],mode=0x%02x"
,
mode
);
}
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
if
(
mode
==
WC_calibration_mode
){
return
status
;
WCmode
|=
BIT
(
1
);
error_return:
return
-
1
;
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
}
ZCL_MODE_ATTRIBUTE_ID
,
int
kk_tsl_set_windowCovering_position
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
{
1
,
uint8_t
position
=
0
;
WCmode
,
EmberStatus
status
=
0
;
true
);
emberAfAppPrintln
(
"Calibration Mode"
);
position
=
*
(
uint8_t
*
)
data
;
}
else
if
(
mode
==
WC_reversed_dir
){
emberAfAppPrintln
(
"[tsl set:Window Covering Position],position=0x%02x"
,
position
);
WCmode
|=
BIT
(
0
);
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
status
=
WindowCover_GotoLiftPercentage
(
node
,
ep
,
position
);
ZCL_MODE_ATTRIBUTE_ID
,
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
1
,
return
status
;
WCmode
,
error_return:
true
);
return
-
1
;
emberAfAppPrintln
(
"Dir:reversed"
);
}
}
else
if
(
mode
==
WC_normal_dir
){
WCmode
=
0
;
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
ZCL_MODE_ATTRIBUTE_ID
,
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
1
,
WCmode
,
true
);
emberAfAppPrintln
(
"Dir:Normal"
);
}
else
{
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
return
status
;
error_return:
return
-
1
;
}
int
kk_tsl_set_windowCovering_position
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
position
=
0
;
EmberStatus
status
=
0
;
position
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:Window Covering Position],position=0x%02x"
,
position
);
status
=
WindowCover_GotoLiftPercentage
(
node
,
ep
,
position
);
emberAfAppPrintln
(
"status=0x%02x"
,
status
);
return
status
;
error_return:
return
-
1
;
}
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
View file @
490a67cf
#ifndef __KK_TSL_PROPERTY_SET_H
#ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h"
#include "kk_test.h"
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
cJSON
*
kk_topo_change_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_position
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_windowCovering_position
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
#endif
#endif
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
View file @
490a67cf
#ifndef _KK_TEST_H
#ifndef _KK_TEST_H
#define _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "RPC_API.h"
#include "com_api.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#include "kk_tsl_property_set.h"
#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_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_DEVICE_TOPO_CHANGE_TYPE "/thing/topo/change"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
int
kk_zcl_onoff_set
(
jrpc_context
*
ctx
,
const
char
*
mac
,
unsigned
char
ep
,
void
*
data
);
int
kk_zcl_onoff_set
(
jrpc_context
*
ctx
,
const
char
*
mac
,
unsigned
char
ep
,
void
*
data
);
int
kk_sendData2CCU
(
char
*
data
,
int
len
);
int
kk_sendData2CCU
(
char
*
data
,
int
len
);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD}
#define RPC_KK_TEST_FUNCTION_TABLE \
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
},
\
{(
rpc_function
*
)
kk_tsl_property_operation
,
KK_READ_ATTRIBUTE_METHOD
},
\
{(
rpc_function
*
)
kk_topo_change_operation
,
KK_DEVICE_TOPO_CHANGE_TYPE
}
enum
{
WC_normal_dir
=
0
,
//"正转"
WC_reversed_dir
=
1
,
//"反转"
WC_calibration_mode
=
2
,
//"校验"
}
windowCoveringMode
;
enum
{
WC_normal_dir
=
0
,
//"正转"
WC_reversed_dir
=
1
,
//"反转"
WC_calibration_mode
=
2
,
//"校验"
}
windowCoveringMode
;
#endif
#endif
platform/zigbee/app/builder/Z3GatewayHost/libapi_com.so
View file @
490a67cf
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