[r5]: / Tags / The -Command- Pattern / Command2.project  Maximize  Restore  History

Download this file

582 lines (430 with data), 177.0 kB

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 

-------------------------------------------------------------------------------
FB_AirConComfortCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_AirConComfortCommand

VAR
    refAirConditioning: REFERENCE TO FB_AirConditioning;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refAirConditioning)) THEN
	THIS^.refAirConditioning.Activate();
	THIS^.refAirConditioning.SetTemperature(20.0);
END_IF

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refAirConditioning: REFERENCE TO FB_AirConditioning;
END_VAR
IF (__ISVALIDREF(refAirConditioning)) THEN
	THIS^.refAirConditioning REF= refAirConditioning;
ELSE
	THIS^.refAirConditioning REF= 0;
END_IF

-------------------------------------------------------------------------------
FB_LampSetLevelCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_LampSetLevelCommand

VAR
    refLamp: REFERENCE TO FB_Lamp;
    byNewLevel: BYTE;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refLamp)) THEN
	THIS^.refLamp.SetLevel(THIS^.byNewLevel);
END_IF
-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refLamp: REFERENCE TO FB_Lamp;
    byNewLevel: BYTE;
END_VAR
IF (__ISVALIDREF(refLamp)) THEN
	THIS^.refLamp REF= refLamp;
ELSE
	THIS^.refLamp REF= 0;
END_IF
THIS^.byNewLevel := byNewLevel;
-------------------------------------------------------------------------------
FB_Lamp
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_Lamp

VAR_OUTPUT
    byLevel: BYTE;
END_VAR

-------------------------------------------------------------------------------
SetLevel
-------------------------------------------------------------------------------


METHOD SetLevel: BOOL

VAR_INPUT
    byNewLevel: BYTE;
END_VAR
byLevel := byNewLevel;
-------------------------------------------------------------------------------
FB_AirConditioning
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_AirConditioning

VAR_OUTPUT
    bActive: BOOL;
    lrTemperature: LREAL;
END_VAR

-------------------------------------------------------------------------------
Activate
-------------------------------------------------------------------------------


METHOD Activate: 
bActive := TRUE;


-------------------------------------------------------------------------------
Deactivate
-------------------------------------------------------------------------------


METHOD Deactivate: 
bActive := false;
-------------------------------------------------------------------------------
SetTemperature
-------------------------------------------------------------------------------


METHOD SetTemperature: BOOL

VAR_INPUT
    lrNewTemperature: LREAL;
END_VAR
lrTemperature := lrNewTemperature;

-------------------------------------------------------------------------------
FB_MusicPlayCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_MusicPlayCommand

VAR
    refCDPlayer: REFERENCE TO FB_CDPlayer;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refCDPlayer)) THEN
	THIS^.refCDPlayer.SetVolume(40);
	THIS^.refCDPlayer.SetTrack(1);
	THIS^.refCDPlayer.Start();
END_IF

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refCDPlayer: REFERENCE TO FB_CDPlayer;
END_VAR
IF (__ISVALIDREF(refCDPlayer)) THEN
	THIS^.refCDPlayer REF= refCDPlayer;
ELSE
	THIS^.refCDPlayer REF= 0;
END_IF
-------------------------------------------------------------------------------
FB_MusicStopCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_MusicStopCommand

VAR
    refCDPlayer: REFERENCE TO FB_CDPlayer;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refCDPlayer)) THEN
	THIS^.refCDPlayer.Stop();
END_IF

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refCDPlayer: REFERENCE TO FB_CDPlayer;
END_VAR
IF (__ISVALIDREF(refCDPlayer)) THEN
	THIS^.refCDPlayer REF= refCDPlayer;
ELSE
	THIS^.refCDPlayer REF= 0;
END_IF
-------------------------------------------------------------------------------
FB_RoomOffCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_RoomOffCommand

VAR
    aiCommand: ARRAY [..] OF ;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 

VAR
    nIndex: INT;
END_VAR
FOR nIndex := 1 TO 4 DO
	IF (THIS^.aiCommand[nIndex] <> 0) THEN
		THIS^.aiCommand[nIndex].Execute();
	END_IF
END_FOR

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    iCommand01: I_Command;
    iCommand02: I_Command;
    iCommand03: I_Command;
    iCommand04: I_Command;
END_VAR
THIS^.aiCommand[1] := 0;
THIS^.aiCommand[2] := 0;
THIS^.aiCommand[3] := 0;
THIS^.aiCommand[4] := 0;
IF (iCommand01 <> 0) THEN
	THIS^.aiCommand[1] := iCommand01;
END_IF
IF (iCommand02 <> 0) THEN
	THIS^.aiCommand[2] := iCommand02;
END_IF
IF (iCommand03 <> 0) THEN
	THIS^.aiCommand[3] := iCommand03;
END_IF
IF (iCommand04 <> 0) THEN
	THIS^.aiCommand[4] := iCommand04;
END_IF


-------------------------------------------------------------------------------
FB_Socket
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_Socket

VAR_OUTPUT
    bActive: BOOL;
END_VAR

-------------------------------------------------------------------------------
Off
-------------------------------------------------------------------------------


METHOD Off: 
bActive := false;
-------------------------------------------------------------------------------
On
-------------------------------------------------------------------------------


METHOD On: 
bActive := true;
-------------------------------------------------------------------------------
FB_AirConStandbyCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_AirConStandbyCommand

VAR
    refAirConditioning: REFERENCE TO FB_AirConditioning;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refAirConditioning)) THEN
	THIS^.refAirConditioning.Activate();
	THIS^.refAirConditioning.SetTemperature(17.5);
END_IF
	
