Class: RSMP::AlarmState
- Inherits:
-
Object
- Object
- RSMP::AlarmState
- Defined in:
- lib/rsmp/component/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:, **options) ⇒ 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:, **options) ⇒ AlarmState
Returns a new instance of AlarmState.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rsmp/component/alarm_state.rb', line 22 def initialize(component:, code:, **) @component = component @component_id = component.c_id @code = code @suspended = [:suspended] == true @acknowledged = [:acknowledged] == true @active = [:active] == true @timestamp = [:timestamp] @category = [:category] || 'D' @priority = [:priority] || 2 @rvs = [:rvs] || [] end |
Instance Attribute Details
#acknowledged ⇒ Object (readonly)
Returns the value of attribute acknowledged.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def acknowledged @acknowledged end |
#active ⇒ Object (readonly)
Returns the value of attribute active.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def active @active end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def category @category end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def code @code end |
#component_id ⇒ Object (readonly)
Returns the value of attribute component_id.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def component_id @component_id end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def priority @priority end |
#rvs ⇒ Object (readonly)
Returns the value of attribute rvs.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def rvs @rvs end |
#suspended ⇒ Object (readonly)
Returns the value of attribute suspended.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def suspended @suspended end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/rsmp/component/alarm_state.rb', line 7 def @timestamp end |
Class Method Details
.create_from_message(component, message) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rsmp/component/alarm_state.rb', line 9 def self.(component, ) = { 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') } new(component: component, code: .attribute('aCId'), **) end |
Instance Method Details
#acknowledge ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rsmp/component/alarm_state.rb', line 49 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
73 74 75 76 77 78 79 |
# File 'lib/rsmp/component/alarm_state.rb', line 73 def activate change = !@active @active = true @acknowledged = false if change change end |
#clear_timestamp ⇒ Object
104 105 106 |
# File 'lib/rsmp/component/alarm_state.rb', line 104 def @timestamp = nil end |
#deactivate ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rsmp/component/alarm_state.rb', line 81 def deactivate change = @active @active = false if change change end |
#differ_from_message?(message) ⇒ Boolean
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rsmp/component/alarm_state.rb', line 92 def () return true if () return true if acknowledgment_differs?() return true if suspension_differs?() return true if activity_differs?() return true if category_differs?() return true if priority_differs?() # return true @rvs = message.attribute('rvs') false end |
#older_message?(message) ⇒ Boolean
108 109 110 111 112 |
# File 'lib/rsmp/component/alarm_state.rb', line 108 def () return false if @timestamp.nil? RSMP::Clock.parse(.attribute('aTs')) < @timestamp end |
#resume ⇒ Object
63 64 65 66 67 68 |
# File 'lib/rsmp/component/alarm_state.rb', line 63 def resume change = @suspended @suspended = false if change change end |
#suspend ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rsmp/component/alarm_state.rb', line 56 def suspend change = !@suspended @suspended = true if change change end |
#to_hash ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rsmp/component/alarm_state.rb', line 35 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rsmp/component/alarm_state.rb', line 116 def () unless raise RepeatedAlarmError, "no changes from previous alarm #{.m_id_short}" end raise TimestampError, "timestamp is earlier than previous alarm #{.m_id_short}" if 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
88 89 90 |
# File 'lib/rsmp/component/alarm_state.rb', line 88 def @timestamp = @component.now end |