Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk 2311 integration #44

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .vs/slnx.sqlite
Binary file not shown.
1,099 changes: 704 additions & 395 deletions apax-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Library to create state machines according an OOP state pattern
type: lib
targets:
- '1500'
- 'axunit-llvm'
- 'llvm'
# URL to repository
repository:
type: git
Expand All @@ -29,7 +29,7 @@ scripts:
- apax pack
# Dependencies
devDependencies:
'@ax/sdk': 4.0.2
'@ax/sdk': 2311.0.1
"@simatic-ax/snippetscollection": 0.1.3
dependencies:
"@ax/system-timer": 6.0.94
Expand All @@ -43,3 +43,5 @@ files:
- 'doc'
- 'src' # ship library with source
# - 'bin/1500/' # ship library with binary
installStrategy: strict
apaxVersion: 3.1.0
3 changes: 3 additions & 0 deletions src/StateFramework/State/StateController.st
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ NAMESPACE Simatic.Ax.StateFramework
EXIT;
END_IF;
END_FOR;
ELSE
_status := StateControllerStatus#STATUS_NO_TRANSITION;
RETURN;
END_IF;
_status := StateControllerStatus#STATUS_IS_RUNNING;
// TODO action will be called after OnExit --> has to be changed
Expand Down
3 changes: 2 additions & 1 deletion src/StateFramework/State/StateControllerStatus.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ NAMESPACE Simatic.Ax.StateFramework
STATUS_IS_RUNNING := WORD#16#7001,
STATUS_STATE_CHANGED := WORD#16#7002,
STATUS_NO_INITIALSTATE := WORD#16#8100,
STATUS_NO_NEXTSTATE := WORD#16#8101
STATUS_NO_NEXTSTATE := WORD#16#8101,
STATUS_NO_TRANSITION := WORD#16#8102
) := STATUS_NO_ERR;
END_TYPE
END_NAMESPACE
8 changes: 1 addition & 7 deletions test/Assert.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
USING Simatic.Ax.Stateframework;

NAMESPACE AxUnit.Assert
FUNCTION Equal
VAR_INPUT
expected: StateControllerStatus;
actual: StateControllerStatus;
END_VAR
Equal(expected := TRUE, actual := expected = actual);
END_FUNCTION


FUNCTION Equal
VAR_INPUT
Expand Down
42 changes: 42 additions & 0 deletions test/StateControllerStatusAssert.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
USING Simatic.Ax.StateFramework;
USING AxUnit.ResultFunctions;
USING System.Strings;

NAMESPACE AxUnit.Assert
FUNCTION PUBLIC Equal2
VAR_INPUT
expected : StateControllerStatus;
actual : StateControllerStatus;
{CallerFilePath}
file : WSTRING[1024];
{CallerLineNumber}
line : INT;
END_VAR

IF actual = expected THEN
axunit_Succeed();
ELSE
;
axunit_Fail(Concat('Expected ', ToString(expected), ', but found ', ToString(actual)), file, line);
END_IF;

END_FUNCTION

