await_controller.c 1.8 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
/*
	Copyright Stichting C.A. Muller Radioastronomiestation, 2011

	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 <string.h>
#include <unistd.h>

Jeroen Vreeken's avatar
Jeroen Vreeken committed
24
#include <utils/tcp_connect.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
25

Jeroen Vreeken's avatar
Jeroen Vreeken committed
26
27
#include <dt_port_numbers.h>
#include <utils/dt_host.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
28
29
30
31
32
33
34
35
36
37
38
39
40

#define MAX_RETRIES 30
#define SLEEP_INTERVAL 10


int main(int argc, char **argv)
{
static char *tr_host;
static int tr_port;
int fd;
int retries = 0;


Jeroen Vreeken's avatar
Jeroen Vreeken committed
41
42
	if (argc != 1) {
		printf("Usage: %s\n", argv[0]);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
43
		printf("\n");
Jeroen Vreeken's avatar
Jeroen Vreeken committed
44
		printf("e.g. %s\n", argv[0]);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
45
46
47
		return 1;
	}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
48
	tr_host = dt_host_controller();
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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
	tr_port = CTRL_TRACE_PORT;

	fd = tcp_connect(tr_host, tr_port);

	while ((fd < 0) && (retries < MAX_RETRIES)) {
		printf("Kan CTRL_TRACE_PORT op de controller-PC niet bereiken\n");
		fflush (stdout);
		sleep (SLEEP_INTERVAL);
		fd = tcp_connect(tr_host, tr_port);
                retries++;
	}

	close(fd);

	tr_port = CTRL_COMMAND_PORT;

	fd = tcp_connect(tr_host, tr_port);

	while ((fd < 0) && (retries < MAX_RETRIES)) {
		printf("Kan CTRL_COMMAND_PORT op de controller-PC niet bereiken\n");
		fflush (stdout);
		sleep (SLEEP_INTERVAL);
		fd = tcp_connect(tr_host, tr_port);
                retries++;
	}

	close(fd);

        return ((retries >= MAX_RETRIES) ? 1 : 0);
}