sms_serial 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2218e40033ca0ee896ded51cb8b596405c686eb9e58344b69c1a5143850657e9
4
- data.tar.gz: 6ba62af5a95cdf967e25033f337abaea4a6be9f42a516e1174f4185863bbd386
3
+ metadata.gz: 4e5a10cce55b72c9b41594ef88286e54a7b6e4bdd28932b15dbe4569881f0972
4
+ data.tar.gz: bb6155c5d9aef10ededbe6b997db728159362a0ac615c4a6c0daaa6227408b41
5
5
  SHA512:
6
- metadata.gz: b113fa9f96def320338e1acdb868254b098bbca025169b7981e5ddd75029bc0610ba59f075644132a827b83d52cdbb72b6f6d21ebbddd62bf3979b581ea0a98d
7
- data.tar.gz: 7f4ae90d700dd22100913d10f5fd033546d710346ec0242beb2a7c5d4de85fec1687e97cf5ef8f2dbac60f7a88e3a02ec051df13bf2a3ef2e9744e6ee209f338
6
+ metadata.gz: f8b3838457059f336cfa0b6df438b1a3864d1214dcd9b300fe7f25b36382892e665beabd3100db84dfb64bb1af3951754c600ffaa7b9fb3f32d6cd6d8e90d20b
7
+ data.tar.gz: 79c1c779d0d1c560c1c70b7a927b368007a5d1a49f210668c0db64e6beb7a778ec14c27545361efa57191e458f31131fa339c533a64b8cf9c83b476d2c8fc3d5
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/sms_serial.rb CHANGED
@@ -20,7 +20,6 @@ class SmsSerial
20
20
  @debug = debug
21
21
  @sp = SerialPort.new dev, 115200
22
22
  puts 'running ' + "SmsSerial".highlight
23
- @buffer = []
24
23
 
25
24
  @t = Thread.new {
26
25
 
@@ -49,22 +48,24 @@ class SmsSerial
49
48
 
50
49
  puts 'inside count'.info if @debug
51
50
 
52
- r = cmd 'CPMS?'
53
- puts 'r: ' + r.inspect if @debug
54
- total = r.lines[2].split(',')[1].to_i
55
- puts ('message count: ' + total.to_s).debug if @debug
56
-
57
- total
51
+ cmd 'CPMS?' do |r|
52
+ puts 'r: ' + r.inspect if @debug
53
+ total = r.lines[2].split(',')[1].to_i
54
+ puts ('message count: ' + total.to_s).debug if @debug
58
55
 
56
+ total
57
+ end
58
+
59
59
  end
60
60
 
61
61
  def delete(idx)
62
62
 
63
- r = cmd 'CMD'
64
- total = r.lines[2].split(',')[1].to_i
65
- puts ('message count: ' + total.to_s).debug if @debug
63
+ cmd 'CMD' do |r|
64
+ total = r.lines[2].split(',')[1].to_i
65
+ puts ('message count: ' + total.to_s).debug if @debug
66
66
 
67
- total
67
+ total
68
+ end
68
69
 
69
70
  end
70
71
 
@@ -84,18 +85,15 @@ class SmsSerial
84
85
  @sp.write %Q(AT+CMGL="ALL"\r\n)
85
86
  n.times.map {r = read_buffer; parse_msg(r)}
86
87
 
87
- if n < 1 then
88
- r = read_buffer
89
- []
90
- end
88
+ flush_output() if n < 1
89
+
91
90
  end
92
91
 
93
92
  # read an SMS message
94
93
  #
95
94
  def read(idx=1)
96
95
 
97
- r = cmd 'CMGR=' + idx.to_s
98
- parse_msg r
96
+ cmd('CMGR=' + idx.to_s) {|r| parse_msg r }
99
97
 
100
98
  end
101
99
 
@@ -106,11 +104,16 @@ class SmsSerial
106
104
  def cmd(s)
107
105
 
108
106
  @sp.write "AT+%s\r\n" % [s]
109
- sleep 1.5 # give the command time to be processed by the SIM module
110
- r = ''
107
+ sleep 1.5 # give the above command time to be processed by the SIM module
108
+
111
109
  r = read_buffer
112
110
 
113
- return r
111
+ block_given? ? yield(r) : r
112
+ end
113
+
114
+ def flush_output()
115
+ r = read_buffer
116
+ []
114
117
  end
115
118
 
116
119
  def read_buffer()
@@ -125,12 +128,9 @@ class SmsSerial
125
128
 
126
129
  raise SmsSerialError, "Message not found" unless heading
127
130
 
128
- a = CSV.parse(heading)
129
- sender, sent = a.first.values_at(1,3)
130
- msg = {header: {sender: sender, sent: Time.parse(sent)},
131
- body: r.lines[4].rstrip}
131
+ sender, sent = CSV.parse(heading).first.values_at(1,3)
132
+ {sender: sender, sent: Time.parse(sent), body: r.lines[4].rstrip}
132
133
 
133
134
  end
134
135
 
135
136
  end
136
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  EYzIL92BZpCZCtjvESIrEv5VJgAmyveQNNU5h8mCJUtl5niL+zFr9No3bLdleGKx
36
36
  h+73cUmDE6yvcIa2oIkbUrre
37
37
  -----END CERTIFICATE-----
38
- date: 2019-09-02 00:00:00.000000000 Z
38
+ date: 2019-09-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
metadata.gz.sig CHANGED
Binary file