Class: RSMP::AlarmState
- Inherits:
-
Object
- Object
- RSMP::AlarmState
- Defined in:
- lib/rsmp/alarm_state.rb
Overview
The state of an alarm on a component. The alarm state is for a particular alarm code, a component typically have an alarm state for each alarm code that is defined for the component type.
Instance Attribute Summary collapse
-
#acknowledged ⇒ Object
readonly
Returns the value of attribute acknowledged.
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#component_id ⇒ Object
readonly
Returns the value of attribute component_id.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#rvs ⇒ Object
readonly
Returns the value of attribute rvs.
-
#suspended ⇒ Object
readonly
Returns the value of attribute suspended.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #acknowledge ⇒ Object
-
#activate ⇒ Object
according to the rsmp core spec, the only time an alarm changes to unanknowledged, is when it’s activated.
- #clear_timestamp ⇒ Object
- #deactivate ⇒ Object
- #differ_from_message?(message) ⇒ Boolean
-
#initialize(component:, code:, suspended: false, acknowledged: false, active: false, timestamp: nil, category: 'D', priority: 2, rvs: []) ⇒ AlarmState
constructor
A new instance of AlarmState.
- #older_message?(message) ⇒ Boolean
- #resume ⇒ Object
- #suspend ⇒ Object
- #to_hash ⇒ Object
-
#update_from_message(message) ⇒ Object
update from rsmp message component id, alarm code and specialization are not updated.
- #update_timestamp ⇒ Object
Constructor Details
#initialize(component:, code:, suspended: false, acknowledged: false, active: false, timestamp: nil, category: 'D', priority: 2, rvs: []) ⇒ AlarmState
Returns a new instance of AlarmState.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rsmp/alarm_state.rb', line 25 def initialize component:, code:, suspended: false, acknowledged: false, active: false, timestamp: nil, category: 'D', priority: 2, rvs: [] @component = component @component_id = component.c_id @code = code @suspended = !!suspended @acknowledged = !!acknowledged @active = !!active @timestamp = @category = category || 'D' @priority = priority || 2 @rvs = rvs end |
Instance Attribute Details
#acknowledged ⇒ Object (readonly)
Returns the value of attribute acknowledged.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def acknowledged @acknowledged end |
#active ⇒ Object (readonly)
Returns the value of attribute active.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def active @active end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def category @category end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def code @code end |
#component_id ⇒ Object (readonly)
Returns the value of attribute component_id.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def component_id @component_id end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def priority @priority end |
#rvs ⇒ Object (readonly)
Returns the value of attribute rvs.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def rvs @rvs end |
#suspended ⇒ Object (readonly)
Returns the value of attribute suspended.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def suspended @suspended end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
9 10 11 |
# File 'lib/rsmp/alarm_state.rb', line 9 def @timestamp end |
Class Method Details
.create_from_message(component, message) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rsmp/alarm_state.rb', line 11 def self. component, self.new( component: component, code: .attribute("aCId"), timestamp: RSMP::Clock.parse(.attribute('aTs')), acknowledged: .attribute('ack') == 'Acknowledged', suspended: .attribute('aS') == 'Suspended', active: .attribute('sS') == 'Active', category: .attribute('cat'), priority: .attribute('pri').to_i, rvs: .attribute('rvs') ) end |
Instance Method Details
#acknowledge ⇒ Object
54 55 56 57 58 |
# File 'lib/rsmp/alarm_state.rb', line 54 def acknowledge change, @acknowledged = !@acknowledged, true if change change end |
#activate ⇒ Object
according to the rsmp core spec, the only time an alarm changes to unanknowledged, is when it’s activated. See: rsmp-nordic.org/rsmp_specifications/core/3.2.0/applicability/basic_structure.html#alarm-status
75 76 77 78 79 |
# File 'lib/rsmp/alarm_state.rb', line 75 def activate change, @active, @acknowledged = !@active, true, false if change change end |
#clear_timestamp ⇒ Object
102 103 104 |
# File 'lib/rsmp/alarm_state.rb', line 102 def @timestamp = nil end |
#deactivate ⇒ Object
81 82 83 84 85 |
# File 'lib/rsmp/alarm_state.rb', line 81 def deactivate change, @active = @active, false if change change end |
#differ_from_message?(message) ⇒ Boolean
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rsmp/alarm_state.rb', line 91 def return true if RSMP::Clock.to_s(@timestamp) != .attribute('aTs') return true if .attribute('ack') && @acknowledged != (.attribute('ack').downcase == 'acknowledged') return true if .attribute('sS') && @suspended != (.attribute('sS').downcase == 'suspended') return true if .attribute('aS') && @active != (.attribute('aS').downcase == 'active') return true if .attribute('cat') && @category != .attribute('cat') return true if .attribute('pri') && @priority != .attribute('pri').to_i #return true @rvs = message.attribute('rvs') false end |
#older_message?(message) ⇒ Boolean
106 107 108 109 |
# File 'lib/rsmp/alarm_state.rb', line 106 def return false if @timestamp == nil RSMP::Clock.parse(.attribute('aTs')) < @timestamp end |
#resume ⇒ Object
66 67 68 69 70 |
# File 'lib/rsmp/alarm_state.rb', line 66 def resume change, @suspended = @suspended, false if change change end |
#suspend ⇒ Object
60 61 62 63 64 |
# File 'lib/rsmp/alarm_state.rb', line 60 def suspend change, @suspended = !@suspended, true if change change end |
#to_hash ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rsmp/alarm_state.rb', line 40 def to_hash { 'cId' => @component_id, 'aCId' => @code, 'aTs' => Clock.to_s(@timestamp), 'ack' => (@acknowledged ? 'Acknowledged' : 'notAcknowledged'), 'sS' => (@suspended ? 'Suspended' : 'notSuspended'), 'aS' => (@active ? 'Active' : 'inActive'), 'cat' => @category, 'pri' => @priority.to_s, 'rvs' => @rvs } end |
#update_from_message(message) ⇒ Object
update from rsmp message component id, alarm code and specialization are not updated
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rsmp/alarm_state.rb', line 113 def unless raise RepeatedAlarmError.new("no changes from previous alarm #{.m_id_short}") end if raise TimestampError.new("timestamp is earlier than previous alarm #{.m_id_short}") end ensure @timestamp = RSMP::Clock.parse .attribute('aTs') @acknowledged = .attribute('ack') == 'True' @suspended = .attribute('sS') == 'True' @active = .attribute('aS') == 'True' @category = .attribute('cat') @priority = .attribute('pri').to_i @rvs = .attribute('rvs') end |
#update_timestamp ⇒ Object
87 88 89 |
# File 'lib/rsmp/alarm_state.rb', line 87 def @timestamp = @component.now end |