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
- #acknowledge ⇒ Object
- #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
#acknowledge ⇒ Object
34 35 36 37 38 |
# File 'lib/rsmp/alarm_state.rb', line 34 def acknowledge change, @acknowledged = !@acknowledged, true if change change end |
#activate ⇒ Object
52 53 54 55 56 |
# File 'lib/rsmp/alarm_state.rb', line 52 def activate change, @active = !@active, true if change change end |
#deactivate ⇒ Object
58 59 60 61 62 |
# File 'lib/rsmp/alarm_state.rb', line 58 def deactivate change, @active = @active, false if change change end |
#differ_from_message?(message) ⇒ Boolean
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rsmp/alarm_state.rb', line 83 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
46 47 48 49 50 |
# File 'lib/rsmp/alarm_state.rb', line 46 def resume change, @suspended = @suspended, false if change change end |
#suspend ⇒ Object
40 41 42 43 44 |
# File 'lib/rsmp/alarm_state.rb', line 40 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rsmp/alarm_state.rb', line 68 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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rsmp/alarm_state.rb', line 96 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
64 65 66 |
# File 'lib/rsmp/alarm_state.rb', line 64 def @timestamp = @component.node.clock.now end |