quelink-mg 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ea5c2cf43ce12b5862a854e1cec5cc7149fa196f70cc6de57390d8ba4e4ef0b
4
- data.tar.gz: ced81a168e9b4c4db172bcb205b16a1e4c981cb03ea3a565149b1524487c1c88
3
+ metadata.gz: 156a74e9c90ed12d937afba89ed165d4c79f655b81158352aca3138962aeab2c
4
+ data.tar.gz: 5a3ec61486354ecfd8c359a8cc651b1c94f73eceba33164dedab67abc27ede56
5
5
  SHA512:
6
- metadata.gz: c27447f6092dcf66651a7cb7154fe85c8d491ee8945a111dad3f950ec4077f3d231425d468af84ab501ef525dad525b0a55726ec48158909c608a75a986ea4d9
7
- data.tar.gz: 1772f49c7e43a6e2d47eafb541428f88bb1611dc0e7f5782a76d1957a57fff7067daad797d1d5ed9cb99643c250047570c5ae90b1d62ce6007fcd4ec48ba1f78
6
+ metadata.gz: 873fca115ba479772b24a1f9cafce41112528c8fe5847a190e67a77cfb10e73b6aa4a0e14049178bb5b811be8e9e38d6d43defa0dd41cdb9d5f0313be2202b56
7
+ data.tar.gz: 15fb64bf910ce1ac9178535af37818f9c2482877db381df655b7412046189d28bb927cde60d8ac7f5839bc4514b2e068ef1532740766886dddbf9baf19d98bad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quelink-mg (0.2.0)
4
+ quelink-mg (0.3.0)
5
5
  activesupport (~> 7.0)
6
6
 
7
7
  GEM
@@ -19,13 +19,23 @@ module QuelinkMg
19
19
  private
20
20
 
21
21
  def verify_params(acceptable_values, error)
22
+ required_values.each do |rv|
23
+ raise_error(rv, error) if @params.fetch(rv, nil).nil?
24
+ end
25
+
22
26
  acceptable_values.each do |k, v|
23
- next if v.include?(@params.fetch(k, nil))
27
+ value = @params.fetch(k, nil)
28
+
29
+ next if value.blank? || v.include?(value)
24
30
 
25
31
  raise_error(k, error)
26
32
  end
27
33
  end
28
34
 
35
+ def required_values
36
+ %i[password serial_number]
37
+ end
38
+
29
39
  def raise_error(type, error)
30
40
  raise error, "Wrong #{type}: #{@params}"
31
41
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuelinkMg
4
+ module Buff
5
+ class Base < ::QuelinkMg::Resp::Base
6
+ QUELINK_DATE_FORMAT = '%Y%m%d%H%M%S'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuelinkMg
4
+ module Buff
5
+ class Gtfri < Base
6
+ GTFRI_RESP_KEYS = %w[protocol_version unique_id device_name report_id report_type number
7
+ gps_accuracy speed azimuth elevation longitude latitude gps_utc_time
8
+ mcc mnc lac cell_id odo_mileage battery_percentage send_time count_number].freeze
9
+
10
+ def hash
11
+ unify_keys(GTFRI_RESP_KEYS.zip(@response.split(',')).to_h)
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/quelink_mg.rb CHANGED
@@ -34,6 +34,9 @@ require File.expand_path('quelink-mg/ack/gtrto.rb', __dir__)
34
34
  require File.expand_path('quelink-mg/ack/gtsri.rb', __dir__)
35
35
  require File.expand_path('quelink-mg/ack/gtudf.rb', __dir__)
36
36
 
37
+ require File.expand_path('quelink-mg/buff/base.rb', __dir__)
38
+ require File.expand_path('quelink-mg/buff/gtfri.rb', __dir__)
39
+
37
40
  require File.expand_path('quelink-mg/configuration.rb', __dir__)
38
41
 
39
42
  module QuelinkMg
data/pkg/quelink-mg.gem CHANGED
Binary file
data/quelink-mg.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'quelink-mg'
5
- s.version = '0.2.1'
5
+ s.version = '0.4.0'
6
6
  s.summary = 'Quelink devices command reader and writer'
7
7
  s.description = 'Quelink devices command reader and writer'
8
8
  s.authors = ['Stanislaw Zawadzki']
@@ -34,6 +34,16 @@ RSpec.describe QuelinkMg::At::Gtcfg do
34
34
  '300,2,0,20491231235959,0,0000,0,10,,,FFFF$'
35
35
  end
36
36
 
37
+ it 'creates message if some params available' do
38
+ params =
39
+ {
40
+ password: 'gl310m',
41
+ gps_on_need: 1,
42
+ serial_number: 'FFFF'
43
+ }
44
+ expect(described_class.new(params:).message).to eq 'AT+GTCFG=gl310m,,,,,1,,,,,,,,,,,,,,,,,,,FFFF$'
45
+ end
46
+
37
47
  it 'raises error on missing params' do
38
48
  expect { described_class.new(params: {}).message }.to raise_error(InvalidATGTCFGException)
39
49
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe QuelinkMg::Buff::Gtfri do
6
+ it 'parses valid response' do
7
+ response = 'C30204,860201061504521,,0,0,1,1,0.0,0,96.2,21.012847,52.200338,20230813061232,\\
8
+ 0260,0003,E31F,0447020D,,34,20230813061231,3E94'
9
+
10
+ parsed_response = described_class.new(response:).hash
11
+ expect(parsed_response).not_to eq({})
12
+ expect(parsed_response['send_time']).to eq Time.use_zone('UTC') { Time.zone.parse('20230813061231') }.in_time_zone
13
+ expect(parsed_response['gps_utc_time']).to eq Time.use_zone('UTC') {
14
+ Time.zone.parse('20230813061232')
15
+ }.in_time_zone
16
+ expect(parsed_response['longitude']).to eq 21.012847
17
+ expect(parsed_response['latitude']).to eq 52.200338
18
+ expect(parsed_response['unique_id']).to eq 860_201_061_504_521
19
+ expect(parsed_response['battery_percentage']).to eq 34
20
+ expect(parsed_response['device_name']).to eq ''
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quelink-mg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislaw Zawadzki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-10 00:00:00.000000000 Z
11
+ date: 2023-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,6 +109,8 @@ files:
109
109
  - lib/quelink-mg/at/gtrto.rb
110
110
  - lib/quelink-mg/at/gtsri.rb
111
111
  - lib/quelink-mg/at/gtudf.rb
112
+ - lib/quelink-mg/buff/base.rb
113
+ - lib/quelink-mg/buff/gtfri.rb
112
114
  - lib/quelink-mg/configuration.rb
113
115
  - lib/quelink-mg/resp/base.rb
114
116
  - lib/quelink-mg/resp/gtfri.rb
@@ -136,6 +138,7 @@ files:
136
138
  - spec/quelink_mg/at/gtrto_spec.rb
137
139
  - spec/quelink_mg/at/gtsri_spec.rb
138
140
  - spec/quelink_mg/at/gtudf_spec.rb
141
+ - spec/quelink_mg/buff/gtfri_spec.rb
139
142
  - spec/quelink_mg/resp/gtfri_spec.rb
140
143
  - spec/quelink_mg/resp/gtgsv_spec.rb
141
144
  - spec/quelink_mg/resp/gtinf_spec.rb