Class: RSMP::TLC::DetectorLogic

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

Constant Summary

Constants inherited from ComponentBase

ComponentBase::AGGREGATED_STATUS_KEYS

Instance Attribute Summary collapse

Attributes inherited from ComponentBase

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

Instance Method Summary collapse

Methods inherited from Component

#acknowledge_alarm, #activate_alarm, #deactivate_alarm, #resume_alarm, #status_updates_sent, #suspend_alarm

Methods inherited from ComponentBase

#aggregated_status_changed, #clear_aggregated_status, #clear_alarm_timestamps, #get_alarm_state, #log, #now, #set_aggregated_status

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:) ⇒ DetectorLogic

Returns a new instance of DetectorLogic.



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

def initialize(node:, id:)
  super(node: node, id: id, grouped: false)
  @forced = 0
  @value = 0
end

Instance Attribute Details

#forcedObject (readonly)

Returns the value of attribute forced.



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

def forced
  @forced
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#force_detector_logic(forced, value) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/rsmp/tlc/detector_logic.rb', line 74

def force_detector_logic(forced, value)
  @forced = forced
  @value = value
  if @forced
    log "Forcing to #{value}", level: :info
  else
    log 'Releasing', level: :info
  end
end

#get_status(code, name = nil, _options = {}) ⇒ Object



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

def get_status(code, name = nil, _options = {})
  case code
  when 'S0201', 'S0202', 'S0203', 'S0204'
    send("handle_#{code.downcase}", code, name)
  else
    raise InvalidMessage, "unknown status code #{code}"
  end
end

#handle_command(command_code, arg, _options = {}) ⇒ Object



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

def handle_command(command_code, arg, _options = {})
  case command_code
  when 'M0008'
    handle_m0008 arg
  else
    raise UnknownCommand, "Unknown command #{command_code}"
  end
end

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



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

def handle_m0008(arg, _options = {})
  @node.verify_security_code 2, arg['securityCode']
  status = arg['status'] == 'True'
  mode = arg['mode'] == 'True'
  force_detector_logic status, mode
  arg
end

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



21
22
23
24
25
26
27
28
# File 'lib/rsmp/tlc/detector_logic.rb', line 21

def handle_s0201(_status_code, status_name = nil, _options = {})
  case status_name
  when 'starttime'
    TrafficControllerSite.make_status @node.clock.to_s
  when 'vehicles'
    TrafficControllerSite.make_status 0
  end
end

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



30
31
32
33
34
35
36
37
# File 'lib/rsmp/tlc/detector_logic.rb', line 30

def handle_s0202(_status_code, status_name = nil, _options = {})
  case status_name
  when 'starttime'
    TrafficControllerSite.make_status @node.clock.to_s
  when 'speed'
    TrafficControllerSite.make_status 0
  end
end

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



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

def handle_s0203(_status_code, status_name = nil, _options = {})
  case status_name
  when 'starttime'
    TrafficControllerSite.make_status @node.clock.to_s
  when 'occupancy'
    TrafficControllerSite.make_status 0
  end
end

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



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

def handle_s0204(_status_code, status_name = nil, _options = {})
  case status_name
  when 'starttime'
    TrafficControllerSite.make_status @node.clock.to_s
  when 'P', 'PS', 'L', 'LS', 'B', 'SP', 'MC', 'C', 'F'
    TrafficControllerSite.make_status 0
  end
end