/
gltmonitor.c
532 lines (454 loc) · 11.7 KB
/
gltmonitor.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/* monitor program for GLT
adopted from SMA.
Nimesh Patel
14 June 2012
version 1.0
Only the following pages will be ported for now (for Socorro/Norfolk tests).
1) Main page: "a": combination of array and antenna page
2) Pointing models: "P"
3) Smainit info: "s"
4) Error messages: "e"
5) Commands summary: "l"
6) 2op messages: "m"
*/
/* Note added on 17 June 2012:
Only page (1) of above will be implemented for now!
*/
/* NAP 1 May 2021. Many changes to document here, but the code is now on github
where more comments will be in commits. */
#define PRINT_DSM_ERRORS 0 /* set this to 1 to debug DSM problems
* with the use of call_dsm_read() */
#define N_LINES 20
#define MIN_LINES_FOR_BOTTOM_2OP 25
#define MIN_LINES_FOR_BOTTOM_OPMSG 26
#define DEBUG 0
#include <stdio.h>
#include <sys/utsname.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <termio.h>
#include <time.h>
#include <ncurses.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
/*
#include <pthread.h>
*/
#include <termios.h>
/*
#include "smapopt.h"
#include "commonLib.h"
#include "rm.h"
*/
#include "dsm.h"
#include "monitor.h"
#include "antMonitor.h"
enum {
/* to add a page, insert a new name at the top and decrement the initializor */
MESSAGE_DISPLAY,PMODEL_DISPLAY, /* -5 */
SMAINIT_DISPLAY,HELP_DISPLAY, /* -3 */
SMASH_DISPLAY,STDERR_DISPLAY,METROLOGY_DISPLAY,RECEIVERS_DISPLAY,MASER_DISPLAY,HOME_DISPLAY, /* 0 */
ANTENNAPAGE_DISPLAY /* 1 (going up 10) */
};
#define TRUE 1
#define FALSE 0
#define TIMEOUT 3600
#define COLOR_NORMAL 1
#define COLOR_LABEL 2
#define COLOR_EMPHASIS 3
#define COLOR_ENABLED 4
#define COLOR_DISABLED 5
#define COLOR_VARIANT 6
#include "commandMonitor.h"
int colorFlag = TRUE;
int bottom2op = FALSE;
int bottomOpMsg = FALSE;
int projectLockout;
int defaultTiltFlag[20];
void readIFServerInfo(void);
void handlerForSIGINT(int signum);
void goto80width(void);
void goto80WidthAndExit(int value);
void goto132width(void);
void allow132width(void);
double sunDistance(double az1,double el1,double az2,double el2);
int user, lastUser;
double radian=0.01745329;
struct termio tio, tin;
int beepFlag=1;
int antsAvailable[MAX_NUMBER_ANTENNAS+1] = {0,0,0,0,0,0,0,0,0,0,0};
int deadAntennas[MAX_NUMBER_ANTENNAS+1] = {0,0,0,0,0,0,0,0,0,1,1};
/*
int monoFlag = FALSE;
int setSimpleChars = FALSE;
int extCharset = TRUE;
int lowColorFlag = FALSE;
int whiteBG = FALSE;
typedef struct {
int isColor;
int isWhiteBG;
int isReducedColor;
} COLOR_SCHEME;
static COLOR_SCHEME schemes[5] = { { TRUE, FALSE, FALSE }, { TRUE, FALSE, TRUE }, { TRUE, TRUE, FALSE }, { TRUE, TRUE, TRUE}, { FALSE, FALSE, FALSE } };
static int scheme = 0;
*/
int smainitMode = 0; /* Set to 1 when displaying smainit pages */
int antMode = 0;
int commandMode = 0;
int searchMode = 0;
int messageMode = 0;
int errorMode = 0;
/* remember to add any new entries to the functions SetAllPageModesToZero()
* and SetMostPageModesToZero() */
int smainitPage = 0; /* Selects computer within smainit pages */
int antPage = 0;
int statesPage = FALSE;
int pageOffset = 0;
char searchString[100];
int opBeepCount = 3;
extern void help(int count);
extern void timeStamp(void);
/*
extern void messagePage(int count, int kind);
extern int pmodelspage(int icount,int *antlist);
extern void smainitMonitor(int count, int page);
*/
extern void metrologyPage(int count);
extern void receiversPage(int count);
extern void maserPage(int count);
/* on the wide 'a' page, this tells which window to start with in the
* upper right corner */
int upperRightWindow = UR_MESSAGES;
void usage(char *a);
void usage(char *a) {
printf("Usage: %s -H -h --help\n",a);
/*
printf("Usage: %s -i -z -Z -H --help\n");
printf(" -i ignore messages from 2op\n");
*/
printf(" -a or --antenna display values for antenna(s) even if 'dead'\n");
printf(" -H show the hangar display page only\n");
printf(" -h or --help show this message\n");
exit(0);
}
main(int argc, char *argv[])
{
int i;
int ant=HOME_DISPLAY; /* start up on the 'a' page */
int cycle = FALSE;
int delay = 1;
int spinCount = 0;
char *outputFile = NULL;
struct utsname unamebuf;
int rms;
struct sigaction action, old_action;
int sigactionInt;
int icount=0;
int firstUpdate = TRUE;
int rc;
int startDay;
int message = 0;
int ignoreFlag;
struct stat messageStat, oldMessageStat;
/* The following variables are for the default Tilt flag read from
the pointing model files */
FILE *fpMountModel;
int itilt;
char mountModelFile[100],line[BUFSIZ];
char pointingParameter[20],opticalValue[20],radioValue[20];
/* signal handler for control C */
action.sa_flags=0;
sigemptyset(&action.sa_mask);
action.sa_handler = handlerForSIGINT;
sigactionInt = sigaction(SIGINT,&action, &old_action);
system("resize -s 58 90");
uname(&unamebuf);
i = 0;
rms = dsm_open();
if(rms != DSM_SUCCESS) {
dsm_error_message(rms, "dsm_open");
exit(-1);
}
#if DEBUG
fprintf(stderr,"Finished opening DSM\n");
#endif
/*
* This is to get the user input as a single unbuffered char and
* zero-wait
*/
ioctl(0, TCGETA, &tio);
tin = tio;
tin.c_lflag &= ~ECHO;
tin.c_lflag &= ~ICANON;
tin.c_cc[VMIN] = 0;
tin.c_cc[VTIME] = 0;
ioctl(0, TCSETA, &tin);
stat(MESSAGES_LOG, &oldMessageStat);
#if DEBUG
fprintf(stderr,"1. Finished stat() on messages file\n");
#endif
/* starting infinite loop */
/* begin while loop every 1 second */
initialize();
ant=HOME_DISPLAY;
while (1) {
time_t lastKeystrokeTime, curTime;
ioctl(0, TCSETA,&tin);
icount++;
lastUser = user;
user = getchar();
switch (user) {
case 'q':
move(LINES-1,0);
printw("Bye.\n");
refresh();
ioctl(0, TCSETA, &tio);
goto80width();
printf("\n");
rms = dsm_close();
if(rms != DSM_SUCCESS) {
dsm_error_message(rms, "dsm_close");
exit(-1);
}
exit(0);
break;
case 'm':
ant = METROLOGY_DISPLAY;
icount = 1;
break;
case 'r':
ant = RECEIVERS_DISPLAY;
icount = 1;
break;
case 'M':
ant = MASER_DISPLAY;
icount = 1;
break;
case 'a':
ant = HOME_DISPLAY;
icount = 0;
break;
case 'h':
ant = HELP_DISPLAY;
printw("got help key");
icount = 0;
break;
} /* end of switch */
if (ant == HOME_DISPLAY) {
antDisplay(ant, icount);
} else if (ant == HELP_DISPLAY) {
help(icount);
} else if (ant == METROLOGY_DISPLAY) {
metrologyPage(icount);
} else if (ant == RECEIVERS_DISPLAY) {
receiversPage(icount);
} else if (ant == MASER_DISPLAY) {
maserPage(icount);
}
sleep(delay);
} /* this is the big while loop */
ioctl(0, TCSETA, &tio);
} /* end of main Loop */
void handlerForSIGINT(int signum)
{
user='q'; /* 'q' for quit command */
fprintf(stderr,"Got the control C signal. Quitting.\n");
printf("Bye.\n");
ioctl(0, TCSETA, &tio);
goto80WidthAndExit(0);
}
int call_dsm_read(char *machine, char *variable, void *ptr, time_t *tstamp) {
char buf[256];
int rms;
rms = dsm_read(machine,variable,ptr,tstamp);
if (rms != DSM_SUCCESS) {
if (PRINT_DSM_ERRORS) {
sprintf(buf,"dsm_read - %s",variable);
dsm_error_message(rms, buf);
}
}
return(rms);
}
int call_dsm_structure_get_element(dsm_structure *ds, char *name, void *ptr) {
char buf[256];
int rms;
rms = dsm_structure_get_element(ds, name, ptr);
if (rms != DSM_SUCCESS) {
if (PRINT_DSM_ERRORS) {
sprintf(buf,"dms_structure_get_element - %s",name);
dsm_error_message(rms, buf);
}
}
return(rms);
}
void allow132width(void) {
char name[20];
sprintf(name,"%c?40h",0x9b);
printf(name);
}
void goto132width(void) {
char name[20];
sprintf(name,"%c?3h",0x9b);
printf(name);
}
void goto80width(void) {
char name[20];
sprintf(name,"%c?3l",0x9b);
printf(name);
}
void initialize() {
int i;
int numberAntennas;
initscr();
if(colorFlag) {
start_color();
/*
init_color(COLOR_WHITE, CSAT, CSAT, CSAT);
init_color(COLOR_RED, CSAT, 0, 0);
init_color(COLOR_GREEN, 0, CSAT, 0);
init_color(COLOR_BLUE, 0, 0, CSAT);
init_color(COLOR_YELLOW, CSAT, CSAT, CSAT/2);
init_color(COLOR_CYAN, CSAT/4, (3*CSAT)/4, CSAT);
init_color(COLOR_MAGENTA, CSAT, CSAT/2, CSAT);
init_pair(COLOR_NORMAL, COLOR_WHITE, COLOR_BLACK);
init_pair(COLOR_ENABLED, COLOR_GREEN, bgColor);
init_pair(COLOR_DISABLED, COLOR_RED, bgColor);
init_pair(COLOR_EMPHASIS, COLOR_YELLOW, bgColor);
init_pair(COLOR_LABEL, COLOR_CYAN, bgColor);
init_pair(COLOR_VARIANT, whiteBG ? COLOR_BLUE : COLOR_MAGENTA, bgColor);
bkgd(A_NORMAL | COLOR_PAIR(COLOR_NORMAL));
*/
}
nonl();
clear();
/* LINES and COLS are now defined */
if (COLS > 132)
COLS = 132;
if ((COLS >= MINIMUM_SCREEN_WIDTH_FOR_ESMA) && FALSE){
numberAntennas = 10;
} else {
numberAntennas = 8;
}
if (LINES >= MIN_LINES_FOR_BOTTOM_2OP) {
bottom2op = TRUE;
}
if (LINES >= MIN_LINES_FOR_BOTTOM_OPMSG) {
bottomOpMsg = TRUE;
}
if ((COLS >= MINIMUM_SCREEN_WIDTH_FOR_ESMA) && FALSE) {
numberAntennas = 10;
} else {
numberAntennas = 8;
}
/*
box(stdscr, '|','-');
*/
/* draw outline */
/*
for (i = 1; i < COLS-1; i++) {move(0,i);printw("-");}
for (i = 1; i < COLS-1; i++) {move(80,i);printw("-");}
for (i = 1; i < 23; i++) {move(i,0);printw("|");}
for (i = 1; i < 23; i++) {move(i,COLS-1);printw("|");}
*/
#if 0
move(0,0);
printw("COLS=%d",COLS);
#endif
move(2,2);
}
void goto80WidthAndExit(int value) {
goto80width();
exit(value);
}
int present(char *a, char *b) {
if (strstr(a,b) == NULL) {
return(0);
} else {
return(1);
}
}
int computeMonthFrom3CharString(char *month) {
int mon;
if (!strcmp("Jan", month))
mon = 0;
else if (!strcmp("Feb", month))
mon = 1;
else if (!strcmp("Feb", month))
mon = 1;
else if (!strcmp("Mar", month))
mon = 2;
else if (!strcmp("Apr", month))
mon = 3;
else if (!strcmp("May", month))
mon = 4;
else if (!strcmp("Jun", month))
mon = 5;
else if (!strcmp("Jul", month))
mon = 6;
else if (!strcmp("Aug", month))
mon = 7;
else if (!strcmp("Sep", month))
mon = 8;
else if (!strcmp("Oct", month))
mon = 9;
else if (!strcmp("Nov", month))
mon = 10;
else
mon = 11;
return(mon);
}
int oldDate(char *string, int rightnow) {
int day,year,monthNumber;
char month[10];
float yearFraction, presentYearFraction;
struct tm *now;
sscanf(string,"%2d%3s%2d",&day,month,&year);
year += 2000;
#if 0
printw("%2d%3s%2d= ",day,month,year);
#endif
monthNumber = computeMonthFrom3CharString(month);
yearFraction = computeYearFraction(day,monthNumber,year);
#if 0
printw("%.3f =",yearFraction);
#endif
/* Now compare it to the present time */
now = gmtime(&rightnow);
presentYearFraction = computeYearFraction(now->tm_mday, now->tm_mon, 1900+now->tm_year);
if (fabs(presentYearFraction - yearFraction) > 0.1) {
return(1);
} else {
return(0);
}
}
float computeYearFraction(int day, int month, int year) {
/* day should be 1..31, month should be 0..11, year should be >2000 */
/* returns a value such as 2005.0534 (for some time in January 2005) */
float doy, yearFraction;
int m;
doy = day;
for (m=0; m<month; m++) {
doy += 30;
if (m==2) {
doy--;
if ((year % 4) != 0) {
doy--;
}
}
if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10) {
doy++;
}
}
if ((year % 4) == 0) {
yearFraction = year + doy/366;
} else {
yearFraction = year + doy/365;
}
return(yearFraction);
}