-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refAirConditioning: REFERENCE TO FB_AirConditioning;
END_VAR
IF (__ISVALIDREF(refAirConditioning)) THEN
	THIS^.refAirConditioning REF= refAirConditioning;
ELSE
	THIS^.refAirConditioning REF= 0;
END_IF
-------------------------------------------------------------------------------
FB_SocketOffCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_SocketOffCommand

VAR
    refSocket: REFERENCE TO FB_Socket;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refSocket)) THEN
	THIS^.refSocket.Off();
END_IF
-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refNewSocket: REFERENCE TO FB_Socket;
END_VAR
IF (__ISVALIDREF(refNewSocket)) THEN
	THIS^.refSocket REF= refNewSocket;
ELSE
	THIS^.refSocket REF= 0;
END_IF

-------------------------------------------------------------------------------
FB_SocketOnCommand
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_SocketOnCommand

VAR
    refSocket: REFERENCE TO FB_Socket;
END_VAR

-------------------------------------------------------------------------------
Execute
-------------------------------------------------------------------------------


METHOD Execute: 
IF (__ISVALIDREF(THIS^.refSocket)) THEN
	THIS^.refSocket.On();
END_IF

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refNewSocket: REFERENCE TO FB_Socket;
END_VAR
IF (__ISVALIDREF(refNewSocket)) THEN
	THIS^.refSocket REF= refNewSocket;
ELSE
	THIS^.refSocket REF= 0;
END_IF
-------------------------------------------------------------------------------
FB_CDPlayer
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_CDPlayer

VAR_OUTPUT
    bPlayerActive: BOOL;
    byVolume: BYTE;
    byTrack: UINT;
END_VAR

-------------------------------------------------------------------------------
SetTrack
-------------------------------------------------------------------------------


METHOD SetTrack: BOOL

VAR_INPUT
    byNewTrack: UINT;
END_VAR
byTrack := byNewTrack;
-------------------------------------------------------------------------------
SetVolume
-------------------------------------------------------------------------------


METHOD SetVolume: BOOL

VAR_INPUT
    byNewVolume: BYTE;
END_VAR
byVolume := byNewVolume;
-------------------------------------------------------------------------------
Start
-------------------------------------------------------------------------------


METHOD Start: 
bPlayerActive := true;
-------------------------------------------------------------------------------
Stop
-------------------------------------------------------------------------------


METHOD Stop: 
bPlayerActive := FALSE;
-------------------------------------------------------------------------------
FB_SwitchPanel
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_SwitchPanel

VAR_INPUT
    arrSwitch: ARRAY [..] OF ;
END_VAR

VAR
    aiCommand: ARRAY [..] OF ;
    arrRtrig: ARRAY [..] OF ;
    nIndex: INT;
END_VAR
FOR nIndex := 1 TO 8 DO
	arrRtrig[nIndex](CLK := arrSwitch[nIndex]);
	IF arrRtrig[nIndex].Q THEN
		IF (aiCommand[nIndex] <> 0) THEN
			aiCommand[nIndex].Execute();
		END_IF
	END_IF
END_FOR

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
END_VAR

VAR
    nIndex: INT;
END_VAR
FOR nIndex := 1 TO 8 DO
	aiCommand[nIndex] := 0;
END_FOR



-------------------------------------------------------------------------------
SetCommand
-------------------------------------------------------------------------------


METHOD SetCommand: BOOL

VAR_INPUT
    nPosition: INT;
    iCommand: I_Command;
END_VAR
IF ((nPosition >= 1) AND (nPosition <= 8) AND (iCommand <> 0)) THEN
	THIS^.aiCommand[nPosition] := iCommand;
END_IF

-------------------------------------------------------------------------------
MAIN
-------------------------------------------------------------------------------


PROGRAM MAIN

VAR
    fbSwitchPanel: FB_SwitchPanel;
    fbSocket: FB_Socket;
    refSocket: REFERENCE TO FB_Socket;
    fbLamp: FB_Lamp;
    refLamp: REFERENCE TO FB_Lamp;
    fbAirConditioning: FB_AirConditioning;
    refAirConditioning: REFERENCE TO FB_AirConditioning;
    fbCDPlayer: FB_CDPlayer;
    refCDPlayer: REFERENCE TO FB_CDPlayer;
    fbSocketOnCommand: FB_SocketOnCommand;
    fbSocketOffCommand: FB_SocketOffCommand;
    fbLampSetLevel100Command: FB_LampSetLevelCommand;
    fbLampSetLevel0Command: FB_LampSetLevelCommand;
    fbAirConComfortCommand: FB_AirConComfortCommand;
    fbAirConStandbyCommand: FB_AirConStandbyCommand;
    fbMusicPlayCommand: FB_MusicPlayCommand;
    fbMusicStopCommand: FB_MusicStopCommand;
    fbRoomOffCommand: FB_RoomOffCommand;
    bInit: BOOL;
END_VAR
IF bInit THEN
	fbSwitchPanel.SetCommand(1, fbSocketOnCommand);
	fbSwitchPanel.SetCommand(2, fbSocketOffCommand);
	fbSwitchPanel.SetCommand(3, fbLampSetLevel100Command);
	fbSwitchPanel.SetCommand(4, fbLampSetLevel0Command);
	fbSwitchPanel.SetCommand(5, fbAirConComfortCommand);
	fbSwitchPanel.SetCommand(6, fbAirConStandbyCommand);
	fbSwitchPanel.SetCommand(7, fbMusicPlayCommand);
	fbSwitchPanel.SetCommand(8, fbRoomOffCommand);
	bInit := FALSE;
ELSE
	fbSwitchPanel();	
END_IF