Class: RSMP::Component

Inherits:
Object
  • Object
show all
Includes:
Inspect
Defined in:
lib/rsmp/component.rb

Direct Known Subclasses

DetectorLogic, SignalGroup, TrafficController

Constant Summary collapse

AGGREGATED_STATUS_KEYS =
[ :local_control,
:communication_distruption,
:high_priority_alarm,
:medium_priority_alarm,
:low_priority_alarm,
:normal,
:rest,
:not_connected ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:, grouped:) ⇒ Component

Returns a new instance of Component.


16
17
18
19
20
21
22
23
# File 'lib/rsmp/component.rb', line 16

def initialize node:, id:, grouped:
  @c_id = id
  @node = node
  @grouped = grouped
  @alarms = {}
  @statuses = {}
  clear_aggregated_status
end

Instance Attribute Details

#aggregated_statusObject (readonly)

Returns the value of attribute aggregated_status.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def aggregated_status
  @aggregated_status
end

#aggregated_status_boolsObject (readonly)

Returns the value of attribute aggregated_status_bools.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def aggregated_status_bools
  @aggregated_status_bools
end

#alarmsObject (readonly)

Returns the value of attribute alarms.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def alarms
  @alarms
end

#c_idObject (readonly)

Returns the value of attribute c_id.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def c_id
  @c_id
end

#groupedObject (readonly)

Returns the value of attribute grouped.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def grouped
  @grouped
end

#nodeObject (readonly)

Returns the value of attribute node.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def node
  @node
end

#statusesObject (readonly)

Returns the value of attribute statuses.


5
6
7
# File 'lib/rsmp/component.rb', line 5

def statuses
  @statuses
end

Instance Method Details

#aggregated_status_changed(options = {}) ⇒ Object


57
58
59
# File 'lib/rsmp/component.rb', line 57

def aggregated_status_changed options={}
  @node.aggregated_status_changed self, options
end

#alarm(code:, status:) ⇒ Object


61
62
# File 'lib/rsmp/component.rb', line 61

def alarm code:, status:
end

#clear_aggregated_statusObject


25
26
27
28
29
# File 'lib/rsmp/component.rb', line 25

def clear_aggregated_status
  @aggregated_status = []
  @aggregated_status_bools = Array.new(8,false)
  @aggregated_status_bools[5] = true
end

#get_status(status_code, status_name = nil) ⇒ Object


72
73
74
# File 'lib/rsmp/component.rb', line 72

def get_status status_code, status_name=nil
  raise UnknownStatus.new "Status #{status_code}/#{status_name} not implemented by #{self.class}"
end

#handle_command(command_code, arg) ⇒ Object


68
69
70
# File 'lib/rsmp/component.rb', line 68

def handle_command command_code, arg
  raise UnknownCommand.new "Command #{command_code} not implemented by #{self.class}"
end

#log(str, options) ⇒ Object


64
65
66
# File 'lib/rsmp/component.rb', line 64

def log str, options
  @node.log str, options
end

#set_aggregated_status(status, options = {}) ⇒ Object

Raises:

  • (InvalidArgument)

31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rsmp/component.rb', line 31

def set_aggregated_status status, options={}
  status = [status] if status.is_a? Symbol
  raise InvalidArgument unless status.is_a? Array
  input = status & AGGREGATED_STATUS_KEYS
  if input != @aggregated_status
    AGGREGATED_STATUS_KEYS.each_with_index do |key,index|
      @aggregated_status_bools[index] = status.include?(key)
    end
    aggregated_status_changed options
  end
end

#set_aggregated_status_bools(status) ⇒ Object

Raises:

  • (InvalidArgument)

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

def set_aggregated_status_bools status
  raise InvalidArgument unless status.is_a? Array
  raise InvalidArgument unless status.size == 8
  if status != @aggregated_status_bools
    @aggregated_status = []
    AGGREGATED_STATUS_KEYS.each_with_index do |key,index|
      on = status[index] == true
      @aggregated_status_bools[index] = on
      @aggregated_status << key if on
    end
    aggregated_status_changed
  end
end