Class: RSMP::TLC::TrafficController

Inherits:
Component
  • Object
show all
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 Component

Component::AGGREGATED_STATUS_KEYS

Instance Attribute Summary collapse

Attributes inherited from Component

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

Instance Method Summary collapse

Methods inherited from Component

#aggregated_status_changed, #clear_aggregated_status, #handle_alarm, #handle_status_response, #handle_status_subscribe, #handle_status_unsubscribe, #handle_status_update, #log, #set_aggregated_status, #set_aggregated_status_bools, #store_status

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:, cycle_time: 10, signal_plans:) ⇒ TrafficController

Returns a new instance of TrafficController.



10
11
12
13
14
15
16
17
18
19
# File 'lib/rsmp/tlc/traffic_controller.rb', line 10

def initialize node:, id:, cycle_time: 10, signal_plans:
  super node: node, id: id, grouped: true
  @signal_groups = []
  @detector_logics = []
  @plans = signal_plans
  @cycle_time = cycle_time
  @num_traffic_situations = 1
  @num_inputs = 8
  reset
end

Instance Attribute Details

#cycle_timeObject (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

#planObject (readonly)

Returns the value of attribute plan.



8
9
10
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8

def plan
  @plan
end

#posObject (readonly)

Returns the value of attribute pos.



8
9
10
# File 'lib/rsmp/tlc/traffic_controller.rb', line 8

def pos
  @pos
end

Instance Method Details

#add_detector_logic(logic) ⇒ Object



62
63
64
# File 'lib/rsmp/tlc/traffic_controller.rb', line 62

def add_detector_logic logic
  @detector_logics << logic
end

#add_signal_group(group) ⇒ Object



58
59
60
# File 'lib/rsmp/tlc/traffic_controller.rb', line 58

def add_signal_group group
  @signal_groups << group
end

#clockObject



45
46
47
# File 'lib/rsmp/tlc/traffic_controller.rb', line 45

def clock
  node.clock
end

#current_planObject



49
50
51
52
53
54
55
56
# File 'lib/rsmp/tlc/traffic_controller.rb', line 49

def current_plan
  # TODO plan 0 should means use time table
  if @plans
    @plans[ plan ] || @plans.values.first
  else
    nil
  end
end

#find_plan(plan_nr) ⇒ Object



189
190
191
192
193
# File 'lib/rsmp/tlc/traffic_controller.rb', line 189

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_statusObject



101
102
103
104
105
106
107
# File 'lib/rsmp/tlc/traffic_controller.rb', line 101

def format_signal_group_status
  if @yellow_flash
    'c' * @signal_groups.size
  else
    @signal_groups.map { |group| group.state }.join
  end
end

#get_status(code, name = nil) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rsmp/tlc/traffic_controller.rb', line 291

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',
       'S0091', 'S0092', 'S0095', 'S0096', 'S0097',
       '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) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rsmp/tlc/traffic_controller.rb', line 109

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',
       'M0103', 'M0104'

    return send("handle_#{command_code.downcase}", arg)
  else
    raise UnknownCommand.new "Unknown command #{command_code}"
  end
end

#handle_m0001(arg) ⇒ Object



122
123
124
125
# File 'lib/rsmp/tlc/traffic_controller.rb', line 122

def handle_m0001 arg
  @node.verify_security_code 2, arg['securityCode']
  switch_mode arg['status']
end

#handle_m0002(arg) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/rsmp/tlc/traffic_controller.rb', line 127

def handle_m0002 arg
  @node.verify_security_code 2, arg['securityCode']
  if TrafficControllerSite.from_rsmp_bool(arg['status'])
    switch_plan arg['timeplan']
  else
    switch_plan 0   # TODO use clock/calender
  end
end

#handle_m0003(arg) ⇒ Object



136
137
138
139
# File 'lib/rsmp/tlc/traffic_controller.rb', line 136

def handle_m0003 arg
  @node.verify_security_code 2, arg['securityCode']
  @traffic_situation = arg['traficsituation'].to_i
end

