-
Notifications
You must be signed in to change notification settings - Fork 0
/
PumpSystem.thingml
113 lines (111 loc) · 2.44 KB
/
PumpSystem.thingml
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
import "./Sensor.thingml"
import "./Pump.thingml"
import "./_Datatypes.thingml"
thing PumpSystem includes TimerMsgs, SensorMsgs, PumpMsgs {
// Sensor ports
required port sbcb {
receives read_value
}
required port sbca {
receives read_value
}
required port sacb {
receives read_value
}
required port saca {
receives read_value
}
// Pump port
required port pump {
sends pump_state
}
property sbcb: UInt8 = 0
property sacb: UInt8 = 0
property sbca: UInt8 = 0
property saca: UInt8 = 0
property sensorUpdated: Boolean = false
property pumpIsOn : Boolean = false
property isEmptying : Boolean = false
function updatePump() : Boolean do
var isOn : Boolean = pumpIsOn
if (not isOn) do
if(sbcb == 1 and sacb == 1 and saca == 0 and not isEmptying) do
isOn = true
end
else do
isOn = false
end
end
else do
if (sbcb == 1 and saca == 0)
isOn = true
else isOn = false
end
return isOn
end
statechart PumpSystem init LISTENING {
state LISTENING {
internal
event e: sbcb?read_value
action do
sbcb = e.val
sensorUpdated = true
end
internal
event e: sacb?read_value
action do
sacb = e.val
sensorUpdated = true
end
internal
event e: sbca?read_value
action do
if (sbca == 1 and e.val == 0)
isEmptying = false
sbca = e.val
sensorUpdated = true
end
internal
event e: saca?read_value
action do
if (sbca == 1 and saca == 1 and e.val == 0)
isEmptying = true
saca = e.val
sensorUpdated = true
end
transition -> UPDATING
guard (sensorUpdated)
}
state UPDATING {
on entry do
pumpIsOn = updatePump()
pump!pump_state(pumpIsOn)
sensorUpdated = false
end
transition -> LISTENING
}
}
}
protocol Timer;
configuration PumpSystem {
instance pumpSystem : PumpSystem
instance pump : Pump
set pump.PIN = 6
instance sbcb : Sensor
set sbcb.PIN = 2
instance sacb : Sensor
set sacb.PIN = 3
instance sbca : Sensor
set sbca.PIN = 4
instance saca : Sensor
set saca.PIN = 5
connector pumpSystem.sbcb => sbcb.ctrl
connector pumpSystem.sacb => sacb.ctrl
connector pumpSystem.sbca => sbca.ctrl
connector pumpSystem.saca => saca.ctrl
connector pumpSystem.pump => pump.notify
connector sbcb.clock over Timer
connector sacb.clock over Timer
connector sbca.clock over Timer
connector saca.clock over Timer
}