forked from philcrump/groundstation-tracking-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
92 lines (75 loc) · 2.14 KB
/
main.c
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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <stdlib.h>
#include <libpq-fe.h>
#include "config.h"
#include "tle.h"
#include "schedule.h"
#include "track.h"
#include "libpredict/predict.h"
void _print_usage(void)
{
printf(
"\n"
"Usage: gss [options]\n"
"\n"
" -V, --version Print version string and exit.\n"
"\n"
);
}
int main(int argc, char *argv[])
{
fprintf(stdout,
"gs-scheduler "BUILD_VERSION" (built "BUILD_DATE")\n"
"Phil Crump 2018\n"
);
int opt, c;
static const struct option long_options[] = {
{ "version", no_argument, 0, 'V' },
{ "config", required_argument, 0, 'c' },
{ 0, 0, 0, 0 }
};
char config_filename[100];
strncpy(config_filename, "config.ini", 100);
while((c = getopt_long(argc, argv, "Vc:", long_options, &opt)) != -1)
{
switch(c)
{
case 'c':
strncpy(config_filename, optarg, 100);
break;
case '?':
default:
_print_usage();
return 0;
}
}
printf("Loading config from file: %s\n", config_filename);
if(!config_load(&config, config_filename))
{
printf("Error loading config from file! Exiting..\n");
return 1;
}
PGconn *conn = PQconnectdb(config.db_conn_string);
if (PQstatus(conn) == CONNECTION_BAD) {
fprintf(stderr, "Connection to database failed: %s\n",
PQerrorMessage(conn));
PQfinish(conn);
return 1;
}
printf("Connected to Server (server: %d, client: %d)\n"
, PQserverVersion(conn), PQlibVersion()
);
printf("Updating TLEs from celestrak..\n");
tle_update_http(conn);
printf("Updating TLEs from spacetrack..\n");
tle_update_spacetrack(conn, config.spacetrack_user, config.spacetrack_passwd);
printf("Updating Tracks..\n");
track_update_all(conn);
printf("Updating Schedule..\n");
schedule_update_all(conn);
PQfinish(conn);
return 0;
}