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

#set_state(state) ⇒ Object



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

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

#timerObject



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

def timer
  @age = @node.clock.now - @updated
  case @state
  when 'received'
    set_state 'activated' if @age >= 0.5
  when 'activated'
    set_state 'completed' if @age >= 0.5
  end
end