Commit 800ea9db authored by 黄振令's avatar 黄振令

【修改内容】串口连接的ncp网关,打开GATEWAY_TYPE_NCP,通过nanomsg连接,不需要局域网发现

parent 2cdff660
......@@ -32,6 +32,14 @@
#define GW2CCU_PROTOCOL "tcp"
//#define GATEWAY_TYPE_NCP
#ifdef GATEWAY_TYPE_NCP
#undef GW2CCU_PROTOCOL
#define GW2CCU_PROTOCOL "nanomsg"
#endif
......
......@@ -538,15 +538,63 @@ int kk_connect_check(){
void ipcHandle(void)
{
#ifdef GATEWAY_TYPE_NCP
kk_print_info( "Thread rpc Interface Parse create\n" );
_init_param(&my_server);
char* macString = kk_get_gw_mac();
if (macString == NULL){
kk_print_error("[%s] get mac fail, exit pthread !!!!!!!!!!!!!!!!!\n",__FUNCTION__);
return;
}
kk_ipc_init(IPC_PLAT2MID, _cb, macString, "127.0.0.1");
kk_print_info("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));
for(int i=0;i<sizeof(rpc_table)/sizeof(rpc_table_s);i++){
kk_print_debug("i=%d,%s\r\n",i,rpc_table[i].name);
jrpc_register_procedure(&my_server, rpc_table[i].func, rpc_table[i].name, NULL );
}
//send add gw to ccu
char* outbuf = _msg_topo_add();
if (outbuf == NULL){
kk_print_error("[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
kk_print_info("check nanomsg is connect(%d) \n", kk_ipc_isconnect(IPC_PLAT2MID));
kk_ipc_send(IPC_PLAT2MID, outbuf, strlen(outbuf) + 1);
free(outbuf);
char* postmsg = _msg_event_property_post("127.0.0.1",0);
if (postmsg == NULL){
kk_print_error("[%s] property_post msg failed\n",__FUNCTION__);
return;
}
kk_ipc_send(IPC_PLAT2MID, postmsg, strlen(postmsg) + 1);
free(postmsg);
//handle procidure
while(1){
//
usleep(20000);
}
#else
char deviceCode[33] = {0};
char ip[16] = {0};
int port = 0;
emberAfAppPrint( "Thread rpc Interface Parse create\n" );
kk_print_info( "Thread rpc Interface Parse create\n" );
search_ccu(deviceCode, ip, &port);
_init_param(&my_server);
char* macString = kk_get_gw_mac();
if (macString == NULL){
printf("[%s] get mac fail, exit pthread !!!!!!!!!!!!!!!!!\n",__FUNCTION__);
kk_print_error("[%s] get mac fail, exit pthread !!!!!!!!!!!!!!!!!\n",__FUNCTION__);
return;
}
if(strcmp(GW2CCU_PROTOCOL, "tcp") == 0){
......@@ -555,9 +603,9 @@ void ipcHandle(void)
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));
kk_print_info("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));
for(int i=0;i<sizeof(rpc_table)/sizeof(rpc_table_s);i++){
emberAfAppPrint("i=%d,%s\r\n",i,rpc_table[i].name);
kk_print_info("i=%d,%s\r\n",i,rpc_table[i].name);
jrpc_register_procedure(&my_server, rpc_table[i].func, rpc_table[i].name, NULL );
}
......@@ -565,11 +613,11 @@ void ipcHandle(void)
char* outbuf = _msg_topo_add();
if (outbuf == NULL){
printf("[%s] topo add msg failed, exit\n",__FUNCTION__);
kk_print_error("[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
if (strcmp(GW2CCU_PROTOCOL, "tcp") != 0){
printf("check nanomsg is connect(%d) \n", kk_ipc_isconnect(IPC_PLAT2MID));
kk_print_info("check nanomsg is connect(%d) \n", kk_ipc_isconnect(IPC_PLAT2MID));
}
kk_sendData2CCU(outbuf, strlen(outbuf));
free(outbuf);
......@@ -585,9 +633,9 @@ void ipcHandle(void)
char gwIp[17] = {0};
HAL_Get_IP(gwIp,NULL);
char* postmsg = _msg_event_property_post(gwIp,port);
if (outbuf == NULL){
if (postmsg == NULL){
printf("[%s] property_post msg failed\n",__FUNCTION__);
kk_print_error("[%s] property_post msg failed\n",__FUNCTION__);
continue;
}
kk_sendData2CCU(postmsg, strlen(postmsg));
......@@ -608,7 +656,7 @@ void ipcHandle(void)
outbuf = _msg_topo_add();
if (outbuf == NULL){
printf("[%s] topo add msg failed, exit\n",__FUNCTION__);
kk_print_error("[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
kk_sendData2CCU(outbuf, strlen(outbuf));
......@@ -619,8 +667,7 @@ void ipcHandle(void)
}
//jrpc_server_run(&my_server);
//jrpc_server_destroy(&my_server);
#endif
}
......
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