#handle_m0004(arg) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/rsmp/tlc/traffic_controller.rb', line 141

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) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rsmp/tlc/traffic_controller.rb', line 149

def handle_m0005 arg
  @node.verify_security_code 2, arg['securityCode']
  @emergency_route = (arg['status'] == 'True')
  @emergency_route_number = arg['emergencyroute'].to_i

  if @emergency_route
    log "Switching to emergency route #{@emergency_route_number}", level: :info
  else
    log "Switching off emergency route", level: :info
  end
end

#handle_m0006(arg) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rsmp/tlc/traffic_controller.rb', line 161

def handle_m0006 arg
  @node.verify_security_code 2, arg['securityCode']
  input = arg['input'].to_i
  idx = input - 1
  return unless idx>=0 && input<@num_inputs # TODO should NotAck
  @input_activations[idx] = (arg['status']=='True' ? '1' : '0')
  result = @input_activations[idx]=='1' || @inputs[idx]=='1'
  @input_results[idx] = (result ? '1' : '0')
  if @input_activations[idx]
    log "Activate input #{idx}", level: :info
  else
    log "Deactivate input #{idx}", level: :info
  end
end

#handle_m0007(arg) ⇒ Object



176
177
178
179
# File 'lib/rsmp/tlc/traffic_controller.rb', line 176

def handle_m0007 arg
  @node.verify_security_code 2, arg['securityCode']
  set_fixed_time_control arg['status']
end

#handle_m0012(arg) ⇒ Object



181
182
183
# File 'lib/rsmp/tlc/traffic_controller.rb', line 181

def handle_m0012 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0013(arg) ⇒ Object



185
186
187
# File 'lib/rsmp/tlc/traffic_controller.rb', line 185

def handle_m0013 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0014(arg) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/rsmp/tlc/traffic_controller.rb', line 195

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) ⇒ Object



207
208
209
# File 'lib/rsmp/tlc/traffic_controller.rb', line 207

def handle_m0015 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0016(arg) ⇒ Object



211
212
213
# File 'lib/rsmp/tlc/traffic_controller.rb', line 211

def handle_m0016 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0017(arg) ⇒ Object



215
216
217
# File 'lib/rsmp/tlc/traffic_controller.rb', line 215

def handle_m0017 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0018(arg) ⇒ Object



219
220
221
# File 'lib/rsmp/tlc/traffic_controller.rb', line 219

def handle_m0018 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0019(arg) ⇒ Object



223
224
225
# File 'lib/rsmp/tlc/traffic_controller.rb', line 223

def handle_m0019 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0020(arg) ⇒ Object



227
228
229
# File 'lib/rsmp/tlc/traffic_controller.rb', line 227

def handle_m0020 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0021(arg) ⇒ Object



231
232
233
# File 'lib/rsmp/tlc/traffic_controller.rb', line 231

def handle_m0021 arg
  @node.verify_security_code 2, arg['securityCode']
end

#handle_m0103(arg) ⇒ Object



235
236
237
238
# File 'lib/rsmp/tlc/traffic_controller.rb', line 235

def handle_m0103 arg
  level = {'Level1'=>1,'Level2'=>2}[arg['status']]
  @node.change_security_code level, arg['oldSecurityCode'], arg['newSecurityCode']
end

#handle_m0104(arg) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/rsmp/tlc/traffic_controller.rb', line 240

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'
  )
  @node.clock.set time
  log "Clock set to #{time}, (adjustment is #{@node.clock.adjustment}s)", level: :info
end

#handle_s0001(status_code, status_name = nil) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/rsmp/tlc/traffic_controller.rb', line 306

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 @pos.to_s
  when 'basecyclecounter'
    TrafficControllerSite.make_status @pos.to_s
  when 'stage'
    TrafficControllerSite.make_status 0.to_s
  end
end

#handle_s0002(status_code, status_name = nil) ⇒ Object



319
320
321
322
323
324
# File 'lib/rsmp/tlc/traffic_controller.rb', line 319

