Class: RSMP::TLC::SignalGroup

Inherits:
Component show all
Defined in:
lib/rsmp/tlc/signal_group.rb

Constant Summary

Constants inherited from ComponentBase

ComponentBase::AGGREGATED_STATUS_KEYS

Instance Attribute Summary collapse

Attributes inherited from ComponentBase

#aggregated_status, #aggregated_status_bools, #alarms, #c_id, #grouped, #node, #ntsoid, #statuses, #xnid

Instance Method Summary collapse

Methods inherited from Component

#acknowledge_alarm, #activate_alarm, #deactivate_alarm, #resume_alarm, #status_updates_sent, #suspend_alarm

Methods inherited from ComponentBase

#aggregated_status_changed, #clear_aggregated_status, #clear_alarm_timestamps, #get_alarm_state, #log, #now, #set_aggregated_status

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:) ⇒ SignalGroup

plan is a string, with each character representing a signal phase at a particular second in the cycle



7
8
9
# File 'lib/rsmp/tlc/signal_group.rb', line 7

def initialize(node:, id:)
  super(node: node, id: id, grouped: false)
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



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

def plan
  @plan
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#compute_plan_stateObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/rsmp/tlc/signal_group.rb', line 27

def compute_plan_state
  default = 'a' # phase a means disabled/dark
  plan = node.main.current_plan
  return default unless plan&.states

  states = plan.states[c_id]
  return default unless states

  state_at_cycle_position(states, node.main.cycle_counter, default)
end

#compute_stateObject



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

def compute_state
  return 'a' if node.main.dark?
  return 'c' if node.main.yellow_flash?
  return startup_state if node.main.startup_sequence.active?

  compute_plan_state
end

#get_status(code, name = nil, _options = {}) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/rsmp/tlc/signal_group.rb', line 71

def get_status(code, name = nil, _options = {})
  case code
  when 'S0025'
    send("handle_#{code.downcase}", code, name)
  else
    raise InvalidMessage, "unknown status code #{code}"
  end
end

#handle_command(command_code, arg, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/rsmp/tlc/signal_group.rb', line 46

def handle_command(command_code, arg, options = {})
  case command_code
  when 'M0010', 'M0011'
    send("handle_#{command_code.downcase}", arg, options)
  else
    raise UnknownCommand, "Unknown command #{command_code}"
  end
end

#handle_m0010(arg, _options = {}) ⇒ Object

Start of signal group. Orders a signal group to green



56
57
58
59
60
61
# File 'lib/rsmp/tlc/signal_group.rb', line 56

def handle_m0010(arg, _options = {})
  @node.verify_security_code 2, arg['securityCode']
  return unless TrafficControllerSite.from_rsmp_bool? arg['status']

  log "Start signal group #{c_id}, go to green", level: :info
end

#handle_m0011(arg, _options = {}) ⇒ Object

Stop of signal group. Orders a signal group to red



64
65
66
67
68
69
# File 'lib/rsmp/tlc/signal_group.rb', line 64

def handle_m0011(arg, _options = {})
  @node.verify_security_code 2, arg['securityCode']
  return unless TrafficControllerSite.from_rsmp_bool? arg['status']

  log "Stop signal group #{c_id}, go to red", level: :info
end

#handle_s0025(_status_code, status_name = nil, _options = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/rsmp/tlc/signal_group.rb', line 80

def handle_s0025(_status_code, status_name = nil, _options = {})
  now = @node.clock.to_s
  case status_name
  when 'minToGEstimate', 'maxToGEstimate', 'likelyToGEstimate',
       'minToREstimate', 'maxToREstimate', 'likelyToREstimate'
    TrafficControllerSite.make_status now
  when 'ToGConfidence', 'ToRConfidence'
    TrafficControllerSite.make_status 0
  end
end

#startup_stateObject



23
24
25
# File 'lib/rsmp/tlc/signal_group.rb', line 23

def startup_state
  node.main.startup_state || 'a'
end

#state_at_cycle_position(states, cycle_counter, default) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rsmp/tlc/signal_group.rb', line 38

def state_at_cycle_position(states, cycle_counter, default)
  counter = [cycle_counter, states.length - 1].min
  state = states[counter]
  return default unless state =~ /[a-hA-G0-9N-P]/ # valid signal group states

  state
end

#timerObject



11
12
13
# File 'lib/rsmp/tlc/signal_group.rb', line 11

def timer
  @state = compute_state
end