Class: RSMP::TrafficController

Inherits:
Component show all
Defined in:
lib/rsmp/tlc.rb

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, #alarm, #clear_aggregated_status, #log, #set_aggregated_status, #set_aggregated_status_bools

Methods included from Inspect

#inspect, #inspector

Constructor Details

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

Returns a new instance of TrafficController.


8
9
10
11
12
13
14
15
16
17
# File 'lib/rsmp/tlc.rb', line 8

def initialize node:, id:, cycle_time:
  super node: node, id: id, grouped: true
  @signal_groups = []
  @detector_logics = []
  @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.


6
7
8
# File 'lib/rsmp/tlc.rb', line 6

def cycle_time
  @cycle_time
end

#posObject (readonly)

Returns the value of attribute pos.


6
7
8
# File 'lib/rsmp/tlc.rb', line 6

def pos
  @pos
end

Instance Method Details

#add_detector_logic(logic) ⇒ Object


52
53
54
# File 'lib/rsmp/tlc.rb', line 52

def add_detector_logic logic
  @detector_logics << logic
end

#add_signal_group(group) ⇒ Object


48
49
50
# File 'lib/rsmp/tlc.rb', line 48

def add_signal_group group
  @signal_groups << group
end

#clockObject


43
44
45
# File 'lib/rsmp/tlc.rb', line 43

def clock
  node.clock
end

#format_signal_group_statusObject


90
91
92
93
94
95
96
# File 'lib/rsmp/tlc.rb', line 90

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


265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/rsmp/tlc.rb', line 265

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


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rsmp/tlc.rb', line 98

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


111
112
113
114
# File 'lib/rsmp/tlc.rb', line 111

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

#handle_m0002(arg) ⇒ Object


116
117
118
119
120
121
122
123
# File 'lib/rsmp/tlc.rb', line 116

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

#handle_m0003(arg) ⇒ Object


125
126
127
128
# File 'lib/rsmp/tlc.rb', line 125

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

#handle_m0004(arg) ⇒ Object


130
131
132
133
134
135
136
# File 'lib/rsmp/tlc.rb', line 130

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


138
139
140
141
142
143
144
145
146
147
148
# File 'lib/rsmp/tlc.rb', line 138

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


150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rsmp/tlc.rb', line 150

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


165
166
167
168
# File 'lib/rsmp/tlc.rb', line 165

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

#handle_m0012(arg) ⇒ Object


170
171
172
# File 'lib/rsmp/tlc.rb', line 170

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

#handle_m0013(arg) ⇒ Object


174
175
176
# File 'lib/rsmp/tlc.rb', line 174

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

#handle_m0014(arg) ⇒ Object


178
179
180
# File 'lib/rsmp/tlc.rb', line 178

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

#handle_m0015(arg) ⇒ Object


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

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

#handle_m0016(arg) ⇒ Object


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

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

#handle_m0017(arg) ⇒ Object


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

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

#handle_m0018(arg) ⇒ Object


194
195
196
# File 'lib/rsmp/tlc.rb', line 194

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

#handle_m0019(arg) ⇒ Object


198
199
200
# File 'lib/rsmp/tlc.rb', line 198

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

#handle_m0020(arg) ⇒ Object


202
203
204
# File 'lib/rsmp/tlc.rb', line 202

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

#handle_m0021(arg) ⇒ Object


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

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

#handle_m0103(arg) ⇒ Object


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

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


215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/rsmp/tlc.rb', line 215

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


280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/rsmp/tlc.rb', line 280

def handle_s0001 status_code, status_name=nil
  case status_name
  when 'signalgroupstatus'
    RSMP::Tlc.make_status format_signal_group_status
  when 'cyclecounter'
    RSMP::Tlc.make_status @pos.to_s
  when 'basecyclecounter'
    RSMP::Tlc.make_status @pos.to_s
  when 'stage'
    RSMP::Tlc.make_status 0.to_s
  end
end

#handle_s0002(status_code, status_name = nil) ⇒ Object


293
294
295
296
297
298
# File 'lib/rsmp/tlc.rb', line 293

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

#handle_s0003(status_code, status_name = nil) ⇒ Object


