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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/* Classic Ladder Project */
/* Copyright (C) 2001-2007 Marc Le Douarain */
/* http://membres.lycos.fr/mavati/classicladder/ */
/* http://www.sourceforge.net/projects/classicladder */
/* October 2002 */
/* ---------------------------------- */
/* Sequential language - Refresh page */
/* ---------------------------------- */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef MODULE
#include <linux/string.h>
#else
#include <stdio.h>
#include <string.h>
#endif
#include "classicladder.h"
#include "global.h"
#include "vars_access.h"
#include "calc_sequential.h"
void InitSequential( void )
{
int NumStep;
int NumTrans;
int NumSwitch;
int NumSeqComment;
for( NumStep=0; NumStep<NBR_STEPS; NumStep++ )
{
Sequential->Step[ NumStep ].InitStep = FALSE;
Sequential->Step[ NumStep ].StepNumber = 0;
Sequential->Step[ NumStep ].NumPage = -1;
Sequential->Step[ NumStep ].PosiX = 0;
Sequential->Step[ NumStep ].PosiY = 0;
Sequential->Step[ NumStep ].Activated = FALSE;
Sequential->Step[ NumStep ].TimeActivated = 0;
Sequential->Step[ NumStep ].OffDrawCrossStep = 0;
}
for( NumTrans=0; NumTrans<NBR_TRANSITIONS; NumTrans++ )
{
Sequential->Transition[ NumTrans ].VarTypeCondi = 0;
Sequential->Transition[ NumTrans ].VarNumCondi = 0;
for( NumSwitch=0; NumSwitch<NBR_SWITCHS_MAX; NumSwitch++ )
{
Sequential->Transition[ NumTrans ].NumStepToActiv[ NumSwitch ] = -1;
Sequential->Transition[ NumTrans ].NumStepToDesactiv[ NumSwitch ] = -1;
Sequential->Transition[ NumTrans ].NumTransLinkedForStart[ NumSwitch ] = -1;
Sequential->Transition[ NumTrans ].NumTransLinkedForEnd[ NumSwitch ] = -1;
}
Sequential->Transition[ NumTrans ].NumPage = -1;
Sequential->Transition[ NumTrans ].PosiX = 0;
Sequential->Transition[ NumTrans ].PosiY = 0;
Sequential->Transition[ NumTrans ].Activated = FALSE;
}
for( NumSeqComment=0; NumSeqComment<NBR_SEQ_COMMENTS; NumSeqComment++ )
{
Sequential->SeqComment[ NumSeqComment ].NumPage = -1;
Sequential->SeqComment[ NumSeqComment ].PosiX = 0;
Sequential->SeqComment[ NumSeqComment ].PosiY = 0;
Sequential->SeqComment[ NumSeqComment ].Comment[ 0 ] = '\0';
}
}
/* set active all the init steps (called at start and after modification with the editor) */
void PrepareSequential( void )
{
int NumStep,NumTrans;
for( NumStep=0; NumStep<NBR_STEPS; NumStep++ )
{
Sequential->Step[ NumStep ].Activated = FALSE;
Sequential->Step[ NumStep ].TimeActivated = 0;
if ( Sequential->Step[ NumStep ].InitStep )
Sequential->Step[ NumStep ].Activated = TRUE;
}
for( NumTrans=0; NumTrans<NBR_TRANSITIONS; NumTrans++ )
Sequential->Transition[ NumTrans ].Activated = FALSE;
}
int RefreshTransi( StrTransition * pTransi )
{
int HasChanged = FALSE;
pTransi->Activated = ReadVar( pTransi->VarTypeCondi, pTransi->VarNumCondi );
/* Condi associated true ? */
if ( pTransi->Activated )
{
int AllStepsOn = TRUE;
int ScanStep = 0;
/* Steps to desactivate are activated ? */
while( ScanStep<NBR_SWITCHS_MAX && pTransi->NumStepToDesactiv[ ScanStep ]!=-1 && AllStepsOn )
{
if ( !Sequential->Step[ pTransi->NumStepToDesactiv[ ScanStep ] ].Activated )
AllStepsOn = FALSE;
ScanStep++;
}
/* Transition is on ? */
if ( AllStepsOn )
{
HasChanged = TRUE;
/* Reset all the steps to desactivate */
ScanStep = 0;
while( ScanStep<NBR_SWITCHS_MAX && pTransi->NumStepToDesactiv[ ScanStep ]!=-1 )
{
Sequential->Step[ pTransi->NumStepToDesactiv[ ScanStep ] ].Activated = FALSE;
ScanStep++;
}
/* Set all the steps to activate */
ScanStep = 0;
while( ScanStep<NBR_SWITCHS_MAX && pTransi->NumStepToActiv[ ScanStep ]!=-1 )
{
Sequential->Step[ pTransi->NumStepToActiv[ ScanStep ] ].Activated = TRUE;
ScanStep++;
}
}
}
return HasChanged;
}
/* refresh vars of the steps (activity+time) */
void RefreshStepsVars( void )
{
int NumStep;
for( NumStep=0; NumStep<NBR_STEPS; NumStep++ )
{
if ( Sequential->Step[ NumStep ].Activated )
Sequential->Step[ NumStep ].TimeActivated += InfosGene->GeneralParams.PeriodicRefreshMilliSecs;
else
Sequential->Step[ NumStep ].TimeActivated = 0;
/* refresh the vars for the step number associated to this step */
WriteVar( VAR_STEP_ACTIVITY, Sequential->Step[ NumStep ].StepNumber, Sequential->Step[ NumStep ].Activated );
WriteVar( VAR_STEP_TIME, Sequential->Step[ NumStep ].StepNumber, Sequential->Step[ NumStep ].TimeActivated/1000 );
}
}
void RefreshSequentialPage( int PageNbr )
{
int ScanTransi;
StrTransition * pTransi;
int StateChanged;
int LoopSecurity = 0;
/* we loop here while some transitions have changed of state */
do
{
StateChanged = FALSE;
for( ScanTransi=0; ScanTransi<NBR_TRANSITIONS; ScanTransi++ )
{
pTransi = &Sequential->Transition[ ScanTransi ];
/* transition for the page under refresh ? */
if( pTransi->NumPage==PageNbr )
{
if ( RefreshTransi( pTransi ) )
StateChanged = TRUE;
}
}
LoopSecurity++;
}
while( StateChanged && LoopSecurity<50 );
RefreshStepsVars( );
}
|