← Back to dashboard

File view

PLC_MAIN_STATE.lib

1
//$Id: tcn_main_state.lib,v 1.00 2009-04-28 13:45:06 barrett Exp $
2
3
/*
4
  $Log: tcn_main_state.lib,v $
5
*/
6
7
/*** BeginHeader */
8
9
#ifndef	__PLC_MAIN_STATE_
10
#define	__PLC_MAIN_STATE_
11
12
/*** EndHeader */
13
14
/*** BeginHeader
15
16
MainStateHandler,
17
DisplayState,
18
ResetLDN,
19
FormatTestResault,
20
FormatAlarm
21
22
*/
23
24
// Defines **********************************************************************
25
26
27
28
29
// Global function prototypes ***************************************************
30
31
void	MainStateHandler  (chanStPtr channel);			// Call next state
32
void  DisplayState		(void);					    	// Display Update
33
void  ResetLDN				(int chn, int res);
34
void  FormatTestResault (char *TopLine, char *BotLine, EventSt *EventSet);
35
void  FormatAlarm			(char *TopLine, char *BotLine, EventSt *EventSet);
36
37
// Display strings *******************************************************************
38
39
const char stateName[][] = {
40
   "WAIT            ",
41
   "STANDBY         ",
42
   "MONITOR         ",
43
#if SCH2
44
	"FILLING INT TANK",
45
#else
46
   "DISPENSE        ",
47
#endif
48
	"REPRESSURE      ",
49
   "VALVE           ",
50
   "ALARM           ",
51
   "3 GPH TEST      ",
52
   "PRECISION TEST  ",
53
   "SENSOR OUT      ",
54
   "UST FILTER      ",
55
   "OVER 95%: RETURN"
56
};
57
58
const char GPH3TestName[][] = {
59
	"REPRESSURE 3 GPH",
60
	"DROP PRES  3 GPH",
61
	"MONITOR    3 GPH"
62
};
63
64
const char PTestName[][] = {
65
	"REPRESSURE 0.%d %d",
66
	"DROP PRES  0.%d %d",
67
	"MONITOR    0.%d %d",
68
   "EXPANSION  0.%d %d",
69
   "CONTRACT   0.%d %d",
70
   "STEADY     0.%d %d"
71
};
72
73
const char pressureName[][] = {
74
   "LOW ",
75
   "MID ",
76
   "HIGH"
77
};
78
79
const char resultName[][] = {
80
   "FAIL",
81
   "PASS",
82
   "N/A "
83
};
84
85
/*** EndHeader */
86
87
//Local function prototypes ****************************************************
88
89
void	Wait 					(uint8_t first);		//general standby mode
90
void	Standby 				(uint8_t first);		//delay foe turbine start
91
void	Monitor 				(uint8_t first);		//monitor for dispensing status
92
void	Dispense 			(uint8_t first);		//dispense fuel
93
void	Repressure 			(uint8_t first);		//repressurize line
94
void	Valve 				(uint8_t first);		//control shunt valve
95
void	Alarm 				(uint8_t first);		//set alarms
96
void	GPH3Test 			(uint8_t first);		// GPH3 Leak test sequence
97
void  PrecisionTest 		(uint8_t first);		// Precision Test sequence
98
void  SensorOut 			(uint8_t first);		//wire disconnect with LDN
99
void  Filter 				(uint8_t first);		//Filter State
100
void  FuelReturn 			(uint8_t first);		//Fuel Return State
101
102
//Local declorations ***********************************************************
103
104
chanStPtr PLC;
105
106
//PLC->State index list *************************************************************
107
108
enum {
109
   WAIT     = 0,
110
   STANDBY  = 1,
111
   MONITOR,
112
   DISPENSE,
113
   REPRESSURE,
114
   VALVE,
115
   ALARM,
116
	TESTGPH3,
117
   TESTPREC,
118
   SENSOROUT,
119
   FILTER,
120
   FUELRETURN,
121
   NOSTATE
122
};
123
124
125
/******************************************************************
126
 * 			Function Name:
127
 * 
128
 * 
129
 * 		Args / Parameters:
130
 * 
131
 * 
132
 * 		Description:
133
 * 
134
 * 
135
 * 
136
 * 		Returns:
137
 * 
138
 */
139
void (* const MainStateTable[]) () = {
140
					Wait,
141
					Standby,
142
					Monitor,
143
					Dispense,
144
					Repressure,
145
					Valve,
146
					Alarm,
147
					GPH3Test,
148
					PrecisionTest,
149
					SensorOut,
150
					Filter,
151
					FuelReturn
152
		};
153
154
155
/******************************************************************
156
 * 			Function Name:
157
 * 
158
 * 
159
 * 		Args / Parameters:
160
 * 
161
 * 
162
 * 		Description:
163
 * 
164
 * 
165
 * 
166
 * 		Returns:
167
 * 
168
 */
169
void MainStateHandler (chanStPtr channel)    //direct program to next state
170
{	
171
	uint8_t first;
172
	int tmpPrevious;
173
174
   PLC = channel;
175
176
	if (PLC->PreviousState != PLC->State) 		
177
   {
178
      first = 1;
179
   }
180
	else	
181
   {
182
      first = 0;
183
   }
184
185
	tmpPrevious = PLC->State;					      //update previous state reg
186
	MainStateTable[PLC->State] (first);				//call next state
187
	PLC->PreviousState = tmpPrevious;
188
}
189
190
191
/******************************************************************
192
 * 			Function Name:
193
 * 
194
 * 
195
 * 		Args / Parameters:
196
 * 
197
 * 
198
 * 		Description:
199
 * 
200
 * 
201
 * 
202
 * 		Returns:
203
 * 
204
 */
