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

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

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

#include "graf_mdl_ventouse.h"


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

CB_Index graf_mdl_ventouse__num = 0;
CB_Mem_Bool *graf_mdl_ventouse_DS;
CB_Mem_Bool *graf_mdl_ventouse_DR;
CB_Mem_Bool *graf_mdl_ventouse_ACQ;
CB_Mem_Bool *graf_mdl_ventouse_AU;
CB_Mem_Bool *graf_mdl_ventouse_OrdreR;
CB_Mem_Bool *graf_mdl_ventouse_OrdreS;
CB_Mem_Bool *graf_mdl_ventouse_EtatS;
CB_Mem_Bool *graf_mdl_ventouse_EtatR;
CB_Mem_Bool *graf_mdl_ventouse__X_10;
CB_Mem_Bool *graf_mdl_ventouse__X_11;
CB_Mem_Bool *graf_mdl_ventouse__X_12;
CB_Mem_Bool *graf_mdl_ventouse__X_20;
CB_Mem_Bool *graf_mdl_ventouse__X_21;
CB_Mem_Bool *graf_mdl_ventouse__X_22;
CB_Mem_Bool *graf_mdl_ventouse__X_23;
CB_Mem_Bool *graf_mdl_ventouse__FORCING_G2;
CB_Mem_Bool *graf_mdl_ventouse__X_20_PREV;
CB_Mem_Bool *graf_mdl_ventouse__X_21_PREV;
CB_Mem_Bool *graf_mdl_ventouse__X_22_PREV;
CB_Mem_Bool *graf_mdl_ventouse__X_23_PREV;

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

#define DS (graf_mdl_ventouse_DS->CB_current_value)
#define DR (graf_mdl_ventouse_DR->CB_current_value)
#define ACQ (graf_mdl_ventouse_ACQ->CB_current_value)
#define AU (graf_mdl_ventouse_AU->CB_current_value)
#define OrdreR (graf_mdl_ventouse_OrdreR->CB_current_value)
#define OrdreS (graf_mdl_ventouse_OrdreS->CB_current_value)
#define EtatS (graf_mdl_ventouse_EtatS->CB_current_value)
#define EtatR (graf_mdl_ventouse_EtatR->CB_current_value)
#define _X_10 (graf_mdl_ventouse__X_10->CB_current_value)
#define _X_11 (graf_mdl_ventouse__X_11->CB_current_value)
#define _X_12 (graf_mdl_ventouse__X_12->CB_current_value)
#define _X_20 (graf_mdl_ventouse__X_20->CB_current_value)
#define _X_21 (graf_mdl_ventouse__X_21->CB_current_value)
#define _X_22 (graf_mdl_ventouse__X_22->CB_current_value)
#define _X_23 (graf_mdl_ventouse__X_23->CB_current_value)
#define _FORCING_G2 (graf_mdl_ventouse__FORCING_G2->CB_current_value)
#define _X_20_PREV (graf_mdl_ventouse__X_20_PREV->CB_current_value)
#define _X_21_PREV (graf_mdl_ventouse__X_21_PREV->CB_current_value)
#define _X_22_PREV (graf_mdl_ventouse__X_22_PREV->CB_current_value)
#define _X_23_PREV (graf_mdl_ventouse__X_23_PREV->CB_current_value)


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


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

