Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michel Roelofs
dt_ctrl
Commits
1027ba5b
Commit
1027ba5b
authored
May 13, 2017
by
Tammo Jan Dijkema
Browse files
Add trace2port
parent
c3d4895a
Changes
2
Hide whitespace changes
Inline
Side-by-side
common/trace/build.mk
View file @
1027ba5b
...
...
@@ -6,6 +6,7 @@ TRACE_TARGETS += $(DIR)/trace_dumpdiff
TRACE_TARGETS
+=
$(DIR)
/trace_list
TRACE_TARGETS
+=
$(DIR)
/trace_view
TRACE_TARGETS
+=
$(DIR)
/trace2file
TRACE_TARGETS
+=
$(DIR)
/trace2port
ARCHSRCS
:=
$(DIR)
/trace.c
$(DIR)
/trace_tcp.c
...
...
@@ -54,6 +55,12 @@ $(DIR)/trace2file: libtrace.la
$(DIR)/
trace2file_LDFLAGS
+=
-ltrace
$(DIR)/trace2file
:
$(TRACE2FILE_OBJS)
TRACE2PORT_SRCS
:=
$(DIR)
/trace2port.c
TRACE2PORT_OBJS
:=
$(TRACE2PORT_SRCS:.c=.o)
$(DIR)/trace2port.o
:
CFLAGS += -Wall -O3
$(DIR)/
trace2port_LDFLAGS
+=
-lm
-ltrace
$(DIR)/trace2port
:
libtrace.la
$(DIR)/trace2port
:
$(TRACE2PORT_OBJS)
TARGETS
+=
$(TRACE_TARGETS)
SRCS
+=
$(ARCHSRCS)
...
...
@@ -63,6 +70,7 @@ SRCS += $(TRACE_FFT_SRCS)
SRCS
+=
$(TRACE_LIST_SRCS)
SRCS
+=
$(TRACE_VIEW_SRCS)
SRCS
+=
$(TRACE2FILE_SRCS)
SRCS
+=
$(TRACE2PORT_SRCS)
CLEAN
+=
$(TRACE_TARGETS)
$(ARCHOBJS)
$(LIBDIR)
/libtrace.a
CLEAN
+=
$(TRACE_DUMP_OBJS)
CLEAN
+=
$(TRACE_DUMPDIFF_OBJS)
...
...
@@ -70,3 +78,4 @@ CLEAN += $(TRACE_FFT_OBJS)
CLEAN
+=
$(TRACE_LIST_OBJS)
CLEAN
+=
$(TRACE_VIEW_OBJS)
CLEAN
+=
$(TRACE2FILE_OBJS)
CLEAN
+=
$(TRACE2PORT_OBJS)
common/trace/trace2port.c
0 → 100644
View file @
1027ba5b
/*
Program to echo a trace periodically in plain text to a port
Based on work from Jeroen Vreeken (pe1rxq@amsat.org)
Adapted by Tammo Jan Dijkema (t.j.dijkema@camras.nl)
Copyright Stichting C.A. Muller Radioastronomiestation, 2017
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<time.h>
#include
<sys/time.h>
#include
<unistd.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
<string.h>
#include
<fcntl.h>
#include
<termios.h>
#include
<signal.h>
#include
<ctype.h>
#include
<inttypes.h>
#include
<arpa/inet.h>
#include
<sys/select.h>
#include
<sys/ioctl.h>
#include
<errno.h>
#include
<stdbool.h>
#include
<command/command.h>
#include
<trace/trace.h>
#include
<dt_port_numbers.h>
#include
<utils/status_server.h>
#include
<utils/dt_host.h>
#include
<log/log.h>
#define TIME_OFFSET 2
char
*
trace_host
=
"consoledemo.dmz.camras.nl"
;
int
trace_port
=
CONSOLE_TRACE_PORT
;
int
stat_port
=
11042
;
void
output
(
struct
status_server
*
stat_srv
,
int
ntraces
,
struct
trace
**
tracevals
)
{
static
time_t
last
=
0
;
time_t
now
;
time_t
now_t
=
time
(
NULL
);
char
statline
[
200
];
int
do_output
=
1
;
int
tracenum
;
now
=
tracevals
[
0
]
->
value
.
t
.
tv_sec
;
for
(
tracenum
=
0
;
tracenum
<
ntraces
;
++
tracenum
)
{
if
(
tracevals
[
tracenum
]
->
value
.
t
.
tv_sec
!=
now
)
{
do_output
=
0
;
}
}
if
(
now_t
-
now
>
2
)
{
printf
(
"No trace for more than 2 seconds, using last known position
\n
"
);
now
=
now_t
;
}
if
(
now
<=
last
)
{
do_output
=
0
;
}
if
(
do_output
==
0
)
{
return
;
}
else
{
last
=
now
;
}
int
statlinelen
=
0
;
for
(
tracenum
=
0
;
tracenum
<
ntraces
;
++
tracenum
)
{
printf
(
"%f "
,
tracevals
[
tracenum
]
->
value
.
value
.
f
*
360
.
0
/
(
2
*
M_PI
));
statlinelen
+=
sprintf
(
statline
+
statlinelen
,
"%f "
,
tracevals
[
tracenum
]
->
value
.
value
.
f
*
360
.
0
/
(
2
*
M_PI
));
}
printf
(
"
\n
"
);
sprintf
(
statline
+
statlinelen
,
"
\n
"
);
status_server_send
(
stat_srv
,
statline
);
}
static
void
handler_interval
(
struct
trace
*
trace
,
struct
timespec
*
interval
,
enum
trace_interval_type
type
)
{
printf
(
"interval: %ld.%09ld
\n
"
,
interval
->
tv_sec
,
interval
->
tv_nsec
);
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
printf
(
"Usage: %s Azimuth_Position Elevation_Position azimuth_setpoint_error.difference elevation_setpoint_error.difference
\n
"
,
argv
[
0
]);
return
1
;
}
int
ntraces
=
argc
-
1
;
struct
trace
*
tracevals
[
ntraces
];
struct
status_server
*
stat_srv
;
time_t
lastt
=
0
;
struct
timespec
t_int
;
signal
(
SIGPIPE
,
SIG_IGN
);
log_client_start
(
dt_host_console
(),
CONSOLE_LOG_PORT_IN
,
LOG_T_DEBUG
,
LOG_T_INFO
,
"console/j2000tracker"
);
printf
(
"Number of traces: %d
\n
"
,
ntraces
);
t_int
.
tv_sec
=
1
;
t_int
.
tv_nsec
=
0
;
int
tracenum
;
for
(
tracenum
=
0
;
tracenum
<
ntraces
;
++
tracenum
)
{
tracevals
[
tracenum
]
=
trace_open
(
trace_host
,
trace_port
);
trace_name_set
(
tracevals
[
tracenum
],
0
,
argv
[
tracenum
+
1
]);
trace_autorecover
(
tracevals
[
tracenum
],
true
);
tracevals
[
tracenum
]
->
handler_interval
=
handler_interval
;
trace_interval_set
(
tracevals
[
tracenum
],
&
t_int
,
TRACE_INTERVAL_TYPE_INTERVAL
);
}
stat_srv
=
status_server_create
(
stat_port
,
0
,
100
);
while
(
1
)
{
time_t
t
;
int
high
=
0
;
fd_set
fdset_rx
;
struct
timeval
tv
;
t
=
time
(
NULL
);
if
(
t
!=
lastt
)
{
lastt
=
t
;
t
+=
TIME_OFFSET
;
}
FD_ZERO
(
&
fdset_rx
);
status_server_fdset_add
(
stat_srv
,
&
fdset_rx
,
&
high
);
for
(
tracenum
=
0
;
tracenum
<
ntraces
;
++
tracenum
)
{
trace_fd_set
(
tracevals
[
tracenum
],
&
fdset_rx
,
&
high
);
}
tv
.
tv_sec
=
1
;
tv
.
tv_usec
=
0
;
select
(
high
+
1
,
&
fdset_rx
,
NULL
,
NULL
,
&
tv
);
for
(
tracenum
=
0
;
tracenum
<
ntraces
;
++
tracenum
)
{
trace_handle
(
tracevals
[
tracenum
],
&
fdset_rx
);
}
status_server_fdset_handle
(
stat_srv
,
&
fdset_rx
);
output
(
stat_srv
,
ntraces
,
tracevals
);
}
}
Write
Preview
Supports
Markdown
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