serial_modem 0.3.1 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/lib/serial_modem.rb +179 -124
- data/lib/test +5 -0
- data/serial_modem.gemspec +3 -3
- data/test/{test_hw.rb → run_hw.rb} +0 -0
- data/test/run_thread.rb +25 -0
- data/test/sm_receive.rb +58 -0
- data/test/test.rb +20 -0
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ac79b6bee703df41e62638e3b588409c30a4cfd
|
4
|
+
data.tar.gz: 5f18729b44e78ffe9a67a93708e36b74b589b32a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f02e06aa1f74d62968e6921c7db4e10372898b2547f9d579b251e416b81d530c7e2b1c7762d48e1bfb69ead667f0185bac5c3f780e2f79ba41d920b5c98c2403
|
7
|
+
data.tar.gz: 6e2b0792c5760afe18f10c1f418ea236b7fee1e402a06cbb1273725fa2141982dbd7b2b29d795c03bd440f5d345a0c838d54a198416ee960a4904e3f1be27b00
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/serial_modem.rb
CHANGED
@@ -11,6 +11,7 @@ module SerialModem
|
|
11
11
|
extend HelperClasses::DPuts
|
12
12
|
|
13
13
|
def setup_modem(dev = nil)
|
14
|
+
# @serial_debug = true
|
14
15
|
@serial_debug = false
|
15
16
|
@serial_tty = @serial_tty_error = @serial_sp = nil
|
16
17
|
@serial_replies = []
|
@@ -18,6 +19,7 @@ module SerialModem
|
|
18
19
|
@serial_sms = {}
|
19
20
|
# TODO: once serialmodem == class, change this into Observer
|
20
21
|
@serial_sms_new = []
|
22
|
+
@serial_sms_new_list = []
|
21
23
|
@serial_sms_autoscan = 20
|
22
24
|
@serial_sms_autoscan_last = Time.now
|
23
25
|
@serial_ussd = []
|
@@ -25,119 +27,135 @@ module SerialModem
|
|
25
27
|
@serial_ussd_timeout = 30
|
26
28
|
@serial_ussd_results = []
|
27
29
|
@serial_ussd_results_max = 100
|
30
|
+
@serial_ussd_sent = 0
|
31
|
+
@serial_ussd_sent_max = 5
|
32
|
+
@serial_ussd_send_next = false
|
28
33
|
# TODO: once serialmodem == class, change this into Observer
|
29
34
|
@serial_ussd_new = []
|
30
|
-
@
|
31
|
-
@
|
35
|
+
@serial_ussd_new_list = []
|
36
|
+
@serial_mutex = Mutex.new
|
32
37
|
# Some Huawei-modems eat SMS once they send a +CMTI-message - this
|
33
38
|
# turns off the CMTI-messages which slows down incoming SMS detection
|
34
39
|
@serial_eats_sms = false
|
35
40
|
setup_tty
|
41
|
+
dp "tty is #{@serial_tty}"
|
36
42
|
end
|
37
43
|
|
38
|
-
def read_reply(wait = nil)
|
44
|
+
def read_reply(wait = nil, lock: true)
|
39
45
|
@serial_debug and dputs_func
|
40
46
|
raise IOError.new('NoModemHere') unless @serial_sp
|
41
|
-
ret = []
|
42
47
|
begin
|
43
|
-
@
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
}
|
54
|
-
|
55
|
-
while m = @serial_replies.shift
|
56
|
-
@serial_debug and dputs_func
|
57
|
-
next if (m == '' || m =~ /^\^/)
|
58
|
-
dputs(3) { "Reply: #{m}" }
|
59
|
-
ret.push m
|
60
|
-
if m =~ /\+[\w]{4}: /
|
61
|
-
code, msg = m[1..4], m[7..-1]
|
62
|
-
dputs(3) { "found code #{code.inspect} - #{msg.inspect}" }
|
63
|
-
@serial_codes[code] = msg
|
64
|
-
case code
|
65
|
-
when /CMGL/
|
66
|
-
# Typical input from the modem:
|
67
|
-
# "0,\"REC UNREAD\",\"+23599836457\",,\"15/04/08,17:12:21+04\""
|
68
|
-
# Output desired:
|
69
|
-
# ["0", "REC UNREAD", "+23599836457", "", "15/04/08,17:12:21+04"]
|
70
|
-
id, flag, number, unknown, date =
|
71
|
-
msg.scan(/"(.*?)"|([^",]+)\s*|,,/).collect { |a, b| a.to_s + b.to_s }
|
72
|
-
ret.push @serial_replies.shift
|
73
|
-
sms_new(id, flag, number, date, ret.last, unknown)
|
74
|
-
when /CUSD/
|
75
|
-
if pdu = msg.match(/.*\"(.*)\".*/)
|
76
|
-
ussd_received(pdu_to_ussd(pdu[1]))
|
77
|
-
elsif msg == '2'
|
78
|
-
#log_msg :serialmodem, 'Closed USSD.'
|
79
|
-
#ussd_received('')
|
80
|
-
#ussd_close
|
81
|
-
else
|
82
|
-
log_msg :serialmodem, "Unknown: CUSD - #{msg}"
|
83
|
-
end
|
84
|
-
when /CMTI/
|
85
|
-
if msg =~ /^.ME.,/
|
86
|
-
dputs(3) { "I think I got a new message: #{msg}" }
|
87
|
-
sms_scan true
|
88
|
-
else
|
89
|
-
log_msg :serialmodem, "Unknown: CMTI - #{msg}"
|
90
|
-
end
|
91
|
-
@serial_eats_sms and modem_send('AT+CNMI=0,0,0,0,0', 'OK')
|
92
|
-
# Probably a message or so - '+CMTI: "ME",0' is a new message
|
93
|
-
end
|
48
|
+
lock and @serial_mutex.lock
|
49
|
+
while !@serial_sp.eof? || wait
|
50
|
+
begin
|
51
|
+
@serial_replies.push rep = @serial_sp.readline.chomp
|
52
|
+
break if rep == wait
|
53
|
+
rescue EOFError => e
|
54
|
+
dputs(4) { 'Waited for string, but got nothing' }
|
55
|
+
break
|
94
56
|
end
|
95
57
|
end
|
58
|
+
lock and @serial_mutex.unlock
|
59
|
+
|
60
|
+
ret = interpret_serial_reply
|
96
61
|
rescue IOError => e
|
97
62
|
raise e
|
98
|
-
=begin
|
99
|
-
rescue Exception => e
|
100
|
-
puts "#{e.inspect}"
|
101
|
-
puts "#{e.to_s}"
|
102
|
-
puts e.backtrace
|
103
|
-
=end
|
104
63
|
end
|
105
64
|
ret
|
106
65
|
end
|
107
66
|
|
67
|
+
def interpret_serial_reply
|
68
|
+
ret = []
|
69
|
+
@serial_replies.each { |s| dputs(3) { s } }
|
70
|
+
while m = @serial_replies.shift
|
71
|
+
@serial_debug and dputs_func
|
72
|
+
dputs(3) { "Reply: #{m}" }
|
73
|
+
next if (m == '' || m =~ /^\^/)
|
74
|
+
ret.push m
|
75
|
+
if m =~ /\+[\w]{4}: /
|
76
|
+
code, msg = m[1..4], m[7..-1]
|
77
|
+
dputs(3) { "found code #{code.inspect} - #{msg.inspect}" }
|
78
|
+
@serial_codes[code] = msg
|
79
|
+
case code
|
80
|
+
when /CMGL/
|
81
|
+
# Typical input from the modem:
|
82
|
+
# "0,\"REC UNREAD\",\"+23599836457\",,\"15/04/08,17:12:21+04\""
|
83
|
+
# Output desired:
|
84
|
+
# ["0", "REC UNREAD", "+23599836457", "", "15/04/08,17:12:21+04"]
|
85
|
+
id, flag, number, unknown, date =
|
86
|
+
msg.scan(/"(.*?)"|([^",]+)\s*|,,/m).collect { |a, b| a.to_s + b.to_s }
|
87
|
+
msg = []
|
88
|
+
# Read all lines up to an empty line or a +CMGL: which indicates
|
89
|
+
# a new message
|
90
|
+
while @serial_replies[0] &&
|
91
|
+
@serial_replies[0] != '' &&
|
92
|
+
!(@serial_replies[0] =~ /^\+CMGL:/)
|
93
|
+
msg.push @serial_replies.shift
|
94
|
+
end
|
95
|
+
# If we finish with an empty line, delete it and the 'OK' that follows
|
96
|
+
if @serial_replies[0] == ''
|
97
|
+
@serial_replies.shift(2)
|
98
|
+
end
|
99
|
+
ret.push msg.join("\n")
|
100
|
+
sms_new(id, flag, number, date, ret.last, unknown)
|
101
|
+
when /CUSD/
|
102
|
+
if pdu = msg.match(/.*\"(.*)\".*/)
|
103
|
+
ussd_received(pdu_to_ussd(pdu[1]))
|
104
|
+
elsif msg == '2'
|
105
|
+
#log_msg :serialmodem, 'Closed USSD.'
|
106
|
+
#ussd_received('')
|
107
|
+
#ussd_close
|
108
|
+
else
|
109
|
+
log_msg :serialmodem, "Unknown: CUSD - #{msg}"
|
110
|
+
end
|
111
|
+
when /CMTI/
|
112
|
+
if msg =~ /^.ME.,/
|
113
|
+
dputs(3) { "I think I got a new message: #{msg}" }
|
114
|
+
@serial_sms_autoscan_last = Time.now - @serial_sms_autoscan
|
115
|
+
else
|
116
|
+
log_msg :serialmodem, "Unknown: CMTI - #{msg}"
|
117
|
+
end
|
118
|
+
# Probably a message or so - '+CMTI: "ME",0' is a new message
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
108
124
|
def sms_new(id, flag, number, date, msg, unknown = nil)
|
109
125
|
sms = {flag: flag, number: number, unknown: unknown, date: date,
|
110
126
|
msg: msg, id: id}
|
111
127
|
@serial_sms[id.to_s] = sms
|
112
|
-
|
113
|
-
|
114
|
-
rescue_all do
|
115
|
-
@serial_sms_new.each { |s|
|
116
|
-
s.call(sms)
|
117
|
-
}
|
118
|
-
end
|
119
|
-
end
|
128
|
+
log_msg :SerialModem, "New SMS: #{sms.inspect}"
|
129
|
+
@serial_sms_new_list.push(sms)
|
120
130
|
sms
|
121
131
|
end
|
122
132
|
|
123
|
-
def modem_send(str, reply = true)
|
133
|
+
def modem_send(str, reply = true, lock: true)
|
124
134
|
return unless @serial_sp
|
125
135
|
@serial_debug and dputs_func
|
126
136
|
dputs(3) { "Sending string #{str} to modem" }
|
127
|
-
@
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
137
|
+
lock and @serial_mutex.lock
|
138
|
+
begin
|
139
|
+
@serial_sp.write("#{str}\r\n")
|
140
|
+
rescue Errno::EIO => e
|
141
|
+
log_msg :SerialModem, "Couldn't write to device"
|
142
|
+
kill
|
143
|
+
return
|
144
|
+
rescue Errno::ENODEV => e
|
145
|
+
log_msg :SerialModem, 'Device is not here anymore'
|
146
|
+
kill
|
147
|
+
return
|
148
|
+
end
|
149
|
+
read_reply(reply, lock: false)
|
150
|
+
lock and @serial_mutex.unlock
|
151
|
+
end
|
152
|
+
|
153
|
+
def modem_send_array(cmds)
|
154
|
+
@serial_mutex.synchronize {
|
155
|
+
cmds.each { |str, reply=true|
|
156
|
+
modem_send(str, reply, lock: false)
|
157
|
+
}
|
139
158
|
}
|
140
|
-
read_reply(reply)
|
141
159
|
end
|
142
160
|
|
143
161
|
def switch_to_hilink
|
@@ -155,7 +173,7 @@ module SerialModem
|
|
155
173
|
|
156
174
|
def pdu_to_ussd(str)
|
157
175
|
[str].pack('H*').unpack('b*').join.scan(/.{7}/).
|
158
|
-
map { |s| [s+
|
176
|
+
map { |s| [s+'0'].pack('b*') }.join
|
159
177
|
end
|
160
178
|
|
161
179
|
def ussd_send_now
|
@@ -164,7 +182,7 @@ module SerialModem
|
|
164
182
|
@serial_ussd_last = Time.now
|
165
183
|
if str_send
|
166
184
|
#log_msg :SerialModem, "Sending ussd-string #{str_send} with add of #{@ussd_add} "+
|
167
|
-
|
185
|
+
#"and queue #{@serial_ussd}"
|
168
186
|
modem_send("AT+CUSD=1,\"#{ussd_to_pdu(str_send)}\"#{@ussd_add}", 'OK')
|
169
187
|
else
|
170
188
|
dputs(2) { 'Sending ussd-close' }
|
@@ -179,6 +197,7 @@ module SerialModem
|
|
179
197
|
end
|
180
198
|
|
181
199
|
def ussd_send(str)
|
200
|
+
# dputs_func
|
182
201
|
if str.class == String
|
183
202
|
dputs(3) { "Sending ussd-code #{str}" }
|
184
203
|
@serial_ussd.push str
|
@@ -189,6 +208,7 @@ module SerialModem
|
|
189
208
|
@serial_ussd.push nil
|
190
209
|
@serial_ussd.length == str.length + 1 and ussd_send_now
|
191
210
|
end
|
211
|
+
@serial_ussd_sent = 0
|
192
212
|
end
|
193
213
|
|
194
214
|
def ussd_store_result(str)
|
@@ -199,7 +219,8 @@ module SerialModem
|
|
199
219
|
code: code, result: str)
|
200
220
|
@serial_ussd_results.shift([0, @serial_ussd_results.length -
|
201
221
|
@serial_ussd_results_max].max)
|
202
|
-
|
222
|
+
@serial_ussd_send_next = true
|
223
|
+
@serial_ussd_sent = 0
|
203
224
|
code
|
204
225
|
else
|
205
226
|
#log_msg :serialmodem, "Got unasked code #{str}"
|
@@ -210,9 +231,7 @@ module SerialModem
|
|
210
231
|
def ussd_received(str)
|
211
232
|
code = ussd_store_result(str)
|
212
233
|
dputs(2) { "Got result for #{code}: -#{str}-" }
|
213
|
-
@
|
214
|
-
s.call(code, str)
|
215
|
-
}
|
234
|
+
@serial_ussd_new_list.push([code, str])
|
216
235
|
end
|
217
236
|
|
218
237
|
def ussd_fetch(str)
|
@@ -224,9 +243,9 @@ module SerialModem
|
|
224
243
|
|
225
244
|
def sms_send(number, msg)
|
226
245
|
log_msg :SerialModem, "Sending SMS --#{msg.inspect}-- to --#{number.inspect}--"
|
227
|
-
|
228
|
-
|
229
|
-
|
246
|
+
modem_send_array([['AT+CMGF=1', 'OK'],
|
247
|
+
["AT+CMGS=\"#{number}\""],
|
248
|
+
["#{msg}\x1a", 'OK']])
|
230
249
|
end
|
231
250
|
|
232
251
|
def sms_scan(force = false)
|
@@ -234,8 +253,10 @@ module SerialModem
|
|
234
253
|
Time.now - @serial_sms_autoscan_last > @serial_sms_autoscan)
|
235
254
|
dputs(3) { 'Auto-scanning sms' }
|
236
255
|
@serial_sms_autoscan_last = Time.now
|
237
|
-
|
238
|
-
|
256
|
+
req = [['AT+CMGF=1', 'OK'],
|
257
|
+
['AT+CMGL="ALL"', 'OK']]
|
258
|
+
@serial_eats_sms and req.push(['AT+CNMI=0,0,0,0,0', 'OK'])
|
259
|
+
modem_send_array(req)
|
239
260
|
end
|
240
261
|
end
|
241
262
|
|
@@ -249,8 +270,8 @@ module SerialModem
|
|
249
270
|
end
|
250
271
|
|
251
272
|
def get_operator
|
252
|
-
|
253
|
-
|
273
|
+
modem_send_array([['AT+COPS=3,0', 'OK'],
|
274
|
+
['AT+COPS?', 'OK']])
|
254
275
|
(1..6).each {
|
255
276
|
if @serial_codes.has_key? 'COPS'
|
256
277
|
return '' if @serial_codes['COPS'] == '0'
|
@@ -288,39 +309,46 @@ module SerialModem
|
|
288
309
|
def setup_tty
|
289
310
|
check_presence
|
290
311
|
|
291
|
-
@
|
312
|
+
@serial_mutex.synchronize {
|
292
313
|
if !@serial_sp && @serial_tty
|
293
314
|
if File.exists? @serial_tty
|
294
|
-
dputs(2){ 'setting up SerialPort'}
|
315
|
+
dputs(2) { 'setting up SerialPort' }
|
295
316
|
@serial_sp = SerialPort.new(@serial_tty, 115200)
|
296
317
|
@serial_sp.read_timeout = 500
|
297
318
|
end
|
298
319
|
elsif @serial_sp &&
|
299
320
|
(!@serial_tty||(@serial_tty && !File.exists?(@serial_tty)))
|
300
|
-
dputs(2){'disconnecting modem'}
|
321
|
+
dputs(2) { 'disconnecting modem' }
|
301
322
|
kill
|
302
323
|
end
|
303
324
|
}
|
304
325
|
if @serial_sp
|
305
|
-
dputs(2){'initialising modem'}
|
326
|
+
dputs(2) { 'initialising modem' }
|
306
327
|
init_modem
|
307
328
|
start_serial_thread
|
308
329
|
if !@serial_sp
|
309
|
-
dputs(2){'Lost serial-connection while initialising -
|
330
|
+
dputs(2) { 'Lost serial-connection while initialising - killing and reloading' }
|
310
331
|
kill
|
311
332
|
reload_option
|
312
|
-
|
313
|
-
return
|
333
|
+
return false
|
314
334
|
end
|
315
|
-
dputs(2){'finished connecting'}
|
335
|
+
dputs(2) { 'finished connecting' }
|
316
336
|
end
|
337
|
+
return @serial_sp != nil
|
317
338
|
end
|
318
339
|
|
319
340
|
def check_presence
|
320
|
-
@
|
341
|
+
@serial_mutex.synchronize {
|
321
342
|
@serial_tty.to_s.length > 0 and File.exists?(@serial_tty) and return
|
343
|
+
System.exists?('lsusb') or return
|
322
344
|
case lsusb = System.run_str('lsusb')
|
323
|
-
when /
|
345
|
+
when /19d2:fff1/
|
346
|
+
log_msg :SerialModem, 'Found CDMA-modem with ttyUSB0-ttyUSB4'
|
347
|
+
@serial_tty_error = '/dev/ttyUSB5'
|
348
|
+
@serial_tty = '/dev/ttyUSB1'
|
349
|
+
@ussd_add = ''
|
350
|
+
@serial_eats_sms = true
|
351
|
+
when /12d1:1506/, /12d1:14ac/, /12d1:1c05/, /12d1:1001/
|
324
352
|
log_msg :SerialModem, 'Found 3G-modem with ttyUSB0-ttyUSB2'
|
325
353
|
@serial_tty_error = '/dev/ttyUSB3'
|
326
354
|
@serial_tty = '/dev/ttyUSB2'
|
@@ -335,8 +363,8 @@ module SerialModem
|
|
335
363
|
#puts caller.join("\n")
|
336
364
|
@serial_tty = @serial_tty_error = nil
|
337
365
|
end
|
338
|
-
dputs(2){"serial_tty is #{@serial_tty.inspect} and exists " +
|
339
|
-
|
366
|
+
dputs(2) { "serial_tty is #{@serial_tty.inspect} and exists " +
|
367
|
+
"#{File.exists?(@serial_tty.to_s)}" }
|
340
368
|
if @serial_tty_error && File.exists?(@serial_tty_error)
|
341
369
|
log_msg :SerialModem, 'resetting modem'
|
342
370
|
reload_option
|
@@ -346,27 +374,53 @@ module SerialModem
|
|
346
374
|
|
347
375
|
def start_serial_thread
|
348
376
|
@serial_thread = Thread.new {
|
349
|
-
#dputs_func
|
350
|
-
dputs(2){'Thread started'}
|
351
|
-
|
377
|
+
# dputs_func
|
378
|
+
dputs(2) { 'Thread started' }
|
379
|
+
while @serial_sp do
|
352
380
|
begin
|
353
|
-
dputs(
|
354
|
-
|
355
|
-
#@serial_sms.each { |id, sms|
|
356
|
-
# ddputs(3) { "Deleting sms #{sms.inspect} afterwards" }
|
357
|
-
# sms_delete(id)
|
358
|
-
#}
|
359
|
-
end
|
381
|
+
dputs(3) { 'Reading out modem' }
|
382
|
+
read_reply
|
360
383
|
|
361
384
|
dputs(4) { (Time.now - @serial_ussd_last).to_s }
|
362
|
-
if
|
363
|
-
|
364
|
-
log_msg :SerialModem, "Re-sending #{@serial_ussd.first}"
|
385
|
+
if @serial_ussd_send_next
|
386
|
+
@serial_ussd_send_next = false
|
365
387
|
ussd_send_now
|
388
|
+
elsif ((Time.now - @serial_ussd_last > @serial_ussd_timeout) &&
|
389
|
+
(@serial_ussd.length > 0)) || @serial_ussd_send_next
|
390
|
+
if (@serial_ussd_sent += 1) <= @serial_ussd_sent_max
|
391
|
+
log_msg :SerialModem, "Re-sending #{@serial_ussd.first} for #{@serial_ussd_sent}"
|
392
|
+
ussd_send_now
|
393
|
+
else
|
394
|
+
log_msg :SerialModem, "Discarding #{@serial_ussd.first}"
|
395
|
+
@serial_ussd.shift
|
396
|
+
@serial_ussd_sent = 0
|
397
|
+
end
|
366
398
|
end
|
367
399
|
|
368
400
|
sms_scan
|
369
401
|
|
402
|
+
# Check for any new sms and call attached methods
|
403
|
+
while (sms = @serial_sms_new_list.shift) do
|
404
|
+
rescue_all do
|
405
|
+
if sms._flag =~ /unread/i
|
406
|
+
@serial_sms_new.each { |s|
|
407
|
+
s.call(sms)
|
408
|
+
}
|
409
|
+
else
|
410
|
+
dputs(2) { "Already read sms: #{sms}" }
|
411
|
+
end
|
412
|
+
sms_delete(sms._id)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
# Check for any new ussds and call attached methods
|
417
|
+
while (ussd = @serial_ussd_new_list.shift) do
|
418
|
+
code, str = ussd
|
419
|
+
@serial_ussd_new.each { |s|
|
420
|
+
s.call(code, str)
|
421
|
+
}
|
422
|
+
end
|
423
|
+
|
370
424
|
sleep 0.5
|
371
425
|
rescue IOError
|
372
426
|
log_msg :SerialModem, 'IOError - killing modem'
|
@@ -378,8 +432,8 @@ module SerialModem
|
|
378
432
|
e.backtrace.each { |l| dputs(0) { l } }
|
379
433
|
end
|
380
434
|
dputs(5) { 'Finished' }
|
381
|
-
|
382
|
-
dputs(
|
435
|
+
end
|
436
|
+
dputs(0) { '@serial_sp disappeared - quitting' }
|
383
437
|
}
|
384
438
|
end
|
385
439
|
|
@@ -387,7 +441,7 @@ module SerialModem
|
|
387
441
|
@serial_sp and @serial_sp.close
|
388
442
|
@serial_sp = nil
|
389
443
|
dputs(1) { 'Trying to reload modem-driver - killing and reloading' }
|
390
|
-
%w(
|
444
|
+
%w(chat ppp).each { |pro|
|
391
445
|
System.run_str("killall -9 #{pro}")
|
392
446
|
}
|
393
447
|
%w(rmmod modprobe).each { |cmd|
|
@@ -397,6 +451,7 @@ module SerialModem
|
|
397
451
|
|
398
452
|
def kill
|
399
453
|
#dputs_func
|
454
|
+
#puts "Killed by \n" + caller.join("\n")
|
400
455
|
if @serial_thread
|
401
456
|
if @serial_thread.alive?
|
402
457
|
dputs(3) { 'Killing thread' }
|
data/lib/test
ADDED
data/serial_modem.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'serial_modem'
|
7
|
-
spec.version = '0.3.
|
7
|
+
spec.version = '0.3.5'
|
8
8
|
spec.authors = ['Linus Gasser']
|
9
9
|
spec.email = ['ineiti@linusetviviane.ch']
|
10
10
|
spec.summary = %q{Interface to serial-usb-modems}
|
@@ -12,12 +12,12 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/ineiti/SerialModem'
|
13
13
|
spec.license = 'GPLv3'
|
14
14
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.files = `if [ -d '.git' ]; then git ls-files -z; fi`.split("\x0")
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
21
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
22
22
|
spec.add_runtime_dependency 'serialport', '1.3.1'
|
23
23
|
end
|
File without changes
|
data/test/run_thread.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
$m = Mutex.new
|
5
|
+
|
6
|
+
def killme
|
7
|
+
t.kill
|
8
|
+
t.join
|
9
|
+
end
|
10
|
+
|
11
|
+
$t = Thread.new {
|
12
|
+
$m.synchronize {
|
13
|
+
loop do
|
14
|
+
puts "In thread"
|
15
|
+
sleep 1
|
16
|
+
killme
|
17
|
+
end
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
sleep 2
|
22
|
+
|
23
|
+
$m.synchronize {
|
24
|
+
puts "OK to synch here"
|
25
|
+
}
|
data/test/sm_receive.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'serial_modem'
|
3
|
+
|
4
|
+
class SM_receive < Test::Unit::TestCase
|
5
|
+
include SerialModem
|
6
|
+
|
7
|
+
def setup
|
8
|
+
setup_modem
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_receive_sms
|
16
|
+
str = 'AT+CMGL="ALL"
|
17
|
+
+CMGL: 1,"REC UNREAD","192",,"15/06/24,09:14:06+04"
|
18
|
+
Souscription reussie:GPRS 3030. 10240MB valable 30 jours. Cout 50000F
|
19
|
+
|
20
|
+
OK'
|
21
|
+
@serial_replies = str.split("\n")
|
22
|
+
interpret_serial_reply
|
23
|
+
assert_equal({'1' =>
|
24
|
+
{:flag => 'REC UNREAD',
|
25
|
+
:number => '192',
|
26
|
+
:unknown => '',
|
27
|
+
:date => '15/06/24,09:14:06+04',
|
28
|
+
:msg =>
|
29
|
+
'Souscription reussie:GPRS 3030. 10240MB valable 30 jours. Cout 50000F',
|
30
|
+
:id => '1'}}, @serial_sms)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_receive_two_sms
|
34
|
+
str = 'AT+CMGL="ALL"
|
35
|
+
+CMGL: 0,"REC UNREAD","+121",,"15/06/24,21:20:01+04"
|
36
|
+
Cmd: stat1
|
37
|
+
+CMGL: 1,"REC UNREAD","+121",,"15/06/24,21:20:01+04"
|
38
|
+
Cmd: stat2
|
39
|
+
|
40
|
+
OK'
|
41
|
+
@serial_replies = str.split("\n")
|
42
|
+
interpret_serial_reply
|
43
|
+
assert_equal({'0' =>
|
44
|
+
{:flag => 'REC UNREAD',
|
45
|
+
:number => '+121',
|
46
|
+
:unknown => '',
|
47
|
+
:date => '15/06/24,21:20:01+04',
|
48
|
+
:msg => 'Cmd: stat1',
|
49
|
+
:id => '0'},
|
50
|
+
'1' =>
|
51
|
+
{:flag => 'REC UNREAD',
|
52
|
+
:number => '+121',
|
53
|
+
:unknown => '',
|
54
|
+
:date => '15/06/24,21:20:01+04',
|
55
|
+
:msg => 'Cmd: stat2',
|
56
|
+
:id => '1'}}, @serial_sms)
|
57
|
+
end
|
58
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
DEBUG_LVL=3
|
7
|
+
|
8
|
+
require 'serial_modem'
|
9
|
+
|
10
|
+
tests = Dir.glob('sm_*.rb')
|
11
|
+
tests = %w( receive )
|
12
|
+
|
13
|
+
$LOAD_PATH.push '.'
|
14
|
+
tests.each { |t|
|
15
|
+
begin
|
16
|
+
require "sm_#{t}"
|
17
|
+
rescue LoadError => e
|
18
|
+
require t
|
19
|
+
end
|
20
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serial_modem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linus Gasser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.9'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,9 +66,13 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- commit
|
68
68
|
- lib/serial_modem.rb
|
69
|
+
- lib/test
|
69
70
|
- serial_modem.gemspec
|
71
|
+
- test/run_hw.rb
|
70
72
|
- test/run_test
|
71
|
-
- test/
|
73
|
+
- test/run_thread.rb
|
74
|
+
- test/sm_receive.rb
|
75
|
+
- test/test.rb
|
72
76
|
homepage: https://github.com/ineiti/SerialModem
|
73
77
|
licenses:
|
74
78
|
- GPLv3
|
@@ -89,10 +93,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
93
|
version: '0'
|
90
94
|
requirements: []
|
91
95
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.6.13
|
93
97
|
signing_key:
|
94
98
|
specification_version: 4
|
95
99
|
summary: Interface to serial-usb-modems
|
96
100
|
test_files:
|
101
|
+
- test/run_hw.rb
|
97
102
|
- test/run_test
|
98
|
-
- test/
|
103
|
+
- test/run_thread.rb
|
104
|
+
- test/sm_receive.rb
|
105
|
+
- test/test.rb
|