Class: RSMP::TLC::SignalGroup
- Inherits:
-
Component
- Object
- ComponentBase
- Component
- RSMP::TLC::SignalGroup
- Defined in:
- lib/rsmp/tlc/signal_group.rb
Overview
Signal group representation for the TLC.
Constant Summary
Constants inherited from ComponentBase
ComponentBase::AGGREGATED_STATUS_KEYS
Instance Attribute Summary collapse
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Attributes inherited from ComponentBase
#aggregated_status, #aggregated_status_bools, #alarms, #c_id, #grouped, #node, #ntsoid, #statuses, #xnid
Instance Method Summary collapse
- #compute_plan_state ⇒ Object
- #compute_state ⇒ Object
- #get_status(code, name = nil, _options = {}) ⇒ Object
- #handle_command(command_code, arg, options = {}) ⇒ Object
-
#handle_m0010(arg, _options = {}) ⇒ Object
Start of signal group.
-
#handle_m0011(arg, _options = {}) ⇒ Object
Stop of signal group.
- #handle_s0025(_status_code, status_name = nil, _options = {}) ⇒ Object
-
#initialize(node:, id:) ⇒ SignalGroup
constructor
plan is a string, with each character representing a signal phase at a particular second in the cycle.
- #startup_state ⇒ Object
- #state_at_cycle_position(states, cycle_counter, default) ⇒ Object
- #timer ⇒ Object
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
Constructor Details
#initialize(node:, id:) ⇒ SignalGroup
plan is a string, with each character representing a signal phase at a particular second in the cycle
8 9 10 |
# File 'lib/rsmp/tlc/signal_group.rb', line 8 def initialize(node:, id:) super(node: node, id: id, grouped: false) end |
Instance Attribute Details
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
5 6 7 |
# File 'lib/rsmp/tlc/signal_group.rb', line 5 def plan @plan end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/rsmp/tlc/signal_group.rb', line 5 def state @state end |
Instance Method Details
#compute_plan_state ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rsmp/tlc/signal_group.rb', line 28 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_state ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rsmp/tlc/signal_group.rb', line 16 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
72 73 74 75 76 77 78 79 |
# File 'lib/rsmp/tlc/signal_group.rb', line 72 def get_status(code, name = nil, = {}) 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
47 48 49 50 51 52 53 54 |
# File 'lib/rsmp/tlc/signal_group.rb', line 47 def handle_command(command_code, arg, = {}) case command_code when 'M0010', 'M0011' send("handle_#{command_code.downcase}", arg, ) else raise UnknownCommand, "Unknown command #{command_code}" end end |
#handle_m0010(arg, _options = {}) ⇒ Object
Start of signal group. Orders a signal group to green
57 58 59 60 61 62 |
# File 'lib/rsmp/tlc/signal_group.rb', line 57 def handle_m0010(arg, = {}) @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
65 66 67 68 69 70 |
# File 'lib/rsmp/tlc/signal_group.rb', line 65 def handle_m0011(arg, = {}) @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
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rsmp/tlc/signal_group.rb', line 81 def handle_s0025(_status_code, status_name = nil, = {}) 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_state ⇒ Object
24 25 26 |
# File 'lib/rsmp/tlc/signal_group.rb', line 24 def startup_state node.main.startup_state || 'a' end |
#state_at_cycle_position(states, cycle_counter, default) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rsmp/tlc/signal_group.rb', line 39 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 |
#timer ⇒ Object
12 13 14 |
# File 'lib/rsmp/tlc/signal_group.rb', line 12 def timer @state = compute_state end |