def handle_s0002 status_code, status_name=nil
  case status_name
  when 'detectorlogicstatus'
    TrafficControllerSite.make_status @detector_logics.map { |dl| dl.value ? '1' : '0' }.join
  end
end

#handle_s0003(status_code, status_name = nil) ⇒ Object



326
327
328
329
330
331
332
333
# File 'lib/rsmp/tlc/traffic_controller.rb', line 326

def handle_s0003 status_code, status_name=nil
  case status_name
  when 'inputstatus'
    TrafficControllerSite.make_status @input_results
  when 'extendedinputstatus'
    TrafficControllerSite.make_status 0.to_s
  end
end

#handle_s0004(status_code, status_name = nil) ⇒ Object



335
336
337
338
339
340
341
342
# File 'lib/rsmp/tlc/traffic_controller.rb', line 335

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) ⇒ Object



344
345
346
347
348
349
# File 'lib/rsmp/tlc/traffic_controller.rb', line 344

def handle_s0005 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status @is_starting
  end
end

#handle_s0006(status_code, status_name = nil) ⇒ Object



351
352
353
354
355
356
357
358
# File 'lib/rsmp/tlc/traffic_controller.rb', line 351

def handle_s0006 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status @emergency_route
  when 'emergencystage'
    TrafficControllerSite.make_status @emergency_route_number
  end
end

#handle_s0007(status_code, status_name = nil) ⇒ Object



360
361
362
363
364
365
366
367
# File 'lib/rsmp/tlc/traffic_controller.rb', line 360

def handle_s0007 status_code, status_name=nil
  case status_name
  when 'intersection'
    TrafficControllerSite.make_status @intersection
  when 'status'
    TrafficControllerSite.make_status !@dark_mode
  end
end

#handle_s0008(status_code, status_name = nil) ⇒ Object



369
370
371
372
373
374
375
376
# File 'lib/rsmp/tlc/traffic_controller.rb', line 369

def handle_s0008 status_code, status_name=nil
  case status_name
  when 'intersection'
    TrafficControllerSite.make_status @intersection
  when 'status'
    TrafficControllerSite.make_status @manual_control
  end
end

#handle_s0009(status_code, status_name = nil) ⇒ Object



378
379
380
381
382
383
384
385
# File 'lib/rsmp/tlc/traffic_controller.rb', line 378

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
  end
end

#handle_s0010(status_code, status_name = nil) ⇒ Object



387
388
389
390
391
392
393
394
# File 'lib/rsmp/tlc/traffic_controller.rb', line 387

def handle_s0010 status_code, status_name=nil
  case status_name
  when 'intersection'
    TrafficControllerSite.make_status @intersection
  when 'status'
    TrafficControllerSite.make_status @isolated_control
  end
end

#handle_s0011(status_code, status_name = nil) ⇒ Object



396
397
398
399
400
401
402
403
# File 'lib/rsmp/tlc/traffic_controller.rb', line 396

def handle_s0011 status_code, status_name=nil
  case status_name
  when 'intersection'
    TrafficControllerSite.make_status @intersection
  when 'status'
    TrafficControllerSite.make_status @yellow_flash
  end
end

#handle_s0012(status_code, status_name = nil) ⇒ Object



405
406
407
408
409
410
411
412
# File 'lib/rsmp/tlc/traffic_controller.rb', line 405

def handle_s0012 status_code, status_name=nil
  case status_name
  when 'intersection'
    TrafficControllerSite.make_status @intersection
  when 'status'
    TrafficControllerSite.make_status @all_red
  end
end

#handle_s0013(status_code, status_name = nil) ⇒ Object



414
415
416
417
418
419
420
421
# File 'lib/rsmp/tlc/traffic_controller.rb', line 414

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) ⇒ Object



423
424
425
426
427
428
# File 'lib/rsmp/tlc/traffic_controller.rb', line 423

def handle_s0014 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status @plan
  end
end

#handle_s0015(status_code, status_name = nil) ⇒ Object



430
431
432
433
434
435
# File 'lib/rsmp/tlc/traffic_controller.rb', line 430

