Module: RSMP::TLC::Modules::System

Included in:
TrafficController
Defined in:
lib/rsmp/tlc/modules/system.rb

Overview

System-level commands and status for traffic controllers Handles restart, emergency routes, security, clock, version, and configuration

Instance Method Summary collapse

Instance Method Details

#clockObject



7
8
9
# File 'lib/rsmp/tlc/modules/system.rb', line 7

def clock
  node.clock
end

#datetime_componentsObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/rsmp/tlc/modules/system.rb', line 85

def datetime_components
  {
    'year' => [4, :year],
    'month' => [2, :month],
    'day' => [2, :day],
    'hour' => [2, :hour],
    'minute' => [2, :min],
    'second' => [2, :sec]
  }
end

#handle_m0004(arg, _options = {}) ⇒ Object

M0004 - Restart traffic light controller



12
13
14
15
16
17
18
# File 'lib/rsmp/tlc/modules/system.rb', line 12

def handle_m0004(arg, _options = {})
  @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_m0103(arg, _options = {}) ⇒ Object

M0103 - Set security code



21
22
23
24
# File 'lib/rsmp/tlc/modules/system.rb', line 21

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

#handle_m0104(arg, _options = {}) ⇒ Object

M0104 - Set clock



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rsmp/tlc/modules/system.rb', line 27

def handle_m0104(arg, _options = {})
  @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_s0005(_status_code, status_name = nil, _options = {}) ⇒ Object

S0005 - Traffic controller starting



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rsmp/tlc/modules/system.rb', line 43

def handle_s0005(_status_code, status_name = nil, _options = {})
  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_s0091(_status_code, status_name = nil, _options = {}) ⇒ Object

S0091 - Operator logged in/out OP-panel



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

def handle_s0091(_status_code, status_name = nil, _options = {})
  case status_name
  when 'user'
    TrafficControllerSite.make_status 0
  when 'username'
    TrafficControllerSite.make_status ''
  end
end

#handle_s0092(_status_code, status_name = nil, _options = {}) ⇒ Object

S0092 - Operator logged in/out web-interface



76
77
78
79
80
81
82
83
# File 'lib/rsmp/tlc/modules/system.rb', line 76

def handle_s0092(_status_code, status_name = nil, _options = {})
  case status_name
  when 'user'
    TrafficControllerSite.make_status 0
  when 'username'
    TrafficControllerSite.make_status ''
  end
end

#handle_s0095(_status_code, status_name = nil, _options = {}) ⇒ Object

S0095 - Version information



58
59
60
61
62
63
# File 'lib/rsmp/tlc/modules/system.rb', line 58

def handle_s0095(_status_code, status_name = nil, _options = {})
  case status_name
  when 'status'
    TrafficControllerSite.make_status RSMP::VERSION
  end
end

#handle_s0096(_status_code, status_name = nil, _options = {}) ⇒ Object

S0096 - Current date and time



97
98
99
100
101
102
103
104
# File 'lib/rsmp/tlc/modules/system.rb', line 97

def handle_s0096(_status_code, status_name = nil, _options = {})
  component = datetime_components[status_name]
  return nil unless component

  width, method = component
  now = clock.now
  TrafficControllerSite.make_status format_datetime_component(now.send(method), width)
end