Class: RSMP::TLC::SignalPriority

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/tlc/signal_priority.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node:, id:, level:, eta:, vehicleType:) ⇒ SignalPriority

Returns a new instance of SignalPriority.



4
5
6
7
8
9
10
11
# File 'lib/rsmp/tlc/signal_priority.rb', line 4

def initialize node:, id:, level:, eta:, vehicleType:
  @node = node
  @id = id
  @level = level
  @eta = eta
  @vehicleType = vehicleType
  set_state 'received'
end

Instance Attribute Details

#ageObject (readonly)

Returns the value of attribute age.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def age
  @age
end

#etaObject (readonly)

Returns the value of attribute eta.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def eta
  @eta
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def level
  @level
end

#nodeObject (readonly)

Returns the value of attribute node.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def node
  @node
end

#stateObject (readonly)

Returns the value of attribute state.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def state
  @state
end

#updatedObject (readonly)

Returns the value of attribute updated.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def updated
  @updated
end

#vehicleTypeObject (readonly)

Returns the value of attribute vehicleType.



2
3
4
# File 'lib/rsmp/tlc/signal_priority.rb', line 2

def vehicleType
  @vehicleType
end

Instance Method Details

#cancelObject



17
18
19
20
21
# File 'lib/rsmp/tlc/signal_priority.rb', line 17

def cancel
  if @state == 'activated'
    set_state 'completed'
  end
end

#prune?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rsmp/tlc/signal_priority.rb', line 13

def prune?
  @state == 'stale' || @state == 'completed'
end

#set_state(state) ⇒ Object



23
24
25
26
27
# File 'lib/rsmp/tlc/signal_priority.rb', line 23

def set_state state
  @state = state
  @updated = node.clock.now
  @node.signal_priority_changed self, @state
end

#timerObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rsmp/tlc/signal_priority.rb', line 29

def timer
  @age = @node.clock.now - @updated
  case @state
  when 'received'
    if @age >= 0.5
      @node.log "Priority request #{@id} activated.", level: :info
      set_state 'activated'
    end
  when 'activated'
    if @age >= 1
      @node.log "Priority request #{@id} became stale.", level: :info
      set_state 'stale'
    end
  end
end