Class: RSMP::AlarmState
- Inherits:
-
Object
- Object
- RSMP::AlarmState
- Defined in:
- lib/rsmp/alarm_state.rb
Overview
class that tracks the state of an alarm
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.
Instance Method Summary collapse
- #activate ⇒ Object
- #deactivate ⇒ Object
- #differ_from_message?(message) ⇒ Boolean
-
#initialize(component:, code:) ⇒ AlarmState
constructor
A new instance of AlarmState.
- #resume ⇒ Object
- #suspend ⇒ Object
- #to_hash ⇒ Object
- #to_message(specialization:) ⇒ 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:) ⇒ AlarmState
Returns a new instance of AlarmState.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rsmp/alarm_state.rb', line 6 def initialize component:, code: @component = component @component_id = component.c_id @code = code @suspended = false @acknowledged = false @suspended = false @active = false @timestamp = nil @category = 'D' @priority = 2 @rvs = [] end |
Instance Attribute Details
#acknowledged ⇒ Object (readonly)
Returns the value of attribute acknowledged.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def acknowledged @acknowledged end |
#active ⇒ Object (readonly)
Returns the value of attribute active.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def active @active end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def category @category end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def code @code end |
#component_id ⇒ Object (readonly)
Returns the value of attribute component_id.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def component_id @component_id end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def priority @priority end |
#rvs ⇒ Object (readonly)
Returns the value of attribute rvs.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def rvs @rvs end |
#suspended ⇒ Object (readonly)
Returns the value of attribute suspended.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def suspended @suspended end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/rsmp/alarm_state.rb', line 4 def @timestamp end |
Instance Method Details
#activate ⇒ Object
45 46 47 48 49 |
# File 'lib/rsmp/alarm_state.rb', line 45 def activate change, @active = !@active, true if change change end |
#deactivate ⇒ Object
51 52 53 54 55 |
# File 'lib/rsmp/alarm_state.rb', line 51 def deactivate change, @active = @active, false if change change end |
#differ_from_message?(message) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rsmp/alarm_state.rb', line 76 def return true if @timestamp != .attribute('aTs') return true if .attribute('ack') && @acknowledged != (.attribute('ack') == 'True') return true if .attribute('sS') && @suspended != (.attribute('sS') == 'True') return true if .attribute('aS') && @active != (.attribute('aS') == 'True') 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 |
#resume ⇒ Object
39 40 41 42 43 |
# File 'lib/rsmp/alarm_state.rb', line 39 def resume change, @suspended = @suspended, false if change change end |
#suspend ⇒ Object
33 34 35 36 37 |
# File 'lib/rsmp/alarm_state.rb', line 33 def suspend change, @suspended = !@suspended, true if change change end |
#to_hash ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rsmp/alarm_state.rb', line 20 def to_hash { 'cId' => component_id, 'aCId' => code, 'aTs' => Clock.to_s(), 'ack' => (acknowledged ? 'Acknowledged' : 'notAcknowledged'), 'sS' => (suspended ? 'suspended' : 'notSuspended'), 'aS' => (active ? 'Active' : 'inActive'), 'cat' => category, 'pri' => priority.to_s, 'rvs' => rvs } end |
#to_message(specialization:) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rsmp/alarm_state.rb', line 61 def specialization: Alarm.new( 'cId' => @component_id, 'aSp' => specialization, '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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rsmp/alarm_state.rb', line 89 def unless raise RepeatedAlarmError.new("no changes from previous alarm #{.m_id_short}") end if Time.parse(.attribute('aTs')) < Time.parse(.attribute('aTs')) raise TimestampError.new("timestamp is earlier than previous alarm #{.m_id_short}") end ensure @timestamp = .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
57 58 59 |
# File 'lib/rsmp/alarm_state.rb', line 57 def @timestamp = @component.node.clock.now end |