def handle_s0015 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status @traffic_situation
  end
end

#handle_s0016(status_code, status_name = nil) ⇒ Object



437
438
439
440
441
442
# File 'lib/rsmp/tlc/traffic_controller.rb', line 437

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) ⇒ Object



444
445
446
447
448
449
# File 'lib/rsmp/tlc/traffic_controller.rb', line 444

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) ⇒ Object



451
452
453
454
455
456
# File 'lib/rsmp/tlc/traffic_controller.rb', line 451

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) ⇒ Object



458
459
460
461
462
463
# File 'lib/rsmp/tlc/traffic_controller.rb', line 458

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) ⇒ Object



465
466
467
468
469
470
471
472
# File 'lib/rsmp/tlc/traffic_controller.rb', line 465

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) ⇒ Object



474
475
476
477
478
479
# File 'lib/rsmp/tlc/traffic_controller.rb', line 474

def handle_s0021 status_code, status_name=nil
  case status_name
  when 'detectorlogics'
    TrafficControllerSite.make_status @detector_logics.map { |logic| logic.forced=='True' ? '1' : '0'}.join
  end
end

#handle_s0022(status_code, status_name = nil) ⇒ Object



481
482
483
484
485
486
# File 'lib/rsmp/tlc/traffic_controller.rb', line 481

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) ⇒ Object



488
489
490
491
492
493
494
495
# File 'lib/rsmp/tlc/traffic_controller.rb', line 488

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) ⇒ Object



497
498
499
500
501
502
# File 'lib/rsmp/tlc/traffic_controller.rb', line 497

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) ⇒ Object



504
505
506
507
508
509
# File 'lib/rsmp/tlc/traffic_controller.rb', line 504

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) ⇒ Object



511
512
513
514
515
516
# File 'lib/rsmp/tlc/traffic_controller.rb', line 511

def handle_s0027 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status '00-00-00-00'
  end
end

#handle_s0028(status_code, status_name = nil) ⇒ Object



518
519
520
521
522
523
# File 'lib/rsmp/tlc/traffic_controller.rb', line 518

def handle_s0028 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status '00-00'
  end
end

#handle_s0029(status_code, status_name = nil) ⇒ Object



525
526
527
528
529
530
# File 'lib/rsmp/tlc/traffic_controller.rb', line 525

def handle_s0029 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status ''
  end
end

#handle_s0030(status_code, status_name = nil) ⇒ Object



532
533
534
535
536
537
# File 'lib/rsmp/tlc/traffic_controller.rb', line 532

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) ⇒ Object



539
540
541
542
543
544
# File 'lib/rsmp/tlc/traffic_controller.rb', line 539

def handle_s0031 status_code, status_name=nil
  case status_name
  when 'status'
    TrafficControllerSite.make_status ''
  end
end

#handle_s0091(status_code, status_name = nil) ⇒ Object



546
547
548
549
550
551
552
553
# File 'lib/rsmp/tlc/traffic_controller.rb', line 546

def handle_s0091 status_code, status_name=nil
  case status_name
  when 'user'
    TrafficControllerSite.make_status 'nobody'
  when 'status'
    TrafficControllerSite.make_status 'logout'
  end
end

#handle_s0092(status_code, status_name = nil) ⇒ Object



555
556
557
558
559
560
561
562
# File 'lib/rsmp/tlc/traffic_controller.rb', line 555

def handle_s0092 status_code, status_name=nil
  case status_name
  when 'user'
    TrafficControllerSite.make_status 'nobody'
  when 'status'
    TrafficControllerSite.make_status 'logout'
  end
end

#handle_s0095(status_code, status_name = nil) ⇒ Object



564
565
566
567
568
569
# File 'lib/rsmp/tlc/traffic_controller.rb', line 564

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) ⇒ Object



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/rsmp/tlc/traffic_controller.rb', line 571

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) ⇒ Object



589
590
591
592
593
594
595
596
597
# File 'lib/rsmp/tlc/traffic_controller.rb', line 589

