dt_ctrl.c 2.77 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
/*
Jeroen Vreeken's avatar
Jeroen Vreeken committed
2
3
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007 - 2013
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007 - 2013
Jeroen Vreeken's avatar
Jeroen Vreeken committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

	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/>.

 */

20
21
#define _GNU_SOURCE

Jeroen Vreeken's avatar
Jeroen Vreeken committed
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

28
#include "dynarg.h"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
29
30
31
32
33
34
35
36
37
38

#include "controller_block.h"
#include "controller_trace.h"
#include "controller_sample.h"
#include "controller_dumpdot.h"
#include "controller_load.h"
#include "shell.h"
#include "ec.h"
#include "log.h"

39
#include "dt_port_numbers.h"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
40
41
42
43
44



int main(int argc, char **argv)
{
45
46
47
	char *ctrl_filename;
	char *dot_filename;
	
48
49
	log_server_start(CTRL_LOG_PORT, LOG_T_DEBUG, LOG_T_INFO);

Jeroen Vreeken's avatar
Jeroen Vreeken committed
50
51
	controller_block_param_init();
	
52
53
54
55
	if (argc < 2) {
		printf("Usage: %s <controllerfile>\n", argv[0]);
		printf("\n");
		printf("E.g.: %s dt_ctrl.ctrl\n", argv[0]);
56
		goto err_init;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
57
	}
58
	
59
60
	ctrl_filename = argv[1];
	
61
	/* Create and link blocks */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
62

63
	if (controller_load(ctrl_filename)) {
64
65
		printf("Could not load controller file\n");
		goto err_init;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
66
67
68
69
70
71
	}

	controller_trace_server_start(CTRL_TRACE_PORT, 100);

	/* Start command shell */
	
72
	controller_sample_shell_add();
Jeroen Vreeken's avatar
Jeroen Vreeken committed
73
74
75
76
77
78
79
	controller_load_shell_add();

	shell_intro = "Dwingeloo Telescope controller\n";
	shell_prompt = "DT>";
	
	shell_server_start(CTRL_SHELL_PORT, 10);

80
81
82
	asprintf(&dot_filename, "%s.dot", ctrl_filename);
	controller_dumpdot(dot_filename);
	free(dot_filename);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
83
84
85

	/* Start 'sample' */

86
	if (controller_block_sample_init()) {
87
		goto err_init;
88
	}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
89
90
91
92
93
94
95

	controller_sample_start();

	while (1) {
		float az_pos;
		float el_pos;
		float el_tor;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
96

Jeroen Vreeken's avatar
Jeroen Vreeken committed
97
98
99
100
101
102
103
		if (controller_block_output_get_float("elevation_input_matrix", "out0", &el_pos))
			log_send(LOG_T_ERROR, "Getting elevation_input_matrix.out0 failed\n");
		if (controller_block_output_get_float("elevation_input_matrix", "out1", &el_tor))
			log_send(LOG_T_ERROR, "Getting elevation_input_matrix.out1 failed\n");
		if (controller_block_output_get_float("dt_az", "position", &az_pos))
			log_send(LOG_T_ERROR, "Getting dt_az.position failed\n");

Jeroen Vreeken's avatar
Jeroen Vreeken committed
104
		log_send(LOG_T_INFO, "Elevation: %e (Torsion: %e) Azimuth: %e",
Jeroen Vreeken's avatar
Jeroen Vreeken committed
105
106
107
108
109
110
111
		    el_pos, el_tor, az_pos);
		
		/* Log once every 15 minutes */
		sleep(15 * 60);
	}

	return 0;
112
113
114
115

err_init:
	log_server_flush();
	return 1;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
116
}