Commit 87d2de68 authored by 尹佳钦's avatar 尹佳钦

Merge branch 'master' of http://172.17.3.10:17001/chenweican/k-sdk

# Conflicts:
#	platform/zigbee/app/builder/Z3GatewayHost/Makefile
parents ea981073 a9d72488
...@@ -10,12 +10,16 @@ CFLAGS += -I$(TOP_DIR)/common/api ...@@ -10,12 +10,16 @@ CFLAGS += -I$(TOP_DIR)/common/api
CFLAGS += -I$(TOP_DIR)/common/json CFLAGS += -I$(TOP_DIR)/common/json
CFLAGS += -I$(TOP_DIR)/common/nanomsg/include CFLAGS += -I$(TOP_DIR)/common/nanomsg/include
CFLAGS += -I$(TOP_DIR)/common/ev/include CFLAGS += -I$(TOP_DIR)/common/ev/include
CFLAGS += -I$(TOP_DIR)/common/sqlite LDFLAGS += -lkk_tsl
LDFLAGS += -lapi_com -lkk_tsl LDFLAGS += -lapi_com
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg ifeq ($(CONFIG_VENDOR),ubuntu)
LDFLAGS += -L$(TOP_DIR)/common/ev -lev LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu
LDFLAGS += -L$(TOP_DIR)/output/release/lib -lapi_com LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu
LDFLAGS += -liot_cjson -liot_mqtt -lsqlite -ldl -lm -lanl -lkk_hal else
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg
LDFLAGS += -L$(TOP_DIR)/common/ev -lev
endif
LDFLAGS += -liot_cjson -liot_mqtt -ldl -lm -lanl -lkk_hal -lzlog
LIBSO_TARGET := libapi_com.so LIBSO_TARGET := libapi_com.so
LIBA_TARGET := libapi_com.a
CFLAGS += -I$(TOP_DIR)/common/nanomsg/include CFLAGS += -I$(TOP_DIR)/common/nanomsg/include
CFLAGS += -I$(TOP_DIR)/common/ev/include CFLAGS += -I$(TOP_DIR)/common/ev/include
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -static -lnanomsg
LDFLAGS += -L$(TOP_DIR)/common/ev -static -lev ifeq ($(CONFIG_VENDOR),ubuntu)
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu
LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu
else
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg
LDFLAGS += -L$(TOP_DIR)/common/ev -lev
endif
LDFLAGS += -ldl LDFLAGS += -ldl
\ No newline at end of file
...@@ -196,6 +196,26 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){ ...@@ -196,6 +196,26 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){
return -1; return -1;
} }
int kk_set_tcp_channel_by_idx(int idx, char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
int i = 0;
if(idx >= MAX_LISTEN_NUM){
printf("kk_set_tcp_channel_by_idx idx[] need less than %d \n", idx, MAX_LISTEN_NUM);
return - 1;
}
if (devCode == NULL || strlen(devCode) == 0 || ip == NULL || strlen(ip) == 0){
return -1;
}
//printf("[%s] devCode=%s \n", __FUNCTION__,devCode);
memcpy(g_tcp_ctrl[idx].deviceCode, devCode, strlen(devCode));
memcpy(g_tcp_ctrl[idx].ip, ip, strlen(ip));
return 0;
}
int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
int i = 0; int i = 0;
int isEmptyIdx = -1; int isEmptyIdx = -1;
...@@ -210,7 +230,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ ...@@ -210,7 +230,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
if(strcmp(devCode, g_tcp_ctrl[i].deviceCode) == 0){ if(strcmp(devCode, g_tcp_ctrl[i].deviceCode) == 0){
strncpy(g_tcp_ctrl[i].ip, ip, strlen(ip)); strncpy(g_tcp_ctrl[i].ip, ip, strlen(ip));
printf("find and replace it [%d][%s][%s] \n",i, g_tcp_ctrl[i].ip, devCode); printf("find and replace it [%d][%s][%s] \n",i, g_tcp_ctrl[i].ip, devCode);
kk_gw_list_save(); //kk_gw_list_save();
break; break;
} }
...@@ -228,7 +248,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ ...@@ -228,7 +248,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
strncpy(g_tcp_ctrl[isEmptyIdx].ip, ip, strlen(ip)); strncpy(g_tcp_ctrl[isEmptyIdx].ip, ip, strlen(ip));
strncpy(g_tcp_ctrl[isEmptyIdx].deviceCode, devCode, strlen(devCode)); strncpy(g_tcp_ctrl[isEmptyIdx].deviceCode, devCode, strlen(devCode));
printf("idx deviceCode ip[%d][%s][%s]",isEmptyIdx, g_tcp_ctrl[isEmptyIdx].deviceCode, g_tcp_ctrl[isEmptyIdx].ip); printf("idx deviceCode ip[%d][%s][%s]",isEmptyIdx, g_tcp_ctrl[isEmptyIdx].deviceCode, g_tcp_ctrl[isEmptyIdx].ip);
kk_gw_list_save(); //kk_gw_list_save();
return 0; return 0;
} }
...@@ -433,9 +453,11 @@ int kk_TCP_channel_init(ipc_cb cb) ...@@ -433,9 +453,11 @@ int kk_TCP_channel_init(ipc_cb cb)
return -1; return -1;
} }
g_init = 1; g_init = 1;
memset(g_tcp_ctrl, 0, sizeof(kk_tcp_ctrl_t)*MAX_LISTEN_NUM); //memset(g_tcp_ctrl, 0, sizeof(kk_tcp_ctrl_t)*MAX_LISTEN_NUM);
kk_gw_list_load(); //kk_gw_list_load();
for(i = 0; i < MAX_LISTEN_NUM; i++){
g_tcp_ctrl[i].sock = -1;
}
if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) { if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) {
printf("create pthread failed\r\n"); printf("create pthread failed\r\n");
...@@ -639,7 +661,7 @@ static void loop_tcp_client_thread(void *arg){ ...@@ -639,7 +661,7 @@ static void loop_tcp_client_thread(void *arg){
int kk_tcp_client_send(char* data, int len){ int kk_tcp_client_send(char* data, int len){
int ret = 0; int ret = 0;
int cnt = 0; int cnt = 0;
if ( data != NULL && g_client_ctrl.isConnect == 1){ if ( data != NULL){
while(g_client_ctrl.sd == -1 && cnt < 5){ while(g_client_ctrl.sd == -1 && cnt < 5){
printf("[%s] tcp don't connect, sleep 1s !!!! \n",__FUNCTION__); printf("[%s] tcp don't connect, sleep 1s !!!! \n",__FUNCTION__);
sleep(1); sleep(1);
......
LIBA_TARGET := libkk_hal.a LIBSO_TARGET := libkk_hal.so
\ No newline at end of file \ No newline at end of file
LIBA_TARGET := libsqlite.a LIBA_TARGET := libsqlite.a
LDFLAGS += -ldl
\ No newline at end of file
LIBSO_TARGET := libzlog.so LIBSO_TARGET := libzlog.so
LIBA_TARGET := libzlog.a #LIBA_TARGET := libzlog.a
...@@ -148,7 +148,7 @@ static int _dm_init_tsl_params(int devId) ...@@ -148,7 +148,7 @@ static int _dm_init_tsl_params(int devId)
} }
return res; return res;
} }
int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode ) int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode,int devType )
{ {
int num = 0,idx = 0; int num = 0,idx = 0;
kk_tsl_data_t *pProperty = NULL; kk_tsl_data_t *pProperty = NULL;
...@@ -163,7 +163,7 @@ int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode ) ...@@ -163,7 +163,7 @@ int dm_mgr_properities_db_create(kk_tsl_t* dev_shadow,char *deviceCode )
pProperty = dev_shadow->properties+idx; pProperty = dev_shadow->properties+idx;
INFO_PRINT("dm_mgr_properities_db_create pProperty->identifier:%s!!\n",pProperty->identifier); INFO_PRINT("dm_mgr_properities_db_create pProperty->identifier:%s!!\n",pProperty->identifier);
if(pProperty){ if(pProperty){
kk_property_db_insert(deviceCode,pProperty->identifier,pProperty->data_value.type); kk_property_db_insert(deviceCode,pProperty->identifier,pProperty->data_value.type,devType);
} }
} }
} }
...@@ -224,7 +224,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA ...@@ -224,7 +224,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA
return FAIL_RETURN; return FAIL_RETURN;
} }
} }
dm_mgr_properities_db_create(node->dev_shadow,deviceCode); dm_mgr_properities_db_create(node->dev_shadow,deviceCode,dev_type);
INIT_LIST_HEAD(&node->linked_list); INIT_LIST_HEAD(&node->linked_list);
list_add_tail(&node->linked_list, &ctx->dev_list); list_add_tail(&node->linked_list, &ctx->dev_list);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "sqlite3.h" #include "sqlite3.h"
#include "kk_log.h" #include "kk_log.h"
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "kk_property_db.h"
#define KK_PROPERTIES_DB_FILE "kk_properties.db" #define KK_PROPERTIES_DB_FILE "kk_properties.db"
...@@ -18,6 +19,7 @@ typedef enum{ ...@@ -18,6 +19,7 @@ typedef enum{
DB_IDENTIFITER, DB_IDENTIFITER,
DB_VALUE, DB_VALUE,
DB_VALUETYPE, DB_VALUETYPE,
DB_DEVTYPE
}; };
static kk_property_db_ctx_t s_kk_property_db_ctx = {0}; static kk_property_db_ctx_t s_kk_property_db_ctx = {0};
...@@ -60,7 +62,8 @@ static int kk_property_db_Init(void) ...@@ -60,7 +62,8 @@ static int kk_property_db_Init(void)
deviceCode varchar(33), \ deviceCode varchar(33), \
identifier varchar(33), \ identifier varchar(33), \
value varchar(33), \ value varchar(33), \
valueType INTEGER)"; valueType INTEGER, \
devType INTEGER)";
char *pcErr; char *pcErr;
// DBG_vPrintf(DBG_SQL, "Execute SQL: '%s'\n", pConditionTableDef); // DBG_vPrintf(DBG_SQL, "Execute SQL: '%s'\n", pConditionTableDef);
...@@ -129,10 +132,10 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie ...@@ -129,10 +132,10 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie
} }
int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype) int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int devtype)
{ {
const char *insertCmd = "insert into PropertiesInfo (deviceCode,identifier,value,valueType) \ const char *insertCmd = "insert into PropertiesInfo (deviceCode,identifier,value,valueType,devType) \
values ('%s','%s','%s','%d');"; values ('%s','%s','%s','%d','%d');";
char *sqlCmd = NULL; char *sqlCmd = NULL;
int rc = 0; int rc = 0;
char *zErrMsg = 0; char *zErrMsg = 0;
...@@ -145,7 +148,7 @@ int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_d ...@@ -145,7 +148,7 @@ int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_d
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
_kk_property_db_lock(); _kk_property_db_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,"",valuetype); sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,"",valuetype,devtype);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
...@@ -183,6 +186,93 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co ...@@ -183,6 +186,93 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_property_db_get_value(const char *deviceCode,const char *identifier,void* value)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
int valueType = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE deviceCode= '%s' and identifier = '%s'",deviceCode,identifier);
DEBUG_PRINT("kk_property_db_get_value sqlCmd:%s\n",sqlCmd);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
valueStr = sqlite3_column_text(stmt, DB_VALUE);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
int value_int = atoi(valueStr);
*(int*)value = value_int;
}
else if(valueType == KK_TSL_DATA_TYPE_FLOAT){
float value_float = atoi(valueStr);
*(float*)value = value_float;
}
else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
double value_double = atoi(valueStr);
*(double*)value = value_double;
}
else{
memcpy(value,valueStr, strlen(valueStr));
}
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_prop_raw_struct_t* raw, int count)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
char *devcode = NULL;
int valueType = 0;
int idx = 0;
kk_prop_raw_struct_t *curData = NULL;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE devType= '%d' and identifier = '%s'",dev_type,identifier);
DEBUG_PRINT("kk_property_db_get_gw_value sqlCmd:%s\n",sqlCmd);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
curData = raw;
while(sqlite3_step(stmt) == SQLITE_ROW && idx < count){
devcode = sqlite3_column_text(stmt, DB_DEVICECODE);
valueStr = sqlite3_column_text(stmt, DB_VALUE);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
memcpy(curData->deviceCode,devcode, strlen(devcode));
memcpy(curData->raw,valueStr, strlen(valueStr));
curData->type = valueType;
curData++;
idx++;
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_property_db_update(const char *deviceCode) int kk_property_db_update(const char *deviceCode)
{ {
int res = 0; int res = 0;
...@@ -283,6 +373,7 @@ int kk_property_sync_values(const char *deviceCode) ...@@ -283,6 +373,7 @@ int kk_property_sync_values(const char *deviceCode)
} }
sqlite3_free(sqlCmd);
_kk_property_db_unlock(); _kk_property_db_unlock();
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
#define _KK_PROPERTY_DB_H_ #define _KK_PROPERTY_DB_H_
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
typedef struct{
int type;
char deviceCode[DEVICE_CODE_MAXLEN];
char raw[60];
}kk_prop_raw_struct_t;
int kk_property_db_init(void); int kk_property_db_init(void);
#endif #endif
......
LIBA_TARGET := libmid_test.a LIBA_TARGET := libmid.a
$(call Append_Conditional, LIB_SRCS_EXCLUDE, midware.c) $(call Append_Conditional, LIB_SRCS_EXCLUDE, midware.c)
$(call Append_Conditional, SRCS_midware, midware.c) $(call Append_Conditional, SRCS_midware, midware.c)
...@@ -11,6 +11,12 @@ CFLAGS += -I$(TOP_DIR)/common/sqlite ...@@ -11,6 +11,12 @@ CFLAGS += -I$(TOP_DIR)/common/sqlite
CFLAGS += -I$(TOP_DIR)/common/zlog CFLAGS += -I$(TOP_DIR)/common/zlog
CFLAGS += -I$(TOP_DIR)/src/tsl/tsl_handle CFLAGS += -I$(TOP_DIR)/src/tsl/tsl_handle
LDFLAGS += -lapi_com -liot_cjson -lkk_tsl LDFLAGS += -lapi_com -liot_cjson -lkk_tsl
LDFLAGS += -lsqlite -ldl -lm LDFLAGS += -lm -lkk_hal -lzlog
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg -lanl LDFLAGS += -lsqlite -ldl
LDFLAGS += -L$(TOP_DIR)/common/ev -lev -lkk_hal ifeq ($(CONFIG_VENDOR),ubuntu)
\ No newline at end of file LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu -lanl
LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu
else
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg -lanl
LDFLAGS += -L$(TOP_DIR)/common/ev -lev
endif
\ No newline at end of file
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "kk_log.h" #include "kk_log.h"
#include "kk_dm_queue.h" #include "kk_dm_queue.h"
#include "kk_property_db.h"
char * g_filerToPlatTable[] = char * g_filerToPlatTable[] =
...@@ -323,6 +324,7 @@ void *ota_dispatch_yield(void *args) ...@@ -323,6 +324,7 @@ void *ota_dispatch_yield(void *args)
#define UDP_LAN_PORT 25556 #define UDP_LAN_PORT 25556
#define UDP_LAN_PORT_HOST 25555 #define UDP_LAN_PORT_HOST 25555
#define test_ #define test_
void *udp_dispatch_yield(void *args){ void *udp_dispatch_yield(void *args){
...@@ -381,7 +383,16 @@ void *udp_dispatch_yield(void *args){ ...@@ -381,7 +383,16 @@ void *udp_dispatch_yield(void *args){
char mac[32] = {0}; char mac[32] = {0};
char device_code[DEVICE_CODE_LEN] = {0}; char device_code[DEVICE_CODE_LEN] = {0};
int devId = 0; int devId = 0;
kk_prop_raw_struct_t ipList[10] = {0};
int idx = 0;
kk_property_db_get_rawdata("IPAddress",4, ipList, sizeof(ipList));
for(; idx < 10; idx++){
DEBUG_PRINT("ipList[%d][%s][%s] \n", idx, ipList[idx].deviceCode, ipList[idx].raw);
if (strlen(ipList[idx].deviceCode)>0 && strlen(ipList[idx].raw)>0){
kk_set_tcp_channel_by_idx(idx, ipList[idx].deviceCode, ipList[idx].raw);
}
}
kk_TCP_channel_init(gw2mid_cb); kk_TCP_channel_init(gw2mid_cb);
while(1) while(1)
......
...@@ -34,14 +34,19 @@ ...@@ -34,14 +34,19 @@
# or # or
# "cd app/builder/Z3GatewayHost; make INCLUDE_MAKEFILE=my-custom.mak" # "cd app/builder/Z3GatewayHost; make INCLUDE_MAKEFILE=my-custom.mak"
# #
CONFIG_VENDOR = ubuntu
ifdef INCLUDE_MAKEFILE ifdef INCLUDE_MAKEFILE
include $(INCLUDE_MAKEFILE) include $(INCLUDE_MAKEFILE)
endif endif
ifeq ($(CONFIG_VENDOR),ubuntu)
COMPILER ?= gcc COMPILER ?= gcc
LINKER ?= gcc LINKER ?= gcc
ARCHIVE ?= ar ARCHIVE ?= ar
else
COMPILER ?= mips-openwrt-linux-gcc
LINKER ?= mips-openwrt-linux-gcc
ARCHIVE ?= mips-openwrt-linux-ar
endif
STD ?= gnu99 STD ?= gnu99
ARCHIVE_EXTENSION ?= .a ARCHIVE_EXTENSION ?= .a
...@@ -322,14 +327,18 @@ DEPENDENCY_POST_PROCESS ?= ...@@ -322,14 +327,18 @@ DEPENDENCY_POST_PROCESS ?=
CPPFLAGS= $(INCLUDES) $(DEFINES) $(COMPILER_FLAGS) $(DEPENDENCY_FLAGS) CPPFLAGS= $(INCLUDES) $(DEFINES) $(COMPILER_FLAGS) $(DEPENDENCY_FLAGS)
LINKER_FLAGS ?= LINKER_FLAGS ?=
ifdef NO_READLINE
CPPFLAGS += -DNO_READLINE ifeq ($(CONFIG_VENDOR),ubuntu)
LINKER_FLAGS += \
-lreadline_ubuntu \
-lncurses_ubuntu
else else
LINKER_FLAGS += \ LINKER_FLAGS += \
-lreadline \ -lreadline \
-lncurses -lncurses
endif endif
# Conditionally include the math library if EM_AF_LINK_M is defined. # Conditionally include the math library if EM_AF_LINK_M is defined.
ifeq ($(findstring -DEM_AF_LINK_M,$(DEFINES)),-DEM_AF_LINK_M) ifeq ($(findstring -DEM_AF_LINK_M,$(DEFINES)),-DEM_AF_LINK_M)
LINKER_FLAGS += \ LINKER_FLAGS += \
...@@ -361,8 +370,13 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES) ...@@ -361,8 +370,13 @@ $(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. -lapi_com -lnanomsg -lanl -pthread -lev -ltinfo -o $(TARGET_FILE) ifeq ($(CONFIG_VENDOR),ubuntu)
$(LD) $^ $(LINKER_FLAGS) -lm -L. -lapi_com_ubuntu -lnanomsg_ubuntu -lanl -pthread -lev_ubuntu -lkk_hal_ubuntu -o $(TARGET_FILE)
@echo -e '\n$@ build success' @echo -e '\n$@ build success'
else
$(LD) $^ $(LINKER_FLAGS) -lm -L. -lapi_com -lnanomsg -lanl -pthread -lev -lkk_hal -o $(TARGET_FILE)
@echo -e '\n$@ build success'
endif
endif endif
.PHONY: clean .PHONY: clean
......
...@@ -266,7 +266,21 @@ int _init_param(struct jrpc_server *server) { ...@@ -266,7 +266,21 @@ int _init_param(struct jrpc_server *server) {
return 0; return 0;
} }
char g_mac[19] = {0};
char* kk_get_gw_mac(){
int cnt = 0;
EmberEUI64 eui64;
emberAfGetEui64(eui64);
while(eui64[0] ==0 && eui64[1] ==0 && eui64[2] == 0 && cnt++ < 3){
sleep(1);
}
if (eui64[0] ==0 && eui64[1] ==0 && eui64[2] == 0){
printf("get gw mac error !!! \n");
return NULL;
}
rpc_eui64ToString(eui64,g_mac);
return g_mac;
}
int search_ccu(char devcode[33], char ip[16], int* port){ int search_ccu(char devcode[33], char ip[16], int* port){
...@@ -283,7 +297,13 @@ int search_ccu(char devcode[33], char ip[16], int* port){ ...@@ -283,7 +297,13 @@ int search_ccu(char devcode[33], char ip[16], int* port){
struct sockaddr_in Addrto; struct sockaddr_in Addrto;
struct sockaddr_in AddrRev; struct sockaddr_in AddrRev;
sprintf(sendMessage,sendCmdFmt,GW_DEVICE_CODE,GW2CCU_PROTOCOL); char* macString = kk_get_gw_mac();
if (macString == NULL){
printf("[%s] get mac fail\n",__FUNCTION__);
return -1;
}
sprintf(sendMessage,sendCmdFmt,macString/*GW_DEVICE_CODE*/,GW2CCU_PROTOCOL);
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{ {
printf("[%s] socket fail\n",__FUNCTION__); printf("[%s] socket fail\n",__FUNCTION__);
...@@ -431,7 +451,12 @@ void* _msg_topo_add(){ ...@@ -431,7 +451,12 @@ void* _msg_topo_add(){
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\ char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}"; \"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}";
char msg[520] = {0}; char msg[520] = {0};
sprintf(msg, msgFmt, GW_PRODUCT_CODE, GW_DEVICE_CODE, 1, GW_DEVICE_CODE, GW_PRODUCT_CODE,GW_MAC); char* macString = kk_get_gw_mac();
if (macString == NULL){
printf("[%s] get mac fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString, 1, macString/*GW_DEVICE_CODE*/, GW_PRODUCT_CODE,macString);
cJSON* msgObj = cJSON_Parse(msg); cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj); char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj); cJSON_Delete(msgObj);
...@@ -447,8 +472,14 @@ void* _msg_event_property_post(char ip[16], int port){ ...@@ -447,8 +472,14 @@ void* _msg_event_property_post(char ip[16], int port){
\"time\":1524448722000,\"method\":\"thing.event.property.post\"}\ \"time\":1524448722000,\"method\":\"thing.event.property.post\"}\
}"; }";
char msg[620] = {0}; char msg[620] = {0};
sprintf(msg, msgFmt, GW_PRODUCT_CODE, GW_DEVICE_CODE, char* macString = kk_get_gw_mac();
1, 0, 0, 0, "12345", ip,GW_MAC,port); if (macString == NULL){
printf("[%s] get mac fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString/*GW_DEVICE_CODE*/,
1, 0, 0, 0, "12345", ip,macString, port);
cJSON* msgObj = cJSON_Parse(msg); cJSON* msgObj = cJSON_Parse(msg);
char* outbuf = cJSON_Print(msgObj); char* outbuf = cJSON_Print(msgObj);
cJSON_Delete(msgObj); cJSON_Delete(msgObj);
...@@ -464,11 +495,16 @@ void ipcHandle(void) ...@@ -464,11 +495,16 @@ void ipcHandle(void)
int port = 0; int port = 0;
emberAfAppPrint( "Thread rpc Interface Parse create\n" ); emberAfAppPrint( "Thread rpc Interface Parse create\n" );
search_ccu(deviceCode, ip, &port); search_ccu(deviceCode, ip, &port);
char* macString = kk_get_gw_mac();
if (macString == NULL){
printf("[%s] get mac fail, exit pthread !!!!!!!!!!!!!!!!!\n",__FUNCTION__);
return;
}
_init_param(&my_server); _init_param(&my_server);
if(strcmp(GW2CCU_PROTOCOL, "tcp") == 0){ if(strcmp(GW2CCU_PROTOCOL, "tcp") == 0){
kk_tcp_client_init(ip, port, _cb); kk_tcp_client_init(ip, port, _cb);
}else{ }else{
kk_ipc_init(IPC_PLAT2MID, _cb, GW_DEVICE_CODE, ip); kk_ipc_init(IPC_PLAT2MID, _cb, macString/*GW_DEVICE_CODE*/, ip);
} }
emberAfAppPrint("sizeof(rpc_table)=%d,sizeof(rpc_table_s)=%d,%d\n",sizeof(rpc_table),sizeof(rpc_table_s),sizeof(rpc_table)/sizeof(rpc_table_s)); emberAfAppPrint("sizeof(rpc_table)=%d,sizeof(rpc_table_s)=%d,%d\n",sizeof(rpc_table),sizeof(rpc_table_s),sizeof(rpc_table)/sizeof(rpc_table_s));
...@@ -479,6 +515,11 @@ void ipcHandle(void) ...@@ -479,6 +515,11 @@ void ipcHandle(void)
//send add gw to ccu //send add gw to ccu
char* outbuf = _msg_topo_add(); char* outbuf = _msg_topo_add();
if (outbuf == NULL){
printf("[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
if (strcmp(GW2CCU_PROTOCOL, "tcp") != 0){ if (strcmp(GW2CCU_PROTOCOL, "tcp") != 0){
printf("check nanomsg is connect(%d) \n", kk_ipc_isconnect(IPC_PLAT2MID)); printf("check nanomsg is connect(%d) \n", kk_ipc_isconnect(IPC_PLAT2MID));
} }
...@@ -493,7 +534,14 @@ void ipcHandle(void) ...@@ -493,7 +534,14 @@ void ipcHandle(void)
cnt++; cnt++;
if (cnt == 2){ if (cnt == 2){
sleep(1); sleep(1);
char* postmsg = _msg_event_property_post(ip,port); char gwIp[17] = {0};
HAL_Get_IP(gwIp,NULL);
char* postmsg = _msg_event_property_post(gwIp,port);
if (outbuf == NULL){
printf("[%s] property_post msg failed\n",__FUNCTION__);
continue;
}
kk_sendData2CCU(postmsg, strlen(postmsg)); kk_sendData2CCU(postmsg, strlen(postmsg));
free(postmsg); free(postmsg);
} }
......
...@@ -516,10 +516,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -516,10 +516,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
return -1; return -1;
} }
pthread_t tid;
//pthread_create(&tid, NULL, rpcInterfaceParse, NULL);
pthread_create(&tid, NULL, ipcHandle, NULL);
/*int pid=fork(); /*int pid=fork();
...@@ -546,6 +543,12 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -546,6 +543,12 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
emberAfCorePrintln("~~~~~~~~~~~~~~~~~~~~~NCP MAC:"); emberAfCorePrintln("~~~~~~~~~~~~~~~~~~~~~NCP MAC:");
emberAfPrintBigEndianEui64(eui64); emberAfPrintBigEndianEui64(eui64);
pthread_t tid;
//pthread_create(&tid, NULL, rpcInterfaceParse, NULL);
pthread_create(&tid, NULL, ipcHandle, NULL);
// initialize the ZCL framework ,(plug in) ,mqtt init is here // initialize the ZCL framework ,(plug in) ,mqtt init is here
emAfInit(); emAfInit();
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
......
CONFIG_ENV_CFLAGS += \
-Os -Wall \
-g3 --coverage \
-D_PLATFORM_IS_LINUX_ \
CONFIG_ENV_CFLAGS += \
-DWITH_MQTT_DYN_BUF=1 \
-DWITH_MEM_STATS=0 \
-DWITH_MEM_STATS_PER_MODULE=0 \
-DWITH_MQTT_JSON_FLOW=1 \
-DWITH_MQTT_ZIP_TOPIC=1 \
-DWITH_MQTT_SUB_SHORTCUT=1 \
-DSDK_TEAM_TEST \
-D_GNU_SOURCE \
CONFIG_ENV_CFLAGS += \
-DCONFIG_HTTP_AUTH_TIMEOUT=500 \
-DCONFIG_MID_HTTP_TIMEOUT=500 \
-DCONFIG_GUIDER_AUTH_TIMEOUT=500 \
-DCONFIG_MQTT_RX_MAXLEN=5000 \
-DCONFIG_MBEDTLS_DEBUG_LEVEL=0 \
CONFIG_ENV_CFLAGS += -rdynamic
CONFIG_ENV_CFLAGS += -Wno-unused -std=c99
CONFIG_ENV_LDFLAGS += -lpthread -lrt
OVERRIDE_CC = mips-openwrt-linux-gcc
OVERRIDE_AR = mips-openwrt-linux-ar
OVERRIDE_LD = mips-openwrt-linux-ld
CROSS_PREFIX = mips-openwrt-linux-
OVERRIDE_STRIP := strip
...@@ -104,13 +104,13 @@ done ...@@ -104,13 +104,13 @@ done
\$(Q)mkdir -p \$\$(dirname \$@) \$(Q)mkdir -p \$\$(dirname \$@)
\$(Q)S=\$\$(echo \$@|sed 's,${OUTPUT_DIR},${TOP_DIR},1'); \\ \$(Q)S=\$\$(echo \$@|sed 's,${OUTPUT_DIR},${TOP_DIR},1'); \\
if echo \$\${S//.o/.c} | grep -q 'mbedtls\|HAL_\|hal-impl'; then \\ if echo \$\${S//.o/.c} | grep -q 'mbedtls\|HAL_\|hal-impl'; then \\
${CC} -c \\ ${CC} -c -fPIC\\
-o \$@ \\ -o \$@ \\
\$(filter-out -ansi,\$(CFLAGS)) \\ \$(filter-out -ansi,\$(CFLAGS)) \\
\$(IFLAGS) \\ \$(IFLAGS) \\
\$\${S//.o/.c}; \\ \$\${S//.o/.c}; \\
else \\ else \\
${CC} -c \\ ${CC} -c -fPIC\\
-o \$@ \\ -o \$@ \\
\$(CFLAGS) \\ \$(CFLAGS) \\
\$(IFLAGS) \\ \$(IFLAGS) \\
...@@ -206,7 +206,7 @@ for i in ${ALL_PROG}; do ...@@ -206,7 +206,7 @@ for i in ${ALL_PROG}; do
cat << EOB >> ${TARGET_FILE} cat << EOB >> ${TARGET_FILE}
${OUTPUT_DIR}/usr/bin/${i}: \\ ${OUTPUT_DIR}/usr/bin/${i}: \\
${EXTRA_SRCS} \\ ${EXTRA_SRCS} \\
$(for m in ${j} ${OUTPUT_DIR}/usr/lib/${COMP_LIB} ${ALL_LIBS} ${ALL_LIBSO}; do $(for m in ${j} ${OUTPUT_DIR}/usr/lib/${COMP_LIB} ${ALL_LIBS}; do
echo " ${m} \\"|sed 's!//*!/!g'; echo " ${m} \\"|sed 's!//*!/!g';
done) done)
......
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