/********************************************************************
 * _init.c
 * 
 * generated by: plcgen 1.0.29
 * generation parameters:
 *  -L C:\ControlBuild\tooldir\embedded\nt_simu\embedded
 *  --fl iec_1131
 *  --nl
 *  -R D:\Users\Applis\ControlBuildV4\SFP_JFP
 *  sfp.manipulateur
 ********************************************************************/

#include "cb_products.h"
#include "sfp/functional/graf_mdl_manipulateur/exec/graf_mdl_manipulateur.h"
#include "sfp/functional/deplacement/exec/deplacement.h"
#include "sfp/functional/mdl_deplacement/exec/mdl_deplacement.h"
#include "sfp/functional/graf_mdl_verin_bist/exec/graf_mdl_verin_bist.h"
#include "sfp/functional/prise_pose/exec/prise_pose.h"
#include "sfp/functional/graf_mdl_prdpos/exec/graf_mdl_prdpos.h"
#include "sfp/functional/graf_mdl_verin_mono/exec/graf_mdl_verin_mono.h"
#include "sfp/functional/graf_mdl_ventouse/exec/graf_mdl_ventouse.h"
#include "sfp/functional/manipulateur/exec/manipulateur.h"

/* Low voltage specific */
int lv_iteration_step;

/* Input/output variables initialization function */
void inputOutputVariablesInit(void)
{
	manipulateur_acq = self.Bool;
	self.Bool++;
	manipulateur_au = self.Bool;
	self.Bool++;
	manipulateur_Pos_depart = self.Int;
	self.Int++;
	manipulateur_Pos_arrivee = self.Int;
	self.Int++;
	manipulateur_DCY = self.Bool;
	self.Bool++;
	manipulateur_FCGXS = self.Bool;
	self.Bool++;
	manipulateur_FCGXR = self.Bool;
	self.Bool++;
	manipulateur_FCPXS = self.Bool;
	self.Bool++;
	manipulateur_FCPXR = self.Bool;
	self.Bool++;
	manipulateur_FCVRS = self.Bool;
	self.Bool++;
	manipulateur_FCVRR = self.Bool;
	self.Bool++;
	manipulateur_FCVZH = self.Bool;
	self.Bool++;
	manipulateur_FCVZB = self.Bool;
	self.Bool++;
	manipulateur_vacuostat = self.Bool;
	self.Bool++;
	manipulateur_Def_Manip = self.Bool;
	self.Bool++;
	manipulateur_OKcycle = self.Bool;
	self.Bool++;
	manipulateur_EVGXR = self.Bool;
	self.Bool++;
	manipulateur_EVGXS = self.Bool;
	self.Bool++;
	manipulateur_EVPXR = self.Bool;
	self.Bool++;
	manipulateur_EVPXS = self.Bool;
	self.Bool++;
	manipulateur_EVVRR = self.Bool;
	self.Bool++;
	manipulateur_EVVRS = self.Bool;
	self.Bool++;
	manipulateur_EVVZ = self.Bool;
	self.Bool++;
	manipulateur_EVVTA = self.Bool;
	self.Bool++;
	manipulateur_EVVTM = self.Bool;
	self.Bool++;
}

/* Main behavior initialization function */
int behaviorsInit(void)
{
	int old_self_num = self_num;

	manipulateur__num = self_num;
	inputOutputVariablesInit();
	sfp__manipulateur_init();
	self_num = old_self_num;
	return 0;
}

/* Main behavior function */
int behaviorsStep(void)
{
	int old_self_num = self_num;
	int __ret, i;

	lv_iteration_step = 0;
	inputOutputVariablesInit();
	manipulateur__num = self_num;
	__ret = sfp__manipulateur();
	if (__ret != 0) {
		return __ret; /*execution failure*/
	}
	self_num = old_self_num;
	return 0;
}

/* Actors and products initialization */
T_ElementTableActeursProduits TableActeursProduits[] = {
	{{0, 0, 0, 0}, {0, 0, 0, 0},
	0, 0, 0, 0, {{0, 0}, {0, 0}}}
};
T_Instance NbActeurs = 0;
T_Instance NbProduits = 0;
T_Instance NbActeursEtProduits = 0;



/* Global variables initialization */
void globalesInit(void)
{
}

/* Memory sizes initialization */
void memorySizeInit(CB_Offset *minSize, CB_Offset *maxSize, CB_Offset *memSize)
{


	minSize->Bool = 0;
	minSize->Int = 0;
	minSize->Float = 0;
	minSize->Char = 0;

	maxSize->Bool = 167;
	maxSize->Int = 551;
	maxSize->Float = 17;
	maxSize->Char = 53;

	memSize->Bool = 167;
	memSize->Int = 551;
	memSize->Float = 17;
	memSize->Char = 53;
}


