Skip to content

Commit

Permalink
Merge pull request #12 from loupeteam/feature/StandardizeInternals
Browse files Browse the repository at this point in the history
Feature/standardize internals
  • Loading branch information
shanereetz authored Feb 17, 2024
2 parents a24c885 + ef7c3d2 commit dd3851f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_status : PLCopenStatusBase;
_remote : IPLCopenCall;
_nullRemote : PLCopenNullRemote;
_commandGroups : ARRAY[0..GVL.MAX_RELATED_GROUPS] OF IPLCopenGroup;
_commandGroups : ARRAY[0..GVLTcCommando.MAX_RELATED_GROUPS] OF IPLCopenGroup;
END_STRUCT
END_TYPE
]]></Declaration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
_isError : BOOL;
_statusChecked : BOOL;
_numberActiveCommands : INT;
_commands : ARRAY[0..GVL.MAX_RELATED_GROUPS] OF PLCopenCall;
_commands : ARRAY[0..GVLTcCommando.MAX_RELATED_GROUPS] OF PLCopenCall;
_syncAbort : BOOL;
_syncError : BOOL;
_syncDone : BOOL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<GVL Name="GVL" Id="{1c792e27-feb4-0b48-1cf6-c8147134d538}">
<GVL Name="GVLTcCommando" Id="{1c792e27-feb4-0b48-1cf6-c8147134d538}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL
END_VAR
Expand Down
83 changes: 40 additions & 43 deletions TcCommando/TcCommando/TcCommando/POUs/PLCOpenCall.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ VAR_OUTPUT
CommandAborted : BOOL;
END_VAR
VAR
i_PLCopenCallInternal : PLCopenCallInternal;
END_VAR
VAR CONSTANT
MAX_RELATED_GROUPS : USINT := 19; // TODO evaluate this
_PLCopenCallInternal : PLCopenCallInternal;
END_VAR
]]></Declaration>
<Implementation>
Expand All @@ -34,7 +31,7 @@ Call();]]></ST>
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
i_PLCopenCallInternal._abort := true;]]></ST>
_PLCopenCallInternal._abort := true;]]></ST>
</Implementation>
</Method>
<Method Name="Call" Id="{678db6c7-a95b-4103-a6a7-438e03861a08}" FolderPath="internal\">
Expand All @@ -47,29 +44,29 @@ END_VAR]]></Declaration>
//Capture edges
IF NOT Execute THEN
i_PLCopenCallInternal._execute := FALSE;
_PLCopenCallInternal._execute := FALSE;
END_IF
// Start a new command on edge
IF (Execute AND NOT i_PLCopenCallInternal._execute) THEN
i_PLCopenCallInternal._execute := TRUE;
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_NEW_COMMAND;
IF (Execute AND NOT _PLCopenCallInternal._execute) THEN
_PLCopenCallInternal._execute := TRUE;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_NEW_COMMAND;
END_IF
// If this call get aborted, handle it
IF (i_PLCopenCallInternal._abort) THEN
i_PLCopenCallInternal._abort := 0;
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_ABORTED;
IF (_PLCopenCallInternal._abort) THEN
_PLCopenCallInternal._abort := 0;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_ABORTED;
END_IF
i_PLCopenCallInternal._self := THIS^;
_PLCopenCallInternal._self := THIS^;
// Use a "while not break" to enable multiple passes on the state machine,
// to do as much as possible in a single call
_break := FALSE;
WHILE _break = FALSE DO
CASE (i_PLCopenCallInternal._state) OF
CASE (_PLCopenCallInternal._state) OF
// IDLE
PLCopenCallState.PLCOPEN_FUB_IDLE:
Expand All @@ -83,7 +80,7 @@ WHILE _break = FALSE DO
// Start a new command
PLCopenCallState.PLCOPEN_FUB_NEW_COMMAND:
Status := PLCopenStatusBase.BUSY;
i_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.BUSY;
_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.BUSY;
Busy := TRUE;
Done := FALSE;
Error := FALSE;
Expand All @@ -93,49 +90,49 @@ WHILE _break = FALSE DO
// 1. don't need feedback (TODO why? because it is being aborted?)
// 2. this call doesn't get the abort
// so remove this FUB before calling abort previous
IF i_PLCopenCallInternal._Command <> 0 THEN
IF i_PLCopenCallInternal._Command.Remote = i_PLCopenCallInternal._self THEN
i_PLCopenCallInternal._Command.Remote := 0;
IF _PLCopenCallInternal._Command <> 0 THEN
IF _PLCopenCallInternal._Command.Remote = _PLCopenCallInternal._self THEN
_PLCopenCallInternal._Command.Remote := 0;
END_IF
END_IF
// Get the new command
i_PLCopenCallInternal._command := Command;
_PLCopenCallInternal._command := Command;
IF i_PLCopenCallInternal._Command <> 0 THEN
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_ABORT_OLD;
IF _PLCopenCallInternal._Command <> 0 THEN
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_ABORT_OLD;
// No _break
ELSE
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_WORKING;
i_PLCopenCallInternal._RemoteStatus := Fallback;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_WORKING;
_PLCopenCallInternal._RemoteStatus := Fallback;
_break := TRUE;
END_IF
// No _break
// Abort any commands that were active using the same PLCopen state
PLCopenCallState.PLCOPEN_FUB_ABORT_OLD:
i_PLCopenCallInternal._Command.AbortPreviousCommands(i_PLCopenCallInternal._Command);
_PLCopenCallInternal._Command.AbortPreviousCommands(_PLCopenCallInternal._Command);
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_SET_COMMAND;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_SET_COMMAND;
//no break;
// Start the command
PLCopenCallState.PLCOPEN_FUB_SET_COMMAND:
i_PLCopenCallInternal._Command.Execute := TRUE;
i_PLCopenCallInternal._Command.Remote := THIS^;
_PLCopenCallInternal._Command.Execute := TRUE;
_PLCopenCallInternal._Command.Remote := THIS^;
Busy := TRUE;
i_PLCOpenCallInternal._state := PLCOpenCallState.PLCOPEN_FUB_WORKING;
_PLCopenCallInternal._state := PLCOpenCallState.PLCOPEN_FUB_WORKING;
// No _break
//Wait for the command to be finished
PLCopenCallState.PLCOPEN_FUB_WORKING:
Busy := TRUE;
// No _break
IF (i_PLCopenCallInternal._RemoteStatus <> PLCopenStatusBase.BUSY AND
i_PLCopenCallInternal._RemoteStatus <> PLCopenStatusBase.ENABLED_WAITING) THEN
Status := i_PLCopenCallInternal._RemoteStatus;
IF (_PLCopenCallInternal._RemoteStatus <> PLCopenStatusBase.BUSY AND
_PLCopenCallInternal._RemoteStatus <> PLCopenStatusBase.ENABLED_WAITING) THEN
Status := _PLCopenCallInternal._RemoteStatus;
Busy := FALSE;
IF (Status = 0) THEN
Expand All @@ -145,27 +142,27 @@ WHILE _break = FALSE DO
Error := TRUE;
END_IF
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_CLEANUP;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_CLEANUP;
// No _break
ELSE
_break := TRUE;
END_IF
PLCopenCallState.PLCOPEN_FUB_CLEANUP:
// Remove self from the source command
IF i_PLCopenCallInternal._Command <> 0 THEN
i_PLCopenCallInternal._Command.Remote := 0;
i_PLCopenCallInternal._Command := 0;
IF _PLCopenCallInternal._Command <> 0 THEN
_PLCopenCallInternal._Command.Remote := 0;
_PLCopenCallInternal._Command := 0;
END_IF
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_DONE;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_DONE;
// Break to force at least 1 cycle with statuses
_break := TRUE;
PLCopenCallState.PLCOPEN_FUB_DONE:
IF (NOT Execute) THEN
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_IDLE;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_IDLE;
Status := PLCopenStatusBase.NOT_ENABLED;
Busy := FALSE;
Done := FALSE;
Expand All @@ -181,8 +178,8 @@ WHILE _break = FALSE DO
Done := FALSE;
Error := FALSE;
CommandAborted := TRUE;
i_PLCopenCallInternal._command := 0;
i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_DONE;
_PLCopenCallInternal._command := 0;
_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_DONE;
_break := TRUE;
END_CASE
Expand All @@ -196,7 +193,7 @@ END_WHILE]]></ST>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
THIS^.Execute := FALSE;
THIS^.i_PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_CLEANUP;
THIS^._PLCopenCallInternal._state := PLCopenCallState.PLCOPEN_FUB_CLEANUP;
//One call to cleanup
THIS^.Call();
//Second call to clear
Expand All @@ -219,10 +216,10 @@ CASE ID OF
PLCopenStatusBase.BUSY,
PLCopenStatusBase.ENABLED_WAITING,
PLCopenStatusBase.ERR_OK:
i_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.ERROR;
_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.ERROR;
ELSE
//Any other status can be passed through
i_PLCopenCallInternal._RemoteStatus := ID;
_PLCopenCallInternal._RemoteStatus := ID;
END_CASE]]></ST>
</Implementation>
</Method>
Expand Down Expand Up @@ -253,7 +250,7 @@ Exec := THIS^.Status;]]></ST>
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
i_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.ERR_OK;
_PLCopenCallInternal._RemoteStatus := PLCopenStatusBase.ERR_OK;
]]></ST>
</Implementation>
</Method>
Expand Down
64 changes: 32 additions & 32 deletions TcCommando/TcCommando/TcCommando/POUs/PLCOpenCallGroup.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ END_VAR
VAR_OUTPUT
END_VAR
VAR
i_callgroup : PLCopenCallGroupType;
_callGroup : PLCopenCallGroupType;
END_VAR
]]></Declaration>
<Implementation>
Expand All @@ -22,7 +22,7 @@ END_VAR
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
i_callgroup._syncAbort := TRUE;]]></ST>
_callGroup._syncAbort := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="CheckStatus" Id="{69b5b758-9323-4002-906a-f59304b6dbf8}">
Expand All @@ -37,32 +37,32 @@ END_VAR]]></Declaration>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
//If it's not in the list
FOR _commandIndex := 0 TO GVL.MAX_RELATED_GROUPS DO
IF i_callgroup._commands[_commandIndex].Command <> 0 THEN
i_callgroup._commands[_commandIndex]();
FOR _commandIndex := 0 TO GVLTcCommando.MAX_RELATED_GROUPS DO
IF _callGroup._commands[_commandIndex].Command <> 0 THEN
_callGroup._commands[_commandIndex]();
IF i_callgroup._commands[_commandIndex].CommandAborted THEN
IF _callGroup._commands[_commandIndex].CommandAborted THEN
_anyAbort := TRUE;
ELSIF i_callgroup._commands[_commandIndex].Error THEN
ELSIF _callGroup._commands[_commandIndex].Error THEN
_anyError := TRUE;
ELSIF i_callgroup._commands[_commandIndex].Busy THEN
ELSIF _callGroup._commands[_commandIndex].Busy THEN
_anyBusy := TRUE;
ELSE
i_callgroup._commands[_commandIndex].Command := 0;
_callGroup._commands[_commandIndex].Command := 0;
END_IF
END_IF
END_FOR
i_callgroup._isError := FALSE;
i_callgroup._isAbort := FALSE;
i_callgroup._isDone := FALSE;
_callGroup._isError := FALSE;
_callGroup._isAbort := FALSE;
_callGroup._isDone := FALSE;
IF _anyError OR i_callgroup._syncError THEN
i_callgroup._isError := TRUE;
ELSIF _anyAbort OR i_callgroup._syncAbort THEN
i_callgroup._isAbort := TRUE;
IF _anyError OR _callGroup._syncError THEN
_callGroup._isError := TRUE;
ELSIF _anyAbort OR _callGroup._syncAbort THEN
_callGroup._isAbort := TRUE;
ELSIF NOT _anyBusy THEN
i_callgroup._isDone := TRUE;
_callGroup._isDone := TRUE;
END_IF
]]></ST>
</Implementation>
Expand All @@ -76,7 +76,7 @@ END_VAR
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
i_callgroup._syncError := TRUE;]]></ST>
_callGroup._syncError := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="Finished" Id="{a2282568-2a57-49ba-abc9-a320ea291002}" FolderPath="PLCopenCaller\">
Expand All @@ -85,7 +85,7 @@ i_callgroup._syncError := TRUE;]]></ST>
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
i_callgroup._syncDone := TRUE;]]></ST>
_callGroup._syncDone := TRUE;]]></ST>
</Implementation>
</Method>
<Property Name="IsAbort" Id="{96e569b0-457f-4c6e-bec1-643c895a8b9c}">
Expand All @@ -98,7 +98,7 @@ END_VAR
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
CheckStatus();
IsAbort := i_callgroup._isAbort;]]></ST>
IsAbort := _callGroup._isAbort;]]></ST>
</Implementation>
</Get>
</Property>
Expand All @@ -112,7 +112,7 @@ IsAbort := i_callgroup._isAbort;]]></ST>
CheckStatus();
//Check if we are done
IsDone := i_callgroup._isDone;]]></ST>
IsDone := _callGroup._isDone;]]></ST>
</Implementation>
</Get>
</Property>
Expand All @@ -127,7 +127,7 @@ END_VAR
CheckStatus();
IsError := i_callgroup._isError;]]></ST>
IsError := _callGroup._isError;]]></ST>
</Implementation>
</Get>
</Property>
Expand All @@ -153,8 +153,8 @@ END_VAR]]></Declaration>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
//If it's not in the list
FOR _commandIndex := 0 TO GVL.MAX_RELATED_GROUPS DO
i_callgroup._commands[_commandIndex].Clear();
FOR _commandIndex := 0 TO GVLTcCommando.MAX_RELATED_GROUPS DO
_callGroup._commands[_commandIndex].Clear();
END_FOR
]]></ST>
</Implementation>
Expand All @@ -170,19 +170,19 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Copyright (c) 2024 Loupe (https://loupe.team), provided under the MIT License.
//Check if it's already in the list
FOR _commandIndex := 0 TO GVL.MAX_RELATED_GROUPS DO
IF i_callgroup._commands[_commandIndex].Command = Command THEN
i_callgroup._commands[_commandIndex].Exec(Command);
// Check if it's already in the list
FOR _commandIndex := 0 TO GVLTcCommando.MAX_RELATED_GROUPS DO
IF _callGroup._commands[_commandIndex].Command = Command THEN
_callGroup._commands[_commandIndex].Exec(Command);
Start := TRUE;
RETURN;
END_IF
END_FOR
//If it's not in the list
FOR _commandIndex := 0 TO GVL.MAX_RELATED_GROUPS DO
IF i_callgroup._commands[_commandIndex].Command = 0 THEN
i_callgroup._commands[_commandIndex].Exec(Command);
// If it's not in the list
FOR _commandIndex := 0 TO GVLTcCommando.MAX_RELATED_GROUPS DO
IF _callGroup._commands[_commandIndex].Command = 0 THEN
_callGroup._commands[_commandIndex].Exec(Command);
Start := TRUE;
RETURN;
END_IF
Expand Down
Loading

0 comments on commit dd3851f

Please sign in to comment.