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 @@
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_FILTER_STATUS_OFFLINE "/thing/status/offline"
#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_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
\"
}"
;
#define KK_TOPIC_SERVICE_DELIMITER '/'
...
...
@@ -202,6 +204,9 @@ static int _check_invalid_topic(const char* topic)
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_TOPO_CHANEG_REPLY
)
!=
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
...
...
@@ -273,7 +278,31 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli,
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
)
{
cJSON
*
root
;
...
...
@@ -301,17 +330,20 @@ static char * _kk_data_create(const char *topic,const char *data)
cJSON
*
infoObj
=
cJSON_Parse
(
infoStr
);
cJSON
*
payloadObj
=
cJSON_Parse
(
data
);
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
);
cJSON_Delete
(
root
);
free
(
msgStr
);
free
(
infoStr
);
INFO_PRINT
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
//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
\"
}"
;
int
KK_Send_CloudState
(
int
state
)
{
char
*
infoStr
=
NULL
;
...
...
application/kcloud/kcloud_main.c
View file @
490a67cf
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
static
int
mqtt_start
(
void
)
{
int
count
=
0
;
MQTTAsync
mqttClient
;
int
rc
=
0
;
mqttClient
=
KK_MQTT_Connect
();
if
(
mqttClient
==
NULL
)
{
WARNING_PRINT
(
"KK_MQTT_Connect FAIL!!!
\n
"
);
}
else
{
INFO_PRINT
(
"Waiting for publication of %s
\n
"
"on topic %s for client with ClientID: %s
\n
"
,
PAYLOAD
,
TOPIC
,
CLIENTID
);
}
while
(
1
)
{
usleep
(
100000L
);
count
++
;
if
(
count
>
50
)
{
count
=
0
;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
}
INFO_PRINT
(
"MQTTAsync_destroy
\n
"
);
MQTTAsync_destroy
(
&
mqttClient
);
return
rc
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
rc
=
0
;
//KK_Data_Hdl_Init();
kk_zlog_init
(
"kcloud"
);
/*set the callback to get the device date to cloud*/
HAL_SetProduct_Type
(
PRODUCT_TPYE
);
HAL_SetProduct_Code
(
PRODUCT_CODE
);
kk_ipc_init
(
IPC_APP2MID
,
KK_Data_FromDev
,
NULL
,
NULL
);
rc
=
mqtt_start
();
return
rc
;
}
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
static
int
mqtt_start
(
void
)
{
int
count
=
0
;
MQTTAsync
mqttClient
;
int
rc
=
0
;
mqttClient
=
KK_MQTT_Connect
();
if
(
mqttClient
==
NULL
)
{
WARNING_PRINT
(
"KK_MQTT_Connect FAIL!!!
\n
"
);
}
else
{
INFO_PRINT
(
"Waiting for publication of %s
\n
"
"on topic %s for client with ClientID: %s
\n
"
,
PAYLOAD
,
TOPIC
,
CLIENTID
);
}
while
(
1
)
{
usleep
(
100000L
);
count
++
;
if
(
count
>
50
)
{
count
=
0
;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
}
INFO_PRINT
(
"MQTTAsync_destroy
\n
"
);
MQTTAsync_destroy
(
&
mqttClient
);
return
rc
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
rc
=
0
;
//KK_Data_Hdl_Init();
kk_zlog_init
(
"kcloud"
);
/*set the callback to get the device date to cloud*/
kk_ipc_init
(
IPC_APP2MID
,
KK_Data_FromDev
,
NULL
,
NULL
);
rc
=
mqtt_start
();
return
rc
;
}
application/kcloud/kk_topic_mng.c
View file @
490a67cf
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kk_product.h"
#include "cJSON.h"
#include "com_api.h"
#include "kk_log.h"
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_OTA_PREFIX
[]
=
"/ota/device/upgrade/kk/%s/%s/#"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
int
KK_Subdev_Subscribe
(
const
cJSON
*
root
)
{
int
res
=
0
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
productCode
=
NULL
;
cJSON
*
data
=
NULL
;
cJSON
*
cmd
=
NULL
;
int
url_len
=
0
;
data
=
cJSON_GetObjectItem
(
root
,
"data"
);
if
(
data
==
NULL
){
return
-
1
;
}
deviceCode
=
cJSON_GetObjectItem
(
data
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
return
-
1
;
}
productCode
=
cJSON_GetObjectItem
(
data
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
return
-
1
;
}
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
return
res
;
}
static
int
_kk_client_subscribe
(
char
productCode
[
PRODUCT_CODE_LEN
],
char
deviceCode
[
DEVICE_CODE_LEN
])
{
int
res
=
0
,
index
=
0
,
fail_count
=
0
;
int
url_len
=
0
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
return
res
;
}
int
KK_Client_Gateway_Subscribe
(
void
)
{
char
productCode
[
PRODUCT_CODE_LEN
]
=
{
0
};
char
deviceCode
[
MAC_ADDR_LEN
]
=
{
0
};
HAL_GetProduct_Code
(
productCode
);
HAL_Get_mac
(
deviceCode
);
return
_kk_client_subscribe
(
productCode
,
"CCU_66666"
);
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_code
,
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
name
==
NULL
||
product_code
==
NULL
||
device_code
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
+
strlen
(
name
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_code
,
device_code
);
if
(
name
!=
NULL
)
{
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
}
return
0
;
}
static
int
_kk_utils_topic_ota
(
_IN_
char
*
str
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
str
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
str
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
memcpy
(
*
topic
,
str
,
service_name_len
);
return
0
;
}
int
KK_Subdev_UnSubscribe
(
cJSON
*
payload
)
{
cJSON
*
params
,
*
productCode
,
*
deviceCode
;
char
*
topic
=
NULL
;
int
topic_len
=
0
;
if
(
payload
==
NULL
){
goto
errorreturn
;
}
params
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
if
(
params
==
NULL
){
goto
errorreturn
;
}
productCode
=
cJSON_GetObjectItem
(
params
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
goto
errorreturn
;
}
deviceCode
=
cJSON_GetObjectItem
(
params
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
goto
errorreturn
;
}
topic_len
=
strlen
(
KK_URI_SYS_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
topic
=
malloc
(
topic_len
);
if
(
topic
==
NULL
)
{
goto
errorreturn
;
}
memset
(
topic
,
0
,
topic_len
);
snprintf
(
topic
,
topic_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
KK_MQTT_UnsubTopic
(
topic
);
free
(
topic
);
return
0
;
errorreturn:
return
-
1
;
}
char
*
KK_Make_Topic
(
cJSON
*
info
)
{
cJSON
*
type
,
*
product_code
,
*
device_code
;
char
*
topic
=
NULL
;
//root=cJSON_Parse((char*)info->valuestring);
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
if
(
type
==
NULL
){
goto
errorreturn
;
}
product_code
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_CODE_STR
);
if
(
product_code
==
NULL
){
goto
errorreturn
;
}
device_code
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
if
(
device_code
==
NULL
){
goto
errorreturn
;
}
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)
||
strstr
(
type
->
valuestring
,
"/ota/device/progress"
)){
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
}
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
;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kk_product.h"
#include "cJSON.h"
#include "com_api.h"
#include "kk_log.h"
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_OTA_PREFIX
[]
=
"/ota/device/upgrade/kk/%s/%s/#"
;
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
const
char
KK_URI_OTA_INFORM
[]
=
"/ota/device/inform/%s/%s"
;
int
KK_Subdev_Subscribe
(
const
cJSON
*
root
)
{
int
res
=
0
;
cJSON
*
deviceCode
=
NULL
;
cJSON
*
productCode
=
NULL
;
cJSON
*
data
=
NULL
;
cJSON
*
cmd
=
NULL
;
int
url_len
=
0
;
data
=
cJSON_GetObjectItem
(
root
,
"data"
);
if
(
data
==
NULL
){
return
-
1
;
}
deviceCode
=
cJSON_GetObjectItem
(
data
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
return
-
1
;
}
productCode
=
cJSON_GetObjectItem
(
data
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
return
-
1
;
}
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
->
valuestring
)
+
strlen
(
deviceCode
->
valuestring
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
->
valuestring
,
deviceCode
->
valuestring
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
return
res
;
}
static
int
_kk_client_subscribe
(
char
productCode
[
PRODUCT_CODE_LEN
],
char
deviceCode
[
DEVICE_CODE_LEN
])
{
int
res
=
0
,
index
=
0
,
fail_count
=
0
;
int
url_len
=
0
;
url_len
=
strlen
(
KK_URI_OTA_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
char
*
url
=
malloc
(
url_len
);
if
(
url
==
NULL
)
{
return
-
1
;
}
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_OTA_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"ota [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
memset
(
url
,
0
,
url_len
);
snprintf
(
url
,
url_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"sys [%s][%d] URL:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
url
);
res
=
KK_MQTT_SubTopic
(
url
);
free
(
url
);
return
res
;
}
int
KK_Client_Gateway_Subscribe
(
void
)
{
char
productCode
[
PRODUCT_CODE_LEN
]
=
{
0
};
char
deviceCode
[
MAC_ADDR_LEN
]
=
{
0
};
HAL_GetProduct_Code
(
productCode
);
HAL_Get_mac
(
deviceCode
);
return
_kk_client_subscribe
(
productCode
,
"CCU_66666"
);
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_code
,
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
name
==
NULL
||
product_code
==
NULL
||
device_code
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
+
strlen
(
name
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_code
,
device_code
);
if
(
name
!=
NULL
)
{
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
}
return
0
;
}
static
int
_kk_utils_topic_ota
(
_IN_
char
*
str
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
str
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
str
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
memcpy
(
*
topic
,
str
,
service_name_len
);
return
0
;
}
int
KK_Subdev_UnSubscribe_By_DeviceCode
(
const
char
*
deviceCode
,
const
char
*
productCode
)
{
char
*
topic
=
NULL
;
int
topic_len
=
0
;
topic_len
=
strlen
(
KK_URI_SYS_PREFIX
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
1
;
topic
=
malloc
(
topic_len
);
if
(
topic
==
NULL
)
{
return
-
1
;
}
memset
(
topic
,
0
,
topic_len
);
snprintf
(
topic
,
topic_len
,
KK_URI_SYS_PREFIX
,
productCode
,
deviceCode
);
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
KK_MQTT_UnsubTopic
(
topic
);
free
(
topic
);
return
0
;
}
int
KK_Subdev_UnSubscribe
(
cJSON
*
payload
)
{
cJSON
*
params
,
*
productCode
,
*
deviceCode
;
if
(
payload
==
NULL
){
goto
errorreturn
;
}
params
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
if
(
params
==
NULL
){
goto
errorreturn
;
}
productCode
=
cJSON_GetObjectItem
(
params
,
MSG_PRODUCT_CODE_STR
);
if
(
productCode
==
NULL
){
goto
errorreturn
;
}
deviceCode
=
cJSON_GetObjectItem
(
params
,
MSG_DEVICE_CODE_STR
);
if
(
deviceCode
==
NULL
){
goto
errorreturn
;
}
KK_Subdev_UnSubscribe_By_DeviceCode
(
deviceCode
->
valuestring
,
productCode
->
valuestring
);
return
0
;
errorreturn:
return
-
1
;
}
char
*
KK_Make_Topic
(
cJSON
*
info
)
{
cJSON
*
type
,
*
product_code
,
*
device_code
;
char
*
topic
=
NULL
;
//root=cJSON_Parse((char*)info->valuestring);
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
if
(
type
==
NULL
){
goto
errorreturn
;
}
product_code
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_CODE_STR
);
if
(
product_code
==
NULL
){
goto
errorreturn
;
}
device_code
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
if
(
device_code
==
NULL
){
goto
errorreturn
;
}
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)
||
strstr
(
type
->
valuestring
,
"/ota/device/progress"
)){
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
}
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
*/
#ifndef _KK_COM_API_H_
#define _KK_COM_API_H_
#if defined(__cplusplus)
extern
"C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ev.h"
#include "nn.h"
#include "pair.h"
#include "pubsub.h"
#include "pipeline.h"
//=====kk======================
typedef
enum
{
IPC_APP2MID
=
0
,
IPC_MID2APP
,
IPC_MID2PLAT
,
IPC_PLAT2MID
,
IPC_UNDEF
}
ipc_type
;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
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_deinit
(
ipc_type
type
);
int
kk_ipc_send
(
ipc_type
type
,
void
*
data
,
int
len
);
int
kk_ipc_send_ex
(
ipc_type
type
,
void
*
data
,
int
len
,
char
*
chalMark
);
#if defined(__cplusplus)
}
#endif
#endif
/*
* Copyright (C) 2020-2020 ikonke
*/
#ifndef _KK_COM_API_H_
#define _KK_COM_API_H_
#if defined(__cplusplus)
extern
"C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ev.h"
#include "nn.h"
#include "pair.h"
#include "pubsub.h"
#include "pipeline.h"
//=====kk======================
typedef
enum
{
IPC_APP2MID
=
0
,
IPC_MID2APP
,
IPC_MID2PLAT
,
IPC_PLAT2MID
,
IPC_UNDEF
}
ipc_type
;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
#define MSG_DEVICE_CODE_STR "deviceCode"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
#define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
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_deinit
(
ipc_type
type
);
int
kk_ipc_send
(
ipc_type
type
,
void
*
data
,
int
len
);
int
kk_ipc_send_ex
(
ipc_type
type
,
void
*
data
,
int
len
,
char
*
chalMark
);
#if defined(__cplusplus)
}
#endif
#endif
midware/midware/dm/kk_dm_msg.h
View file @
490a67cf
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
typedef
struct
{
lite_cjson_t
id
;
lite_cjson_t
code
;
lite_cjson_t
data
;
lite_cjson_t
message
;
}
dm_msg_response_payload_t
;
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
#endif
#define DM_MSG_VERSION "1.0"
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post"
#define KK_THING_TOPO_DELETE_MSG "/thing/topo/delete"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
#endif
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
typedef
struct
{
lite_cjson_t
id
;
lite_cjson_t
code
;
lite_cjson_t
data
;
lite_cjson_t
message
;
}
dm_msg_response_payload_t
;
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
#endif
#define DM_MSG_VERSION "1.0"
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate_reply"
#define KK_THING_TOPO_ADD_MSG "/thing/topo/add"
#define KK_THING_PROPERTY_POST "property/post"
#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/";
#endif
midware/midware/dm/kk_linkkit.c
View file @
490a67cf
...
...
@@ -234,6 +234,31 @@ int kk_get_cloud_recv_status(void){
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
)
{
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)
INFO_PRINT
(
"ota upgrade...
\n
"
);
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
"
);
}
...
...
midware/midware/midware.c
View file @
490a67cf
...
...
@@ -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
)
{
...
...
@@ -638,7 +630,6 @@ int main(const int argc, const char **argv)
kk_zlog_init
(
"midware"
);
memset
(
mid_ctx
,
0
,
sizeof
(
mid_ctx_t
));
kk_set_product_info
();
kk_tsl_api_init
();
kk_ipc_init
(
IPC_MID2APP
,
mid_cb
,
NULL
,
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"
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//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
)
{
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
int
index
=
0
;
zigbee_property_set
*
func
;
int
num
;
uint8_t
findFlag
=
0xff
;
cJSON
*
propertyItem
=
NULL
;
EmberEUI64
eui64
;
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
if
(
params
==
NULL
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
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
);
if
(
propertyItem
!=
NULL
){
findFlag
=
1
;
break
;
}
}
if
(
findFlag
==
0xff
){
num
=
kk_get_tsl_glb_num
();
for
(
index
=
0
;
index
<
num
;
index
++
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
if
(
propertyItem
!=
NULL
){
findFlag
=
2
;
break
;
}
}
}
if
(
findFlag
!=
0xff
)
{
int
value
=
0
;
if
(
propertyItem
->
type
!=
cJSON_Number
){
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
}
else
{
value
=
propertyItem
->
valueint
;
}
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
emberAfDebugPrint
(
"mac:"
);
emberAfPrintBigEndianEui64
(
eui64
);
emberAfDebugPrintln
(
",node:0x%04X"
,
nodeId
);
if
(
findFlag
==
1
)
res
=
g_tsl_zigbee_map
[
index
].
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map
[
index
].
endpoint
,
&
value
);
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
(
res
<
0
)
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
return
rpc_cJSON_CreateNumber
(
res
);
}
}
}
error_return:
return
rpc_cJSON_CreateNull
();
}
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
Onoff
=
0
;
EmberStatus
status
=
0
;
Onoff
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:OnOff],Onoff=0x%02x"
,
Onoff
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
if
(
Onoff
==
1
){
status
=
zclOnOff_On
(
node
,
ep
);
emberAfAppPrintln
(
"On"
);
}
else
if
(
Onoff
==
0
){
status
=
zclOnOff_Off
(
node
,
ep
);
emberAfAppPrintln
(
"Off"
);
}
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_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
Operation
=
0
;
EmberStatus
status
=
0
;
Operation
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:Window Covering Operation Mode],mode=0x%02x"
,
Operation
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
if
(
Operation
==
0
){
status
=
WindowCover_UpOpen
(
node
,
ep
);
emberAfAppPrintln
(
"Up/Open"
);
}
else
if
(
Operation
==
1
){
status
=
WindowCover_DownClose
(
node
,
ep
);
emberAfAppPrintln
(
"Down/Close"
);
}
else
if
(
Operation
==
2
){
status
=
WindowCover_Stop
(
node
,
ep
);
emberAfAppPrintln
(
"Stop"
);
}
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_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
mode
=
0
;
uint8_t
WCmode
=
0
;
EmberStatus
status
=
0
;
mode
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:Window Covering Run Mode],mode=0x%02x"
,
mode
);
if
(
mode
==
WC_calibration_mode
){
WCmode
|=
BIT
(
1
);
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
ZCL_MODE_ATTRIBUTE_ID
,
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
1
,
WCmode
,
true
);
emberAfAppPrintln
(
"Calibration Mode"
);
}
else
if
(
mode
==
WC_reversed_dir
){
WCmode
|=
BIT
(
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: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
;
}
#include "kk_tsl_property_set.h"
//emberAfAppPrintln("[tsl report:Gloabl] OnOff~~~~~~~~~");
//cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
cJSON
*
kk_topo_change_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
int
res
=
0
;
cJSON
*
changeTypeStr
=
NULL
;
UTIL_LOG_INFO
(
"
\n
********************kk_topo_change_operation********************
\n
"
);
if
(
params
==
NULL
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
changeTypeStr
=
rpc_cJSON_GetObjectItem
(
params
,
MSG_TOPO_CHANGE_TYPE_STR
);
if
(
changeTypeStr
!=
NULL
&&
changeTypeStr
->
valueint
==
1
){
cJSON
*
deviceArray
=
rpc_cJSON_GetObjectItem
(
params
,
MSG_TOPO_CHANGE_DEVICES_STR
);
if
(
deviceArray
==
NULL
){
goto
error_return
;
}
cJSON
*
item
=
deviceArray
->
child
;
while
(
item
!=
NULL
){
char
*
deviceCode
=
rpc_cJSON_GetObjectItem
(
item
,
MSG_DEVICE_CODE_STR
)
->
valuestring
;
item
=
item
->
next
;
}
}
}
return
rpc_cJSON_CreateNumber
(
res
);
error_return:
return
rpc_cJSON_CreateNull
();
}
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
int
index
=
0
;
zigbee_property_set
*
func
;
int
num
;
uint8_t
findFlag
=
0xff
;
cJSON
*
propertyItem
=
NULL
;
EmberEUI64
eui64
;
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
if
(
params
==
NULL
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
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
);
if
(
propertyItem
!=
NULL
){
findFlag
=
1
;
break
;
}
}
if
(
findFlag
==
0xff
){
num
=
kk_get_tsl_glb_num
();
for
(
index
=
0
;
index
<
num
;
index
++
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
if
(
propertyItem
!=
NULL
){
findFlag
=
2
;
break
;
}
}
}
if
(
findFlag
!=
0xff
)
{
int
value
=
0
;
if
(
propertyItem
->
type
!=
cJSON_Number
){
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
}
else
{
value
=
propertyItem
->
valueint
;
}
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
emberAfDebugPrint
(
"mac:"
);
emberAfPrintBigEndianEui64
(
eui64
);
emberAfDebugPrintln
(
",node:0x%04X"
,
nodeId
);
if
(
findFlag
==
1
)
res
=
g_tsl_zigbee_map
[
index
].
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map
[
index
].
endpoint
,
&
value
);
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
(
res
<
0
)
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
return
rpc_cJSON_CreateNumber
(
res
);
}
}
}
error_return:
return
rpc_cJSON_CreateNull
();
}
int
kk_tsl_set_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
Onoff
=
0
;
EmberStatus
status
=
0
;
Onoff
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:OnOff],Onoff=0x%02x"
,
Onoff
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
if
(
Onoff
==
1
){
status
=
zclOnOff_On
(
node
,
ep
);
emberAfAppPrintln
(
"On"
);
}
else
if
(
Onoff
==
0
){
status
=
zclOnOff_Off
(
node
,
ep
);
emberAfAppPrintln
(
"Off"
);
}
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_OperationMode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
Operation
=
0
;
EmberStatus
status
=
0
;
Operation
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:Window Covering Operation Mode],mode=0x%02x"
,
Operation
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
if
(
Operation
==
0
){
status
=
WindowCover_UpOpen
(
node
,
ep
);
emberAfAppPrintln
(
"Up/Open"
);
}
else
if
(
Operation
==
1
){
status
=
WindowCover_DownClose
(
node
,
ep
);
emberAfAppPrintln
(
"Down/Close"
);
}
else
if
(
Operation
==
2
){
status
=
WindowCover_Stop
(
node
,
ep
);
emberAfAppPrintln
(
"Stop"
);
}
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_mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
uint8_t
mode
=
0
;
uint8_t
WCmode
=
0
;
EmberStatus
status
=
0
;
mode
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:Window Covering Run Mode],mode=0x%02x"
,
mode
);
if
(
mode
==
WC_calibration_mode
){
WCmode
|=
BIT
(
1
);
status
=
zclGWrite
(
node
,
1
,
ep
,
false
,
ZCL_WINDOW_COVERING_CLUSTER_ID
,
ZCL_MODE_ATTRIBUTE_ID
,
ZCL_BITMAP8_ATTRIBUTE_TYPE
,
1
,
WCmode
,
true
);
emberAfAppPrintln
(
"Calibration Mode"
);
}
else
if
(
mode
==
WC_reversed_dir
){
WCmode
|=
BIT
(
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: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
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h"
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_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
#ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h"
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_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
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
View file @
490a67cf
#ifndef _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#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 TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
int
kk_zcl_onoff_set
(
jrpc_context
*
ctx
,
const
char
*
mac
,
unsigned
char
ep
,
void
*
data
);
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}
enum
{
WC_normal_dir
=
0
,
//"正转"
WC_reversed_dir
=
1
,
//"反转"
WC_calibration_mode
=
2
,
//"校验"
}
windowCoveringMode
;
#endif
#ifndef _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#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_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#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 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_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
},
\
{(
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
;
#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