Class: RSMP::TLC::SignalPriority

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

Overview

Representation of a priority request for a TLC signal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SignalPriority.



7
8
9
10
11
12
13
14
# File 'lib/rsmp/tlc/signal_priority.rb', line 7

def initialize(node:, id:, level:, eta:, vehicle_type:)
  @node = node
  @id = id
  @level = level
  @eta = eta
  @vehicle_type = vehicle_type
  self.state = 'received'
end

Instance Attribute Details

#ageObject (readonly)

Returns the value of attribute age.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def age
  @age
end

#etaObject (readonly)

Returns the value of attribute eta.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def eta
  @eta
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def level
  @level
end

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def node
  @node
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def state
  @state
end

#updatedObject (readonly)

Returns the value of attribute updated.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def updated
  @updated
end

#vehicle_typeObject (readonly)

Returns the value of attribute vehicle_type.



5
6
7
# File 'lib/rsmp/tlc/signal_priority.rb', line 5

def vehicle_type
  @vehicle_type
end

Instance Method Details

#cancelObject



20
21
22
23
24
# File 'lib/rsmp/tlc/signal_priority.rb', line 20

def cancel
  return unless @state == 'activated'

  self.state = 'completed'
end

#prune?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rsmp/tlc/signal_priority.rb', line 16

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

#timerObject



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

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