FUNCTION INTERNAL ToString : STRING
VAR_INPUT
actual : StateControllerStatus;
END_VAR
IF (actual = StateControllerStatus#STATUS_NO_ERR) THEN
ToString := 'STATUS_NO_ERR';
ELSIF (actual = StateControllerStatus#STATUS_IS_RUNNING) THEN
ToString := 'STATUS_IS_RUNNING';
ELSIF (actual = StateControllerStatus#STATUS_STATE_CHANGED) THEN
ToString := 'STATUS_STATE_CHANGED';
ELSIF (actual = StateControllerStatus#STATUS_NO_INITIALSTATE) THEN
ToString := 'STATUS_NO_INITIALSTATE';
ELSIF (actual = StateControllerStatus#STATUS_NO_NEXTSTATE) THEN
ToString := 'STATUS_NO_NEXTSTATE';
END_IF;
;
END_FUNCTION
END_NAMESPACE
7 changes: 7 additions & 0 deletions test/StateFramework/Guards/GuardTest.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ NAMESPACE Simatic.Ax.StateFramework.Test
CLASS CountGuardTest
VAR
_guard : Simatic.Ax.StateFramework.CountGuard;
_guardStateless : Simatic.Ax.StateFramework.CountGuard;
END_VAR

{TestSetup}
METHOD PUBLIC MyTestSetup
// Will be called before each test
_guard := _guardStateless;
END_METHOD

{Test}
METHOD PUBLIC TestCheck_Two_Times_Expect_TRUE
_guard.Count := 2;
Expand Down
10 changes: 9 additions & 1 deletion test/StateFramework/Transitions/TestState1Transition.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ NAMESPACE Simatic.Ax.StateFramework.Test
{TestFixture}
CLASS TestTransition1
VAR
state1 : State1Transition := (StateId := 99, StateName := 'blabla');
state1 : State1Transition;
state1StateLess : State1Transition := (StateId := 99, StateName := 'blabla');
trans : Transition;
END_VAR


{TestSetup}
METHOD PUBLIC MyTestSetup
// Will be called before each test
state1 := state1StateLess;
END_METHOD

{Test}
METHOD PUBLIC TransitionCount_Expect_0
Equal(expected := UINT#0, actual := state1.TransitionCount());
Expand Down
7 changes: 7 additions & 0 deletions test/StateFramework/Transitions/TestState2Transition.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ NAMESPACE Simatic.Ax.StateFramework.Test
CLASS TestTransition2
VAR
state2 : State2Transition;
state2StateLess : State2Transition;
trans1 : Transition;
trans2 : Transition;
END_VAR

{TestSetup}
METHOD PUBLIC MyTestSetup
// Will be called before each test
state2 := state2StateLess;
END_METHOD

{Test}
METHOD PUBLIC Set_no_trans_And_Expect_0
Equal(expected := UINT#0, actual := state2.TransitionCount());
Expand Down
7 changes: 7 additions & 0 deletions test/StateFramework/Transitions/TestState3Transition.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ NAMESPACE Simatic.Ax.StateFramework.Test
CLASS TestTransition3
VAR
state3 : State3Transition;
state3StateLess : State3Transition;
trans1 : Transition;
trans2 : Transition;
trans3 : Transition;
END_VAR

{TestSetup}
METHOD PUBLIC MyTestSetup
// Will be called before each test
state3 := state3StateLess;
END_METHOD

{Test}
METHOD PUBLIC Set_no_trans_And_Expect_0
Equal(expected := UINT#0, actual := state3.TransitionCount());
Expand Down
86 changes: 50 additions & 36 deletions test/StateFramework/testStateController.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,52 @@ NAMESPACE Simatic.Ax.StateFramework.TestStateController
CLASS StateControllerTest
VAR
sc : StateController;
is : InitialState := (StateName := 'Initial State');
ns : NextState1 := (StateName := 'Next State');
ls : LastState := (StateName := 'LastState');
scStateLess : StateController;
is : InitialState;
ns : NextState1;
ls : LastState;
isStateLess : InitialState := (StateName := 'Initial State');
nsStateLess : NextState1 := (StateName := 'Next State');
lsStateLess : LastState := (StateName := 'Last State');
t1 : Transition;
t2 : Transition;
t3 : Transition;
t1StateLess : Transition;
t2StateLess : Transition;
t3StateLess : Transition;
g1 : BoolGuard;
b : BOOL;
END_VAR

{TestSetup}
METHOD PUBLIC MyTestSetup
// Will be called before each test
sc := scStateLess;
is := isStateLess;
ns := nsStateLess;
ls := lsStateLess;
t1 := t1StateLess;
t2 := t2StateLess;
t3 := t3StateLess;

b := FALSE;
g1.Value := REF(b);

is.Transition1 := t1;
t1.Guard := g1;
t1.NextState := ns;

ns.Transition1 := t2;
t2.NextState := ls;
t2.Guard := g1;
sc.InitialState := is;

// ls.Transition1 := t3;

END_METHOD

{Test}
METHOD PUBLIC Test_Sc_Activate_State_1
THIS.SetupStatemachine();
sc.Execute();
Equal(expected := 'Initial State', actual := sc.GetActiveStateName());
Equal(expected := 1, actual := is.OnEntryCount);
Expand Down Expand Up @@ -50,35 +83,21 @@ NAMESPACE Simatic.Ax.StateFramework.TestStateController
;
END_METHOD



// {Test}
// METHOD PUBLIC TestNoInitialState_and_Expect_8100
// sc.Execute();
// Equal(expected := StateControllerStatus#STATUS_NO_INITIALSTATE, actual := sc.GetState());
// END_METHOD

METHOD SetupStatemachine
g1.Value := REF(b);
t1.Guard := g1;
is.Transition1 := t1;
t1.NextState := ns;

ns.Transition1 := t2;
t2.Guard := g1;

sc.InitialState := is;
END_METHOD

METHOD SetupStatemachine3States
g1.Value := REF(b);
t1.Guard := g1;

// configure initial state
is.Transition1 := t1;
t1.NextState := ns;
t1.Guard := g1;

// configure next state
ns.Transition1 := t2;
t2.NextState := ls;
t2.Guard := g1;

// configure last state
ls.Transition1 := t3;
t3.NextState := NULL;
t3.Guard := g1;
Expand All @@ -87,54 +106,49 @@ NAMESPACE Simatic.Ax.StateFramework.TestStateController
END_METHOD
{Test}
METHOD PUBLIC TestExecute_ExpectStatusRunning
THIS.SetupStatemachine();
sc.Execute();
Equal(expected := TRUE, actual := sc.GetState() = StateControllerStatus#STATUS_IS_RUNNING);
Equal2(expected := StateControllerStatus#STATUS_IS_RUNNING, actual := sc.GetState());
END_METHOD

{Test}
METHOD PUBLIC TestExecute_ChangeStateTransition_True
THIS.SetupStatemachine();
b := TRUE;
sc.Execute();
Equal(expected := TRUE, actual := sc.GetState() = StateControllerStatus#STATUS_IS_RUNNING);
Equal2(expected := StateControllerStatus#STATUS_IS_RUNNING, actual := sc.GetState());
END_METHOD


{Test}
METHOD PUBLIC TestExecute_ExpectStatus_No_NextStateRunning
THIS.SetupStatemachine();
b := TRUE;
sc.Execute(); // finalize first state
sc.Execute(); // finalize next state (switchover fails, because next state has no own next state)
Equal(expected := TRUE, actual := sc.GetState() = StateControllerStatus#STATUS_NO_NEXTSTATE);
Equal2(expected := StateControllerStatus#STATUS_IS_RUNNING, actual := sc.GetState());
sc.Execute();
Equal(expected := TRUE, actual := sc.GetState() = StateControllerStatus#STATUS_NO_NEXTSTATE);
Equal2(expected := StateControllerStatus#STATUS_NO_TRANSITION, actual := sc.GetState());
END_METHOD

{Test}
METHOD PUBLIC Restart_starts_with_the_InitialState
THIS.SetupStatemachine();
// 1. Cycle
b := TRUE; // Transition to nextState = TRUE
sc.Execute(); // finalize first state
// 2. Cycle
b := FALSE;
sc.Restart();
sc.Execute(); // finalize next state (switchover fails, because next state has no own next state)
Equal(expected := TRUE, actual := StateControllerStatus#STATUS_IS_RUNNING = sc.GetState());
Equal(expected := StateControllerStatus#STATUS_IS_RUNNING, actual := sc.GetState());
Equal(expected := 'Initial State', actual := sc.GetActiveStateName());
END_METHOD

{Test}
METHOD PUBLIC States_where_all_transitions_are_true_passed_in_two_cycles
THIS.SetupStatemachine3States();
// 1. Cycle
b := TRUE; // Transition to nextState = TRUE
sc.Execute();
sc.Execute();
Equal(expected := TRUE, actual := sc.GetState() = StateControllerStatus#STATUS_IS_RUNNING);
Equal(expected := 'LastState', actual := sc.GetActiveStateName());
Equal(expected := StateControllerStatus#STATUS_IS_RUNNING, actual := sc.GetState());
Equal(expected := 'Last State', actual := sc.GetActiveStateName());
Equal(expected := TRUE, actual := ls.GetStatus() = StateStatus#Active);
END_METHOD

Expand Down
22 changes: 22 additions & 0 deletions test/StringAssert.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
USING AxUnit.ResultFunctions;
USING System.Strings;

NAMESPACE AxUnit.Assert
FUNCTION PUBLIC Equal
VAR_INPUT
actual : String;
expected: String;
{CallerFilePath}
file : WSTRING[1024];
{CallerLineNumber}
line : INT;
END_VAR

IF actual = expected THEN
axunit_Succeed();
ELSE
axunit_Fail(Concat('Expected ', expected, ', but found ', actual), file, line);
END_IF;

END_FUNCTION
END_NAMESPACE
Loading