Class: SGS::GPS
Instance Attribute Summary collapse
-
#cmg ⇒ Object
Returns the value of attribute cmg.
-
#location ⇒ Object
Returns the value of attribute location.
-
#magvar ⇒ Object
Returns the value of attribute magvar.
-
#sog ⇒ Object
Returns the value of attribute sog.
-
#time ⇒ Object
Returns the value of attribute time.
-
#val ⇒ Object
Returns the value of attribute val.
Class Method Summary collapse
-
.daemon ⇒ Object
Main daemon function (called from executable).
Instance Method Summary collapse
-
#force(lat, long, time = nil) ⇒ Object
Hard-code a GPS value (usually for debugging purposes).
-
#initialize(lat = nil, long = nil) ⇒ GPS
constructor
Create a new GPS record.
-
#is_valid ⇒ Object
Set the validity.
-
#to_s ⇒ Object
Display the GPS data as a useful string (in degrees).
-
#valid? ⇒ Boolean
Is the GPS data valid?.
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
#initialize(lat = nil, long = nil) ⇒ GPS
Create a new GPS record. Lat/Long are in radians.
43 44 45 46 47 48 49 50 51 |
# File 'lib/sgs/gps.rb', line 43 def initialize(lat = nil, long = nil) @time = Time.new(2000, 1, 1) @location = Location.new(lat, long) @sog = 0.0 @cmg = 0.0 @magvar = nil @valid = false super() end |
Instance Attribute Details
#cmg ⇒ Object
Returns the value of attribute cmg.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def cmg @cmg end |
#location ⇒ Object
Returns the value of attribute location.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def location @location end |
#magvar ⇒ Object
Returns the value of attribute magvar.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def magvar @magvar end |
#sog ⇒ Object
Returns the value of attribute sog.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def sog @sog end |
#time ⇒ Object
Returns the value of attribute time.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def time @time end |
#val ⇒ Object
Returns the value of attribute val.
39 40 41 |
# File 'lib/sgs/gps.rb', line 39 def val @val end |
Class Method Details
.daemon ⇒ Object
Main daemon function (called from executable)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sgs/gps.rb', line 55 def self.daemon puts "GPS reader starting up..." config = Config.load sp = SerialPort.new config.gps_device, config.gps_speed sp.read_timeout = 10000 loop do nmea = NMEA.parse sp.readline if nmea.is_gprmc? gps = nmea.parse_gprmc p gps gps.save_and_publish if gps and gps.valid? end end end |
Instance Method Details
#force(lat, long, time = nil) ⇒ Object
Hard-code a GPS value (usually for debugging purposes)
74 75 76 77 78 |
# File 'lib/sgs/gps.rb', line 74 def force(lat, long, time = nil) @time = time || Time.now @location = Location.new(lat, long) @valid = true end |
#is_valid ⇒ Object
Set the validity
82 83 84 |
# File 'lib/sgs/gps.rb', line 82 def is_valid @valid = true end |
#to_s ⇒ Object
Display the GPS data as a useful string (in degrees)
94 95 96 97 98 99 100 |
# File 'lib/sgs/gps.rb', line 94 def to_s if valid? "@#{@time.strftime('%Y%m%d-%T')}, #{@location}, SOG:#{@sog}, CMG:#{@cmg}" else "GPS error" end end |
#valid? ⇒ Boolean
Is the GPS data valid?
88 89 90 |
# File 'lib/sgs/gps.rb', line 88 def valid? @valid == true end |