← Back to dashboard

File view

plc_print.lib

1
/*** BeginHeader */
2
3
#ifndef __ISM_PRINT_
4
#define __ISM_PRINT_
5
6
/*** EndHeader */
7
8
/*** BeginHeader
9
10
     InitializePrint,
11
     HandlePrint,
12
     PrintTestLog,
13
     PrintAlarmLog,
14
     PrintSystemLog,
15
     PrintConfig,
16
     AddPrintEvent
17
*/
18
19
//Global function prototypes **************************************************
20
21
void  InitializePrint	(void);
22
void 	HandlePrint			(void);
23
void	PrintTestLog		(void);
24
void	PrintAlarmLog		(void);
25
void	PrintSystemLog		(void);
26
void	PrintConfig			(void);
27
void	PrintTest3P			(void);
28
void	AddPrintEvent		(int eventType, char *eventLine1, char *eventLine2, int chan);
29
30
/*** EndHeader */
31
32
//Local function prototypes *********************************************
33
34
void 	PrintEvent			(char *eventLine1, char *eventLine2);
35
36
void	PrintStateHandler	(void);
37
void	PrintReportInit 	(int init);
38
void	PrintReportCurrent(int first);
39
void	PrintReportTitle 	(int first);
40
void	PrintReportTest1 	(int first);
41
void	PrintReportTest2 	(int first);
42
void	PrintReportTest3F (int first);
43
void	PrintReportTest3P (int first);
44
void	PrintReportAlarm 	(int first);
45
void	PrintReportSystem (int first);
46
void	PrintReportConfig (int first);
47
void	PrintReportEnd 	(int first);
48
49
//Constants *******************************************************
50
51
52
/*** Local variables ***/
53
54
int	PreviousPrintState;						// index for previous active state
55
int	PrintState;										// index pointing to next state
56
int	RestartPrintState;
57
int	ActivePrintFlag;
58
int	ActiveReportFlag;
59
int	Prod;
60
int	ReportCycle;
61
int	TestCount;
62
char	AlarmBuffer[N_ISM*2][BOUTBUFSIZE-2];
63
char	TestBuffer[N_ISM*2][BOUTBUFSIZE-2];
64
char  WarnBuffer[N_ISM*2][BOUTBUFSIZE-2];
65
char	PrintLine[BOUTBUFSIZE-2];
66
char 	BlankPrintLine[BOUTBUFSIZE-2];
67
char	tmpResult[BOUTBUFSIZE-2];
68
69
//	Print State indexes list ***************************************************************
70
71
enum {
72
	PRINT_NOSTATE 	= -1,
73
   PRINT_CURRENT	= 0,
74
   PRINT_TITLE		= 1,
75
   PRINT_TEST1,
76
   PRINT_TEST2,
77
   PRINT_TEST3F,
78
   PRINT_TEST3P,
79
   PRINT_ALARM,
80
   PRINT_SYSTEM,
81
   PRINT_CONFIG,
82
   PRINT_END
83
};
84
85
// Print State machine table **************************************************************
86
87
void (* const PrintStateTable[]) () = {
88
   PrintReportCurrent,
89
	PrintReportTitle,
90
	PrintReportTest1,
91
   PrintReportTest2,
92
   PrintReportTest3F,
93
   PrintReportTest3P,
94
	PrintReportAlarm,
95
	PrintReportSystem,
96
	PrintReportConfig,
97
   PrintReportEnd
98
};
99
100
//Code  ************************************************************************
101
102
void InitializePrint (void)
103
{
104
	int i;
105
	printf("Init Print ...\n");
106
	ActivePrintFlag = 0;
107
   	ActiveReportFlag = 0;
108
   	Prod = 0;
109
   	ReportCycle = 0;
110
   	PrintReportInit(PRINT_CURRENT);
111
   	for (i = 0 ; i < BOUTBUFSIZE-2 ; i++)
112
   	{
113
   		BlankPrintLine[i] = '\0';
114
   	}
115
   	for (i = 0 ; i < N_ISM*2 ; i++)
116
   	{
117
   		strcpy(AlarmBuffer[i], BlankPrintLine);
118
      	strcpy(TestBuffer[i],  BlankPrintLine);
119
      	strcpy(WarnBuffer[i],  BlankPrintLine);
120
   	}
121
   	strcpy(PrintLine, BlankPrintLine);
122
}
123
124
// Printer Handler *************************************************************
125
126
void HandlePrint(void)
127
{
128
	int i;
129
   int tickResult;
130
131
   tickResult = PrintTick();
132
   tickResult = 0;
133
134
	if (ActivePrintFlag)
135
	{
136
	   if (tickResult == PRINT_ERROR_NONE)
137
	   {
138
	      EnquePrintLine(PrintLine);
139
	      ActivePrintFlag = 0;
140
	   }
141
	   else if (tickResult == PRINT_ERROR_PRINTER_NOT_READY)
142
	   {
143
	      // just wait. It could take a long time for printer to be ready.
144
	      // Suppose, for example, CTS goes away when 90% of the 5KB
145
	      //  printer buffer is full. And suppose CTS comes back when
146
	      //  the printer buffer is 10% full. It could take a long time
147
	      //  for the printer to grind out 80% of the 5KB buffer.
148
	      // On the other hand, if it has been a really really long time,
149
	      //   you might want to do something else. I don't know what.
150
	   }
151
	}
152
	else // we are not sending a report
153
	{
154
    	PrintStateHandler();
155
156
	   if (tickResult != PRINT_ERROR_NONE)
157
	   {
158
	      // if you want to do anything here, such as do something
159
	      //   if you get PRINT_ERROR_PRINTER_NOT_READY. But remember,
160
	      //   the printer might go not-ready after you send the last
161
	      //   line of the report, and it may stay not ready for
162
	      //   quite a long time.
163
	   }
164
	}
165
}
166
167
// Add Event *******************************************************************
168
169
void	AddPrintEvent(int eventType, char *eventLine1, char *eventLine2, int chan)
170
{
171
	if (eventType == ALRM_LOG)
172
   {
173
		strcpy(AlarmBuffer[chan*2],   eventLine1);
174
   	strcpy(AlarmBuffer[chan*2+1], eventLine2);
175
   }
176
	else if (eventType == WARN_LOG)
177
   {
178
		strcpy(WarnBuffer[chan*2],   eventLine1);
179
   	strcpy(WarnBuffer[chan*2+1], eventLine2);
180
   }
181
   else if (eventType == TEST_LOG)
182
   {
183
		strcpy(TestBuffer[chan*2],   eventLine1);
184
   	strcpy(TestBuffer[chan*2+1], eventLine2);
185
   }
186
}
187
188
// Print Event Handler *********************************************************
189
190
void PrintEvent(char *eventLine1, char *eventLine2)
191
{
192
	char 	ts[16+1];
193
   char	printTmp[BOUTBUFSIZE-2];
194
   TmStr tmpTime;
195
	Ms    timeData;
196
	char	year;
197
198
   if (!ActivePrintFlag)
199
   {
200
	   timeData = SEC_TIMER;
201
	   mktm(&tmpTime,timeData);
202
      if (tmpTime.tm_year > 99)
203
      	year = tmpTime.tm_year - 100;
204
      else
205
      	year = tmpTime.tm_year;
206
	   sprintf(ts,"%02d/%02d/%02d %02d:%02d", tmpTime.tm_mon,
207
      													tmpTime.tm_mday,
208
                                             			  year,
209
	                                          tmpTime.tm_hour,
210
                                             tmpTime.tm_min);
211
		sprintf(printTmp, "%s\n%s\n%s\n\n\n\n\n", ts, eventLine1, eventLine2);
212
      strcpy(PrintLine,printTmp);
213
      //printf(PrintLine);
214
	   ActivePrintFlag = 1;
215
   }
216
}
217
218
// Print Init State ************************************************************
219
void	PrintReportInit (int init) 
220
{
221
	if (ActiveReportFlag == 0) 
222
	{
223
		PreviousPrintState - 1;
224
      	ActiveReportFlag = init;
225
      	if (init == PRINT_TEST1  || init == PRINT_TEST3P ||
226
      	 	init == PRINT_ALARM  || init == PRINT_SYSTEM ||
227
      	 	init == PRINT_CONFIG) 
228
		{
229
      		UpdataFlashLog();
230
      		PrintState = PRINT_TITLE;
231
      	}
232
      	else
233
	  	{
234
      		PrintState = PRINT_CURRENT;
235
	  	}
236
		RestartPrintState = 0;
237
	}
238
}
239
240
// Print State handler ********************************************************************
241
242
void PrintStateHandler (void)	
243
{
244
	int first;
245
	int tmpPrintState;
246
	first = 0;
247
248
	if (PreviousPrintState != PrintState || RestartPrintState) 
249
	{
250
	   first = 1;
251
	   RestartPrintState = 0;
252
	}
253
	tmpPrintState 			= PrintState;
254
	PrintStateTable[PrintState] (first);
255
	PreviousPrintState 	= tmpPrintState;
256
}
257
258
// Print Current State *********************************************************
259
void	PrintReportCurrent (int first)
260
{
261
	int i;
262
263
   if (first)
264
   {
265
   		ActiveReportFlag = PRINT_CURRENT;
266
   }
267
   else
268
   {
269
	   for (i = 0 ; i < N_ISM ; i++)
270
	   {
271
	      if (AlarmBuffer[i*2][0] != '\0')
272
	      {
273
	         PrintEvent(AlarmBuffer[i*2], AlarmBuffer[i*2+1]);
274
	         strcpy(AlarmBuffer[i*2], BlankPrintLine);
275
	         strcpy(AlarmBuffer[i*2+1], BlankPrintLine);
276
	         PrintState = PRINT_CURRENT;
277
	         break;
278
	      }
279
	      if (WarnBuffer[i*2][0] != '\0')
280
	      {
281
	         PrintEvent(WarnBuffer[i*2], WarnBuffer[i*2+1]);
282
	         strcpy(WarnBuffer[i*2], BlankPrintLine);
283
	         strcpy(WarnBuffer[i*2+1], BlankPrintLine);
284
	         PrintState = PRINT_CURRENT;
285
	         break;
286
	      }
287
	      if (TestBuffer[i*2][0] != '\0')
288
	      {
289
	         PrintEvent(TestBuffer[i*2], TestBuffer[i*2+1]);
290
	         strcpy(TestBuffer[i*2], BlankPrintLine);
291
	         strcpy(TestBuffer[i*2+1], BlankPrintLine);
292
	         PrintState = PRINT_CURRENT;
293
	         break;
294
	      }
295
	   }
296
   }
297
}
298
299
// Print Title State ***********************************************************
300
void	PrintReportTitle (int first)
301
{
302
	if (first)
303
   {
304
   	sprintf(tmpResult,"     PLC-5000\n%s - %s\n", my_id, VersionString());
305
      strcpy(PrintLine,tmpResult);
306
   	ActivePrintFlag = 1;
307
   }
308
   else
309
   {
310
	   #ifdef STA
311
	   	sprintf(tmpResult,"ST ANTHONY HOSPITAL\n\n");
312
	   #endif
313
	   #ifdef ACH
314
	   	sprintf(tmpResult,"SEATTLE CHILDRENS HOSP\n\n");
315
	   #endif
316
      PrintState = ActiveReportFlag;
317
   }
318
}
319
320
// Print Test State ************************************************************
321
void	PrintReportTest1 (int first)
322
{
323
	int	result;
324
   char 	timestr[16+1];
325
   char  datastr[27];
326
	EventSt EventData;
327
328
   result = 1;
329
330
	if (first)
331
   {
332
   	sprintf(tmpResult, "\n  0.1 PRECISION TESTS\n\n");
333
      ReportCycle = 0;
334
   }
335
   else
336
   {
337
   	if (ReportCycle == 0)
338
      {
339
      	result = SearchEvent(TEST_LOG, OPEN_FILE, &EventData);
340
         ReportCycle++;
341
      }
342
      else
343
	   	result = SearchEvent(TEST_LOG, PREVIOUS_EVENT, &EventData);
344
	   if (result)
345
	   {
346
	      if (ReportCycle == 1)
347
	         sprintf(tmpResult, "None\n\n");
348
         else
349
         	result = 0;
350
	      PrintState = PRINT_TEST2;
351
	   }
352
	   else if (EventData.Code == TEST_PNT1)
353
	   {
354
	   	FormatEvent(&EventData, timestr, datastr);
355
	      sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
356
	      ReportCycle++;
357
         result = 1;
358
	   }
359
   }
360
   if (result)
361
   {
362
   	strcpy(PrintLine,tmpResult);
363
   	ActivePrintFlag = 1;
364
   }
365
}
366
367
// Print Test State ************************************************************
368
void	PrintReportTest2 (int first)
369
{
370
	int	result;
371
   	char 	timestr[16+1];
372
   	char  datastr[27];
373
	EventSt EventData;
374
375
   result = 1;
376
377
	if (first)
378
   {
379
   	sprintf(tmpResult, "\n0.2 PRECISION TESTS\n\n");
380
      ReportCycle = 0;
381
   }
382
   else
383
   {
384
   	if (ReportCycle == 0)
385
      {
386
      	result = SearchEvent(TEST_LOG, OPEN_FILE, &EventData);
387
         ReportCycle++;
388
      }
389
      else
390
	   	result = SearchEvent(TEST_LOG, PREVIOUS_EVENT, &EventData);
391
	   if (result)
392
	   {
393
	      if (ReportCycle == 1)
394
	         sprintf(tmpResult, "None\n\n");
395
         else
396
         	result = 0;
397
	      PrintState = PRINT_TEST3F;
398
	   }
399
	   else if (EventData.Code == TEST_PNT2)
400
	   {
401
	   	FormatEvent(&EventData, timestr, datastr);
402
	      sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
403
	      ReportCycle++;
404
         result = 1;
405
	   }
406
   }
407
   if (result)
408
   {
409
   	strcpy(PrintLine,tmpResult);
410
   	ActivePrintFlag = 1;
411
   }
412
}
413
414
// Print Test State ************************************************************
415
void	PrintReportTest3F (int first)
416
{
417
	int	result;
418
   	char 	timestr[16+1];
419
   	char  datastr[27];
420
	EventSt EventData;
421
422
   	result = 1;
423
424
	if (first)
425
   	{
426
   	sprintf(tmpResult, "\n  3 GPH TEST FAILS \n\n");
427
      ReportCycle = 0;
428
   	}
429
   else
430
   {
431
   	if (ReportCycle == 0)
432
      {
433
      	result = SearchEvent(TEST_LOG, OPEN_FILE, &EventData);
434
         ReportCycle++;
435
      }
436
      else
437
	  {
438
	   	result = SearchEvent(TEST_LOG, PREVIOUS_EVENT, &EventData);
439
	  }
440
	   if (result)
441
	   {
442
	      	if (ReportCycle == 1)
443
		  	{
444
	         	sprintf(tmpResult, "None\n\n");
445
		  	}
446
         	else
447
		 	{
448
         		result = 0;
449
		 	}
450
	    PrintState = PRINT_END;
451
	   }
452
	   else if (EventData.Code == TEST_GPH3 && EventData.Status != PASS)
453
	   {
454
	   		FormatEvent(&EventData, timestr, datastr);
455
	      	sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
456
	      	ReportCycle++;
457
         	result = 1;
458
	   }
459
   }
460
   if (result)
461
   {
462
   		strcpy(PrintLine,tmpResult);
463
   		ActivePrintFlag = 1;
464
   }
465
}
466
467
// Print Test State ************************************************************
468
void	PrintReportTest3P (int first)
469
{
470
	int	result;
471
   	char 	timestr[16+1];
472
   	char  datastr[27];
473
	EventSt EventData;
474
475
   	result = 1;
476
477
	if (first)
478
   	{
479
   		sprintf(tmpResult, "\n 3 GPH TEST PASSES\n\n");
480
      	ReportCycle = 0;
481
   	}
482
   	else
483
   	{
484
   	if (ReportCycle == 0)
485
      {
486
      	result = SearchEvent(TEST_LOG, OPEN_FILE, &EventData);
487
         ReportCycle++;
488
      }
489
      else
490
	   	result = SearchEvent(TEST_LOG, PREVIOUS_EVENT, &EventData);
491
	   if (result)
492
	   {
493
	      if (ReportCycle == 1)
494
	         sprintf(tmpResult, "None\n\n");
495
         else
496
         	result = 0;
497
	      PrintState = PRINT_END;
498
	   }
499
	   else if (EventData.Code == TEST_GPH3 && EventData.Status == PASS)
500
	   {
501
         	FormatEvent(&EventData, timestr, datastr);
502
	      	sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
503
	      	ReportCycle++;
504
         	result = 1;
505
	   }
506
   }
507
   if (result)
508
   {
509
   	strcpy(PrintLine,tmpResult);
510
   	ActivePrintFlag = 1;
511
   }
512
}
513
514
// Print Alarm State ***********************************************************
515
void	PrintReportAlarm (int first)
516
{
517
	int	result;
518
   char 	timestr[16];
519
   char  datastr[27];
520
	EventSt EventData;
521
522
   result = 1;
523
524
	if (first)
525
   {
526
   	sprintf(tmpResult, "\n       ALARM LOG\n\n");
527
      ReportCycle = 0;
528
   }
529
   else
530
   {
531
   	if (ReportCycle == 0)
532
      {
533
      	result = SearchEvent(ALRM_LOG, OPEN_FILE, &EventData);
534
         ReportCycle++;
535
      }
536
      else
537
	   	result = SearchEvent(ALRM_LOG, PREVIOUS_EVENT, &EventData);
538
	   if (result)
539
	   {
540
	      if (ReportCycle == 1)
541
	         sprintf(tmpResult, "None\n\n");
542
	      PrintState = PRINT_END;
543
	   }
544
	   // && EventData.Status == ALM_OPEN
545
	   else if (EventData.Code != NO_ALARM)
546
	   {
547
	   	FormatEvent(&EventData, timestr, datastr);
548
	      sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
549
	      ReportCycle++;
550
         result = 1;
551
	   }
552
   }
553
   if (result)
554
   {
555
   	strcpy(PrintLine,tmpResult);
556
   	ActivePrintFlag = 1;
557
   }
558
}
559
560
// Print System State **********************************************************
561
void	PrintReportSystem (int first)
562
{
563
	int	result;
564
   int 	i;
565
   char 	timestr[16];
566
   char  datastr[27];
567
	EventSt EventData;
568
569
   result = 1;
570
571
	if (first)
572
   {
573
   	sprintf(tmpResult, "\n      SYSTEM LOG\n\n");
574
      ReportCycle = 0;
575
   }
576
   else
577
   {
578
      if (ReportCycle == 0)
579
      {
580
         result = SearchEvent(SYST_LOG, OPEN_FILE, &EventData);
581
         ReportCycle++;
582
      }
583
      else
584
         result = SearchEvent(SYST_LOG, PREVIOUS_EVENT, &EventData);
585
      if (result)
586
      {
587
         if (ReportCycle == 1)
588
            sprintf(tmpResult, "None\n\n");
589
         else
590
            sprintf(tmpResult, " \n\n");
591
         PrintState = PRINT_END;
592
      }
593
      else if (EventData.Code == REBOOT)
594
      {
595
      	FormatEvent(&EventData, timestr, datastr);
596
         sprintf(tmpResult, "%s\n%s\n\n", timestr, datastr);
597
         ReportCycle++;
598
         result = 1;
599
      }
600
   }
601
   if (result)
602
   {
603
   	strcpy(PrintLine,tmpResult);
604
   	ActivePrintFlag = 1;
605
   }
606
}
607
608
// Print Config State **********************************************************
609
void	PrintReportConfig (int first)
610
{
611
	if (first)
612
   {
613
   	sprintf(tmpResult, "\n     CONFIGURATION\n\n");
614
      Prod = 0;
615
      ReportCycle = 0;
616
   }
617
   else
618
   {
619
      if (Prod < Config.N_Products)
620
      {
621
      	if (ReportCycle == 0)
622
         {
623
      		sprintf(tmpResult, "PRODUCT - %d\n", Product[Prod].ProdName);
624
            sprintf(tmpResult, "%sSTATE - %s\n", tmpResult,
625
            			stateName[Channel[Product[Prod].LeadTurbine].State]);
626
         }
627
         else if (ReportCycle == 1)
628
         {
629
         	sprintf(tmpResult, "RESILIENCE - %d\n", Product[Prod].ResilVal);
630
            sprintf(tmpResult, "%sNUM TURBINES - %d\n", tmpResult, Product[Prod].N_Turbines);
631
         }
632
         else if (ReportCycle == 2)
633
         {
634
         	sprintf(tmpResult, "NUM LEAD TURBINES - %d\n", Product[Prod].N_LeadTurbines);
635
            sprintf(tmpResult, "%sNUM RUN TURBINES - %d\n", tmpResult, Product[Prod].N_RunTurbines);
636
         }
637
         else if (ReportCycle == 3)
638
         {
639
         	sprintf(tmpResult, "NUM LDNS - %d\n", Product[Prod].N_PistonSwitches);
640
            sprintf(tmpResult, "%sNUM SUCTION CV - %d\n", tmpResult, Product[Prod].CV.SCV);
641
         }
642
         else if (ReportCycle == 4)
643
         {
644
645
         	sprintf(tmpResult, "NUM PRESSURE CV - %d\n", Product[Prod].CV.PCV);
646
            sprintf(tmpResult, "%sNUM DISPENSER CV - %d\n", tmpResult, Product[Prod].CV.DCV);
647
         }
648
         else if (ReportCycle == 5)
649
         {
650
            if (Product[Prod].RotateFlag)
651
            	sprintf(tmpResult, "AUTO ROTATE - YES\n");
652
         	else
653
            	sprintf(tmpResult, "AUTO ROTATE - NO\n");
654
655
            if (Product[Prod].AutoAuthFlag == AUTH_INPUT)
656
            	sprintf(tmpResult, "%sINPUT BASED STAGING\n", tmpResult);
657
         	else if (Product[Prod].AutoAuthFlag == AUTH_CASCADE)
658
            	sprintf(tmpResult, "%sAUTOMATIC BASED STAGING\n", tmpResult);
659
            else
660
            	sprintf(tmpResult, "%sPRESSURE BASED STAGING\n", tmpResult);
661
         }
662
         else if (ReportCycle == 6)
663
         {
664
665
         	sprintf(tmpResult, "MIN RUN PRESSURE - %2u\n", Product[Prod].RunPressure);
666
            sprintf(tmpResult, "%sTEST HI PRESSURE - %2u\n", tmpResult, Product[Prod].HighPressure);
667
         }
668
         else if (ReportCycle == 7)
669
         {
670
671
         	sprintf(tmpResult, "TEST LO PRESSURE - %2u\n", Product[Prod].LowPressure);
672
         }
673
         else
674
         {
675
      		Prod++;
676
            ReportCycle = -1;
677
            sprintf(tmpResult, "\n");
678
         }
679
         ReportCycle++;
680
      }
681
      else
682
      {
683
      	PrintState = PRINT_END;
684
      }
685
   }
686
   strcpy(PrintLine,tmpResult);
687
   ActivePrintFlag = 1;
688
}
689
690
// Report End ******************************************************************
691
void	PrintReportEnd (int first) {
692
	sprintf(tmpResult, "** END **\n\n\n\n\n\n");
693
   strcpy(PrintLine,tmpResult);
694
   ActivePrintFlag = 1;
695
   PrintState = PRINT_CURRENT;
696
}
697
698
// Print Test Log **************************************************************
699
void	PrintTestLog(void) {
700
	PrintReportInit(PRINT_TEST1);
701
}
702
703
// Print Test Log **************************************************************
704
void	PrintAlarmLog(void) {
705
	PrintReportInit(PRINT_ALARM);
706
}
707
708
// Print Test Log **************************************************************
709
void	PrintSystemLog(void) {
710
	PrintReportInit(PRINT_SYSTEM);
711
}
712
713
// Print Test Log **************************************************************
714
void	PrintConfig(void) {
715
	PrintReportInit(PRINT_CONFIG);
716
}
717
718
// Print Test Log **************************************************************
719
void	PrintTest3P(void) {
720
	PrintReportInit(PRINT_TEST3P);
721
}
722
723
/*** BeginHeader */
724
725
726
#endif
727
728
/*** EndHeader */