Module: RSMP::TLC::Proxy::Status
- Included in:
- SupervisorInterface
- Defined in:
- lib/rsmp/tlc/proxy/status.rb
Overview
Status reading and waiting methods for a remote TLC. Covers status subscriptions, group waits, and plan/band reading.
Instance Method Summary collapse
-
#fetch_signal_plan(options: {}) ⇒ Object
Fetch the current signal plan from the remote TLC.
- #fetch_signal_plan! ⇒ Object
-
#read_current_plan(options: {}) ⇒ Object
Read the current signal plan number via S0014.
- #read_current_plan! ⇒ Object
-
#read_cycle_times(options: {}) ⇒ Object
Read cycle times for all plans via S0028.
- #read_cycle_times! ⇒ Object
-
#read_dynamic_band(plan:, band:, options: {}) ⇒ Object
Read the value of a single dynamic band for a given plan and band index via S0023.
- #read_dynamic_band! ⇒ Object
-
#wait_for_groups(state, timeout:) ⇒ Object
Wait for all signal groups to match state (as regex string, e.g. 'c' for yellow flash).
- #wait_for_groups! ⇒ Object
-
#wait_for_normal_control(timeout: nil) ⇒ Object
Wait for the TLC to return to normal control mode (functional position NormalControl, yellow flash off, startup mode off).
- #wait_for_normal_control! ⇒ Object
-
#wait_for_status(description, status_list, update_rate: 0, timeout: nil, component_id: nil) ⇒ Object
Subscribe to one or more statuses and wait until they match the expected values.
- #wait_for_status! ⇒ Object
Instance Method Details
#fetch_signal_plan(options: {}) ⇒ Object
Fetch the current signal plan from the remote TLC. Returns Result
8 9 10 11 12 13 14 15 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 8 def fetch_signal_plan(options: {}) timeout = [:timeout] || @timeouts['status_response'] request_status_and_collect({ S0014: i[status source] }, within: timeout).map do |exchange| exchange.collection..last.attributes['sS'].to_h do |item| [item['n'], item['s']] end end end |
#fetch_signal_plan! ⇒ Object
17 18 19 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 17 def fetch_signal_plan!(...) fetch_signal_plan(...).value! end |
#read_current_plan(options: {}) ⇒ Object
Read the current signal plan number via S0014. Returns the plan number as an Integer.
101 102 103 104 105 106 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 101 def read_current_plan(options: {}) timeout = [:timeout] || @timeouts['status_response'] request_status_and_collect({ S0014: [:status] }, within: timeout).map do |exchange| exchange.collection..first.attributes['sS'].first['s'].to_i end end |
#read_current_plan! ⇒ Object
108 109 110 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 108 def read_current_plan!(...) read_current_plan(...).value! end |
#read_cycle_times(options: {}) ⇒ Object
Read cycle times for all plans via S0028. Returns a hash of plan_nr (Integer) => cycle_time (Integer, seconds).
86 87 88 89 90 91 92 93 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 86 def read_cycle_times(options: {}) timeout = [:timeout] || @timeouts['status_response'] request_status_and_collect({ S0028: [:status] }, within: timeout).map do |exchange| status_items(exchange.collection..first.attributes['sS'].first['s']).to_h do |item| item.split('-').map(&:to_i) end end end |
#read_cycle_times! ⇒ Object
95 96 97 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 95 def read_cycle_times!(...) read_cycle_times(...).value! end |
#read_dynamic_band(plan:, band:, options: {}) ⇒ Object
Read the value of a single dynamic band for a given plan and band index via S0023. Returns the band value as an Integer, or nil if not found.
114 115 116 117 118 119 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 114 def read_dynamic_band(plan:, band:, options: {}) timeout = [:timeout] || @timeouts['status_response'] request_status_and_collect({ S0023: [:status] }, within: timeout).map do |exchange| extract_band_value(exchange.collection, plan, band) end end |
#read_dynamic_band! ⇒ Object
121 122 123 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 121 def read_dynamic_band!(...) read_dynamic_band(...).value! end |
#wait_for_groups(state, timeout:) ⇒ Object
Wait for all signal groups to match state (as regex string, e.g. 'c' for yellow flash).
53 54 55 56 57 58 59 60 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 53 def wait_for_groups(state, timeout:) regex = /^#{state}+$/ wait_for_status( "all groups to reach state #{state}", [{ 'sCI' => 'S0001', 'n' => 'signalgroupstatus', 's' => regex }], timeout: timeout ) end |
#wait_for_groups! ⇒ Object
62 63 64 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 62 def wait_for_groups!(...) wait_for_groups(...).value! end |
#wait_for_normal_control(timeout: nil) ⇒ Object
Wait for the TLC to return to normal control mode (functional position NormalControl, yellow flash off, startup mode off).
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 68 def wait_for_normal_control(timeout: nil) wait_for_status( 'normal control on, yellow flash off, startup mode off', [ { 'sCI' => 'S0007', 'n' => 'status', 's' => [true] }, { 'sCI' => 'S0011', 'n' => 'status', 's' => [false] }, { 'sCI' => 'S0005', 'n' => 'status', 's' => false } ], timeout: timeout ) end |
#wait_for_normal_control! ⇒ Object
80 81 82 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 80 def wait_for_normal_control!(...) wait_for_normal_control(...).value! end |
#wait_for_status(description, status_list, update_rate: 0, timeout: nil, component_id: nil) ⇒ Object
Subscribe to one or more statuses and wait until they match the expected values.
status_list items: { 'sCI' => ..., 'n' => ..., 's' =>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 25 def wait_for_status(description, status_list, update_rate: 0, timeout: nil, component_id: nil) readiness = validate_ready 'wait for status' return readiness if readiness.failure? component_id ||= main.c_id timeout ||= @timeouts['command'] subscribe_list = status_list.map do |item| entry = item.merge('uRt' => update_rate.to_s) entry = entry.merge('sOc' => true) if use_soc? entry end log "Wait for #{description}", level: :debug begin subscribe_to_status_and_collect(subscribe_list, component: component_id, within: timeout) ensure unsubscribe_list = status_list.map { |item| item.slice('sCI', 'n') } unsubscribe_to_status unsubscribe_list, component: component_id end end |
#wait_for_status! ⇒ Object
48 49 50 |
# File 'lib/rsmp/tlc/proxy/status.rb', line 48 def wait_for_status!(...) wait_for_status(...).value! end |