Class: RSMP::TLC::TrafficController
- Inherits:
-
Component
- Object
- ComponentBase
- Component
- RSMP::TLC::TrafficController
- Defined in:
- lib/rsmp/tlc/traffic_controller.rb
Overview
TrafficController is the main component of a TrafficControllerSite. It handles all command and status for the main component, and keeps track of signal plans, detector logics, inputs, etc. which do not have dedicated components.
Constant Summary
Constants inherited from ComponentBase
ComponentBase::AGGREGATED_STATUS_KEYS
Instance Attribute Summary collapse
-
#cycle_counter ⇒ Object
readonly
Returns the value of attribute cycle_counter.
-
#cycle_time ⇒ Object
readonly
Returns the value of attribute cycle_time.
-
#functional_position ⇒ Object
readonly
Returns the value of attribute functional_position.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#startup_sequence ⇒ Object
readonly
Returns the value of attribute startup_sequence.
-
#startup_sequence_active ⇒ Object
readonly
Returns the value of attribute startup_sequence_active.
-
#startup_sequence_pos ⇒ Object
readonly
Returns the value of attribute startup_sequence_pos.
Attributes inherited from ComponentBase
#aggregated_status, #aggregated_status_bools, #alarms, #c_id, #grouped, #node, #ntsOId, #statuses, #xNId
Instance Method Summary collapse
- #add_detector_logic(logic) ⇒ Object
- #add_signal_group(group) ⇒ Object
- #bool_string_to_digit(bool) ⇒ Object
- #bool_to_digit(bool) ⇒ Object
- #check_functional_position_timeout ⇒ Object
- #clock ⇒ Object
- #current_plan ⇒ Object
- #dark? ⇒ Boolean
- #end_startup_sequence ⇒ Object
- #find_plan(plan_nr) ⇒ Object
- #format_signal_group_status ⇒ Object
- #get_priority_list ⇒ Object
- #get_status(code, name = nil, options = {}) ⇒ Object
- #handle_command(command_code, arg, options = {}) ⇒ Object
- #handle_m0001(arg, options = {}) ⇒ Object
- #handle_m0002(arg, options = {}) ⇒ Object
- #handle_m0003(arg, options = {}) ⇒ Object
- #handle_m0004(arg, options = {}) ⇒ Object
- #handle_m0005(arg, options = {}) ⇒ Object
- #handle_m0006(arg, options = {}) ⇒ Object
- #handle_m0007(arg, options = {}) ⇒ Object
- #handle_m0012(arg, options = {}) ⇒ Object
- #handle_m0013(arg, options = {}) ⇒ Object
- #handle_m0014(arg, options = {}) ⇒ Object
- #handle_m0015(arg, options = {}) ⇒ Object
- #handle_m0016(arg, options = {}) ⇒ Object
- #handle_m0017(arg, options = {}) ⇒ Object
- #handle_m0018(arg, options = {}) ⇒ Object
- #handle_m0019(arg, options = {}) ⇒ Object
- #handle_m0020(arg, options = {}) ⇒ Object
- #handle_m0021(arg, options = {}) ⇒ Object
- #handle_m0022(arg, options = {}) ⇒ Object
- #handle_m0023(arg, options = {}) ⇒ Object
- #handle_m0103(arg, options = {}) ⇒ Object
- #handle_m0104(arg, options = {}) ⇒ Object
- #handle_s0001(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0002(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0003(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0004(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0005(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0006(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0007(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0008(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0009(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0010(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0011(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0012(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0013(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0014(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0015(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0016(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0017(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0018(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0019(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0020(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0021(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0022(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0023(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0024(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0026(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0027(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0028(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0029(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0030(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0031(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0032(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0033(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0035(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0091(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0092(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0095(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0096(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0097(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0098(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0205(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0206(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0207(status_code, status_name = nil, options = {}) ⇒ Object
- #handle_s0208(status_code, status_name = nil, options = {}) ⇒ Object
-
#initialize(node:, id:, ntsOId: nil, xNId: nil, signal_plans:, startup_sequence:, live_output: nil, inputs: {}) ⇒ TrafficController
constructor
A new instance of TrafficController.
- #initiate_startup_sequence ⇒ Object
- #input_logic(input, change) ⇒ Object
- #move_cycle_counter ⇒ Object
- #move_startup_sequence ⇒ Object
- #normal_control? ⇒ Boolean
- #output_states ⇒ Object
-
#prune_priorities ⇒ Object
remove all stale priority requests.
- #reset ⇒ Object
- #reset_modes ⇒ Object
- #set_fixed_time_control(status, source:) ⇒ Object
- #set_input(i, value) ⇒ Object
- #signal_priority_changed(priority, state) ⇒ Object
- #startup_state ⇒ Object
-
#status_updates_sent ⇒ Object
this method is called by the supervisor proxy each time status updates have been send we can then prune our priority request list.
- #string_to_bool(bool_str) ⇒ Object
- #switch_functional_position(mode, timeout: nil, reverting: false, source:) ⇒ Object
- #switch_plan(plan, source:) ⇒ Object
- #switch_traffic_situation(situation, source:) ⇒ Object
- #timer(now) ⇒ Object
- #yellow_flash? ⇒ Boolean
Methods inherited from Component
#acknowledge_alarm, #activate_alarm, #deactivate_alarm, #resume_alarm, #suspend_alarm
Methods inherited from ComponentBase
#aggregated_status_changed, #clear_aggregated_status, #clear_alarm_timestamps, #get_alarm_state, #log, #now, #set_aggregated_status, #set_aggregated_status_bools
Methods included from Inspect
Constructor Details
#initialize(node:, id:, ntsOId: nil, xNId: nil, signal_plans:, startup_sequence:, live_output: nil, inputs: {}) ⇒ TrafficController
Returns a new instance of TrafficController.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 12 def initialize node:, id:, ntsOId: nil, xNId: nil, signal_plans:, startup_sequence:, live_output:nil, inputs:{} super node: node, id: id, ntsOId: ntsOId, xNId: xNId, grouped: true @signal_groups = [] @detector_logics = [] @plans = signal_plans @num_traffic_situations = 1 if inputs num_inputs = inputs['total'] @input_programming = inputs['programming'] else @input_programming = nil end @inputs = TLC::Inputs.new num_inputs || 8 @startup_sequence = startup_sequence @live_output = live_output reset end |
Instance Attribute Details
#cycle_counter ⇒ Object (readonly)
Returns the value of attribute cycle_counter.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def cycle_counter @cycle_counter end |
#cycle_time ⇒ Object (readonly)
Returns the value of attribute cycle_time.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def cycle_time @cycle_time end |
#functional_position ⇒ Object (readonly)
Returns the value of attribute functional_position.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def functional_position @functional_position end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def plan @plan end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def pos @pos end |
#startup_sequence ⇒ Object (readonly)
Returns the value of attribute startup_sequence.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def startup_sequence @startup_sequence end |
#startup_sequence_active ⇒ Object (readonly)
Returns the value of attribute startup_sequence_active.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def startup_sequence_active @startup_sequence_active end |
#startup_sequence_pos ⇒ Object (readonly)
Returns the value of attribute startup_sequence_pos.
8 9 10 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8 def startup_sequence_pos @startup_sequence_pos end |
Instance Method Details
#add_detector_logic(logic) ⇒ Object
103 104 105 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 103 def add_detector_logic logic @detector_logics << logic end |
#add_signal_group(group) ⇒ Object
99 100 101 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 99 def add_signal_group group @signal_groups << group end |
#bool_string_to_digit(bool) ⇒ Object
472 473 474 475 476 477 478 479 480 481 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 472 def bool_string_to_digit bool case bool when 'True' '1' when 'False' '0' else raise RSMP::MessageRejected.new "Invalid boolean '#{bool}', must be 'True' or 'False'" end end |
#bool_to_digit(bool) ⇒ Object
483 484 485 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 483 def bool_to_digit bool bool ? '1' : '0' end |
#check_functional_position_timeout ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 150 def check_functional_position_timeout return unless @functional_position_timeout if clock.now >= @functional_position_timeout switch_functional_position @previous_functional_position, reverting: true, source: 'calendar_clock' @functional_position_timeout = nil @previous_functional_position = nil end end |
#clock ⇒ Object
86 87 88 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 86 def clock node.clock end |
#current_plan ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 90 def current_plan # TODO plan 0 should means use time table if @plans @plans[ plan ] || @plans.values.first else nil end end |
#dark? ⇒ Boolean
74 75 76 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 74 def dark? @function_position == 'Dark' end |
#end_startup_sequence ⇒ Object
173 174 175 176 177 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 173 def end_startup_sequence @startup_sequence_active = false @startup_sequence_initiated_at = nil @startup_sequence_pos = nil end |
#find_plan(plan_nr) ⇒ Object
408 409 410 411 412 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 408 def find_plan plan_nr plan = @plans[plan_nr.to_i] raise InvalidMessage.new "unknown signal plan #{plan_nr}, known only [#{@plans.keys.join(', ')}]" unless plan plan end |
#format_signal_group_status ⇒ Object
236 237 238 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 236 def format_signal_group_status @signal_groups.map { |group| group.state }.join end |
#get_priority_list ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 133 def get_priority_list @signal_priorities.map do |priority| { "r" => priority.id, "t" => RSMP::Clock.to_s(priority.updated), "s" => priority.state } end end |
#get_status(code, name = nil, options = {}) ⇒ Object
630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 630 def get_status code, name=nil, ={} case code when 'S0001', 'S0002', 'S0003', 'S0004', 'S0005', 'S0006', 'S0007', 'S0008', 'S0009', 'S0010', 'S0011', 'S0012', 'S0013', 'S0014', 'S0015', 'S0016', 'S0017', 'S0018', 'S0019', 'S0020', 'S0021', 'S0022', 'S0023', 'S0024', 'S0026', 'S0027', 'S0028', 'S0029', 'S0030', 'S0031', 'S0032', 'S0033', 'S0035', 'S0091', 'S0092', 'S0095', 'S0096', 'S0097', 'S0098', 'S0205', 'S0206', 'S0207', 'S0208' return send("handle_#{code.downcase}", code, name, ) else raise InvalidMessage.new "unknown status code #{code}" end end |
#handle_command(command_code, arg, options = {}) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 240 def handle_command command_code, arg, ={} case command_code when 'M0001', 'M0002', 'M0003', 'M0004', 'M0005', 'M0006', 'M0007', 'M0012', 'M0013', 'M0014', 'M0015', 'M0016', 'M0017', 'M0018', 'M0019', 'M0020', 'M0021', 'M0022', 'M0023', 'M0103', 'M0104' return send("handle_#{command_code.downcase}", arg, ) else raise UnknownCommand.new "Unknown command #{command_code}" end end |
#handle_m0001(arg, options = {}) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 253 def handle_m0001 arg, ={} @node.verify_security_code 2, arg['securityCode'] # timeout is specified in minutes, but we take 1 to mean 1s # this is not according to the curent rsmp spec, but is done # to speed up testing timeout = arg['timeout'].to_i if timeout == 1 timeout = 1 else timeout *= 60 end switch_functional_position arg['status'], timeout: timeout, source: 'forced' end |
#handle_m0002(arg, options = {}) ⇒ Object
271 272 273 274 275 276 277 278 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 271 def handle_m0002 arg, ={} @node.verify_security_code 2, arg['securityCode'] if TrafficControllerSite.from_rsmp_bool(arg['status']) switch_plan arg['timeplan'], source: 'forced' else switch_plan 0, source: 'startup' # TODO use clock/calender end end |
#handle_m0003(arg, options = {}) ⇒ Object
280 281 282 283 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 280 def handle_m0003 arg, ={} @node.verify_security_code 2, arg['securityCode'] switch_traffic_situation arg['traficsituation'], source: 'forced' end |
#handle_m0004(arg, options = {}) ⇒ Object
290 291 292 293 294 295 296 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 290 def handle_m0004 arg, ={} @node.verify_security_code 2, arg['securityCode'] # don't restart immeediately, since we need to first send command response # instead, defer an action, which will be handled by the TLC site log "Sheduling restart of TLC", level: :info @node.defer :restart end |
#handle_m0005(arg, options = {}) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 298 def handle_m0005 arg, ={} @node.verify_security_code 2, arg['securityCode'] route = arg['emergencyroute'].to_i enable = (arg['status'] == 'True') @last_emergency_route = route if enable if @emergency_routes.add? route log "Enabling emergency route #{route}", level: :info else log "Emergency route #{route} already enabled", level: :info end else if @emergency_routes.delete? route log "Disabling emergency route #{route}", level: :info else log "Emergency route #{route} already disabled", level: :info end end end |
#handle_m0006(arg, options = {}) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 340 def handle_m0006 arg, ={} @node.verify_security_code 2, arg['securityCode'] input = arg['input'].to_i status = string_to_bool arg['status'] unless input>=1 && input<=@inputs.size raise MessageRejected.new("Input must be in the range 1-#{@inputs.size}") end if status log "Activating input #{input}", level: :info else log "Deactivating input #{input}", level: :info end change = @inputs.set input, status input_logic input, change if change != nil end |
#handle_m0007(arg, options = {}) ⇒ Object
356 357 358 359 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 356 def handle_m0007 arg, ={} @node.verify_security_code 2, arg['securityCode'] set_fixed_time_control arg['status'], source: 'forced' end |
#handle_m0012(arg, options = {}) ⇒ Object
361 362 363 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 361 def handle_m0012 arg, ={} @node.verify_security_code 2, arg['securityCode'] end |
#handle_m0013(arg, options = {}) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 365 def handle_m0013 arg, ={} @node.verify_security_code 2, arg['securityCode'] set, clear = [], [] arg['status'].split(';').map do |part| offset, set_bits, clear_bits = part.split(',').map { |i| i.to_i } set_bits.to_s(2).reverse.each_char.with_index do |bit,i| set << i + offset if bit == '1' end clear_bits.to_s(2).reverse.each_char.with_index do |bit,i| clear << i + offset if bit == '1' end end set = set.uniq.sort clear = clear.uniq.sort # if input is both activated and deacticvated, there is no need to acticate first set -= (set & clear) [set,clear].each do |inputs| inputs.each do |input| if input<1 raise MessageRejected.new("Cannot acticate inputs #{set} and deactive inputs #{clear}: input #{input} is invalid (must be 1 or higher)" ) if input<1 end if input>@inputs.size raise MessageRejected.new("Cannot acticate inputs #{set} and deactive inputs #{clear}: input #{input} is invalid (only #{@inputs.size} inputs present)") end end end log "Activating inputs #{set} and deactivating inputs #{clear}", level: :info set.each do |input| change = @inputs.set input, true input_logic input, change if change != nil end clear.each do |input| change = @inputs.set input, false input_logic input, change if change != nil end end |
#handle_m0014(arg, options = {}) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 414 def handle_m0014 arg, ={} @node.verify_security_code 2, arg['securityCode'] plan = find_plan arg['plan'] arg['status'].split(',').each do |item| matched = /(\d+)-(\d+)/.match item band = matched[1].to_i value = matched[2].to_i log "Set plan #{arg['plan']} dynamic band #{band} to #{value}", level: :info plan.set_band band, value end end |
#handle_m0015(arg, options = {}) ⇒ Object
426 427 428 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 426 def handle_m0015 arg, ={} @node.verify_security_code 2, arg['securityCode'] end |
#handle_m0016(arg, options = {}) ⇒ Object
430 431 432 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 430 def handle_m0016 arg, ={} @node.verify_security_code 2, arg['securityCode'] end |
#handle_m0017(arg, options = {}) ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 434 def handle_m0017 arg, ={} @node.verify_security_code 2, arg['securityCode'] arg['status'].split(',').each do |item| elems = item.split('-') nr = elems[0].to_i plan = elems[1].to_i hour = elems[2].to_i min = elems[3].to_i if nr<0 || nr>12 raise InvalidMessage.new "time table id must be between 0 and 12, got #{nr}" end #p "nr: #{nr}, plan #{plan} at #{hour}:#{min}" @day_time_table[nr] = {plan: plan, hour: hour, min:min} end end |
#handle_m0018(arg, options = {}) ⇒ Object
450 451 452 453 454 455 456 457 458 459 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 450 def handle_m0018 arg, ={} @node.verify_security_code 2, arg['securityCode'] nr = arg['plan'].to_i cycle_time = arg['status'].to_i plan = @plans[nr] raise RSMP::MessageRejected.new "Plan '#{nr}' not found" unless plan raise RSMP::MessageRejected.new "Cycle time must be greater or equal to zero" if cycle_time < 0 log "Set plan #{nr} cycle time to #{cycle_time}", level: :info plan.set_cycle_time cycle_time end |
#handle_m0019(arg, options = {}) ⇒ Object
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 487 def handle_m0019 arg, ={} @node.verify_security_code 2, arg['securityCode'] input = arg['input'].to_i force = string_to_bool arg['status'] forced_value = string_to_bool arg['inputValue'] unless input>=1 && input<=@inputs.size raise MessageRejected.new("Input must be in the range 1-#{@inputs.size}") end if force log "Forcing input #{input} to #{forced_value}", level: :info else log "Releasing input #{input}", level: :info end change = @inputs.set_forcing input, force, forced_value input_logic input, change if change != nil end |
#handle_m0020(arg, options = {}) ⇒ Object
505 506 507 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 505 def handle_m0020 arg, ={} @node.verify_security_code 2, arg['securityCode'] end |
#handle_m0021(arg, options = {}) ⇒ Object
509 510 511 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 509 def handle_m0021 arg, ={} @node.verify_security_code 2, arg['securityCode'] end |
#handle_m0022(arg, options = {}) ⇒ Object
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 513 def handle_m0022 arg, ={} id = arg['requestId'] type = arg['type'] priority = @signal_priorities.find { |priority| priority.id == id } case type when 'new' if priority raise MessageRejected.new("Priority Request #{id} already exists") else #ref = arg.slice('signalGroupId','inputId','connectionId','approachId','laneInId','laneOutId') if arg['signalGroupId'] signal_group = node.find_component arg['signalGroupId'] end level = arg['level'] eta = arg['eta'] vehicleType = arg['vehicleType'] @signal_priorities << SignalPriority.new(node:self, id:id, level:level, eta:eta, vehicleType:vehicleType) log "Priority request #{id} for signal group #{signal_group.c_id} received.", level: :info end when 'update' if priority log "Updating Priority Request #{id}", level: :info else raise MessageRejected.new("Cannot update priority request #{id}, not found") end when 'cancel' if priority priority.cancel log "Priority request with id #{id} cancelled.", level: :info else raise MessageRejected.new("Cannot cancel priority request #{id}, not found") end else raise MessageRejected.new("Unknown type #{type}") end end |
#handle_m0023(arg, options = {}) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 552 def handle_m0023 arg, ={} @node.verify_security_code 2, arg['securityCode'] timeout = arg['status'].to_i unless timeout>=0 and timeout <= 65535 raise RSMP::MessageRejected.new "Timeout must be in the range 0-65535, got #{timeout}" end if timeout == 0 log "Dynamic bands timeout disabled", level: :info else log "Dynamic bands timeout set to #{timeout}min", level: :info end @dynamic_bands_timeout = timeout end |
#handle_m0103(arg, options = {}) ⇒ Object
566 567 568 569 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 566 def handle_m0103 arg, ={} level = {'Level1'=>1,'Level2'=>2}[arg['status']] @node.change_security_code level, arg['oldSecurityCode'], arg['newSecurityCode'] end |
#handle_m0104(arg, options = {}) ⇒ Object
571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 571 def handle_m0104 arg, ={} @node.verify_security_code 1, arg['securityCode'] time = Time.new( arg['year'], arg['month'], arg['day'], arg['hour'], arg['minute'], arg['second'], 'UTC' ) clock.set time log "Clock set to #{time}, (adjustment is #{clock.adjustment}s)", level: :info end |
#handle_s0001(status_code, status_name = nil, options = {}) ⇒ Object
645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 645 def handle_s0001 status_code, status_name=nil, ={} case status_name when 'signalgroupstatus' TrafficControllerSite.make_status format_signal_group_status when 'cyclecounter' TrafficControllerSite.make_status @cycle_counter.to_s when 'basecyclecounter' TrafficControllerSite.make_status @cycle_counter.to_s when 'stage' TrafficControllerSite.make_status 0.to_s end end |
#handle_s0002(status_code, status_name = nil, options = {}) ⇒ Object
658 659 660 661 662 663 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 658 def handle_s0002 status_code, status_name=nil, ={} case status_name when 'detectorlogicstatus' TrafficControllerSite.make_status @detector_logics.map { |dl| bool_to_digit(dl.value) }.join end end |
#handle_s0003(status_code, status_name = nil, options = {}) ⇒ Object
665 666 667 668 669 670 671 672 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 665 def handle_s0003 status_code, status_name=nil, ={} case status_name when 'inputstatus' TrafficControllerSite.make_status @inputs.actual_string when 'extendedinputstatus' TrafficControllerSite.make_status 0.to_s end end |
#handle_s0004(status_code, status_name = nil, options = {}) ⇒ Object
674 675 676 677 678 679 680 681 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 674 def handle_s0004 status_code, status_name=nil, ={} case status_name when 'outputstatus' TrafficControllerSite.make_status 0 when 'extendedoutputstatus' TrafficControllerSite.make_status 0 end end |
#handle_s0005(status_code, status_name = nil, options = {}) ⇒ Object
683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 683 def handle_s0005 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status @is_starting when 'statusByIntersection' # from sxl 1.2.0 TrafficControllerSite.make_status([ { "intersection"=>"1", "startup" => TrafficControllerSite.to_rmsp_bool(@is_starting) } ]) end end |
#handle_s0006(status_code, status_name = nil, options = {}) ⇒ Object
697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 697 def handle_s0006 status_code, status_name=nil, ={} if Proxy.version_meets_requirement? [:sxl_version], '>=1.2.0' log "S0006 is depreciated, use S0035 instead.", level: :warning end status = @emergency_routes.any? case status_name when 'status' TrafficControllerSite.make_status status when 'emergencystage' TrafficControllerSite.make_status status ? @last_emergency_route : 0 end end |
#handle_s0007(status_code, status_name = nil, options = {}) ⇒ Object
718 719 720 721 722 723 724 725 726 727 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 718 def handle_s0007 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @function_position != 'Dark' when 'source' TrafficControllerSite.make_status @function_position_source end end |
#handle_s0008(status_code, status_name = nil, options = {}) ⇒ Object
729 730 731 732 733 734 735 736 737 738 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 729 def handle_s0008 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @manual_control when 'source' TrafficControllerSite.make_status @manual_control_source end end |
#handle_s0009(status_code, status_name = nil, options = {}) ⇒ Object
740 741 742 743 744 745 746 747 748 749 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 740 def handle_s0009 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @fixed_time_control when 'source' TrafficControllerSite.make_status @fixed_time_control_source end end |
#handle_s0010(status_code, status_name = nil, options = {}) ⇒ Object
751 752 753 754 755 756 757 758 759 760 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 751 def handle_s0010 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @isolated_control when 'source' TrafficControllerSite.make_status @isolated_control_source end end |
#handle_s0011(status_code, status_name = nil, options = {}) ⇒ Object
762 763 764 765 766 767 768 769 770 771 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 762 def handle_s0011 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status TrafficControllerSite.to_rmsp_bool( @function_position == 'YellowFlash' ) when 'source' TrafficControllerSite.make_status @function_position_source end end |
#handle_s0012(status_code, status_name = nil, options = {}) ⇒ Object
773 774 775 776 777 778 779 780 781 782 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 773 def handle_s0012 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @all_red when 'source' TrafficControllerSite.make_status @all_red_source end end |
#handle_s0013(status_code, status_name = nil, options = {}) ⇒ Object
784 785 786 787 788 789 790 791 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 784 def handle_s0013 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status @police_key end end |
#handle_s0014(status_code, status_name = nil, options = {}) ⇒ Object
793 794 795 796 797 798 799 800 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 793 def handle_s0014 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status @plan when 'source' TrafficControllerSite.make_status @plan_source end end |
#handle_s0015(status_code, status_name = nil, options = {}) ⇒ Object
802 803 804 805 806 807 808 809 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 802 def handle_s0015 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status @traffic_situation when 'source' TrafficControllerSite.make_status @traffic_situation_source end end |
#handle_s0016(status_code, status_name = nil, options = {}) ⇒ Object
811 812 813 814 815 816 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 811 def handle_s0016 status_code, status_name=nil, ={} case status_name when 'number' TrafficControllerSite.make_status @detector_logics.size end end |
#handle_s0017(status_code, status_name = nil, options = {}) ⇒ Object
818 819 820 821 822 823 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 818 def handle_s0017 status_code, status_name=nil, ={} case status_name when 'number' TrafficControllerSite.make_status @signal_groups.size end end |
#handle_s0018(status_code, status_name = nil, options = {}) ⇒ Object
825 826 827 828 829 830 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 825 def handle_s0018 status_code, status_name=nil, ={} case status_name when 'number' TrafficControllerSite.make_status @plans.size end end |
#handle_s0019(status_code, status_name = nil, options = {}) ⇒ Object
832 833 834 835 836 837 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 832 def handle_s0019 status_code, status_name=nil, ={} case status_name when 'number' TrafficControllerSite.make_status @num_traffic_situations end end |
#handle_s0020(status_code, status_name = nil, options = {}) ⇒ Object
839 840 841 842 843 844 845 846 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 839 def handle_s0020 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'controlmode' TrafficControllerSite.make_status @control_mode end end |
#handle_s0021(status_code, status_name = nil, options = {}) ⇒ Object
848 849 850 851 852 853 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 848 def handle_s0021 status_code, status_name=nil, ={} case status_name when 'detectorlogics' TrafficControllerSite.make_status @detector_logics.map { |logic| bool_to_digit(logic.forced)}.join end end |
#handle_s0022(status_code, status_name = nil, options = {}) ⇒ Object
855 856 857 858 859 860 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 855 def handle_s0022 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status @plans.keys.join(',') end end |
#handle_s0023(status_code, status_name = nil, options = {}) ⇒ Object
862 863 864 865 866 867 868 869 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 862 def handle_s0023 status_code, status_name=nil, ={} case status_name when 'status' dynamic_bands = @plans.map { |nr,plan| plan.dynamic_bands_string } str = dynamic_bands.compact.join(',') TrafficControllerSite.make_status str end end |
#handle_s0024(status_code, status_name = nil, options = {}) ⇒ Object
871 872 873 874 875 876 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 871 def handle_s0024 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status '1-0' end end |
#handle_s0026(status_code, status_name = nil, options = {}) ⇒ Object
878 879 880 881 882 883 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 878 def handle_s0026 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status '0-00' end end |
#handle_s0027(status_code, status_name = nil, options = {}) ⇒ Object
885 886 887 888 889 890 891 892 893 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 885 def handle_s0027 status_code, status_name=nil, ={} case status_name when 'status' status = @day_time_table.map do |i,item| "#{i}-#{item[:plan]}-#{item[:hour]}-#{item[:min]}" end.join(',') TrafficControllerSite.make_status status end end |
#handle_s0028(status_code, status_name = nil, options = {}) ⇒ Object
895 896 897 898 899 900 901 902 903 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 895 def handle_s0028 status_code, status_name=nil, ={} case status_name when 'status' times = @plans.map {|nr,plan| "#{"%02d" % plan.nr}-#{"%02d" % plan.cycle_time}"}.join(",") TrafficControllerSite.make_status times end rescue StandardError => e puts e end |
#handle_s0029(status_code, status_name = nil, options = {}) ⇒ Object
905 906 907 908 909 910 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 905 def handle_s0029 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status @inputs.forced_string end end |
#handle_s0030(status_code, status_name = nil, options = {}) ⇒ Object
912 913 914 915 916 917 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 912 def handle_s0030 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status '' end end |
#handle_s0031(status_code, status_name = nil, options = {}) ⇒ Object
919 920 921 922 923 924 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 919 def handle_s0031 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status '' end end |
#handle_s0032(status_code, status_name = nil, options = {}) ⇒ Object
926 927 928 929 930 931 932 933 934 935 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 926 def handle_s0032 status_code, status_name=nil, ={} case status_name when 'intersection' TrafficControllerSite.make_status @intersection when 'status' TrafficControllerSite.make_status 'local' when 'source' TrafficControllerSite.make_status @intersection_source end end |
#handle_s0033(status_code, status_name = nil, options = {}) ⇒ Object
937 938 939 940 941 942 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 937 def handle_s0033 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status get_priority_list end end |
#handle_s0035(status_code, status_name = nil, options = {}) ⇒ Object
710 711 712 713 714 715 716 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 710 def handle_s0035 status_code, status_name=nil, ={} case status_name when 'emergencyroutes' list = @emergency_routes.sort.map {|route| {'id'=>route.to_s}} TrafficControllerSite.make_status list end end |
#handle_s0091(status_code, status_name = nil, options = {}) ⇒ Object
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 944 def handle_s0091 status_code, status_name=nil, ={} if Proxy.version_meets_requirement? [:sxl_version], '>=1.1' case status_name when 'user' TrafficControllerSite.make_status 0 end else case status_name when 'user' TrafficControllerSite.make_status 'nobody' when 'status' TrafficControllerSite.make_status 'logout' end end end |
#handle_s0092(status_code, status_name = nil, options = {}) ⇒ Object
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 960 def handle_s0092 status_code, status_name=nil, ={} if Proxy.version_meets_requirement? [:sxl_version], '>=1.1' case status_name when 'user' TrafficControllerSite.make_status 0 end else case status_name when 'user' TrafficControllerSite.make_status 'nobody' when 'status' TrafficControllerSite.make_status 'logout' end end end |
#handle_s0095(status_code, status_name = nil, options = {}) ⇒ Object
976 977 978 979 980 981 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 976 def handle_s0095 status_code, status_name=nil, ={} case status_name when 'status' TrafficControllerSite.make_status RSMP::VERSION end end |
#handle_s0096(status_code, status_name = nil, options = {}) ⇒ Object
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 983 def handle_s0096 status_code, status_name=nil, ={} now = clock.now case status_name when 'year' TrafficControllerSite.make_status now.year.to_s.rjust(4, "0") when 'month' TrafficControllerSite.make_status now.month.to_s.rjust(2, "0") when 'day' TrafficControllerSite.make_status now.day.to_s.rjust(2, "0") when 'hour' TrafficControllerSite.make_status now.hour.to_s.rjust(2, "0") when 'minute' TrafficControllerSite.make_status now.min.to_s.rjust(2, "0") when 'second' TrafficControllerSite.make_status now.sec.to_s.rjust(2, "0") end end |
#handle_s0097(status_code, status_name = nil, options = {}) ⇒ Object
1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1001 def handle_s0097 status_code, status_name=nil, ={} case status_name when 'checksum' TrafficControllerSite.make_status '1' when 'timestamp' now = clock.to_s TrafficControllerSite.make_status now end end |
#handle_s0098(status_code, status_name = nil, options = {}) ⇒ Object
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1011 def handle_s0098 status_code, status_name=nil, ={} settings = node.site_settings.slice('components','signal_plans','inputs','startup_sequence') json = JSON.generate(settings) case status_name when 'config' TrafficControllerSite.make_status json when 'timestamp' now = clock.to_s TrafficControllerSite.make_status now when 'version' TrafficControllerSite.make_status Digest::MD5.hexdigest(json) end end |
#handle_s0205(status_code, status_name = nil, options = {}) ⇒ Object
1025 1026 1027 1028 1029 1030 1031 1032 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1025 def handle_s0205 status_code, status_name=nil, ={} case status_name when 'start' TrafficControllerSite.make_status clock.to_s when 'vehicles' TrafficControllerSite.make_status 0 end end |
#handle_s0206(status_code, status_name = nil, options = {}) ⇒ Object
1034 1035 1036 1037 1038 1039 1040 1041 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1034 def handle_s0206 status_code, status_name=nil, ={} case status_name when 'start' TrafficControllerSite.make_status clock.to_s when 'speed' TrafficControllerSite.make_status 0 end end |
#handle_s0207(status_code, status_name = nil, options = {}) ⇒ Object
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1043 def handle_s0207 status_code, status_name=nil, ={} case status_name when 'start' TrafficControllerSite.make_status clock.to_s when 'occupancy' values = [-1,0,50,100] output = @detector_logics.each_with_index.map {|dl,i| values[i%values.size] }.join(",") p values TrafficControllerSite.make_status output end end |
#handle_s0208(status_code, status_name = nil, options = {}) ⇒ Object
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 1055 def handle_s0208 status_code, status_name=nil, ={} case status_name when 'start' TrafficControllerSite.make_status clock.to_s when 'P' TrafficControllerSite.make_status 0 when 'PS' TrafficControllerSite.make_status 0 when 'L' TrafficControllerSite.make_status 0 when 'LS' TrafficControllerSite.make_status 0 when 'B' TrafficControllerSite.make_status 0 when 'SP' TrafficControllerSite.make_status 0 when 'MC' TrafficControllerSite.make_status 0 when 'C' TrafficControllerSite.make_status 0 when 'F' TrafficControllerSite.make_status 0 end end |
#initiate_startup_sequence ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 165 def initiate_startup_sequence log "Initiating startup sequence", level: :info reset_modes @startup_sequence_active = true @startup_sequence_initiated_at = nil @startup_sequence_pos = nil end |
#input_logic(input, change) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 319 def input_logic input, change return unless @input_programming && change != nil action = @input_programming[input] return unless action if action['raise_alarm'] if action['component'] component = node.find_component action['component'] else component = node.main end alarm_code = action['raise_alarm'] if change log "Activating input #{input} is programmed to raise alarm #{alarm_code} on #{component.c_id}", level: :info component.activate_alarm alarm_code else log "Deactivating input #{input} is programmed to clear alarm #{alarm_code} on #{component.c_id}", level: :info component.deactivate_alarm alarm_code end end end |
#move_cycle_counter ⇒ Object
143 144 145 146 147 148 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 143 def move_cycle_counter counter = Time.now.to_i % current_plan.cycle_time changed = counter != @cycle_counter @cycle_counter = counter changed end |
#move_startup_sequence ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 179 def move_startup_sequence was = @startup_sequence_pos if @startup_sequence_initiated_at == nil @startup_sequence_initiated_at = Time.now.to_i + 1 @startup_sequence_pos = 0 else @startup_sequence_pos = Time.now.to_i - @startup_sequence_initiated_at end if @startup_sequence_pos >= @startup_sequence.size end_startup_sequence end end |
#normal_control? ⇒ Boolean
82 83 84 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 82 def normal_control? @function_position == 'NormalControl' end |
#output_states ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 192 def output_states return unless @live_output str = @signal_groups.map do |group| state = group.state s = "#{group.c_id}:#{state}" if state =~ /^[1-9]$/ s.colorize(:green) elsif state =~ /^[NOP]$/ s.colorize(:yellow) elsif state =~ /^[ae]$/ s.colorize(:light_black) elsif state =~ /^[f]$/ s.colorize(:yellow) elsif state =~ /^[g]$/ s.colorize(:red) else s.colorize(:red) end end.join ' ' modes = '.'*9 modes[0] = 'N' if @function_position == 'NormalControl' modes[1] = 'Y' if @function_position == 'YellowFlash' modes[2] = 'D' if @function_position == 'Dark' modes[3] = 'B' if @booting modes[4] = 'S' if @startup_sequence_active modes[5] = 'M' if @manual_control modes[6] = 'F' if @fixed_time_control modes[7] = 'R' if @all_red modes[8] = 'I' if @isolated_control modes[9] = 'P' if @police_key != 0 plan = "P#{@plan}" # create folders if needed FileUtils.mkdir_p File.dirname(@live_output) # append a line with the current state to the file File.open @live_output, 'w' do |file| file.puts "#{modes} #{plan.rjust(2)} #{@cycle_counter.to_s.rjust(3)} #{str}\r" end end |
#prune_priorities ⇒ Object
remove all stale priority requests
123 124 125 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 123 def prune_priorities @signal_priorities.delete_if {|priority| priority.prune? } end |
#reset ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 53 def reset reset_modes @cycle_counter = 0 @plan = 1 @plan_source = 'startup' @intersection = 0 @intersection_source = 'startup' @emergency_routes = Set.new @last_emergency_route = nil @traffic_situation = 0 @traffic_situation_source = 'startup' @day_time_table = {} @startup_sequence_active = false @startup_sequence_initiated_at = nil @startup_sequence_pos = 0 @time_int = nil @inputs.reset @signal_priorities = [] @dynamic_bands_timeout = 0 end |
#reset_modes ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 33 def reset_modes @function_position = 'NormalControl' @function_position_source = 'startup' @previous_functional_position = nil @functional_position_timeout = nil @booting = false @is_starting = false @control_mode = 'control' @manual_control = false @manual_control_source = 'startup' @fixed_time_control = false @fixed_time_control_source = 'startup' @isolated_control = false @isolated_control_source = 'startup' @all_red = false @all_red_source = 'startup' @police_key = 0 end |
#set_fixed_time_control(status, source:) ⇒ Object
591 592 593 594 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 591 def set_fixed_time_control status, source: @fixed_time_control = status @fixed_time_control_source = source end |
#set_input(i, value) ⇒ Object
586 587 588 589 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 586 def set_input i, value return unless i>=0 && i<@num_inputs @inputs[i] = bool_to_digit arg['value'] end |
#signal_priority_changed(priority, state) ⇒ Object
119 120 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 119 def signal_priority_changed priority, state end |
#startup_state ⇒ Object
159 160 161 162 163 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 159 def startup_state return unless @startup_sequence_active return unless @startup_sequence_pos @startup_sequence[ @startup_sequence_pos ] end |
#status_updates_sent ⇒ Object
this method is called by the supervisor proxy each time status updates have been send we can then prune our priority request list
129 130 131 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 129 def status_updates_sent prune_priorities end |
#string_to_bool(bool_str) ⇒ Object
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 461 def string_to_bool bool_str case bool_str when 'True' true when 'False' false else raise RSMP::MessageRejected.new "Invalid boolean '#{bool}', must be 'True' or 'False'" end end |
#switch_functional_position(mode, timeout: nil, reverting: false, source:) ⇒ Object
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 608 def switch_functional_position mode, timeout: nil, reverting: false, source: unless ['NormalControl','YellowFlash','Dark'].include? mode raise RSMP::MessageRejected.new "Invalid functional position #{mode.inspect}, must be NormalControl, YellowFlash or Dark" end if reverting log "Reverting to functional position #{mode} after timeout", level: :info elsif timeout && timeout > 0 log "Switching to functional position #{mode} with timeout #{(timeout/60).round(1)}min", level: :info @previous_functional_position = @function_position now = clock.now @functional_position_timeout = now + timeout else log "Switching to functional position #{mode}", level: :info end if mode == 'NormalControl' initiate_startup_sequence if @function_position != 'NormalControl' end @function_position = mode @function_position_source = source mode end |
#switch_plan(plan, source:) ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 596 def switch_plan plan, source: plan_nr = plan.to_i if plan_nr == 0 log "Switching to plan selection by time table", level: :info else plan = find_plan plan_nr log "Switching to plan #{plan_nr}", level: :info end @plan = plan_nr @plan_source = source end |
#switch_traffic_situation(situation, source:) ⇒ Object
285 286 287 288 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 285 def switch_traffic_situation situation, source: @traffic_situation = situation.to_i @traffic_situation_source = 'forced' end |
#timer(now) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 107 def timer now # TODO use monotone timer, to avoid jumps in case the user sets the system time return unless move_cycle_counter check_functional_position_timeout move_startup_sequence if @startup_sequence_active @signal_groups.each { |group| group.timer } @signal_priorities.each {|priority| priority.timer } output_states end |
#yellow_flash? ⇒ Boolean
78 79 80 |
# File 'lib/rsmp/tlc/traffic_controller.rb', line 78 def yellow_flash? @function_position == 'YellowFlash' end |