205
void Wait (uint8_t first) 
206
{
207
   if (first) 
208
   {
209
   	PLC->Turbine 			= OFF;
210
      PLC->RdyFlag 			= OFF;
211
      PLC->ShuntValve 		= OFF;
212
      PLC->StartTime 		= SEC_TIMER;
213
      PLC->AuthOff 			= AUTH_TIME_ON;
214
      PLC->DurationTime 	= Config.PresCheckDelay;
215
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
216
217
      if (PLC->LeadFlag) 
218
      {
219
      	ResetLDN				(PLC->Idx, PLC->ResilVal);
220
      #if MODBUS_S_ON
221
         SetStatusReg		(CURRENT_TESTS, PLC->Prod->Idx, PLC->Idx, 0);
222
         SetStatusReg		(SHUNT_VALVE,   PLC->Prod->Idx, PLC->Idx, 0);
223
      #endif
224
      #if SCH2
225
      	 PLC->Prod->CheckPres = OFF;
226
      #endif
227
      }
228
   }
229
   else if(PLC->SensorOutFlag) 
230
   {
231
   	PLC->State 				= SENSOROUT;
232
   }
233
   else if (PLC->ResetPbFlag && PLC->LeadFlag) 
234
   {
235
   	PLC->ResetPbFlag 		= 0;
236
      PLC->State 				= REPRESSURE;
237
   }
238
   else if (PLC->Prod->ReturnFuel && PLC->LeadFlag) 
239
   {
240
   	PLC->State 				= FUELRETURN;
241
   }
242
   else if (PLC->Authorize) 
243
   {
244
      PLC->State 				= STANDBY;
245
   }
246
   else if (PLC->PresFlag == 2 && PLC->LeadFlag) 
247
   {
248
      PLC->State 				= VALVE;
249
	}
250
   else if ((SEC_TIMER - PLC->StartTime > PLC->DurationTime) &&
251
				 PLC->PresFlag == 0 &&  PLC->LeadFlag) 
252
   {
253
      PLC->State 				= TESTGPH3;
254
   }
255
   else if (SEC_TIMER - PLC->StartTime > PLC->DurationTime) 
256
   {
257
      PLC->StartTime 		= SEC_TIMER;
258
      PLC->DurationTime 	= Config.PresCheckDelay;
259
      #if SCH2
260
         PLC->Prod->CheckPres = ON;
261
         PLC->Prod->CheckTime = MS_TIMER;
262
      #endif
263
	}
264
   else if (PLC->PrecTest.Status == PT_PENDING && PLC->PresFlag == 1 && PLC->LeadFlag) 
265
   {
266
    	PLC->State 				= TESTPREC;
267
   }
268
   #if SCH2
269
   else if (PLC->Prod->CheckTime + P_CHECK_TIME < MS_TIMER && PLC->LeadFlag) 
270
   {
271
      PLC->Prod->CheckPres = OFF;
272
   }
273
   #endif
274
}
275
276
277
/******************************************************************
278
 * 			Function Name:
279
 * 
280
 * 
281
 * 		Args / Parameters:
282
 * 
283
 * 
284
 * 		Description:
285
 * 
286
 * 
287
 * 
288
 * 		Returns:
289
 * 
290
 */
291
void Standby (uint8_t first)//burn 5 sec for turbine start 
292
{   						
293
   if (first) 
294
   {
295
   	PLC->StartTime 		= SEC_TIMER;
296
      PLC->ShuntValve 		= OFF;
297
     	PLC->Turbine 			= OFF;
298
      PLC->DurationTime 	= STANDBYDLY;
299
300
     	if (PLC->LeadFlag)
301
      {
302
     		ResetLDN				(PLC->Idx, PLC->ResilVal);
303
      }
304
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
305
      #if SCH2
306
      	PLC->Prod->CheckPres = ON;
307
      #endif
308
   }
309
   else if (PLC->Prod->ReturnFuel && PLC->LeadFlag)
310
   {
311
   	PLC->State 				= WAIT;
312
   }
313
   else if (PLC->AuthOff == AUTH_TIME_ON)
314
   {
315
	   if (PLC->OnDly + PLC->StartTime <= SEC_TIMER)
316
	   {
317
         PLC->AuthOff 		= AUTH_RUN;
318
         PLC->Turbine 		= ON;						//turn on turbine
319
	   }
320
   }
321
   else if (PLC->Authorize && SEC_TIMER - PLC->StartTime > PLC->DurationTime)
322
   {
323
      PLC->State 				= MONITOR;
324
   }
325
   else if (!PLC->Authorize)
326
   {
327
      PLC->State 				= WAIT;
328
   }
329
   else if (PLC->ResetPbFlag && PLC->LeadFlag)
330
   {
331
   	PLC->ResetPbFlag 		= 0;
332
   }
333
}
334
335
336
/******************************************************************
337
 * 			Function Name:
338
 * 
339
 * 
340
 * 		Args / Parameters:
341
 * 
342
 * 
343
 * 		Description:
344
 * 
345
 * 
346
 * 
347
 * 		Returns:
348
 * 
349
 */
350
void Monitor (uint8_t first)
351
{
352
353
   if (first)
354
   {
355
   	PLC->Turbine 			= ON;
356
    	PLC->StartTime 		= SEC_TIMER;
357
      PLC->DurationTime 	= PRESSUREDLY;
358
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
359
   }
360
   else if (!PLC->Authorize)
361
   {
362
      PLC->State 				= WAIT;
363
   }
364
   else if (PLC->ResetPbFlag && PLC->LeadFlag)
365
   {
366
   	PLC->ResetPbFlag 		= 0;
367
   }
368
   #if MODBUS_M_ON
369
   	else if (PLC->LDN->Pressure >= PLC->RunPressure || !PLC->LeadFlag)
370
   #else
371
   	else if (PLC->PresFlag == 2 || !PLC->LeadFlag)
372
   #endif
373
   {
374
   	if (PLC->Prod->FilterFlag)
375
      {
376
      	PLC->State 			= FILTER;
377
      }
378
      else
379
      {
380
      	PLC->State 			= DISPENSE;
381
      }
382
      PLC->Prod->RePresCount = 0;
383
   }
384
#if MODBUS_M_ON
385
   else if (PLC->LDN->Pressure < PLC->RunPressure &&
386
           (SEC_TIMER - PLC->StartTime > PLC->DurationTime))
387
#else
388
   else if (PLC->PresFlag < 2 && (SEC_TIMER - PLC->StartTime > PLC->DurationTime))
389
#endif
390
   {
391
      if (Config.ShutDownMode == SD_ALARM_ONLY || Config.ShutDownMode == SD_NO_DISPENSE)
392
      {
393
      	PLC->State 			= DISPENSE;
394
      	PLC->WarnFlag		= NO_PRES_WARN;
395
         #if ALM_OUT_WARN
396
         	PLC->AlarmFlag = NO_PRES_WARN;
397
         #endif
398
         // Log
399
      }
400
      else
401
      {
402
      	if (Config.ShutDownMode == SD_PER_CHANNEL)
403
         {
404
      		ReAuth(PLC->Prod->Idx);
405
         }
406
      	PLC->AlarmFlag 			= NO_PRES_ALARM;
407
         PLC->Prod->RePresCount  = 0;
408
         PLC->State 					= ALARM;
409
      }
410
   }
411
}
412
413
414
/******************************************************************
415
 * 			Function Name:
416
 * 
417
 * 
418
 * 		Args / Parameters:
419
 * 
420
 * 
421
 * 		Description:
422
 * 
423
 * 
424
 * 
425
 * 		Returns:
426
 * 
427
 */
