/*2013-01-18T16:22:37-01:00*/

/********************************************************************
 * calcul_debit.c
 * 
 * generated by: plcgen 2.3.253
 ********************************************************************/

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

#include "calcul_debit.h"



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

CB_Index calcul_debit__num = 0;
CB_Mem_Float *calcul_debit_debitEntree;
CB_Mem_Float *calcul_debit_debitSortie;
CB_Mem_Float *calcul_debit_unite;
CB_Mem_Float *calcul_debit_debitMax;
CB_Mem_Bool *calcul_debit_debitEnHeure;
CB_Mem_Bool *calcul_debit_debitEnMinute;

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

#define debitEntree (calcul_debit_debitEntree->CB_current_value)
#define debitSortie (calcul_debit_debitSortie->CB_current_value)
#define unite (calcul_debit_unite->CB_current_value)
#define debitMax (calcul_debit_debitMax->CB_current_value)
#define debitEnHeure (calcul_debit_debitEnHeure->CB_current_value)
#define debitEnMinute (calcul_debit_debitEnMinute->CB_current_value)


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


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

int _bibliotheque_epo__calcul_debit_init(void)
{
	(self.Float+1)->CB_current_value = 200.0; /*debitMax*/
	(self.Bool+0)->CB_current_value = 1; /*debitEnHeure*/
	self.Bool+=2;
	self.Float+=2;


	return 0;
}


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

int bibliotheque_epo__calcul_debit(void)
{
	if (exec_term_node(self_num)) {

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

		calcul_debit_unite = self.Float+0;
		calcul_debit_debitMax = self.Float+1;
		calcul_debit_debitEnHeure = self.Bool+0;
		calcul_debit_debitEnMinute = self.Bool+1;

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

		/*no Pre-conditions*/

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

		{
			/* -----------------------------------------------------------------	*/
			/* Type : Modèle de Comportement Opératif					*/
			/* Catégorie :  Preactionneurs - batch					*/
			/* Auteur : Techniques Nouvelles d'Informatique				*/
			/* Date de révision : Octobre 2002						*/
			/* -----------------------------------------------------------------	*/
			/* Calcul du debit en litre / min 						*/
			/* Ce module se positionne en entrée de circuit (ou sortie de cuve)	*/
			/* -----------------------------------------------------------------	*/

			if (debitEnHeure) unite = 3600.0;
			else if (debitEnMinute) unite = 60.0;
				else unite = 1.0;

			debitSortie = (debitMax * CLOCK_PERIOD / 1000000) / unite;

			if (debitEntree < debitSortie)
				debitSortie = debitEntree;

		}

		CB_post_float(calcul_debit_debitSortie);

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

		/*no Post-conditions*/
	}

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

	self.Bool += 2;
	self.Float += 2;

	return 0;
}