300
301
302
303
304
305
306
307
# File 'lib/rsmp/tlc.rb', line 300

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

#handle_s0004(status_code, status_name = nil) ⇒ Object


309
310
311
312
313
314
315
316
# File 'lib/rsmp/tlc.rb', line 309

def handle_s0004 status_code, status_name=nil
  case status_name
  when 'outputstatus'
    RSMP::Tlc.make_status 0
  when 'extendedoutputstatus'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0005(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0006(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0007(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0008(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0009(status_code, status_name = nil) ⇒ Object


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

def handle_s0009 status_code, status_name=nil
  case status_name
  when 'intersection'
    RSMP::Tlc.make_status @intersection
  when 'status'
    RSMP::Tlc.make_status @fixed_time_control
  end
end

#handle_s0010(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0011(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0012(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0013(status_code, status_name = nil) ⇒ Object


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

def handle_s0013 status_code, status_name=nil
  case status_name
  when 'intersection'
    RSMP::Tlc.make_status @intersection
  when 'status'
    RSMP::Tlc.make_status @police_key
  end
end

#handle_s0014(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0015(status_code, status_name = nil) ⇒ Object


404
405
406
407
408
409
# File 'lib/rsmp/tlc.rb', line 404

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

#handle_s0016(status_code, status_name = nil) ⇒ Object


411
412
413
414
415
416
# File 'lib/rsmp/tlc.rb', line 411

def handle_s0016 status_code, status_name=nil
  case status_name
  when 'number'
    RSMP::Tlc.make_status @detector_logics.size
  end
end

#handle_s0017(status_code, status_name = nil) ⇒ Object


418
419
420
421
422
423
# File 'lib/rsmp/tlc.rb', line 418

def handle_s0017 status_code, status_name=nil
  case status_name
  when 'number'
    RSMP::Tlc.make_status @signal_groups.size
  end
end

#handle_s0018(status_code, status_name = nil) ⇒ Object


425
426
427
428
429
430
# File 'lib/rsmp/tlc.rb', line 425

def handle_s0018 status_code, status_name=nil
  case status_name
  when 'number'
    RSMP::Tlc.make_status @plans.size
  end
end

#handle_s0019(status_code, status_name = nil) ⇒ Object


432
433
434
435
436
437
# File 'lib/rsmp/tlc.rb', line 432

def handle_s0019 status_code, status_name=nil
  case status_name
  when 'number'
    RSMP::Tlc.make_status @num_traffic_situations
  end
end

#handle_s0020(status_code, status_name = nil) ⇒ Object


439
440
441
442
443
444
445
446
# File 'lib/rsmp/tlc.rb', line 439

def handle_s0020 status_code, status_name=nil
  case status_name
  when 'intersection'
    RSMP::Tlc.make_status @intersection
  when 'controlmode'
    RSMP::Tlc.make_status @control_mode
  end
end

#handle_s0021(status_code, status_name = nil) ⇒ Object


448
449
450
451
452
453
# File 'lib/rsmp/tlc.rb', line 448

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

#handle_s0022(status_code, status_name = nil) ⇒ Object


455
456
457
458
459
460
# File 'lib/rsmp/tlc.rb', line 455

def handle_s0022 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status '1'
  end
end

#handle_s0023(status_code, status_name = nil) ⇒ Object


462
463
464
465
466
467
# File 'lib/rsmp/tlc.rb', line 462

def handle_s0023 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status '1-1-0'
  end
end

#handle_s0024(status_code, status_name = nil) ⇒ Object


469
470
471
472
473
474
# File 'lib/rsmp/tlc.rb', line 469

def handle_s0024 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status '1-0'
  end
end

#handle_s0026(status_code, status_name = nil) ⇒ Object


476
477
478
479
480
481
# File 'lib/rsmp/tlc.rb', line 476

def handle_s0026 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status '0-00'
  end
end

#handle_s0027(status_code, status_name = nil) ⇒ Object


483
484
485
486
487
488
# File 'lib/rsmp/tlc.rb', line 483

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

#handle_s0028(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0029(status_code, status_name = nil) ⇒ Object


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

def handle_s0029 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status ''
  end
end

#handle_s0030(status_code, status_name = nil) ⇒ Object


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

def handle_s0030 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status ''
  end
end

#handle_s0031(status_code, status_name = nil) ⇒ Object


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

def handle_s0031 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status ''
  end
end

#handle_s0091(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0092(status_code, status_name = nil) ⇒ Object


527
528
529
530
531
532
533
534
# File 'lib/rsmp/tlc.rb', line 527

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

#handle_s0095(status_code, status_name = nil) ⇒ Object


536
537
538
539
540
541
# File 'lib/rsmp/tlc.rb', line 536

def handle_s0095 status_code, status_name=nil
  case status_name
  when 'status'
    RSMP::Tlc.make_status RSMP::VERSION
  end
end

#handle_s0096(status_code, status_name = nil) ⇒ Object


543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/rsmp/tlc.rb', line 543

def handle_s0096 status_code, status_name=nil
  now = clock.now
  case status_name
  when 'year'
    RSMP::Tlc.make_status now.year.to_s.rjust(4, "0")
  when 'month'
    RSMP::Tlc.make_status now.month.to_s.rjust(2, "0")
  when 'day'
    RSMP::Tlc.make_status now.day.to_s.rjust(2, "0")
  when 'hour'
    RSMP::Tlc.make_status now.hour.to_s.rjust(2, "0")
  when 'minute'
    RSMP::Tlc.make_status now.min.to_s.rjust(2, "0")
  when 'second'
    RSMP::Tlc.make_status now.sec.to_s.rjust(2, "0")
  end
end

#handle_s0097(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0205(status_code, status_name = nil) ⇒ Object


571
572
573
574
575
576
577
578
# File 'lib/rsmp/tlc.rb', line 571

def handle_s0205 status_code, status_name=nil
  case status_name
  when 'start'
    RSMP::Tlc.make_status clock.to_s
  when 'vehicles'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0206(status_code, status_name = nil) ⇒ Object


580
581
582
583
584
585
586
587
# File 'lib/rsmp/tlc.rb', line 580

def handle_s0206 status_code, status_name=nil
  case status_name
  when 'start'
    RSMP::Tlc.make_status clock.to_s
  when 'speed'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0207(status_code, status_name = nil) ⇒ Object


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

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

#handle_s0208(status_code, status_name = nil) ⇒ Object


598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/rsmp/tlc.rb', line 598

def handle_s0208 status_code, status_name=nil
  case status_name
  when 'start'
    RSMP::Tlc.make_status clock.to_s
  when 'P'
    RSMP::Tlc.make_status 0
  when 'PS'
    RSMP::Tlc.make_status 0
  when 'L'
    RSMP::Tlc.make_status 0
  when 'LS'
    RSMP::Tlc.make_status 0
  when 'B'
    RSMP::Tlc.make_status 0
  when 'SP'
    RSMP::Tlc.make_status 0
  when 'MC'
    RSMP::Tlc.make_status 0
  when 'C'
    RSMP::Tlc.make_status 0
  when 'F'
    RSMP::Tlc.make_status 0
  end
end

#move(pos) ⇒ Object


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

def move pos
  @signal_groups.each do |group|
    group.move pos
  end
  if pos == 0
    aggregated_status_changed
  end
end

#output_statesObject


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rsmp/tlc.rb', line 76

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)
    else
      s.colorize(:red)
    end
  end.join ' '
  print "\t#{pos.to_s.ljust(3)} #{str}\r"
end

#resetObject


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

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


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

def set_fixed_time_control status
  @fixed_time_control = status
end

#set_input(i, value) ⇒ Object


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

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

#switch_mode(mode) ⇒ Object


249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/rsmp/tlc.rb', line 249

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


239
240
241
242
243
244
245
246
247
# File 'lib/rsmp/tlc.rb', line 239

def switch_plan plan
  plan_nr = plan.to_i
  if plan_nr == 0
    log "Switching to plan selection by time table", level: :info
  else
    log "Switching to plan #{plan_nr}", level: :info
  end
  @plan = plan_nr
end

#timer(now) ⇒ Object


56
57
58
59
60
61
62
63
64
65
# File 'lib/rsmp/tlc.rb', line 56

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