428
void Dispense (uint8_t first)
429
{
430
	int i;
431
   int result;
432
433
   result = 0;
434
435
   if (first)
436
   {
437
   	//FlowCV(ON);
438
      PLC->FlowTime = SEC_TIMER;
439
      PLC->StartTime = SEC_TIMER;
440
      PLC->DurationTime = PLC->ResilVal / 10;
441
442
      if (PLC->DurationTime < 5) 
443
      {
444
         PLC->DurationTime = 5;
445
      }
446
      if (PLC->DurationTime > 60) 
447
      {
448
         PLC->DurationTime = 60;
449
      }
450
      if (PLC->LeadFlag || PLC->Prod->AutoAuthFlag != AUTH_DEMAND)
451
      {
452
   		PLC->RdyFlag = ON;
453
      }
454
   	printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
455
   }
456
   else if (PLC->ResetPbFlag && PLC->LeadFlag)
457
   {
458
   	PLC->ResetPbFlag = 0;
459
   }
460
   else if (!PLC->Authorize)						//test for no authorization request
461
	{
462
   	if (PLC->AuthOff != AUTH_TIME_OFF)
463
      {
464
      	PLC->StartTime = SEC_TIMER;
465
         PLC->AuthOff = AUTH_TIME_OFF;
466
         PLC->RdyFlag = OFF;
467
      }
468
      else if (PLC->OffDly + PLC->StartTime <= SEC_TIMER)
469
      {
470
	      if (PLC->LeadFlag)
471
         {
472
	         PLC->State =  TESTGPH3;
473
         }
474
	      else
475
         {
476
	         PLC->State = WAIT;
477
         }
478
         #if ALM_OUT_WARN
479
         	PLC->AlarmFlag = NO_ALARM;
480
         #endif
481
      }
482
   }
483
   else if (PLC->Prod->ReturnFuel)
484
   {
485
   	PLC->State = FUELRETURN;
486
      PLC->AuthOff = AUTH_TIME_ON;
487
   }
488
   #if FLOWSWITCH
489
	   if (PLC->FlowFlag == 0 && SEC_TIMER - PLC->FlowTime > Config.FlowDelay)
490
	   {
491
      	ReAuth(PLC->Prod->Idx);
492
         PLC->AlarmFlag = NO_FLOW;
493
         PLC->Prod->RePresCount = 0;
494
      	PLC->State = ALARM;
495
	   }
496
   #endif
497
   else if (PLC->RdyFlag == 2)
498
   {
499
   	PLC->Prod->Authorize++;
500
   }
501
   else if (SEC_TIMER - PLC->StartTime > PLC->DurationTime)
502
   {
503
   	#if MODBUS_M_ON
504
         if (PLC->LDN->Pressure < PLC->RunPressure
505
         		&& PLC->Prod->AutoAuthFlag == AUTH_DEMAND)
506
      #else
507
      	if (PLC->PresFlag < PRES_HIGH && PLC->Prod->AutoAuthFlag == AUTH_DEMAND)
508
      #endif
509
      {
510
      	PLC->Prod->Authorize++;
511
   		PLC->RdyFlag = 2;
512
      }
513
      PLC->StartTime = SEC_TIMER;
514
   }
515
}
516
517
518
/******************************************************************
519
 * 			Function Name:
520
 * 
521
 * 
522
 * 		Args / Parameters:
523
 * 
524
 * 
525
 * 		Description:
526
 * 
527
 * 
528
 * 
529
 * 		Returns:
530
 * 
531
 */
532
void Repressure (uint8_t first)
533
{
534
   if (first)
535
   {
536
		PLC->Turbine 			= ON;
537
	   PLC->ShuntValve 		= OFF;
538
      PLC->RdyFlag 			= OFF;
539
      PLC->StartTime 		= SEC_TIMER;
540
      PLC->DurationTime 	= PRESSUREDLY;
541
   	if (PLC->LeadFlag)
542
      {
543
      	ResetLDN				(PLC->Idx, PLC->ResilVal);
544
      }
545
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
546
      #if SCH2
547
      	PLC->Prod->CheckPres = ON;
548
      #endif
549
   }
550
   else if(PLC->SensorOutFlag)
551
	{
552
   	PLC->State 				= SENSOROUT;
553
   }
554
   else if (PLC->Prod->ReturnFuel && PLC->LeadFlag)
555
   {
556
   	PLC->State 				= WAIT;
557
      #if ALM_OUT_WARN
558
         PLC->AlarmFlag 	= NO_ALARM;
559
      #endif
560
   }
561
   else if (PLC->Authorize) 						//test for authorization request
562
   {
563
      PLC->State 				= WAIT;
564
      #if ALM_OUT_WARN
565
         PLC->AlarmFlag 	= NO_ALARM;
566
      #endif
567
   }
568
   else if (PLC->ResetPbFlag || !PLC->LeadFlag)
569
   {
570
   	PLC->ResetPbFlag 		= 0;
571
      PLC->State 				= WAIT;
572
      #if ALM_OUT_WARN
573
         PLC->AlarmFlag 	= NO_ALARM;
574
      #endif
575
   }
576
   else if ((SEC_TIMER - PLC->StartTime > STABLE_TIME) && PLC->PresFlag==2)				//test for pressure > HiSwitch
577
   {
578
   	PLC->State 				= VALVE;
579
   }
580
   else if (PLC->PresFlag < 2 && (SEC_TIMER - PLC->StartTime > PLC->DurationTime))   //test pres < LoSwitch and timer expired
581
   {
582
      PLC->AlarmFlag 			= NO_PRES_ALARM;
583
      PLC->Prod->RePresCount  = 0;
584
      PLC->State 					= ALARM;
585
   }
586
}
587
588
589
/******************************************************************
590
 * 			Function Name:
591
 * 
592
 * 
593
 * 		Args / Parameters:
594
 * 
595
 * 
596
 * 		Description:
597
 * 
598
 * 
599
 * 
600
 * 		Returns:
601
 * 
602
 */
