gps_pvt 0.3.0 → 0.3.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.
@@ -339,10 +339,16 @@ struct GPS_Time {
339
339
  return t.operator<=(*this);
340
340
  }
341
341
 
342
+ /**
343
+ * Convert to std::tm struct
344
+ * @param leap_seconds If offset of GPS time relative to UTC is known,
345
+ * specify it by using this parameter.
346
+ * As of Jan. 1st, 2022, +18 seconds are specified.
347
+ */
342
348
  std::tm c_tm(const float_t &leap_seconds = 0) const {
343
349
  std::tm t;
344
350
 
345
- GPS_Time mod_t((*this) + leap_seconds);
351
+ GPS_Time mod_t((*this) - leap_seconds);
346
352
 
347
353
  std::div_t min_sec(std::div((int)mod_t.seconds, 60));
348
354
  t.tm_sec = min_sec.rem;
@@ -153,6 +153,12 @@ static std::string inspect_str(const VALUE &v){
153
153
  $1 = (TYPE($input) == T_ARRAY) ? 1 : 0;
154
154
  }
155
155
  #endif
156
+ %ignore canonicalize();
157
+ %ignore GPS_Time(const int &_week, const float_t &_seconds);
158
+ %typemap(in, numinputs=0) void *dummy "";
159
+ GPS_Time(const int &week_, const float_t &seconds_, void *dummy){
160
+ return &((new GPS_Time<FloatT>(week_, seconds_))->canonicalize());
161
+ }
156
162
  %apply int *OUTPUT { int *week };
157
163
  %apply FloatT *OUTPUT { FloatT *seconds };
158
164
  void to_a(int *week, FloatT *seconds) const {
@@ -437,8 +437,6 @@ class Matrix : public Matrix_Frozen<T, Array2D_Type, ViewType> {
437
437
  #endif
438
438
 
439
439
  typedef Matrix<T, Array2D_Type, ViewType> self_t;
440
- self_t &swapRows(const unsigned int &row1, const unsigned int &row2);
441
- self_t &swapColumns(const unsigned int &column1, const unsigned int &column2);
442
440
  };
443
441
 
444
442
  %inline {
@@ -995,7 +993,23 @@ MAKE_TO_S(Matrix_Frozen)
995
993
  }
996
994
  #endif
997
995
 
998
- %typemap(out) self_t & "$result = self;"
996
+ /*
997
+ * Returning (*this) requires special care;
998
+ * "self_t &func(){return (*this);}" in a C++ file may generate
999
+ * a new wrapped object deleted by GC in the target language
1000
+ * unless the care.
1001
+ *
1002
+ * Work around 1)
1003
+ * %typemap(in, numinputs=0) self_t *self_p "";
1004
+ * %typemap(argout) self_t *self_p "$result = self;";
1005
+ * void func(self_t *self_p){...}
1006
+ *
1007
+ * Work around 2) (useful without overwrite of the original source, but may overfit)
1008
+ * %typemap(out) self_t & "$result = self;"
1009
+ * self_t &func(){...; return *$self;}
1010
+ */
1011
+ %typemap(in, numinputs=0) self_t *self_p "";
1012
+ %typemap(argout) self_t *self_p "$result = self;";
999
1013
 
1000
1014
  T &__setitem__(const unsigned int &row, const unsigned int &column, const T &value) {
1001
1015
  return (($self)->operator()(row, column) = value);
@@ -1012,41 +1026,50 @@ MAKE_TO_S(Matrix_Frozen)
1012
1026
  #endif
1013
1027
  %rename("scalar") getScalar;
1014
1028
  %rename("I") getI;
1015
- %rename("swap_rows") swapRows;
1016
- %rename("swap_columns") swapColumns;
1029
+
1030
+ void swap_rows(
1031
+ self_t *self_p,
1032
+ const unsigned int &r1, const unsigned int &r2){
1033
+ $self->swapRows(r1, r2);
1034
+ }
1035
+ void swap_columns(
1036
+ self_t *self_p,
1037
+ const unsigned int &c1, const unsigned int &c2){
1038
+ $self->swapColumns(c1, c2);
1039
+ }
1017
1040
 
1018
1041
  template <class T2, class Array2D_Type2, class ViewType2>
1019
- self_t &replace(const Matrix_Frozen<T2, Array2D_Type2, ViewType2> &matrix){
1020
- return $self->replace(matrix);
1042
+ void replace(
1043
+ self_t *self_p,
1044
+ const Matrix_Frozen<T2, Array2D_Type2, ViewType2> &matrix){
1045
+ $self->replace(matrix);
1021
1046
  }
1022
1047
  INSTANTIATE_MATRIX_FUNC(replace, replace);
1023
1048
 
1024
- self_t &replace(const void *replacer = NULL){
1049
+ void replace(self_t *self_p, const void *replacer = NULL){
1025
1050
  if(!MatrixUtil::replace(*$self, replacer)){
1026
1051
  throw std::runtime_error("Unsupported replacement");
1027
1052
  }
1028
- return *$self;
1029
1053
  }
1030
1054
 
1031
- self_t &replace(const T *serialized){
1055
+ void replace(self_t *self_p, const T *serialized){
1032
1056
  if(!MatrixUtil::replace(*$self, serialized)){
1033
1057
  throw std::runtime_error("Unsupported replacement");
1034
1058
  }
1035
- return *$self;
1036
1059
  }
1037
1060
 
1038
1061
  #ifdef SWIGRUBY
1039
- %bang swapRows(const unsigned int &, const unsigned int &);
1040
- %bang swapColumns(const unsigned int &, const unsigned int &);
1062
+ %bang swap_rows;
1063
+ %bang swap_columns;
1041
1064
  %rename("replace!") replace;
1042
1065
 
1043
- self_t &map_bang(
1066
+ void map_bang(
1067
+ self_t *self_p,
1044
1068
  void (*each_func)(
1045
1069
  const T &src, T *dst,
1046
1070
  const unsigned int &i, const unsigned int &j),
1047
1071
  const typename MatrixUtil::each_which_t &each_which = MatrixUtil::EACH_ALL){
1048
1072
  MatrixUtil::each(*$self, each_func, each_which, $self);
1049
- return *$self;
1050
1073
  }
1051
1074
  %rename("map!") map_bang;
1052
1075
  %alias map_bang "collect!,map_with_index!,collect_with_index!";
@@ -253,6 +253,7 @@ __RINEX_OBS_TEXT__
253
253
  t_meas = GPS::Time::new(1849, 172413)
254
254
  puts "Measurement time: #{t_meas.to_a} (a.k.a #{"%d/%d/%d %02d:%02d:%02d UTC"%[*t_meas.c_tm]})"
255
255
  expect(t_meas.c_tm).to eq([2015, 6, 15, 23, 53, 33])
256
+ expect(GPS::Time::new(0, t_meas.serialize)).to eq(t_meas)
256
257
 
257
258
  sn.update_all_ephemeris(t_meas)
258
259
 
@@ -214,9 +214,19 @@ shared_examples 'Matrix' do
214
214
  it 'is swappable with swap_rows! or swap_cloumns!' do
215
215
  mat_builtin = Matrix[*compare_with[0]]
216
216
  [:swap_rows!, :swap_columns!].each.with_index{|func, i|
217
- params[:rc][i].times.to_a.combination(2).to_a{|a, b|
218
- mat[0].send(func, a, b)
219
- mat_builtin.send(func, a, b)
217
+ params[:rc][i].times.to_a.combination(2).to_a.each{|a, b|
218
+ mat_mod = mat[0].send(func, a, b)
219
+ case func
220
+ when :swap_rows!
221
+ idxs = mat_builtin.row_count.times.to_a
222
+ idxs[a], idxs[b] = [b, a]
223
+ mat_builtin = Matrix::rows(mat_builtin.row_vectors.values_at(*idxs))
224
+ when :swap_columns!
225
+ idxs = mat_builtin.column_count.times.to_a
226
+ idxs[a], idxs[b] = [b, a]
227
+ mat_builtin = Matrix::columns(mat_builtin.column_vectors.values_at(*idxs))
228
+ end
229
+ expect(mat_mod).to equal(mat[0])
220
230
  expect(mat[0].to_a).to eq(mat_builtin.to_a)
221
231
  }
222
232
  }
@@ -7,15 +7,22 @@ require_relative 'GPS'
7
7
 
8
8
  module GPS_PVT
9
9
  class Receiver
10
+
11
+ GPS::Time.send(:define_method, :utc){ # send as work around of old Ruby
12
+ res = c_tm(GPS::Time::guess_leap_seconds(self))
13
+ res[-1] += (seconds % 1)
14
+ res
15
+ }
16
+
10
17
  def self.pvt_items(opt = {})
11
18
  opt = {
12
19
  :system => [[:GPS, 1..32]],
13
20
  :satellites => (1..32).to_a,
14
21
  }.merge(opt)
15
22
  [[
16
- [:week, :itow_rcv, :year, :month, :mday, :hour, :min, :sec],
23
+ [:week, :itow_rcv, :year, :month, :mday, :hour, :min, :sec_rcv_UTC],
17
24
  proc{|pvt|
18
- [:week, :seconds, :c_tm].collect{|f| pvt.receiver_time.send(f)}.flatten
25
+ [:week, :seconds, :utc].collect{|f| pvt.receiver_time.send(f)}.flatten
19
26
  }
20
27
  ]] + [[
21
28
  [:receiver_clock_error_meter, :longitude, :latitude, :height, :rel_E, :rel_N, :rel_U],
@@ -402,7 +409,7 @@ class Receiver
402
409
  ubx = UBX::new(open(ubx_fname))
403
410
  ubx_kind = Hash::new(0)
404
411
 
405
- after_run = b || proc{|pvt| puts pvt.to_s}
412
+ after_run = b || proc{|pvt| puts pvt.to_s if pvt}
406
413
 
407
414
  gnss_serial = proc{|svid, sys|
408
415
  if sys then # new numbering
@@ -526,7 +533,7 @@ class Receiver
526
533
  end
527
534
 
528
535
  def parse_rinex_obs(fname, &b)
529
- after_run = b || proc{|pvt| puts pvt.to_s}
536
+ after_run = b || proc{|pvt| puts pvt.to_s if pvt}
530
537
  $stderr.print "Reading RINEX observation file (%s)"%[fname]
531
538
  types = nil
532
539
  count = 0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GPS_PVT
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gps_pvt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - fenrir(M.Naruoka)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake