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
10
# File 'lib/rsmp/tlc/signal_group.rb', line 7

def initialize node:, id:
  super node: node, id: id, grouped: false
  move 0
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

#get_state(pos) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rsmp/tlc/signal_group.rb', line 12

def get_state pos
  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[pos]
  return default unless state =~ /[a-hA-G0-9N-P]/  # valid signal group states
  state
end

#get_status(code, name = nil) ⇒ Object



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

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



28
29
30
31
32
33
34
35
# File 'lib/rsmp/tlc/signal_group.rb', line 28

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



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

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



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

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rsmp/tlc/signal_group.rb', line 62

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

#move(pos) ⇒ Object



24
25
26
# File 'lib/rsmp/tlc/signal_group.rb', line 24

def move pos
  @state = get_state pos
end