603
void Valve (uint8_t first) 
604
{
605
   if (first) 
606
   {
607
      PLC->Turbine 				= OFF;
608
      PLC->ShuntValve 			= ON;
609
      PLC->StartTime 			= SEC_TIMER;
610
   	PLC->Prod->RePresCount 	= 0;
611
   	SetLDNReg					(PLC->Idx, MONITOR_PRES, 	OFF);
612
      SetLDNReg					(PLC->Idx, SET_PRES, PLC->HighPressure);
613
      SetLDNReg					(PLC->Idx, SHUNT_PRES, ON);
614
      #if SCH2
615
      	PLC->Prod->CheckPres = ON;
616
      #endif
617
      #if MODBUS_S_ON
618
         SetStatusReg			(SHUNT_VALVE, PLC->Prod->Idx, PLC->Idx, 1);
619
      #endif
620
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
621
   }
622
   else if(PLC->SensorOutFlag) 
623
   {
624
   	PLC->State 					= SENSOROUT;
625
   }
626
   else if (PLC->Prod->ReturnFuel && PLC->LeadFlag) 
627
   {
628
      PLC->State 					= WAIT;
629
   }
630
   else if (PLC->ResetPbFlag || !PLC->LeadFlag) 
631
   {
632
    	PLC->ResetPbFlag 			= OFF;
633
      PLC->State 					= WAIT;
634
   }
635
   else if ((GetLDNReg(PLC->Idx, SHUNT_COMPLETE) &&  PLC->LDN->DataReady) || PLC->Authorize) 
636
   {
637
      PLC->ShuntValve 			= OFF;
638
      PLC->State 					= WAIT;
639
      #if MODBUS_S_ON
640
         SetStatusReg(SHUNT_VALVE, PLC->Prod->Idx, PLC->Idx, 0);
641
      #endif
642
   }
643
   else if (GetLDNReg(PLC->Idx, LDN_STATE) != LDN_SHUNT &&  PLC->LDN->DataReady) 
644
   {
645
      PLC->State 					= WAIT;
646
   }
647
   else if (SEC_TIMER - PLC->StartTime > MAXSHUNTTIME) 
648
   {
649
      PLC->ShuntValve 			= OFF;
650
      PLC->AlarmFlag 			= NO_PRES_DROP;
651
      PLC->State 					= ALARM;
652
   }
653
}
654
655
656
/******************************************************************
657
 * 			Function Name:
658
 * 
659
 * 
660
 * 		Args / Parameters:
661
 * 
662
 * 
663
 * 		Description:
664
 * 
665
 * 
666
 * 
667
 * 		Returns:
668
 * 
669
 */
670
void Alarm (uint8_t first) 
671
{
672
	int ModbusReset;
673
674
   ModbusReset = 0;
675
676
	if (first) 
677
   {
678
   	PLC->RdyFlag 			= OFF;
679
      PLC->Turbine 			= OFF;
680
      PLC->ShuntValve 		= OFF;
681
      PLC->Retries 			= 0;
682
      PLC->Prod->RePresCount = 0;
683
684
   	if (PLC->LeadFlag)
685
      {
686
      	ResetLDN				(PLC->Idx, PLC->ResilVal);
687
      }
688
      if (PLC->AlarmFlag != FAIL_3GPH)
689
      {
690
      	 PLC->AlarmFlag += DISP_ALARM;
691
      }
692
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
693
      #if MODBUS_S_ON
694
      	if (PLC->AlarmFlag == NO_PRES_ALARM)
695
      		SetAlarmReg(PRES_ALARMS, PLC->Prod->Idx, PLC->Idx, 1);
696
         else if (PLC->AlarmFlag == NO_FLOW)
697
         	SetAlarmReg(NO_FLOW_AL, PLC->Prod->Idx, PLC->Idx, 1);
698
         else if (PLC->AlarmFlag == FAIL_3GPH)
699
         {
700
         	SetAlarmReg(GPH3FAILURES, PLC->Prod->Idx, PLC->Idx, 1);
701
            SetAlarmReg(GPH3FAILURES_WARNING, PLC->Prod->Idx, PLC->Idx, 0);
702
         }
703
         printf("MB PRES_ALM: %d", GetAlarmReg(PRES_ALARMS, PLC->Prod->Idx));
704
      #endif
705
      #if SCH2
706
      	PLC->Prod->CheckPres = OFF;
707
      #endif
708
      #if LOGGING_ON
709
	      PLC->EventAl.LogType = ALRM_LOG;
710
	      PLC->EventAl.Product = PLC->Prod->Idx;
711
	      PLC->EventAl.Channel = PLC->Idx;
712
	      PLC->EventAl.Code    = PLC->AlarmFlag;
713
	      PLC->EventAl.Status  = ALM_OPEN;
714
	      PLC->EventAl.Notes   = 0;
715
	      PLC->EventAl.Rate    = 0.0;
716
	      PLC->EventAl.Time    = SEC_TIMER;
717
      	AddLogEvent(&PLC->EventAl);
718
      #endif
719
   }
720
   else if (PLC->Prod->ReturnFuel && PLC->LeadFlag)
721
   {
722
   	PLC->State = WAIT;
723
   }
724
   else if (Config.ShutDownMode == SD_ALARM_ONLY && PLC->Authorize)                   //test authorization requests
725
   {
726
   	ModbusReset = PLC->AlarmFlag;
727
      PLC->AlarmFlag = NO_ALARM;
728
      PLC->ResetPbFlag = 0;
729
      PLC->Retries = 0;
730
      PLC->State = WAIT;
731
      #if LOGGING_ON
732
      	PLC->EventAl.Status  = ALM_CLOSED;
733
         AddLogEvent(&PLC->EventAl);
734
      #endif
735
   }
736
   else if (PLC->ResetPbFlag)
737
   {
738
   	ModbusReset = PLC->AlarmFlag;
739
   	if (PLC->LeadFlag)
740
      	PLC->State = REPRESSURE;
741
      else
742
      	PLC->State = WAIT;
743
      PLC->AlarmFlag = NO_ALARM;
744
      PLC->ResetPbFlag = 0;
745
      PLC->Retries = 0;
746
      #if LOGGING_ON
747
      	PLC->EventAl.Status  = ALM_CLOSED;
748
         AddLogEvent(&PLC->EventAl);
749
      #endif
750
   }
751
   #if MODBUS_S_ON
752
     else if (ModbusReset)
753
      {
754
      	if (ModbusReset == NO_PRES_ALARM)
755
      		SetAlarmReg(PRES_ALARMS,  PLC->Prod->Idx, PLC->Idx, 0);
756
         else if (ModbusReset == NO_FLOW)
757
         	SetAlarmReg(NO_FLOW_AL,   PLC->Prod->Idx, PLC->Idx, 0);
758
         else if (ModbusReset == FAIL_GPH3)
759
         	SetAlarmReg(GPH3FAILURES, PLC->Prod->Idx, PLC->Idx, 0);
760
      }
761
   #endif
762
}
763
764
// 3 GPH Test - GPH3 Leak test sequence ***********************************
765
/******************************************************************
766
 * 			Function Name:
767
 * 
768
 * 
769
 * 		Args / Parameters:
770
 * 
771
 * 
772
 * 		Description:
773
 * 
774
 * 
775
 * 
776
 * 		Returns:
777
 * 
778
 */
