Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. -- Definition of a "Moore"-FSM modelling the node state
  2.  
  3. -- Apart from usual more FSM, the FSM has no clock input
  4. -- Signal setting is used as an "async"-clock:
  5. -- Every set-signal call (even to the same value) is interpreted as a clock signal
  6.  
  7. fsm = {
  8.   -- Input signals
  9.   signals = {
  10.     'internet_avail',
  11.     'boot_done'
  12.   },
  13.   -- Counters, incremted, every time a signal is set (even to the same value)
  14.   counters = {
  15.     {signal = 'internet_avail', reset_on_transition = true}
  16.   },
  17.  
  18.   states = { -- States
  19.     boot = {
  20.       onEntry = 'echo booting', -- Shell-Commands to be executed
  21.       onExit = 'echo boot done',
  22.       transitions = {
  23.         {dest = 'online',      guard = 'boot_done &&  internet_avail',  do = 'echo Going Online'},
  24.         {dest = 'offline',     guard = 'boot_done && !internet_avail'}
  25.       }
  26.     },
  27.    
  28.     online = {
  29.       onEntry = 'echo online',
  30.         transitions = {
  31.           {dest = 'offline',      guard = '!internet_avail'}
  32.         }
  33.       },
  34.       offline = {
  35.         onEntry = 'echo offline',
  36.         transitions = {
  37.           {dest = 'online',       guard = 'internet_avail'},
  38.           {dest = 'panic',        guard = '!internet_avail && count(internet_avail) > 10'},
  39.           {dest = 'online',       guard = 'internet_avail'}
  40.         }
  41.       },
  42.  
  43.       panic = {
  44.         onEntry = 'echo setup broken'
  45.       }
  46.   },
  47.   initial_state = 'boot'
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement