Class: CycleAnalystLogger::Gps
- Inherits:
-
Object
- Object
- CycleAnalystLogger::Gps
- Defined in:
- lib/cycle_analyst_logger/gps.rb
Constant Summary collapse
- DEFAULTS =
{ tty: '/dev/gps', baudrate: 115200 }
- GPS_DICT =
{ 0 => {address: 0, name: 'Time', key: :time, units: nil, scale: 1}, 1 => {address: 1, name: 'Latitude', key: :latitude, units: 'degrees', scale: 1}, 2 => {address: 2, name: 'Longitude', key: :longitude, units: 'degrees', scale: 1}, 3 => {address: 3, name: 'Altitude', key: :altitude, units: 'meters', scale: 1}, 4 => {address: 4, name: 'Speed', key: :speed, units: 'kph', scale: 1}, 5 => {address: 5, name: 'Fix Quality', key: :fix_quality, units: nil, scale: 1}, 6 => {address: 6, name: 'Satellites', key: :satellites, units: nil, scale: 1}, 7 => {address: 7, name: 'Geoid Height', key: :geoid_height, units: nil, scale: 1}, 8 => {address: 8, name: 'Horizontal Dilution', key: :horizontal_dilution, units: nil, scale: 1}, 9 => {address: 9, name: 'Faa Mode', key: :faa_mode, units: nil, scale: 1} }
Instance Attribute Summary collapse
-
#baudrate ⇒ Object
readonly
Returns the value of attribute baudrate.
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
-
#pre_data ⇒ Object
readonly
Returns the value of attribute pre_data.
-
#serial_io ⇒ Object
readonly
Returns the value of attribute serial_io.
-
#shared_data ⇒ Object
readonly
Returns the value of attribute shared_data.
-
#source_decoder ⇒ Object
readonly
Returns the value of attribute source_decoder.
-
#tty ⇒ Object
readonly
Returns the value of attribute tty.
Instance Method Summary collapse
-
#initialize(shared_data, opts = {}) ⇒ Gps
constructor
A new instance of Gps.
- #log_data ⇒ Object
- #log_header ⇒ Object
- #run(fd = nil, disable_nmea_out = false) ⇒ Object
Constructor Details
#initialize(shared_data, opts = {}) ⇒ Gps
Returns a new instance of Gps.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cycle_analyst_logger/gps.rb', line 33 def initialize(shared_data, opts = {}) final_opts = DEFAULTS.merge(opts) @tty = final_opts[:tty] @baudrate = final_opts[:baudrate] @serial_io = SerialPort.new @tty, @baudrate, 8, 1 @dict = GPS_DICT @pre_data = {} @shared_data = shared_data @source_decoder = NMEAPlus::SourceDecoder.new(@serial_io) end |
Instance Attribute Details
#baudrate ⇒ Object (readonly)
Returns the value of attribute baudrate.
26 27 28 |
# File 'lib/cycle_analyst_logger/gps.rb', line 26 def baudrate @baudrate end |
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
28 29 30 |
# File 'lib/cycle_analyst_logger/gps.rb', line 28 def dict @dict end |
#pre_data ⇒ Object (readonly)
Returns the value of attribute pre_data.
29 30 31 |
# File 'lib/cycle_analyst_logger/gps.rb', line 29 def pre_data @pre_data end |
#serial_io ⇒ Object (readonly)
Returns the value of attribute serial_io.
27 28 29 |
# File 'lib/cycle_analyst_logger/gps.rb', line 27 def serial_io @serial_io end |
#shared_data ⇒ Object (readonly)
Returns the value of attribute shared_data.
30 31 32 |
# File 'lib/cycle_analyst_logger/gps.rb', line 30 def shared_data @shared_data end |
#source_decoder ⇒ Object (readonly)
Returns the value of attribute source_decoder.
31 32 33 |
# File 'lib/cycle_analyst_logger/gps.rb', line 31 def source_decoder @source_decoder end |
#tty ⇒ Object (readonly)
Returns the value of attribute tty.
25 26 27 |
# File 'lib/cycle_analyst_logger/gps.rb', line 25 def tty @tty end |
Instance Method Details
#log_data ⇒ Object
80 81 82 83 84 |
# File 'lib/cycle_analyst_logger/gps.rb', line 80 def log_data dict.map do |address, node| shared_data[node[:key]] end end |
#log_header ⇒ Object
74 75 76 77 78 |
# File 'lib/cycle_analyst_logger/gps.rb', line 74 def log_header dict.map do |(address, node)| node[:name] + (node[:units] ? " (#{node[:units]})" : '') end end |
#run(fd = nil, disable_nmea_out = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cycle_analyst_logger/gps.rb', line 44 def run(fd = nil, disable_nmea_out = false) source_decoder. do || fd.puts .original.strip unless disable_nmea_out case .data_type[2..-1] # Ignore the first two letters when 'GGA' pre_data[:time] = .fix_time pre_data[:latitude] = .latitude pre_data[:longitude] = .longitude pre_data[:altitude] = .altitude pre_data[:dgps_station_id] = .dgps_station_id pre_data[:fix_quality] = .fix_quality pre_data[:geoid_height] = .geoid_height pre_data[:horizontal_dilution] = .horizontal_dilution pre_data[:satellites] = .satellites pre_data[:seconds_since_last_update] = .seconds_since_last_update when 'VTG' pre_data[:speed_kmh] = .speed_kmh pre_data[:speed_knots] = .speed_knots pre_data[:faa_mode] = .faa_mode pre_data[:track_degrees_magnetic] = .track_degrees_magnetic pre_data[:track_degrees_true] = .track_degrees_true # Has to be a copy since shared_data is really a reference to an # instance variable in the outer thread. pre_data.each_pair { |k,v| shared_data[k] = v} else next end end end |