Commit 1cee7e77 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

20130214

parent 8913f709
...@@ -3,3 +3,8 @@ ...@@ -3,3 +3,8 @@
*.sw? *.sw?
*~ *~
*.a *.a
*.tab.c
*.tab.h
*.yy.c
*.yy.h
*.log
all:
$(MAKE) -C common/utils
$(MAKE) -C common/trace
$(MAKE) -C controller
cd libnova-0.13.0 ; ./configure ; make
$(MAKE) -C console
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#define CONSOLE_MANUAL_CMD_PORT 11051 #define CONSOLE_MANUAL_CMD_PORT 11051
#define CONSOLE_SAT_STAT_PORT 11060 #define CONSOLE_SAT_STAT_PORT 11060
#define CONSOLE_SAT_CMD_PORT 11061 #define CONSOLE_SAT_CMD_PORT 11061
#define CONSOLE_SUN_STAT_PORT 11070
#define CONSOLE_SUN_CMD_PORT 11071
#define CONSOLE_MOON_STAT_PORT 11080
#define CONSOLE_MOON_CMD_PORT 11081
#define CONSOLE_LOG_PORT 11200 #define CONSOLE_LOG_PORT 11200
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
CFLAGS= -Wall -O3 CFLAGS= -Wall -O3
LDFLAGS= -lpthread LDFLAGS= -lpthread
UTILSRCS= tcp_connect.c tcp_listen.c config.c weather.c dt_model.c location.c CFLAGS+=`pkg-config --cflags glib-2.0`
LDFLAGS+=`pkg-config --libs glib-2.0`
UTILSRCS= tcp_connect.c tcp_listen.c config.c weather.c dt_model.c location.c dt_host.c
UTILOBJS= $(UTILSRCS:.c=.o) UTILOBJS= $(UTILSRCS:.c=.o)
all: $(UTILOBJS) utils weather_test all: $(UTILOBJS) utils weather_test
......
/* /*
Javascript sending j2000 coordinates over XMLHttp Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008
Copyright Stichting C.A. Muller Radioastronomiestation, 2008
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -19,45 +17,74 @@ ...@@ -19,45 +17,74 @@
*/ */
function j2000_command_cb_default (line) #include <glib.h>
{ #include <stdbool.h>
/* default callback */ #include <string.h>
} #include "dt_host.h"
function j2000_command ()
{
var j2000_command_this = this;
/* Callbacks */
this.callback = j2000_command_cb_default;
this.xrequest = 0; static char *controller_host = "localhost";
this.xrequest_prev = 0; static char *console_host = "localhost";
static bool init_done = false;
this.handle_xml = function (event) static int load_config(void)
{ {
j2000_command_this.callback(j2000_command_this, event.target.responseText); GKeyFile *keyfile;
j2000_command_this.data_wd = 1; gboolean loaded;
} gchar *keyfilename = "dt_host.ini";
int ret = 0;
this.url; keyfile = g_key_file_new();
loaded = g_key_file_load_from_file(
keyfile,
keyfilename,
G_KEY_FILE_NONE,
NULL);
this.open = function (url, ra, dec) if (loaded) {
{ gsize groups_nr;
if (j2000_command_this.xrequest_prev) { gchar **groups;
j2000_command_this.xrequest.abort(); int i;
delete j2000_command_this.xrequest;
groups = g_key_file_get_groups(keyfile, &groups_nr);
for (i = 0; i < groups_nr; i++) {
if (!strcmp(groups[i], "controller")) {
if (g_key_file_has_key(keyfile, groups[i], "host", NULL)) {
controller_host =
g_key_file_get_string(keyfile, groups[i], "host", NULL);
}
}
if (!strcmp(groups[i], "console")) {
if (g_key_file_has_key(keyfile, groups[i], "host", NULL)) {
console_host =
g_key_file_get_string(keyfile, groups[i], "host", NULL);
}
}
} }
j2000_command_this.url = url;
j2000_command_this.xrequest = new XMLHttpRequest(); init_done = true;
j2000_command_this.xrequest.multipart = true; g_strfreev(groups);
j2000_command_this.xrequest.open("POST", url, true); } else {
j2000_command_this.xrequest.onload = this.handle_xml; ret = -1;;
j2000_command_this.xrequest.send(ra + " " + dec);
j2000_command_this.xrequest_prev = 1;
} }
g_key_file_free(keyfile);
return ret;
} }
char *dt_host_console(void)
{
if (!init_done)
load_config();
return console_host;
}
char *dt_host_controller(void)
{
if (!init_done)
load_config();
return controller_host;
}
/* /*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007 Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007 Copyright Stichting C.A. Muller Radioastronomiestation, 2013
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
*/ */
#ifndef _INCLUDE_DT_EL_H_ #ifndef _INCLUDE_DT_HOST_H_
#define _INCLUDE_DT_EL_H_ #define _INCLUDE_DT_HOST_H_
char *dt_host_console(void);
char *dt_host_controller(void);
#endif /* _INCLUDE_DT_HOST_H_ */
#endif /* _INCLUDE_DT_EL_H_ */
...@@ -88,7 +88,7 @@ int tcp_connect(char *host, int port) ...@@ -88,7 +88,7 @@ int tcp_connect(char *host, int port)
} }
freeaddrinfo(result); freeaddrinfo(result);
if (sock < 0) // if (sock < 0)
printf("Failed to connect\n"); // printf("Failed to connect\n");
return sock; return sock;
} }
...@@ -18,9 +18,14 @@ console_zenith ...@@ -18,9 +18,14 @@ console_zenith
log_proxy log_proxy
predictlib/test-001 predictlib/test-001
predictlib/test-002 predictlib/test-002
predictlib/test-003
spg_auth spg_auth
spg_list spg_list
spg_log_parser spg_log_parser
trace_line trace_line
trace_log trace_log
trace_proxy trace_proxy
command.cgi
shell.cgi
status.cgi
trace.cgi
...@@ -3,30 +3,28 @@ include ../build.mk ...@@ -3,30 +3,28 @@ include ../build.mk
CFLAGS= -Wall -g -I../../common/utils -I../controller -Iaalib -Ipredictlib -I../../common/trace -I../../common/include -I../../libnova-0.13.0/src CFLAGS= -Wall -g -I../../common/utils -I../controller -Iaalib -Ipredictlib -I../../common/trace -I../../common/include -I../../libnova-0.13.0/src
ARCHIVES= ../../common/utils/utils.a aalib/aalib.a predictlib/predictlib.a ../../common/trace/trace.a ARCHIVES= ../../common/utils/utils.a aalib/aalib.a predictlib/predictlib.a ../../common/trace/trace.a
LIBNOVA=../../libnova-0.13.0/src/.libs/libnova.a LIBNOVA=../../libnova-0.13.0/src/.libs/libnova.a
LDFLAGS+=`pkg-config --libs glib-2.0`
all: aalib predictlib\ all: aalib predictlib\
setpoint.o console_easycomm console_joystick command_shell \ setpoint.o console_easycomm console_joystick command_shell \
spg_list spg_log_parser \ spg_list spg_log_parser \
console_moontracker \ console_moontracker \
console_httptrace console_httpline console_httpline_install \ console_httptrace \
trace_proxy trace_line_install trace_log \ trace_proxy trace.cgi_install trace_log \
console_j2000tracker console_j2000tracer console_j2000_indi \ console_j2000tracker console_j2000tracer console_j2000_indi \
log_proxy spg_auth console_idle console_zenith \ log_proxy spg_auth console_idle console_zenith \
console_suntracker console_azel console_manual \ console_suntracker console_azel console_manual \
console_weather \ console_weather \
await_controller \ await_controller \
console_sattracker console_sattracker \
status.cgi_install command.cgi_install shell.cgi_install
await_controller: await_controller.o $(ARCHIVES) await_controller: await_controller.o $(ARCHIVES)
console_easycomm: console_easycomm.o setpoint.o $(ARCHIVES) console_easycomm: console_easycomm.o setpoint.o $(ARCHIVES)
console_httpline: console_httpline.o $(ARCHIVES)
console_httpline_install: console_httpline
@echo " CP console_httpline"
@cp console_httpline ../htdocs
console_httptrace: console_httptrace.o $(ARCHIVES) console_httptrace: console_httptrace.o $(ARCHIVES)
console_joystick: console_joystick.o setpoint.o $(ARCHIVES) console_joystick: console_joystick.o setpoint.o $(ARCHIVES)
...@@ -59,11 +57,11 @@ console_zenith: console_zenith.o setpoint.o $(ARCHIVES) ...@@ -59,11 +57,11 @@ console_zenith: console_zenith.o setpoint.o $(ARCHIVES)
trace_proxy: trace_proxy.o $(ARCHIVES) trace_proxy: trace_proxy.o $(ARCHIVES)
trace_line: trace_line.o $(ARCHIVES) trace.cgi: trace.cgi.o $(ARCHIVES)
trace_line_install: trace_line trace.cgi_install: trace.cgi
@echo " CP trace_line" @echo " CP trace.cgi"
@cp trace_line ../htdocs @cp trace.cgi ../htdocs
trace_log: trace_log.o $(ARCHIVES) trace_log: trace_log.o $(ARCHIVES)
...@@ -74,6 +72,24 @@ spg_auth: spg_auth.o setpoint.o $(ARCHIVES) ...@@ -74,6 +72,24 @@ spg_auth: spg_auth.o setpoint.o $(ARCHIVES)
console_sattracker: console_sattracker.o setpoint.o $(ARCHIVES) -lpthread $(LIBNOVA) -lm console_sattracker: console_sattracker.o setpoint.o $(ARCHIVES) -lpthread $(LIBNOVA) -lm
command.cgi: command.cgi.o $(ARCHIVES)
command.cgi_install: command.cgi
@echo " CP command.cgi"
@cp command.cgi ../htdocs
shell.cgi: shell.cgi.o $(ARCHIVES)
shell.cgi_install: shell.cgi
@echo " CP shell.cgi"
@cp shell.cgi ../htdocs
status.cgi: status.cgi.o $(ARCHIVES)
status.cgi_install: status.cgi
@echo " CP status.cgi"
@cp status.cgi ../htdocs
aalib: aalib:
@$(MAKE) -C aalib @$(MAKE) -C aalib
...@@ -93,7 +109,6 @@ clean: ...@@ -93,7 +109,6 @@ clean:
console_easycomm \ console_easycomm \
spg_list \ spg_list \
console_httptrace \ console_httptrace \
console_httpline \
trace_proxy \ trace_proxy \
console_manual \ console_manual \
console_moontracker \ console_moontracker \
...@@ -107,12 +122,14 @@ clean: ...@@ -107,12 +122,14 @@ clean:
console_weather \ console_weather \
console_zenith \ console_zenith \
trace_proxy \ trace_proxy \
trace_line \ trace.cgi \
trace_log \ trace_log \
log_proxy \ log_proxy \
spg_auth \ spg_auth \
spg_log_parser \ spg_log_parser \
await_controller await_controller \
command.cgi \
status.cgi
$(MAKE) -C aalib clean $(MAKE) -C aalib clean
$(MAKE) -C doc clean $(MAKE) -C doc clean
$(MAKE) -C predictlib clean $(MAKE) -C predictlib clean
......
/*
HTTP frontend for commands
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
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 <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "tcp_connect.h"
#include "dt_port_numbers.h"
#include "dt_host.h"
int main(int argc, char **argv)
{
int fd;
char buffer[1000];
char *host;
int port = -1;
host = dt_host_console();
fgets(buffer, sizeof(buffer), stdin);
while (buffer[strlen(buffer)-1] == '\n')
buffer[strlen(buffer)-1] = 0;
if (!strcmp(buffer, "sat"))
port = CONSOLE_SAT_CMD_PORT;
else if (!strcmp(buffer, "sun"))
port = CONSOLE_SUN_CMD_PORT;
else if (!strcmp(buffer, "moon"))
port = CONSOLE_MOON_CMD_PORT;
else if (!strcmp(buffer, "auth"))
port = CONSOLE_ACTIVE_PORT;
else if (!strcmp(buffer, "j2000"))
port = CONSOLE_J2000_CMD_PORT;
else if (!strcmp(buffer, "offset"))
port = CONSOLE_OFFSET_PORT;
else if (!strcmp(buffer, "azel"))
port = CONSOLE_AZEL_PORT;
else if (!strcmp(buffer, "manual"))
port = CONSOLE_MANUAL_CMD_PORT;
alarm(10);
fd = tcp_connect(host, port);
if (fd >= 0) {
ioctl(fd, FIONBIO, &(int){ 0 });
while (fgets(buffer, sizeof(buffer), stdin))
write(fd, buffer, strlen(buffer));
write(fd,"\n", 1);
fsync(fd);
printf("Content-type: text/plain\n");
printf("Cache-Control: no-cache\n");
printf("Pragma: no-cache\n");
printf("\n");
printf("done\n");
} else {
printf("Content-type: text/plain\n");
printf("Cache-Control: no-cache\n");
printf("Pragma: no-cache\n");
printf("\n");
sleep(1);
printf("failed\n");
printf("No response from %s:%d\n", host, port);
}
return 0;
}
...@@ -183,14 +183,23 @@ int main(int argc, char **argv) ...@@ -183,14 +183,23 @@ int main(int argc, char **argv)
command_host = argv[argc - 1]; command_host = argv[argc - 1];
} }
sp_command_az = setpoint_command_init(command_host, command_port, do {
az_command_spg, "console/azel"); sp_command_az = setpoint_command_init(command_host, command_port,
sp_command_el = setpoint_command_init(command_host, command_port, az_command_spg, "console/azel");
el_command_spg, "console/azel"); if (!sp_command_az) {
if (!sp_command_az || !sp_command_el) { printf("Could not open connection for az commands\n");
fprintf(stderr, "Setpoint generator(s) not found\n"); sleep(1);
exit(-1); }
} } while (!sp_command_az);
do {
sp_command_el = setpoint_command_init(command_host, command_port,
el_command_spg, "console/azel");
if (!sp_command_el) {
printf("Could not open connection for el commands\n");
sleep(1);
}
} while (!sp_command_el);
fd_cmd = tcp_listen(cmd_port, 0, 100); fd_cmd = tcp_listen(cmd_port, 0, 100);
if (fd_cmd < 0) { if (fd_cmd < 0) {
......
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include "tcp_connect.h" #include <tcp_connect.h>
#include "tcp_listen.h" #include <tcp_listen.h>
#include "config.h" #include <config.h>
#include "setpoint.h" #include "setpoint.h"
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include "tcp_connect.h" #include <tcp_connect.h>
typedef union { typedef union {
float f; float f;
......
...@@ -48,14 +48,22 @@ int main(int argc, char **argv) ...@@ -48,14 +48,22 @@ int main(int argc, char **argv)
command_host = argv[1]; command_host = argv[1];
} }
sp_command_az = setpoint_command_init(command_host, command_port, do {
az_command_spg, "console/idle"); sp_command_az = setpoint_command_init(command_host, command_port,
sp_command_el = setpoint_command_init(command_host, command_port, az_command_spg, "console/idle");
el_command_spg, "console/idle"); if (!sp_command_az) {
if (!sp_command_az || !sp_command_el) { printf("Could not open connection for az commands\n");
fprintf(stderr, "Setpoint generator(s) not found\n"); sleep(1);
exit(-1); }
} } while (!sp_command_az);
do {
sp_command_el = setpoint_command_init(command_host, command_port,
el_command_spg, "console/idle");
if (!sp_command_el) {
printf("Could not open connection for el commands\n");
sleep(1);
}
} while (!sp_command_el);
while (1) while (1)
{ {
......
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <errno.h> #include <errno.h>
#include "libnova/transform.h" #include <libnova/transform.h>
#include "libnova/julian_day.h" #include <libnova/julian_day.h>
#include "libnova/utility.h" #include <libnova/utility.h>
#include "setpoint.h" #include "setpoint.h"
#include "tcp_connect.h" #include "tcp_connect.h"
......
/* /*
Command generator for J2000.0 positions Command generator for J2000.0 positions
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008, 2011 Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008, 2011, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2011 Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2011, 2013
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -37,12 +37,12 @@ ...@@ -37,12 +37,12 @@
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include "libnova/transform.h" #include <libnova/transform.h>
#include "libnova/julian_day.h"