1
+ /*
2
+ * Copyright (c) 2023. Smart Operating Block
3
+ *
4
+ * Use of this source code is governed by an MIT-style
5
+ * license that can be found in the LICENSE file or at
6
+ * https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ /*
10
+ * This agent is responsible to handle the process of energy-saving withing the Operating Block.
11
+ * It handles the standby mode considering presences in the rooms settings environment values
12
+ * according with the values of the user configuration for the standby mode.
13
+ */
14
+
15
+ !observeOperatingBlock.
16
+ !createClock.
17
+
18
+ +!observeOperatingBlock
19
+ <- ?obtainObserver(OperatingBlockObserverId);
20
+ focus(OperatingBlockObserverId).
21
+
22
+ +!createClock
23
+ <- makeArtifact("power_saver_clock" , "cartago.tools.Clock" , [], ClockId);
24
+ focus(ClockId);
25
+ setFrequency(1 ) [aid(ClockId)]; // 1 tick per second
26
+ start [aid(ClockId)].
27
+
28
+ @no_presence
29
+ +presence(RoomId, RoomType, PresenceDetected)
30
+ : PresenceDetected == false &
31
+ nticks(CurrentMillisecond) &
32
+ minutesToStandby(RoomType, MinutesToStandby)
33
+ <- +no_presence(RoomId, RoomType, CurrentMillisecond, MinutesToStandby * 60 * 1000).
34
+
35
+ @presence [atomic]
36
+ +presence(RoomId, RoomType, PresenceDetected) : PresenceDetected == true
37
+ <- -no_presence(RoomId, RoomType, X, Y).
38
+
39
+ +tick: nticks(CurrentMillisecond)
40
+ <- !checkNeedStandbyMode(CurrentMillisecond).
41
+
42
+ +!checkNeedStandbyMode(CurrentMillisecond)
43
+ : no_presence(RoomId, RoomType, Instant, Limit) &
44
+ CurrentMillisecond - Instant > Limit
45
+ //todo: obtain configuration considering the type of the room
46
+ <- //todo: write on tuple space the configuration to reach
47
+ -no_presence(RoomId, RoomType, Instant, Limit);
48
+ !!checkNeedStandbyMode(CurrentMillisecond). // Continue to check until there are match
49
+
50
+ -!checkNeedStandbyMode(CurrentMillisecond). // No more match found
51
+
52
+ // Obtain the operating block observer
53
+ +?obtainObserver(OperatingBlockObserverId)
54
+ <- lookupArtifact("operating_block_observer" , OperatingBlockObserverId).
55
+
56
+ -?obtainObserver(OperatingBlockObserverId)
57
+ <- .wait(100);
58
+ ?obtainObserver(OperatingBlockObserverId).
59
+
60
+ { include("$jacamoJar/templates/common-cartago.asl" ) }
61
+ { include("$jacamoJar/templates/common-moise.asl" ) }
0 commit comments