779
void	GPH3Test (uint8_t first) 
780
{
781
	if (first) 
782
   {
783
		TestReset (&PLC->GPH3Test);
784
	   TestConfig(&PLC->GPH3Test, TEST_GPH3, (uint16_t)PLC->ResilVal, (uint8_t)PLC->Idx,
785
	   												  (uint8_t)PLC->HighPressure, (uint8_t)PLC->LowPressure);
786
		PLC->GPH3Test.PresFlag = PLC->PresFlag;
787
		TestStart (&PLC->GPH3Test);
788
		printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
789
790
		#if MODBUS_S_ON
791
         SetStatusReg(CURRENT_TESTS, PLC->Prod->Idx, PLC->Idx, TEST_GPH3);
792
      #endif
793
      #if SCH2
794
      	PLC->Prod->CheckPres = ON;
795
      #endif
796
	}
797
	else if (PLC->Prod->ReturnFuel && PLC->LeadFlag) 
798
   {
799
   	TestStop				(&PLC->GPH3Test);
800
   	PLC->AlarmFlag 	= NO_ALARM;
801
   	PLC->State 			= WAIT;
802
   }
803
   else if (PLC->Authorize || PLC->ResetPbFlag || !PLC->LeadFlag) 
804
   {
805
   	TestStop(&PLC->GPH3Test);
806
   	PLC->ResetPbFlag 	= 0;
807
   	PLC->AlarmFlag 	= NO_ALARM;
808
      PLC->State 			= WAIT;
809
   }
810
   else if (PLC->GPH3Test.Status >= PT_COMPLETE) 
811
   {
812
		if (PLC->GPH3Test.Result == PASS) 
813
      {
814
			PLC->AlarmFlag = NO_ALARM;
815
			PLC->State 		= WAIT;
816
			#if MODBUS_S_ON
817
	         SetStatusReg(GPH3_PASSED,PLC->Prod->Idx, PLC->Idx, 1);
818
	         SetAlarmReg(GPH3FAILURES_WARNING, PLC->Prod->Idx, PLC->Idx, 0);
819
	      #endif
820
		}
821
		else if (PLC->GPH3Test.Status == PT_NO_PRESSURE) 
822
      {
823
         PLC->AlarmFlag = NO_PRES_ALARM;
824
         PLC->State     = ALARM;
825
	   }
826
	   else if (PLC->GPH3Test.Note == NO_PRES_DROP)
827
	   {
828
	      // No pressure drop detected during 3GPH drop phase – mirror VALVE behavior
829
	      TestStop(&PLC->GPH3Test); // ensure test is not displayed as a GPH3 result
830
	      PLC->AlarmFlag = NO_PRES_DROP;
831
	      PLC->State     = ALARM;
832
	   }
833
	   else 
834
      {
835
         printf("Failed in 3GPH test block line 696. Alarm Flag: %d", PLC->AlarmFlag);
836
	    	PLC->AlarmFlag = FAIL_3GPH;
837
	   	PLC->State 		= ALARM;
838
	   }
839
      // Only log test results when it's an actual 3GPH test completion
840
      if (PLC->GPH3Test.Note != NO_PRES_DROP)
841
      {
842
		  PLC->Event.LogType = TEST_LOG;
843
		  PLC->Event.Product = PLC->Prod->Idx;
844
		  PLC->Event.Channel = PLC->Idx;
845
		  PLC->Event.Code	 = PLC->GPH3Test.Type;
846
		  PLC->Event.Status	 = PLC->GPH3Test.Result;
847
		  PLC->Event.Notes	 = PLC->GPH3Test.Note;
848
		  PLC->Event.Rate 	 = 0.0;
849
		  PLC->Event.Time	 = SEC_TIMER;
850
		  AddLogEvent(&PLC->Event);
851
      }
852
   }
853
   else if (PLC->GPH3Test.Status == PT_ACTIVE) 
854
   {
855
   	if (PLC->LDN->DataReady) 
856
      {
857
	      PLC->GPH3Test.PresFlag = PLC->PresFlag;
858
	      TestingStateHandler(&PLC->GPH3Test);
859
	      PLC->Turbine      = PLC->GPH3Test.Turbine;
860
	      PLC->ShuntValve   = PLC->GPH3Test.ShuntValve;
861
	      PLC->RdyFlag      = PLC->GPH3Test.RdyFlag;
862
	   }
863
   }
864
   else 
865
   {
866
   	TestStop(&PLC->GPH3Test);
867
      PLC->State 			= WAIT;
868
   }
869
}
870
871
// Precision Test - Precision Test sequence *************************************
872
/******************************************************************
873
 * 			Function Name:
874
 * 
875
 * 
876
 * 		Args / Parameters:
877
 * 
878
 * 
879
 * 		Description:
880
 * 
881
 * 
882
 * 
883
 * 		Returns:
884
 * 
885
 */
886
void  PrecisionTest (uint8_t first) 
887
{
888
		uint8_t tempType;
889
890
	if (first) 
891
   {
892
		tempType = PLC->PrecTest.Type;
893
		TestReset (&PLC->PrecTest);
894
	   TestConfig(&PLC->PrecTest, tempType, (uint16_t)PLC->ResilVal, (uint8_t)PLC->Idx,
895
	   												 (uint8_t)PLC->HighPressure, (uint8_t)PLC->LowPressure);
896
		TestStart (&PLC->PrecTest);
897
		printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
898
899
		#if MODBUS_S_ON
900
         SetStatusReg(CURRENT_TESTS, PLC->Prod->Idx, PLC->Idx, PLC->PrecTest.Type);
901
      #endif
902
903
      #if SCH2
904
      	PLC->Prod->CheckPres = ON;
905
      #endif
906
	}
907
	else if (PLC->Prod->ReturnFuel && PLC->LeadFlag) 
908
   {
909
   	TestHold				(&PLC->PrecTest);
910
   	PLC->AlarmFlag 	= NO_ALARM;
911
   	PLC->State 			= WAIT;
912
   }
913
	else if (PLC->Authorize) 
914
   {
915
   	TestHold				(&PLC->PrecTest);
916
   	PLC->AlarmFlag 	= NO_ALARM;
917
   	PLC->State 			= WAIT;
918
   }
919
   else if (PLC->ResetPbFlag || !PLC->LeadFlag) 
920
   {
921
   	TestStop				(&PLC->PrecTest);
922
   	PLC->ResetPbFlag 	= 0;
923
   	PLC->AlarmFlag 	= NO_ALARM;
924
      PLC->State 			= WAIT;
925
   }
926
   else if (PLC->PrecTest.Status >= PT_COMPLETE) 
927
   {
928
     	printf("CH: %d - 0.%d: %s\n", PLC->Idx, PLC->PrecTest.Type, resultName[PLC->PrecTest.Result]);
929
930
		if (PLC->PrecTest.Status == PT_NO_PRESSURE) 
931
      {
932
         PLC->AlarmFlag 	= NO_PRES_ALARM;
933
         PLC->State     	= ALARM;
934
	   }
935
	   else 
936
      {
937
			PLC->AlarmFlag 	= NO_ALARM;
938
			PLC->State 			= WAIT;
939
	   }
940
	   PLC->Event.LogType = TEST_LOG;
941
		PLC->Event.Product = PLC->Prod->Idx;
942
		PLC->Event.Channel = PLC->Idx;
943
	   PLC->Event.Code	 = PLC->PrecTest.Type;
944
		PLC->Event.Status	 = PLC->PrecTest.Result;
945
		PLC->Event.Notes	 = PLC->PrecTest.Note;
946
		PLC->Event.Rate 	 = PLC->PrecTest.Rate[0];
947
		PLC->Event.Time	 = SEC_TIMER;
948
		AddLogEvent(&PLC->Event);
949
   }
950
   else if (PLC->PrecTest.Status == PT_ACTIVE) 
951
   {
952
		if (PLC->LDN->DataReady) 
953
      {
954
	      PLC->PrecTest.PresFlag = PLC->PresFlag;
955
	      TestingStateHandler(&PLC->PrecTest);
956
	      PLC->Turbine      = PLC->PrecTest.Turbine;
957
	      PLC->ShuntValve   = PLC->PrecTest.ShuntValve;
958
	      PLC->RdyFlag      = PLC->PrecTest.RdyFlag;
959
		}
960
   }
961
   else 
962
   {
963
   	TestStop(&PLC->PrecTest);
964
      PLC->State 			= WAIT;
965
   }
966
}
967
968
969
/******************************************************************
970
 * 			Function Name:
971
 * 
972
 * 
973
 * 		Args / Parameters:
974
 * 
975
 * 
976
 * 		Description:
977
 * 
978
 * 
979
 * 
980
 * 		Returns:
981
 * 
982
 */
