Class: Phidgets::GPS
- Defined in:
- lib/phidgets/gps.rb,
ext/phidgets/phidgets_gps.c
Instance Method Summary collapse
-
#getAltitude ⇒ Object
(also: #altitude)
The altitude above mean sea level in meters.
-
#getDate ⇒ Object
(also: #date)
The UTC date of the last received position.
-
#getHeading ⇒ Object
(also: #heading)
The current true course over ground of the GPS.
-
#getLatitude ⇒ Object
(also: #latitude)
The latitude of the GPS in degrees.
-
#getLongitude ⇒ Object
(also: #longitude)
The longitude of the GPS.
-
#getNMEAData ⇒ Object
(also: #nmea_data)
The NMEA data structure.
-
#getPositionFixState ⇒ Object
(also: #position_fix?)
The status of the position fix True if a fix is available and latitude, longitude, and altitude can be read.
-
#getTime ⇒ Time
(also: #time)
The current UTC time of the GPS.
-
#getVelocity ⇒ Object
(also: #velocity)
The current speed over ground of the GPS.
-
#new ⇒ Object
constructor
Creates a Phidget GPS object.
-
#setOnHeadingChangeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_heading_change)
call-seq: setOnHeadingChangeHandler(proc=nil, &block).
-
#setOnPositionChangeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_position_change)
call-seq: setOnPositionChangeHandler(proc=nil, &block).
-
#setOnPositionFixStateChangeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_position_fix_state_change)
call-seq: setOnPositionFixStateChangeHandler(proc=nil, &block).
Methods inherited from Common
#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDataInterval, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDataInterval, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel
Constructor Details
#new ⇒ Object
Creates a Phidget GPS object.
10 11 12 13 14 |
# File 'ext/phidgets/phidgets_gps.c', line 10
VALUE ph_gps_init(VALUE self) {
ph_data_t *ph = get_ph_data(self);
ph_raise(PhidgetGPS_create((PhidgetGPSHandle *)(&(ph->handle))));
return self;
}
|
Instance Method Details
#getAltitude ⇒ Object Also known as: altitude
The altitude above mean sea level in meters.
24 25 26 |
# File 'ext/phidgets/phidgets_gps.c', line 24
VALUE ph_gps_get_altitude(VALUE self) {
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getAltitude);
}
|
#getDate ⇒ Object Also known as: date
The UTC date of the last received position.
48 49 50 51 52 53 54 55 56 57 |
# File 'ext/phidgets/phidgets_gps.c', line 48
VALUE ph_gps_get_date(VALUE self) {
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
PhidgetGPS_Date date;
VALUE rb_date = rb_hash_new();
ph_raise(PhidgetGPS_getDate(handle, &date));
rb_hash_aset(rb_date, rb_str_new2("tm_year"), INT2NUM(date.tm_year));
rb_hash_aset(rb_date, rb_str_new2("tm_mon"), INT2NUM(date.tm_mon));
rb_hash_aset(rb_date, rb_str_new2("tm_mday"), INT2NUM(date.tm_mday));
return rb_date;
}
|
#getHeading ⇒ Object Also known as: heading
The current true course over ground of the GPS.
28 29 30 |
# File 'ext/phidgets/phidgets_gps.c', line 28
VALUE ph_gps_get_heading(VALUE self) {
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getHeading);
}
|
#getLatitude ⇒ Object Also known as: latitude
The latitude of the GPS in degrees.
16 17 18 |
# File 'ext/phidgets/phidgets_gps.c', line 16
VALUE ph_gps_get_latitude(VALUE self) {
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getLatitude);
}
|
#getLongitude ⇒ Object Also known as: longitude
The longitude of the GPS.
20 21 22 |
# File 'ext/phidgets/phidgets_gps.c', line 20
VALUE ph_gps_get_longitude(VALUE self) {
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getLongitude);
}
|
#getNMEAData ⇒ Object Also known as: nmea_data
The NMEA data structure.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/phidgets/phidgets_gps.c', line 63
VALUE ph_gps_get_nmea_data(VALUE self) {
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
PhidgetGPS_NMEAData nmea_data;
VALUE rb_gga_data = rb_hash_new();
VALUE rb_gsa_data = rb_hash_new();
VALUE rb_rmc_data = rb_hash_new();
VALUE rb_vtg_data = rb_hash_new();
VALUE rb_nmea_data = rb_hash_new();
VALUE sat_used = rb_ary_new();
int i;
ph_raise(PhidgetGPS_getNMEAData(handle, &nmea_data));
// GGA
rb_hash_aset(rb_gga_data, rb_str_new2("latitude"), DBL2NUM(nmea_data.GGA.latitude));
rb_hash_aset(rb_gga_data, rb_str_new2("longitude"), DBL2NUM(nmea_data.GGA.longitude));
rb_hash_aset(rb_gga_data, rb_str_new2("fixQuality"), INT2NUM(nmea_data.GGA.fixQuality));
rb_hash_aset(rb_gga_data, rb_str_new2("numSatellites"), INT2NUM(nmea_data.GGA.numSatellites));
rb_hash_aset(rb_gga_data, rb_str_new2("horizontalDilution"), DBL2NUM(nmea_data.GGA.horizontalDilution));
rb_hash_aset(rb_gga_data, rb_str_new2("altitude"), DBL2NUM(nmea_data.GGA.altitude));
rb_hash_aset(rb_gga_data, rb_str_new2("heightOfGeoid"), DBL2NUM(nmea_data.GGA.heightOfGeoid));
// GSA
rb_hash_aset(rb_gsa_data, rb_str_new2("mode"), INT2NUM(nmea_data.GSA.mode));
rb_hash_aset(rb_gsa_data, rb_str_new2("fixType"), INT2NUM(nmea_data.GSA.fixType));
for(i=0; i<12; i++) {rb_ary_push(sat_used, INT2NUM(nmea_data.GSA.satUsed[i]));}
rb_hash_aset(rb_gsa_data, rb_str_new2("satUsed"), sat_used);
rb_hash_aset(rb_gsa_data, rb_str_new2("posnDilution"), DBL2NUM(nmea_data.GSA.posnDilution));
rb_hash_aset(rb_gsa_data, rb_str_new2("horizDilution"), DBL2NUM(nmea_data.GSA.horizDilution));
rb_hash_aset(rb_gsa_data, rb_str_new2("vertDilution"), DBL2NUM(nmea_data.GSA.vertDilution));
// RMC
rb_hash_aset(rb_rmc_data, rb_str_new2("status"), INT2NUM(nmea_data.RMC.status));
rb_hash_aset(rb_rmc_data, rb_str_new2("latitude"), DBL2NUM(nmea_data.RMC.latitude));
rb_hash_aset(rb_rmc_data, rb_str_new2("longitude"), DBL2NUM(nmea_data.RMC.longitude));
rb_hash_aset(rb_rmc_data, rb_str_new2("speedKnots"), DBL2NUM(nmea_data.RMC.speedKnots));
rb_hash_aset(rb_rmc_data, rb_str_new2("heading"), DBL2NUM(nmea_data.RMC.heading));
rb_hash_aset(rb_rmc_data, rb_str_new2("magneticVariation"), DBL2NUM(nmea_data.RMC.magneticVariation));
rb_hash_aset(rb_rmc_data, rb_str_new2("mode"), INT2NUM(nmea_data.RMC.mode));
// VTG
rb_hash_aset(rb_vtg_data, rb_str_new2("trueHeading"), DBL2NUM(nmea_data.VTG.trueHeading));
rb_hash_aset(rb_vtg_data, rb_str_new2("magneticHeading"), DBL2NUM(nmea_data.VTG.magneticHeading));
rb_hash_aset(rb_vtg_data, rb_str_new2("speedKnots"), DBL2NUM(nmea_data.VTG.speedKnots));
rb_hash_aset(rb_vtg_data, rb_str_new2("speed"), DBL2NUM(nmea_data.VTG.speed));
rb_hash_aset(rb_vtg_data, rb_str_new2("mode"), INT2NUM(nmea_data.VTG.mode));
rb_hash_aset(rb_nmea_data, rb_str_new2("GGA"), rb_gga_data);
rb_hash_aset(rb_nmea_data, rb_str_new2("GSA"), rb_gsa_data);
rb_hash_aset(rb_nmea_data, rb_str_new2("RMC"), rb_rmc_data);
rb_hash_aset(rb_nmea_data, rb_str_new2("VTG"), rb_vtg_data);
return rb_nmea_data;
}
|
#getPositionFixState ⇒ Object Also known as: position_fix?
The status of the position fix True if a fix is available and latitude, longitude, and altitude can be read. False if the fix is not available.
59 60 61 |
# File 'ext/phidgets/phidgets_gps.c', line 59
VALUE ph_gps_get_position_fix_state(VALUE self) {
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetGPS_getPositionFixState);
}
|
#getTime ⇒ Time Also known as: time
The current UTC time of the GPS.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'ext/phidgets/phidgets_gps.c', line 36
VALUE ph_gps_get_time(VALUE self) {
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
PhidgetGPS_Time time;
VALUE rb_time = rb_hash_new();
ph_raise(PhidgetGPS_getTime(handle, &time));
rb_hash_aset(rb_time, rb_str_new2("tm_hour"), INT2NUM(time.tm_hour));
rb_hash_aset(rb_time, rb_str_new2("tm_min"), INT2NUM(time.tm_min));
rb_hash_aset(rb_time, rb_str_new2("tm_sec"), INT2NUM(time.tm_sec));
rb_hash_aset(rb_time, rb_str_new2("tm_ms"), INT2NUM(time.tm_ms));
return rb_time;
}
|
#getVelocity ⇒ Object Also known as: velocity
The current speed over ground of the GPS.
32 33 34 |
# File 'ext/phidgets/phidgets_gps.c', line 32
VALUE ph_gps_get_velocity(VALUE self) {
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getVelocity);
}
|
#setOnHeadingChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_heading_change
call-seq:
setOnHeadingChangeHandler(proc=nil, &block)
Assigns a handler that will be called when the HeadingChange event occurs.
11 12 13 14 15 |
# File 'lib/phidgets/gps.rb', line 11 def setOnHeadingChangeHandler(cb_proc = nil, &cb_block) @on_heading_change_thread.kill if defined? @on_heading_change_thread and @on_heading_change_thread.alive? callback = cb_proc || cb_block @on_heading_change_thread = Thread.new {ext_setOnHeadingChangeHandler(callback)} end |
#setOnPositionChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_position_change
call-seq:
setOnPositionChangeHandler(proc=nil, &block)
Assigns a handler that will be called when the PositionChange event occurs.
22 23 24 25 26 |
# File 'lib/phidgets/gps.rb', line 22 def setOnPositionChangeHandler(cb_proc = nil, &cb_block) @on_position_change_thread.kill if defined? @on_position_change_thread and @on_position_change_thread.alive? callback = cb_proc || cb_block @on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)} end |
#setOnPositionFixStateChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_position_fix_state_change
call-seq:
setOnPositionFixStateChangeHandler(proc=nil, &block)
Assigns a handler that will be called when the PositionFixStateChange event occurs.
33 34 35 36 37 |
# File 'lib/phidgets/gps.rb', line 33 def setOnPositionFixStateChangeHandler(cb_proc = nil, &cb_block) @on_position_fix_state_change_thread.kill if defined? @on_position_fix_state_change_thread and @on_position_fix_state_change_thread.alive? callback = cb_proc || cb_block @on_position_fix_state_change_thread = Thread.new {ext_setOnPositionFixStateChangeHandler(callback)} end |