Class: RSMP::TLC::TrafficControllerSite
- Inherits:
-
Site
- Object
- Node
- Site
- RSMP::TLC::TrafficControllerSite
show all
- Defined in:
- lib/rsmp/tlc/traffic_controller_site.rb,
lib/rsmp/options/traffic_controller_site_options.rb
Overview
Simulates a Traffic Light Controller Site
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
Attributes inherited from Site
#core_version, #logger, #proxies, #site_settings
Attributes included from Components
#components
Attributes inherited from Node
#archive, #clock, #collector, #deferred, #error_queue, #logger, #task
Attributes included from RSMP::Task
#task
Attributes included from Logging
#archive, #logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Site
#aggregated_status_changed, #alarm_acknowledged, #alarm_activated_or_deactivated, #alarm_suspended_or_resumed, #build_proxies, #check_core_versions, #check_sxl_version, #connect_to_supervisor, #find_supervisor, #handle_site_settings, #log_site_starting, #run, #send_alarm, #site_id, #stop, #sxl_version, #wait_for_supervisor
Methods included from Components
#add_component, #aggregated_status_changed, #check_main_component, #clear_alarm_timestamps, #find_component, #infer_component_type, #initialize_components, #setup_components
Methods inherited from Node
#author, #check_required_settings, #clear_deferred, #defer, #distribute_error, #ignore_errors, #now, #process_deferred
Methods included from RSMP::Task
#initialize_task, #restart, #run, #stop, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Inspect
#inspect, #inspector
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
Returns a new instance of TrafficControllerSite.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 11
def initialize(options = {})
@sxl = 'traffic_light_controller'
@security_codes = normalize_security_codes(options.dig(:site_settings, 'security_codes'))
@interval = options[:site_settings].dig('intervals', 'timer') || 1
@startup_sequence = options[:site_settings]['startup_sequence'] || 'efg'
build_plans options[:site_settings]['signal_plans']
super
return if main
raise ConfigurationError, 'TLC must have a main component'
end
|
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
5
6
7
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 5
def main
@main
end
|
#signal_plans ⇒ Object
Returns the value of attribute signal_plans.
5
6
7
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 5
def signal_plans
@signal_plans
end
|
Class Method Details
.from_rsmp_bool?(str) ⇒ Boolean
156
157
158
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 156
def self.from_rsmp_bool?(str)
str == 'True'
end
|
.make_status(value, quality = 'recent') ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 160
def self.make_status(value, quality = 'recent')
case value
when true, false
[to_rmsp_bool(value), quality]
else
[value, quality]
end
end
|
.to_rmsp_bool(bool) ⇒ Object
148
149
150
151
152
153
154
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 148
def self.to_rmsp_bool(bool)
if bool
'True'
else
'False'
end
end
|
Instance Method Details
#build_component(id:, type:, settings: {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 61
def build_component(id:, type:, settings: {})
case type
when 'main'
TrafficController.new node: self,
id: id,
ntsoid: settings['ntsOId'],
xnid: settings['xNId'],
startup_sequence: @startup_sequence,
signal_plans: @signal_plans,
live_output: @site_settings['live_output'],
inputs: @site_settings['inputs']
when 'signal_group'
group = SignalGroup.new node: self, id: id
main.add_signal_group group
group
when 'detector_logic'
logic = DetectorLogic.new node: self, id: id
main.add_detector_logic logic
logic
end
end
|
#build_plans(signal_plans) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 42
def build_plans(signal_plans)
@signal_plans = {}
return unless signal_plans
signal_plans.each_pair do |id, settings|
states = nil
cycle_time = settings['cycle_time']
states = settings['states'] if settings
dynamic_bands = settings['dynamic_bands'] if settings
@signal_plans[id.to_i] =
SignalPlan.new(number: id.to_i, cycle_time: cycle_time, states: states, dynamic_bands: dynamic_bands)
end
end
|
#change_security_code(level, old_code, new_code) ⇒ Object
143
144
145
146
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 143
def change_security_code(level, old_code, new_code)
verify_security_code level, old_code
@security_codes[level] = new_code
end
|
#do_deferred(key, _item = nil) ⇒ Object
169
170
171
172
173
174
175
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 169
def do_deferred(key, _item = nil)
case key
when :restart
log 'Restarting TLC', level: :info
restart
end
end
|
#get_plan(_group_id, _plan_nr) ⇒ Object
57
58
59
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 57
def get_plan(_group_id, _plan_nr)
'NN1BB1'
end
|
#normalize_security_codes(codes) ⇒ Object
134
135
136
137
138
139
140
141
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 134
def normalize_security_codes(codes)
return {} unless codes.is_a?(Hash)
codes.each_with_object({}) do |(key, value), memo|
int_key = key.is_a?(String) && key.match?(/^\d+$/) ? key.to_i : key
memo[int_key] = value
end
end
|
#run_tlc_timer(task) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 93
def run_tlc_timer(task)
next_time = Time.now.to_f
loop do
timer(@clock.now)
rescue StandardError => e
distribute_error e, level: :internal
ensure
next_time += @interval
duration = next_time - Time.now.to_f
task.sleep duration
end
end
|
#site_type_name ⇒ Object
27
28
29
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 27
def site_type_name
'TLC'
end
|
#start ⇒ Object
31
32
33
34
35
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 31
def start
super
start_tlc_timer
main.initiate_startup_sequence
end
|
#start_tlc_timer ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 83
def start_tlc_timer
task_name = 'tlc timer'
log "Starting #{task_name} with interval #{@interval} seconds", level: :debug
@timer = @task.async do |task|
task.annotate task_name
run_tlc_timer task
end
end
|
#stop_subtasks ⇒ Object
37
38
39
40
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 37
def stop_subtasks
stop_tlc_timer
super
end
|
#stop_tlc_timer ⇒ Object
114
115
116
117
118
119
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 114
def stop_tlc_timer
return unless @timer
@timer.stop
@timer = nil
end
|
#timer(now) ⇒ Object
121
122
123
124
125
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 121
def timer(now)
return unless main
main.timer now
end
|
#verify_security_code(level, code) ⇒ Object
127
128
129
130
131
132
|
# File 'lib/rsmp/tlc/traffic_controller_site.rb', line 127
def verify_security_code(level, code)
raise ArgumentError, "Level must be 1-2, got #{level}" unless (1..2).include?(level)
return unless @security_codes[level] != code
raise MessageRejected, "Wrong security code for level #{level}"
end
|