Commit 4d5b2765 authored by chen.weican's avatar chen.weican

【修改内容】恢复之前修改的关于gw mac的获取

【提交人】陈伟灿
parent 8bb38811
...@@ -87,6 +87,7 @@ cJSON * test_func(jrpc_context * ctx, cJSON * params, cJSON *id) { ...@@ -87,6 +87,7 @@ cJSON * test_func(jrpc_context * ctx, cJSON * params, cJSON *id) {
static int send_result_resp(cJSON * result, static int send_result_resp(cJSON * result,
cJSON * id) { cJSON * id) {
#if 0
int return_value = 0; int return_value = 0;
cJSON *info_root = rpc_cJSON_CreateObject(); cJSON *info_root = rpc_cJSON_CreateObject();
if(info_root){ if(info_root){
...@@ -115,11 +116,15 @@ static int send_result_resp(cJSON * result, ...@@ -115,11 +116,15 @@ static int send_result_resp(cJSON * result,
free(str_result); free(str_result);
rpc_cJSON_Delete(result_root); rpc_cJSON_Delete(result_root);
return return_value; return return_value;
#else
return 0;
#endif
} }
static int send_error_resp(int code, char* message, static int send_error_resp(int code, char* message,
cJSON * id) { cJSON * id) {
#if 0
int return_value = 0; int return_value = 0;
cJSON *edata; cJSON *edata;
...@@ -155,6 +160,9 @@ static int send_error_resp(int code, char* message, ...@@ -155,6 +160,9 @@ static int send_error_resp(int code, char* message,
rpc_cJSON_Delete(result_root); rpc_cJSON_Delete(result_root);
free(message); free(message);
return return_value; return return_value;
#else
return 0;
#endif
} }
static int invoke_procedure(struct jrpc_server *server, static int invoke_procedure(struct jrpc_server *server,
...@@ -266,6 +274,21 @@ int _init_param(struct jrpc_server *server) { ...@@ -266,6 +274,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 +306,14 @@ int search_ccu(char devcode[33], char ip[16], int* port){ ...@@ -283,7 +306,14 @@ 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__);
...@@ -425,13 +455,17 @@ int search_ccu(char devcode[33], char ip[16], int* port){ ...@@ -425,13 +455,17 @@ int search_ccu(char devcode[33], char ip[16], int* port){
} }
#define GW_PRODUCT_CODE "2" #define GW_PRODUCT_CODE "2"
#define GW_MAC GW_DEVICE_CODE
void* _msg_topo_add(){ 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_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 +481,13 @@ void* _msg_event_property_post(char ip[16], int port){ ...@@ -447,8 +481,13 @@ 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,
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);
...@@ -465,10 +504,15 @@ void ipcHandle(void) ...@@ -465,10 +504,15 @@ void ipcHandle(void)
emberAfAppPrint( "Thread rpc Interface Parse create\n" ); emberAfAppPrint( "Thread rpc Interface Parse create\n" );
search_ccu(deviceCode, ip, &port); search_ccu(deviceCode, ip, &port);
_init_param(&my_server); _init_param(&my_server);
char* macString = kk_get_gw_mac();
if (macString == NULL){
printf("[%s] get mac fail, exit pthread !!!!!!!!!!!!!!!!!\n",__FUNCTION__);
return;
}
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, 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 +523,11 @@ void ipcHandle(void) ...@@ -479,6 +523,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 +542,14 @@ void ipcHandle(void) ...@@ -493,7 +542,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);
} }
......
...@@ -486,7 +486,7 @@ void emAfDeviceTableLoad(void) ...@@ -486,7 +486,7 @@ void emAfDeviceTableLoad(void)
deviceTable[i].clusterOutStartPosition = (uint16_t) data; deviceTable[i].clusterOutStartPosition = (uint16_t) data;
deviceTable[i].state = EMBER_AF_PLUGIN_DEVICE_TABLE_STATE_JOINED; deviceTable[i].state = EMBER_AF_PLUGIN_DEVICE_TABLE_STATE_JOINED;
kk_sub_tsl_add(deviceTable[i].eui64,TEST_PRODUCT_CODE); //kk_sub_tsl_add(deviceTable[i].eui64,TEST_PRODUCT_CODE);
} }
deviceTable[i].lastMsgTimestamp = halCommonGetInt32uMillisecondTick(); deviceTable[i].lastMsgTimestamp = halCommonGetInt32uMillisecondTick();
......
...@@ -503,7 +503,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -503,7 +503,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
kk_print("*******************123****************\r\n"); kk_print("*******************123****************\r\n");
kk_print_info("\r\n-----hello world![%s:%s]-----\r\n",__DATE__,__TIME__); kk_print_info("\r\n-----hello world![%s:%s]-----\r\n",__DATE__,__TIME__);
kk_print_version(); kk_print_version();
kk_tsl_init();
emberSerialInit(APP_SERIAL, BAUD_RATE, PARITY_NONE, 1); //fock child process emberSerialInit(APP_SERIAL, BAUD_RATE, PARITY_NONE, 1); //fock child process
emberAfAppPrintln("Reset info: %d (%p)", emberAfAppPrintln("Reset info: %d (%p)",
...@@ -542,7 +542,8 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -542,7 +542,8 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
emberAfGetEui64(eui64); emberAfGetEui64(eui64);
emberAfCorePrintln("~~~~~~~~~~~~~~~~~~~~~NCP MAC:"); emberAfCorePrintln("~~~~~~~~~~~~~~~~~~~~~NCP MAC:");
emberAfPrintBigEndianEui64(eui64); emberAfPrintBigEndianEui64(eui64);
//kk_network_check();
kk_tsl_init(eui64);
pthread_t tid; pthread_t tid;
...@@ -556,6 +557,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -556,6 +557,7 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
EmberNetworkStatus Status = ezspNetworkState(); EmberNetworkStatus Status = ezspNetworkState();
kk_print("ezspNetworkState()~~~~~~[%d]\r\n",Status); kk_print("ezspNetworkState()~~~~~~[%d]\r\n",Status);
// main loop // main loop
......
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