-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempControlMixed.sysml
More file actions
249 lines (197 loc) · 9 KB
/
Copy pathTempControlMixed.sysml
File metadata and controls
249 lines (197 loc) · 9 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//@ HAMR: --platform JVM --slang-output-dir hamr/slang
package TempControlMixed {
private import HAMR::*;
language "GUMBO" /*{
library
functions
def inRange(temp: Temperature): Base_Types::Boolean :=
temp.degrees >= -40.0 [f32] and temp.degrees <= 122.0 [f32];
}*/
part def TempControlSystem :> System {
// subcomponents
part tcp: TempControlProcess;
}
part def TempControlProcess :> Process {
// subcomponents
part tempSensor : TempSensor;
part tempControl : TempControl;
part fan : Fan;
part opInterface : OperatorInterface;
// connections
connection ctTStoTC : PortConnection connect tempSensor.currentTemp to tempControl.currentTemp;
connection ctTStoOI : PortConnection connect tempSensor.currentTemp to opInterface.currentTemp;
connection tcTStoTC : PortConnection connect tempSensor.tempChanged to tempControl.tempChanged;
connection fcTCtoF : PortConnection connect tempControl.fanCmd to fan.fanCmd;
connection faFtoTC : PortConnection connect fan.fanAck to tempControl.fanAck;
connection spOItoTC : PortConnection connect opInterface.setPoint to tempControl.setPoint;
}
// TempSensor Thread
part def TempSensor :> Thread {
// features
out port currentTemp : DataPort { out :>> type : Temperature; }
out port tempChanged : EventPort;
attribute :>> Dispatch_Protocol = Supported_Dispatch_Protocols::Periodic;
attribute :>> Period = 1000 [ms];
language "GUMBO" /*{
functions
def defaultTempDegrees(): Base_Types::Float_32 := 72 [f32];
integration
guarantee Sensor_Temperature_Range:
TempControlMixed::GUMBO__Library::inRange(currentTemp);
initialize
guarantee initializes:
currentTemp.degrees == defaultTempDegrees();
}*/
}
part def TempControl :> Thread {
// features
in port currentTemp : DataPort { in :>> type : Temperature; }
in port tempChanged : EventPort;
in port fanAck : EventDataPort { in :>> type : FanAck; }
in port setPoint : EventDataPort { in :>> type : SetPoint; }
out port fanCmd : EventDataPort { out :>> type : FanCmd; }
attribute :>> Dispatch_Protocol = Supported_Dispatch_Protocols::Sporadic;
attribute :>> Period = 1000 [ms];
language "GUMBO" /*{
state
currentSetPoint: SetPoint;
currentFanState: FanCmd;
latestTemp: Temperature;
integration
assume currentTempRange:
(currentTemp.degrees >= -40.0 [f32]) & (currentTemp.degrees <= 122.0 [f32]);
initialize
modifies currentSetPoint, currentFanState, latestTemp;
guarantee defaultSetPoint:
(currentSetPoint.low.degrees == 70 [f32]) and (currentSetPoint.high.degrees == 80 [f32]);
guarantee defaultFanStates:
currentFanState == FanCmd.Off;
guarantee defaultLatestTemp:
latestTemp.degrees == 72.0[f32];
compute // behaviors for COMPUTE Entrypoint
modifies currentSetPoint, currentFanState, latestTemp;
assume
a1 "If the previously received currentTemp was less than the previously
|received setPoint then the last fan command must have been Off":
'->:'(latestTemp.degrees < currentSetPoint.low.degrees,
currentFanState == FanCmd.Off);
assume
a2 "If the previously received currentTemp was more than the previously
|received setPoint then the last fan command must have been On":
'->:'(latestTemp.degrees > currentSetPoint.high.degrees,
currentFanState == FanCmd.On);
// ---------------------------
// Compute Entry Point General Clauses
// The following contracts state properties reflecting control laws that should always
// hold no matter what incoming event triggers dispatch. Therefore, they are stated
// as independent (not associated with a handler) guarantee clauses.
// ---------------------------
guarantee TC_Req_01 "If the current temperature is less than the set point, then the fan state shall be Off.":
'->:'(latestTemp.degrees < currentSetPoint.low.degrees,
currentFanState == FanCmd.Off);
guarantee TC_Req_02 "If the current temperature is greater than the set point,
|then the fan state shall be On.":
'->:' (latestTemp.degrees > currentSetPoint.high.degrees,
currentFanState == FanCmd.On);
guarantee TC_Req_03 "If the current temperature is greater than or equal to the
|current low set point and less than or equal to the current high set point,
|then the current fan state is maintained.":
'->:'(latestTemp.degrees >= currentSetPoint.low.degrees & latestTemp.degrees <= currentSetPoint.high.degrees,
// if we are still in set point range, don't change the fan state
currentFanState == In(currentFanState));
guarantee mustSendFanCmd "If the local record of the fan state was updated,
|then send a fan command event with this updated value.":
(In(currentFanState) != currentFanState) implies MustSend(fanCmd, currentFanState) and
(currentFanState == In(currentFanState)) implies NoSend(fanCmd);
// ---------------------------
// Compute Entry Point Handler Contracts
// Handler contracts allow the compute entry point contracts to be extended with additional
// constraints that must hold for a particular handler.
//
// At the Slang level, each handler's contract is formed by conjoining the compute entry point
// general clauses with the contract clauses given in the handlers.
// For the modifies clauses, CURRENTLY, the modifies clauses must be identical to the modifies
// clause in the compute entry point general clauses. Note this means that the modifies may be
// an over-approximation -- some listed variables may actually not be modified in the handler.
// (I believe SPARK would give an error/warning if a listed variable is not written on at least
// one path, but Logika does not enforce that).
// Thus, in the current state of the tools, if a variable is not actually modified
// in the handler, an explicit frame condition must be given equating the pre- and post-state
// version of the variable.
// In the future, such frame conditions may be automatically generated.
// ---------------------------
handle setPoint:
modifies (currentSetPoint);
guarantee setPointChanged:
currentSetPoint == setPoint;
guarantee latestTempNotModified:
(latestTemp == In(latestTemp));
handle tempChanged:
modifies (latestTemp);
guarantee tempChanged:
latestTemp == currentTemp;
guarantee setPointNotModified:
currentSetPoint == In(currentSetPoint);
handle fanAck:
guarantee setPointNotModified:
currentSetPoint == In(currentSetPoint);
guarantee lastTempNotModified:
latestTemp == In(latestTemp);
guarantee currentFanState:
currentFanState == In(currentFanState);
guarantee noEventsSent:
NoSend(fanCmd);
}*/
}
part def Fan :> Thread {
// features
in port fanCmd : EventDataPort { in :>> type : FanCmd; }
out port fanAck : EventDataPort { out :>> type : FanAck; }
attribute :>> Dispatch_Protocol = Supported_Dispatch_Protocols::Periodic;
attribute :>> Period = 1000 [ms];
}
part def OperatorInterface :> Thread {
// features
in port currentTemp : DataPort { in :>> type : Temperature; }
out port setPoint : EventDataPort { out :>> type : SetPoint; }
attribute :>> Dispatch_Protocol = Supported_Dispatch_Protocols::Periodic;
attribute :>> Period = 1000 [ms];
}
// Data Types
part def Temperature :> Data {
part degrees : Base_Types::Float_32;
attribute unit : TempUnit;
language "GUMBO" /*{
// data invariant
// data invariants are assumed whenever value of the datatype is consumed
// and must be proved whenever a value of the data type is constructed
invariants
inv AbsZero:
GUMBO_Mixed_Definitions::GUMBO__Library::aboveAbsoluteZero(degrees);
}*/
}
part def SetPoint :> Data {
part low : Temperature;
part high : Temperature;
language "GUMBO" /*{
invariants
inv SetPoint_Data_Invariant:
(low.degrees >= 50 [f32]) &
(high.degrees <= 110 [f32]) &
(low.degrees <= high.degrees);
}*/
}
enum def TempUnit {
enum Fahrenheit;
enum Celsius;
enum Kelvin;
}
enum def FanCmd {
enum On;
enum Off;
}
enum def FanAck {
Ok;
Error;
}
}