Commit 4dcf5660 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】1,增加gateway的配置文件;2,去掉kk_sub_tsl.c,同一改用kk_device_manage里的接口

See merge request chenweican/k-sdk!12
parents a615faf9 8c3bbd07
......@@ -291,7 +291,6 @@ APPLICATION_FILES= \
./ZB/kk_plat_ota.c\
./ZB/kk_rgb_hsl_convert.c\
./kk_test.c\
./kk_sub_tsl.c\
./rpc_api/src/rpc_common.c\
./rpc_api/src/rpc_onoff.c\
./rpc_api/src/rpc_global_cmd.c\
......
{
"productCode":"2",
"config":[
{
"identity":"NetChannelState",
"endpoint":1,
"cluster":"0x0000",
"attribute":"0x0000",
"reportFunc":"",
"controlFunc":"kk_permit_join"
}
]
}
\ No newline at end of file
......@@ -771,7 +771,6 @@ void kk_rpc_report_attribute(EmberEUI64 eui64,
{
int i,j,num,status;
char macString[19] = {0};
sub_dev_node_t *node = NULL;
char * pCode;
......@@ -788,8 +787,11 @@ void kk_rpc_report_attribute(EmberEUI64 eui64,
}
void kk_device_gateway_add(EmberEUI64 eui64)
{
kk_device_config_map_add("2");
kk_device_table_add(eui64,0,"2",0);
}
#ifndef __KK_DEVICE_MANAGER_H
#define __KK_DEVICE_MANAGER_H
#include "kk_test.h"
#include "kk_sub_tsl.h"
#include "kk_product_code.h"
#include "kk_zb_com.h"
......
......@@ -138,8 +138,6 @@ void kk_device_table_add(EmberEUI64 mac,EmberNodeId nodeId,const char *productCo
emberAfDebugPrint("mac:");
emberAfPrintBigEndianEui64(mac);
kk_sub_tsl_add(mac,productCode);
if(kk_device_find_by_node(nodeId)!=NULL){
emberAfDebugPrintln(" is already in device table!!!");
kk_print_device_table();
......
......@@ -6,20 +6,19 @@ static void kk_msg_report(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
static uint16_t msgid;
char msgIdString[10]= {0};
char macString[19] = {0};
sub_dev_node_t *node = NULL;
int res = 0;
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]kk_rpc_send_message error!!!\n",__FUNCTION__,__LINE__);
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
printf("[%s][%d]kk_msg_report error!!!\n",__FUNCTION__,__LINE__);
return;
}
cJSON *info = rpc_cJSON_CreateObject();
if(info != NULL){
rpc_cJSON_AddStringToObject(info, "msgType",msgtype);
rpc_cJSON_AddStringToObject(info, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(info, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode",macString);
}
cJSON *payload = rpc_cJSON_CreateObject();
......@@ -73,7 +72,6 @@ void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode)
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
rpc_cJSON_AddStringToObject(devicesJson, "mac",macString);
kk_sub_tsl_add(mac,productCode);
emberAfGetEui64(localEui64);
kk_msg_report_joined(devicesJson,localEui64);
}
......@@ -82,22 +80,20 @@ void kk_msg_report_dev_leave(EmberEUI64 mac)
{
int res = 0;
cJSON* devicesJson;
sub_dev_node_t *node = NULL;
EmberEUI64 localEui64 = {0};
char macString[KK_EUI64_STRING_LENGTH];
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
emberAfDebugPrintln("[%s][%d]kk msg send error!!!\n",__FUNCTION__,__LINE__);
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
emberAfDebugPrintln("[%s][%d]kk_msg_report_dev_leave error!!!\n",__FUNCTION__,__LINE__);
return;
}
devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddStringToObject(devicesJson, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
emberAfGetEui64(localEui64);
kk_msg_report_leave(devicesJson,localEui64);
kk_sub_tsl_delete(mac);
kk_device_table_delete(mac);
kk_device_db_delete(mac);
}
......
......@@ -7,7 +7,6 @@
#include ".././jsonrpc/rpccJSON.h"
#include "com_api.h"
#include "kk_zb_com.h"
#include "kk_sub_tsl.h"
#define KK_IPC_VERSION "1.0"
......
......@@ -111,7 +111,6 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
uint8_t *data)
{
int i,j,num,status;
sub_dev_node_t *node = NULL;
int res = 0;
char macString[RPC_EUI64_STRING_LENGTH];
kk_device_table_s *dev;
......
......@@ -35,15 +35,13 @@ cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJS
}
}
}
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 kk_tsl_utils_memtok( char *input, char *delimiter, int index, int *offset)
{
int item_index = 0;
int count = 0;
......@@ -103,7 +101,6 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
}
item = &dev_info->item;
while(item!=NULL){
rev = kk_tsl_utils_memtok(item->identity,'.',2,&startIdx2);
if(!rev){
kk_tsl_utils_memtok(item->identity,'.',1,&startIdx1);
......
......@@ -24,7 +24,8 @@ void kk_rpc_test(void);
{"kk_tsl_set_colorlight_RGB_red",kk_tsl_set_colorlight_RGB_red},\
{"kk_tsl_set_colorlight_RGB_green",kk_tsl_set_colorlight_RGB_green},\
{"kk_tsl_set_colorlight_RGB_blue",kk_tsl_set_colorlight_RGB_blue},\
{"kk_tsl_set_colorlight_Brightness",kk_tsl_set_colorlight_Brightness},\
{"kk_tsl_set_colorlight_Brightness",kk_tsl_set_colorlight_Brightness},\
{"kk_permit_join",kk_permit_join},\
}
#define KK_RPC_REPORT_FUNCTION_TABLE {\
......
#include "kk_sub_tsl.h"
typedef unsigned char EmberEUI64[8];
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 void _sub_dev_mutex_lock(void)
{
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
if (ctx->mutex) {
HAL_MutexLock(ctx->mutex);
}
}
static void _sub_dev_mutex_unlock(void)
{
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
if (ctx->mutex) {
HAL_MutexUnlock(ctx->mutex);
}
}
int kk_tsl_init(EmberEUI64 mac)
{
int res = 0;
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
ctx->mutex = HAL_MutexCreate();
if (ctx->mutex == NULL) {
return FAIL_RETURN;
}
ctx->sub_devid = 1;
INIT_LIST_HEAD(&ctx->dev_list);
kk_sub_tsl_add(mac,"2");
//usleep(1000000);
//kk_test();
return SUCCESS_RETURN;
}
static int _kk_tsl_check_exist(const char *deviceCode)
{
sub_dev_node_t *search_node = NULL;
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
if(deviceCode == NULL){
return INVALID_PARAMETER;
}
list_for_each_entry(search_node, &ctx->dev_list, linked_list, sub_dev_node_t) {
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
return SUCCESS_RETURN;
}
}
return FAIL_RETURN;
}
int kk_sub_tsl_add(EmberEUI64 device_mac,const char *productCode)
{
sub_dev_node_t *node = NULL;
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
char *tsl_str = NULL;
int res = 0;
char macString[19] = {0};
if(productCode == NULL)
{
return INVALID_PARAMETER;
}
rpc_eui64ToString(device_mac,macString);
if(_kk_tsl_check_exist(device_mac) == SUCCESS_RETURN){
return SUCCESS_RETURN;
}
node = malloc(sizeof(sub_dev_node_t));
if (node == NULL) {
return MEMORY_NOT_ENOUGH;
}
_sub_dev_mutex_lock();
memset(node,0,sizeof(sub_dev_node_t) );
memcpy(node->deviceCode, macString, strlen(macString));
memcpy(node->productCode, productCode, strlen(productCode));
INIT_LIST_HEAD(&node->linked_list);
list_add_tail(&node->linked_list, &ctx->dev_list);
_sub_dev_mutex_unlock();
return SUCCESS_RETURN;
}
int kk_sub_tsl_delete(EmberEUI64 device_mac)
{
sub_dev_node_t *node = NULL;
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
char *tsl_str = NULL;
int res = 0;
char macString[19] = {0};
rpc_eui64ToString(device_mac,macString);
_sub_dev_mutex_lock();
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
_sub_dev_mutex_unlock();
return FAIL_RETURN;
}
list_del(&node->linked_list);
free(node);
node = NULL;
_sub_dev_mutex_unlock();
return SUCCESS_RETURN;
}
int kk_sub_tsl_get_device_by_mac(_IN_ const char *deviceCode , _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->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
if (node) {
*node = search_node;
}
return SUCCESS_RETURN;
}
}
printf("Device Not Found, device_mac: %s\n", deviceCode);
return FAIL_RETURN;
}
#ifndef _KK_SUB_TSL_H_
#define _KK_SUB_TSL_H_
#include "kk_tsl_common.h"
#include "klist.h"
typedef struct {
char productCode[PRODUCT_TYPE_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN];
struct list_head linked_list;
} sub_dev_node_t;
#endif
#include "kk_test.h"
#include "kk_sub_tsl.h"
static void kk_rpc_send_message(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
{
static uint16_t msgid;
char msgIdString[10]= {0};
char macString[19] = {0};
sub_dev_node_t *node = NULL;
int res = 0;
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
printf("[%s][%d]kk_rpc_send_message error!!!\n",__FUNCTION__,__LINE__);
return;
}
......@@ -19,7 +18,7 @@ static void kk_rpc_send_message(cJSON *data,char *msgtype,char *method,EmberEUI6
cJSON *info = rpc_cJSON_CreateObject();
if(info != NULL){
rpc_cJSON_AddStringToObject(info, "msgType",msgtype);
rpc_cJSON_AddStringToObject(info, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(info, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode",macString);
}
cJSON *payload = rpc_cJSON_CreateObject();
......@@ -70,22 +69,21 @@ void kk_rpc_reportLeftDevices(EmberEUI64 mac)
{
cJSON* devicesJson;
char macString[RPC_EUI64_STRING_LENGTH];
sub_dev_node_t *node = NULL;
int res = 0;
EmberEUI64 gw_eui64 = {0};
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
res = kk_sub_tsl_get_device_by_mac(macString, &node);
if (res != SUCCESS_RETURN) {
printf("[%s][%d]kk_rpc_send_message error!!!\n",__FUNCTION__,__LINE__);
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
printf("[%s][%d]kk_rpc_reportLeftDevices error!!!\n",__FUNCTION__,__LINE__);
return;
}
devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddStringToObject(devicesJson, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
emberAfGetEui64(gw_eui64);
kk_rpc_report_left_devices(devicesJson,gw_eui64);
kk_sub_tsl_delete(mac);
kk_device_table_delete(mac);
......@@ -109,7 +107,6 @@ void kk_rpc_reportDevices(EmberEUI64 mac,const char* productCode)
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
rpc_cJSON_AddStringToObject(devicesJson, "mac",macString);
//
kk_sub_tsl_add(mac,productCode);
emberAfGetEui64(eui64);
kk_rpc_report_devices(devicesJson,eui64);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment