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
Hide 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= \
./jsonrpc/rpccJSON.c
\
./yjq_ezsp.c
\
./kk_test.c
\
./kk_sub_tsl.c
\
./kk_tsl_zigbee_map.c
\
./rpc_api/src/rpc_common.c
\
./rpc_api/src/rpc_onoff.c
\
./rpc_api/src/rpc_global_cmd.c
\
...
...
@@ -375,7 +377,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
@
echo
-e
'\n$@ build success'
else
$(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'
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"
static
void
kk_rpc_send_message
(
cJSON
*
data
,
char
*
method
,
EmberEUI64
mac
)
{
static
uint16_t
msgid
;
cJSON
*
item
=
rpc_cJSON_CreateObject
();
char
msgIdString
[
10
];
sprintf
(
msgIdString
,
"%d"
,
++
msgid
);
rpc_cJSON_AddStringToObject
(
item
,
"msgId"
,
msgIdString
);
rpc_cJSON_AddStringToObject
(
item
,
"version"
,
KK_IPC_VERSION
);
if
(
mac
!=
NULL
){
rpc_cJSON_AddMACToObject
(
item
,
mac
);
}
rpc_cJSON_AddStringToObject
(
item
,
"method"
,
method
);
rpc_cJSON_AddItemToObject
(
item
,
"params"
,
data
);
char
*
p
=
rpc_cJSON_Print
(
item
);
emberAfAppPrintln
(
"send json:
\n
%s
\n
"
,
p
);
free
(
p
);
jrpc_send_msg
(
item
);
}
void
kk_rpc_report_devices
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_rpc_send_message
(
data
,
KK_REPORT_DEVICE_JOINED_METHOD
,
mac
);
}
void
kk_rpc_report_status
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_rpc_send_message
(
data
,
KK_REPORT_ATTRIBUTE_METHOD
,
mac
);
}
typedef
struct
{
EmberEUI64
mac
;
uint8_t
AppVersion
;
uint8_t
deviceType
;
uint8_t
deviceCode
;
uint8_t
productType
;
uint8_t
productCode
;
}
kk_report_device_s
;
void
kk_rpc_reportDevices
(
kk_report_device_s
device
)
{
cJSON
*
devicesJson
;
devicesJson
=
rpc_cJSON_CreateObject
();
rpc_cJSON_AddAppVersionToObject
(
devicesJson
,
device
.
AppVersion
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceType"
,
"1"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceCode"
,
"2"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productType"
,
"3"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productCode"
,
"4"
);
kk_rpc_report_devices
(
devicesJson
,
device
.
mac
);
}
bool
kk_rpc_report_LightStatus
(
EmberEUI64
mac
,
bool
LightStatus
)
{
cJSON
*
root
;
root
=
rpc_cJSON_CreateObject
();
if
(
LightStatus
==
true
){
rpc_cJSON_AddStringToObject
(
root
,
"LightStatus"
,
"1"
);
}
else
{
rpc_cJSON_AddStringToObject
(
root
,
"LightStatus"
,
"0"
);
}
kk_rpc_report_status
(
root
,
mac
);
}
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
];
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
);
if
(
node
==
0xffff
){
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
if
(
flag
){
EmberStatus
status
;
if
(
LightStatus
==
1
){
status
=
zclOnOff_On
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
}
else
if
(
LightStatus
==
0
){
status
=
zclOnOff_Off
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
}
else
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
}
else
{
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
return
rpc_cJSON_CreateNumber
(
status
);
}
error_return:
return
rpc_cJSON_CreateNull
();
}
cJSON
*
rpc_Control
(
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
];
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
);
if
(
node
==
0xffff
){
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
if
(
flag
){
EmberStatus
status
;
if
(
LightStatus
==
1
){
status
=
zclOnOff_On
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
}
else
if
(
LightStatus
==
0
){
status
=
zclOnOff_Off
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
}
else
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
}
else
{
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
return
rpc_cJSON_CreateNumber
(
status
);
}
error_return:
return
rpc_cJSON_CreateNull
();
}
cJSON
*
rpc_nwkPermitJoin
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
)
{
cJSON
*
OpenOrClose
;
EmberStatus
status
;
uint8_t
isEnable
;
if
(
params
==
NULL
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
if
(
params
->
type
==
cJSON_Object
){
OpenOrClose
=
rpc_cJSON_GetObjectItem
(
params
,
"NetChannelState"
);
}
else
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
isEnable
=
rpc_get_u8
(
OpenOrClose
->
valuestring
);
if
(
isEnable
==
0
){
status
=
nwkPermitJoinCMD
(
FALSE
);
emberAfCorePrintln
(
"Disable Permit join
\r\n
"
);
}
else
if
(
isEnable
==
1
){
status
=
nwkPermitJoinCMD
(
TRUE
);
emberAfCorePrintln
(
"Enable Permit join 180s
\r\n
"
);
}
else
{
emberAfCorePrintln
(
"item type error[%d]
\r\n
"
,
OpenOrClose
->
type
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
return
rpc_cJSON_CreateNumber
(
status
);
error_return:
return
rpc_cJSON_CreateNull
();
}
void
emberAfPluginDeviceTableNewDeviceCallback
(
EmberEUI64
nodeEui64
)
{
uint16_t
deviceTableIndex
=
emberAfDeviceTableGetFirstIndexFromEui64
(
nodeEui64
);
if
(
deviceTableIndex
==
0xffff
){
kk_print_info
(
"not find item!"
);
return
;
}
//EmberAfPluginDeviceTableEntry *deviceTable = emberAfDeviceTablePointer();
//cJSON* nodeJson = rpc_reportDeviceState("joined",deviceTable[deviceTableIndex].eui64);
//rpc_printfJSON("joined",nodeJson);
//rpc_send_message(nodeJson,"device joined");
//rpc_add_device(deviceTable[deviceTableIndex].nodeId);
kk_report_device_s
device
;
//device.mac = nodeEui64;
device
.
AppVersion
=
0x10
;
memcpy
(
device
.
mac
,
nodeEui64
,
EUI64_SIZE
);
kk_rpc_reportDevices
(
device
);
}
#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
uint16_t
msgid
;
cJSON
*
item
=
rpc_cJSON_CreateObject
();
char
msgIdString
[
10
];
sprintf
(
msgIdString
,
"%d"
,
++
msgid
);
rpc_cJSON_AddStringToObject
(
item
,
"msgId"
,
msgIdString
);
rpc_cJSON_AddStringToObject
(
item
,
"version"
,
KK_IPC_VERSION
);
if
(
mac
!=
NULL
){
rpc_cJSON_AddMACToObject
(
item
,
mac
);
}
rpc_cJSON_AddStringToObject
(
item
,
"method"
,
method
);
rpc_cJSON_AddItemToObject
(
item
,
"params"
,
data
);
char
*
p
=
rpc_cJSON_Print
(
item
);
emberAfAppPrintln
(
"send json:
\n
%s
\n
"
,
p
);
free
(
p
);
jrpc_send_msg
(
item
);
}
void
kk_rpc_report_devices
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_rpc_send_message
(
data
,
KK_REPORT_DEVICE_JOINED_METHOD
,
mac
);
}
void
kk_rpc_report_status
(
cJSON
*
data
,
EmberEUI64
mac
)
{
kk_rpc_send_message
(
data
,
KK_REPORT_ATTRIBUTE_METHOD
,
mac
);
}
typedef
struct
{
EmberEUI64
mac
;
uint8_t
AppVersion
;
uint8_t
deviceType
;
uint8_t
deviceCode
;
uint8_t
productType
;
uint8_t
productCode
;
}
kk_report_device_s
;
void
kk_rpc_reportDevices
(
kk_report_device_s
device
)
{
cJSON
*
devicesJson
;
devicesJson
=
rpc_cJSON_CreateObject
();
rpc_cJSON_AddAppVersionToObject
(
devicesJson
,
device
.
AppVersion
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceType"
,
"1"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"deviceCode"
,
"2"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productType"
,
"3"
);
rpc_cJSON_AddStringToObject
(
devicesJson
,
"productCode"
,
"4"
);
kk_sub_tsl_add
(
devicesJson
,
device
.
mac
,
"3"
);
kk_rpc_report_devices
(
devicesJson
,
device
.
mac
);
}
bool
kk_rpc_report_LightStatus
(
EmberEUI64
mac
,
bool
LightStatus
)
{
cJSON
*
root
;
root
=
rpc_cJSON_CreateObject
();
if
(
LightStatus
==
true
){
rpc_cJSON_AddStringToObject
(
root
,
"LightStatus"
,
"1"
);
}
else
{
rpc_cJSON_AddStringToObject
(
root
,
"LightStatus"
,
"0"
);
}
kk_rpc_report_status
(
root
,
mac
);
}
int
lightStatusCtrl
(
jrpc_context
*
ctx
,
const
char
*
mac
,
void
*
data
)
{
uint8_t
eui64
[
EUI64_SIZE
];
uint8_t
LightStatus
=
0
;
EmberStatus
status
=
0
;
LightStatus
=
*
(
uint8_t
*
)
data
;
bool
flag
=
rpc_get_mac
(
mac
,
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
);
if
(
node
==
0xffff
){
emberAfCorePrintln
(
"
\r\n
not find device!
\r\n
"
);
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
emberAfCorePrintln
(
"
\r\n
node=0x%02X,LightStatus=%d
\r\n
"
,
node
,
LightStatus
);
if
(
flag
){
if
(
LightStatus
==
1
){
status
=
zclOnOff_On
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_On
\r\n
"
);
}
else
if
(
LightStatus
==
0
){
status
=
zclOnOff_Off
(
node
,
1
);
emberAfCorePrintln
(
"
\r\n
zclOnOff_Off
\r\n
"
);
}
else
{
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
}
else
{
emberAfCorePrintln
(
"
\r\n
22222
\r\n
"
);
if
(
ctx
)
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
return
status
;
error_return:
return
-
1
;
}
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
);
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
;
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
){
emberAfCorePrintln
(
"
\r\n
params == NULL
\r\n
"
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
{
res
=
kk_sub_tsl_get_device_by_mac
(
mac
->
valuestring
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
error_return
;
}
pCtrlIdx
=
kk_find_ctrl_obj
(
node
->
product_type
);
if
(
pCtrlIdx
<
SUCCESS_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
);
}
}
}
}
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
;
int
index
=
0
,
idx
=
0
;
char
*
identifier
=
NULL
;
cJSON
*
propertyItem
=
NULL
;
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
{
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
);
goto
error_return
;
}
pCtrlIdx
=
kk_find_ctrl_obj
(
node
->
product_type
);
if
(
pCtrlIdx
==
-
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
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
;
}
else
{
free
(
identifier
);
return
rpc_cJSON_CreateNumber
(
res
);
}
}
}
}
free
(
identifier
);
identifier
=
NULL
;
}
}
error_return:
return
rpc_cJSON_CreateNull
();
}
cJSON
*
rpc_nwkPermitJoin
(
jrpc_context
*
ctx
,
cJSON
*
params
,
cJSON
*
id
)
{
cJSON
*
OpenOrClose
;
EmberStatus
status
;
uint8_t
isEnable
;
if
(
params
==
NULL
){
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
else
if
(
params
->
type
==
cJSON_Object
){
OpenOrClose
=
rpc_cJSON_GetObjectItem
(
params
,
"NetChannelState"
);
}
else
{
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
isEnable
=
rpc_get_u8
(
OpenOrClose
->
valuestring
);
if
(
isEnable
==
0
){
status
=
nwkPermitJoinCMD
(
FALSE
);
emberAfCorePrintln
(
"Disable Permit join
\r\n
"
);
}
else
if
(
isEnable
==
1
){
status
=
nwkPermitJoinCMD
(
TRUE
);
emberAfCorePrintln
(
"Enable Permit join 180s
\r\n
"
);
}
else
{
emberAfCorePrintln
(
"item type error[%d]
\r\n
"
,
OpenOrClose
->
type
);
set_json_error_type
(
ctx
,
JRPC_INVALID_PARAMS
,
MSG_INVALID_PARAMS
);
goto
error_return
;
}
return
rpc_cJSON_CreateNumber
(
status
);
error_return:
return
rpc_cJSON_CreateNull
();
}
void
emberAfPluginDeviceTableNewDeviceCallback
(
EmberEUI64
nodeEui64
)
{
uint16_t
deviceTableIndex
=
emberAfDeviceTableGetFirstIndexFromEui64
(
nodeEui64
);
if
(
deviceTableIndex
==
0xffff
){
kk_print_info
(
"not find item!"
);
return
;
}
//EmberAfPluginDeviceTableEntry *deviceTable = emberAfDeviceTablePointer();
//cJSON* nodeJson = rpc_reportDeviceState("joined",deviceTable[deviceTableIndex].eui64);
//rpc_printfJSON("joined",nodeJson);
//rpc_send_message(nodeJson,"device joined");
//rpc_add_device(deviceTable[deviceTableIndex].nodeId);
kk_report_device_s
device
;
//device.mac = nodeEui64;
device
.
AppVersion
=
0x10
;
memcpy
(
device
.
mac
,
nodeEui64
,
EUI64_SIZE
);
kk_rpc_reportDevices
(
device
);
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/kk_test.h
View file @
784fe296
...
...
@@ -13,6 +13,7 @@
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
);
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
#ifndef _INFRA_LIST_H_
#define _INFRA_LIST_H_
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) || defined(__GNUC__)) && \
!defined(inline) && !defined(__cplusplus)
#define inline __inline
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
/*
* Get offset of a member variable.
*
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_offsetof(type, member) ((int)&(((type *)0)->member))
/*
* Get the struct for this entry.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define aos_container_of(ptr, type, member) \
((type *) ((char *) (ptr) - aos_offsetof(type, member)))
/* for double link list */
typedef
struct
dlist_s
{
struct
dlist_s
*
prev
;
struct
dlist_s
*
next
;
}
dlist_t
;
static
inline
void
__dlist_add
(
dlist_t
*
node
,
dlist_t
*
prev
,
dlist_t
*
next
)
{
node
->
next
=
next
;
node
->
prev
=
prev
;
//printf("[%s][%d]node->name:%d\n",__FUNCTION__,__LINE__);
prev
->
next
=
node
;
next
->
prev
=
node
;
}
/*
* Get the struct for this entry.
*
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_entry(addr, type, member) \
((type *)((long)addr - aos_offsetof(type, member)))
static
inline
void
dlist_add
(
dlist_t
*
node
,
dlist_t
*
queue
)
{
__dlist_add
(
node
,
queue
,
queue
->
next
);
}
static
inline
void
dlist_add_tail
(
dlist_t
*
node
,
dlist_t
*
queue
)
{
__dlist_add
(
node
,
queue
->
prev
,
queue
);
}
static
inline
void
dlist_del
(
dlist_t
*
node
)
{
dlist_t
*
prev
=
node
->
prev
;
dlist_t
*
next
=
node
->
next
;
prev
->
next
=
next
;
next
->
prev
=
prev
;
}
static
inline
void
dlist_init
(
dlist_t
*
node
)
{
node
->
next
=
node
->
prev
=
node
;
}
static
inline
void
INIT_AOS_DLIST_HEAD
(
dlist_t
*
list
)
{
list
->
next
=
list
;
list
->
prev
=
list
;
}
static
inline
int
dlist_empty
(
const
dlist_t
*
head
)
{
return
head
->
next
==
head
;
}
/*
* Initialise the list.
*
* @param[in] list the list to be inited.
*/
#define AOS_DLIST_INIT(list) {&(list), &(list)}
/*
* Get the first element from a list
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_first_entry(ptr, type, member) \
dlist_entry((ptr)->next, type, member)
/*
* Iterate over a list.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] head he head for your list.
*/
#define dlist_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/*
* Iterate over a list safe against removal of list entry.
*
* @param[in] pos the &struct dlist_t to use as a loop cursor.
* @param[in] n another &struct dlist_t to use as temporary storage.
* @param[in] head he head for your list.
*/
#define dlist_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the &struct dlist_t to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member != (queue); \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] n the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the dlist_t within the struct.
*/
#define dlist_for_each_entry_safe(queue, n, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
n = (queue)->next ? (queue)->next->next : NULL; \
&node->member != (queue); \
node = aos_container_of(n, type, member), n = n ? n->next : NULL)
/*
* Get the struct for this entry.
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the variable within the struct.
*/
#define list_entry(ptr, type, member) \
aos_container_of(ptr, type, member)
/*
* Iterate backwards over list of given type.
*
* @param[in] pos the type * to use as a loop cursor.
* @param[in] head he head for your list.
* @param[in] member the name of the dlist_t within the struct.
* @param[in] type the type of the struct this is embedded in.
*/
#define dlist_for_each_entry_reverse(pos, head, member, type) \
for (pos = list_entry((head)->prev, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static
inline
int
__dlist_entry_number
(
dlist_t
*
queue
)
{
int
num
;
dlist_t
*
cur
=
queue
;
for
(
num
=
0
;
cur
->
next
!=
queue
;
cur
=
cur
->
next
,
num
++
)
;
return
num
;
}
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
#define dlist_entry_number(head) \
__dlist_entry_number(head)
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD_INIT(name) { &(name), &(name) }
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_DLIST_HEAD(name) \
dlist_t name = AOS_DLIST_HEAD_INIT(name)
/* for single link list */
typedef
struct
slist_s
{
struct
slist_s
*
next
;
}
slist_t
;
static
inline
void
slist_add
(
slist_t
*
node
,
slist_t
*
head
)
{
node
->
next
=
head
->
next
;
head
->
next
=
node
;
}
static
inline
void
slist_add_tail
(
slist_t
*
node
,
slist_t
*
head
)
{
while
(
head
->
next
)
{
head
=
head
->
next
;
}
slist_add
(
node
,
head
);
}
static
inline
void
slist_del
(
slist_t
*
node
,
slist_t
*
head
)
{
while
(
head
->
next
)
{
if
(
head
->
next
==
node
)
{
head
->
next
=
node
->
next
;
break
;
}
head
=
head
->
next
;
}
}
static
inline
int
slist_empty
(
const
slist_t
*
head
)
{
return
!
head
->
next
;
}
static
inline
void
slist_init
(
slist_t
*
head
)
{
head
->
next
=
0
;
}
/*
* Iterate over list of given type.
*
* @param[in] queue he head for your list.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry(queue, node, type, member) \
for (node = aos_container_of((queue)->next, type, member); \
&node->member; \
node = aos_container_of(node->member.next, type, member))
/*
* Iterate over list of given type safe against removal of list entry.
*
* @param[in] queue the head for your list.
* @param[in] tmp the type * to use as a temp.
* @param[in] node the type * to use as a loop cursor.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_for_each_entry_safe(queue, tmp, node, type, member) \
for (node = aos_container_of((queue)->next, type, member), \
tmp = (queue)->next ? (queue)->next->next : NULL; \
&node->member; \
node = aos_container_of(tmp, type, member), tmp = tmp ? tmp->next : tmp)
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD_INIT(name) {0}
/*
* Initialise the list.
*
* @param[in] name the list to be initialized.
*/
#define AOS_SLIST_HEAD(name) \
slist_t name = AOS_SLIST_HEAD_INIT(name)
/*
* Get the struct for this entry.
* @param[in] addr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_entry(addr, type, member) ( \
addr ? (type *)((long)addr - aos_offsetof(type, member)) : (type *)addr \
)
/*
* Get the first element from a list.
*
* @param[in] ptr the list head to take the element from.
* @param[in] type the type of the struct this is embedded in.
* @param[in] member the name of the slist_t within the struct.
*/
#define slist_first_entry(ptr, type, member) \
slist_entry((ptr)->next, type, member)
/*
* Get the list length.
*
* @param[in] queue the head for your list.
*/
static
inline
int
slist_entry_number
(
slist_t
*
queue
)
{
int
num
;
slist_t
*
cur
=
queue
;
for
(
num
=
0
;
cur
->
next
;
cur
=
cur
->
next
,
num
++
)
;
return
num
;
}
#ifndef offset_of
#define offset_of aos_offsetof
#endif
#ifndef container_of
#define container_of aos_container_of
#endif
#define LIST_HEAD AOS_DLIST_HEAD
#define LIST_HEAD_INIT AOS_DLIST_INIT
#define INIT_LIST_HEAD INIT_AOS_DLIST_HEAD
#define LIST_INIT AOS_DLIST_INIT
#define list_head dlist_s
#define list_head_t dlist_t
#define list_add dlist_add
#define list_add_tail dlist_add_tail
#define list_del dlist_del
#define list_empty dlist_empty
#define list_entry_number dlist_entry_number
#define list_first_entry dlist_first_entry
#define list_for_each dlist_for_each
#define list_for_each_entry_reverse dlist_for_each_entry_reverse
#define list_for_each_safe dlist_for_each_safe
#define list_init dlist_init
#define list_for_each_entry(pos, head, member, type) \
dlist_for_each_entry(head, pos, type, member)
#define list_for_each_entry_safe(pos, n, head, member, type) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#define list_next_entry(pos, member, type) \
list_entry((pos)->member.next, type, member)
static
inline
void
list_del_init
(
struct
list_head
*
entry
)
{
list_del
(
entry
);
INIT_LIST_HEAD
(
entry
);
}
static
inline
int
list_is_last
(
const
struct
list_head
*
list
,
const
struct
list_head
*
head
)
{
return
list
->
next
==
head
;
}
typedef
struct
propertyInfo
{
char
name
[
50
];
char
identifier
[
50
];
struct
list_head
list
;
}
propertyInfo_t
;
#ifdef __cplusplus
}
#endif
#endif
/* AOS_LIST_H */
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