983
void SensorOut (uint8_t first)
984
{
985
   if (first)
986
   {
987
      PLC->RdyFlag = OFF;
988
   	PLC->Turbine = OFF;
989
   	PLC->AuthOff = AUTH_TIME_ON;
990
   	printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
991
      #if SCH2
992
      	PLC->Prod->CheckPres = OFF;
993
      #endif
994
   }
995
   else if (PLC->SensorOutFlag == 0)
996
	{
997
   	PLC->State = WAIT;
998
   }
999
}
1000
1001
1002
/******************************************************************
1003
 * 			Function Name:
1004
 * 
1005
 * 
1006
 * 		Args / Parameters:
1007
 * 
1008
 * 
1009
 * 		Description:
1010
 * 
1011
 * 
1012
 * 
1013
 * 		Returns:
1014
 * 
1015
 */
1016
void Filter (uint8_t first) 
1017
{
1018
   if (first) 
1019
   {
1020
   	#if MODBUS_S_ON
1021
			SetStatusReg(FILTER_ACTIVE, PLC->Prod->Idx, 0, PLC->Prod->FilterFlag);
1022
      #endif
1023
      #if SCH2
1024
      	PLC->Prod->CheckPres = ON;
1025
      #endif
1026
      printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
1027
   }
1028
   else if (!PLC->Prod->FilterFlag) 
1029
   {						
1030
      //test for no authorization request
1031
   	#if MODBUS_S_ON
1032
   		SetStatusReg(FILTER_ACTIVE, PLC->Prod->Idx, 0, PLC->Prod->FilterFlag);
1033
      #endif
1034
      if (PLC->LeadFlag)
1035
      {
1036
			PLC->State = TESTGPH3;
1037
      }
1038
      else
1039
      {
1040
      	PLC->State = WAIT;
1041
      }
1042
   }
1043
}
1044
1045
1046
/******************************************************************
1047
 * 			Function Name:
1048
 * 
1049
 * 
1050
 * 		Args / Parameters:
1051
 * 
1052
 * 
1053
 * 		Description:
1054
 * 
1055
 * 
1056
 * 
1057
 * 		Returns:
1058
 * 
1059
 */
1060
void FuelReturn(uint8_t first) 
1061
{
1062
   if (first)
1063
   {
1064
		printf("CH: %d | State: %s \n", PLC->Idx, stateName[PLC->State]);
1065
   }
1066
   else if (!PLC->Prod->ReturnFuel)						//test for no authorization request
1067
   {
1068
   	PLC->State = WAIT;
1069
   }
1070
}
1071
1072
1073
/******************************************************************
1074
 * 			Function Name:
1075
 * 
1076
 * 
1077
 * 		Args / Parameters:
1078
 * 
1079
 * 
1080
 * 		Description:
1081
 * 
1082
 * 
1083
 * 
1084
 * 		Returns:
1085
 * 
1086
 */
