console_moontracker.c 2.54 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
	Command generator for moon tracking

	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
	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 "setpoint.h"
#include "tcp_connect.h"
#include "tcp_listen.h"

#include "aalib.h"
#include "weather.h"

#include "dt_port_numbers.h"

char *command_host = "localhost";
int command_port = CONSOLE_COMMAND_PORT;
char *az_command_spg = "Azimuth_Setpoint";
char *el_command_spg = "Elevation_Setpoint";



int main(int argc, char **argv)
{
	struct setpoint_command *sp_command_az = NULL;
	struct setpoint_command *sp_command_el = NULL;
	struct weather *weather;
	double az, el;

	time_t lastt = 0;

	signal(SIGPIPE, SIG_IGN);

	sp_command_az = setpoint_command_init(command_host, command_port,
	    az_command_spg, "console/moontracker");
	sp_command_el = setpoint_command_init(command_host, command_port,
	    el_command_spg, "console/moontracker");
	if (!sp_command_az || !sp_command_el) {
		fprintf(stderr, "Setpoint generator(s) not found\n");
		exit(-1);
	}


	aalib_init();
	weather = weather_create("Dwingeloo");

	while (1)
	{
		time_t t;
		
		t = time(NULL);
		if (t != lastt) {
			lastt = t;
			t += 5;
		
//			jul 26 2008 5:39 utc
//			t =  1217050740;
		
			aalib(3, t, 
			    weather_get_temperature(weather),
			    weather_get_pressure(weather),
			    &az, &el);

			az -= 180.0;

			printf("%s", ctime(&t));
			printf("Setpoint: %d %f %f\n\n",
			    (unsigned int)t, az, el);

			setpoint_command_setpoint_time(sp_command_az,
			    az * 2 * M_PI / 360.0, t);
			setpoint_command_setpoint_time(sp_command_el,
			    el * 2 * M_PI / 360.0, t);

			sleep(1);
		}

	}

}