RbGps 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/RbGps.so +0 -0
  2. data/rb_gps.c +94 -9
  3. data/test.rb +11 -3
  4. metadata +3 -2
Binary file
data/rb_gps.c CHANGED
@@ -1,10 +1,9 @@
1
1
 
2
-
3
- #include <ruby.h>
4
- #include <errno.h>
5
2
  #include "version.h"
6
- #include "gps.h"
7
-
3
+ #include <errno.h>
4
+ #include <gps.h>
5
+ #include <math.h>
6
+ #include <ruby.h>
8
7
  #include <stdio.h>
9
8
 
10
9
  /* classes */
@@ -37,10 +36,25 @@ struct _symbols {
37
36
  VALUE fix_climb;
38
37
 
39
38
  VALUE sat_prn;
39
+
40
40
  VALUE sat_elevation;
41
41
  VALUE sat_azimuth;
42
42
  VALUE sat_ss;
43
43
  VALUE sat_used;
44
+
45
+ VALUE prec_time;
46
+ VALUE prec_horiz;
47
+ VALUE prec_spheric;
48
+ VALUE prec_speed;
49
+ VALUE prec_vert;
50
+ VALUE prec_climb;
51
+ VALUE prec_sat_used;
52
+ VALUE prec_sat_visible;
53
+ VALUE prec_pdop;
54
+ VALUE prec_hdop;
55
+ VALUE prec_vdop;
56
+ VALUE prec_tdop;
57
+ VALUE prec_gdop;
44
58
  };
45
59
 
46
60
  static struct _symbols symbolTable;
