Class: RSMP::TLC::SignalGroup

Inherits:
Component show all
Defined in:
lib/rsmp/tlc/signal_group.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, #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:) ⇒ SignalGroup

plan is a string, with each character representing a signal phase at a particular second in the cycle



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

def initialize node:, id:
  super node: node, id: id, grouped: false
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



4
5
6
# File 'lib/rsmp/tlc/signal_group.rb', line 4

def plan
  @plan
end

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/rsmp/tlc/signal_group.rb', line 4

def state
  @state
end

Instance Method Details

#compute_stateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rsmp/tlc/signal_group.rb', line 15

def compute_state
  return 'a' if node.main.dark?
  return 'c' if node.main.yellow_flash?

  cycle_counter = node.main.cycle_counter

  if node.main.startup_sequence_active
    return node.main.startup_state || 'a'
  end

  default = 'a'   # phase a means disabled/dark
  plan = node.main.current_plan
  return default unless plan
  return default unless plan.states

  states = plan.states[c_id]
  return default unless states

  state = states[cycle_counter]
  return default unless state =~ /[a-hA-G0-9N-P]/  # valid signal group states
  state
end

#get_status(code, name = nil) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/rsmp/tlc/signal_group.rb', line 63

def get_status code, name=nil
  case code
  when 'S0025'
    return send("handle_#{code.downcase}", code, name)
  else
    raise InvalidMessage.new "unknown status code #{code}"
  end
end

#handle_command(command_code, arg) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/rsmp/tlc/signal_group.rb', line 38

def handle_command command_code, arg
  case command_code
  when 'M0010', 'M0011'
    return send("handle_#{command_code.downcase}", arg)
  else
    raise UnknownCommand.new "Unknown command #{command_code}"
  end
end

#handle_m0010(arg) ⇒ Object

Start of signal group. Orders a signal group to green



48
49
50
51
52
53
# File 'lib/rsmp/tlc/signal_group.rb', line 48

def handle_m0010 arg
  @node.verify_security_code 2, arg['securityCode']
  if TrafficControllerSite.from_rsmp_bool arg['status']
    log "Start signal group #{c_id}, go to green", level: :info
  end
end

#handle_m0011(arg) ⇒ Object

Stop of signal group. Orders a signal group to red



56
57
58
59
60
61
# File 'lib/rsmp/tlc/signal_group.rb', line 56

def handle_m0011 arg
  @node.verify_security_code 2, arg['securityCode']
  if TrafficControllerSite.from_rsmp_bool arg['status']
    log "Stop signal group #{c_id}, go to red", level: :info
  end
end

#handle_s0025(status_code, status_name = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rsmp/tlc/signal_group.rb', line 72

def handle_s0025 status_code, status_name=nil
  now = @node.clock.to_s
  case status_name
  when 'minToGEstimate'
    TrafficControllerSite.make_status now
  when 'maxToGEstimate'
    TrafficControllerSite.make_status now
  when 'likelyToGEstimate'
    TrafficControllerSite.make_status now
  when 'ToGConfidence'
    TrafficControllerSite.make_status 0
  when 'minToREstimate'
    TrafficControllerSite.make_status now
  when 'maxToREstimate'
    TrafficControllerSite.make_status now
  when 'likelyToREstimate'
    TrafficControllerSite.make_status now
  when 'ToRConfidence'
    TrafficControllerSite.make_status 0
  end
end

#timerObject



11
12
13
# File 'lib/rsmp/tlc/signal_group.rb', line 11

def timer
  @state = compute_state
end