-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvvavi.c
3189 lines (2604 loc) · 128 KB
/
vvavi.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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h> /* file functions & much more... */
#include <stdlib.h> /* integer converts, etc */
#include <dos.h> /* For date stuff, etc. */
#include <conio.h> /* keyboard routines (getch() & kbhit()) */
#include <time.h> /* for timing functions */
#include <string.h> /* for string compare operations */
#include <alloc.h> /* for use of 'coreleft()' function */
#include <vv_sys.h> /* Vermont Views */
#include <vv_wnkt.h> /* Vermont Views - windowing routines */
#include <vv_main.h> /* Vermont Views */
#include "vvdavi.h" /* AVI program function declares & data structs */
#include "hllapi.h" /* Header file for HLLAPI functions */
#include "hllapi.inc" /* Include file of HLLAPI functions */
#include <async.h> /* For ASYNC comm library functions */
ASYNC * comport[3]; /* Pointer to comm ports */
WINDOWPTR rdrwin[4], /* Reader window pointers */
alarmwin, /* Alarm window pointer */
msgwin, /* Message window pointer */
statuswin, /* Status window */
errorwin, /* Error window */
xcierrwin[2]; /* Controller error windows */
FILE * logfile, /* Audit file pointer */
* countsfile, /* Counts file pointer */
* errorfile; /* Error log file pointer */
struct XCIREC xcidata[4]; /* Structures to hold XCI data */
struct BTRVQREC xciqdata; /* Data structure for BTRIEVE Q'ing */
struct AVI param; /* Structure to hold program parameters */
struct COM comset[2]; /* Structure to hold comm settings */
int rdrwinx[4] = {0,40,0,40}, /* X coords for read windows */
rdrwiny[4] = {0,0,9,9}, /* Y coords for reader windows */
rdrwinatt[4] = { /* Reader window color attributes */
LHIGHLITE,LHIGHLITE,
LHIGHLITE,LHIGHLITE},
rdrtitleatt[4] = { /* Rdr window title attributes */
LARROW,LARROW,
LARROW,LARROW},
rdrgood[4] = {0,0,0,0}, /* Good reads counts */
rdrbad[4] = {0,0,0,0}, /* Bad reads counts */
rdrprox[4] = {0,0,0,0}, /* Prox down counts */
rdrdown[4] = {0,0,0,0}, /* Flags for reader down */
rdrbcon[4] = {1,1,1,1}, /* Flag for reader broadcast comm */
qcount[4] = {0,0,0,0}, /* Queue counters */
qcounttotal = 0, /* Total queue counts */
soundflag = 0, /* Soundflag 3-way toggle */
qmax[4], /* Max queue count */
qflag, /* Flag for queueing on/off */
dl10 = -1, /* DL10 present - set to -1 at startup */
error, /* Generic error flag */
xciflag[2] = {0, 0}, /* Flag for XCI controller present */
errorflag[2] = {0, 0}, /* Controller error flags */
hllapiflag = 0, /* HLLAPI on/off flag */
garbcount[2] = {0,0}, /* Garbage counter */
dosbug = 0, /* Day flag for DOS date error handler */
initday, /* Startup day */
initmonth, /* Startup month */
inityear, /* Startup year */
initcentury,
monthdays[] = {0,31,28,31, /* Number of days in each month */
30,31,30,31,31, /* (0 for element 0 in array) */
30,31,30,31}, /* used to correct DOS date bug */
sendcount, /* Total number of sends to broadcast */
dl10dbug = 0; /* DL10 mode flag */
float avgtime; /* Average time to broadcast */
char API_String[255], /* Buffer for HLLAPI calls */
utility[80], /* All-purpose work buffer */
bcsend[30], /* Work buffer for BCPC sends */
pos_blk[128], /* Buffer for BTRV queue file */
err_blk[128], /* Buffer for BTRV error log */
errkey[2], /* Key 0 for BTRV error file */
qkey0[19], /* Lookup key 0 for BTRV Q record */
qkey1[3], /* Lookup key 1 for BTRV Q record */
rdrtitle[4][36], /* Reader window titles */
* msgwintitle = "MESSAGES", /* Message window title */
* version = "AVI/PC v1.00 10/23/91 by JS Butler", /* Version string */
lastgood[4][30], /* Last good read array for no reads */
instring[2][30], /* Input buffers for comm ports */
outstring[30]; /* Output buffers for comm ports */
#include "turcbtrv.c" /* Include file for BTRIEVE interface */
main(void) {
int i,t; /* General purpose integers */
char userkey; /* Holder for user keystrokes */
unsigned long memleft; /* For memory status */
init_vv(); /* Initialize Vermont Views system */
printf("%s\n",version); /* Show version on startup */
getcfginfo(); /* Get info from config file */
initstartday();
initstartmonth();
initstartyear();
initstartcentury();
drawscreen(); /* Draw the screen! */
showavgtime(); /* Show status line info */
openlogfile(); /* Open the audit file */
opencountsfile(0); /* Open counts file */
openerrlog(); /* Open the error log file */
sprintf(utility, "AVI/PC: %s program startup", param.mname);
logerror(utility,"O"); /* Put startup info in ERROR.LOG */
error = openqfile(t); /* Open the BTRV files for queueing */
if(error != 0) { /* Problems? */
sprintf(utility, "AVI/PC: BTRV Error %i opening queue file %i.",
error, t);
outmessage(utility); /* Display the message */
logerror(utility,"O"); /* Log the message in ERROR.LOG */
}
gotoxy(1,1); /* Reset cursor to upper left */
csr_hide(); /* Hide the cursor */
for(t=0; t<2; t++) { /* Check to see what's on each port */
if(strstr(comset[t].device,"XCI") != NULL) { /* XCI on port */
initasync(t); /* Initialize port as XCI */
xciflag[t] = 1; /* Set the XCI flag for this port */
checkxcistatus(0,t); /* Reset XCI message timer for this port */
} else { /* If it's NOT an XCI controller */
if(strstr(comset[t].device,"DL10") != NULL) { /* DL10 on port */
dl10 = t; /* Set DL10 flag */
initdl10(t); /* Initialize com port as DL10 */
}
}
}
if(param.dl10com3 == 1) { /* If DL10 is on COM3: */
initdl10(2); /* Initialize it as such */
dl10 = 2; /* Set DL10 flag */
}
showdl10("SYSTEM INIT - WAIT"); /* Show on DL10 */
if ((error = (get3270())) != 0) { /* If can't connect to HLLAPI session */
msgalert(); /* Turn messages yellow on red */
sprintf(utility, "BCPC: Error %i connecting to 3270!");
outmessage(utility); /* Show error message */
alarm(1,0); /* Sound 1 alarm (no flash) */
logerror(utility, "C"); /* Log error */
msgnormal(); /* Messages back to normal */
if (wn_isup(statuswin) != 0) hidestatus(); /* Hide status window if up */
} else { /* Connected OK */
hllapiflag = 1; /* Set HLLAPI flag */
outmessage("BCPC: Connected to 3270"); /* Show message */
}
if(param.bcautologon == 1) broadcastlogon(); /* logon to broadcast */
showavgtime(); /* Update status line */
showdl10("AVI/PC v1.35 READY"); /* Show DL10 message */
while(userkey != 27) { /* Do until user hits ESCape */
while(!kbhit()) { /* If no key is pressed */
showsystime(); /* Show the current time */
for(t=0;t<2;t++) { /* Repeat twice (2 com ports) */
if(xciflag[t] == 1) { /* If XCI on this com port */
xcihandler(t); /* Call XCI handler routine */
}
}
}
userkey = getch(); /* A key was hit, so get it */
switch(userkey) { /* See what it is */
case 'c': /* Clear the counts */
error = getpassword(15, param.password); /* Get system password */
if(error == 0) { /* If password OK */
clearcounts(); /* Clear counts */
outmessage("USER: Counts cleared");
logerror("USER: Counts cleared","O");
}
break;
case 'l': /* Toggle DL10 mode (normal/debug) */
if(dl10dbug==0) { /* If now NORMAL (0) */
dl10dbug = 1; /* Flip it to DEBUG (1) */
outmessage("USER: DL10 now in debug mode"); /* Show on screen */
showdl10("DL10 DEBUG MODE"); /* Show on DL10 */
break; /* Get out of case statement */
} else { /* If its in DEBUG */
dl10dbug = 0; /* Set to NORMAL */
outmessage("USER: DL10 now in normal operation");
showdl10("DL10 NORMAL MODE"); /* Show on DL10 */
break; /* Get out of CASE statement */
}
case 'q': /* Toggle sound flag */
if(soundflag == 0) { /* If at first toggle position */
soundflag = 2; /* Wrap around to last toggle position */
} else { /* Otherwise... */
soundflag--; /* Decrement toggle position */
}
switch(soundflag) { /* Assemble appropriate message */
case 0:
sprintf(utility,"USER: Sound and flash now ON");
break;
case 1:
sprintf(utility,"USER: Sound is off, flash is on");
break;
case 2:
sprintf(utility,"USER: Sound and flash now OFF");
break;
default:
break;
}
outmessage(utility); /* Show message on screen */
showavgtime(); /* Update status line */
alarm(1,1); /* Alarm with 1 beep & 1 flash */
break; /* Break out of case statement */
case 'b': /* Toggle broadcast */
error = getpassword(15, param.password); /* Get system password */
if(error == 0) { /* If it's OK */
if(param.bccomm == 1) { /* If broadcast now on */
msgnormal(); /* Normal messages */
param.bccomm = 0; /* Set broadcast flag */
outmessage("USER: Broadcast communications now OFF!");
logerror("USER: Broadcast communications now OFF!","C");
} else { /* Otherwise... */
param.bccomm = 1; /* Set broadcast flag */
outmessage("USER: Broadcast communications now ON!");
logerror("USER: Broadcast communications now ON!","C");
}
showavgtime(); /* Update status line */
}
break; /* Break out of functon */
case 'x': /* Toggle HLLAPI connection */
error = getpassword(15, param.password); /* Get system password */
if(error == 0) { /* If it's OK */
if(hllapiflag == 1) { /* If HLLAPI's now ON */
msgalert(); /* Set message output to alert colors */
outmessage("USER: 3270 HLLAPI link cut!"); /* Show message */
alarm(1,0); /* Alarm with 1 beep and no flashes */
logerror("USER: 3270 HLLAPI link cut!", "C"); /* Log it */
drop3270(); /* Call function to cut 3270 */
hllapiflag = 0; /* Reset HLLAPI flag */
msgnormal(); /* Reset message colors */
} else { /* If HLLAPI's now OFF */
if((error = get3270()) == 0) { /* If restored OK */
outmessage("USER: 3270 HLLAPI link restored");
logerror("USER: 3270 HLLAPI link restored","C");
hllapiflag = 1; /* Set flag back to 1 */
} else { /* Error restoring HLLAPI */
msgalert(); /* Alert messages */
sprintf(utility,
"USER: 3270 HLLAPI link NOT restored! (Error %i)",
error);
outmessage(utility); /* Show error message */
alarm(1,1); /* Sound alarm & flash */
logerror(utility,"C"); /* Log error message */
msgnormal(); /* Reset message colors */
}
}
}
break;
case 'm': /* Display free memory */
memleft = coreleft(); /* Get the amount of mem left */
sprintf(utility, "USER: System memory free %lu", memleft);
outmessage(utility); /* Show it */
break; /* Done */
case 'v': /* Display version information */
sw_att(LHIGHLITE, msgwin); /* Change window output colors */
sw_bdratt(LDEBUGMSG, msgwin);
wn_upd(msgwin); /* Update the window */
outmessage(version); /* Show the version string */
msgnormal(); /* Reset the message colors */
break; /* Done */
case 'd': /* Test DL10 display, if attached */
testdl10(); /* Call function */
break; /* Done */
case 's': /* User wants a status check */
outmessage("USER: Status check");
for(t=0; t<2; t++) { /* Once for each com port */
if(xciflag[t] == 1) { /* Does it have an XCI controller? */
a_putc('r',comport[t]); /* Send an 'r' to XCI to get status */
}
}
break; /* End case statement */
case '1': /* Toggle broadcast comm for readers */
rdrtoggle(0); /* Call function */
break;
case '2':
rdrtoggle(1);
break;
case '3':
rdrtoggle(2);
break;
case '4':
rdrtoggle(3);
break;
case 27: /* ESC key - exit program */
error = getpassword(15, param.password); /* Get system password */
if(error == 0) { /* If it's OK */
outmessage("USER: Password OK - closing down");
logerror("USER: Password OK - closing down","O");
msgnormal();
break;
} else {
if(error != 0) userkey = ' '; /* Reset key buffer */
break;
}
default: /* Unrecognized key */
alarm(1,0); /* Beep */
}
}
if(param.bccomm != 0) {
showstatus("AVI/PC STATUS"); /* Put up status window */
statusmsg("Logging off...."); /* Show status message */
sendkeystrokes("logoff",param.hkeydelay); /* Send to broadcast */
hidestatus(); /* Remove status window */
}
drop3270(); /* Drop HLLAPI connection */
closeerrlog(); /* Close the error log */
cleardl10(); /* Clear DL10 display */
undrawscreen(); /* Remove windows and erase screen */
a_close(comport[0],0); /* Close COM1: */
a_close(comport[1],0); /* Close COM2: */
if(param.dl10com3 == 1) { /* If DL10 on COM3: */
a_close(comport[3],0); /* Close it */
}
closeqfile(); /* Close BTRV queue file */
updatecountsfile(); /* Write counts */
flushall(); /* Close all open files */
exit_vv(); /* Release Vermont Views */
clrscr(); /* Clear the screen */
exit(0); /* That's all folks! */
return(0); /* To shut the compiler up */
}
/***************************************************************************/
/* AVI/PC ROUTINES */
/***************************************************************************/
void clearcounts() {
/*********************************************************************/
/* Clears counts and updates screen and counts file */
/*********************************************************************/
int t; /* Counter */
for(t=0;t<4;t++) { /* Repeat once for each reader */
rdrgood[t] = 0; /* Clear good reads */
rdrbad[t] = 0; /* Clear bad reads */
rdrprox[t] = 0; /* Clear prox counts */
showcounts(t); /* Show new counts */
}
updatecountsfile(); /* Write cleared counts to counts file */
}
int rdrtoggle(int w) {
/*********************************************************************/
/* PURPOSE: Toggles broadcast communications for a reader */
/* PARAMS: int w - reader to toggle */
/* RETURNS: 0 if successful or 1 if reader not installes */
/*********************************************************************/
if (strstr((char *) rdrtitle[w],"UNUSED") != NULL) { /* No reader here! */
sprintf(utility, "USER: Reader %i is not installed!", w);
outmessage(utility); /* Show error message */
alarm(1,0); /* Beep */
return(1); /* Return error */
}
if((error = getpassword(15,param.password)) == 0) { /* Get password */
if(rdrbcon[w] != 0) { /* If broadcast is on for reader */
rdrbcon[w] = 0; /* Turn it off */
rdrwinatt[w] = LFLDACT; /* Change color attribute for reader win */
changewindow(w,rdrwinatt[w]); /* Change reader window */
sprintf(utility, "USER: Reader %i broadcast OFF", (w+1));
outmessage(utility); /* Show message */
return(0); /* Return OK */
} else { /* If reader is off */
rdrbcon[w] = 1; /* Turn it on */
rdrwinatt[w] = LHIGHLITE; /* Change window color attribute */
changewindow(w,rdrwinatt[w]); /* Change window */
sprintf(utility, "USER: Reader %i broadcast ON", (w+1));
outmessage(utility); /* Show message */
}
}
updatecountsfile(); /* Store change in counts file */
return(0); /* Return OK */
}
int isprintstr(char * teststring) {
/*********************************************************************/
/* PURPOSE: Sees if string has no unprintable characters in it */
/* PARAMS: char * testring - pointer to string to test */
/* RETURNS: 1 if unprintable characters or 0 if OK */
/*********************************************************************/
int t, /* Counter */
slen; /* String length */
slen = strlen(teststring); /* Get string length */
for(t=0; t<slen; t++){ /* Repeat for length of string */
if (!isprint(teststring[t])) return(1); /* Check each character */
} /* and return if unprintable */
return(0); /* Return OK if all chars check out */
}
int getpassword(int passtime, char * password) {
/*********************************************************************/
/* PURPOSE: gets a password within an alloted number of seconds */
/* PARAMS: int passtime - number of seconds to wait for password */
/* char * password - password to wait for */
/* RETURNS: 0 if password is correct, 1 if not, 2 if time expired */
/*********************************************************************/
clock_t start, end; /* Start & end time holders */
char temp; /* Holds user keystroke */
int counter = 0, /* Keystroke counter */
countlen = strlen((char *) password); /* Length of password */
float etime; /* Elapsed time */
msgalert(); /* Alert messages */
sprintf(utility,"USER: Type password within %i seconds", passtime);
outmessage(utility); /* Prompt user */
start = clock(); /* Store start time (clock ticks) */
do { /* Repeat loop */
end = clock(); /* Get current time in clock ticks */
gotoxy(1,1); /* Move cursor */
etime = ((end-start)/18.2); /* Calculate elapsed time in seconds */
if(kbhit()) { /* If a key was hit */
temp = getch(); /* Get the key */
if(temp != password[counter++]) {
/* Compare it with password array character and advance */
/* counter */
outmessage("USER: Password incorrect."); /* Show message */
logerror("USER: Password incorrect.","O"); /* Log error */
msgnormal(); /* Normal message color */
return(1); /* Return error message */
}
}
} while((etime < passtime) && (counter < countlen));
/* Repeat while elapsed time is less than wait time and number of */
/* keystrokes is less than length of password (no need to hit RETURN) */
if(counter==countlen) { /* If entered full length of password */
msgnormal(); /* Normal message color */
return(0); /* Return OK */
} else { /* Otherwise, time ran out! */
outmessage("USER: 15 seconds elapsed....try again....");
logerror("USER: 15 seconds elapsed....try again....","O");
msgnormal(); /* Normal messages */
return(2); /* Return 2 for timeout error */
}
}
int validate(char * string, int valtype) {
/*********************************************************************/
/* PURPOSE: Checks a string to see if it's all number or letters */
/* PARAMS: char * string - string to test */
/* int valtype - 0 for numeric, 1 for alpha check */
/* RETURNS: 1 if check fails, 0 if checks ok */
/*********************************************************************/
int t; /* Counter */
switch(valtype) {
case 0: /* Test string for numbers only */
for(t=0; t<(strlen(string)); t++) { /* Check each character */
if(!(isdigit(string[t]))) return(1); /* Return if not numeric */
}
break; /* Break out of case */
case 1: /* Test string for alpha only */
for(t=0; t<(strlen(string)) ;t++) { /* Check each character */
if(!(isalpha(string[t]))) return(1); /* Return if non alpha */
}
break; /* Break out of function */
}
return(0); /* Return OK */
}
void getdatestr(char * string) {
/*********************************************************************/
/* PURPOSE: Place today's date in mm/dd/yy format in string */
/* PARAMS: char * testring - pointer to buffer to put date in */
/* RETURNS: nothing */
/*********************************************************************/
struct date nowdate; /* Data structure for current time */
int month, day, year; /* Whaddya think? */
getdate(&nowdate); /* Get today's date */
day = nowdate.da_day; /* Break down date into integers */
month = nowdate.da_mon;
year = nowdate.da_year;
sprintf(string, /* Put in string buffer. As an */
"%02i/%02i/%02i", /* example, February 14, 1991 would */
month,day,(year-initcentury)); /* be '02/14/91'*/
}
void gettimestr(char * string) {
/*********************************************************************/
/* PURPOSE: Place current time in HH:MM:SSXM format in string */
/* PARAMS: char * string - pointer to buffer to put time in */
/* RETURNS: nothing */
/*********************************************************************/
struct time nowtime; /* Data structure for current time */
int hour, minute, second; /* Whaddya think? */
gettime(&nowtime); /* Get the current time */
hour = nowtime.ti_hour; /* Breakout hour */
minute = nowtime.ti_min; /* Breakout minute */
second = nowtime.ti_sec; /* Breakout second */
if(hour > 12) { /* If hour is larger than 12 */
sprintf(string,"%02i:%02i:%02iPM",
(hour-12),minute,second); /* Example: 01:12:43PM */
} else {
if(hour <12) { /* If hour is smaller than 12 */
sprintf(string,"%02i:%02i:%02iAM",
hour,minute,second); /* Example 10:48:11AM */
} else { /* If hour equals 12 */
sprintf(string,"%02i:%02i:%02iPM",
hour,minute,second); /* Example 12:24:38pm */
}
}
}
int openlogfile() {
/*********************************************************************/
/* PURPOSE: Opens the audit log file 'AUDITnn.LOG', where nn is the */
/* number of the current month. For example, if today were */
/* January 1, 1992, we'd open 'AUDIT01.LOG'. */
/* PARAMS: none */
/* RETURNS: nothing */
/*********************************************************************/
struct date logdate; /* Data structure for today's date */
int month; /* Integer for month number */
char filename[14]; /* Buffer for filename */
getdate(&logdate); /* Get today's date */
month = logdate.da_mon; /* Get the month number */
/* Prepare the filename: AUDIT##.LOG, where ## is the month number */
sprintf(filename,"AUDIT%02i.LOG",month); /* Prepare the filename */
sprintf(utility, "AVI/PC: Opening audit file %s", filename);
outmessage(utility); /* Show message */
if ((logfile = fopen(filename, "at")) == NULL) { /* If can't open file */
msgalert(); /* Alert message colors */
outmessage("AVI/PC: Error opening log file!"); /* Show message */
alarm(2,1); /* Alarm twice with 1 flash */
logerror("AVI/PC: Error opening log file!", "O"); /* Log it */
msgnormal(); /* Normal messages */
return(1); /* Bail out of function with error */
}
return(0); /* Return from function */
}
int closelogfile() {
if((error = fclose(logfile)) != 0) {
sprintf(utility, "AVI/PC: Error %i closing log file",error);
msgalert();
outmessage(utility);
logerror(utility, "O");
msgnormal();
return(error);
}
return(0);
}
int opencountsfile(int flag) {
/*********************************************************************/
/* PURPOSE: Opens the counts file and reads in the counts for all */
/* readers, as well as the current state of the broadcast */
/* communications, the sound toggle, and the queue counts. */
/* PARAMS: flag (this was to clear the counts - obsolete) */
/* RETURNS: 0 if successful or 1 is there's an error */
/*********************************************************************/
char filename[14], /* Buffer for filename */
temp1[8], /* Temp strings */
temp2[8],
temp3[8];
int t; /* Integer for counter */
sprintf(filename,"COUNTS.FIL"); /* Load filename buffer */
if ((access(filename,0) == 0) && (flag == 0)) { /* Does file exist? */
if ((countsfile = fopen(filename, "r+")) == NULL) { /* If can't open */
msgalert();
outmessage("AVI/PC: Error opening counts file!"); /* Show error */
logerror("AVI/PC: Error opening counts file!","O"); /* Log error */
msgnormal();
return(1); /* Return error code */
}
outmessage("AVI/PC: Retrieving counts");
for(t=0;t<4;t++) { /* Once for each reader */
fgets(temp1, 8, countsfile); /* Get line with good reads */
fgets(temp2, 8, countsfile); /* Get line with bad reads */
fgets(temp3, 8, countsfile); /* Get line with prox count */
rdrgood[t] = atoi((char *) temp1); /* Convert goods to integer */
rdrbad[t] = atoi((char *) temp2); /* Convert bads to integer */
rdrprox[t] = atoi((char *) temp3); /* Convert prox count to integer */
if (strstr((char *) rdrtitle[t],"UNUSED") == NULL) {
/* If reader installed here, show counts */
showcounts(t);
}
}
for(t=0;t<4;t++) { /* Get queue counts for each reader */
fgets(temp1,8,countsfile); /* Get line from counts file */
qcount[t] = atoi((char *) temp1); /* Convert line to int */
qcounttotal = qcounttotal + qcount[t]; /* Add total queue count */
}
for(t=0;t<4;t++) { /* Get reader broadcast comm status */
fgets(temp1,8,countsfile); /* Get line from file */
rdrbcon[t] = atoi((char *) temp1); /* Convert to integer */
if(rdrbcon[t] != 0) { /* If it's broadcast is on for reader */
if (strstr((char *) rdrtitle[t],"UNUSED") == NULL) {
/* If a reader is installed here the reader title */
/* shouldn't have "UNUSED" in it! */
rdrwinatt[t] = LHIGHLITE; /* Set the reader window color */
changewindow(t,rdrwinatt[t]); /* Change reader window */
}
} else { /* If broadcast is off for this reader */
if (strstr((char *) rdrtitle[t],"UNUSED") == NULL) {
/* If a reader is installed here */
rdrwinatt[t] = LFLDACT; /* Change window attribute */
changewindow(t,rdrwinatt[t]); /* Change reader window */
}
}
}
fgets(temp1,8,countsfile); /* Get line from file */
soundflag = atoi((char *) temp1); /* Convert & store as soundflag */
} else { /* If file doesn't exist, create & open */
if ((countsfile = fopen(filename, "w+")) == NULL) { /* File error ? */
msgalert();
outmessage("AVI/PC: Error opening counts file!"); /* Show error */
logerror("AVI/PC: Error opening counts file!","O"); /* Log error */
msgnormal();
return(1); /* Return error code */
} else {
for(t=0; t<4; t++) { /* Once for each reader window */
if (strstr((char *) rdrtitle[t],"UNUSED") == NULL) {
/* If reader is installed for window */
showcounts(t); /* Show the counts */
}
}
}
}
if(qcounttotal != 0) qflag = 1; /* Turn queue flag on if queues exist */
return(0); /* Return with no error */
}
int updatecountsfile() {
/*********************************************************************/
/* PURPOSE: Updates counts file with current counts */
/* PARAMS: none */
/* RETURNS: 0 if successful or 1 if error writing to file */
/*********************************************************************/
int t; /* Counter integer */
if(countsfile == NULL)
return(1); /* If file isn't open, abort function */
rewind(countsfile); /* Move file pointer to beginning of file */
for(t=0;t<4;t++) { /* Repeat once for each reader */
/* Write good reads, bad reads, & prox counts to file */
fprintf(countsfile,"%i\n%i\n%i\n",rdrgood[t],rdrbad[t],rdrprox[t]);
}
for(t=0;t<4;t++) { /* Repeat once for each reader */
fprintf(countsfile,"%i\n",qcount[t]); /* Write queue counts */
}
for(t=0;t<4;t++) { /* Repeat once for each reader */
/* Write broadcast communications toggles for each reader */
fprintf(countsfile,"%i\n",rdrbcon[t]);
}
fprintf(countsfile,"%i\n",soundflag); /* Write sound toggle */
return(0); /* Return from function */
}
int logtrans(int rdrnum) {
/*********************************************************************/
/* PURPOSE: Logs current tag read to audit file */
/* PARAMS: logical reader number to log for (11, 31, etc) */
/* RETURNS: 0 if successful or 1 if error writing to file */
/*********************************************************************/
char msg[255]; /* Buffer for message */
/* Print record to a string prior to writing to audit file */
sprintf(msg,"%s,%s,%02i%02i%02i,%02i%02i%02i,%s,%s,%s",
xcidata[rdrnum].readerport, xcidata[rdrnum].tagid,
xcidata[rdrnum].year,xcidata[rdrnum].month, xcidata[rdrnum].day,
xcidata[rdrnum].hour,xcidata[rdrnum].minute,xcidata[rdrnum].second,
xcidata[rdrnum].samereads,xcidata[rdrnum].goodreads,
xcidata[rdrnum].dblevel);
if(logfile != NULL) { /* If audit file is open */
fprintf(logfile, "%s\n", msg); /* Write the record to file */
return(0); /* Return from function */
} else { /* If audit file ISN'T open */
return(1); /* Bail out of function with error */
}
return(0); /* Return with no errors */
}
int stripnewline(char * string) {
/*********************************************************************/
/* PURPOSE: Strips newline character from a character string */
/* PARAMS: none */
/* RETURNS: 0 */
/*********************************************************************/
int t; /* Counter integer */
for(t=0;t<(strlen(string));t++) { /* Repeat for length of string */
/* If newline character, terminate string by inserting ASCII 0 */
if(string[t] == '\n') string[t] = '\0';
}
return(0); /* Return from function */
}
int showxcierrwin(int com) {
/*********************************************************************/
/* PURPOSE: Shows error window if XCI controller goes down */
/* PARAMS: Logical controller number (0 or 1) */
/* RETURNS: 0 */
/*********************************************************************/
int t; /* counter */
char title[80], /* Buffer for window title */
message[80], /* Message buffer */
nowtime[11], /* Buffer for time */
nowdate[9]; /* Buffer for date */
if wn_isup(xcierrwin[com]) /* Is it already up for some reason? */
return(1); /* If it is, return with an error */
gettimestr(nowtime); /* Get the current time and store in nowtime */
getdatestr(nowdate); /* Get the current date and store in nowdate */
sprintf(title, " COMMUNICATIONS PORT %i ERROR AT %s ON %s! ",
(com+1), nowtime, nowdate); /* Prepare error message */
alarm(3,1); /* Sound alarm & flash */
sw_title(title, LDEBUGMSG, TOPCENTER,
xcierrwin[com]); /* Change window's title attribs */
wn_expset(xcierrwin[com]); /* Explode window up */
sprintf(message, "XCI CONTROLLER '%s' AT '%s' IS DOWN!",
(char *) comset[com].comctrldesc,
(char *) comset[com].ctrlloc); /* Prepare message */
/* Show message in center of window */
v_stpl(3, CENTER_TEXT, message, xcierrwin[com]);
return(0); /* End function */
}
int hex2dec(char * string) {
/*********************************************************************/
/* PURPOSE: Converts a hexadecimal number to a decimal integer */
/* PARAMS: char * string - string containing hex number */
/* RETURNS: integer containg decimal number */
/*********************************************************************/
int multi; /* Multiplier */
strupr(string); /* Convert hex string to uppercase */
if(isupper(string[1])) { /* If second char is A thru F */
/* Convert to decimal by subtracting from ASCII value */
multi = ((int) string[1] - 55);
} else { /* If not... */
/* subtract ASCII value to get decimal value */
multi = ((int) string[1] - 48);
}
if(isupper(string[0])) { /* If first char is A thru F....*/
/* Convert ASCII char to decimal & multiply by 16,
adding value of second char */
multi = multi + (((int) string[0] -55) *16);
} else {
/* If number, convert ASCII to decimal number & multiply * 16,
adding value of second char */
multi = multi + ((int) string[0] - 48) * 16;
}
return(multi); /* Return decimal value */
}
void stathandle(int com) {
/*********************************************************************/
/* PURPOSE: Handles status messages from XCI controller */
/* PARAMS: com port status message came in on (0 or 1) */
/* RETURNS: 0 */
/*********************************************************************/
int statint, /* Integer for hex status checksum */
t, /* counter */
winno, /* logical reader window number to update */
multi = 1; /* multiplier for bit operations */
char statmsg[5];
strmid(instring[com], 4, 2, statmsg);
statint = hex2dec(statmsg);
for(t=0;t<2;t++) {
if((comset[com].reader[t].rdrnum !=0) && ((statint & multi) != multi)) {
/* If reader exists and bit for reader is off */
rdrdown[((com+com)+t)] = 1; /* Set flag for reader down */
changewindow((com+com)+t,LDEBUG); /* change reader window to red */
sprintf(utility, "XCI %i: Reader %i down!",(com+1), (t+1));
msgalert(); /* Alert message output */
outmessage(utility); /* show message */
/* If reader down alarm is set for this reader, sound alarm */
if(comset[com].reader[t].rdrdownalarm == 1)
alarm(5,1);
logerror(utility, "E"); /* Log error in file */
msgnormal(); /* Return to normal output message color */
if(param.bccomm == 1 && rdrbcon[((com+com)+t)] == 1) {
/* If broadcast communication for AVIPC & reader are on */
error = getportnum(com, t); /* Get the port number (11, 31 etc) */
sprintf(bcsend,"BCPC%iDOWN %.3sRT", /* prepare BCPC message */
error,comset[com].reader[t].rdrloc);
sendbcpc(bcsend); /* send it */
}
} else { /* if checksum from XCI shows reader is attached */
if(rdrdown[((com+com)+t)] == 1) { /* if reader down flag is set */
/* change the reader window back to normal */
/* ((com+com)+t) will calculate the array offset
example: reader 0 (the first reader) on com 2
(known to program as 1 in 'com' variable) would
calculate: 1+1+0=2 so we now have an array
offset. For example: rdrwin[2]. */
changewindow(((com+com)+t), rdrwinatt[((com+com)+t)]);
rdrdown[((com+com)+t)] = 0; /* reset the reader down flag */
/* prepare message for display and error log */
sprintf(utility, "XCI %i: Reader %i now online",
(com+1), (t+1));
outmessage(utility); /* Show message in message window */
logerror(utility,"E"); /* Log message to error log file */
error = getportnum(com,t); /* Get BCPC port number */
sprintf(bcsend,"BCPC%iUP %.3sUT",
error,comset[com].reader[t].rdrloc); /* prepare BCPC message */
if(param.bccomm == 1 && rdrbcon[((com+com)+t)] == 1) {
/* If AVIPC & reader broadcast communications are on */
sendbcpc(bcsend); /* send it */
}
}
msgnormal(); /* Reset msg window output to default */
}
multi = (multi + multi) * 2; /* add to multi for second comm port */
}
}
int getportnum(int comport, int rdrport) {
/*********************************************************************/
/* PURPOSE: Returns a BCPC port number for a reader based on which */
/* comm port & reader port it's on */
/* PARAMS: int comport - which comport (0 or 1) it's on */
/* int rdrport - which reade port (0 or 1) it's on */
/* RETURNS: the port number for BCPC (11, 31, 21 or 41) */
/*********************************************************************/
/* COM1: Reader 1 */
int portnum = 11;
/* COM1: Reader 2 */
if((comport == 0) && (rdrport == 1)) portnum = 31;
/* COM2: Reader 1 */
if((comport == 1) && (rdrport == 0)) portnum = 21;
/* COM2: Reader 2 */
if((comport == 1) && (rdrport == 1)) portnum = 41;
return(portnum); /* Return the port number */
}
int alarm(int number, int flash) {
/*********************************************************************/
/* PURPOSE: Sounds an alarm & optionally flashes message window */
/* PARAMS: int number - number of times to sound alarm */
/* int flash - 1 for flash or 0 for no flash */
/* RETURNS: always 0 */
/*********************************************************************/
int t; /* Counter */
if(soundflag == 2) return(0); /* If no sound or flash return */
for(t=0;t<number;t++) { /* Repeat for number */
if(flash == 1) { /* If flash flag is on... */
/* Flash window */
sw_att(LDEBUG,alarmwin);
if(wn_isup(alarmwin)!=0) wn_dn(alarmwin);
wn_up(alarmwin);
if(soundflag == 1) time_delay(7);
}
if(soundflag == 0) beep_vv(7, 1000); /* If sound flag on, beep */
if(flash == 1) { /* If flash flag is on */
/* Flash over message window */
sw_att(LREVERSE,alarmwin);
wn_dn(alarmwin);
wn_up(alarmwin);
if(soundflag == 1) time_delay(7); /* Pause flash if no sound */
}
if(soundflag == 0) beep_vv(7, 800); /* If sound flag, beep */
}
/* Repeat the same process, but with lower tone */
if(flash == 1) {
for(t=0;t<3;t++) {
sw_att(LDEBUG,alarmwin);
if(wn_isup(alarmwin)!=0) wn_dn(alarmwin);
wn_up(alarmwin);
time_delay(7);
sw_att(LREVERSE,alarmwin);
wn_dn(alarmwin);
wn_up(alarmwin);
time_delay(7);
}
}
if(wn_isup(alarmwin)!=0) wn_dn(alarmwin);
return(0);
}
int getcfginfo() {
/*********************************************************************/
/* PURPOSE: Retrieves data from config file & stores in structures */
/* PARAMS: none */
/* RETURNS: 0 if successful or 1 if error */
/*********************************************************************/
int t, multi, loop1, loop2, loop3;
char cfgparam[30]; /* Buffer for lines from file */
FILE * cfg; /* File pointer */
if((cfg = fopen("NETAVI.CFG","rt")) == NULL) {
/* If error opening file, abort the program */
printf("FATAL ERROR! Could not access NETAVI.CFG!\n");