Class: GpsdBaudRate
- Inherits:
-
Object
- Object
- GpsdBaudRate
- Defined in:
- lib/gpsd_baud_rate.rb,
lib/gpsd_baud_rate/version.rb
Constant Summary collapse
- VERSION =
"0.1.32"
- @@version =
GpsdBaudRate::VERSION.to_s
- @@device =
'/dev/ttyAMA0'
- @@service =
'gpsd.service'
- @@socket =
'gpsd.socket'
- @@baud_rates =
%w[115200 57600 38400 19200 14400 9600 4800]
- @@NMEA_sentences =
%w[$GPGGA $GPGSA $GPGSV $GPRMC $GPZDA]
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.baud_rate ⇒ Object
~~~~~~~~~~~~~~~~~~~~~~~~ baud rate ~~~~~~~~~~~~~~~~~~~.
- .baud_rate?(b_rate) ⇒ Boolean
-
.check_device? ⇒ Boolean
returns true if device exists.
- .gpsd_active? ⇒ Boolean
- .gpsd_start ⇒ Object
- .gpsd_stop ⇒ Object
Instance Method Summary collapse
-
#baud_rate=(b_rate) ⇒ Object
returns original baud_rate.
-
#initialize(goal_rate = @@baud_rates[0]) ⇒ GpsdBaudRate
constructor
A new instance of GpsdBaudRate.
-
#set_baud_rate(b_rate = @goal_rate) ⇒ Object
initiallize.
-
#test_baud_rate(b_rate) ⇒ Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
Constructor Details
#initialize(goal_rate = @@baud_rates[0]) ⇒ GpsdBaudRate
Returns a new instance of GpsdBaudRate.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gpsd_baud_rate.rb', line 18 def initialize goal_rate = @@baud_rates[0] @logger = new_logger path: "log/GpsdBaudRate.log", progname: "GpsdBaudRate", time_format: "'%Y-%m-%d %T.%N %z %Z'", level: Logger::DEBUG @logger.info "GpsdBaudRate Gem - Version: #{@@version}" unless self.class.check_device? msg = "Device: #{@@device} not found" @logger.error msg raise StandardError.new msg else @logger.info "Device: #{@@device} Okay" end # pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"| # @logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}" @goal_rate = goal_rate.to_i @logger.debug "Goal_rate: #{@goal_rate}" end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/gpsd_baud_rate.rb', line 7 def version @version end |
Class Method Details
.baud_rate ⇒ Object
~~~~~~~~~~~~~~~~~~~~~~~~ baud rate ~~~~~~~~~~~~~~~~~~~
104 105 106 |
# File 'lib/gpsd_baud_rate.rb', line 104 def self.baud_rate %x| sudo stty -F "#{@@device}"|.split('; ')[0].split(/\W+/)[1].to_i end |
.baud_rate?(b_rate) ⇒ Boolean
108 109 110 |
# File 'lib/gpsd_baud_rate.rb', line 108 def self.baud_rate?(b_rate) b_rate==baud_rate end |
.check_device? ⇒ Boolean
returns true if device exists
75 76 77 78 79 80 |
# File 'lib/gpsd_baud_rate.rb', line 75 def self.check_device? # Does the @@device exist and is it a character device # [[ ]] returns true (0) if 'file' exists "0\n" == %x| [ -c "#{@@device}" ] ; echo $?| end |
.gpsd_active? ⇒ Boolean
82 83 84 85 86 |
# File 'lib/gpsd_baud_rate.rb', line 82 def self.gpsd_active? arry = %x|sudo systemctl status "#{@@socket}"|.split(/\n/) s = arry.select!{ |e| e.include? "Active:"}[0].split(/\W+/)[2] s == 'active' end |
.gpsd_start ⇒ Object
95 96 97 98 99 100 |
# File 'lib/gpsd_baud_rate.rb', line 95 def self.gpsd_start %x|sudo systemctl start "#{@@service}"| %x|sudo systemctl start "#{@@socket}"| sleep 1 %x|sudo systemctl daemon-reload| end |
.gpsd_stop ⇒ Object
88 89 90 91 92 93 |
# File 'lib/gpsd_baud_rate.rb', line 88 def self.gpsd_stop %x|sudo systemctl stop "#{@@socket}"| %x|sudo systemctl stop "#{@@service}"| sleep 1 %x|sudo systemctl daemon-reload| end |
Instance Method Details
#baud_rate=(b_rate) ⇒ Object
returns original baud_rate
113 114 115 116 |
# File 'lib/gpsd_baud_rate.rb', line 113 def baud_rate=( b_rate) msg= %x| sudo stty #{b_rate} -F "#{@@device}"| msg.each {|m| @logger.debug m} end |
#set_baud_rate(b_rate = @goal_rate) ⇒ Object
initiallize
37 38 39 40 41 42 43 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 |
# File 'lib/gpsd_baud_rate.rb', line 37 def set_baud_rate b_rate = @goal_rate @logger.debug "In set_baud_rate" GpsdBaudRate::gpsd_start unless GpsdBaudRate::gpsd_active? #make sure it's running @logger.debug "Service Status: #{GpsdBaudRate::gpsd_active?}" @logger.debug "Baud Rate: #{active_rate = GpsdBaudRate::baud_rate}" GpsdBaudRate::gpsd_stop @logger.debug "Service Status: #{GpsdBaudRate::gpsd_active?}" @logger.debug "Baud Rate: #{inactive_rate = GpsdBaudRate::baud_rate}" if active_rate == b_rate.to_i @logger.debug "Already at Goal Baud Rate" else @logger.debug "~~~~~~~~~~~~ Read at #{active_rate} baud ~~~~~~~~~~~~~~" unless (read_from_device active_rate) @logger.debug "Read at #{active_rate} baud Failed" else @logger.debug "Setting Goal Rate (#{b_rate})" set_PMTK_baud_rate active_rate, b_rate @logger.debug "Attempting Read at #{b_rate}" if read_from_device b_rate @logger.debug "Baud Rate Modification Successful" @logger.debug "Goal Baud Rate (#{b_rate}) has been set" else @logger.debug "Setting Baud Rate Failed" end end end # # Cleanup GpsdBaudRate::gpsd_start @logger.debug "Service Status: #{GpsdBaudRate::gpsd_active?}" end |
#test_baud_rate(b_rate) ⇒ Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120 121 122 |
# File 'lib/gpsd_baud_rate.rb', line 120 def test_baud_rate b_rate read_from_device b_rate end |