Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
1984c81c
Commit
1984c81c
authored
Sep 03, 2020
by
黄振令
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】网关连接主机不上,开始重新发现机制,防止主机ip地址变化,而无法连接
【提交人】huang.zhenling
parent
aab93033
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
21 deletions
+85
-21
common/api/tcp_channel.c
common/api/tcp_channel.c
+59
-18
platform/zigbee/app/builder/Z3GatewayHost/libapi_com_ubuntu.so
...orm/zigbee/app/builder/Z3GatewayHost/libapi_com_ubuntu.so
+0
-0
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
...p/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
+26
-3
No files found.
common/api/tcp_channel.c
View file @
1984c81c
...
...
@@ -6,6 +6,10 @@
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include "com_api.h"
#define CCU_TCP_PORT 16565
...
...
@@ -554,14 +558,14 @@ typedef struct {
char
ip
[
MAX_IP_LEN
];
int
port
;
ipc_cb
*
cb
;
int
retry
;
}
kk_tcp_client_t
;
static
kk_tcp_client_t
g_client_ctrl
=
{
NULL
,
-
1
,
0
,{
0
},
0
,
NULL
};
static
kk_tcp_client_t
g_client_ctrl
=
{
NULL
,
-
1
,
0
,{
0
},
0
,
NULL
,
0
};
static
int
_init_client
(){
memset
(
&
g_client_ctrl
,
0
,
sizeof
(
kk_tcp_client_t
));
/* Create Mutex */
g_client_ctrl
.
mutex
=
_MutexCreate
();
if
(
g_client_ctrl
.
mutex
==
NULL
)
{
return
-
1
;
...
...
@@ -601,14 +605,14 @@ static int client_socket_init(int *sd, char *ipaddr, uint16_t port)
}
//连接
int
retry
=
0
;
for
(;
retry
<
10
;
retry
++
){
for
(;
retry
<
3
;
retry
++
){
if
(
-
1
!=
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))){
break
;
}
printf
(
"==================connect retry=%d
\n
"
,
retry
);
//
printf("==================connect retry=%d \n", retry);
sleep
(
1
);
}
if
(
retry
>=
10
){
if
(
retry
>=
3
){
printf
(
"==================connect failed
\n
"
);
goto
err2
;
}
...
...
@@ -626,28 +630,56 @@ static void loop_tcp_client_thread(void *arg){
printf
(
"loop_tcp_client_thread start!
\r\n
"
);
char
buf
[
1024
]
=
{
0
};
int
ret
=
0
;
fd_set
fds
;
struct
timeval
timeout
=
{
0
,
200
};
//select等待3秒,3秒轮询,要非阻塞就置0
while
(
1
){
if
(
-
1
==
client_socket_init
(
&
g_client_ctrl
.
sd
,
g_client_ctrl
.
ip
,
g_client_ctrl
.
port
)){
printf
(
"connect failed
\n
"
);
sleep
(
1
);
g_client_ctrl
.
retry
++
;
continue
;
}
g_client_ctrl
.
isConnect
=
1
;
g_client_ctrl
.
retry
=
0
;
while
(
g_client_ctrl
.
isConnect
){
FD_ZERO
(
&
fds
);
//每次循环都要清空集合,否则不能检测描述符变化
FD_SET
(
g_client_ctrl
.
sd
,
&
fds
);
//添加描述符
switch
(
select
(
g_client_ctrl
.
sd
+
1
,
&
fds
,
NULL
,
NULL
,
&
timeout
))
//select使用
{
case
-
1
:
g_client_ctrl
.
isConnect
=
0
;
printf
(
" [%s] select error ret=%d
\n
"
,
__FUNCTION__
,
ret
);
break
;
//select错误 退出循环
case
0
:
break
;
//再次轮询
default:
if
(
FD_ISSET
(
g_client_ctrl
.
sd
,
&
fds
))
//测试sock是否可读,即是否网络上有数据
{
//接受网络数据
_MutexLock
(
g_client_ctrl
.
mutex
);
ret
=
read
(
g_client_ctrl
.
sd
,
buf
,
sizeof
(
buf
));
_MutexUnlock
(
g_client_ctrl
.
mutex
);
if
(
-
1
==
ret
){
//printf("=================read error \n");
//break ;
if
(
ret
<=
0
){
printf
(
"=================read error ret=%d
\n
"
,
ret
);
if
(
errno
!=
EINTR
){
g_client_ctrl
.
isConnect
=
0
;
printf
(
"read error reconnect!!
\n
"
);
break
;
}
}
else
if
(
ret
>
0
){
printf
(
"buf = %s
\n
"
,
buf
);
if
(
g_client_ctrl
.
cb
!=
NULL
){
g_client_ctrl
.
cb
(
buf
,
ret
,
""
);
}
}
}
break
;
usleep
(
100000
);
}
// end switch
//usleep(100000);
}
printf
(
"network error, try connect again!
\n
"
);
...
...
@@ -658,6 +690,14 @@ static void loop_tcp_client_thread(void *arg){
}
int
kk_get_retry_num
(){
return
g_client_ctrl
.
retry
;
}
int
kk_reset_retry_num
(){
return
g_client_ctrl
.
retry
=
0
;
}
int
kk_tcp_client_send
(
char
*
data
,
int
len
){
int
ret
=
0
;
int
cnt
=
0
;
...
...
@@ -698,6 +738,7 @@ int kk_tcp_client_init(char ip[MAX_IP_LEN], int port, ipc_cb cb)
kk_tcp_client_deinit
(){
if
(
g_client_ctrl
.
sd
>
-
1
){
close
(
g_client_ctrl
.
sd
);
g_client_ctrl
.
sd
=
-
1
;
}
_MutexDestroy
(
g_client_ctrl
.
mutex
);
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/libapi_com_ubuntu.so
View file @
1984c81c
No preview for this file type
platform/zigbee/app/builder/Z3GatewayHost/rpc_api/src/rpc_interface_parse.c
View file @
1984c81c
...
...
@@ -369,6 +369,7 @@ int search_ccu(char devcode[33], char ip[16], int* port){
return
-
1
;
}
printf
(
"[%s] start search ccu!!
\n
"
,
__FUNCTION__
);
while
(
1
)
{
if
((
iSendbytes
=
sendto
(
sock
,
sendMessage
,
strlen
(
sendMessage
)
+
1
,
0
,
(
struct
sockaddr
*
)
&
Addrto
,
sizeof
(
struct
sockaddr
)))
==
-
1
)
...
...
@@ -487,7 +488,6 @@ void* _msg_event_property_post(char ip[16], int port){
}
void
ipcHandle
(
void
)
{
char
deviceCode
[
33
]
=
{
0
};
...
...
@@ -513,6 +513,8 @@ void ipcHandle(void)
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
){
...
...
@@ -546,10 +548,31 @@ void ipcHandle(void)
free
(
postmsg
);
}
if
(
kk_get_retry_num
()
>
20
){
//discover ccu
search_ccu
(
deviceCode
,
ip
,
&
port
);
if
(
strcmp
(
GW2CCU_PROTOCOL
,
"tcp"
)
==
0
){
kk_tcp_client_init
(
ip
,
port
,
_cb
);
}
else
{
//kk_ipc_init(IPC_PLAT2MID, _cb, macString/*GW_DEVICE_CODE*/, ip);
}
//send add gw to ccu
outbuf
=
_msg_topo_add
();
if
(
outbuf
==
NULL
){
printf
(
"[%s] topo add msg failed, exit
\n
"
,
__FUNCTION__
);
return
;
}
kk_sendData2CCU
(
outbuf
,
strlen
(
outbuf
));
free
(
outbuf
);
cnt
=
0
;
kk_reset_retry_num
();
}
}
//jrpc_server_run(&my_server);
//jrpc_server_destroy(&my_server);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment