Class: SGS::Alarm

Inherits:
RedisBase show all
Defined in:
lib/sgs/alarm.rb

Overview

Deal with alarm subsystem.

Constant Summary collapse

OTTO_RESTART =

Alarms generated by Otto.

0
MISSION_SWITCH =
1
RUDDER_FAULT =
2
SAIL_FAULT =
3
BATTERY_FAULT =
4
SOLAR_FAULT =
5
COMPASS_FAULT =
6
ACCEL_FAULT =
7
WDI_FAULT =
8
MOTHER_UNRESP =
9
RESERVED1 =
10
RESERVED2 =
11
RESERVED3 =
12
RESERVED4 =
13
RESERVED5 =
14
RESERVED6 =
15
OTTO_FAULT =

Alarms generated by Mother.

16
MISSION_COMMENCE =
17
MISSION_COMPLETE =
18
MISSION_ABORT =
19
WAYPOINT_REACHED =
20
CROSS_TRACK_ERROR =
21
INSIDE_FENCE =
22
ALARM_NAMES =
[
  "OTTO Restarted Unexpectedly",
  "Mission Activation Switch",
  "Fault in Rudder Control System",
  "Fault in Sail Control System",
  "Battery Failure",
  "Failure in Solar Array",
  "Fault in Electronic Compass",
  "Fault in Accelerometer",
  "Fault in Wind Direction Indicator",
  "Mother is Unresponsive",
  "** Reserved 1 **",
  "** Reserved 2 **",
  "** Reserved 3 **",
  "** Reserved 4 **",
  "** Reserved 5 **",
  "** Reserved 6 **",
  "Fault with OTTO Communications",
  "Mission has commenced",
  "Mission is completed",
  "*** MISSION ABORT ***",
  "Waypoint has been reached",
  "Significant cross-track error",
  "Vessel is inside the fence"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RedisBase

#count, #count_name, #load, load, #make_redis_name, #publish, redis, redis_handle, #redis_read_var, #save, #save_and_publish, setup, subscribe, to_redis, var_init

Constructor Details

#initializeAlarm

Returns a new instance of Alarm.



101
102
103
104
105
106
# File 'lib/sgs/alarm.rb', line 101

def initialize
  @count = 0
  @last_report = nil
  @time = Array.new(32, Time.at(0))
  super
end

Instance Attribute Details

#last_reportObject

Returns the value of attribute last_report.



45
46
47
# File 'lib/sgs/alarm.rb', line 45

def last_report
  @last_report
end

#timeObject

Returns the value of attribute time.



45
46
47
# File 'lib/sgs/alarm.rb', line 45

def time
  @time
end

Class Method Details

.build_include(fname) ⇒ Object

Build a C include file based on the current alarm definitions



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/sgs/alarm.rb', line 123

def self.build_include(fname)
  alarm = new
  File.open(fname, "w") do |f|
    f.puts "/*\n * Autogenerated by #{__FILE__}.\n * DO NOT HAND-EDIT!\n */"
    constants.sort.each do |c|
      unless c == :ALARM_NAMES
        cval = Alarm.const_get(c)
        str = "#define SGS_ALARM_#{c.to_s}"
        str += "\t" if str.length < 32
        str += "\t#{cval}\t/* #{alarm.name(cval)} */"
        f.puts str
      end
    end
  end
end

.daemonObject

Main daemon function (called from executable)



110
111
112
113
114
115
116
117
118
119
# File 'lib/sgs/alarm.rb', line 110

def self.daemon
  puts  "Alarm daemon starting up. VERSION: #{SGS::VERSION}"
  otto = RPCClient.new(:otto)
  loop do
    #puts "Check for any alarms..."
    #resp = otto.command "A?"
    #puts "Response: #{resp}"
    sleep 30
  end
end

Instance Method Details

#name(alarmno) ⇒ Object

Convert an alarm number into a string.



141
142
143
# File 'lib/sgs/alarm.rb', line 141

def name(alarmno)
  ALARM_NAMES[alarmno]
end