Class: RSMP::ComponentBase
- Inherits:
-
Object
- Object
- RSMP::ComponentBase
- Includes:
- Inspect
- Defined in:
- lib/rsmp/component_base.rb
Overview
RSMP component base class.
Direct Known Subclasses
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
-
#aggregated_status ⇒ Object
readonly
Returns the value of attribute aggregated_status.
-
#aggregated_status_bools ⇒ Object
readonly
Returns the value of attribute aggregated_status_bools.
-
#alarms ⇒ Object
readonly
Returns the value of attribute alarms.
-
#c_id ⇒ Object
readonly
Returns the value of attribute c_id.
-
#grouped ⇒ Object
readonly
Returns the value of attribute grouped.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#ntsOId ⇒ Object
readonly
Returns the value of attribute ntsOId.
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
-
#xNId ⇒ Object
readonly
Returns the value of attribute xNId.
Instance Method Summary collapse
- #aggregated_status_changed(options = {}) ⇒ Object
- #clear_aggregated_status ⇒ Object
- #get_alarm_state(alarm_code) ⇒ Object
-
#initialize(node:, id:, ntsOId: nil, xNId: nil, grouped: false) ⇒ ComponentBase
constructor
A new instance of ComponentBase.
- #log(str, options) ⇒ Object
- #set_aggregated_status(status, options = {}) ⇒ Object
- #set_aggregated_status_bools(status) ⇒ Object
Methods included from Inspect
Constructor Details
#initialize(node:, id:, ntsOId: nil, xNId: nil, grouped: false) ⇒ ComponentBase
Returns a new instance of ComponentBase.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rsmp/component_base.rb', line 20 def initialize node:, id:, ntsOId: nil, xNId: nil, grouped: false if grouped==false && (ntsOId || xNId) raise RSMP::ConfigurationError.new("ntsOId and xNId are only allowed for grouped objects") end @c_id = id @ntsOId = ntsOId @xNId = xNId @node = node @grouped = grouped clear_aggregated_status @alarms = {} end |
Instance Attribute Details
#aggregated_status ⇒ Object (readonly)
Returns the value of attribute aggregated_status.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def aggregated_status @aggregated_status end |
#aggregated_status_bools ⇒ Object (readonly)
Returns the value of attribute aggregated_status_bools.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def aggregated_status_bools @aggregated_status_bools end |
#alarms ⇒ Object (readonly)
Returns the value of attribute alarms.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def alarms @alarms end |
#c_id ⇒ Object (readonly)
Returns the value of attribute c_id.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def c_id @c_id end |
#grouped ⇒ Object (readonly)
Returns the value of attribute grouped.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def grouped @grouped end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def node @node end |
#ntsOId ⇒ Object (readonly)
Returns the value of attribute ntsOId.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def ntsOId @ntsOId end |
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def statuses @statuses end |
#xNId ⇒ Object (readonly)
Returns the value of attribute xNId.
8 9 10 |
# File 'lib/rsmp/component_base.rb', line 8 def xNId @xNId end |
Instance Method Details
#aggregated_status_changed(options = {}) ⇒ Object
74 75 76 |
# File 'lib/rsmp/component_base.rb', line 74 def aggregated_status_changed ={} @node.aggregated_status_changed self, end |
#clear_aggregated_status ⇒ Object
37 38 39 40 41 |
# File 'lib/rsmp/component_base.rb', line 37 def clear_aggregated_status @aggregated_status = [] @aggregated_status_bools = Array.new(8,false) @aggregated_status_bools[5] = true end |
#get_alarm_state(alarm_code) ⇒ Object
33 34 35 |
# File 'lib/rsmp/component_base.rb', line 33 def get_alarm_state alarm_code alarm = @alarms[alarm_code] ||= RSMP::AlarmState.new component: self, code: alarm_code end |
#log(str, options) ⇒ Object
43 44 45 46 |
# File 'lib/rsmp/component_base.rb', line 43 def log str, default = { component: c_id} @node.log str, default.merge() end |
#set_aggregated_status(status, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rsmp/component_base.rb', line 48 def set_aggregated_status status, ={} 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 end end |
#set_aggregated_status_bools(status) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rsmp/component_base.rb', line 60 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 |