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
784fe296
Commit
784fe296
authored
Aug 12, 2020
by
whmaizmy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加zigbee端物模型处理
【提交人】陈伟灿
parent
47872e3f
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1390 additions
and
240 deletions
+1390
-240
platform/zigbee/app/builder/Z3GatewayHost/Makefile
platform/zigbee/app/builder/Z3GatewayHost/Makefile
+3
-1
platform/zigbee/app/builder/Z3GatewayHost/a1h88DsZIaY.json
platform/zigbee/app/builder/Z3GatewayHost/a1h88DsZIaY.json
+222
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.c
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.c
+166
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.h
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.h
+14
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
+367
-239
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
+1
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_common.h
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_common.h
+156
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.c
...form/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.c
+41
-0
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.h
...form/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.h
+19
-0
platform/zigbee/app/builder/Z3GatewayHost/klist.h
platform/zigbee/app/builder/Z3GatewayHost/klist.h
+401
-0
platform/zigbee/app/builder/Z3GatewayHost/libkk_tsl.a
platform/zigbee/app/builder/Z3GatewayHost/libkk_tsl.a
+0
-0
No files found.
platform/zigbee/app/builder/Z3GatewayHost/Makefile
View file @
784fe296
...
@@ -294,6 +294,8 @@ APPLICATION_FILES= \
...
@@ -294,6 +294,8 @@ APPLICATION_FILES= \
./jsonrpc/rpccJSON.c
\
./jsonrpc/rpccJSON.c
\
./yjq_ezsp.c
\
./yjq_ezsp.c
\
./kk_test.c
\
./kk_test.c
\
./kk_sub_tsl.c
\
./kk_tsl_zigbee_map.c
\
./rpc_api/src/rpc_common.c
\
./rpc_api/src/rpc_common.c
\
./rpc_api/src/rpc_onoff.c
\
./rpc_api/src/rpc_onoff.c
\
./rpc_api/src/rpc_global_cmd.c
\
./rpc_api/src/rpc_global_cmd.c
\
...
@@ -375,7 +377,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
...
@@ -375,7 +377,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
@
echo
-e
'\n$@ build success'
@
echo
-e
'\n$@ build success'
else
else
$(TARGET_FILE)
:
$(APPLICATION_OBJECTS) $(LIBRARIES)
$(TARGET_FILE)
:
$(APPLICATION_OBJECTS) $(LIBRARIES)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-static
-lapi_com
-static
-lnanomsg
-lanl
-pthread
-static
-lev
-ltinfo
-o
$(TARGET_FILE)
$(LD)
$^
$(LINKER_FLAGS)
-lm
-L
.
-static
-lapi_com
-static
-lnanomsg
-l
kk_tsl
-l
anl
-pthread
-static
-lev
-ltinfo
-o
$(TARGET_FILE)
@
echo
-e
'\n$@ build success'
@
echo
-e
'\n$@ build success'
endif
endif
...
...
platform/zigbee/app/builder/Z3GatewayHost/a1h88DsZIaY.json
0 → 100644
View file @
784fe296
{
"schema"
:
"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json"
,
"profile"
:{
"productKey"
:
"a1h88DsZIaY"
},
"services"
:[
{
"outputData"
:[
],
"identifier"
:
"set"
,
"inputData"
:[
{
"identifier"
:
"LightStatus"
,
"dataType"
:{
"specs"
:{
"0"
:
"关闭"
,
"1"
:
"打开"
},
"type"
:
"bool"
},
"name"
:
"工作状态"
},
{
"identifier"
:
"LightAdjustLevel"
,
"dataType"
:{
"specs"
:{
"unit"
:
"%"
,
"min"
:
"0"
,
"max"
:
"100"
,
"step"
:
"1"
},
"type"
:
"int"
},
"name"
:
"调光等级"
},
{
"identifier"
:
"LightAlias"
,
"dataType"
:{
"specs"
:{
"length"
:
"32"
},
"type"
:
"text"
},
"name"
:
"别名"
}
],
"method"
:
"thing.service.property.set"
,
"name"
:
"set"
,
"required"
:
true
,
"callType"
:
"async"
,
"desc"
:
"属性设置"
},
{
"outputData"
:[
{
"identifier"
:
"LightStatus"
,
"dataType"
:{
"specs"
:{
"0"
:
"关闭"
,
"1"
:
"打开"
},
"type"
:
"bool"
},
"name"
:
"工作状态"
},
{
"identifier"
:
"LightAdjustLevel"
,
"dataType"
:{
"specs"
:{
"unit"
:
"%"
,
"min"
:
"0"
,
"max"
:
"100"
,
"step"
:
"1"
},
"type"
:
"int"
},
"name"
:
"调光等级"
},
{
"identifier"
:
"LightAlias"
,
"dataType"
:{
"specs"
:{
"length"
:
"32"
},
"type"
:
"text"
},
"name"
:
"别名"
}
],
"identifier"
:
"get"
,
"inputData"
:[
"LightStatus"
,
"LightAdjustLevel"
,
"LightAlias"
],
"method"
:
"thing.service.property.get"
,
"name"
:
"get"
,
"required"
:
true
,
"callType"
:
"async"
,
"desc"
:
"属性获取"
}
],
"properties"
:[
{
"identifier"
:
"LightStatus"
,
"dataType"
:{
"specs"
:{
"0"
:
"关闭"
,
"1"
:
"打开"
},
"type"
:
"bool"
},
"name"
:
"工作状态"
,
"accessMode"
:
"rw"
,
"required"
:
false
},
{
"identifier"
:
"LightAdjustLevel"
,
"dataType"
:{
"specs"
:{
"unit"
:
"%"
,
"min"
:
"0"
,
"max"
:
"100"
,
"step"
:
"1"
},
"type"
:
"int"
},
"name"
:
"调光等级"
,
"accessMode"
:
"rw"
,
"required"
:
false
,
"desc"
:
"调光等级采用百分比表示"
},
{
"identifier"
:
"LightAlias"
,
"dataType"
:{
"specs"
:{
"length"
:
"32"
},
"type"
:
"text"
},
"name"
:
"别名"
,
"accessMode"
:
"rw"
,
"required"
:
false
}
],
"events"
:[
{
"outputData"
:[
{
"identifier"
:
"LightStatus"
,
"dataType"
:{
"specs"
:{
"0"
:
"关闭"
,
"1"
:
"打开"
},
"type"
:
"bool"
},
"name"
:
"工作状态"
},
{
"identifier"
:
"LightAdjustLevel"
,
"dataType"
:{
"specs"
:{
"unit"
:
"%"
,
"min"
:
"0"
,
"max"
:
"100"
,
"step"
:
"1"
},
"type"
:
"int"
},
"name"
:
"调光等级"
},
{
"identifier"
:
"LightAlias"
,
"dataType"
:{
"specs"
:{
"length"
:
"32"
},
"type"
:
"text"
},
"name"
:
"别名"
}
],
"identifier"
:
"post"
,
"method"
:
"thing.event.property.post"
,
"name"
:
"post"
,
"type"
:
"info"
,
"required"
:
true
,
"desc"
:
"属性上报"
},
{
"outputData"
:[
{
"identifier"
:
"ErrorCode"
,
"dataType"
:{
"specs"
:{
"0"
:
"恢复正常"
},
"type"
:
"enum"
},
"name"
:
"故障代码"
}
],
"identifier"
:
"Error"
,
"method"
:
"thing.event.Error.post"
,
"name"
:
"故障上报"
,
"type"
:
"alert"
,
"required"
:
false
},
{
"outputData"
:[
],
"identifier"
:
"TamperAlarm"
,
"method"
:
"thing.event.TamperAlarm.post"
,
"name"
:
"防撬报警"
,
"type"
:
"alert"
,
"required"
:
false
}
]
}
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.c
0 → 100644
View file @
784fe296
#include "kk_sub_tsl.h"
typedef
struct
{
void
*
mutex
;
int
sub_devid
;
struct
list_head
dev_list
;
}
kk_sub_dev_ctx_t
;
static
kk_sub_dev_ctx_t
g_sub_dev_mgr
=
{
0
};
static
kk_sub_dev_ctx_t
*
_sub_dev_get_ctx
(
void
)
{
return
&
g_sub_dev_mgr
;
}
static
int
_sub_tsl_next_devid
(
void
)
{
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
return
ctx
->
sub_devid
++
;
}
static
void
_sub_dev_mutex_lock
(
void
)
{
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
if
(
ctx
->
mutex
)
{
kk_MutexLock
(
ctx
->
mutex
);
}
}
static
void
_sub_dev_mutex_unlock
(
void
)
{
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
if
(
ctx
->
mutex
)
{
kk_MutexUnLock
(
ctx
->
mutex
);
}
}
int
kk_tsl_init
(
void
)
{
char
*
tsl_str
=
NULL
;
int
res
=
0
;
kk_tsl_t
*
dev_shadow
;
sub_dev_node_t
*
node
=
NULL
;
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
ctx
->
mutex
=
kk_MutexCreate
();
if
(
ctx
->
mutex
==
NULL
)
{
return
FAIL_RETURN
;
}
ctx
->
sub_devid
=
1
;
INIT_LIST_HEAD
(
&
ctx
->
dev_list
);
kk_sub_tsl_add
(
"112233445566"
,
"a1h88DsZIaY"
);
usleep
(
1000000
);
kk_test
();
return
SUCCESS_RETURN
;
}
int
kk_sub_tsl_add
(
const
char
*
device_mac
,
const
char
*
product_type
)
{
sub_dev_node_t
*
node
=
NULL
;
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
char
name
[
TSL_PATH_MAXLEN
]
=
{
0
};
char
*
tsl_str
=
NULL
;
int
res
=
0
;
if
(
device_mac
==
NULL
||
product_type
==
NULL
)
{
return
INVALID_PARAMETER
;
}
node
=
malloc
(
sizeof
(
sub_dev_node_t
));
if
(
node
==
NULL
)
{
return
MEMORY_NOT_ENOUGH
;
}
memset
(
node
->
product_type
,
0x0
,
sizeof
(
node
->
product_type
));
memcpy
(
node
->
device_mac
,
device_mac
,
strlen
(
device_mac
));
memcpy
(
node
->
product_type
,
product_type
,
strlen
(
product_type
));
node
->
devid
=
_sub_tsl_next_devid
();
node
->
dev_shadow
=
NULL
;
memset
(
name
,
0x0
,
sizeof
(
name
));
sprintf
(
name
,
"%s.json"
,
product_type
);
tsl_str
=
kk_load_json
(
name
);
if
(
tsl_str
!=
NULL
)
{
res
=
kk_tsl_create
(
tsl_str
,
strlen
(
tsl_str
),
&
node
->
dev_shadow
);
free
(
tsl_str
);
if
(
res
!=
0
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
FAIL_RETURN
;
}
}
INIT_LIST_HEAD
(
&
node
->
linked_list
);
list_add_tail
(
&
node
->
linked_list
,
&
ctx
->
dev_list
);
return
SUCCESS_RETURN
;
}
int
kk_sub_tsl_get_device_by_mac
(
_IN_
char
device_mac
[
DEVICE_MAC_MAXLEN
],
_OU_
sub_dev_node_t
**
node
)
{
kk_sub_dev_ctx_t
*
ctx
=
_sub_dev_get_ctx
();
sub_dev_node_t
*
search_node
=
NULL
;
list_for_each_entry
(
search_node
,
&
ctx
->
dev_list
,
linked_list
,
sub_dev_node_t
)
{
if
((
strlen
(
search_node
->
device_mac
)
==
strlen
(
device_mac
))
&&
(
memcmp
(
search_node
->
device_mac
,
device_mac
,
strlen
(
device_mac
))
==
0
))
{
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if
(
node
)
{
*
node
=
search_node
;
}
return
SUCCESS_RETURN
;
}
}
printf
(
"Device Not Found, device_mac: %s
\n
"
,
device_mac
);
return
FAIL_RETURN
;
}
int
kk_sub_tsl_get_Identifier_by_index
(
_IN_
char
device_mac
[
DEVICE_MAC_MAXLEN
],
int
idx
,
_OU_
char
**
identifiers
)
{
int
res
=
0
;
sub_dev_node_t
*
node
=
NULL
;
int
index
=
0
;
kk_tsl_t
*
dev_shadow
=
NULL
;
int
propertiesNum
=
0
;
kk_tsl_data_t
*
pProperty
=
NULL
;
char
*
identifier
=
NULL
;
res
=
kk_sub_tsl_get_device_by_mac
(
device_mac
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
dev_shadow
=
node
->
dev_shadow
;
propertiesNum
=
dev_shadow
->
property_number
;
if
(
idx
>=
propertiesNum
){
return
FAIL_RETURN
;
}
pProperty
=
(
kk_tsl_data_t
*
)(
dev_shadow
->
properties
+
idx
);
identifier
=
(
char
*
)
malloc
(
strlen
(
pProperty
->
identifier
)
+
1
);
memset
(
identifier
,
0x0
,
strlen
(
pProperty
->
identifier
)
+
1
);
memcpy
(
identifier
,
pProperty
->
identifier
,
strlen
(
pProperty
->
identifier
));
*
identifiers
=
identifier
;
return
SUCCESS_RETURN
;
}
int
kk_sub_tsl_get_Identifiers_Num
(
_IN_
char
device_mac
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
num
)
{
int
res
=
0
;
sub_dev_node_t
*
node
=
NULL
;
kk_tsl_t
*
dev_shadow
=
NULL
;
res
=
kk_sub_tsl_get_device_by_mac
(
device_mac
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
dev_shadow
=
node
->
dev_shadow
;
*
num
=
dev_shadow
->
property_number
;
return
SUCCESS_RETURN
;
}
const
char
DM_MSG_REQUEST
[]
=
"{
\"
LightStatus123
\"
:
\"
1
\"
}"
;
int
kk_test
(
void
)
{
int
num
;
int
i
=
0
;
char
*
identifier
=
NULL
;
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_test_fuc
(
"112233445566"
,
DM_MSG_REQUEST
);
return
0
;
}
platform/zigbee/app/builder/Z3GatewayHost/kk_sub_tsl.h
0 → 100644
View file @
784fe296
#ifndef _KK_SUB_TSL_H_
#define _KK_SUB_TSL_H_
#include "kk_tsl_common.h"
#include "klist.h"
typedef
struct
{
int
devid
;
kk_tsl_t
*
dev_shadow
;
char
product_type
[
PRODUCT_KEY_MAXLEN
];
char
device_mac
[
DEVICE_MAC_MAXLEN
];
struct
list_head
linked_list
;
}
sub_dev_node_t
;
#endif
platform/zigbee/app/builder/Z3GatewayHost/kk_test.c
View file @
784fe296
#include "kk_test.h"
#include "kk_test.h"
#include "kk_sub_tsl.h"
#include "kk_tsl_zigbee_map.h"
static
void
kk_rpc_send_message
(
cJSON
*
data
,
char
*
method
,
EmberEUI64
mac
)
static
void
kk_rpc_send_message
(
cJSON
*
data
,
char
*
method
,
EmberEUI64
mac
)
...
@@ -54,7 +55,7 @@ void kk_rpc_reportDevices(kk_report_device_s device)
...
@@ -54,7 +55,7 @@ void kk_rpc_reportDevices(kk_report_device_s device)
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceCode"
,
"2"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceCode"
,
"2"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productType"
,
"3"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productType"
,
"3"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productCode"
,
"4"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productCode"
,
"4"
);
kk_sub_tsl_add
(
devicesJson
,
device
.
mac
,
"3"
);
kk_rpc_report_devices
(
devicesJson
,
device
.
mac
);
kk_rpc_report_devices
(
devicesJson
,
device
.
mac
);
}
}
bool
kk_rpc_report_LightStatus
(
EmberEUI64
mac
,
bool
LightStatus
)
bool
kk_rpc_report_LightStatus
(
EmberEUI64
mac
,
bool
LightStatus
)
...
@@ -70,36 +71,29 @@ bool kk_rpc_report_LightStatus(EmberEUI64 mac,bool LightStatus)
...
@@ -70,36 +71,29 @@ bool kk_rpc_report_LightStatus(EmberEUI64 mac,bool LightStatus)
kk_rpc_report_status
(
root
,
mac
);
kk_rpc_report_status
(
root
,
mac
);
}
}
int
lightStatusCtrl
(
jrpc_context
*
ctx
,
const
char
*
mac
,
void
*
data
)
cJSON
*
rpc_read_attribue
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
{
rpc_nwk_info_s
info
;
EmberStatus
status
;
if
(
params
==
NULL
){
emberAfCorePrintln
(
"
\r\n
params == NULL
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
cJSON
*
LightStatus_item
=
rpc_cJSON_GetObjectItem
(
params
,
"LightStatus"
);
uint8_t
LightStatus
=
rpc_get_u8
(
LightStatus_item
->
valuestring
);
uint8_t
eui64
[
EUI64_SIZE
];
uint8_t
eui64
[
EUI64_SIZE
];
bool
flag
=
rpc_get_mac
(
mac
->
valuestring
,
eui64
);
uint8_t
LightStatus
=
0
;
EmberStatus
status
=
0
;
LightStatus
=
*
(
uint8_t
*
)
data
;
bool
flag
=
rpc_get_mac
(
mac
,
eui64
);
emberAfCorePrintBuffer
(
eui64
,
EUI64_SIZE
,
true
);
emberAfCorePrintBuffer
(
eui64
,
EUI64_SIZE
,
true
);
for
(
int
i
=
0
;
i
<
EUI64_SIZE
;
i
++
){
for
(
int
i
=
0
;
i
<
EUI64_SIZE
;
i
++
){
emberAfCorePrintln
(
"i=%d,val=%02x"
,
i
,
eui64
[
i
]);
emberAfCorePrintln
(
"i=%d,val=%02x"
,
i
,
eui64
[
i
]);
}
}
EmberNodeId
node
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
EmberNodeId
node
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
if
(
node
==
0xffff
){
if
(
node
==
0xffff
){
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
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
;
}
}
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
if
(
flag
){
if
(
flag
){
EmberStatus
status
;
if
(
LightStatus
==
1
){
if
(
LightStatus
==
1
){
status
=
zclOnOff_On
(
node
,
1
);
status
=
zclOnOff_On
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
...
@@ -107,69 +101,203 @@ cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac
...
@@ -107,69 +101,203 @@ cJSON *rpc_read_attribue(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac
status
=
zclOnOff_Off
(
node
,
1
);
status
=
zclOnOff_Off
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
}
else
{
}
else
{
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
;
}
}
}
else
{
}
else
{
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
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
;
}
}
return
rpc_cJSON_CreateNumber
(
status
);
return
status
;
}
error_return:
error_return:
return
-
1
;
return
rpc_cJSON_CreateNull
();
}
}
extern
kk_tsl_zigbee_map_t
g_tsl_zigbee_map
[];
int
kk_test_fuc
(
char
*
mac
,
const
char
*
params
)
{
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
;
int
pCtrlIdx
=
0
;
int
num
=
0
;
int
index
=
0
,
idx
=
0
;
char
*
identifier
=
NULL
;
cJSON
*
propertyItem
=
NULL
;
cJSON
*
root
;
root
=
cJSON_Parse
((
char
*
)
params
);
res
=
kk_sub_tsl_get_device_by_mac
(
mac
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
}
printf
(
"[%s][%d]node->product_type:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
node
->
product_type
);
pCtrlIdx
=
kk_find_ctrl_obj
(
node
->
product_type
);
if
(
pCtrlIdx
==
-
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_sub_tsl_get_Identifiers_Num
(
mac
,
&
num
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
for
(
index
=
0
;
index
<
num
;
index
++
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_sub_tsl_get_Identifier_by_index
(
mac
,
index
,
&
identifier
);
printf
(
"[%s][%d]identifier:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
identifier
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
root
,
identifier
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
if
(
propertyItem
!=
NULL
)
{
int
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
printf
(
"[%s][%d]value:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
value
);
for
(
idx
=
0
;
idx
<
num
;
idx
++
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
if
(
!
strcmp
(
identifier
,
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
Identity
))
{
res
=
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
zigbee_cb
(
NULL
,
mac
,
&
value
);
if
(
res
<
0
)
{
free
(
identifier
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
}
else
{
free
(
identifier
);
cJSON
*
rpc_Control
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
0
;
}
}
}
}
free
(
identifier
);
identifier
=
NULL
;
}
return
0
;
}
cJSON
*
rpc_read_attribue
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
{
rpc_nwk_info_s
info
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
EmberStatus
status
;
int
num
=
0
,
index
=
0
,
idx
=
0
;
char
*
identifier
=
NULL
;
cJSON
*
propertyItem
=
NULL
;
sub_dev_node_t
*
node
=
NULL
;
int
pCtrlIdx
=
0
;
int
res
=
0
,
ret
=
0
;
if
(
params
==
NULL
){
if
(
params
==
NULL
){
emberAfCorePrintln
(
"
\r\n
params == NULL
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
params == NULL
\r\n
"
);
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
{
}
else
{
cJSON
*
LightStatus_item
=
rpc_cJSON_GetObjectItem
(
params
,
"LightStatus"
);
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
error_return
;
uint8_t
LightStatus
=
rpc_get_u8
(
LightStatus_item
->
valuestring
);
uint8_t
eui64
[
EUI64_SIZE
];
bool
flag
=
rpc_get_mac
(
mac
->
valuestring
,
eui64
);
emberAfCorePrintBuffer
(
eui64
,
EUI64_SIZE
,
true
);
for
(
int
i
=
0
;
i
<
EUI64_SIZE
;
i
++
){
emberAfCorePrintln
(
"i=%d,val=%02x"
,
i
,
eui64
[
i
]);
}
}
EmberNodeId
node
=
emberAfDeviceTableGetNodeIdFromEui64
(
eui64
);
pCtrlIdx
=
kk_find_ctrl_obj
(
node
->
product_type
);
if
(
node
==
0xffff
){
if
(
pCtrlIdx
<
SUCCESS_RETURN
){
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
goto
error_return
;
}
}
kk_sub_tsl_get_Identifiers_Num
(
mac
->
valuestring
,
&
num
);
for
(
index
=
0
;
index
<
num
;
index
++
){
kk_sub_tsl_get_Identifier_by_index
(
mac
->
valuestring
,
index
,
&
identifier
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
identifier
);
if
(
propertyItem
!=
NULL
)
{
int
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
for
(
idx
=
0
;
idx
<
num
;
idx
++
)
{
if
(
!
strcmp
(
identifier
,
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
Identity
))
{
res
=
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
zigbee_cb
(
ctx
,
mac
,
&
value
);
if
(
ret
<
0
)
{
free
(
identifier
);
goto
error_return
;
}
else
{
free
(
identifier
);
return
rpc_cJSON_CreateNumber
(
ret
);
}
}
}
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
}
if
(
flag
){
free
(
identifier
);
identifier
=
NULL
;
}
}
error_return:
return
rpc_cJSON_CreateNull
();
}
cJSON
*
rpc_Control
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
)
{
sub_dev_node_t
*
node
=
NULL
;
int
res
=
0
;
int
num
=
0
;
int
pCtrlIdx
=
0
;
rpc_nwk_info_s
info
;
EmberStatus
status
;
EmberStatus
status
;
if
(
LightStatus
==
1
){
int
index
=
0
,
idx
=
0
;
status
=
zclOnOff_On
(
node
,
1
);
char
*
identifier
=
NULL
;
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
cJSON
*
propertyItem
=
NULL
;
}
else
if
(
LightStatus
==
0
){
status
=
zclOnOff_Off
(
node
,
1
);
if
(
params
==
NULL
){
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
emberAfCorePrintln
(
"
\r\n
params == NULL
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
}
else
{
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
string
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
goto
error_return
;
}
}
}
else
{
pCtrlIdx
=
kk_find_ctrl_obj
(
node
->
product_type
);
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
if
(
pCtrlIdx
==
-
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
goto
error_return
;
}
}
return
rpc_cJSON_CreateNumber
(
status
);
kk_sub_tsl_get_Identifiers_Num
(
mac
->
string
,
&
num
);
for
(
index
=
0
;
index
<
num
;
index
++
){
kk_sub_tsl_get_Identifier_by_index
(
mac
->
string
,
index
,
&
identifier
);
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
identifier
);
if
(
propertyItem
!=
NULL
)
{
int
value
=
rpc_get_u8
(
propertyItem
->
valuestring
);
for
(
idx
=
0
;
idx
<
num
;
idx
++
)
{
if
(
!
strcmp
(
identifier
,
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
Identity
))
{
res
=
g_tsl_zigbee_map
[
pCtrlIdx
].
zigbee_ctrl
[
idx
].
zigbee_cb
(
ctx
,
mac
,
&
value
);
if
(
res
<
0
)
{
free
(
identifier
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
}
error_return:
else
{
free
(
identifier
);
return
rpc_cJSON_CreateNumber
(
res
);
}
}
}
}
free
(
identifier
);
identifier
=
NULL
;
}
}
error_return:
return
rpc_cJSON_CreateNull
();
return
rpc_cJSON_CreateNull
();
}
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
View file @
784fe296
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
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
*
rpc_read_attribue
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
cJSON
*
rpc_read_attribue
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
,
cJSON
*
mac
);
int
lightStatusCtrl
(
jrpc_context
*
ctx
,
const
char
*
mac
,
void
*
data
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_common.h
0 → 100644
View file @
784fe296
#ifndef __KK_TSL_COM__
#define __KK_TSL_COM__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _IN_
#define _IN_
#endif
#ifndef _OU_
#define _OU_
#endif
#define PRODUCT_KEY_MAXLEN (32 + 1)
#define DEVICE_NAME_MAXLEN (32 + 1)
#define DEVICE_SECRET_MAXLEN (64 + 1)
#define DEVICE_MAC_MAXLEN (16 + 1)
#define DEVICE_SN_MAXLEN (32 + 1)
#define TSL_PATH_MAXLEN (64 + 1)
#define DM_UTILS_UINT16_STRLEN (5)
#define DM_UTILS_UINT32_STRLEN (10)
#define DM_UTILS_UINT64_STRLEN (20)
#define KK_TSL_KEY_SCHEMA "schema"
#define KK_TSL_KEY_LINK "link"
#define KK_TSL_KEY_PROFILE "profile"
#define KK_TSL_KEY_PROPERTIES "properties"
#define KK_TSL_KEY_EVENTS "events"
#define KK_TSL_KEY_SERVICES "services"
#define KK_TSL_KEY_PROFILE_PK "productKey"
#define KK_TSL_KEY_PROFILE_DN "deviceName"
#define KK_TSL_KEY_IDENTIFIER "identifier"
#define KK_TSL_KEY_NAME "name"
#define KK_TSL_KEY_DESC "desc"
#define KK_TSL_KEY_ACCESS_MODE "accessMode"
#define KK_TSL_KEY_REQUIRED "required"
#define KK_TSL_KEY_METHOD "method"
#define KK_TSL_KEY_CALLTYPE "callType"
#define KK_TSL_KEY_OUTPUTDATA "outputData"
#define KK_TSL_KEY_INPUTDATA "inputData"
#define KK_TSL_KEY_DATATYPE "dataType"
#define KK_TSL_KEY_TYPE "type"
#define KK_TSL_KEY_SPECS "specs"
#define KK_TSL_KEY_UNIT "unit"
#define KK_TSL_KEY_UNITNAME "unitName"
#define KK_TSL_KEY_MIN "min"
#define KK_TSL_KEY_MAX "max"
#define KK_TSL_KEY_LENGTH "length"
#define KK_TSL_KEY_SIZE "size"
#define KK_TSL_KEY_ITEM "item"
#define KK_MSG_KEY_DELIMITER '.'
#define KK_URI_SERVICE_DELIMITER '/'
#define KK_URI_OFFSET 0
//Special Service And Event
#define KK_TSL_SPECIAL_SERVICE_SET_IDENTIFIER "set"
#define KK_TSL_SPECIAL_SERVICE_SET_METHOD "thing.service.property.set"
#define KK_TSL_SPECIAL_SERVICE_GET_IDENTIFIER "get"
#define KK_TSL_SPECIAL_SERVICE_GET_METHOD "thing.service.property.get"
#define KK_TSL_SPECIAL_EVENT_POST_IDENTIFIER "post"
#define KK_TSL_SPECIAL_EVENT_POST_METHOD "thing.event.property.post"
#define KK_TSL_GATAWAY_VERSION_IDENTIFIER "Version"
#define KK_TSL_GATAWAY_IP_IDENTIFIER "IPAddress"
#define KK_TSL_GATAWAY_MAC_IDENTIFIER "MACAddress"
#define KK_TSL_GATAWAY_PORT_IDENTIFIER "Port"
#define KK_TSL_GATAWAY_SN_IDENTIFIER "SN"
#define KK_TSL_GATAWAY_WHITELIST_IDENTIFIER "WhiteListState"
typedef
enum
{
KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA
,
KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA
}
kk_tsl_data_target_e
;
typedef
enum
{
TSL_SERVICE_GET_FAILED
=
-
13
,
TSL_SERVICE_SET_FAILED
=
-
12
,
TSL_EVENT_GET_FAILED
=
-
11
,
TSL_EVENT_SET_FAILED
=
-
10
,
TSL_PROPERTY_GET_FAILED
=
-
9
,
TSL_PROPERTY_SET_FAILED
=
-
8
,
TSL_EVENT_NOT_EXIST
=
-
7
,
TSL_PROPERTY_NOT_EXIST
=
-
6
,
TSL_SERVICE_NOT_EXIST
=
-
5
,
JSON_PARSE_FAILED
=
-
4
,
MEMORY_NOT_ENOUGH
=
-
3
,
INVALID_PARAMETER
=
-
2
,
FAIL_RETURN
=
-
1
,
SUCCESS_RETURN
=
0
,
}
kk_tsl_error_code_t
;
typedef
enum
{
KK_TSL_DATA_TYPE_NONE
,
//none
KK_TSL_DATA_TYPE_INT
,
//int
KK_TSL_DATA_TYPE_FLOAT
,
//float
KK_TSL_DATA_TYPE_DOUBLE
,
//double
KK_TSL_DATA_TYPE_TEXT
,
//string
KK_TSL_DATA_TYPE_ENUM
,
//int
KK_TSL_DATA_TYPE_DATE
,
//string
KK_TSL_DATA_TYPE_BOOL
,
//bool,0 or 1
KK_TSL_DATA_TYPE_ARRAY
,
//support int, float, double, text
KK_TSL_DATA_TYPE_STRUCT
,
//support above 8 data types
}
kk_tsl_data_type_e
;
typedef
struct
{
kk_tsl_data_type_e
type
;
int
size
;
void
*
value
;
}
kk_tsl_data_value_complex_t
;
typedef
struct
{
kk_tsl_data_type_e
type
;
union
{
int
value_int
;
float
value_float
;
double
value_double
;
void
*
value
;
//string or complex type accroding to data type
};
}
kk_tsl_data_value_t
;
typedef
struct
{
char
*
identifier
;
kk_tsl_data_value_t
data_value
;
}
kk_tsl_data_t
;
typedef
struct
{
char
*
identifier
;
int
input_data_number
;
//input_data Number
kk_tsl_data_t
*
input_datas
;
//input_data array, type is dm_shw_data_t
int
output_data_number
;
//ouput_data Number
kk_tsl_data_t
*
output_datas
;
//output_data array, type is dm_shw_data_t
}
kk_tsl_event_t
;
typedef
struct
{
char
*
identifier
;
//synchronized or asynchronized
int
input_data_number
;
//input_data_number
kk_tsl_data_t
*
input_datas
;
//input_data array, type is dm_shw_data_t
int
output_data_number
;
//ouput_data Number
kk_tsl_data_t
*
output_datas
;
//output_data array, type is dm_shw_data_t
}
kk_tsl_service_t
;
typedef
struct
{
int
property_number
;
kk_tsl_data_t
*
properties
;
//property array, type is dm_shw_data_t
int
event_number
;
kk_tsl_event_t
*
events
;
//event array, type is dm_shw_event_t
int
service_number
;
kk_tsl_service_t
*
services
;
//service array, type is dm_shw_service_t
}
kk_tsl_t
;
#endif
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.c
0 → 100644
View file @
784fe296
#include "kk_tsl_zigbee_map.h"
#include "kk_test.h"
kk_tsl_zigbee_map_t
g_tsl_zigbee_map
[]
=
{
{
"a1h88DsZIaY"
,
{
{
KK_TSL_DATA_TYPE_TEXT
,
"LightStatus"
,
lightStatusCtrl
},
{
KK_TSL_DATA_TYPE_TEXT
,
"LightAdjustLevel"
,
lightStatusCtrl
},
{
KK_TSL_DATA_TYPE_TEXT
,
"LightAlias"
,
lightStatusCtrl
},
}
},
{
"testtype"
,
{
{
KK_TSL_DATA_TYPE_TEXT
,
"test1"
,
lightStatusCtrl
},
{
KK_TSL_DATA_TYPE_TEXT
,
"test12"
,
lightStatusCtrl
},
{
KK_TSL_DATA_TYPE_TEXT
,
"test123"
,
lightStatusCtrl
},
{
KK_TSL_DATA_TYPE_TEXT
,
"test1234"
,
lightStatusCtrl
},
}
},
};
int
kk_find_ctrl_obj
(
const
char
*
product_type
)
{
int
map_num
=
sizeof
(
g_tsl_zigbee_map
)
/
sizeof
(
kk_tsl_zigbee_map_t
);
int
index
=
0
;
for
(
index
=
0
;
index
<
map_num
;
index
++
)
{
if
(
!
strcmp
(
product_type
,
g_tsl_zigbee_map
[
index
].
product_type
))
{
return
index
;
}
}
return
-
1
;
}
platform/zigbee/app/builder/Z3GatewayHost/kk_tsl_zigbee_map.h
0 → 100644
View file @
784fe296
#ifndef _KK_ZIGBEE_MAP_H_
#define _KK_ZIGBEE_MAP_H_
#include "RPC_API.h"
#include "kk_tsl_common.h"
typedef
int
(
*
zigbee_ctrl_cb
)(
jrpc_context
*
ctx
,
const
char
*
mac
,
void
*
data
);
typedef
struct
{
int
type
;
char
*
Identity
;
zigbee_ctrl_cb
zigbee_cb
;
}
kk_zigbee_ctrl_map_t
;
typedef
struct
{
char
*
product_type
;
kk_zigbee_ctrl_map_t
zigbee_ctrl
[
20
];
}
kk_tsl_zigbee_map_t
;
#endif
platform/zigbee/app/builder/Z3GatewayHost/klist.h
0 → 100644
View file @
784fe296
This diff is collapsed.
Click to expand it.
platform/zigbee/app/builder/Z3GatewayHost/libkk_tsl.a
0 → 100644
View file @
784fe296
File added
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