Skip to content
GitLab
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
55846590
Commit
55846590
authored
Mar 15, 2013
by
Jeroen Vreeken
Browse files
Remove old console_easycomm stuff
parent
5517c99d
Changes
6
Hide whitespace changes
Inline
Side-by-side
console/README
View file @
55846590
...
...
@@ -18,8 +18,6 @@ Programs
command_shell Command line tool to send commands to a setpoint
generator.
console_easycomm Control (and view) the controller DT with easycomm.
console_joystick Control the DT with a joystick.
console_moontracker Track the moon.
...
...
console/console/.gitignore
View file @
55846590
...
...
@@ -2,7 +2,6 @@ await_controller
command_shell
console_azel
console_dt_model
console_easycomm
console_httpline
console_httptrace
console_idle
...
...
console/console/Makefile
View file @
55846590
...
...
@@ -9,7 +9,7 @@ LIBNOVA=-lnova -L../../lib/
RELEASE_FILE
=
../../release/console.tar.gz
all
:
lib/libaa.la lib/libpredict.la
\
setpoint.o
console_easycomm
console_joystick command_shell
\
setpoint.o console_joystick command_shell
\
spg_list spg_log_parser
\
console_moontracker
\
console_httptrace
\
...
...
@@ -30,8 +30,6 @@ release: $(RELEASE_FILE)
await_controller
:
await_controller.o
console_easycomm
:
console_easycomm.o setpoint.o
console_httptrace
:
console_httptrace.o
console_joystick
:
console_joystick.o setpoint.o
...
...
@@ -127,7 +125,6 @@ clean:
command_shell
\
console_joystick
\
console_dt_model
\
console_easycomm
\
console_httptrace
\
console_manual
\
console_moontracker
\
...
...
@@ -145,11 +142,11 @@ clean:
spg_auth
\
spg_list
\
spg_log_parser
\
status.cgi
status.cgi
\
trace_proxy
\
trace_proxy
\
trace_log
\
trace.cgi
\
trace.cgi
$(MAKE)
-C
aalib clean
$(MAKE)
-C
doc clean
$(MAKE)
-C
predictlib clean
...
...
console/console/console_easycomm.c
deleted
100644 → 0
View file @
5517c99d
/*
console_easycomm.c
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007
Copyright Stichting C.A. Muller Radioastronomiestation, 2007
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
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<netinet/in.h>
#include
<string.h>
#include
<math.h>
#include
<sys/select.h>
#include
<time.h>
#include
<errno.h>
#include
<signal.h>
#include
<tcp_connect.h>
#include
<tcp_listen.h>
#include
<config.h>
#include
"setpoint.h"
typedef
union
{
float
f
;
uint32_t
u
;
}
f32_t
;
int
easycomm_local
=
0
;
int
easycomm_port
=
13000
;
char
*
controller_trace_host
=
"localhost"
;
int
controller_trace_port
=
10000
;
char
*
controller_trace_azimuth
=
"Azimuth_Position"
;
char
*
controller_trace_elevation
=
"Elevation_Position"
;
char
*
controller_command_host
=
"localhost"
;
int
controller_command_port
=
11000
;
char
*
controller_command_azimuth
=
"Azimuth_Setpoint"
;
char
*
controller_command_elevation
=
"Elevation_Setpoint"
;
char
*
controller_trace_unit
;
struct
traceval
{
time_t
seconds
;
int
sample
;
float
value
;
int
wasnan
;
int
new
;
float
newval
;
};
struct
traceval
traceval_az
=
{
0
,
-
1
,
0
.
0
,
0
,
0
,
0
.
0
};
struct
traceval
traceval_el
=
{
0
,
-
1
,
0
.
0
,
0
,
0
,
0
.
0
};
int
controller_command_fd
=
-
1
;
#define VERSION "CAMRAS-console_easycomm-0.1"
#define RX_BUFSIZE 4096
#define TX_BUFSIZE 4096
struct
easycomm_conn
{
struct
easycomm_conn
*
next
;
int
fd
;
char
rxbuffer
[
RX_BUFSIZE
];
char
txbuffer
[
TX_BUFSIZE
];
size_t
rxsize
;
size_t
txsize
;
};
struct
easycomm_conn
*
easycomm_connections
=
NULL
;
struct
setpoint_command
*
sp_command_az
=
NULL
;
struct
setpoint_command
*
sp_command_el
=
NULL
;
int
init_trace
(
int
fd
,
char
*
trace_name
)
{
char
name
[
100
];
char
prevname
[
100
];
int
len
=
0
;
int
unit
=
0
;
int
ret
;
do
{
ret
=
read
(
fd
,
name
+
len
,
1
);
if
(
ret
==
1
)
{
if
(
name
[
len
]
==
0
)
{
if
(
len
==
0
)
break
;
if
(
!
unit
)
{
strcpy
(
prevname
,
name
);
}
else
{
if
(
!
strcmp
(
prevname
,
trace_name
))
{
controller_trace_unit
=
malloc
(
strlen
(
name
)
+
1
);
if
(
controller_trace_unit
)
{
strcpy
(
controller_trace_unit
,
name
);
}
else
{
controller_trace_unit
=
"?"
;
}
}
}
len
=
-
1
;
unit
=
!
unit
;
}
len
++
;
if
(
len
>=
100
)
{
len
=
0
;
}
}
}
while
(
ret
==
1
);
write
(
fd
,
trace_name
,
strlen
(
trace_name
)
+
1
);
return
0
;
}
int
handle_trace
(
int
fd
,
struct
traceval
*
trc
)
{
int
ret
;
uint32_t
nin
;
float
fin
;
f32_t
f
;
ret
=
read
(
fd
,
&
nin
,
sizeof
(
uint32_t
));
if
(
ret
!=
sizeof
(
uint32_t
))
{
close
(
fd
);
return
-
1
;
}
nin
=
ntohl
(
nin
);
f
.
u
=
nin
;
fin
=
f
.
f
;
if
(
trc
->
wasnan
)
{
trc
->
seconds
=
nin
;
trc
->
sample
=
0
;
trc
->
wasnan
=
0
;
}
else
if
(
isnan
(
fin
))
{
trc
->
wasnan
=
1
;
}
else
{
if
(
trc
->
seconds
!=
0
)
trc
->
value
=
fin
;
if
(
trc
->
sample
==
0
)
{
trc
->
new
=
1
;
trc
->
newval
=
fin
;
}
trc
->
sample
++
;
}
return
0
;
}
int
easycomm_output
(
void
)
{
struct
tm
trace_time
;
char
ec_line
[
100
];
struct
easycomm_conn
*
conn
;
if
(
!
traceval_az
.
new
||
!
traceval_el
.
new
)
return
0
;
if
(
traceval_az
.
seconds
!=
traceval_el
.
seconds
)
return
0
;
gmtime_r
(
&
traceval_az
.
seconds
,
&
trace_time
);
sprintf
(
ec_line
,
"ST%04d:%02d:%02d:%02d:%02d:%02d AZ%f EL%f
\n
"
,
trace_time
.
tm_year
+
1900
,
trace_time
.
tm_mon
+
1
,
trace_time
.
tm_mday
,
trace_time
.
tm_hour
,
trace_time
.
tm_min
,
trace_time
.
tm_sec
,
traceval_az
.
newval
*
180
.
0
/
M_PI
,
traceval_el
.
newval
*
180
.
0
/
M_PI
);
for
(
conn
=
easycomm_connections
;
conn
;
conn
=
conn
->
next
)
{
if
(
conn
->
txsize
+
strlen
(
ec_line
)
<=
TX_BUFSIZE
)
{
memcpy
(
conn
->
txbuffer
+
conn
->
txsize
,
ec_line
,
strlen
(
ec_line
));
conn
->
txsize
+=
strlen
(
ec_line
);
}
}
traceval_az
.
new
=
0
;
traceval_el
.
new
=
0
;
return
0
;
}
int
handle_ec_new
(
int
fd_listen
)
{
int
fd
;
struct
easycomm_conn
*
conn
;
fd
=
tcp_accept
(
fd_listen
);
if
(
fd
<
0
)
return
fd
;
printf
(
"Accepted new client connection.
\n
"
);
conn
=
malloc
(
sizeof
(
struct
easycomm_conn
));
if
(
!
conn
)
{
return
-
1
;
close
(
fd
);
}
conn
->
fd
=
fd
;
conn
->
rxsize
=
0
;
sprintf
(
conn
->
txbuffer
,
"VE%s
\n
"
,
VERSION
);
conn
->
txsize
=
strlen
(
conn
->
txbuffer
);
conn
->
next
=
easycomm_connections
;
easycomm_connections
=
conn
;
return
0
;
}
int
handle_ec_send
(
void
)
{
struct
easycomm_conn
**
connp
,
**
next
;
for
(
connp
=
&
easycomm_connections
;
*
connp
;
connp
=
next
)
{
struct
easycomm_conn
*
conn
=
*
connp
;
int
ret
;
next
=
&
conn
->
next
;
if
(
conn
->
txsize
==
0
)
continue
;
ret
=
write
(
conn
->
fd
,
conn
->
txbuffer
,
conn
->
txsize
);
if
(
ret
<=
0
&&
errno
!=
EAGAIN
)
{
printf
(
"Closing client socket
\n
"
);
close
(
conn
->
fd
);
*
connp
=
conn
->
next
;
next
=
connp
;
free
(
conn
);
}
else
{
if
(
ret
==
conn
->
txsize
)
{
conn
->
txsize
=
0
;
}
else
if
(
ret
>
0
)
{
memmove
(
conn
->
txbuffer
,
conn
->
txbuffer
+
ret
,
conn
->
txsize
-
ret
);
conn
->
txsize
-=
ret
;
}
}
}
return
0
;
}
void
handle_ec_command
(
struct
easycomm_conn
*
conn
)
{
conn
->
rxbuffer
[
conn
->
rxsize
]
=
0
;
if
(
!
strncmp
(
conn
->
rxbuffer
,
"AZ"
,
2
))
{
float
value_deg
;
float
value
;
value_deg
=
atof
(
conn
->
rxbuffer
+
2
);
value
=
value_deg
/
180
.
0
*
M_PI
;
printf
(
"New setpoint: %e (%e)
\n
"
,
value
,
value_deg
);
setpoint_command_setpoint
(
sp_command_az
,
value
);
}
if
(
!
strncmp
(
conn
->
rxbuffer
,
"EL"
,
2
))
{
float
value_deg
;
float
value
;
value_deg
=
atof
(
conn
->
rxbuffer
+
2
);
value
=
value_deg
/
180
.
0
*
M_PI
;
printf
(
"New setpoint: %e (%e)
\n
"
,
value
,
value_deg
);
setpoint_command_setpoint
(
sp_command_el
,
value
);
}
}
int
handle_ec_recv
(
void
)
{
struct
easycomm_conn
**
connp
,
**
next
;
for
(
connp
=
&
easycomm_connections
;
*
connp
;
connp
=
next
)
{
struct
easycomm_conn
*
conn
=
*
connp
;
int
ret
=
1
;
next
=
&
conn
->
next
;
if
(
conn
->
rxsize
<
RX_BUFSIZE
)
do
{
ret
=
read
(
conn
->
fd
,
conn
->
rxbuffer
+
conn
->
rxsize
,
1
);
if
(
ret
==
1
)
{
conn
->
rxsize
+=
1
;
switch
(
conn
->
rxbuffer
[
conn
->
rxsize
-
1
])
{
case
' '
:
case
'\t'
:
case
'\n'
:
case
'\r'
:
handle_ec_command
(
conn
);
conn
->
rxsize
=
0
;
}
}
}
while
(
ret
>
0
&&
conn
->
rxsize
<
RX_BUFSIZE
);
if
(
ret
<=
0
&&
errno
!=
EAGAIN
)
{
close
(
conn
->
fd
);
*
connp
=
conn
->
next
;
next
=
connp
;
free
(
conn
);
}
if
(
conn
->
rxsize
==
RX_BUFSIZE
)
conn
->
rxsize
=
0
;
}
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
fd_trace_az
,
fd_trace_el
;
int
fd_ec_listen
;
int
ret
;
fd_set
fdset_rx
;
int
high
;
printf
(
"Controller console interface using Easycomm starting...
\n
"
);
signal
(
SIGPIPE
,
SIG_IGN
);
config_add
(
"controller_trace_host"
,
config_string
,
&
controller_trace_host
);
config_add
(
"controller_trace_port"
,
config_int
,
&
controller_trace_port
);
config_add
(
"controller_trace_azimuth"
,
config_string
,
&
controller_trace_azimuth
);
config_add
(
"controller_command_host"
,
config_string
,
&
controller_command_host
);
config_add
(
"controller_command_port"
,
config_int
,
&
controller_command_port
);
config_add
(
"controller_command_azimuth"
,
config_string
,
&
controller_command_azimuth
);
config_add
(
"easycomm_port"
,
config_int
,
&
easycomm_port
);
config_add
(
"easycomm_local"
,
config_int
,
&
easycomm_local
);
if
(
argc
>=
2
)
{
printf
(
"Reading config file '%s'
\n
"
,
argv
[
1
]);
config_read
(
argv
[
1
]);
}
fd_trace_az
=
tcp_connect
(
controller_trace_host
,
controller_trace_port
);
if
(
fd_trace_az
>=
0
)
{
init_trace
(
fd_trace_az
,
controller_trace_azimuth
);
printf
(
"Controller trace is in '%s'.
\n
"
,
controller_trace_unit
);
}
fd_trace_el
=
tcp_connect
(
controller_trace_host
,
controller_trace_port
);
if
(
fd_trace_el
>=
0
)
{
init_trace
(
fd_trace_el
,
controller_trace_elevation
);
printf
(
"Controller trace is in '%s'.
\n
"
,
controller_trace_unit
);
}
sp_command_az
=
setpoint_command_init
(
controller_command_host
,
controller_command_port
,
controller_command_azimuth
,
"console/easycomm"
);
sp_command_el
=
setpoint_command_init
(
controller_command_host
,
controller_command_port
,
controller_command_elevation
,
"console/easycomm"
);
printf
(
"Going to listen for Easycomm clients on port %d.
\n
"
,
easycomm_port
);
printf
(
"Connections from %s will be accepted.
\n
"
,
easycomm_local
?
"local clients only"
:
"any clients"
);
fd_ec_listen
=
tcp_listen
(
easycomm_port
,
easycomm_local
,
10
);
if
(
fd_ec_listen
<
0
)
{
return
0
;
}
printf
(
"Starting main loop.
\n
"
);
do
{
high
=
0
;
FD_ZERO
(
&
fdset_rx
);
if
(
fd_trace_el
>=
0
&&
fd_trace_az
>=
0
)
{
FD_SET
(
fd_trace_az
,
&
fdset_rx
);
if
(
fd_trace_az
>
high
)
high
=
fd_trace_az
;
FD_SET
(
fd_trace_el
,
&
fdset_rx
);
if
(
fd_trace_el
>
high
)
high
=
fd_trace_el
;
FD_SET
(
fd_ec_listen
,
&
fdset_rx
);
if
(
fd_ec_listen
>
high
)
high
=
fd_ec_listen
;
ret
=
select
(
high
+
1
,
&
fdset_rx
,
NULL
,
NULL
,
NULL
);
if
(
FD_ISSET
(
fd_trace_az
,
&
fdset_rx
))
{
ret
=
handle_trace
(
fd_trace_az
,
&
traceval_az
);
if
(
ret
<
0
)
{
fd_trace_az
=
-
1
;
printf
(
"Trace connection lost.
\n
"
);
}
}
if
(
FD_ISSET
(
fd_trace_el
,
&
fdset_rx
))
{
ret
=
handle_trace
(
fd_trace_el
,
&
traceval_el
);
if
(
ret
<
0
)
{
fd_trace_el
=
-
1
;
printf
(
"Trace connection lost.
\n
"
);
}
}
easycomm_output
();
if
(
FD_ISSET
(
fd_ec_listen
,
&
fdset_rx
))
{
handle_ec_new
(
fd_ec_listen
);
}
handle_ec_recv
();
}
else
{
if
(
fd_trace_az
<
0
)
{
do
{
sleep
(
1
);
fd_trace_az
=
tcp_connect
(
controller_trace_host
,
controller_trace_port
);
}
while
(
fd_trace_az
<
0
);
init_trace
(
fd_trace_az
,
controller_trace_azimuth
);
printf
(
"Controller trace is in '%s'.
\n
"
,
controller_trace_unit
);
}
if
(
fd_trace_el
<
0
)
{
do
{
sleep
(
1
);
fd_trace_el
=
tcp_connect
(
controller_trace_host
,
controller_trace_port
);
}
while
(
fd_trace_el
<
0
);
init_trace
(
fd_trace_el
,
controller_trace_elevation
);
printf
(
"Controller trace is in '%s'.
\n
"
,
controller_trace_unit
);
}
}
handle_ec_send
();
}
while
(
1
);
close
(
fd_trace_az
);
close
(
fd_trace_el
);
return
0
;
}
console/console/elevation.conf
deleted
100644 → 0
View file @
5517c99d
easycomm_port
13001
easycomm_variable
EL
controller_trace_variable
Elevation_Position
controller_command_port
11000
controller_command_variable
Elevation_Setpoint
console/console/test.conf
deleted
100644 → 0
View file @
5517c99d
easycomm_port
1234
controller_trace_variable
Azimuth_Error
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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