1087
void DisplayState (void) 
1088
{
1089
	char 	TopLine  [DISPLAY_LENGTH + 1];
1090
	char 	BotLine  [DISPLAY_LENGTH + 1];
1091
	char  TestLine [10];
1092
   int 	result;
1093
   int 	prodName;
1094
   int 	chName;
1095
1096
   result 	= 1;
1097
   prodName = 0;
1098
   chName 	= 0;
1099
1100
   if (Disp.UpdateFlag && (MS_TIMER - Disp.Timer > Disp.NextUpdate)) 
1101
   {
1102
      if (Disp.Hold && (MS_TIMER - Disp.HoldTimer > DSP_CHAN_HOLD))
1103
      {
1104
         Disp.Hold = 0;
1105
      }
1106
1107
      if (Config.TestCnl > -1)
1108
      {
1109
	   	Disp.Chan = Config.TestCnl;
1110
      }
1111
	   else if (Config.ViewCnl > -1)
1112
      {
1113
	   	Disp.Chan = Config.ViewCnl;
1114
      }
1115
	   else if (!Disp.Hold)
1116
      {
1117
         Disp.Chan++;
1118
      }
1119
1120
      while (result) 
1121
      {
1122
         if (Disp.Chan < 0) 
1123
         {
1124
         	Disp.Chan = 0;
1125
         	result 	 = 0;
1126
         }
1127
         else if (Disp.Chan >= Config.N_Turbines) 
1128
         {
1129
         	Disp.Chan = 0;
1130
            result 	 = 0;
1131
         }
1132
         else if (Channel[Disp.Chan].NeverLeadFlag)
1133
         {
1134
            Disp.Chan++;
1135
         }
1136
         else
1137
         {
1138
            result = 0;
1139
         }
1140
      }
1141
1142
      prodName = Channel[Disp.Chan].Prod->ProdName;
1143
      chName = Disp.Chan+1;
1144
1145
      if (Disp.Hold)
1146
      {
1147
      	Disp.NextUpdate = DSP_HOLD / 4;
1148
      }
1149
      else
1150
      {
1151
      	Disp.NextUpdate = DSP_HOLD;
1152
      }
1153
1154
      #if SCH2
1155
         if (Config.ModBus.Address == 2) 
1156
         {
1157
            prodName = Channel[Disp.Chan].Prod->ProdName;
1158
            chName = Disp.Chan+1;
1159
         }
1160
      #endif
1161
1162
      #if MODBUS_M_ON
1163
         sprintf (TopLine, "P=%d-%d%c  PR=%5.1f", prodName, chName,
1164
                  Channel[Disp.Chan].LeadFlag ? 'L' : ' ',
1165
                  Channel[Disp.Chan].LDN->Pressure);
1166
      #else
1167
         sprintf (TopLine, "P=%d-%d%c   PR=%s",   prodName, chName,
1168
                  Channel[Disp.Chan].LeadFlag ? 'L' : ' ',
1169
                  pressureName[Channel[Disp.Chan].PresFlag]);
1170
      #endif
1171
1172
      if (Channel[Disp.Chan].GPH3Test.Status >= PT_COMPLETE) 
1173
      {
1174
         FormatTestResault(TopLine, BotLine, &Channel[Disp.Chan].Event);
1175
         if (Channel[Disp.Chan].GPH3Test.Result == FAIL)
1176
         {
1177
            //TODO this might be where it is failing for garbage char on display
1178
            AddPrintEvent(TEST_LOG, TopLine, BotLine, Disp.Chan);
1179
         }
1180
      	TestStop (&Channel[Disp.Chan].GPH3Test);
1181
         Disp.NextUpdate = DSP_HOLD * 2;
1182
      }
1183
      else if (Channel[Disp.Chan].PrecTest.Status >= PT_COMPLETE) 
1184
      {
1185
         FormatTestResault(TopLine, BotLine, &Channel[Disp.Chan].Event);
1186
         AddPrintEvent (TEST_LOG, TopLine, BotLine, Disp.Chan);
1187
         TestStop (&Channel[Disp.Chan].PrecTest);
1188
         Disp.NextUpdate = DSP_HOLD * 2;
1189
      }
1190
      else if (Channel[Disp.Chan].AlarmFlag > DISP_ALARM) 
1191
      {
1192
      	Channel[Disp.Chan].AlarmFlag -= DISP_ALARM;
1193
         FormatAlarm(TopLine, BotLine, &Channel[Disp.Chan].EventAl);
1194
         AddPrintEvent(ALRM_LOG, TopLine, BotLine, Disp.Chan);
1195
         Disp.NextUpdate = DSP_HOLD * 2;
1196
      }
1197
      else if (Channel[Disp.Chan].WarnFlag > NO_WARNING) 
1198
      {
1199
         if (Channel[Disp.Chan].WarnFlag == NO_PRES_WARN)
1200
         {
1201
            sprintf (BotLine, "W - NO PRESSURE ");
1202
         }
1203
         else if (Channel[Disp.Chan].WarnFlag == FAIL_3GPH_WARN)
1204
         {
1205
            sprintf (BotLine, "W - 3 GPH FAIL  ");
1206
         }
1207
         AddPrintEvent(WARN_LOG, TopLine, BotLine, Disp.Chan);
1208
         Channel[Disp.Chan].WarnFlag = NO_WARNING;
1209
      }
1210
      else if (Channel[Disp.Chan].GPH3Test.Status == PT_ACTIVE)
1211
      {   
1212
         sprintf (BotLine, GPH3TestName[Channel[Disp.Chan].GPH3Test.State]);
1213
      }
1214
      else if (Channel[Disp.Chan].PrecTest.Status == PT_ACTIVE)
1215
      {
1216
         sprintf (BotLine, PTestName[Channel[Disp.Chan].PrecTest.State - 3],
1217
                  Channel[Disp.Chan].PrecTest.Type, Channel[Disp.Chan].PrecTest.CurCycle + 1);
1218
      }
1219
      else
1220
      {
1221
         sprintf (BotLine, stateName[Channel[Disp.Chan].State]);
1222
      }
1223
1224
      Disp.Timer = MS_TIMER;
1225
      DisplayMsgCtr (TopLine, BotLine);
1226
	}
1227
}
1228
1229
// Format Test Resault ********************************************************
1230
//I added additional test checks before setting a failed result as we had bleed over from PT.
1231
/******************************************************************
1232
 * 			Function Name:
1233
 * 
1234
 * 
1235
 * 		Args / Parameters:
1236
 * 
1237
 * 
1238
 * 		Description:
1239
 *                   Formats the test result to send to screen and printer.
1240
 * 
1241
 * 
1242
 * 
1243
 * 		Returns:
1244
 * 
1245
 */
1246
void FormatTestResault(char *TopLine, char *BotLine, EventSt *EventSet) 
1247
{
1248
	char 	TmpLine [DISPLAY_LENGTH + 1];
1249
   //BotLine[17] = ""; //Initialize char array to NULL values.
1250
1251
	sprintf (TmpLine, "P=%d-%dL ", EventSet->Product+1, EventSet->Channel+1);
1252
1253
   if (EventSet->Code == TEST_GPH3)
1254
   {
1255
      sprintf (TopLine, "%s", TmpLine);
1256
1257
	   if (EventSet->Status == PASS)
1258
      {
1259
         printf("Passed GPH with: %d \n", EventSet->Status);
1260
	      sprintf (BotLine, " 3 GPH    PASS  ");
1261
      }
1262
	   else if(EventSet->Status == FAIL)
1263
      {
1264
         printf("Failed 3GPH in FormatTestResault with: %d \n", EventSet->Status);
1265
	      sprintf (BotLine, " 3 GPH    FAIL  ");
1266
      }
1267
	}
1268
   //Testing .1 results
1269
   if (EventSet->Code == TEST_PNT1)
1270
   {
1271
      sprintf (TopLine, "%s", TmpLine);
1272
1273
      if (EventSet->Status == PASS)
1274
      {
1275
         sprintf (TopLine, "%s LR=0.00", TmpLine);
1276
         sprintf (BotLine, "0.%d PASS", EventSet->Code);
1277
      }
1278
      else if (EventSet->Status == FAIL)
1279
      {
1280
         sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1281
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1282
      }
1283
      else if (EventSet->Notes == PT_NO_PRESSURE) 
1284
      {
1285
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1286
	   	sprintf (TopLine, "%s NO PRES ", TmpLine);
1287
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1288
	   }
1289
	   else if (EventSet->Notes == PT_INGRESS) 
1290
      {
1291
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1292
	      sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1293
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1294
	   }
1295
1296
   }
1297
   //Testing .2 results
1298
   if (EventSet->Code == TEST_PNT2)
1299
   {
1300
      printf("LEAK RATE IS %d ", EventSet->Rate);
1301
      sprintf (TopLine, "%s", TmpLine);
1302
1303
      if (EventSet->Status == PASS)
1304
      {
1305
         sprintf (TopLine, "%s LR=0.00", TmpLine);
1306
         sprintf (BotLine, "0.%d PASS", EventSet->Code);
1307
      }
1308
      else if (EventSet->Status == FAIL)
1309
      {
1310
         sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1311
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1312
      }
1313
1314
      else if (EventSet->Notes == PT_NO_PRESSURE) 
1315
      {
1316
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1317
	   	sprintf (TopLine, "%s NO PRES ", TmpLine);
1318
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1319
	   }
1320
	   else if (EventSet->Notes == PT_INGRESS) 
1321
      {
1322
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1323
	      sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1324
	      sprintf (BotLine, "0.%d FAIL", EventSet->Code);
1325
	   }
1326
1327
   }
1328
1329
   /*
1330
	else if (EventSet->Code == TEST_PNT1 && EventSet->Status == PASS || EventSet->Code == TEST_PNT2 && EventSet->Status == PASS)
1331
   {
1332
      printf("Passed .1 or .2 with: %d \n", EventSet->Status);
1333
	   sprintf (TopLine, "%s LR=0.00", TmpLine);
1334
  	   sprintf (BotLine, "  0.%d    PASS  ", EventSet->Code);
1335
	}
1336
	else if (EventSet->Code == TEST_PNT1 && EventSet->Status == FAIL || EventSet->Code == TEST_PNT1 && EventSet->Status == FAIL)
1337
   {
1338
	   if (EventSet->Notes == PT_NO_PRESSURE) 
1339
      {
1340
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1341
	   	sprintf (TopLine, "%s NO PRES ", TmpLine);
1342
	      sprintf (BotLine, "  0.%d    FAIL  ", EventSet->Code);
1343
	   }
1344
	   else if (EventSet->Notes == PT_INGRESS) 
1345
      {
1346
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1347
	      sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1348
	      sprintf (BotLine, "  0.%d    FAIL  ", EventSet->Code);
1349
	   }
1350
      
1351
	   else //Possibly causing char corruption when failing
1352
      {
1353
         
1354
         printf("Failed .1 or .2 with: %d \n", EventSet->Status);
1355
         printf("Failed with a note of %d: \n", EventSet->Notes);
1356
	      sprintf (TopLine, "%s LR=%4.2f" , TmpLine, EventSet->Rate);
1357
	      sprintf (BotLine, "  0.%d    FAIL  ", EventSet->Code);
1358
         
1359
	   } 
1360
	}
1361
	else if (EventSet->Notes == PT_CYCLE_LIMIT) 
1362
   {
1363
      printf("Error on line 1054 PLC Main Note: %d", EventSet->Notes);
1364
      sprintf (TopLine, "  %s     N/A    ", TmpLine);
1365
      sprintf (BotLine, "  0.%d   C.L.   ", EventSet->Code);
1366
	}
1367
   */
1368
1369
}
1370
1371
// Format Alarm ***************************************************************
1372
/******************************************************************
1373
 * 			Function Name:
1374
 * 
1375
 * 
1376
 * 		Args / Parameters:
1377
 * 
1378
 * 
1379
 * 		Description:
1380
 * 
1381
 * 
1382
 * 
1383
 * 		Returns:
1384
 * 
1385
 */
