Commit af90a653 authored by chen.weican's avatar chen.weican

【修改内容】1,修改zigbee端根据modelId映射productCode后导致控制无反应的BUG;

【提交人】陈伟灿
parent 65243975
......@@ -136,7 +136,7 @@ void mid2p_cb(void* data, int len, char* chalMark){
queue_msg->data = buf;
memset(queue_msg->chalMark, 0, sizeof(queue_msg->chalMark));
if(chalMark != NULL){
memcpy(queue_msg->chalMark, chalMark, sizeof(chalMark));
memcpy(queue_msg->chalMark, chalMark, strlen(chalMark));
}
res = dm_queue_msg_insert2((void *)queue_msg);
if (res != SUCCESS_RETURN) {
......
......@@ -65,7 +65,8 @@ static void kk_device_fill(kk_device_table_s *ptr,EmberEUI64 mac,EmberNodeId nod
ptr->deviceId = deviceId;
ptr->identifyCnt = KK_MAX_READ_MODLE_ID_COUNT;
ptr->productCode = productCode;
memcpy(ptr->productCode,productCode,strlen(productCode));
}
kk_device_table_s * kk_device_find_by_mac(EmberEUI64 mac)
......@@ -115,6 +116,7 @@ void kk_device_table_add(EmberEUI64 mac,EmberNodeId nodeId,const char *productCo
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 ;
......@@ -347,6 +349,7 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
kk_device_table_s *ptr = kk_zb_device_table;
EmberEUI64 eui64;
uint8_t modelID[33] = {0};
char *pCode = NULL;
while(ptr!=NULL){
if(ptr->nodeId == nodeId){
emberAfCorePrintln("[match tsl]node:0x%04X,status:0x%02x,dataType:0x%02x",nodeId,status,dataType);
......@@ -357,8 +360,12 @@ static void kk_device_modle_id_identify(EmberNodeId nodeId,
emberAfCorePrintln("[warring]modle id size = %d,max = 32!!!");
}
memcpy(modelID,data,dataSize);
ptr->productCode = kk_match_tsl_productCode(modelID);
pCode = kk_match_tsl_productCode(modelID);
if(pCode == NULL){
emberAfCorePrintln("not match pCode!!!");
return;
}
memcpy(ptr->productCode,pCode,strlen(pCode));
if(ptr->productCode!=NULL){
if(emberAfDeviceTableGetEui64FromNodeId(ptr->nodeId,eui64)){
kk_rpc_reportDevices(eui64,ptr->productCode);
......
......@@ -15,7 +15,7 @@ typedef struct kk_device_table_s{
EmberNodeId nodeId;
uint16_t deviceId;
uint16_t identifyCnt;
char *productCode;
char productCode[33];
struct kk_device_table_s *next;
}kk_device_table_s;
#define KK_MAX_SUPPORT_ENDPOINT_NUMBER 32
......
......@@ -53,11 +53,12 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
uint8_t *data)
{
int i,j,num,status;
char macString[19] = {0};
sub_dev_node_t *node = NULL;
int res = 0;
UTIL_LOG_INFO("\n********************kk tsl report attribute********************\n");
emberAfDebugPrint("mac:");
emberAfGetEui64(eui64);
emberAfPrintBigEndianEui64(eui64);
emberAfDebugPrintln(",ep:%d,clu:0x%04X,attr:0x%04X,dataType=0x%02x,len=%d,data:",
EP,clusterId,attributeId,dataType,len);
emberAfDebugPrintBuffer(data,len,true);
......@@ -72,6 +73,24 @@ void kk_tsl_report_attribute(EmberEUI64 eui64,
return ;
}
}
rpc_eui64ToString(eui64,macString);
res = kk_sub_tsl_get_device_by_mac(macString,&node);
if(res != tsl_rpt_success){
emberAfAppPrintln("[kk_tsl_report_attribute] error~~~~~~~~~\n");
return;
}
num = kk_get_tsl_glb_num();
for(i=0;i<num;i++){
if( g_tsl_zigbee_map_glb[i].map.clusterId == clusterId &&
g_tsl_zigbee_map_glb[i].map.attributeId == attributeId &&
strncmp(node->productCode,g_tsl_zigbee_map_glb[i].ProductCode,strlen(node->productCode)) == 0 &&
g_tsl_zigbee_map_glb[i].map.zigbee_report!=NULL){
status = g_tsl_zigbee_map_glb[i].map.zigbee_report(eui64,EP,clusterId,attributeId,dataType,len,data);
emberAfDebugPrintln("--report status:%s",kk_tsl_rpt_status_string[status]);
return ;
}
}
}
......
......@@ -38,7 +38,7 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
break;
}
}
if(findFlag==false){
if(findFlag==0xff){
num = kk_get_tsl_glb_num();
for(index = 0; index < num; index++){
propertyItem = rpc_cJSON_GetObjectItem(params, g_tsl_zigbee_map_glb[index].map.Identity);
......@@ -68,9 +68,9 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
emberAfPrintBigEndianEui64(eui64);
emberAfDebugPrintln(",node:0x%04X",nodeId);
if(findFlag==1)
res = g_tsl_zigbee_map[index].zigbee_set(ctx,mac->valuestring,g_tsl_zigbee_map[index].endpoint,&value);
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,mac->valuestring,g_tsl_zigbee_map[index].endpoint,&value);
res = g_tsl_zigbee_map_glb[index].map.zigbee_set(ctx,nodeId,g_tsl_zigbee_map_glb[index].map.endpoint,&value);
if(res < 0)
{
......
......@@ -14,71 +14,12 @@ static kk_sub_dev_ctx_t * _sub_dev_get_ctx(void)
{
return &g_sub_dev_mgr;
}
static void *_sub_MutexCreate(void)
{
int err_num;
pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
if (NULL == mutex)
{
return NULL;
}
if (0 != (err_num = pthread_mutex_init(mutex, NULL)))
{
printf("create mutex failed\n");
free(mutex);
return NULL;
}
return mutex;
}
static void _sub_MutexLock(void *mutex)
{
int err_num;
if (0 != (err_num = pthread_mutex_lock((pthread_mutex_t *)mutex)))
{
printf("lock mutex failed: - '%s' (%d)\n", strerror(err_num), err_num);
}
}
static void _sub_MutexUnLock(void *mutex)
{
int err_num;
if (0 != (err_num = pthread_mutex_unlock((pthread_mutex_t *)mutex)))
{
printf("unlock mutex failed - '%s' (%d)\n", strerror(err_num), err_num);
}
}
static void _sub_MutexDestroy(void *mutex)
{
int err_num;
if (!mutex)
{
printf("mutex want to destroy is NULL!\n");
return;
}
if (0 != (err_num = pthread_mutex_destroy((pthread_mutex_t *)mutex)))
{
printf("destroy mutex failed\n");
}
free(mutex);
}
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) {
_sub_MutexLock(ctx->mutex);
HAL_MutexLock(ctx->mutex);
}
}
......@@ -86,26 +27,43 @@ static void _sub_dev_mutex_unlock(void)
{
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
if (ctx->mutex) {
_sub_MutexUnLock(ctx->mutex);
HAL_MutexUnlock(ctx->mutex);
}
}
int kk_tsl_init(void)
int kk_tsl_init(EmberEUI64 mac)
{
int res = 0;
EmberEUI64 testMac = {0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11};
kk_sub_dev_ctx_t *ctx = _sub_dev_get_ctx();
ctx->mutex = _sub_MutexCreate();
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(testMac,"2");
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;
......@@ -119,17 +77,17 @@ int kk_sub_tsl_add(EmberEUI64 device_mac,const char *productCode)
}
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->device_mac, macString, strlen(macString));
memcpy(node->deviceCode, macString, strlen(macString));
memcpy(node->productCode, productCode, strlen(productCode));
node->devid = _sub_tsl_next_devid();
INIT_LIST_HEAD(&node->linked_list);
list_add_tail(&node->linked_list, &ctx->dev_list);
......@@ -159,32 +117,22 @@ int kk_sub_tsl_delete(EmberEUI64 device_mac)
return SUCCESS_RETURN;
}
int kk_sub_tsl_get_device_by_mac(_IN_ char device_mac[DEVICE_MAC_MAXLEN], _OU_ sub_dev_node_t **node)
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->device_mac) == strlen(device_mac)) &&
(memcmp(search_node->device_mac, device_mac, strlen(device_mac)) == 0)) {
if ((strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
if (node) {
*node = search_node;
}
_sub_dev_mutex_unlock();
return SUCCESS_RETURN;
}
}
printf("Device Not Found, device_mac: %s\n", device_mac);
printf("Device Not Found, device_mac: %s\n", deviceCode);
return FAIL_RETURN;
}
int kk_test(void)
{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//kk_test_fuc("112233445566",DM_MSG_REQUEST);
//kk_get_Identity_Num(0);
return 0;
}
......@@ -4,9 +4,8 @@
#include "klist.h"
typedef struct {
int devid;
char productCode[PRODUCT_TYPE_MAXLEN];
char device_mac[DEVICE_MAC_MAXLEN];
char deviceCode[DEVICE_CODE_MAXLEN];
struct list_head linked_list;
} sub_dev_node_t;
......
......@@ -10,13 +10,20 @@ static void kk_rpc_send_message(cJSON *data,char *msgtype,char *method,EmberEUI6
static uint16_t msgid;
char msgIdString[10]= {0};
char macString[19] = {0};
sub_dev_node_t *node = NULL;
int res = 0;
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__);
return;
}
cJSON *info = rpc_cJSON_CreateObject();
if(info != NULL){
rpc_cJSON_AddStringToObject(info, "msgType",msgtype);
rpc_cJSON_AddStringToObject(info, "productCode","2");
rpc_eui64ToString(mac,macString);
rpc_cJSON_AddStringToObject(info, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode",macString);
}
cJSON *payload = rpc_cJSON_CreateObject();
......@@ -66,19 +73,22 @@ typedef struct{
void kk_rpc_reportLeftDevices(EmberEUI64 mac)
{
cJSON* devicesJson;
//EmberEUI64 testMac = {0x4A,0x83,0xD3,0xFE,0xFF,0x81,0x8E,0x58};
EmberEUI64 testMac_GW = {0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11};
char macString[RPC_EUI64_STRING_LENGTH];
sub_dev_node_t *node = NULL;
int res = 0;
EmberEUI64 gw_eui64 = {0};
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
devicesJson = rpc_cJSON_CreateObject();
rpc_eui64ToString(mac,macString);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
rpc_cJSON_AddStringToObject(devicesJson, "productCode",TEST_PRODUCT_CODE);
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__);
return;
}
devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddStringToObject(devicesJson, "productCode",node->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
kk_rpc_report_left_devices(devicesJson,testMac_GW);
emberAfGetEui64(gw_eui64);
kk_rpc_report_left_devices(devicesJson,gw_eui64);
kk_sub_tsl_delete(mac);
kk_device_table_delete(mac);
......@@ -93,23 +103,11 @@ int kk_sendData2CCU(char* data, int len){
}
}
void kk_rpc_reportDevices(EmberEUI64 mac,const char* productCode)
{
cJSON* devicesJson;
char macString[19] = {0};
EmberEUI64 eui64 = {0};
UTIL_LOG_WARNING("report tsl product code:%s\n",productCode);
emberAfPrintBigEndianEui64(mac);
......@@ -122,7 +120,8 @@ void kk_rpc_reportDevices(EmberEUI64 mac,const char* productCode)
rpc_cJSON_AddStringToObject(devicesJson, "mac",macString);
//
kk_sub_tsl_add(mac,productCode);
kk_rpc_report_devices(devicesJson,mac);
emberAfGetEui64(eui64);
kk_rpc_report_devices(devicesJson,eui64);
}
......
......@@ -25,7 +25,6 @@
#define TEST_PRODUCT_CODE "24"
#define GW2CCU_PROTOCOL "tcp"
#define GW_DEVICE_CODE "1122334455667788"
......
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