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:, vehicle_type:) ⇒ SignalPriority

Returns a new instance of SignalPriority.



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

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.



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

def age
  @age
end

#etaObject (readonly)

Returns the value of attribute eta.



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

def eta
  @eta
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#updatedObject (readonly)

Returns the value of attribute updated.



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

def updated
  @updated
end

#vehicle_typeObject (readonly)

Returns the value of attribute vehicle_type.



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

def vehicle_type
  @vehicle_type
end

Instance Method Details

#cancelObject



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

def cancel
  return unless @state == 'activated'

  self.state = 'completed'
end

#prune?Boolean

Returns:

  • (Boolean)


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

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

#timerObject



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

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