-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmonitor_state.lua
More file actions
44 lines (36 loc) · 1.16 KB
/
monitor_state.lua
File metadata and controls
44 lines (36 loc) · 1.16 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
--
-- simple example to illustrate the use of gen_monitor_state.
--
rfsm = require("rfsm")
rfsm_ext = require("rfsm.ext")
--- generate a function which ramdomly returns true n of m times
-- @param n
-- @param m
function gen_sometimes_true(n, m)
math.randomseed( os.time() )
return function ()
if n > math.random(0,m) then
return true
else
return false
end
end
end
-- generate a function which prints 'this'
-- @param this
function gen_print_this(this)
return function() print(this) end
end
-- a table of event=monitorfunction pairs
mon={
event_1 = gen_sometimes_true(1, 1000000),
event_5 = gen_sometimes_true(5, 1000000),
event_10 = gen_sometimes_true(10, 1000000),
}
return rfsm.csta {
monitoring = rfsm_ext.gen_monitor_state{montab=mon, break_first=true},
rfsm.trans{src='.monitoring', tgt='.monitoring', events={'event_1'}, effect=gen_print_this("event_1")},
rfsm.trans{src='.monitoring', tgt='.monitoring', events={'event_5'}, effect=gen_print_this("event_5")},
rfsm.trans{src='.monitoring', tgt='.monitoring', events={'event_10'}, effect=gen_print_this("event_10")},
rfsm.trans{src='initial', tgt='.monitoring'},
}