-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathLoopDistributedCentralized.lf
48 lines (42 loc) · 1.2 KB
/
LoopDistributedCentralized.lf
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
/**
* This tests a feedback loop with physical actions and centralized coordination.
*
* @author Edward A. Lee
*/
target C {
coordination: centralized,
coordination-options: {
advance-message-interval: 100 msec
},
timeout: 4 sec,
logging: DEBUG
}
reactor Looper(incr: int = 1, delay: time = 0 msec) {
input in: int
output out: int
physical action a(delay)
state count: int = 0
timer t(0, 1 sec)
reaction(t) -> out {=
lf_set(out, self->count);
self->count += self->incr;
=}
reaction(in) {=
instant_t time_lag = lf_time_physical() - lf_time_logical();
char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807
lf_comma_separated_time(time_buffer, time_lag);
lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer);
=}
reaction(shutdown) {=
lf_print("******* Shutdown invoked.");
if (self->count != 5 * self->incr) {
lf_print_error_and_exit("Failed to receive all five expected inputs.");
}
=}
}
federated reactor LoopDistributedCentralized(delay: time = 0) {
left = new Looper()
right = new Looper(incr=-1)
left.out -> right.in
right.out -> left.in
}