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

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

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

#include "graf_mdl_manipulateur.h"


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

CB_Index graf_mdl_manipulateur__num = 0;
CB_Mem_Int *graf_mdl_manipulateur_CR_pos;
CB_Mem_Bool *graf_mdl_manipulateur_def_depl;
CB_Mem_Int *graf_mdl_manipulateur_Pos_depart;
CB_Mem_Int *graf_mdl_manipulateur_Pos_arrivee;
CB_Mem_Bool *graf_mdl_manipulateur_DCY;
CB_Mem_Bool *graf_mdl_manipulateur_AU;
CB_Mem_Bool *graf_mdl_manipulateur_acq;
CB_Mem_Bool *graf_mdl_manipulateur_OKprise;
CB_Mem_Bool *graf_mdl_manipulateur_OKpose;
CB_Mem_Bool *graf_mdl_manipulateur_def_prisepose;
CB_Mem_Int *graf_mdl_manipulateur_Demande_pos;
CB_Mem_Bool *graf_mdl_manipulateur_GO;
CB_Mem_Bool *graf_mdl_manipulateur_Def_Manip;
CB_Mem_Bool *graf_mdl_manipulateur_OKcycle;
CB_Mem_Bool *graf_mdl_manipulateur_Dprise;
CB_Mem_Bool *graf_mdl_manipulateur_Dpose;
CB_Mem_Bool *graf_mdl_manipulateur__X_20;
CB_Mem_Bool *graf_mdl_manipulateur__X_21;
CB_Mem_Bool *graf_mdl_manipulateur__X_22;
CB_Mem_Bool *graf_mdl_manipulateur__X_10;
CB_Mem_Bool *graf_mdl_manipulateur__X_11;
CB_Mem_Bool *graf_mdl_manipulateur__X_12;
CB_Mem_Bool *graf_mdl_manipulateur__X_13;
CB_Mem_Bool *graf_mdl_manipulateur__X_14;
CB_Mem_Bool *graf_mdl_manipulateur__FORCING_G1;
CB_Mem_Bool *graf_mdl_manipulateur__X_10_PREV;
CB_Mem_Bool *graf_mdl_manipulateur__X_11_PREV;
CB_Mem_Bool *graf_mdl_manipulateur__X_12_PREV;
CB_Mem_Bool *graf_mdl_manipulateur__X_13_PREV;
CB_Mem_Bool *graf_mdl_manipulateur__X_14_PREV;

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

#define CR_pos (*((short *)&(graf_mdl_manipulateur_CR_pos->CB_current_value) + ALIGN_OFFSET_SHORT))
#define def_depl (graf_mdl_manipulateur_def_depl->CB_current_value)
#define Pos_depart (*((short *)&(graf_mdl_manipulateur_Pos_depart->CB_current_value) + ALIGN_OFFSET_SHORT))
#define Pos_arrivee (*((short *)&(graf_mdl_manipulateur_Pos_arrivee->CB_current_value) + ALIGN_OFFSET_SHORT))
#define DCY (graf_mdl_manipulateur_DCY->CB_current_value)
#define AU (graf_mdl_manipulateur_AU->CB_current_value)
#define acq (graf_mdl_manipulateur_acq->CB_current_value)
#define OKprise (graf_mdl_manipulateur_OKprise->CB_current_value)
#define OKpose (graf_mdl_manipulateur_OKpose->CB_current_value)
#define def_prisepose (graf_mdl_manipulateur_def_prisepose->CB_current_value)
#define Demande_pos (*((short *)&(graf_mdl_manipulateur_Demande_pos->CB_current_value) + ALIGN_OFFSET_SHORT))
#define GO (graf_mdl_manipulateur_GO->CB_current_value)
#define Def_Manip (graf_mdl_manipulateur_Def_Manip->CB_current_value)
#define OKcycle (graf_mdl_manipulateur_OKcycle->CB_current_value)
#define Dprise (graf_mdl_manipulateur_Dprise->CB_current_value)
#define Dpose (graf_mdl_manipulateur_Dpose->CB_current_value)
#define _X_20 (graf_mdl_manipulateur__X_20->CB_current_value)
#define _X_21 (graf_mdl_manipulateur__X_21->CB_current_value)
#define _X_22 (graf_mdl_manipulateur__X_22->CB_current_value)
#define _X_10 (graf_mdl_manipulateur__X_10->CB_current_value)
#define _X_11 (graf_mdl_manipulateur__X_11->CB_current_value)
#define _X_12 (graf_mdl_manipulateur__X_12->CB_current_value)
#define _X_13 (graf_mdl_manipulateur__X_13->CB_current_value)
#define _X_14 (graf_mdl_manipulateur__X_14->CB_current_value)
#define _FORCING_G1 (graf_mdl_manipulateur__FORCING_G1->CB_current_value)
#define _X_10_PREV (graf_mdl_manipulateur__X_10_PREV->CB_current_value)
#define _X_11_PREV (graf_mdl_manipulateur__X_11_PREV->CB_current_value)
#define _X_12_PREV (graf_mdl_manipulateur__X_12_PREV->CB_current_value)
#define _X_13_PREV (graf_mdl_manipulateur__X_13_PREV->CB_current_value)
#define _X_14_PREV (graf_mdl_manipulateur__X_14_PREV->CB_current_value)


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


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

