sms_serial 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d1a5742799fd294c5c48469b8e472694e71689a7f95d3696844e57c272029f8
4
+ data.tar.gz: 56affe24e953965e3e09a09a646ce20a6b46aa2d9a9dec3cae8e48513d253522
5
+ SHA512:
6
+ metadata.gz: a447a06a4979914eb2c21fa5c8b39ff8a7bc2e973800ce19c2355d7d4f3ab4a77ce638dca92f45b84981ba9310cad345f2b809e8ee656fb9c8586dd90825691b
7
+ data.tar.gz: af04aa79b699580d0895dc07c29fed3c0c255544a16074570be3cd468c0f4241691d7e5225e984068befa360784d00f48b0bd3f4e222e1b1ec8bd125e505bc5a
checksums.yaml.gz.sig ADDED
Binary file
data/lib/sms_serial.rb ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: sms_serial.rb
4
+
5
+ require 'c32'
6
+ require 'csv'
7
+ require 'time'
8
+ require "serialport"
9
+
10
+
11
+ class SmsSerialError < Exception
12
+ end
13
+
14
+ class SmsSerial
15
+ using ColouredText
16
+
17
+
18
+ def initialize(dev='/dev/ttyUSB0', callback: nil, debug: false)
19
+
20
+ @debug = debug
21
+ @sp = SerialPort.new dev, 115200
22
+ puts 'running ' + "SmsSerial".highlight
23
+ @buffer = []
24
+
25
+ @t = Thread.new {
26
+
27
+ Thread.current[:v] = []
28
+
29
+ loop do
30
+
31
+ message = @sp.read
32
+ if message.length > 0
33
+
34
+ if message =~ /^\+CMTI:/ then
35
+ callback.call(message.lines[2]) if callback
36
+ else
37
+
38
+ Thread.current[:v] << message
39
+ end
40
+ end
41
+ end
42
+ }
43
+
44
+ end
45
+
46
+ # count the number of SMS messages
47
+ #
48
+ def count()
49
+
50
+ puts 'inside count'.info if @debug
51
+
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
58
+
59
+ end
60
+
61
+ def delete(idx)
62
+
63
+ r = cmd 'CMD'
64
+ total = r.lines[2].split(',')[1].to_i
65
+ puts ('message count: ' + total.to_s).debug if @debug
66
+
67
+ total
68
+
69
+ end
70
+
71
+ def delete_all()
72
+
73
+ # format: [index, delflag]
74
+ # delflag 1 means delete all read messages
75
+ cmd 'CMGD=1,1'
76
+
77
+ end
78
+
79
+ def list_all()
80
+
81
+ n = count()
82
+ sleep 0.3
83
+
84
+ @sp.write %Q(AT+CMGL="ALL"\r\n)
85
+ n.times.map {r = read_buffer; parse_msg(r)}
86
+
87
+ if n < 1 then
88
+ r = read_buffer
89
+ []
90
+ end
91
+ end
92
+
93
+ # read an SMS message
94
+ #
95
+ def read(idx=1)
96
+
97
+ r = cmd 'CMGR=' + idx.to_s
98
+ parse_msg r
99
+
100
+ end
101
+
102
+ private
103
+
104
+ # e.g. cmd 'cmgr=1'
105
+ #
106
+ def cmd(s)
107
+
108
+ @sp.write "AT+%s\r\n" % [s]
109
+ sleep 1.5 # give the command time to be processed by the SIM module
110
+ r = ''
111
+ r = read_buffer
112
+
113
+ return r
114
+ end
115
+
116
+ def read_buffer()
117
+ @t[:v].any? ? @t[:v].shift : ''
118
+ end
119
+
120
+ def parse_msg(r)
121
+
122
+ puts ('parse_msg r: ' + r.inspect).debug if @debug
123
+ return if r.empty?
124
+ heading = r.lines[2][/\+CMG[RL]: (?:\d+,)?(.*)/,1]
125
+
126
+ raise SmsSerialError, "Message not found" unless heading
127
+
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}
132
+
133
+ end
134
+
135
+ end
136
+
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_serial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwOTAyMjE1ODAyWhcN
15
+ MjAwOTAxMjE1ODAyWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCsbDxb
17
+ FIwADjpFZt/Bgp5ltj0RtJKlO6a3Vzx+/Kgcya8YYnTbRhbXDqiyiDBsRKwiKh0E
18
+ HWheP29pZil8tTL60Uv1vjCwrCIekpM/M811sXY0CvHQjrOCHThbL0ypBbr+oxth
19
+ UggpD2ZG8YfyPUOtJYkgHVRu2DR03jrbwQgQ76yKVfcCLRNnuAs1rRq5lQ9sTd4R
20
+ V88M9UdQNcG9MTX2Mspl/sfRLTRSvWv15Dk6VYxirryBG5pfOkvznB1g7ErsQA9q
21
+ AEmuDESz3DtCXcoWgM8yhjjf3RSVsxg371cpI6fElefjaje8eoM41Kdq//X4B1yt
22
+ rA/Yg/1vb0owiPZqmfcHHDYuf+ruziepGUz7wIXjobNUYtsPQWgGlBSWZD12z4hi
23
+ y9LaJ8jSLrB+egZ/TaNjsauigfpjxHJ0Gh1mbNjkPzrcvFVcMmDx9BJbguCKqsw8
24
+ CyRZrbBJrucQVunfV76wNqrlkOdKBJGU+lBEdJdBA9FiMMNGZD3HSrgLxwcCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUfFuZv1Qb
26
+ lUPhFVB3GF3hpmSRnhQwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEACodgyGnp+/NOhRi/bYBGBhbg/OVtBHp+IU94kNjN
29
+ IcDUifpSXtjAuCJbXrE4u4aupN21SJJ9rKt/VHTA0sIRur4qxSLngNWJLMiVa/Py
30
+ Y23LBH3peBAMqrM+yhA5Z8eqy7ienHPcF65Qh+Je3m+vjZF8ehZ1Y+Xd6PCHzmMd
31
+ bod+bbyxraIcQCoBYQ/9j+tJ4+P5POh4jAKBTWnsA+KUyovF7mzuI5VOgi7x1J0c
32
+ Awr7n4hE1oDJfNlfpFRnSAuHB2d8NQBriXcSyNlNkteBf4/+7U/e6cJO3smL4wY6
33
+ JemW2LIHSoRwniioSZmqQAAxvlr2m6589lW2mURVOxwR8y59Dog8Z8SFzx13d3tb
34
+ cveCJWQx1b1jHW+bSY2rsaLO3FUVDvdl+26W/cL89Zo3QWwEUr2Inz7LnT4FKPAo
35
+ EYzIL92BZpCZCtjvESIrEv5VJgAmyveQNNU5h8mCJUtl5niL+zFr9No3bLdleGKx
36
+ h+73cUmDE6yvcIa2oIkbUrre
37
+ -----END CERTIFICATE-----
38
+ date: 2019-09-02 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: c32
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.0
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.2'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.2.0
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.2'
60
+ description:
61
+ email: james@jamesrobertson.eu
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/sms_serial.rb
67
+ homepage: https://github.com/jrobertson/sms_serial
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.0.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Reads SMS messages from a serial connection to an Arduino compatible board
90
+ which uses an SMS module.
91
+ test_files: []
metadata.gz.sig ADDED
Binary file