/*2011-01-03T15:22:35-01:00*/

/********************************************************************
 * graf_mdl_prdpos_cov.c
 * 
 * generated by: plcgen 2.1.201
 ********************************************************************/

#include "cb_comp.h"
#include "cb_covs.h"
#include "iec_1131.h"

#include "graf_mdl_prdpos.h"


/**************************** Variables *****************************/

CB_Index graf_mdl_prdpos__num = 0;
CB_Mem_Bool *graf_mdl_prdpos_acq;
CB_Mem_Bool *graf_mdl_prdpos_AU;
CB_Mem_Bool *graf_mdl_prdpos_dprise;
CB_Mem_Bool *graf_mdl_prdpos_dpose;
CB_Mem_Bool *graf_mdl_prdpos_vacuostat;
CB_Mem_Bool *graf_mdl_prdpos_CR_VZS;
CB_Mem_Bool *graf_mdl_prdpos_CR_VZR;
CB_Mem_Bool *graf_mdl_prdpos_def_VZ;
CB_Mem_Bool *graf_mdl_prdpos_VZS;
CB_Mem_Bool *graf_mdl_prdpos_VZR;
CB_Mem_Bool *graf_mdl_prdpos_VTM;
CB_Mem_Bool *graf_mdl_prdpos_VTA;
CB_Mem_Bool *graf_mdl_prdpos_OKprise;
CB_Mem_Bool *graf_mdl_prdpos_OKpose;
CB_Mem_Bool *graf_mdl_prdpos_def_prisepose;
CB_Mem_Int *graf_mdl_prdpos_t1;
CB_Mem_Int *graf_mdl_prdpos_t2;
CB_Mem_Int *graf_mdl_prdpos_TTL;
CB_Mem_Bool *graf_mdl_prdpos__X_20;
CB_Mem_Bool *graf_mdl_prdpos__X_21;
CB_Mem_Bool *graf_mdl_prdpos__X_22;
CB_Mem_Bool *graf_mdl_prdpos__X_11;
CB_Mem_Bool *graf_mdl_prdpos__X_12;
CB_Mem_Bool *graf_mdl_prdpos__X_13;
CB_Mem_Bool *graf_mdl_prdpos__X_10;
CB_Mem_Bool *graf_mdl_prdpos__X_14;
CB_Mem_Bool *graf_mdl_prdpos__X_15;
CB_Mem_Bool *graf_mdl_prdpos__X_16;
CB_Mem_Bool *graf_mdl_prdpos__FORCING_G1;
CB_Mem_Bool *graf_mdl_prdpos__X_22_PREV;
CB_Mem_Bool *graf_mdl_prdpos__X_11_PREV;
CB_Mem_Bool *graf_mdl_prdpos__X_13_PREV;
CB_Mem_Bool *graf_mdl_prdpos__X_14_PREV;
CB_Mem_Bool *graf_mdl_prdpos__X_15_PREV;
CB_Mem_Bool *graf_mdl_prdpos__X_16_PREV;

/**************************** Variables *****************************/

#define acq (graf_mdl_prdpos_acq->CB_current_value)
#define AU (graf_mdl_prdpos_AU->CB_current_value)
#define dprise (graf_mdl_prdpos_dprise->CB_current_value)
#define dpose (graf_mdl_prdpos_dpose->CB_current_value)
#define vacuostat (graf_mdl_prdpos_vacuostat->CB_current_value)
#define CR_VZS (graf_mdl_prdpos_CR_VZS->CB_current_value)
#define CR_VZR (graf_mdl_prdpos_CR_VZR->CB_current_value)
#define def_VZ (graf_mdl_prdpos_def_VZ->CB_current_value)
#define VZS (graf_mdl_prdpos_VZS->CB_current_value)
#define VZR (graf_mdl_prdpos_VZR->CB_current_value)
#define VTM (graf_mdl_prdpos_VTM->CB_current_value)
#define VTA (graf_mdl_prdpos_VTA->CB_current_value)
#define OKprise (graf_mdl_prdpos_OKprise->CB_current_value)
#define OKpose (graf_mdl_prdpos_OKpose->CB_current_value)
#define def_prisepose (graf_mdl_prdpos_def_prisepose->CB_current_value)
#define t1(i) (graf_mdl_prdpos_t1[i+1].CB_current_value)
#define t2 (graf_mdl_prdpos_t2->CB_current_value)
#define TTL(i) (graf_mdl_prdpos_TTL[i+1].CB_current_value)
#define _X_20 (graf_mdl_prdpos__X_20->CB_current_value)
#define _X_21 (graf_mdl_prdpos__X_21->CB_current_value)
#define _X_22 (graf_mdl_prdpos__X_22->CB_current_value)
#define _X_11 (graf_mdl_prdpos__X_11->CB_current_value)
#define _X_12 (graf_mdl_prdpos__X_12->CB_current_value)
#define _X_13 (graf_mdl_prdpos__X_13->CB_current_value)
#define _X_10 (graf_mdl_prdpos__X_10->CB_current_value)
#define _X_14 (graf_mdl_prdpos__X_14->CB_current_value)
#define _X_15 (graf_mdl_prdpos__X_15->CB_current_value)
#define _X_16 (graf_mdl_prdpos__X_16->CB_current_value)
#define _FORCING_G1 (graf_mdl_prdpos__FORCING_G1->CB_current_value)
#define _X_22_PREV (graf_mdl_prdpos__X_22_PREV->CB_current_value)
#define _X_11_PREV (graf_mdl_prdpos__X_11_PREV->CB_current_value)
#define _X_13_PREV (graf_mdl_prdpos__X_13_PREV->CB_current_value)
#define _X_14_PREV (graf_mdl_prdpos__X_14_PREV->CB_current_value)
#define _X_15_PREV (graf_mdl_prdpos__X_15_PREV->CB_current_value)
#define _X_16_PREV (graf_mdl_prdpos__X_16_PREV->CB_current_value)