int _sfp__graf_mdl_manipulateur_init(void)
{
	(self.Bool+0)->CB_current_value = 1; /*_X_20*/
	self.Bool+=14;


	return 0;
}


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

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

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

		graf_mdl_manipulateur__X_20 = self.Bool+0;
		graf_mdl_manipulateur__X_21 = self.Bool+1;
		graf_mdl_manipulateur__X_22 = self.Bool+2;
		graf_mdl_manipulateur__X_10 = self.Bool+3;
		graf_mdl_manipulateur__X_11 = self.Bool+4;
		graf_mdl_manipulateur__X_12 = self.Bool+5;
		graf_mdl_manipulateur__X_13 = self.Bool+6;
		graf_mdl_manipulateur__X_14 = self.Bool+7;
		graf_mdl_manipulateur__FORCING_G1 = self.Bool+8;
		graf_mdl_manipulateur__X_10_PREV = self.Bool+9;
		graf_mdl_manipulateur__X_11_PREV = self.Bool+10;
		graf_mdl_manipulateur__X_12_PREV = self.Bool+11;
		graf_mdl_manipulateur__X_13_PREV = self.Bool+12;
		graf_mdl_manipulateur__X_14_PREV = self.Bool+13;

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

		/*no Pre-conditions*/

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

		{
			unsigned char _Y_27;
			unsigned char _Y_26;
			unsigned char _Y_25;
			unsigned char _Y_28;
			unsigned char _Y_10;
			unsigned char _Y_9;
			unsigned char _Y_8;
			unsigned char _Y_7;
			unsigned char _Y_6;
			_FORCING_G1 = 0;
			/*pre-SFC*/
			/*transitions G2*/
			_Y_27 = _X_20 && _X_10;
			_Y_26 = _X_21 && Def_Manip;
			_Y_25 = _X_22 && !Def_Manip;
			_Y_28 = _X_20 && (!_Y_27 && Def_Manip);
			/*transitions G1*/
			_Y_10 = _X_10 && DCY;
			_Y_9 = _X_11 && (CR_pos == Pos_depart);
			_Y_8 = _X_12 && OKprise;
			_Y_7 = _X_13 && (CR_pos == Pos_arrivee);
			_Y_6 = _X_14 && OKpose;
			/*evolutions G2*/
			if (_Y_27) {
				_X_20 = 0;
			}
			if (_Y_26) {
				_X_21 = 0;
			}
			if (_Y_25) {
				_X_22 = 0;
			}
			if (_Y_28) {
				_X_20 = 0;
			}
			if (_Y_27) {
				_X_21 = 1;
			}
			if (_Y_26) {
				_X_22 = 1;
			}
			if (_Y_25) {
				_X_20 = 1;
			}
			if (_Y_28) {
				_X_22 = 1;
			}
			/*timers G2*/
			/*actions G2*/
			if (_X_20) {
				_FORCING_G1 = 1;
				_X_10 = 1;
				_X_11 = 0;
				_X_12 = 0;
				_X_13 = 0;
				_X_14 = 0;
			}
			/*evolutions G1*/
			if (!_FORCING_G1) {
				if (_Y_10) {
					_X_10 = 0;
				}
				if (_Y_9) {
					_X_11 = 0;
				}
				if (_Y_8) {
					_X_12 = 0;
				}
				if (_Y_7) {
					_X_13 = 0;
				}
				if (_Y_6) {
					_X_14 = 0;
				}
				if (_Y_10) {
					_X_11 = 1;
				}
				if (_Y_9) {
					_X_12 = 1;
				}
				if (_Y_8) {
					_X_13 = 1;
				}
				if (_Y_7) {
					_X_14 = 1;
				}
				if (_Y_6) {
					_X_10 = 1;
				}
			}
			/*timers G1*/
			/*actions G1*/
			if (CB_edge_bool(_X_10, _X_10_PREV) < 0) {
				OKcycle = 0;
			}
			if (CB_edge_bool(_X_11, _X_11_PREV) < 0) {
				GO = 0;
			}
			if (CB_edge_bool(_X_12, _X_12_PREV) < 0) {
				Dprise = 0;
			}
			if (CB_edge_bool(_X_13, _X_13_PREV) < 0) {
				GO = 0;
			}
			if (CB_edge_bool(_X_14, _X_14_PREV) < 0) {
				Dpose = 0;
			}
			if (_X_10) {
				OKcycle = 1;
			}
			if (_X_11) {
				Demande_pos = Pos_depart;
				GO = 1;
			}
			if (_X_12) {
				Dprise = 1;
			}
			if (_X_13) {
				Demande_pos = Pos_arrivee;
				GO = 1;
			}
			if (_X_14) {
				Dpose = 1;
			}
			/*post-SFC*/
			if ((def_prisepose || AU) || def_depl) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 3, IFTHEN);
				Def_Manip = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 3, IFELSE);
			}
			if (((acq && !def_prisepose) && !AU) && !def_depl) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 5, IFTHEN);
				Def_Manip = 0;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 5, IFELSE);
			}
			_X_14_PREV = _X_14;
			_X_13_PREV = _X_13;
			_X_12_PREV = _X_12;
			_X_11_PREV = _X_11;
			_X_10_PREV = _X_10;
		}

		CB_post_int(graf_mdl_manipulateur_Demande_pos);
		CB_post_bool(graf_mdl_manipulateur_GO);
		CB_post_bool(graf_mdl_manipulateur_Def_Manip);
		CB_post_bool(graf_mdl_manipulateur_OKcycle);
		CB_post_bool(graf_mdl_manipulateur_Dprise);
		CB_post_bool(graf_mdl_manipulateur_Dpose);

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

		/*no Post-conditions*/
	}

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

	self.Bool += 14;

	return 0;
}

