//This file was generated by the LASAL2 CodeGenerator  -- 
//Please, do not edit this file (it might be overwritten by the next generator run)
//{{LSL_DECLARATION

(*!
<Class
	Name               = "RefPosSimulation"
	Revision           = "0.0"
	GUID               = "{88DCE21E-67B9-4D47-A893-56BB2BFC3AFF}"
	RealtimeTask       = "false"
	CyclicTask         = "false"
	BackgroundTask     = "false"
	Sigmatek           = "false"
	OSInterface        = "false"
	HighPriority       = "false"
	Automatic          = "false"
	UpdateMode         = "Prescan"
	SharedCommandTable = "true"
	Objectsize         = "(284,120)">
	<Channels>
		<Server Name="Direction" GUID="{08BA06F9-D184-4626-9036-772B0307C3B5}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Server Name="RefSwitch" GUID="{1637E674-22E6-4AF2-94CE-E3D7935649AB}" Visualized="false" Initialize="false" WriteProtected="true" Retentive="false"/>
		<Client Name="Position" Required="true" Internal="false"/>
	</Channels>
</Class>
*)
RefPosSimulation : CLASS
  //Servers:
	Direction 	: SvrChCmd_DINT;
	RefSwitch 	: SvrCh_DINT;
  //Clients:
	Position 	: CltCh_DINT;
  //Variables:
		oldPos 	: DINT;
  //Functions:
	
	FUNCTION VIRTUAL GLOBAL Direction::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
	
	FUNCTION VIRTUAL GLOBAL RefSwitch::Read
		VAR_OUTPUT
			output (EAX) 	: DINT;
		END_VAR;
  //Tables:
	FUNCTION @STD
		VAR_OUTPUT
			ret_code	: CONFSTATES;
		END_VAR;
	FUNCTION GLOBAL TAB @CT_;
END_CLASS;

//}}LSL_DECLARATION


FUNCTION GLOBAL TAB RefPosSimulation::@CT_
0$UINT,
2#0100000000000010$UINT, //TY_REFPOSSIMULATION
0$UINT, 0$UINT, (SIZEOF(::RefPosSimulation))$UINT, 
2$UINT, 1$UINT, 0$UINT, 
TO_UDINT(1789609988), "RefPosSimulation", //Class
TO_UDINT(0), 0, 0$UINT, 0$UINT, //Baseclass
//Servers:
(::RefPosSimulation.Direction.pMeth)$UINT, _CH_CMD$UINT, 2#0000000000000000$UINT, TO_UDINT(2055786332), "Direction", 
(::RefPosSimulation.RefSwitch.pMeth)$UINT, _CH_SVR$UINT, 2#0000000000000000$UINT, TO_UDINT(3537427625), "RefSwitch", 
//Clients:
(::RefPosSimulation.Position.pCh)$UINT, _CH_CLT_DATA$UINT, 2#0000000000000010$UINT, TO_UDINT(2149546169), "Position", 
END_FUNCTION


#define USER_CNT_RefPosSimulation 0

TYPE
	_LSL_STD_VMETH	: STRUCT
			CmdTable	: CMDMETH;
			UserFcts	: ARRAY[0..USER_CNT_RefPosSimulation] OF ^Void;
	END_STRUCT;
END_TYPE

FUNCTION RefPosSimulation::@STD
	VAR_OUTPUT
		ret_code	: CONFSTATES;
	END_VAR
	VAR
		vmt	: _LSL_STD_VMETH;
	END_VAR

	//Command Methods
	InitCmdTable (nCmd := nSTDCMD + USER_CNT_RefPosSimulation, pCmd := #vmt.CmdTable);
	vmt.CmdTable.Read		:= #Read();
	Direction.pMeth		:= StoreCmd (pCmd := #vmt.CmdTable, SHARED);

	IF Direction.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;
	RefSwitch.pMeth			:= StoreMethod( #RefSwitch::Read(), #M_NO_F() );
	IF RefSwitch.pMeth THEN
		ret_code	:= C_OK;
	ELSE
		ret_code	:= C_OUTOF_NEAR;
		RETURN;
	END_IF;

END_FUNCTION

//{{LSL_IMPLEMENTATION


FUNCTION VIRTUAL GLOBAL RefPosSimulation::Direction::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

  Position := Position.Read();
  
  if Position = 0 then
    //RefSwitch := 1;
    Direction := 1;
  elsif Position < 0 then
    Direction := 1;
  else 
    Direction := 0;
  end_if;

  

	output := Direction;

END_FUNCTION


FUNCTION VIRTUAL GLOBAL RefPosSimulation::RefSwitch::Read
	VAR_OUTPUT
		output (EAX) 	: DINT;
	END_VAR

  Position := Position.Read();
  if (oldPos > 0) & (Position < 0)
   | (oldPos < 0) & (Position > 0)then
    RefSwitch := RefSwitch XOR 1;
  end_if;
  
  oldPos := Position;

	output := RefSwitch;

END_FUNCTION
