Commit 00e102f8 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

prevent j2000 tracker from hogging the cpu

parent 14b372fb
...@@ -667,21 +667,27 @@ int main(int argc, char **argv) ...@@ -667,21 +667,27 @@ int main(int argc, char **argv)
if (fd_cmd >= high) if (fd_cmd >= high)
high = fd_cmd + 1; high = fd_cmd + 1;
} }
if (trace_fd(traceval_el) < 0) {
printf("Reconnect elevation trace\n");
sleep(1);
trace_init(trace_host, trace_port, el_trace_name,
traceval_el);
}
if (trace_fd(traceval_el) >= 0) { if (trace_fd(traceval_el) >= 0) {
FD_SET(trace_fd(traceval_el), &fdset_rx); FD_SET(trace_fd(traceval_el), &fdset_rx);
if (trace_fd(traceval_el) >= high) if (trace_fd(traceval_el) >= high)
high = trace_fd(traceval_el) + 1; high = trace_fd(traceval_el) + 1;
} else { }
trace_init(trace_host, trace_port, el_trace_name, if (trace_fd(traceval_az) < 0) {
traceval_el); printf("Reconnect azimuth trace\n");
sleep(1);
trace_init(trace_host, trace_port, az_trace_name,
traceval_az);
} }
if (trace_fd(traceval_az) >= 0) { if (trace_fd(traceval_az) >= 0) {
FD_SET(trace_fd(traceval_az), &fdset_rx); FD_SET(trace_fd(traceval_az), &fdset_rx);
if (trace_fd(traceval_az) >= high) if (trace_fd(traceval_az) >= high)
high = trace_fd(traceval_az) + 1; high = trace_fd(traceval_az) + 1;
} else {
trace_init(trace_host, trace_port, az_trace_name,
traceval_az);
} }
fdset_cmd_clients(&fdset_rx, &high); fdset_cmd_clients(&fdset_rx, &high);
......
...@@ -164,28 +164,28 @@ int setpoint_command_setpoint(struct setpoint_command *sp_cmd, float sp) ...@@ -164,28 +164,28 @@ int setpoint_command_setpoint(struct setpoint_command *sp_cmd, float sp)
f.f = sp; f.f = sp;
*(uint32_t*)arg = htonl(f.u); *(uint32_t*)arg = htonl(f.u);
do { if (sp_cmd->fd < 0) {
while (sp_cmd->fd == -1) { sleep(1);
sleep(1); sp_cmd->fd = tcp_connect(
sp_cmd->fd = tcp_connect( sp_cmd->host, sp_cmd->port);
sp_cmd->host, sp_cmd->port); setpoint_command_init_spg(sp_cmd);
setpoint_command_init_spg(sp_cmd); if (sp_cmd->fd < 0)
} return 1;
}
ret = write(sp_cmd->fd, command, 4); ret = write(sp_cmd->fd, command, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
if (ret != 4) { if (ret != 4) {
printf("Connection to controller command socket lost.\n"); printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd); close(sp_cmd->fd);
sp_cmd->fd = -1; sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
}
} }
} while (ret != 4); }
return 0; return 0;
} }
...@@ -201,28 +201,28 @@ int setpoint_command_speed(struct setpoint_command *sp_cmd, float speed) ...@@ -201,28 +201,28 @@ int setpoint_command_speed(struct setpoint_command *sp_cmd, float speed)
f.f = speed; f.f = speed;
*(uint32_t*)arg = htonl(f.u); *(uint32_t*)arg = htonl(f.u);
do { if (sp_cmd->fd < 0) {
while (sp_cmd->fd == -1) { sleep(1);
sleep(1); sp_cmd->fd = tcp_connect(
sp_cmd->fd = tcp_connect( sp_cmd->host, sp_cmd->port);
sp_cmd->host, sp_cmd->port); setpoint_command_init_spg(sp_cmd);
setpoint_command_init_spg(sp_cmd); if (sp_cmd->fd < 0)
} return 1;
}
ret = write(sp_cmd->fd, command, 4); ret = write(sp_cmd->fd, command, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
if (ret != 4) { if (ret != 4) {
printf("Connection to controller command socket lost.\n"); printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd); close(sp_cmd->fd);
sp_cmd->fd = -1; sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
}
} }
} while (ret != 4); }
return 0; return 0;
} }
...@@ -240,30 +240,28 @@ int setpoint_command_setpoint_time(struct setpoint_command *sp_cmd, ...@@ -240,30 +240,28 @@ int setpoint_command_setpoint_time(struct setpoint_command *sp_cmd,
*(uint32_t*)arg = htonl(f.u); *(uint32_t*)arg = htonl(f.u);
*(uint32_t*)&arg[4] = htonl(sptime); *(uint32_t*)&arg[4] = htonl(sptime);
do { if (sp_cmd->fd < 0) {
if (sp_cmd->fd == -1) { sleep(1);
sp_cmd->fd = tcp_connect( sp_cmd->fd = tcp_connect(
sp_cmd->host, sp_cmd->port); sp_cmd->host, sp_cmd->port);
if (sp_cmd->fd < 0) { setpoint_command_init_spg(sp_cmd);
return 1; if (sp_cmd->fd < 0)
} return 1;
setpoint_command_init_spg(sp_cmd); }
}
ret = write(sp_cmd->fd, command, 4); ret = write(sp_cmd->fd, command, 4);
if (ret != 4) { if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 8);
if (ret != 8) {
printf("Connection to controller command socket lost.\n"); printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd); close(sp_cmd->fd);
sp_cmd->fd = -1; sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 8);
if (ret != 8) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
}
} }
} while (ret != 4 && ret != 8); }
return 0; return 0;
} }
...@@ -273,21 +271,21 @@ int setpoint_command_setpoint_any(struct setpoint_command *sp_cmd, ...@@ -273,21 +271,21 @@ int setpoint_command_setpoint_any(struct setpoint_command *sp_cmd,
{ {
int ret; int ret;
do { if (sp_cmd->fd < 0) {
while (sp_cmd->fd == -1) { sleep(1);
sleep(1); sp_cmd->fd = tcp_connect(
sp_cmd->fd = tcp_connect( sp_cmd->host, sp_cmd->port);
sp_cmd->host, sp_cmd->port); setpoint_command_init_spg(sp_cmd);
setpoint_command_init_spg(sp_cmd); if (sp_cmd->fd < 0)
} return 1;
}
ret = write(sp_cmd->fd, cmd, len); ret = write(sp_cmd->fd, cmd, len);
if (ret != len) { if (ret != len) {
printf("Connection to controller command socket lost.\n"); printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd); close(sp_cmd->fd);
sp_cmd->fd = -1; sp_cmd->fd = -1;
} }
} while (ret != len);
return 0; return 0;
} }
Supports Markdown
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