/************************ Components offsets ************************/


/********************* Initialization function **********************/

int _sfp__graf_mdl_prdpos_init(void)
{
	(self.Int+5+3)->CB_current_value = 100000; /*TTL[2]*/
	(self.Bool+0)->CB_current_value = 1; /*_X_20*/
	self.Bool+=17;
	self.Int+=9;


	return 0;
}


/************************ Behavior function *************************/

int sfp__graf_mdl_prdpos(void)
{
	static char *__comp_name = "sfp.graf_mdl_prdpos";
	if (exec_term_node(self_num)) {

		/*********************** Internals variables ************************/

		graf_mdl_prdpos_t1 = self.Int+0;
		graf_mdl_prdpos_t2 = self.Int+4;
		graf_mdl_prdpos_TTL = self.Int+5;
		graf_mdl_prdpos__X_20 = self.Bool+0;
		graf_mdl_prdpos__X_21 = self.Bool+1;
		graf_mdl_prdpos__X_22 = self.Bool+2;
		graf_mdl_prdpos__X_11 = self.Bool+3;
		graf_mdl_prdpos__X_12 = self.Bool+4;
		graf_mdl_prdpos__X_13 = self.Bool+5;
		graf_mdl_prdpos__X_10 = self.Bool+6;
		graf_mdl_prdpos__X_14 = self.Bool+7;
		graf_mdl_prdpos__X_15 = self.Bool+8;
		graf_mdl_prdpos__X_16 = self.Bool+9;
		graf_mdl_prdpos__FORCING_G1 = self.Bool+10;
		graf_mdl_prdpos__X_22_PREV = self.Bool+11;
		graf_mdl_prdpos__X_11_PREV = self.Bool+12;
		graf_mdl_prdpos__X_13_PREV = self.Bool+13;
		graf_mdl_prdpos__X_14_PREV = self.Bool+14;
		graf_mdl_prdpos__X_15_PREV = self.Bool+15;
		graf_mdl_prdpos__X_16_PREV = self.Bool+16;

		/********************* Pre-conditions execution *********************/

		/*no Pre-conditions*/

		/************************ Behavior execution ************************/

		{
			unsigned char _Y_34;
			unsigned char _Y_33;
			unsigned char _Y_32;
			unsigned char _Y_35;
			unsigned char _Y_11;
			unsigned char _Y_10;
			unsigned char _Y_9;
			unsigned char _Y_8;
			unsigned char _Y_15;
			unsigned char _Y_14;
			unsigned char _Y_13;
			unsigned char _Y_12;
			_FORCING_G1 = 0;
			/*pre-SFC*/
			/*transitions G2*/
			_Y_34 = _X_20 && _X_10;
			_Y_33 = _X_21 && def_prisepose;
			_Y_32 = _X_22 && !def_prisepose;
			_Y_35 = _X_20 && (!_Y_34 && def_prisepose);
			/*transitions G1*/
			_Y_11 = _X_10 && ((dprise && !dpose) && !vacuostat);
			_Y_10 = _X_11 && CR_VZS;
			_Y_9 = _X_12 && vacuostat;
			_Y_8 = _X_13 && CR_VZR;
			_Y_15 = _X_10 && (!_Y_11 && ((dpose && !dprise) && vacuostat));
			_Y_14 = _X_14 && CR_VZS;
			_Y_13 = _X_15 && !vacuostat;
			_Y_12 = _X_16 && CR_VZR;
			/*evolutions G2*/
			if (_Y_34) {
				_X_20 = 0;
			}
			if (_Y_33) {
				_X_21 = 0;
			}
			if (_Y_32) {
				_X_22 = 0;
			}
			if (_Y_35) {
				_X_20 = 0;
			}
			if (_Y_34) {
				_X_21 = 1;
			}
			if (_Y_33) {
				_X_22 = 1;
			}
			if (_Y_32) {
				_X_20 = 1;
			}
			if (_Y_35) {
				_X_22 = 1;
			}
			/*timers G2*/
			/*actions G2*/
			if (CB_edge_bool(_X_22, _X_22_PREV) < 0) {
				VZR = 0;
				VTA = 0;
			}
			if (_X_20) {
				_FORCING_G1 = 1;
				_X_11 = 0;
				_X_12 = 0;
				_X_13 = 0;
				_X_10 = 1;
				_X_14 = 0;
				_X_15 = 0;
				_X_16 = 0;
			}
			if (_X_22) {
				_FORCING_G1 = 1;
				_X_11 = 0;
				_X_12 = 0;
				_X_13 = 0;
				_X_10 = 0;
				_X_14 = 0;
				_X_15 = 0;
				_X_16 = 0;
				VZR = 1;
				VTA = 1;
			}
			/*evolutions G1*/
			if (!_FORCING_G1) {
				if (_Y_11) {
					_X_10 = 0;
				}
				if (_Y_10) {
					_X_11 = 0;
				}
				if (_Y_9) {
					_X_12 = 0;
				}
				if (_Y_8) {
					_X_13 = 0;
				}
				if (_Y_15) {
					_X_10 = 0;
				}
				if (_Y_14) {
					_X_14 = 0;
				}
				if (_Y_13) {
					_X_15 = 0;
				}
				if (_Y_12) {
					_X_16 = 0;
				}
				if (_Y_11) {
					_X_11 = 1;
				}
				if (_Y_10) {
					_X_12 = 1;
				}
				if (_Y_9) {
					_X_13 = 1;
				}
				if (_Y_8) {
					_X_10 = 1;
				}
				if (_Y_15) {
					_X_14 = 1;
				}
				if (_Y_14) {
					_X_15 = 1;
				}
				if (_Y_13) {
					_X_16 = 1;
				}
				if (_Y_12) {
					_X_10 = 1;
				}
			}
			/*timers G1*/
			/*actions G1*/
			if (CB_edge_bool(_X_11, _X_11_PREV) < 0) {
				VZS = 0;
				VTM = 0;
			}
			if (CB_edge_bool(_X_13, _X_13_PREV) < 0) {
				VZR = 0;
			}
			if (CB_edge_bool(_X_14, _X_14_PREV) < 0) {
				VZS = 0;
			}
			if (CB_edge_bool(_X_15, _X_15_PREV) < 0) {
				VTA = 0;
			}
			if (CB_edge_bool(_X_16, _X_16_PREV) < 0) {
				VZR = 0;
			}
			if (_X_11) {
				VZS = 1;
				VTM = 1;
			}
			if (_X_13) {
				VZR = 1;
			}
			if (_X_14) {
				VZS = 1;
			}
			if (_X_15) {
				VTA = 1;
			}
			if (_X_16) {
				VZR = 1;
			}
			/*post-SFC*/
			if ((AU || def_VZ) | ton_Q(_X_12, graf_mdl_prdpos_TTL, graf_mdl_prdpos_t1, &t2)) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 3, IFTHEN);
				def_prisepose = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 3, IFELSE);
			}
			if ((acq && !def_VZ) && !AU) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 7, IFTHEN);
				def_prisepose = 0;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 7, IFELSE);
			}
			OKprise = _X_10 && vacuostat;
			OKpose = _X_10 && !vacuostat;
			_X_16_PREV = _X_16;
			_X_15_PREV = _X_15;
			_X_14_PREV = _X_14;
			_X_13_PREV = _X_13;
			_X_22_PREV = _X_22;
			_X_11_PREV = _X_11;
		}

		if(nb_alloc > 0) {
			free_all_alloc();
		}

		CB_post_bool(graf_mdl_prdpos_VZS);
		CB_post_bool(graf_mdl_prdpos_VZR);
		CB_post_bool(graf_mdl_prdpos_VTM);
		CB_post_bool(graf_mdl_prdpos_VTA);
		CB_post_bool(graf_mdl_prdpos_OKprise);
		CB_post_bool(graf_mdl_prdpos_OKpose);
		CB_post_bool(graf_mdl_prdpos_def_prisepose);

		/******************** Post-conditions execution *********************/

		/*no Post-conditions*/
	}

	/*************************** self update ****************************/

	self.Bool += 17;
	self.Int += 9;

	return 0;
}

