jgillick / ruby-serialgps

Provides an easy API to get GPS data from your serial GPS module.
13 stars 6 forks source link

Missing satellite ID in loop #3

Open rbur004 opened 7 years ago

rbur004 commented 7 years ago

For my GPS, I need to have a data[:satellites][i][:id] = line.shift #Satellite number in GSV loop below, as there are 4 groups of id, elevation, azimuth, SNR.

def parse_NMEA(raw) ... when "GSV" ... 4.times do |i| data[:satellites][i] ||= {}

  data[:satellites][i][:id]         = line.shift  #added in Satellite number        
  data[:satellites][i][:elevation]  = line.shift
  data[:satellites][i][:azimuth]        = line.shift
  data[:satellites][i][:snr]            = line.shift

end

rbur004 commented 7 years ago

also, the GSV list of satellites is not the same as the GGA and GSA list, but they share the same location in data[]. The GSV are the satellites in view, and are super set of the GSA, which are the ones being used.

My GPS (Garmin GPS II Plus) sets the GGA number of satellites in view, as the the GSA's number of active satellites, not the GSV number of visible satellites.

eg

$GPGGA,042750,3659.415,S,17429.243,E,1,06,1.6,164.9,M,28.0,M,,
$GPGSA,A,3,01,,,06,,,17,19,24,28,,,1.9,1.6,1.2
$GPGSV,3,1,11 ,01,13,139,30, 02,11,328,00, 03,18,105,00, 06,46,342,38
$GPGSV,3,2,11, 11,00,130,00, 13,03,302,00, 17,67,183,37, 19,64,238,36
$GPGSV,3,3,11, 24,23,228,36 ,28,49,077,41, 30,14,010,00, ,,,

In my version of your code, I have added data[:satellites][i][:status] = 'active'. or data[:satellites][i][:status] = 'visible'. and check for this when displaying the satellites list

and change the GSV

     data[:num_sat] = line.shift.to_i

to

    data[:num_sat_in_view]  = line.shift.to_i
rbur004 commented 7 years ago

Also realized that array index in the GSV 4.times loop should be i*(data[:msg_num].to_i - 1) eg

  data[:satellites][i][:id]         = line.shift  #added in Satellite number        
  data[:satellites][i][:elevation]  = line.shift
  data[:satellites][i][:azimuth]        = line.shift
  data[:satellites][i][:snr]            = line.shift

should be

  j = i + (data[:msg_num].to_i - 1) * 4 #Or an optimised version thereof, outside the loop
  data[:satellites][j][:id]         = line.shift  #added in Satellite number        
  data[:satellites][j][:elevation]  = line.shift
  data[:satellites][j][:azimuth]        = line.shift
  data[:satellites][j][:snr]            = line.shift

There are multiple GPGSV records (3 groups of 4), and processing each new GSV line overwrites the previous first 4 records in data[:satellites].

rbur004 commented 7 years ago

I had also added a block to the @data.merge!(data) (in read) to merge the satellites, and just got some spare time to test all this. It didn't work. I see multiple entries for some satellites , and active records with no signal.

The satellites change position in the GPGSA and GPGSV records, sometimes between reading successive GSV records, or the GSA and subsequent GSV. So it isn't as simple as merging the new arrays.

jgillick commented 7 years ago

Hi @rbur004. I have not maintained this library in quite some time (8 years, to be more specific). If you want to file a Pull Request to integrate these updates into the library, I'd be happy to merge it. Thank you!

rbur004 commented 7 years ago

Will do, and thanks for what you have already done. Saved me a lot of research.