-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
484 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
NAMESPACE Simatic.Ax.Json | ||
|
||
CLASS INTERNAL ABSTRACT Command | ||
IMPLEMENTS IPlcOpen | ||
VAR PRIVATE | ||
_Done : BOOL; | ||
_Aborted : BOOL; | ||
_Error : BOOL; | ||
_ErrorID : WORD; | ||
END_VAR | ||
|
||
METHOD PUBLIC Busy : BOOL | ||
THIS.ExecuteIfBusy(); // execute as long it is busy | ||
Busy := THIS.IsBusy(); // check, if it is still busy | ||
END_METHOD | ||
|
||
METHOD PUBLIC Done : BOOL | ||
THIS.ExecuteIfBusy(); | ||
Done := _Done; | ||
END_METHOD | ||
|
||
METHOD PUBLIC Aborted : BOOL | ||
THIS.ExecuteIfBusy(); | ||
Aborted := _Aborted; | ||
END_METHOD | ||
|
||
METHOD PUBLIC ErrorID : WORD | ||
THIS.ExecuteIfBusy(); | ||
ErrorID := _ErrorID; | ||
END_METHOD | ||
|
||
METHOD PUBLIC Error : BOOL | ||
THIS.ExecuteIfBusy(); | ||
Error := _Error; | ||
END_METHOD | ||
|
||
METHOD PROTECTED ABSTRACT Execute | ||
END_METHOD | ||
|
||
METHOD PROTECTED InitState | ||
_Done := FALSE; | ||
_Aborted := FALSE; | ||
_Error := FALSE; | ||
_ErrorID := word#0; | ||
END_METHOD | ||
|
||
METHOD PROTECTED ExecuteIfBusy | ||
IF THIS.IsBusy() THEN | ||
THIS.Execute(); | ||
END_IF; | ||
END_METHOD | ||
|
||
METHOD PROTECTED IsBusy : BOOL | ||
IsBusy := NOT (_Done OR _Error OR _Aborted); | ||
END_METHOD | ||
|
||
METHOD PROTECTED SetDone | ||
_Done := TRUE; | ||
_Error := FALSE; | ||
_ErrorID := WORD#0000; | ||
_Aborted := FALSE; | ||
END_METHOD | ||
|
||
METHOD PROTECTED SetError | ||
VAR_INPUT | ||
ErrorID : WORD := WORD#16#0000; | ||
END_VAR | ||
_Error := TRUE; | ||
_ErrorID := ErrorID; | ||
_Done := FALSE; | ||
_Aborted := FALSE; | ||
END_METHOD | ||
|
||
METHOD PROTECTED SetAborted | ||
_Aborted := TRUE; | ||
_Error := FALSE; | ||
_Done := FALSE; | ||
_ErrorID := WORD#0000; | ||
END_METHOD | ||
END_CLASS | ||
|
||
END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
NAMESPACE Simatic.Ax.Json | ||
|
||
CLASS INTERNAL FindCharacterInArray | ||
EXTENDS Command | ||
VAR PUBLIC | ||
END_VAR | ||
VAR PROTECTED | ||
_buffer : REF_TO ARRAY[*] OF CHAR; | ||
_charToFind : CHAR; | ||
_mode : FindeMode; | ||
_index : INT; | ||
_found : BOOL; | ||
END_VAR | ||
|
||
METHOD INTERNAL Find : IPlcOpen | ||
VAR_INPUT | ||
Buffer : REF_TO ARRAY[*] OF CHAR; | ||
c : CHAR; | ||
Mode : FindeMode; | ||
END_VAR | ||
VAR_OUTPUT | ||
Index : DINT; | ||
END_VAR | ||
_buffer := Buffer; | ||
_mode := Mode; | ||
_charToFind := c; | ||
THIS.InitState(); | ||
THIS.Execute(); | ||
Find := THIS; | ||
|
||
END_METHOD | ||
|
||
METHOD PROTECTED OVERRIDE Execute | ||
VAR_TEMP | ||
index : INT; | ||
_lb, _ub : INT; | ||
END_VAR | ||
_lb := TO_INT(LOWER_BOUND(_buffer^, 1)); | ||
_ub := TO_INT(UPPER_BOUND(_buffer^, 1)); | ||
CASE _mode OF | ||
FindeMode#MODE_FORWARD: | ||
FOR index := _lb TO _ub DO | ||
IF (_buffer^[index] = _charToFind) THEN | ||
_index := index; | ||
THIS.SetDone(); | ||
EXIT; | ||
END_IF; | ||
THIS.SetError(); | ||
END_FOR; | ||
|
||
FindeMode#MODE_REVERSE: | ||
FOR index := _ub TO _lb BY -1 DO | ||
IF (_buffer^[index] = _charToFind) THEN | ||
_index := index; | ||
THIS.SetDone(); | ||
EXIT; | ||
END_IF; | ||
THIS.SetError(); | ||
END_FOR; | ||
|
||
END_CASE; | ||
END_METHOD | ||
|
||
METHOD PUBLIC GetIndex : INT | ||
GetIndex := _index; | ||
END_METHOD | ||
END_CLASS | ||
|
||
TYPE | ||
FindeMode : (MODE_FORWARD, MODE_REVERSE); | ||
END_TYPE | ||
|
||
END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
NAMESPACE Simatic.Ax.Json | ||
|
||
CLASS INTERNAL GetBufferIndizesSyncron EXTENDS Command | ||
IMPLEMENTS IGetBufferIndizes | ||
VAR | ||
_startFound : BOOL; | ||
_endFound : BOOL; | ||
_state : INT; | ||
_finder : FindCharacterInArray; | ||
_buffer : REF_TO ARRAY[*] OF CHAR; | ||
_startIndex : INT; | ||
_endIndex : INT; | ||
END_VAR | ||
VAR CONSTANT | ||
IDLE : INT := 0; | ||
FIND_START : INT := 1; | ||
FIND_END : INT := 2; | ||
EVALUATE : INT := 3; | ||
END_VAR | ||
|
||
METHOD PUBLIC Find : IPlcOpen | ||
VAR_INPUT | ||
Buffer : REF_TO ARRAY[*] OF CHAR; | ||
END_VAR | ||
_buffer := Buffer; | ||
THIS.InitState(); | ||
THIS.Execute(); | ||
Find := THIS; | ||
|
||
END_METHOD | ||
|
||
METHOD PUBLIC StartIndex : INT | ||
StartIndex := _startIndex; | ||
END_METHOD | ||
METHOD PUBLIC EndIndex : INT | ||
EndIndex := _endIndex; | ||
END_METHOD | ||
METHOD PROTECTED OVERRIDE Execute | ||
VAR_TEMP | ||
index : INT; | ||
incrementBackwards : INT := -1; | ||
_lb, _ub : INT; | ||
_cmd : IPlcOpen; | ||
END_VAR | ||
// Idle initialize all variables | ||
IF _state = IDLE THEN | ||
_lb := TO_INT(LOWER_BOUND(_buffer^, 1)); | ||
_ub := TO_INT(UPPER_BOUND(_buffer^, 1)); | ||
_state := FIND_START; | ||
_startFound := FALSE; | ||
_endFound := FALSE; | ||
END_IF; | ||
// Find start '{' | ||
IF _state = FIND_START THEN | ||
_cmd := _finder.Find(buffer := _buffer, c := '{', mode := FindeMode#MODE_FORWARD); | ||
IF (NOT _cmd.Busy()) THEN | ||
IF (_cmd.Done()) THEN | ||
_state := FIND_END; | ||
_startIndex := _finder.GetIndex(); | ||
END_IF; | ||
IF (_cmd.Error()) THEN | ||
_startIndex := 0; | ||
THIS.SetError(); | ||
_state := IDLE; | ||
END_IF; | ||
END_IF; | ||
END_IF; | ||
IF _state = FIND_END THEN | ||
// Find end '}' | ||
_cmd := _finder.Find(buffer := _buffer, c := '}', mode := FindeMode#MODE_REVERSE); | ||
IF (NOT _cmd.Busy()) THEN | ||
IF (_cmd.Done()) THEN | ||
_state := EVALUATE; | ||
_endIndex := _finder.GetIndex(); | ||
END_IF; | ||
IF (_cmd.Error()) THEN | ||
_endIndex := 0; | ||
THIS.SetError(); | ||
_state := IDLE; | ||
END_IF; | ||
END_IF; | ||
END_IF; | ||
IF _state = EVALUATE THEN | ||
IF (_startIndex > _endIndex) THEN | ||
_startIndex := 0; | ||
_endIndex := 0; | ||
_state := IDLE; | ||
THIS.SetError(); | ||
RETURN; | ||
ELSE // Done | ||
_state := IDLE; | ||
THIS.SetDone(); | ||
RETURN; | ||
END_IF; | ||
END_IF; | ||
END_METHOD | ||
END_CLASS | ||
|
||
END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAMESPACE Simatic.Ax.Json | ||
INTERFACE INTERNAL IGetBufferIndizes | ||
METHOD Find : IPlcOpen | ||
VAR_INPUT | ||
buffer : REF_TO ARRAY[*] OF CHAR; | ||
END_VAR | ||
END_METHOD | ||
METHOD StartIndex : INT END_METHOD | ||
METHOD EndIndex : INT END_METHOD | ||
END_INTERFACE | ||
END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
NAMESPACE Simatic.Ax.Json | ||
|
||
INTERFACE IPlcOpen | ||
METHOD Busy : BOOL | ||
END_METHOD | ||
METHOD Done : BOOL | ||
END_METHOD | ||
METHOD Aborted : BOOL | ||
END_METHOD | ||
METHOD Error : BOOL | ||
END_METHOD | ||
METHOD ErrorID : WORD | ||
END_METHOD | ||
END_INTERFACE | ||
|
||
END_NAMESPACE |
Oops, something went wrong.