/* Location of memory starts*/
void memoryStartInit(CB_Object *pMem)
{
	extern int minBool, minInt, minFloat, minChar;

	pMem->Bool += minBool + 5;
	pMem->Int += minInt + 212;
	pMem->Float += minFloat + 7;
	pMem->Char += minChar + 53;
}

/* Initialization utils */
void CB_Bool_Init(char *Mem, int index, CB_Bool value)
{
	P_Bool(Mem, index)->CB_current_value = value;
	P_Bool(Mem, index)->CB_previous_value = value;
}

void CB_Int_Init(char *Mem, int index, CB_Int value)
{
	P_Int(Mem, index)->CB_current_value = value;
	P_Int(Mem, index)->CB_previous_value = value;
}

void CB_Float_Init(char *Mem, int index, CB_Float value)
{
	P_Float(Mem, index)->CB_current_value = value;
	P_Float(Mem, index)->CB_previous_value = value;
}

void CB_Char_Init(char *Mem, int index, CB_Char value)
{
	P_Char(Mem, index)->CB_current_value = value;
	P_Char(Mem, index)->CB_previous_value = value;
}

/* Variable initializations */
void variablesInitialization(void)
{
	char *Mem = (char *) memHeader;

	CB_Float_Init(Mem, 10, 50000.0); /*simuperiod*/
	CB_Int_Init(Mem, 211 + 0, 100); /*bpnoline size*/
	CB_Int_Init(Mem, 313 + 0, 100); /*bpnoinstance size*/
	CB_Char_Init(Mem, 0 + 1, 50); /*taskname size*/
	CB_Char_Init(Mem, 0 + 3, 'm');
	CB_Char_Init(Mem, 0 + 4, 'a');
	CB_Char_Init(Mem, 0 + 5, 'n');
	CB_Char_Init(Mem, 0 + 6, 'i');
	CB_Char_Init(Mem, 0 + 7, 'p');
	CB_Char_Init(Mem, 0 + 8, 'u');
	CB_Char_Init(Mem, 0 + 9, 'l');
	CB_Char_Init(Mem, 0 + 10, 'a');
	CB_Char_Init(Mem, 0 + 11, 't');
	CB_Char_Init(Mem, 0 + 12, 'e');
	CB_Char_Init(Mem, 0 + 13, 'u');
	CB_Char_Init(Mem, 0 + 14, 'r');
	CB_Char_Init(Mem, 0 + 15, '.');
	CB_Char_Init(Mem, 0 + 16, 'e');
	CB_Char_Init(Mem, 0 + 17, 'x');
	CB_Char_Init(Mem, 0 + 18, 'e');
	CB_Bool_Init(Mem, 3, 1); /*allowpreconditions*/
	CB_Bool_Init(Mem, 4, 1); /*allowpostconditions*/
	CB_Bool_Init(Mem, 59 + 0, 10); /*deplacement1/Verin_PX/defaut size*/
	CB_Int_Init(Mem, 426 + 0, 2); /*deplacement1/Verin_PX/TTL size*/
	CB_Int_Init(Mem, 430 + 0, 2); /*deplacement1/Verin_PX/Tinertie size*/
	CB_Int_Init(Mem, 434 + 0, 2); /*deplacement1/Verin_PX/t1 size*/
	CB_Int_Init(Mem, 439 + 0, 2); /*deplacement1/Verin_PX/t3 size*/
	CB_Int_Init(Mem, 444 + 0, 2); /*deplacement1/Verin_PX/t5 size*/
	CB_Int_Init(Mem, 449 + 0, 2); /*deplacement1/Verin_PX/t7 size*/
	CB_Bool_Init(Mem, 79 + 0, 10); /*deplacement1/Verin_VR/defaut size*/
	CB_Int_Init(Mem, 454 + 0, 2); /*deplacement1/Verin_VR/TTL size*/
	CB_Int_Init(Mem, 458 + 0, 2); /*deplacement1/Verin_VR/Tinertie size*/
	CB_Int_Init(Mem, 462 + 0, 2); /*deplacement1/Verin_VR/t1 size*/
	CB_Int_Init(Mem, 467 + 0, 2); /*deplacement1/Verin_VR/t3 size*/
	CB_Int_Init(Mem, 472 + 0, 2); /*deplacement1/Verin_VR/t5 size*/
	CB_Int_Init(Mem, 477 + 0, 2); /*deplacement1/Verin_VR/t7 size*/
	CB_Bool_Init(Mem, 99 + 0, 10); /*deplacement1/Verin_GX/defaut size*/
	CB_Int_Init(Mem, 482 + 0, 2); /*deplacement1/Verin_GX/TTL size*/
	CB_Int_Init(Mem, 486 + 0, 2); /*deplacement1/Verin_GX/Tinertie size*/
	CB_Int_Init(Mem, 490 + 0, 2); /*deplacement1/Verin_GX/t1 size*/
	CB_Int_Init(Mem, 495 + 0, 2); /*deplacement1/Verin_GX/t3 size*/
	CB_Int_Init(Mem, 500 + 0, 2); /*deplacement1/Verin_GX/t5 size*/
	CB_Int_Init(Mem, 505 + 0, 2); /*deplacement1/Verin_GX/t7 size*/
	CB_Int_Init(Mem, 510 + 0, 2); /*prise_pose1/graf_mdl_prdpos1/t1 size*/
	CB_Int_Init(Mem, 515 + 0, 2); /*prise_pose1/graf_mdl_prdpos1/TTL size*/
	CB_Bool_Init(Mem, 139 + 0, 10); /*prise_pose1/Verin_VZ/defaut size*/
	CB_Int_Init(Mem, 519 + 0, 2); /*prise_pose1/Verin_VZ/TTL size*/
	CB_Int_Init(Mem, 523 + 0, 2); /*prise_pose1/Verin_VZ/Tinertie size*/
	CB_Int_Init(Mem, 527 + 0, 2); /*prise_pose1/Verin_VZ/t1 size*/
	CB_Int_Init(Mem, 532 + 0, 2); /*prise_pose1/Verin_VZ/t3 size*/
	CB_Int_Init(Mem, 537 + 0, 2); /*prise_pose1/Verin_VZ/t5 size*/
	CB_Int_Init(Mem, 542 + 0, 2); /*prise_pose1/Verin_VZ/t7 size*/
}

