sms_serial 0.1.2 → 0.1.3

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: 4e5a10cce55b72c9b41594ef88286e54a7b6e4bdd28932b15dbe4569881f0972
4
- data.tar.gz: bb6155c5d9aef10ededbe6b997db728159362a0ac615c4a6c0daaa6227408b41
3
+ metadata.gz: 2a75b0d87e21e0b2c7d3c7d1ea5e85842c16aa04e3f7116e966e1eda99c74be3
4
+ data.tar.gz: b13eae5dc152fa3da533dbaa07e391ec7362372dbedaab3206f837f91de895e6
5
5
  SHA512:
6
- metadata.gz: f8b3838457059f336cfa0b6df438b1a3864d1214dcd9b300fe7f25b36382892e665beabd3100db84dfb64bb1af3951754c600ffaa7b9fb3f32d6cd6d8e90d20b
7
- data.tar.gz: 79c1c779d0d1c560c1c70b7a927b368007a5d1a49f210668c0db64e6beb7a778ec14c27545361efa57191e458f31131fa339c533a64b8cf9c83b476d2c8fc3d5
6
+ metadata.gz: 615c227c6f9ee357102113ec97f7495d2ac0ac10ac926f576a58832a60e6c49790ca4fff0f2ef95b7398b635b3d2ec0e35e9ba2a3d8c13fc44779bf3b85201c7
7
+ data.tar.gz: 17cb01a5a135599c331b6de88afd66004aee074182e3cd2a0516f5121df4ac48119183db07e47635c7f420b06bc5b244f4fffb4daa6bf8de85d31df8783bb96e
checksums.yaml.gz.sig CHANGED
@@ -1,4 +1,3 @@
1
- ez�5�/�vvH0~���ؐ<h0��:w�֝P3d4��o)*􆁰�Λ3 ���Oڒ�(%�>��y��C��yV@F.�� ���
2
- ~��ll�d��o�Dl; oз�#��Y��^���O���!ޖ
3
- "�1a�����д�;��w
4
- ��|����3h'�"�T.2Wȧr�UB�֟c��ı�0�MX�����J}N�|�����}�����*EG��{N�� CU������@�����D�-���͟��$;��Y��z&Km�jx��z'p|&�J�$�5�0��5%���1o`A�D�Dٱ9q{���%����M�̣Y� ,q�� yIk�c��h�� .�?
1
+ ������͚���Q{� ^�^�Jw8Z��SsHe�e�c�ܯ��Ċ����� �Ҍ��ԝS��Ĕ�Rre�r�(o� 8u�a̴O\�J%�ç�
2
+ ��P�:�=Ǯ|Ͼ95����Ւ Ҁ$�o��8 < uQC�n�O� C�L�TZ��-�_EWQm�7�$:�=�N6�
3
+ X������GEV�\([���I:���ׯz&Ӧ�AƐQ��������Ӗܵ��_֭�j�N�r�t_� ��2�F��h��{Y�7�LcE�JAn�n�G����|�ڴ�ٰ�'6߫����m��*�1c��WƂ�C�Tq�னe+���+.1�m�X�}"cnFd���Ā3&T�^��q{��p�(Mi�
data/lib/sms_serial.rb CHANGED
@@ -14,6 +14,7 @@ end
14
14
  class SmsSerial
15
15
  using ColouredText
16
16
 
17
+ attr_reader :t
17
18
 
18
19
  def initialize(dev='/dev/ttyUSB0', callback: nil, debug: false)
19
20
 
@@ -29,12 +30,16 @@ class SmsSerial
29
30
 
30
31
  message = @sp.read
31
32
  if message.length > 0
32
-
33
+
34
+ callback.call(message) if callback and @debug
35
+
33
36
  if message =~ /^\+CMTI:/ then
34
37
  callback.call(message.lines[2]) if callback
35
38
  else
36
39
 
40
+ Thread.current[:v] ||= []
37
41
  Thread.current[:v] << message
42
+
38
43
  end
39
44
  end
40
45
  end
@@ -103,8 +108,10 @@ class SmsSerial
103
108
  #
104
109
  def cmd(s)
105
110
 
106
- @sp.write "AT+%s\r\n" % [s]
107
- sleep 1.5 # give the above command time to be processed by the SIM module
111
+ puts ('inside cmd s: ' + s.inspect).debug if @debug
112
+ r2 = @sp.write "AT+%s\r\n" % [s]
113
+ puts 'r2: ' + r2.inspect if @debug
114
+ puts '@t[:v] ' + @t[:v].inspect if @debug
108
115
 
109
116
  r = read_buffer
110
117
 
@@ -117,18 +124,28 @@ class SmsSerial
117
124
  end
118
125
 
119
126
  def read_buffer()
120
- @t[:v].any? ? @t[:v].shift : ''
127
+
128
+ sleep 2 if @debug
129
+
130
+ puts 'inside read_buffer @t[:v]: ' + @t[:v].inspect if @debug
131
+ r = ''
132
+ @t[:v].any? ? (r += @t[:v].shift until @t[:v].empty?).to_s : r = ''
133
+
134
+ puts 'read_buffer r: ' + r.inspect if @debug
135
+ r
136
+
121
137
  end
122
138
 
123
139
  def parse_msg(r)
124
140
 
125
141
  puts ('parse_msg r: ' + r.inspect).debug if @debug
126
142
  return if r.empty?
127
- heading = r.lines[2][/\+CMG[RL]: (?:\d+,)?(.*)/,1]
143
+ heading = r.lines[2][/\+CMG[RL]: (?:[^,]+,)?(.*)/,1]
144
+ puts ('heading: ' + heading.inspect).debug if @debug
128
145
 
129
146
  raise SmsSerialError, "Message not found" unless heading
130
147
 
131
- sender, sent = CSV.parse(heading).first.values_at(1,3)
148
+ sender, sent = CSV.parse(heading).first.values_at(0,2)
132
149
  {sender: sender, sent: Time.parse(sent), body: r.lines[4].rstrip}
133
150
 
134
151
  end
data.tar.gz.sig CHANGED
Binary file
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file