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
f87d8ac5
Commit
f87d8ac5
authored
Sep 16, 2020
by
尹佳钦
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2020/09/16
parent
bab0bf4f
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
860 additions
and
843 deletions
+860
-843
platform/zigbee/app/builder/Z3GatewayHost/Makefile
platform/zigbee/app/builder/Z3GatewayHost/Makefile
+4
-4
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.c
...m/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.c
+564
-323
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.h
...m/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.h
+7
-14
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
...bee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
+156
-94
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.h
...bee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.h
+12
-4
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
+46
-341
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
+5
-10
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.c
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.c
+21
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
+35
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
+1
-7
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
+5
-11
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
...p/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
+2
-1
platform/zigbee/app/builder/Z3GatewayHost/yjq_ezsp.c
platform/zigbee/app/builder/Z3GatewayHost/yjq_ezsp.c
+1
-33
platform/zigbee/protocol/zigbee/app/framework/plugin/device-table/device-table.c
...l/zigbee/app/framework/plugin/device-table/device-table.c
+1
-1
No files found.
platform/zigbee/app/builder/Z3GatewayHost/Makefile
View file @
f87d8ac5
...
@@ -87,7 +87,6 @@ INCLUDES= \
...
@@ -87,7 +87,6 @@ INCLUDES= \
-I
./../../../platform/base/hal/micro/unix/host
\
-I
./../../../platform/base/hal/micro/unix/host
\
-I
../../../platform/base/hal/micro/unix/host/board
\
-I
../../../platform/base/hal/micro/unix/host/board
\
-I
./rpc_api/inc
\
-I
./rpc_api/inc
\
-I
../../../../../common/curl/include
\
-I
./ZB
-I
./ZB
\
\
...
@@ -285,7 +284,8 @@ APPLICATION_FILES= \
...
@@ -285,7 +284,8 @@ APPLICATION_FILES= \
./ZB/kk_zigbee_api.c
\
./ZB/kk_zigbee_api.c
\
./ZB/kk_tsl_property_report.c
\
./ZB/kk_tsl_property_report.c
\
./ZB/kk_tsl_property_set.c
\
./ZB/kk_tsl_property_set.c
\
./ZB/kk_palt_ota.c
\
./ZB/kk_device_table_db.c
\
./ZB/kk_msg_report.c
\
./kk_test.c
\
./kk_test.c
\
./kk_sub_tsl.c
\
./kk_sub_tsl.c
\
./kk_tsl_zigbee_map.c
\
./kk_tsl_zigbee_map.c
\
...
@@ -375,10 +375,10 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
...
@@ -375,10 +375,10 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
else
else
$(TARGET_FILE)
:
$(APPLICATION_OBJECTS) $(LIBRARIES)
$(TARGET_FILE)
:
$(APPLICATION_OBJECTS) $(LIBRARIES)
ifeq
($(CONFIG_VENDOR),ubuntu)
ifeq
($(CONFIG_VENDOR),ubuntu)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com_ubuntu
-lnanomsg_ubuntu
-lanl
-pthread
-lev_ubuntu
-l
kk_hal_ubuntu
-L
../../../../../common/curl
-lcurl_ubuntu
-o
$(TARGET_FILE)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com_ubuntu
-lnanomsg_ubuntu
-lanl
-pthread
-lev_ubuntu
-l
sqlite3
-lkk_hal_ubuntu
-o
$(TARGET_FILE)
@
echo
-e
'\n$@ build success'
@
echo
-e
'\n$@ build success'
else
else
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com
-lnanomsg
-lanl
-pthread
-lev
-lkk_hal
-
L
../../../../../common/curl
-lcurl
-o
$(TARGET_FILE)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-lapi_com
-lnanomsg
-lanl
-pthread
-lev
-lkk_hal
-
lsqlite3
-o
$(TARGET_FILE)
@
echo
-e
'\n$@ build success'
@
echo
-e
'\n$@ build success'
endif
endif
endif
endif
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.c
View file @
f87d8ac5
#include "kk_device_manager.h"
#include "kk_device_manager.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/****************** ******************************************************************
/****************** ******************************************************************
* File Name : kk_device_manager.c
* File Name : kk_device_manager.c
* Author : yjq
* Author : yjq
...
@@ -7,295 +15,14 @@
...
@@ -7,295 +15,14 @@
#define KK_GP_EP 242
#define KK_GP_EP 242
kk_device_table_s
*
kk_zb_device_table
=
NULL
;
static
void
kk_device_table_save
(
void
);
static
void
kk_device_table_load
(
void
);
void
kk_print_device_table
(
void
)
{
int
i
,
cnt
=
0
;
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
emberAfCorePrintln
(
"
\n
-----------kk device table-----------
\n
"
);
while
(
ptr
!=
NULL
){
emberAfAppPrint
(
"
\n
%d:"
,
++
cnt
);
emberAfAppPrint
(
"
\n
MAC = "
);
emberAfPrintBigEndianEui64
(
ptr
->
mac
);
emberAfAppPrint
(
"
\n
productCode = %s"
,(
ptr
->
productCode
!=
NULL
)
?
ptr
->
productCode
:
"unknow"
);
emberAfAppPrint
(
"
\n
identifyCnt = %d"
,
ptr
->
identifyCnt
);
ptr
=
ptr
->
next
;
}
}
static
kk_device_table_s
*
kk_device_table_create
()
{
emberAfCorePrintln
(
"
\n
[KK device table] add!"
);
kk_device_table_s
*
node
=
(
kk_device_table_s
*
)
malloc
(
sizeof
(
kk_device_table_s
));
if
(
node
==
NULL
){
emberAfCorePrintln
(
"[KK device table] malloc fail!!!%s"
,
__LINE__
);
return
node
;
}
MEMSET
(
node
,
0
,
sizeof
(
kk_device_table_s
));
return
node
;
}
static
kk_device_table_s
*
kk_device_table_find_next_empty
()
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
if
(
ptr
==
NULL
)
return
ptr
;
while
(
ptr
!=
NULL
){
if
(
ptr
->
next
==
NULL
)
return
ptr
;
ptr
=
ptr
->
next
;
}
}
static
void
kk_device_fill
(
kk_device_table_s
*
ptr
,
EmberEUI64
mac
,
EmberNodeId
nodeId
,
char
*
productCode
,
uint16_t
deviceId
)
{
memcpy
(
ptr
->
mac
,
mac
,
sizeof
(
EmberEUI64
));
ptr
->
nodeId
=
nodeId
;
ptr
->
deviceId
=
deviceId
;
ptr
->
identifyCnt
=
KK_MAX_READ_MODLE_ID_COUNT
;
memcpy
(
ptr
->
productCode
,
productCode
,
strlen
(
productCode
));
}
kk_device_table_s
*
kk_device_find_by_mac
(
EmberEUI64
mac
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
while
(
ptr
!=
NULL
){
if
(
MEMCOMPARE
(
ptr
->
mac
,
mac
,
sizeof
(
EmberEUI64
))
==
0
){
return
ptr
;
}
ptr
=
ptr
->
next
;
}
return
NULL
;
}
kk_device_table_s
*
kk_device_find_by_node
(
EmberNodeId
node
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
while
(
ptr
!=
NULL
){
if
(
ptr
->
nodeId
==
node
){
return
ptr
;
}
ptr
=
ptr
->
next
;
}
return
NULL
;
}
bool
kk_device_find_by_mac11111
(
EmberEUI64
mac
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
while
(
ptr
!=
NULL
){
if
(
MEMCOMPARE
(
ptr
->
mac
,
mac
,
sizeof
(
EmberEUI64
))
==
0
){
return
true
;
}
ptr
=
ptr
->
next
;
}
return
false
;
}
void
kk_device_table_add
(
EmberEUI64
mac
,
EmberNodeId
nodeId
,
const
char
*
productCode
,
uint16_t
deviceId
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
kk_device_table_s
*
newNode
;
UTIL_LOG_INFO
(
"
\n
********************kk device table add********************
\n
"
);
emberAfAppPrint
(
"mac:"
);
emberAfPrintBigEndianEui64
(
mac
);
kk_sub_tsl_add
(
mac
,
productCode
);
if
(
kk_device_find_by_node
(
nodeId
)
!=
NULL
){
emberAfAppPrintln
(
" is already in device table!!!"
);
return
;
}
emberAfAppPrintln
(
",nodeId:0x%02x,productCode:%s,device id:0x%04x"
,
nodeId
,(
productCode
==
NULL
)
?
"nukown"
:
productCode
,
deviceId
);
if
(
ptr
==
NULL
){
kk_zb_device_table
=
kk_device_table_create
();
ptr
=
kk_zb_device_table
;
kk_device_fill
(
ptr
,
mac
,
nodeId
,
productCode
,
deviceId
);
return
;
}
ptr
=
kk_device_table_find_next_empty
();
if
(
ptr
!=
NULL
){
newNode
=
kk_device_table_create
();
if
(
newNode
!=
NULL
){
ptr
->
next
=
newNode
;
kk_device_fill
(
newNode
,
mac
,
nodeId
,
productCode
,
deviceId
);
}
}
else
{
emberAfCorePrintln
(
"[KK device table] fatal!!!%s"
,
__LINE__
);
}
}
void
kk_device_table_delete
(
EmberEUI64
mac
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
kk_device_table_s
*
ptr_temp
=
kk_zb_device_table
;
if
(
ptr
==
NULL
){
emberAfCorePrintln
(
"[KK device table] is empty!!!"
);
return
;
}
while
(
ptr
!=
NULL
){
if
(
MEMCOMPARE
(
ptr
->
mac
,
mac
,
sizeof
(
EmberEUI64
))
==
0
){
if
(
ptr
->
next
==
NULL
){
free
(
ptr
);
kk_zb_device_table
=
NULL
;
emberAfCorePrintln
(
"[KK device table]delete,now is empty !!!"
);
return
;
}
else
{
if
(
ptr
==
kk_zb_device_table
){
kk_zb_device_table
=
ptr
->
next
;
emberAfCorePrintln
(
"[KK device table] delete list header"
);
free
(
ptr
);
return
;
}
else
{
ptr_temp
->
next
=
ptr
->
next
;
free
(
ptr
);
emberAfCorePrintln
(
"[KK device table] delete "
);
return
;
}
}
}
ptr_temp
=
ptr
;
ptr
=
ptr
->
next
;
}
}
static
void
kk_device_table_save
(
void
)
{
FILE
*
fp
;
int
i
;
uint16_t
pLen
;
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
fp
=
fopen
(
"kk_devices.txt"
,
"w"
);
while
(
ptr
!=
NULL
){
for
(
i
=
0
;
i
<
8
;
i
++
)
{
fprintf
(
fp
,
"%x "
,
ptr
->
mac
[
i
]);
}
fprintf
(
fp
,
"%x "
,
ptr
->
nodeId
);
fprintf
(
fp
,
"%x "
,
ptr
->
deviceId
);
if
(
ptr
->
productCode
==
NULL
){
pLen
=
0
;
}
else
{
pLen
=
strlen
(
ptr
->
productCode
);
}
fprintf
(
fp
,
"%x "
,
pLen
);
for
(
i
=
0
;
i
<
pLen
;
i
++
){
fprintf
(
fp
,
"%x "
,
ptr
->
productCode
[
i
]);
}
ptr
=
ptr
->
next
;
}
fclose
(
fp
);
}
static
void
kk_device_table_load
(
void
)
{
UTIL_LOG_INFO
(
"
\n
********************kk load device table********************
\n
"
);
FILE
*
fp
;
int
i
;
EmberEUI64
mac
;
uint16_t
nodeId
;
uint16_t
deviceId
;
uint16_t
len
;
char
pCode
[
33
];
fp
=
fopen
(
"kk_devices.txt"
,
"r"
);
if
(
fp
==
NULL
)
return
;
while
(
feof
(
fp
)
==
false
){
emberAfDebugPrintln
(
"111"
);
for
(
i
=
0
;
i
<
8
;
i
++
)
{
fscanf
(
fp
,
"%x "
,
&
mac
[
i
]);
}
emberAfDebugPrintln
(
"222"
);
fscanf
(
fp
,
"%x"
,
&
nodeId
);
fscanf
(
fp
,
"%x "
,
&
deviceId
);
emberAfDebugPrintln
(
"len=%d"
,
len
);
fscanf
(
fp
,
"%x"
,
&
len
);
for
(
i
=
0
;
i
<
len
;
i
++
){
fscanf
(
fp
,
"%x "
,
&
pCode
[
i
]);
}
pCode
[
i
]
=
0
;
if
(
len
==
0
){
kk_device_table_add
(
mac
,
nodeId
,
NULL
,
deviceId
);
}
else
{
kk_device_table_add
(
mac
,
nodeId
,
pCode
,
deviceId
);
}
}
fclose
(
fp
);
//kk_device_table_add(EmberEUI64 mac,EmberNodeId nodeId,uint8_t epNum,uint8_t* epVal,char *productCode)
//kk_print_device_table();
}
void
kk_device_table_clear
(
void
)
{
kk_device_table_s
*
ptr
=
kk_zb_device_table
;
kk_device_table_s
*
ptr_temp
=
kk_zb_device_table
;
if
(
ptr
==
NULL
){
return
;
}
while
(
ptr
!=
NULL
){
if
(
ptr
->
next
==
NULL
){
free
(
ptr
);
kk_zb_device_table
=
NULL
;
return
;
}
else
{
if
(
ptr
==
kk_zb_device_table
){
kk_zb_device_table
=
ptr
->
next
;
free
(
ptr
);
return
;
}
else
{
ptr_temp
->
next
=
ptr
->
next
;
free
(
ptr
);
return
;
}
}
ptr_temp
=
ptr
;
ptr
=
ptr
->
next
;
}
kk_device_table_save
();
}
static
const
char
*
kk_match_tsl_productCode
(
const
char
*
modelId
)
static
const
char
*
kk_match_tsl_productCode
(
const
char
*
modelId
)
{
{
int
i
;
int
i
;
int
num
=
kk_get_product_code_table_size
();
int
num
=
kk_get_product_code_table_size
();
UTIL_LOG_INFO
(
"device model id:%s
\n
"
,
modelId
);
UTIL_LOG_INFO
(
"device model id:%s
,%d
\n
"
,
modelId
,
strlen
(
modelId
)
);
for
(
i
=
0
;
i
<
num
&&
kk_product_code
[
i
].
modelId
!=
NULL
;
i
++
){
for
(
i
=
0
;
i
<
num
&&
kk_product_code
[
i
].
modelId
!=
NULL
;
i
++
){
if
(
strstr
(
modelId
,
kk_product_code
[
i
].
modelId
)
!=
NULL
){
if
(
strstr
(
modelId
,
kk_product_code
[
i
].
modelId
)
!=
NULL
){
UTIL_LOG_INFO
(
"match model id:%s
\n
"
,
kk_product_code
[
i
].
modelId
);
UTIL_LOG_INFO
(
"match model id:%s
\n
"
,
kk_product_code
[
i
].
modelId
);
...
@@ -312,10 +39,8 @@ static const char *kk_match_tsl_productCode(const char* modelId)
...
@@ -312,10 +39,8 @@ static const char *kk_match_tsl_productCode(const char* modelId)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
void
emberAfPluginDeviceTableInitialized
(
void
)
{
kk_device_table_load
();
}
static
int
kk_match_device_id
(
uint16_t
deviceId
)
static
int
kk_match_device_id
(
uint16_t
deviceId
)
...
@@ -346,7 +71,7 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
...
@@ -346,7 +71,7 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
uint8_t
*
data
)
uint8_t
*
data
)
{
{
kk_device_table_s
*
ptr
=
kk_
zb_device_table
;
kk_device_table_s
*
ptr
=
kk_
get_device_table_pointer
()
;
EmberEUI64
eui64
;
EmberEUI64
eui64
;
uint8_t
modelID
[
33
]
=
{
0
};
uint8_t
modelID
[
33
]
=
{
0
};
char
*
pCode
=
NULL
;
char
*
pCode
=
NULL
;
...
@@ -360,7 +85,7 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
...
@@ -360,7 +85,7 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
emberAfCorePrintln
(
"[warring]modle id size = %d,max = 32!!!"
);
emberAfCorePrintln
(
"[warring]modle id size = %d,max = 32!!!"
);
}
}
memcpy
(
modelID
,
data
,
dataSize
);
memcpy
(
modelID
,
data
,
dataSize
);
pCode
=
kk_match_
tsl_
productCode
(
modelID
);
pCode
=
kk_match_productCode
(
modelID
);
if
(
pCode
==
NULL
){
if
(
pCode
==
NULL
){
emberAfCorePrintln
(
"not match pCode!!!"
);
emberAfCorePrintln
(
"not match pCode!!!"
);
return
;
return
;
...
@@ -368,8 +93,9 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
...
@@ -368,8 +93,9 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
memcpy
(
ptr
->
productCode
,
pCode
,
strlen
(
pCode
));
memcpy
(
ptr
->
productCode
,
pCode
,
strlen
(
pCode
));
if
(
ptr
->
productCode
!=
NULL
){
if
(
ptr
->
productCode
!=
NULL
){
if
(
emberAfDeviceTableGetEui64FromNodeId
(
ptr
->
nodeId
,
eui64
)){
if
(
emberAfDeviceTableGetEui64FromNodeId
(
ptr
->
nodeId
,
eui64
)){
kk_rpc_reportDevices
(
eui64
,
ptr
->
productCode
);
kk_msg_report_dev_joined
(
eui64
,
ptr
->
productCode
);
kk_device_table_save
();
kk_device_db_update
(
eui64
,
ptr
->
nodeId
,
ptr
->
deviceId
,
ptr
->
productCode
);
kk_device_config_map_add
(
ptr
->
productCode
);
}
else
{
}
else
{
UTIL_LOG_WARNING
(
"not find mac from node in device table!!!"
);
UTIL_LOG_WARNING
(
"not find mac from node in device table!!!"
);
}
}
...
@@ -428,46 +154,22 @@ void emberAfPluginDeviceTableDeviceLeftCallback(EmberEUI64 nodeEui64)
...
@@ -428,46 +154,22 @@ void emberAfPluginDeviceTableDeviceLeftCallback(EmberEUI64 nodeEui64)
cJSON
*
nodeJson
=
rpc_reportDeviceState
(
"left"
,
deviceTable
[
deviceTableIndex
].
eui64
);
cJSON
*
nodeJson
=
rpc_reportDeviceState
(
"left"
,
deviceTable
[
deviceTableIndex
].
eui64
);
rpc_printfJSON
(
"left"
,
nodeJson
);
rpc_printfJSON
(
"left"
,
nodeJson
);
kk_
rpc_reportLeftDevices
(
deviceTable
[
deviceTableIndex
].
eui64
);
kk_
msg_report_dev_leave
(
deviceTable
[
deviceTableIndex
].
eui64
);
}
}
void
kk_device_joined
(
EmberNodeId
node
)
{
EmberEUI64
mac
;
uint16_t
deviceId
;
uint16_t
deviceTableIndex
;
EmberAfPluginDeviceTableEntry
*
devPtr
;
UTIL_LOG_INFO
(
"
\n
********************kk device joined********************
\n
"
);
if
(
emberAfDeviceTableGetEui64FromNodeId
(
node
,
mac
)
==
false
){
deviceTableIndex
=
emberAfDeviceTableGetIndexFromNodeId
(
node
);
if
(
deviceTableIndex
!=
0xffff
){
devPtr
=
emberAfDeviceTablePointer
();
kk_add_device_to_table
(
mac
,
node
,
devPtr
[
deviceTableIndex
].
deviceId
);
}
}
else
{
emberAfDebugPrintln
(
"[not find 111]"
);
if
(
emberLookupEui64ByNodeId
(
node
,
mac
)
==
EMBER_SUCCESS
){
deviceTableIndex
=
emberAfDeviceTableGetIndexFromNodeId
(
node
);
if
(
deviceTableIndex
!=
0xffff
){
devPtr
=
emberAfDeviceTablePointer
();
kk_add_device_to_table
(
mac
,
node
,
devPtr
[
deviceTableIndex
].
deviceId
);
}
}
else
{
emberAfDebugPrintln
(
"[not find 222]"
);
}
}
}
void
kk_productCode_tick
()
void
kk_productCode_tick
()
{
{
kk_device_table_s
*
ptr
=
kk_
zb_device_table
;
kk_device_table_s
*
ptr
=
kk_
get_device_table_pointer
()
;
EmberEUI64
eui64
;
EmberEUI64
eui64
;
EmberStatus
status
;
EmberStatus
status
;
while
(
ptr
!=
NULL
){
while
(
ptr
!=
NULL
){
if
(
ptr
->
productCode
==
NULL
){
emberAfCorePrintln
(
"%d"
,
strlen
(
ptr
->
productCode
));
if
(
strlen
(
ptr
->
productCode
)
==
0
){
if
(
ptr
->
nodeId
!=
0xffff
&&
ptr
->
identifyCnt
!=
0
){
if
(
ptr
->
nodeId
!=
0xffff
&&
ptr
->
identifyCnt
!=
0
){
status
=
zclGRead
(
ptr
->
nodeId
,
status
=
zclGRead
(
ptr
->
nodeId
,
1
,
1
,
...
@@ -499,7 +201,7 @@ void kk_add_device_to_table(EmberEUI64 mac,EmberNodeId nodeId,uint16_t deviceId)
...
@@ -499,7 +201,7 @@ void kk_add_device_to_table(EmberEUI64 mac,EmberNodeId nodeId,uint16_t deviceId)
kk_match_device_id
(
deviceId
);
kk_match_device_id
(
deviceId
);
kk_device_table_add
(
mac
,
nodeId
,
NULL
,
deviceId
);
kk_device_table_add
(
mac
,
nodeId
,
NULL
,
deviceId
);
kk_device_
table_save
(
);
kk_device_
db_insert
(
mac
,
nodeId
,
deviceId
,
""
);
}
}
...
@@ -513,7 +215,8 @@ void kk_network_check(void)
...
@@ -513,7 +215,8 @@ void kk_network_check(void)
panId
=
HIGH_LOW_TO_INT
(
eui64
[
1
],
eui64
[
0
]);
panId
=
HIGH_LOW_TO_INT
(
eui64
[
1
],
eui64
[
0
]);
status
=
kk_network_form
(
true
,
panId
,
KK_NETWORK_PARAMETER_TX_POWER
,
KK_NETWORK_PARAMETER_CHANNEL
);
status
=
kk_network_form
(
true
,
panId
,
KK_NETWORK_PARAMETER_TX_POWER
,
KK_NETWORK_PARAMETER_CHANNEL
);
if
(
status
==
EMBER_SUCCESS
){
if
(
status
==
EMBER_SUCCESS
){
emberAfAppPrintln
(
"network form success~~~~~~"
);
UTIL_LOG_INFO
(
"network form success~~~~~~"
);
kk_print_network_info
();
}
else
{
}
else
{
emberAfAppPrintln
(
"network form fail!!!,status=0x%x"
,
status
);
emberAfAppPrintln
(
"network form fail!!!,status=0x%x"
,
status
);
}
}
...
@@ -528,6 +231,8 @@ int kk_permit_join(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* da
...
@@ -528,6 +231,8 @@ int kk_permit_join(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* da
EmberStatus
status
;
EmberStatus
status
;
uint8_t
isEnable
=
*
(
uint8_t
*
)
data
;
uint8_t
isEnable
=
*
(
uint8_t
*
)
data
;
kk_network_check
();
if
(
isEnable
==
0
){
if
(
isEnable
==
0
){
status
=
nwkPermitJoinCMD
(
FALSE
);
status
=
nwkPermitJoinCMD
(
FALSE
);
emberAfCorePrintln
(
"Disable Permit join
\r\n
"
);
emberAfCorePrintln
(
"Disable Permit join
\r\n
"
);
...
@@ -548,8 +253,524 @@ error_return:
...
@@ -548,8 +253,524 @@ error_return:
#define KK_DEVICE_MAP_TABLE_FILE "./ZB/dev_map_table.json"
#define KK_DEVICE_MAP_TABLE_ARRAY_IDENTIFY "mapTable"
#define KK_DEVICE_CONFIG_MAP_TABLE_ARRAY_IDENTIFY "config"
typedef
struct
kk_dev_map
{
char
*
modleId
;
char
*
productCode
;
char
*
productName
;
struct
kk_dev_map
*
next
;
}
kk_dev_map
;
static
kk_dev_map
*
device_map
=
NULL
;
bool
kk_device_map_add
(
const
char
*
modleId
,
const
char
*
productCode
,
const
char
*
productName
)
{
int
len
;
kk_dev_map
*
ptr
,
*
pre
;
ptr
=
pre
=
device_map
;
if
(
modleId
==
NULL
&&
productCode
==
NULL
)
return
false
;
while
(
ptr
!=
NULL
){
pre
=
ptr
;
ptr
=
ptr
->
next
;
}
ptr
=
(
kk_dev_map
*
)
malloc
(
sizeof
(
kk_dev_map
));
memset
(
ptr
,
0
,
sizeof
(
kk_dev_map
));
len
=
strlen
(
modleId
);
ptr
->
modleId
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
modleId
,
modleId
,
len
);
ptr
->
modleId
[
len
]
=
'\0'
;
len
=
strlen
(
productCode
);
ptr
->
productCode
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
productCode
,
productCode
,
len
);
ptr
->
productCode
[
len
]
=
'\0'
;
if
(
productName
!=
NULL
){
len
=
strlen
(
productName
);
ptr
->
productName
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
productName
,
productName
,
len
);
ptr
->
productName
[
len
]
=
'\0'
;
}
if
(
device_map
==
NULL
){
device_map
=
ptr
;
}
else
{
pre
->
next
=
ptr
;
}
return
true
;
}
void
kk_device_map_print
(
void
)
{
int
cnt
=
1
;
kk_dev_map
*
ptr
=
device_map
;
UTIL_LOG_INFO
(
"
\n
***************device map list print***************
\n
"
);
while
(
ptr
!=
NULL
){
emberAfCorePrintln
(
"--------------------%d--------------------
\n
"
,
cnt
++
);
emberAfCorePrintln
(
"modleId:%s
\n
"
,
ptr
->
modleId
);
emberAfCorePrintln
(
"productCode:%s
\n
"
,
ptr
->
productCode
);
if
(
ptr
->
productName
){
emberAfCorePrintln
(
"productName:%s
\n
"
,
ptr
->
productName
);
}
ptr
=
ptr
->
next
;
}
}
void
kk_load_dev_map_table
(
void
)
{
int
len
;
int
bufferSize
;
int
fd
=
open
(
KK_DEVICE_MAP_TABLE_FILE
,
O_RDONLY
);
struct
stat
statbuff
;
stat
(
KK_DEVICE_MAP_TABLE_FILE
,
&
statbuff
);
bufferSize
=
statbuff
.
st_size
+
128
;
uint8_t
*
buffer
=
(
uint8_t
*
)
malloc
(
bufferSize
);
memset
(
buffer
,
0
,
bufferSize
);
UTIL_LOG_INFO
(
"
\n
***************load device map table***************
\n
"
);
if
(
fd
<
0
){
free
(
buffer
);
UTIL_LOG_ERR
(
"can not open %s,fd=%d!!!
\n
"
,
KK_DEVICE_MAP_TABLE_FILE
,
fd
);
return
;
}
len
=
read
(
fd
,
buffer
,
bufferSize
);
if
(
len
<
0
){
free
(
buffer
);
close
(
fd
);
UTIL_LOG_ERR
(
"can not read %s!!!
\n
"
,
KK_DEVICE_MAP_TABLE_FILE
);
return
;
}
cJSON
*
map
=
rpc_cJSON_Parse
(
buffer
);
if
(
map
==
NULL
){
free
(
buffer
);
UTIL_LOG_INFO
(
"can not load dev map table!!!
\n
"
);
return
;
}
char
*
p
=
rpc_cJSON_Print
(
map
);
if
(
p
!=
NULL
){
emberAfCorePrintln
(
"device map table JSON:
\n
%s
\n
"
,
p
);
free
(
p
);
}
kk_add_dev_map_table_to_list
(
map
);
free
(
buffer
);
close
(
fd
);
rpc_cJSON_Delete
(
map
);
}
void
kk_add_dev_map_table_to_list
(
cJSON
*
root
)
{
int
i
,
len
,
size
;
cJSON
*
item
,
*
modelId
,
*
productCode
,
*
productName
;
cJSON
*
table
=
rpc_cJSON_GetObjectItem
(
root
,
KK_DEVICE_MAP_TABLE_ARRAY_IDENTIFY
);
if
(
table
==
NULL
){
UTIL_LOG_INFO
(
"can not add dev map to list!!!
\n
"
);
return
;
}
size
=
rpc_cJSON_GetArraySize
(
table
);
for
(
i
=
0
;
i
<
size
;
i
++
){
item
=
rpc_cJSON_GetArrayItem
(
table
,
i
);
modelId
=
cJSON_GetObjectItem
(
item
,
"modleId"
);
productCode
=
cJSON_GetObjectItem
(
item
,
"productCode"
);
productName
=
cJSON_GetObjectItem
(
item
,
"productName"
);
kk_device_map_add
(
modelId
->
valuestring
,
productCode
->
valuestring
,
productName
->
valuestring
);
}
}
char
*
kk_match_productCode
(
const
char
*
modelId
)
{
kk_dev_map
*
ptr
=
device_map
;
UTIL_LOG_INFO
(
"
\n
***************match productCode***************
\n
"
);
UTIL_LOG_INFO
(
"device model id:%s
\n
"
,
modelId
);
while
(
ptr
!=
NULL
){
if
(
strstr
(
modelId
,
ptr
->
modleId
)
!=
NULL
){
UTIL_LOG_INFO
(
"match model id:%s
\n
"
,
ptr
->
modleId
);
UTIL_LOG_INFO
(
"tsl product code:%s
\n
"
,
ptr
->
productCode
);
if
(
ptr
->
productName
!=
NULL
){
UTIL_LOG_INFO
(
"match product:%s
\n
"
,
ptr
->
productName
);
}
return
ptr
->
productCode
;
}
ptr
=
ptr
->
next
;
}
return
NULL
;
}
typedef
struct
kk_dev_config_item
{
char
*
identity
;
char
*
reportFuncName
;
char
*
controlFuncName
;
kk_rpc_report
*
reportFunc
;
kk_rpc_set
*
controlFunc
;
uint8_t
endpoint
;
uint16_t
cluster
;
uint16_t
attribute
;
struct
kk_dev_config_item
*
next
;
}
kk_dev_config_item
;
typedef
struct
kk_dev_config_map
{
char
*
productCode
;
kk_dev_config_item
item
;
struct
kk_dev_config_map
*
next
;
}
kk_dev_config_map
;
static
kk_dev_config_map
*
dev_config_map
=
NULL
;
#define KK_DEVICE_CONFIG_MAP_TABLE_FILE_PREFIX "./ZB/dev_config_table/device_%s.json"
kk_dev_config_item
*
kk_device_config_item_find_by_identity
(
kk_dev_config_map
*
map
,
const
char
*
identity
)
{
kk_dev_config_item
*
item
;
item
=
&
map
->
item
;
while
(
item
!=
NULL
){
if
(
!
strcmp
(
item
->
identity
,
identity
)){
return
item
;
}
}
return
NULL
;
}
kk_dev_config_map
*
kk_device_config_find
(
const
char
*
productCode
)
{
kk_dev_config_map
*
ptr
,
*
pre
;
ptr
=
pre
=
dev_config_map
;
if
(
productCode
==
NULL
)
return
NULL
;
while
(
ptr
!=
NULL
){
if
(
!
memcmp
(
ptr
->
productCode
,
productCode
,
strlen
(
productCode
))){
return
ptr
;
}
pre
=
ptr
;
ptr
=
ptr
->
next
;
}
return
NULL
;
}
void
kk_device_config_item_report
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clu
,
EmberAfAttributeId
attr
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int
status
;
kk_dev_config_item
*
item
;
kk_dev_config_map
*
cfgMap
;
char
*
pCode
;
kk_zigbee_property_report
func
;
pCode
=
kk_device_find_productCode
(
eui64
);
cfgMap
=
kk_device_config_find
(
pCode
);
if
(
cfgMap
==
NULL
)
return
;
item
=
&
cfgMap
->
item
;
while
(
item
!=
NULL
){
if
(
item
->
endpoint
==
EP
&&
item
->
cluster
==
clu
&&
item
->
attribute
==
attr
){
if
(
item
->
reportFunc
!=
NULL
){
func
=
item
->
reportFunc
;
emberAfCorePrintln
(
"[call]:%s
\n
"
,
item
->
reportFuncName
);
status
=
func
(
eui64
,
EP
,
clu
,
attr
,
dataType
,
len
,
data
);
emberAfDebugPrintln
(
"report status:%d"
,
status
);
break
;
}
}
}
}
kk_rpc_set
kk_find_rpc_set_function_api
(
const
char
*
name
)
{
int
rpcFuncSize
=
kk_get_rpc_set_api_size
();
for
(
int
i
=
0
;
i
<
rpcFuncSize
;
i
++
){
if
(
!
strcmp
(
kk_rpc_set_api
[
i
].
name
,
name
)){
return
kk_rpc_set_api
[
i
].
set
;
}
}
}
kk_rpc_report
kk_find_rpc_report_function_api
(
const
char
*
name
)
{
int
rpcFuncSize
=
kk_get_rpc_report_api_size
();
for
(
int
i
=
0
;
i
<
rpcFuncSize
;
i
++
){
if
(
!
strcmp
(
kk_rpc_report_api
[
i
].
name
,
name
)){
return
kk_rpc_report_api
[
i
].
report
;
}
}
}
bool
kk_device_config_exist_check
(
const
char
*
productCode
)
{
kk_dev_config_map
*
ptr
=
dev_config_map
;
while
(
ptr
!=
NULL
){
if
(
!
strcmp
(
ptr
->
productCode
,
productCode
))
return
true
;
ptr
=
ptr
->
next
;
}
return
false
;
}
bool
kk_device_config_add
(
const
char
*
productCode
,
const
char
*
identity
,
uint8_t
ep
,
uint16_t
clu
,
uint16_t
attr
,
const
char
*
reportFuncName
,
const
char
*
controlFuncName
)
{
int
len
;
kk_dev_config_map
*
ptr
,
*
pre
,
*
pTemp
;
kk_dev_config_item
*
item
,
*
itemPre
,
*
newItem
;
ptr
=
kk_device_config_find
(
productCode
);
if
(
ptr
==
NULL
){
ptr
=
(
kk_dev_config_map
*
)
malloc
(
sizeof
(
kk_dev_config_map
));
memset
(
ptr
,
0
,
sizeof
(
kk_dev_config_map
));
len
=
strlen
(
productCode
);
ptr
->
productCode
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
productCode
,
productCode
,
len
);
ptr
->
productCode
[
len
]
=
'\0'
;
len
=
strlen
(
identity
);
ptr
->
item
.
identity
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
item
.
identity
,
identity
,
len
);
ptr
->
item
.
identity
[
len
]
=
'\0'
;
ptr
->
item
.
endpoint
=
ep
;
ptr
->
item
.
cluster
=
clu
;
ptr
->
item
.
attribute
=
attr
;
len
=
strlen
(
reportFuncName
);
ptr
->
item
.
reportFuncName
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
item
.
reportFuncName
,
reportFuncName
,
len
);
ptr
->
item
.
reportFuncName
[
len
]
=
'\0'
;
len
=
strlen
(
controlFuncName
);
ptr
->
item
.
controlFuncName
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
ptr
->
item
.
controlFuncName
,
controlFuncName
,
len
);
ptr
->
item
.
controlFuncName
[
len
]
=
'\0'
;
newItem
->
reportFunc
=
kk_find_rpc_report_function_api
(
reportFuncName
);
newItem
->
controlFunc
=
kk_find_rpc_set_function_api
(
controlFuncName
);
if
(
dev_config_map
==
NULL
){
dev_config_map
=
ptr
;
}
else
{
pTemp
=
dev_config_map
;
while
(
pTemp
!=
NULL
){
pre
=
pTemp
;
pTemp
=
pTemp
->
next
;
}
pTemp
=
pre
;
pTemp
->
next
=
ptr
;
}
}
else
{
item
=
&
ptr
->
item
;
while
(
item
!=
NULL
){
itemPre
=
item
;
item
=
item
->
next
;
}
newItem
=
(
kk_dev_config_item
*
)
malloc
(
sizeof
(
kk_dev_config_item
));
memset
(
newItem
,
0
,
sizeof
(
kk_dev_config_item
));
len
=
strlen
(
identity
);
newItem
->
identity
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
newItem
->
identity
,
identity
,
len
);
newItem
->
identity
[
len
]
=
'\0'
;
newItem
->
endpoint
=
ep
;
newItem
->
cluster
=
clu
;
newItem
->
attribute
=
attr
;
len
=
strlen
(
reportFuncName
);
newItem
->
reportFuncName
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
newItem
->
reportFuncName
,
reportFuncName
,
len
);
newItem
->
reportFuncName
[
len
]
=
'\0'
;
len
=
strlen
(
controlFuncName
);
newItem
->
controlFuncName
=
(
char
*
)
malloc
(
len
+
1
);
memcpy
(
newItem
->
controlFuncName
,
controlFuncName
,
len
);
newItem
->
controlFuncName
[
len
]
=
'\0'
;
newItem
->
reportFunc
=
kk_find_rpc_report_function_api
(
reportFuncName
);
newItem
->
controlFunc
=
kk_find_rpc_set_function_api
(
controlFuncName
);
itemPre
->
next
=
newItem
;
}
return
true
;
}
void
kk_add_dev_config_map_table_to_list
(
cJSON
*
root
,
const
char
*
productCode
)
{
uint8_t
ep
;
uint16_t
clu
;
uint16_t
attr
;
int
i
,
len
,
size
;
cJSON
*
item
,
*
identity
;
cJSON
*
endpoint
,
*
cluster
,
*
attribute
,
*
reportFuncName
,
*
controlFuncName
;
cJSON
*
table
=
rpc_cJSON_GetObjectItem
(
root
,
KK_DEVICE_CONFIG_MAP_TABLE_ARRAY_IDENTIFY
);
if
(
table
==
NULL
){
UTIL_LOG_INFO
(
"can not add dev map to list!!!
\n
"
);
return
;
}
size
=
rpc_cJSON_GetArraySize
(
table
);
for
(
i
=
0
;
i
<
size
;
i
++
){
item
=
rpc_cJSON_GetArrayItem
(
table
,
i
);
identity
=
cJSON_GetObjectItem
(
item
,
"identity"
);
endpoint
=
cJSON_GetObjectItem
(
item
,
"endpoint"
);
cluster
=
cJSON_GetObjectItem
(
item
,
"cluster"
);
attribute
=
cJSON_GetObjectItem
(
item
,
"attribute"
);
reportFuncName
=
cJSON_GetObjectItem
(
item
,
"reportFunc"
);
controlFuncName
=
cJSON_GetObjectItem
(
item
,
"controlFunc"
);
ep
=
endpoint
->
valueint
;
len
=
strlen
(
cluster
->
valuestring
);
if
(
len
>=
4
){
clu
=
rpc_get_u16
(
&
cluster
->
valuestring
[
len
-
4
]);
}
else
{
continue
;
}
len
=
strlen
(
attribute
->
valuestring
);
if
(
len
>=
4
){
attr
=
rpc_get_u16
(
&
attribute
->
valuestring
[
len
-
4
]);
}
else
{
continue
;
}
kk_device_config_add
(
productCode
,
identity
->
valuestring
,
ep
,
clu
,
attr
,
reportFuncName
->
valuestring
,
controlFuncName
->
valuestring
);
}
kk_device_config_map_print
();
}
void
kk_device_config_map_load
(
const
char
*
devFile
,
const
char
*
productCode
)
{
int
len
;
int
bufferSize
;
int
fd
=
open
(
devFile
,
O_RDONLY
);
struct
stat
statbuff
;
if
(
kk_device_config_exist_check
(
productCode
)
==
true
){
UTIL_LOG_ERR
(
"devFile[%s] is already load!!!
\n
"
,
devFile
);
return
;
}
stat
(
devFile
,
&
statbuff
);
bufferSize
=
statbuff
.
st_size
+
128
;
uint8_t
*
buffer
=
(
uint8_t
*
)
malloc
(
bufferSize
);
memset
(
buffer
,
0
,
bufferSize
);
UTIL_LOG_INFO
(
"
\n
***************load device config map table***************
\n
"
);
if
(
fd
<
0
){
free
(
buffer
);
UTIL_LOG_ERR
(
"can not open %s,fd=%d!!!
\n
"
,
devFile
,
fd
);
return
;
}
len
=
read
(
fd
,
buffer
,
bufferSize
);
if
(
len
<
0
){
free
(
buffer
);
close
(
fd
);
UTIL_LOG_ERR
(
"can not read %s!!!
\n
"
,
devFile
);
return
;
}
cJSON
*
map
=
rpc_cJSON_Parse
(
buffer
);
if
(
map
==
NULL
){
UTIL_LOG_INFO
(
"len=%d,data:%s
\n
"
,
len
,
buffer
);
UTIL_LOG_INFO
(
"can not load dev map table!!!
\n
"
);
free
(
buffer
);
return
;
}
char
*
p
=
rpc_cJSON_Print
(
map
);
if
(
p
!=
NULL
){
emberAfCorePrintln
(
"device map table JSON:
\n
%s
\n
"
,
p
);
free
(
p
);
}
free
(
buffer
);
close
(
fd
);
kk_add_dev_config_map_table_to_list
(
map
,
productCode
);
rpc_cJSON_Delete
(
map
);
}
bool
kk_device_config_map_add
(
const
char
*
productCode
)
{
int
len
;
char
devfile
[
128
];
UTIL_LOG_INFO
(
"
\n
***************device config map add***************
\n
"
);
if
(
productCode
==
NULL
)
return
false
;
sprintf
(
devfile
,
KK_DEVICE_CONFIG_MAP_TABLE_FILE_PREFIX
,
productCode
);
emberAfCorePrintln
(
"devfile:%s
\n
"
,
devfile
);
kk_device_config_map_load
(
devfile
,
productCode
);
return
true
;
}
void
kk_device_config_map_print
(
void
)
{
int
cnt1
,
cnt2
=
1
;
kk_dev_config_map
*
ptr
=
dev_config_map
;
kk_dev_config_item
*
item
;
UTIL_LOG_INFO
(
"
\n
***************device config map list print***************
\n
"
);
while
(
ptr
!=
NULL
){
emberAfCorePrintln
(
"--------------------%d--------------------
\n
"
,
cnt1
++
);
emberAfCorePrintln
(
"productCode:%s
\n
"
,
ptr
->
productCode
);
item
=
&
ptr
->
item
;
cnt2
=
0
;
while
(
item
!=
NULL
){
emberAfCorePrintln
(
"**************%d**************
\n
"
,
cnt2
++
);
emberAfCorePrintln
(
"identity:%s
\n
"
,
item
->
identity
);
emberAfCorePrintln
(
"endpoint:%d
\n
"
,
item
->
endpoint
);
emberAfCorePrintln
(
"cluster:0x%04X
\n
"
,
item
->
cluster
);
emberAfCorePrintln
(
"attribute:0x%04X
\n
"
,
item
->
attribute
);
emberAfCorePrintln
(
"reportFunc:%s
\n
"
,
item
->
reportFuncName
);
emberAfCorePrintln
(
"controlFunc:%s
\n
"
,
item
->
controlFuncName
);
item
=
item
->
next
;
}
ptr
=
ptr
->
next
;
}
}
...
@@ -558,12 +779,32 @@ error_return:
...
@@ -558,12 +779,32 @@ error_return:
void
kk_rpc_report_attribute
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int
i
,
j
,
num
,
status
;
char
macString
[
19
]
=
{
0
};
sub_dev_node_t
*
node
=
NULL
;
char
*
pCode
;
int
res
=
0
;
UTIL_LOG_INFO
(
"
\n
********************kk rpc report attribute********************
\n
"
);
emberAfDebugPrint
(
"mac:"
);
emberAfDebugPrintln
(
",ep:%d,clu:0x%04X,attr:0x%04X,dataType=0x%02x,len=%d,data:"
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
);
emberAfDebugPrintBuffer
(
data
,
len
,
true
);
kk_device_config_item_report
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_device_manager.h
View file @
f87d8ac5
...
@@ -4,33 +4,22 @@
...
@@ -4,33 +4,22 @@
#include "kk_sub_tsl.h"
#include "kk_sub_tsl.h"
#include "kk_tsl_zigbee_map.h"
#include "kk_tsl_zigbee_map.h"
#include "kk_product_code.h"
#include "kk_product_code.h"
#include "kk_zb_com.h"
/****************** ******************************************************************
/****************** ******************************************************************
* File Name : kk_device_manager.h
* File Name : kk_device_manager.h
* Author : yjq
* Author : yjq
* data : 2020/09/01
* data : 2020/09/01
*************************************************************************************/
*************************************************************************************/
typedef
struct
kk_device_table_s
{
EmberEUI64
mac
;
EmberNodeId
nodeId
;
uint16_t
deviceId
;
uint16_t
identifyCnt
;
char
productCode
[
33
];
struct
kk_device_table_s
*
next
;
}
kk_device_table_s
;
#define KK_MAX_SUPPORT_ENDPOINT_NUMBER 32
#define KK_MAX_SUPPORT_ENDPOINT_NUMBER 32
#define KK_MAX_READ_MODLE_ID_COUNT 30
#define KK_MAX_READ_MODLE_ID_COUNT 30
#define KK_NETWORK_PARAMETER_TX_POWER 10
#define KK_NETWORK_PARAMETER_TX_POWER 10
#define KK_NETWORK_PARAMETER_CHANNEL 0x0B
#define KK_NETWORK_PARAMETER_CHANNEL 0x0B
void
kk_print_device_table
(
void
);
kk_device_table_s
*
kk_device_find_by_mac
(
EmberEUI64
mac
);
void
kk_device_table_add
(
EmberEUI64
mac
,
EmberNodeId
nodeId
,
const
char
*
productCode
,
uint16_t
deviceId
);
void
kk_device_table_delete
(
EmberEUI64
mac
);
void
kk_add_device_to_table
(
EmberEUI64
mac
,
EmberNodeId
nodeId
,
uint16_t
deviceId
);
void
kk_productCode_tick
();
void
kk_productCode_tick
();
void
kk_read_attr_response
(
EmberNodeId
nodeId
,
void
kk_read_attr_response
(
EmberNodeId
nodeId
,
...
@@ -47,8 +36,12 @@ int kk_permit_join(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* da
...
@@ -47,8 +36,12 @@ int kk_permit_join(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* da
void
kk_load_dev_map_table
(
void
);
void
kk_add_dev_map_table_to_list
(
cJSON
*
root
);
char
*
kk_match_productCode
(
const
char
*
modelId
);
bool
kk_device_config_map_add
(
const
char
*
productCode
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
View file @
f87d8ac5
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_zigbee_map.h"
const
char
*
kk_tsl_rpt_status_string
[]
=
{
const
char
*
kk_tsl_rpt_status_string
[]
=
{
"Success"
,
"Success"
,
...
@@ -8,60 +8,21 @@ const char *kk_tsl_rpt_status_string[] = {
...
@@ -8,60 +8,21 @@ const char *kk_tsl_rpt_status_string[] = {
"Invaild Len"
,
"Invaild Len"
,
"Invaild Type"
"Invaild Type"
};
};
static
cJSON
*
kk_check_identify
(
const
char
*
identify
,
cJSON
*
root
,
int
index
,
int
status
)
//todo: fix it
{
int
rev
=
0
,
startIdx2
=
0
,
startIdx1
=
0
;
char
*
Identify_str
;
char
tmp_Identity
[
64
]
=
{
0
};
rev
=
kk_tsl_utils_memtok
(
identify
,
'.'
,
2
,
&
startIdx2
);
if
(
!
rev
){
cJSON
*
str
=
NULL
;
cJSON
*
str_r
=
NULL
;
kk_tsl_utils_memtok
(
identify
,
'.'
,
1
,
&
startIdx1
);
str
=
rpc_cJSON_CreateObject
();
Identify_str
=
identify
+
1
+
startIdx2
;
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
identify
+
startIdx1
+
1
,
startIdx2
-
startIdx1
);
rpc_cJSON_AddNumberToObject
(
str
,
Identify_str
,
status
);
str_r
=
rpc_cJSON_CreateObject
();
rpc_cJSON_AddItemToObject
(
str_r
,
tmp_Identity
,
str
);
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
identify
,
startIdx1
);
rpc_cJSON_AddItemToObject
(
root
,
tmp_Identity
,
str_r
);
return
root
;
}
else
{
rev
=
kk_tsl_utils_memtok
(
identify
,
'.'
,
1
,
&
startIdx1
);
if
(
!
rev
){
cJSON
*
str
=
NULL
;
str
=
rpc_cJSON_CreateObject
();
Identify_str
=
identify
+
1
+
startIdx1
;
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
identify
,
startIdx1
);
rpc_cJSON_AddNumberToObject
(
str
,
Identify_str
,
status
);
rpc_cJSON_AddItemToObject
(
root
,
tmp_Identity
,
str
);
return
root
;
}
}
return
NULL
;
}
static
int
kk_tsl_report
(
EmberEUI64
mac
,
uint8_t
EP
,
int
status
,
uint16_t
clusterId
,
uint16_t
attributeId
)
static
int
kk_tsl_report
(
EmberEUI64
mac
,
uint8_t
EP
,
int
status
,
uint16_t
clusterId
,
uint16_t
attributeId
)
{
{
cJSON
*
root
,
*
root_tmp
;
cJSON
*
root
;
int
index
;
int
index
;
char
*
Identify
;
char
*
Identify
;
sub_dev_node_t
*
node
=
NULL
;
sub_dev_node_t
*
node
=
NULL
;
kk_device_table_s
*
dev
;
kk_device_table_s
*
dev
;
char
macString
[
RPC_EUI64_STRING_LENGTH
];
char
macString
[
RPC_EUI64_STRING_LENGTH
];
rpc_eui64ToString
(
mac
,
macString
);
rpc_eui64ToString
(
mac
,
macString
);
root
=
rpc_cJSON_CreateObject
();
root
=
rpc_cJSON_CreateObject
();
index
=
kk_get_tsl_index
(
EP
,
clusterId
,
attributeId
);
index
=
kk_get_tsl_index
(
EP
,
clusterId
,
attributeId
);
if
(
index
<
0
){
if
(
index
<
0
){
dev
=
kk_device_find_by_mac
(
mac
);
dev
=
kk_device_find_by_mac
(
mac
);
if
(
dev
!=
NULL
){
if
(
dev
!=
NULL
){
...
@@ -71,27 +32,14 @@ static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId
...
@@ -71,27 +32,14 @@ static int kk_tsl_report(EmberEUI64 mac,uint8_t EP,int status,uint16_t clusterId
if
(
index
<
0
){
if
(
index
<
0
){
return
tsl_rpt_err
;
return
tsl_rpt_err
;
}
else
{
}
else
{
root_tmp
=
kk_check_identify
(
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
root
,
index
,
status
);
if
(
root_tmp
!=
NULL
){
kk_rpc_report_status
(
root_tmp
,
mac
);
return
tsl_rpt_success
;
}
else
{
Identify
=
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
;
Identify
=
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
;
}
}
}
}
else
{
}
else
{
root_tmp
=
kk_check_identify
(
g_tsl_zigbee_map
[
index
].
Identity
,
root
,
index
,
status
);
if
(
root_tmp
!=
NULL
){
kk_rpc_report_status
(
root_tmp
,
mac
);
return
tsl_rpt_success
;
}
else
{
Identify
=
g_tsl_zigbee_map
[
index
].
Identity
;
Identify
=
g_tsl_zigbee_map
[
index
].
Identity
;
}
}
}
rpc_cJSON_AddNumberToObject
(
root
,
Identify
,
status
);
rpc_cJSON_AddNumberToObject
(
root
,
Identify
,
status
);
kk_
rpc_report_status
(
root
,
mac
);
kk_
msg_report_property
(
root
,
mac
);
return
tsl_rpt_success
;
return
tsl_rpt_success
;
}
}
...
@@ -122,7 +70,7 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
...
@@ -122,7 +70,7 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
g_tsl_zigbee_map
[
i
].
attributeId
==
attributeId
&&
g_tsl_zigbee_map
[
i
].
attributeId
==
attributeId
&&
g_tsl_zigbee_map
[
i
].
zigbee_report
!=
NULL
){
g_tsl_zigbee_map
[
i
].
zigbee_report
!=
NULL
){
status
=
g_tsl_zigbee_map
[
i
].
zigbee_report
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
status
=
g_tsl_zigbee_map
[
i
].
zigbee_report
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
emberAfDebugPrintln
(
"report status:%
d"
,
status
);
emberAfDebugPrintln
(
"report status:%
s"
,
kk_tsl_rpt_status_string
[
status
]
);
return
;
return
;
}
}
}
}
...
@@ -146,38 +94,6 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
...
@@ -146,38 +94,6 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
}
}
}
}
int
kk_tsl_report_global_Brightness
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
value
=
data
[
0
];
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_Brightness] value:%d
\n
"
,
value
);
printf
(
"[%s][%d]dataType:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
dataType
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
printf
(
"[%s][%d]len:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
len
);
if
(
len
==
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_tsl_report
(
eui64
,
EP
,
value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_global_RGB
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
value
=
data
[
0
];
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_RGB] value:%d
\n
"
,
value
);
printf
(
"[%s][%d]dataType:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
dataType
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
printf
(
"[%s][%d]len:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
len
);
if
(
len
==
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_tsl_report
(
eui64
,
EP
,
value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_global_onoff
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
int
kk_tsl_report_global_onoff
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
{
...
@@ -238,12 +154,158 @@ int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClu
...
@@ -238,12 +154,158 @@ int kk_tsl_report_windowCovering_position(EmberEUI64 eui64,uint8_t EP,EmberAfClu
int
kk_tsl_report_metering_summationDelivered
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint64_t
summation
;
emberAfAppPrintln
(
"[tsl report:meter(Smart Energy)] Summation Delivered~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT48U_ATTRIBUTE_TYPE
){
if
(
len
==
6
){
summation
=
KK_GET_U48
(
data
);
kk_tsl_report
(
eui64
,
EP
,
summation
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_ias_zoneStatus
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint64_t
Status
;
emberAfAppPrintln
(
"[tsl report:IAS] Zone Status~~~~~~~~~"
);
if
(
dataType
==
ZCL_BITMAP16_ATTRIBUTE_TYPE
){
if
(
len
==
2
){
Status
=
KK_GET_U16
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Status
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_global_Level
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
level
;
emberAfAppPrintln
(
"[tsl report:Gloabl] Level~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
level
=
data
[
0
];
kk_tsl_report
(
eui64
,
EP
,
level
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_temperature_measure
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int16_t
Value
;
emberAfAppPrintln
(
"[tsl report:temperature measurement] Measure Value~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT16S_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
Value
=
KK_GET_U16
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_illuminance_measure
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint16_t
Value
;
emberAfAppPrintln
(
"[tsl report:illuminance measurement] Measure Value~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT16U_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
Value
=
KK_GET_U16
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_local_temperature
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int16_t
Value
;
emberAfAppPrintln
(
"[tsl report:local temperature] Value~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT16S_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
Value
=
KK_GET_U16
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_OccupiedHeatingSetpoint
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int16_t
Value
;
emberAfAppPrintln
(
"[tsl report:Occupied Heating Setpoint] Value~~~~~~~~~"
);
if
(
dataType
==
ZCL_INT16S_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
Value
=
KK_GET_U16
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_Concentration
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
int32_t
Value
;
emberAfAppPrintln
(
"[tsl report:Formaldehyde] Value~~~~~~~~~"
);
if
(
dataType
==
ZCL_FLOAT_SINGLE_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
Value
=
KK_GET_U32
(
data
);
kk_tsl_report
(
eui64
,
EP
,
Value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_Formaldehyde
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
emberAfAppPrintln
(
"[tsl report:Formaldehyde] Value~~~~~~~~~"
);
return
kk_tsl_report_Concentration
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
}
int
kk_tsl_report_PM2_5
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
emberAfAppPrintln
(
"[tsl report:PM2.5] Value~~~~~~~~~"
);
return
kk_tsl_report_Concentration
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
}
int
kk_tsl_report_CO2
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
emberAfAppPrintln
(
"[tsl report:CO2] Value~~~~~~~~~"
);
return
kk_tsl_report_Concentration
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.h
View file @
f87d8ac5
#ifndef __KK_TSL_PROPERTY_REPORT_H
#ifndef __KK_TSL_PROPERTY_REPORT_H
#define __KK_TSL_PROPERTY_REPORT_H
#define __KK_TSL_PROPERTY_REPORT_H
#include "kk_test.h"
#include "kk_zb_com.h"
#include "kk_msg_report.h"
typedef
enum
{
typedef
enum
{
...
@@ -23,15 +24,22 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
...
@@ -23,15 +24,22 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
int
kk_tsl_report_global_onoff
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_global_onoff
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_windowCovering_mode
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_windowCovering_mode
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_windowCovering_position
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_windowCovering_position
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_global_Brightness
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_global_RGB
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_ias_zoneStatus
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_metering_summationDelivered
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_global_Level
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_temperature_measure
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_illuminance_measure
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_local_temperature
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_OccupiedHeatingSetpoint
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_Formaldehyde
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_PM2_5
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
int
kk_tsl_report_CO2
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
View file @
f87d8ac5
#include "kk_tsl_property_set.h"
#include "kk_tsl_property_set.h"
static
uint8_t
s_Red
=
0xff
;
static
uint8_t
s_Green
=
0xff
;
static
uint8_t
s_Blue
=
0xff
;
static
uint8_t
s_RgbCount
=
0
;
//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_topo_change_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
int
res
=
0
;
cJSON
*
changeTypeStr
=
NULL
;
uint8_t
eui64
[
EUI64_SIZE
]
=
{
0
};
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
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
;
rpc_get_mac
(
deviceCode
,
eui64
);
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
kk_zdo_leave_request
(
nodeId
,
false
,
false
);
item
=
item
->
next
;
}
}
}
return
rpc_cJSON_CreateNumber
(
res
);
error_return:
return
rpc_cJSON_CreateNull
();
}
int
kk_tsl_utils_memtok
(
_IN_
char
*
input
,
_IN_
char
*
delimiter
,
_IN_
int
index
,
_OU_
int
*
offset
)
{
int
item_index
=
0
;
int
count
=
0
;
int
input_len
=
0
;
if
(
input
==
NULL
||
offset
==
NULL
)
{
return
-
1
;
}
input_len
=
strlen
(
input
);
for
(
item_index
=
0
;
item_index
<
input_len
;
item_index
++
)
{
if
(
input
[
item_index
]
==
delimiter
&&
(
item_index
+
1
)
<
input_len
)
{
count
++
;
if
(
count
==
index
)
{
*
offset
=
item_index
;
return
0
;
}
}
}
return
-
1
;
}
static
int
kk_tsl_property_execute
(
jrpc_context
*
ctx
,
cJSON
*
propertyItem
,
cJSON
*
mac
,
int
index
,
int
findFlag
)
{
int
value
=
0
;
EmberEUI64
eui64
;
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
int
res
=
0
;
if
(
propertyItem
==
NULL
||
mac
==
NULL
){
return
-
1
;
}
if
(
propertyItem
->
type
!=
cJSON_Number
){
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
}
else
{
value
=
propertyItem
->
valueint
;
}
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
return
-
1
;
}
printf
(
"[%s][%d]g_tsl_zigbee_map[index].endpoint:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
g_tsl_zigbee_map
[
index
].
endpoint
);
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
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
);
else
res
=
-
1
;
printf
(
"[%s][%d]res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
res
;
}
cJSON
*
kk_tsl_property_operation
(
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
;
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
,
rev
=
0
;
int
res
=
0
;
rpc_nwk_info_s
info
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
EmberStatus
status
;
int
index
=
0
;
int
index
=
0
;
...
@@ -107,11 +15,8 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
...
@@ -107,11 +15,8 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
int
num
;
int
num
;
uint8_t
findFlag
=
0xff
;
uint8_t
findFlag
=
0xff
;
cJSON
*
propertyItem
=
NULL
;
cJSON
*
propertyItem
=
NULL
;
cJSON
*
propertyItem1
=
NULL
;
EmberEUI64
eui64
;
int
startIdx_1
=
0
;
EmberNodeId
nodeId
=
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
;
cJSON
*
propertyItem2
=
NULL
;
int
startIdx
=
0
;
char
tmp_Identity
[
64
]
=
{
0
};
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
UTIL_LOG_INFO
(
"
\n
********************kk tsl property operation********************
\n
"
);
if
(
params
==
NULL
){
if
(
params
==
NULL
){
...
@@ -127,263 +32,63 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
...
@@ -127,263 +32,63 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
num
=
kk_get_tsl_num
();
num
=
kk_get_tsl_num
();
for
(
index
=
0
;
index
<
num
;
index
++
){
for
(
index
=
0
;
index
<
num
;
index
++
){
rev
=
kk_tsl_utils_memtok
(
g_tsl_zigbee_map
[
index
].
Identity
,
'.'
,
2
,
&
startIdx
);
if
(
!
rev
){
kk_tsl_utils_memtok
(
g_tsl_zigbee_map
[
index
].
Identity
,
'.'
,
1
,
&
startIdx_1
);
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map
[
index
].
Identity
,
startIdx_1
);
propertyItem2
=
rpc_cJSON_GetObjectItem
(
params
,
tmp_Identity
);
if
(
propertyItem2
!=
NULL
){
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map
[
index
].
Identity
+
startIdx_1
+
1
,
startIdx
-
startIdx_1
);
propertyItem1
=
rpc_cJSON_GetObjectItem
(
propertyItem2
,
tmp_Identity
);
if
(
propertyItem1
!=
NULL
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
propertyItem1
,
g_tsl_zigbee_map
[
index
].
Identity
+
startIdx
+
1
);
if
(
propertyItem
!=
NULL
){
findFlag
=
1
;
}
//break;
}
}
}
else
{
rev
=
kk_tsl_utils_memtok
(
g_tsl_zigbee_map
[
index
].
Identity
,
'.'
,
1
,
&
startIdx
);
if
(
!
rev
){
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map
[
index
].
Identity
,
startIdx
);
propertyItem1
=
rpc_cJSON_GetObjectItem
(
params
,
tmp_Identity
);
if
(
propertyItem1
!=
NULL
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
propertyItem1
,
g_tsl_zigbee_map
[
index
].
Identity
+
startIdx
+
1
);
if
(
propertyItem
!=
NULL
){
findFlag
=
1
;
//break;
}
}
}
else
{
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map
[
index
].
Identity
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map
[
index
].
Identity
);
if
(
propertyItem
!=
NULL
){
if
(
propertyItem
!=
NULL
){
findFlag
=
1
;
findFlag
=
1
;
//break;
break
;
}
}
}
if
(
findFlag
==
1
){
res
=
kk_tsl_property_execute
(
ctx
,
propertyItem
,
mac
,
index
,
findFlag
);
if
(
res
<
0
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
findFlag
=
0
;
}
}
}
}
}
if
(
findFlag
==
0xff
){
if
(
findFlag
==
0xff
){
num
=
kk_get_tsl_glb_num
();
num
=
kk_get_tsl_glb_num
();
for
(
index
=
0
;
index
<
num
;
index
++
){
for
(
index
=
0
;
index
<
num
;
index
++
){
rev
=
kk_tsl_utils_memtok
(
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
'.'
,
2
,
&
startIdx
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
if
(
!
rev
){
kk_tsl_utils_memtok
(
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
'.'
,
1
,
&
startIdx_1
);
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
startIdx_1
);
propertyItem2
=
rpc_cJSON_GetObjectItem
(
params
,
tmp_Identity
);
if
(
propertyItem2
!=
NULL
){
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
+
startIdx_1
+
1
,
startIdx
-
startIdx_1
);
propertyItem1
=
rpc_cJSON_GetObjectItem
(
propertyItem2
,
tmp_Identity
);
if
(
propertyItem1
!=
NULL
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
propertyItem1
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
+
startIdx
+
1
);
if
(
propertyItem
!=
NULL
){
if
(
propertyItem
!=
NULL
){
findFlag
=
2
;
findFlag
=
2
;
break
;
}
}
}
}
}
}
}
if
(
findFlag
!=
0xff
)
else
{
{
rev
=
kk_tsl_utils_memtok
(
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
'.'
,
1
,
&
startIdx
);
int
value
=
0
;
if
(
!
rev
){
if
(
propertyItem
->
type
!=
cJSON_Number
){
memset
(
tmp_Identity
,
0x0
,
sizeof
(
tmp_Identity
));
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
memcpy
(
tmp_Identity
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
,
startIdx
);
}
else
{
propertyItem1
=
rpc_cJSON_GetObjectItem
(
params
,
tmp_Identity
);
value
=
propertyItem
->
valueint
;
if
(
propertyItem1
!=
NULL
){
propertyItem
=
rpc_cJSON_GetObjectItem
(
propertyItem1
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
+
startIdx
+
1
);
if
(
propertyItem
!=
NULL
){
findFlag
=
2
;
}
}
}
}
if
(
rpc_get_mac
(
mac
->
valuestring
,
eui64
)
==
false
){
else
{
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
g_tsl_zigbee_map_glb
[
index
].
map
.
Identity
);
if
(
propertyItem
!=
NULL
){
findFlag
=
2
;
}
}
}
if
(
findFlag
==
2
){
res
=
kk_tsl_property_execute
(
ctx
,
propertyItem
,
mac
,
index
,
findFlag
);
if
(
res
<
0
){
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
;
}
}
else
{
nodeId
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
findFlag
=
0
;
}
}
}
}
return
rpc_cJSON_CreateNumber
(
res
);
}
error_return:
return
rpc_cJSON_CreateNull
();
}
int
kk_tsl_set_colorlight_ModeType
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
value
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_ModeType],value=0x%02x"
,
value
);
return
0
;
}
int
kk_tsl_set_colorlight_Mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
EmberStatus
status
=
0
;
int
value
=
*
(
uint8_t
*
)
data
;
emberAfDebugPrint
(
"mac:"
);
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_Mode],value=0x%02x"
,
value
);
emberAfPrintBigEndianEui64
(
eui64
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
emberAfDebugPrintln
(
",node:0x%04X"
,
nodeId
);
if
(
ctx
)
if
(
findFlag
==
1
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
res
=
g_tsl_zigbee_map
[
index
].
zigbee_set
(
ctx
,
nodeId
,
g_tsl_zigbee_map
[
index
].
endpoint
,
&
value
);
goto
error_return
;
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
);
status
=
zclColorControlLoopSet
(
node
,
ep
,
value
,
0
,
0
,
1
,
55
,
0
,
0
,
0
);
return
status
;
error_return:
return
-
1
;
}
int
kk_tsl_set_colorlight_Brightness
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
if
(
res
<
0
)
{
{
int
value
=
*
(
uint8_t
*
)
data
;
EmberStatus
status
=
0
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_Brightness],value=0x%02x"
,
value
);
if
(
node
==
EMBER_AF_PLUGIN_DEVICE_TABLE_NULL_NODE_ID
){
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 0
else
{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return
rpc_cJSON_CreateNumber
(
res
);
value |= BIT(1);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
status = zclGWrite(node,1,ep,false,0x08,
0,
ZCL_BITMAP8_ATTRIBUTE_TYPE,
1,
value,
true);
emberAfAppPrintln("status=0x%02x",status);
#else
status
=
zclLevel_MoveToLevel
(
node
,
ep
,
value
,
0
,
NULL
,
NULL
);
#endif
return
status
;
error_return:
return
-
1
;
}
int
kk_tsl_set_colorlight_WhiteBrightness
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
value
=
*
(
uint8_t
*
)
data
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_WhiteBrightness],value=0x%02x"
,
value
);
return
0
;
}
int
kk_tsl_set_colorlight_RGB_red
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
value
=
*
(
uint8_t
*
)
data
;
EmberStatus
status
=
0
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_RGB_red],value=0x%02x"
,
value
);
s_Red
=
value
;
s_RgbCount
++
;
if
(
s_RgbCount
>=
3
){
status
=
zclColorControlMovetohueandsat
(
node
,
ep
,
s_Red
,
s_Green
,
s_Blue
,
0
,
0
,
0
);
s_RgbCount
=
0
;
}
return
status
;
}
int
kk_tsl_set_colorlight_RGB_green
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
value
=
*
(
uint8_t
*
)
data
;
EmberStatus
status
=
0
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_RGB_green],value=0x%02x"
,
value
);
s_Green
=
value
;
s_RgbCount
++
;
if
(
s_RgbCount
>=
3
){
status
=
zclColorControlMovetohueandsat
(
node
,
ep
,
s_Red
,
s_Green
,
s_Blue
,
0
,
0
,
0
);
s_RgbCount
=
0
;
}
}
return
status
;
}
int
kk_tsl_set_colorlight_RGB_blue
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
int
value
=
*
(
uint8_t
*
)
data
;
EmberStatus
status
=
0
;
emberAfAppPrintln
(
"[tsl set:kk_tsl_set_colorloght_RGB_blue],value=0x%02x"
,
value
);
s_Blue
=
value
;
s_RgbCount
++
;
if
(
s_RgbCount
>=
3
){
status
=
zclColorControlMovetohueandsat
(
node
,
ep
,
s_Red
,
s_Green
,
s_Blue
,
0
,
0
,
0
);
s_RgbCount
=
0
;
}
}
return
status
;
}
int
kk_tsl_set_colorlight_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 = zclGWrite(node,1,1,false,0xFCC0,0,ZCL_BITMAP8_ATTRIBUTE_TYPE,1,Onoff,true);
status
=
zclOnOff_On
(
node
,
ep
);
emberAfAppPrintln
(
"On"
);
}
else
if
(
Onoff
==
0
){
//status = zclGWrite(node,1,1,false,0xFCC0,0,ZCL_BITMAP8_ATTRIBUTE_TYPE,1,Onoff,true);
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:
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_gloabl_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
{
uint8_t
Onoff
=
0
;
uint8_t
Onoff
=
0
;
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.h
View file @
f87d8ac5
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
#define __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H
#include "kk_test.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
);
cJSON
*
kk_tsl_property_operation
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
...
@@ -13,14 +11,11 @@ int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,
...
@@ -13,14 +11,11 @@ int kk_tsl_set_windowCovering_OperationMode(jrpc_context * ctx,EmberNodeId node,
int
kk_tsl_set_windowCovering_mode
(
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_position
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_OnOff
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_ModeType
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
#define RPC_KK_TEST_FUNCTION_TABLE \
int
kk_tsl_set_colorlight_Mode
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
}
\
int
kk_tsl_set_colorlight_Brightness
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_WhiteBrightness
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_RGB_red
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_RGB_green
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
int
kk_tsl_set_colorlight_RGB_blue
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.c
View file @
f87d8ac5
#include "kk_zigbee_api.h"
#include "kk_zigbee_api.h"
kk_rpc_set_api_s
kk_rpc_set_api
[]
=
KK_RPC_SET_FUNCTION_TABLE
;
kk_rpc_report_api_s
kk_rpc_report_api
[]
=
KK_RPC_REPORT_FUNCTION_TABLE
;
void
kk_rpc_test
(
void
)
{
emberAfAppPrintln
(
"!!!!!!!!!!!kk_rpc_test!!!!!!!!!!!!!!"
);
}
uint8_t
kk_get_rpc_set_api_size
(
void
)
{
return
sizeof
(
kk_rpc_set_api
)
/
sizeof
(
kk_rpc_set_api_s
);
}
uint8_t
kk_get_rpc_report_api_size
(
void
)
{
return
sizeof
(
kk_rpc_report_api
)
/
sizeof
(
kk_rpc_report_api_s
);
}
// network leave
// network leave
EmberStatus
kk_network_leave
(
void
)
EmberStatus
kk_network_leave
(
void
)
{
{
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
View file @
f87d8ac5
...
@@ -2,6 +2,41 @@
...
@@ -2,6 +2,41 @@
#define __KK_ZIGBEE_API_H
#define __KK_ZIGBEE_API_H
#include "kk_test.h"
#include "kk_test.h"
typedef
int
(
*
kk_rpc_set
)(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
);
typedef
int
(
*
kk_rpc_report
)(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
);
typedef
struct
{
const
char
*
name
;
kk_rpc_set
set
;
}
kk_rpc_set_api_s
;
typedef
struct
{
const
char
*
name
;
kk_rpc_report
report
;
}
kk_rpc_report_api_s
;
void
kk_rpc_test
(
void
);
#define KK_RPC_SET_FUNCTION_TABLE {\
{
"zclOnOff_On"
,
zclOnOff_On
},
\
{
"zclOnOff_Off"
,
zclOnOff_Off
}
\
}
#define KK_RPC_REPORT_FUNCTION_TABLE {\
{
"kk_tsl_report_global_onoff"
,
kk_tsl_report_global_onoff
},
\
{
"kk_tsl_report_global_onoff"
,
kk_tsl_report_global_onoff
}
\
}
kk_rpc_set_api_s
kk_rpc_set_api
[];
kk_rpc_report_api_s
kk_rpc_report_api
[];
uint8_t
kk_get_rpc_set_api_size
(
void
);
uint8_t
kk_get_rpc_report_api_size
(
void
);
EmberStatus
kk_network_leave
(
void
);
EmberStatus
kk_network_leave
(
void
);
EmberStatus
kk_network_form
(
bool
centralized
,
EmberPanId
panId
,
int8_t
radioTxPower
,
uint8_t
channel
);
EmberStatus
kk_network_form
(
bool
centralized
,
EmberPanId
panId
,
int8_t
radioTxPower
,
uint8_t
channel
);
void
kk_print_network_info
(
void
);
void
kk_print_network_info
(
void
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
View file @
f87d8ac5
...
@@ -95,13 +95,7 @@ void kk_rpc_reportLeftDevices(EmberEUI64 mac)
...
@@ -95,13 +95,7 @@ void kk_rpc_reportLeftDevices(EmberEUI64 mac)
}
}
int
kk_sendData2CCU
(
char
*
data
,
int
len
){
if
(
strcmp
(
GW2CCU_PROTOCOL
,
"tcp"
)
==
0
){
kk_tcp_client_send
(
data
,
len
);
}
else
{
kk_ipc_send
(
IPC_PLAT2MID
,
data
,
len
);
}
}
void
kk_rpc_reportDevices
(
EmberEUI64
mac
,
const
char
*
productCode
)
void
kk_rpc_reportDevices
(
EmberEUI64
mac
,
const
char
*
productCode
)
{
{
...
...
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
View file @
f87d8ac5
...
@@ -10,11 +10,13 @@
...
@@ -10,11 +10,13 @@
#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"
#include "kk_msg_report.h"
#include "kk_device_table_db.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_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
...
@@ -27,8 +29,6 @@
...
@@ -27,8 +29,6 @@
#define TEST_PRODUCT_CODE "24"
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
#define GW2CCU_PROTOCOL "tcp"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
...
@@ -47,8 +47,7 @@ int kk_sendData2CCU(char* data, int len);
...
@@ -47,8 +47,7 @@ int kk_sendData2CCU(char* data, int len);
#define RPC_KK_TEST_FUNCTION_TABLE \
#define RPC_KK_TEST_FUNCTION_TABLE \
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
},
\
{(
rpc_function
*
)
kk_tsl_property_operation
,
"/thing/service/property/set"
},
\
{(
rpc_function
*
)
kk_tsl_property_operation
,
KK_READ_ATTRIBUTE_METHOD
},
\
{(
rpc_function
*
)
kk_tsl_property_operation
,
KK_READ_ATTRIBUTE_METHOD
}
{(
rpc_function
*
)
kk_topo_change_operation
,
KK_DEVICE_TOPO_CHANGE_TYPE
}
...
@@ -56,11 +55,6 @@ int kk_sendData2CCU(char* data, int len);
...
@@ -56,11 +55,6 @@ int kk_sendData2CCU(char* data, int len);
enum
{
WC_normal_dir
=
0
,
//"正转"
WC_reversed_dir
=
1
,
//"反转"
WC_calibration_mode
=
2
,
//"校验"
}
windowCoveringMode
;
...
...
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
View file @
f87d8ac5
...
@@ -224,6 +224,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
...
@@ -224,6 +224,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
void
_cb
(
void
*
data
,
int
len
,
char
*
chlmark
){
void
_cb
(
void
*
data
,
int
len
,
char
*
chlmark
){
if
(
data
!=
NULL
){
if
(
data
!=
NULL
){
printf
(
"plat_cb: %s RECEIVED
\r\n
"
,
data
);
printf
(
"plat_cb: %s RECEIVED
\r\n
"
,
data
);
...
@@ -237,7 +238,7 @@ void _cb(void* data, int len, char* chlmark){
...
@@ -237,7 +238,7 @@ void _cb(void* data, int len, char* chlmark){
if
(
info
!=
NULL
&&
strstr
(
rpc_cJSON_GetObjectItem
(
info
,
"msgType"
)
->
valuestring
,
KK_THING_OTA_DEVICE_UPGRADE
)
!=
NULL
){
if
(
info
!=
NULL
&&
strstr
(
rpc_cJSON_GetObjectItem
(
info
,
"msgType"
)
->
valuestring
,
KK_THING_OTA_DEVICE_UPGRADE
)
!=
NULL
){
kk_ota_process
(
root
);
//
kk_ota_process(root);
}
else
{
}
else
{
eval_request
(
&
my_server
,
root
);
eval_request
(
&
my_server
,
root
);
}
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/yjq_ezsp.c
View file @
f87d8ac5
...
@@ -86,10 +86,7 @@ void kk_read_ncp_configuration_without_memory_allocation(void)
...
@@ -86,10 +86,7 @@ void kk_read_ncp_configuration_without_memory_allocation(void)
}
}
extern
void
kk_print_device_table
(
void
);
//extern void kk_device_table_add(EmberEUI64 mac,uint8_t epNum,uint8_t* epVal,char *productCode);
extern
void
kk_device_table_delete
(
EmberEUI64
mac
);
extern
bool
kk_device_find_by_mac11111
(
EmberEUI64
mac
);
extern
void
kk_print_network_info
(
void
);
extern
void
kk_print_network_info
(
void
);
void
kk_message_process
(
char
*
messageString
)
void
kk_message_process
(
char
*
messageString
)
...
@@ -102,35 +99,6 @@ void kk_message_process(char *messageString)
...
@@ -102,35 +99,6 @@ void kk_message_process(char *messageString)
emberAfAppPrint
(
"set txpower = 10
\r\n
"
);
emberAfAppPrint
(
"set txpower = 10
\r\n
"
);
setTxPower
(
10
);
setTxPower
(
10
);
}
}
if
(
MEMCOMPARE
(
messageString
,
"AT+123
\r\n
"
,
len
)
==
0
){
kk_print_device_table
();
}
if
(
MEMCOMPARE
(
messageString
,
"AT+KKTEST1
\r\n
"
,
len
)
==
0
){
uint8_t
ep
[
2
]
=
{
1
,
242
};
static
uint8_t
aaa
=
0x00
;
EmberEUI64
mac
=
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
};
mac
[
0
]
=++
aaa
;
//kk_device_table_add(mac,2,ep,"24");
}
if
(
MEMCOMPARE
(
messageString
,
"AT+456
\r\n
"
,
len
)
==
0
){
uint8_t
ep
[
2
]
=
{
1
,
242
};
static
uint8_t
aaa
=
0x01
;
EmberEUI64
mac
=
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
};
mac
[
0
]
=
aaa
++%
5
;
kk_device_table_delete
(
mac
);
}
if
(
MEMCOMPARE
(
messageString
,
"AT+678
\r\n
"
,
len
)
==
0
){
uint8_t
ep
[
2
]
=
{
1
,
242
};
EmberEUI64
mac
=
{
0x01
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
};
if
(
kk_device_find_by_mac11111
(
mac
)
==
true
){
emberAfAppPrint
(
" Exist!!!
\r\n
"
);
}
else
{
emberAfAppPrint
(
" not Exist!!!
\r\n
"
);
}
}
if
(
MEMCOMPARE
(
messageString
,
"AT+GETINFO
\r\n
"
,
len
)
==
0
){
if
(
MEMCOMPARE
(
messageString
,
"AT+GETINFO
\r\n
"
,
len
)
==
0
){
kk_print_network_info
();
kk_print_network_info
();
...
...
platform/zigbee/protocol/zigbee/app/framework/plugin/device-table/device-table.c
View file @
f87d8ac5
...
@@ -407,7 +407,7 @@ void emberAfPluginDeviceTableStackStatusCallback(EmberStatus status)
...
@@ -407,7 +407,7 @@ void emberAfPluginDeviceTableStackStatusCallback(EmberStatus status)
emberAfCorePrintln
(
"DeviceTable: Clear State"
);
emberAfCorePrintln
(
"DeviceTable: Clear State"
);
emberAfDeviceTableClear
();
emberAfDeviceTableClear
();
kk_device_table_clear
();
//
kk_device_table_clear();
}
}
}
}
...
...
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