int _sfp__graf_mdl_ventouse_init(void)
{
	(self.Bool+0)->CB_current_value = 1; /*_X_10*/
	self.Bool+=12;


	return 0;
}


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

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

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

		graf_mdl_ventouse__X_10 = self.Bool+0;
		graf_mdl_ventouse__X_11 = self.Bool+1;
		graf_mdl_ventouse__X_12 = self.Bool+2;
		graf_mdl_ventouse__X_20 = self.Bool+3;
		graf_mdl_ventouse__X_21 = self.Bool+4;
		graf_mdl_ventouse__X_22 = self.Bool+5;
		graf_mdl_ventouse__X_23 = self.Bool+6;
		graf_mdl_ventouse__FORCING_G2 = self.Bool+7;
		graf_mdl_ventouse__X_20_PREV = self.Bool+8;
		graf_mdl_ventouse__X_21_PREV = self.Bool+9;
		graf_mdl_ventouse__X_22_PREV = self.Bool+10;
		graf_mdl_ventouse__X_23_PREV = self.Bool+11;

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

		/*no Pre-conditions*/

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

		{
			unsigned char _Y_6;
			unsigned char _Y_5;
			unsigned char _Y_4;
			unsigned char _Y_7;
			unsigned char _Y_22;
			unsigned char _Y_21;
			unsigned char _Y_20;
			unsigned char _Y_19;
			unsigned char _Y_23;
			unsigned char _Y_24;
			_FORCING_G2 = 0;
			/*pre-SFC*/
			/*transitions G1*/
			_Y_6 = _X_10 && _X_22;
			_Y_5 = _X_11 && AU;
			_Y_4 = _X_12 && (ACQ && !AU);
			_Y_7 = _X_10 && (!_Y_6 && AU);
			/*transitions G2*/
			_Y_22 = _X_20;
			_Y_21 = _X_21 && (DR && !DS);
			_Y_20 = _X_22;
			_Y_19 = _X_23 && (!DR && DS);
			_Y_23 = _X_20 && (!_Y_22 && (DR && !DS));
			_Y_24 = _X_22 && (!_Y_20 && (!DR && DS));
			/*evolutions G1*/
			if (_Y_6) {
				_X_10 = 0;
			}
			if (_Y_5) {
				_X_11 = 0;
			}
			if (_Y_4) {
				_X_12 = 0;
			}
			if (_Y_7) {
				_X_10 = 0;
			}
			if (_Y_6) {
				_X_11 = 1;
			}
			if (_Y_5) {
				_X_12 = 1;
			}
			if (_Y_4) {
				_X_10 = 1;
			}
			if (_Y_7) {
				_X_12 = 1;
			}
			/*timers G1*/
			/*actions G1*/
			if (_X_10) {
				_FORCING_G2 = 1;
				_X_20 = 0;
				_X_21 = 0;
				_X_22 = 1;
				_X_23 = 0;
			}
			if (_X_12) {
				_FORCING_G2 = 1;
				_X_20 = 0;
				_X_21 = 0;
				_X_22 = 0;
				_X_23 = 0;
			}
			/*evolutions G2*/
			if (!_FORCING_G2) {
				if (_Y_22) {
					_X_20 = 0;
				}
				if (_Y_21) {
					_X_21 = 0;
				}
				if (_Y_20) {
					_X_22 = 0;
				}
				if (_Y_19) {
					_X_23 = 0;
				}
				if (_Y_23) {
					_X_20 = 0;
				}
				if (_Y_24) {
					_X_22 = 0;
				}
				if (_Y_22) {
					_X_21 = 1;
				}
				if (_Y_21) {
					_X_22 = 1;
				}
				if (_Y_20) {
					_X_23 = 1;
				}
				if (_Y_19) {
					_X_20 = 1;
				}
				if (_Y_23) {
					_X_22 = 1;
				}
				if (_Y_24) {
					_X_20 = 1;
				}
			}
			/*timers G2*/
			/*actions G2*/
			if (CB_edge_bool(_X_20, _X_20_PREV) < 0) {
				OrdreS = 0;
			}
			if (CB_edge_bool(_X_21, _X_21_PREV) < 0) {
				EtatS = 0;
			}
			if (CB_edge_bool(_X_22, _X_22_PREV) < 0) {
				OrdreR = 0;
			}
			if (CB_edge_bool(_X_23, _X_23_PREV) < 0) {
				EtatR = 0;
			}
			if (_X_20) {
				OrdreS = 1;
			}
			if (_X_21) {
				EtatS = 1;
			}
			if (_X_22) {
				OrdreR = 1;
			}
			if (_X_23) {
				EtatR = 1;
			}
			/*post-SFC*/
			_X_23_PREV = _X_23;
			_X_22_PREV = _X_22;
			_X_21_PREV = _X_21;
			_X_20_PREV = _X_20;
		}

		CB_post_bool(graf_mdl_ventouse_OrdreR);
		CB_post_bool(graf_mdl_ventouse_OrdreS);
		CB_post_bool(graf_mdl_ventouse_EtatS);
		CB_post_bool(graf_mdl_ventouse_EtatR);

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

		/*no Post-conditions*/
	}

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

	self.Bool += 12;

	return 0;
}

