-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarDiagStateTrace.st
91 lines (80 loc) · 4.67 KB
/
StarDiagStateTrace.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
FUNCTION_BLOCK slStarDiagStateTrace
CASE Internal.State OF
slSTAR_DIAG_STATE_IDLE:
IF Enable THEN
Busy := 1;
IF Handle = 0 THEN
Error := 1;
ErrorID := slERR_INVALID_HANDLE;
Internal.State := slSTAR_DIAG_STATE_ERROR;
ELSE
Internal.Handle := Handle;
StarInternal ACCESS Internal.Handle;
IF StarInternal.TypeID <> slSTAR_INTERNAL_TYPE_ID THEN
Error := 1;
ErrorID := slERR_INVALID_HANDLE;
Internal.State := slSTAR_DIAG_STATE_ERROR;
ELSE
brsmemset(ADR(StateData), 0, SIZEOF(StateData));
StateData.StarSync.State[0] := StarInternal.State;
StateData.StarRecovery.State[0] := StarInternal.Recovery.Internal.State;
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
StateData.StarPocket[Internal.i].State[0] := StarInternal.PocketSync[Internal.i].Internal.State;
StateData.StarCalc[Internal.i].State[0] := StarInternal.PocketSync[Internal.i].Internal.StarCalcTarget.Internal.State;
END_FOR
Valid := 1;
Internal.State := slSTAR_DIAG_STATE_RUNNING;
END_IF
END_IF
END_IF
slSTAR_DIAG_STATE_RUNNING:
StarInternal ACCESS Internal.Handle;
IF Enable THEN
//Get the star sync state
IF StarInternal.State <> StateData.StarSync.State[StateData.StarSync.LastIndex] THEN
StateData.StarSync.LastIndex := StateData.StarSync.LastIndex + 1;
IF StateData.StarSync.LastIndex > slMAX_STATE_TRACE_IDX THEN
StateData.StarSync.LastIndex := 0;
END_IF
StateData.StarSync.State[StateData.StarSync.LastIndex] := StarInternal.State;
END_IF
//Get the star recovery state
IF StarInternal.Recovery.Internal.State <> StateData.StarRecovery.State[StateData.StarRecovery.LastIndex] THEN
StateData.StarRecovery.LastIndex := StateData.StarRecovery.LastIndex + 1;
IF StateData.StarRecovery.LastIndex > slMAX_STATE_TRACE_IDX THEN
StateData.StarRecovery.LastIndex := 0;
END_IF
StateData.StarRecovery.State[StateData.StarRecovery.LastIndex] := StarInternal.Recovery.Internal.State;
END_IF
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
//Get the pocket state
IF StarInternal.PocketSync[Internal.i].Internal.State <> StateData.StarPocket[Internal.i].State[StateData.StarPocket[Internal.i].LastIndex] THEN
StateData.StarPocket[Internal.i].LastIndex := StateData.StarPocket[Internal.i].LastIndex + 1;
IF StateData.StarPocket[Internal.i].LastIndex > slMAX_STATE_TRACE_IDX THEN
StateData.StarPocket[Internal.i].LastIndex := 0;
END_IF
StateData.StarPocket[Internal.i].State[StateData.StarPocket[Internal.i].LastIndex] := StarInternal.PocketSync[Internal.i].Internal.State;
END_IF
//Get the calc state
IF StarInternal.PocketSync[Internal.i].Internal.StarCalcTarget.Internal.State <> StateData.StarCalc[Internal.i].State[StateData.StarCalc[Internal.i].LastIndex] THEN
StateData.StarCalc[Internal.i].LastIndex := StateData.StarCalc[Internal.i].LastIndex + 1;
IF StateData.StarCalc[Internal.i].LastIndex > slMAX_STATE_TRACE_IDX THEN
StateData.StarCalc[Internal.i].LastIndex := 0;
END_IF
StateData.StarCalc[Internal.i].State[StateData.StarCalc[Internal.i].LastIndex] := StarInternal.PocketSync[Internal.i].Internal.StarCalcTarget.Internal.State;
END_IF
END_FOR
ELSE
Valid := 0;
Busy := 0;
Internal.State := slSTAR_DIAG_STATE_IDLE;
END_IF
slSTAR_DIAG_STATE_ERROR:
IF NOT Enable THEN
Error := 0;
ErrorID := ERR_OK;
Internal.State := slSTAR_DIAG_STATE_IDLE;
Busy := 0;
END_IF
END_CASE
END_FUNCTION_BLOCK