def handle_s0097 status_code, status_name=nil
  case status_name
  when 'checksum'
    TrafficControllerSite.make_status '1'
  when 'timestamp'
    now = @node.clock.to_s
    TrafficControllerSite.make_status now
  end
end

#handle_s0205(status_code, status_name = nil) ⇒ Object



599
600
601
602
603
604
605
606
# File 'lib/rsmp/tlc/traffic_controller.rb', line 599

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) ⇒ Object



608
609
610
611
612
613
614
615
# File 'lib/rsmp/tlc/traffic_controller.rb', line 608

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) ⇒ Object



617
618
619
620
621
622
623
624
# File 'lib/rsmp/tlc/traffic_controller.rb', line 617

def handle_s0207 status_code, status_name=nil
  case status_name
  when 'start'
    TrafficControllerSite.make_status clock.to_s
  when 'occupancy'
    TrafficControllerSite.make_status 0
  end
end

#handle_s0208(status_code, status_name = nil) ⇒ Object



626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/rsmp/tlc/traffic_controller.rb', line 626

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

#move(pos) ⇒ Object



77
78
79
80
81
82
# File 'lib/rsmp/tlc/traffic_controller.rb', line 77

def move pos
  @signal_groups.each do |group|
    group.move pos
  end
  #output_states
end

#output_statesObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rsmp/tlc/traffic_controller.rb', line 84

def output_states
  str = @signal_groups.map do |group|
    s = "#{group.c_id}:#{group.state}"
    if group.state =~ /^[1-9]$/
        s.colorize(:green)
    elsif group.state =~ /^[NOP]$/
      s.colorize(:yellow)
    elsif group.state =~ /^[a]$/
      s.colorize(color: :black)
    else
      s.colorize(:red)
    end
  end.join ' '
  plan = "P#{@plan}"
  print "#{plan.rjust(4)} #{pos.to_s.rjust(4)} #{str}\r"
end

#resetObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rsmp/tlc/traffic_controller.rb', line 21

def reset
  @pos = 0
  @plan = 0
  @dark_mode = false
  @yellow_flash = false
  @booting = false
  @control_mode = 'control'
  @police_key = 0
  @intersection = 0
  @is_starting = false
  @emergency_route = false
  @emergency_route_number = 0
  @traffic_situation = 0
  @manual_control = false
  @fixed_time_control = false
  @isolated_control = false
  @yellow_flash = false
  @all_red = false

  @inputs = '0'*@num_inputs
  @input_activations = '0'*@num_inputs
  @input_results = '0'*@num_inputs
end

#set_fixed_time_control(status) ⇒ Object



260
261
262
# File 'lib/rsmp/tlc/traffic_controller.rb', line 260

def set_fixed_time_control status
  @fixed_time_control = status
end

#set_input(i, value) ⇒ Object



255
256
257
258
# File 'lib/rsmp/tlc/traffic_controller.rb', line 255

def set_input i, value
  return unless i>=0 && i<@num_inputs
  @inputs[i] = (arg['value'] ? '1' : '0')
end

#switch_mode(mode) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/rsmp/tlc/traffic_controller.rb', line 275

def switch_mode mode
  log "Switching to mode #{mode}", level: :info
  case mode
  when 'NormalControl'
    @yellow_flash = false
    @dark_mode = false
  when 'YellowFlash'
    @yellow_flash = true
    @dark_mode = false
  when 'Dark'
    @yellow_flash = false
    @dark_mode = true
  end
  mode
end

#switch_plan(plan) ⇒ Object



264
265
266
267
268
269
270
271
272
273
# File 'lib/rsmp/tlc/traffic_controller.rb', line 264

def switch_plan plan
  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
end

#timer(now) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/rsmp/tlc/traffic_controller.rb', line 66

def timer now
  # TODO
  # We should use a monotone timer, to avoid jumps
  # in case the user sets the system time
  pos = Time.now.to_i % @cycle_time
  if pos != @pos
    @pos = pos
    move pos
  end
end