1386
1387
/*
1388
void FormatAlarm(char *TopLine, char *BotLine, EventSt *EventSet)
1389
{
1390
   sprintf(TopLine, "P=%d-%dL ", EventSet->Product+1, EventSet->Channel+1);
1391
   //BotLine[17] = "";  //Initialize char array to NULL values.
1392
1393
   if(EventSet->Code == NO_PRES_ALARM)
1394
   {
1395
         sprintf (BotLine, "A - NO PRESSURE ");
1396
   }
1397
   else if (EventSet->Code == LOW_PRES_ALARM)
1398
   {
1399
      sprintf (BotLine, "A - LOW PRESSURE");
1400
   }
1401
   else if (EventSet->Code == NO_FLOW)
1402
   {
1403
      sprintf (BotLine, "A - NO FLOW     ");
1404
   }
1405
   else if (EventSet->Code == FAIL_3GPH)
1406
   {
1407
      sprintf (BotLine, "A - 3 GPH FAIL  ");
1408
   }
1409
   else if (EventSet->Code == TEST_ABORT)
1410
   {
1411
      sprintf (BotLine, "A - TEST ABORTED");
1412
   }
1413
   else if (EventSet->Code == SUMP_ALARM)
1414
   {
1415
      sprintf (BotLine, "A - SUMP SENSOR ");
1416
   }
1417
   else if (EventSet->Code == SENSOR_ALARM)
1418
   {
1419
      sprintf (BotLine, "A - SENSOR OUT  ");
1420
   }
1421
   else if (EventSet->Code == NO_PRES_DROP)
1422
   {
1423
      sprintf (BotLine, "A - NO DROP PRES");
1424
   }
1425
}
1426
*/
1427
void FormatAlarm(char *TopLine, char *BotLine, EventSt *EventSet )
1428
{
1429
    int alarmCode;
1430
    sprintf (TopLine, "P=%d-%dL ", EventSet->Product+1, EventSet->Channel+1);
1431
1432
    
1433
    alarmCode = EventSet->Code;
1434
    if (alarmCode >= DISP_ALARM) 
1435
    {
1436
        alarmCode -= DISP_ALARM;
1437
    }
1438
1439
    switch (alarmCode)
1440
    {
1441
        printf("Switch for Format Alarm Reached. Alarm: %d", alarmCode);
1442
        case NO_PRES_ALARM:
1443
            sprintf (BotLine, "A - NO PRESSURE "); break;
1444
        case LOW_PRES_ALARM:
1445
            sprintf (BotLine, "A - LOW PRESSURE"); break;
1446
        case NO_FLOW:
1447
            sprintf (BotLine, "A - NO FLOW     "); break;
1448
        case FAIL_3GPH:
1449
            sprintf (BotLine, "A - 3 GPH FAIL  "); break;
1450
        case TEST_ABORT:
1451
            sprintf (BotLine, "A - TEST ABORTED"); break;
1452
        case SUMP_ALARM:
1453
            sprintf (BotLine, "A - SUMP SENSOR "); break;
1454
        case SENSOR_ALARM:
1455
            sprintf (BotLine, "A - SENSOR OUT  "); break;
1456
        case NO_PRES_DROP:
1457
            sprintf (BotLine, "A - NO DROP PRES"); break;
1458
        default:
1459
            sprintf (BotLine, "ALARM           ");
1460
    }
1461
}
1462
1463
1464
// Reset LDN Commands **********************************************************
1465
/******************************************************************
1466
 * 			Function Name:
1467
 * 
1468
 * 
1469
 * 		Args / Parameters:
1470
 * 
1471
 * 
1472
 * 		Description:
1473
 * 
1474
 * 
1475
 * 
1476
 * 		Returns:
1477
 * 
1478
 */
1479
void ResetLDN(int chn, int res) 
1480
{
1481
	SetLDNReg 	(chn, RESIL, 		  res);
1482
	SetLDNReg   (chn, SHUNT_PRES,   OFF);
1483
	SetLDNReg   (chn, MONITOR_PRES, OFF);
1484
	SetLDNReg   (chn, AUTH_REQUEST, OFF);
1485
}
1486
1487
//End of program ***************************************************************
1488
//******************************************************************************
1489
1490
/*** BeginHeader */
1491
#endif
1492
/*** EndHeader */
1493