/* Control Variables access */
void controlVariablesAccessInitialization(void)
{
	char *Mem = (char *) memHeader;
	extern CB_Mem_Bool *traceon;
	extern CB_Mem_Bool *resettrace;
	extern CB_Mem_Bool *cb_delay;
	extern CB_Mem_Bool *allowpreconditions;
	extern CB_Mem_Bool *allowpostconditions;
	extern CB_Mem_Int *execstatus;
	extern CB_Mem_Int *bpnoline;
	extern CB_Mem_Int *bpnoinstance;
	extern CB_Mem_Int *bpcurrentinstance;
	extern CB_Mem_Int *bpcurrentlocation;
	extern CB_Mem_Int *bpcurrentprepostcode;
	extern CB_Mem_Int *bpcurrenttypeerror;
	extern CB_Mem_Int *bpcurrentrank;
	extern CB_Mem_Int *signature;
	extern CB_Mem_Int *generationtime;
	extern CB_Mem_Float *simuperiod;
	extern CB_Mem_Float *maxsimuperiod;
	extern CB_Mem_Float *minsimuperiod;
	extern CB_Mem_Float *realsimuperiod;
	extern CB_Mem_Float *mxmeanvariablemodification;
	extern CB_Mem_Float *mxminvariablemodification;
	extern CB_Mem_Float *mxmaxvariablemodification;
	extern CB_Mem_Char *taskname;

	execstatus = P_Int(Mem, 210);
	simuperiod = P_Float(Mem, 10);
	minsimuperiod = P_Float(Mem, 11);
	maxsimuperiod = P_Float(Mem, 12);
	realsimuperiod = P_Float(Mem, 13);
	bpnoline = P_Int(Mem, 211);
	bpnoinstance = P_Int(Mem, 313);
	bpcurrentinstance = P_Int(Mem, 415);
	bpcurrentlocation = P_Int(Mem, 416);
	bpcurrentprepostcode = P_Int(Mem, 417);
	bpcurrenttypeerror = P_Int(Mem, 418);
	bpcurrentrank = P_Int(Mem, 419);
	signature = P_Int(Mem, 420);
	generationtime = P_Int(Mem, 421);
	taskname = P_Char(Mem, 0);
	traceon = P_Bool(Mem, 0);
	resettrace = P_Bool(Mem, 1);
	cb_delay = P_Bool(Mem, 2);
	mxmeanvariablemodification = P_Float(Mem, 14);
	mxminvariablemodification = P_Float(Mem, 15);
	mxmaxvariablemodification = P_Float(Mem, 16);
	allowpreconditions = P_Bool(Mem, 3);
	allowpostconditions = P_Bool(Mem, 4);
}

/* Time cycle initialization */
void timeCycleInitialization(CB_Mem_Float *timecycle)
{
	timecycle->CB_current_value = 50000.0;
}

/* Starting mode */
void initStartingMode(CB_Mem_Int *execstatus)
{
	execstatus->CB_current_value = mx_exec_status_stop;
}

/* Execution mode */
void initExecutionMode(CB_Mem_Bool *delay)
{
	delay->CB_current_value = 0;
}