@@ -149,9 +163,11 @@ static VALUE rbGps_get_fix(VALUE self) {
149
163
  if (!fix)
150
164
  return Qnil;
151
165
  VALUE ret=rb_hash_new();
152
-
153
- rb_hash_aset(ret,symbolTable.fix_time,rb_float_new(fix->time));
154
-
166
+ if (isnan(fix->time)) {
167
+ rb_hash_aset(ret,symbolTable.fix_time,Qnil);
168
+ } else {
169
+ rb_hash_aset(ret,symbolTable.fix_time,rb_float_new(fix->time));
170
+ }
155
171
  if (fix->mode==MODE_NO_FIX) {
156
172
  rb_hash_aset(ret,symbolTable.fix_mode,symbolTable.mode_no_fix);
157
173
  } else if (fix->mode==MODE_2D) {
@@ -207,6 +223,58 @@ static VALUE rbGps_get_sat(VALUE self) {
207
223
  return ret;
208
224
  }
209
225
 
226
+
227
+
228
+ static VALUE rbGps_get_prec(VALUE self) {
229
+ rb_Gps_cls *obj=0;
230
+ Data_Get_Struct(self, rb_Gps_cls, obj);
231
+ if (!obj->gps_data)
232
+ return Qnil;
233
+ const struct gps_data_t *gps_data=obj->gps_data;
234
+ const struct gps_fix_t *fix=&(gps_data->fix);
235
+ if (!fix)
236
+ return Qnil;
237
+ VALUE ret=rb_hash_new();
238
+
239
+ rb_hash_aset(ret,symbolTable.prec_time,rb_float_new(fix->ept));
240
+
241
+ if (fix->mode==MODE_2D || fix->mode==MODE_3D) {
242
+ rb_hash_aset(ret,symbolTable.prec_horiz,rb_float_new(fix->eph));
243
+ rb_hash_aset(ret,symbolTable.prec_spheric,rb_float_new(gps_data->epe));
244
+ rb_hash_aset(ret,symbolTable.prec_speed,rb_float_new(fix->eps));
245
+ } else {
246
+ rb_hash_aset(ret,symbolTable.prec_horiz,Qnil);
247
+ rb_hash_aset(ret,symbolTable.prec_spheric,Qnil);
248
+ rb_hash_aset(ret,symbolTable.prec_speed,Qnil);
249
+ }
250
+
251
+ if (fix->mode==MODE_3D) {
252
+ rb_hash_aset(ret,symbolTable.prec_vert,rb_float_new(fix->epv));
253
+ rb_hash_aset(ret,symbolTable.prec_climb,rb_float_new(fix->epc));
254
+ } else {
255
+ rb_hash_aset(ret,symbolTable.prec_vert,Qnil);
256
+ rb_hash_aset(ret,symbolTable.prec_climb,Qnil);
257
+ }
258
+ rb_hash_aset(ret,symbolTable.prec_sat_used,INT2NUM(gps_data->satellites_used));
259
+ rb_hash_aset(ret,symbolTable.prec_sat_visible,INT2NUM(gps_data->satellites));
260
+
261
+ rb_hash_aset(ret,symbolTable.prec_pdop,rb_float_new(gps_data->pdop));
262
+ rb_hash_aset(ret,symbolTable.prec_hdop,rb_float_new(gps_data->hdop));
263
+ rb_hash_aset(ret,symbolTable.prec_vdop,rb_float_new(gps_data->vdop));
264
+ rb_hash_aset(ret,symbolTable.prec_tdop,rb_float_new(gps_data->tdop));
265
+ rb_hash_aset(ret,symbolTable.prec_gdop,rb_float_new(gps_data->gdop));
266
+
267
+
268
+ return ret;
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
210
278
  static void fill_symbol_table() {
211
279
  symbolTable.online=ID2SYM(rb_intern("online"));
212
280
 
@@ -236,6 +304,22 @@ static void fill_symbol_table() {
236
304
  symbolTable.sat_ss=ID2SYM(rb_intern("ss"));
237
305
  symbolTable.sat_used=ID2SYM(rb_intern("used"));
238
306
 
307
+ symbolTable.prec_time=ID2SYM(rb_intern("prec_time"));
308
+ symbolTable.prec_horiz=ID2SYM(rb_intern("prec_horizontal"));
309
+ symbolTable.prec_spheric=ID2SYM(rb_intern("prec_spherical"));
310
+ symbolTable.prec_speed=ID2SYM(rb_intern("prec_speed"));
311
+ symbolTable.prec_vert=ID2SYM(rb_intern("prec_vertical"));
312
+ symbolTable.prec_climb=ID2SYM(rb_intern("prec_climb"));
313
+
314
+ symbolTable.prec_sat_used=ID2SYM(rb_intern("prec_sat_used"));
315
+ symbolTable.prec_sat_visible=ID2SYM(rb_intern("prec_sat_visible"));
316
+
317
+ symbolTable.prec_pdop=ID2SYM(rb_intern("prec_pdop"));
318
+ symbolTable.prec_hdop=ID2SYM(rb_intern("prec_hdop"));
319
+ symbolTable.prec_vdop=ID2SYM(rb_intern("prec_vdop"));
320
+ symbolTable.prec_tdop=ID2SYM(rb_intern("prec_tdop"));
321
+ symbolTable.prec_gdop=ID2SYM(rb_intern("prec_gdop"));
322
+
239
323
 
240
324
  }
241
325
 
@@ -251,7 +335,8 @@ void Init_RbGps() {
251
335
  rb_define_method(cRbGps, "poll" , rbGps_poll , 0);
252
336
  rb_define_method(cRbGps, "get" , rbGps_get , 0);
253
337
  rb_define_method(cRbGps, "get_fix" , rbGps_get_fix , 0);
254
- rb_define_method(cRbGps, "get_sat" , rbGps_get_sat , 0);
338
+ rb_define_method(cRbGps, "get_sat" , rbGps_get_sat , 0);
339
+ rb_define_method(cRbGps, "get_prec" , rbGps_get_prec , 0);
255
340
  rb_define_method(cRbGps, "query" , rbGps_query , 1);
256
341
 
257
342
  }
data/test.rb CHANGED
@@ -5,16 +5,22 @@ def dump_sats(sats)
5
5
  count=0
6
6
  sats.each do |sat|
7
7
  count=count+1
8
- line=sat.keys.collect { |key| "#{key} #{sat[key]}" }
9
- puts "#{count} "+line.join(' ')
8
+ line=sat.keys.collect { |key| "#{key} #{sprintf("%-5s",sat[key])}" }
9
+ puts "#{sprintf("%2i ",count)} "+line.join(' ')
10
10
  end
11
11
  end
12
12
 
13
13
  def dump_fix(fix)
14
+ fix[:time]=Time::at(fix[:time]) unless fix[:time].nil?
14
15
  line=fix.keys.collect { |key| "#{key} #{fix[key]}" }
15
16
  puts line.join(' ')
16
17
  end
17
18
 
19
+ def dump_prec(fix)
20
+ line=fix.keys.collect { |key| "#{key.to_s.gsub(/^prec_/,'')} #{fix[key]}" }
21
+ puts "prec "+line.join(' ')
22
+ end
23
+
18
24
 
19
25
  gps=RbGps.new('localhost','2947')
20
26
 
@@ -29,7 +35,9 @@ loop do
29
35
  res=gps.get
30
36
  puts res.to_yaml
31
37
  dump_fix(gps.get_fix)
32
- puts "next"
38
+ dump_prec(gps.get_prec)
33
39
  dump_sats(gps.get_sat)
40
+ puts "next"
41
+
34
42
  sleep 1
35
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RbGps
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgen Van Ham
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-22 00:00:00 +01:00
12
+ date: 2009-03-08 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,6 +25,7 @@ files:
25
25
  - ./rb_gps.c
26
26
  - ./test.rb
27
27
  - ./extconf.rb
28
+ - ./RbGps.so
28
29
  has_rdoc: false
29
30
  homepage: http://gpsd.berlios.de/
30
31
  post_install_message: