smartware 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -45,28 +45,29 @@ module Smartware
|
|
45
45
|
# Don`t call with method synchronously from app, method waits USSD answer 3 sec,
|
46
46
|
# Use some scheduler and buffer for balance value
|
47
47
|
#
|
48
|
-
def ussd(code="*100#")
|
48
|
+
def ussd(code="*100#", use_gets = false)
|
49
49
|
port = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
|
50
50
|
port.read_timeout = 3000
|
51
51
|
port.write "AT+CUSD=1,\"#{code}\",15\r\n"
|
52
|
-
|
52
|
+
result = use_gets ? port.gets : port.read
|
53
|
+
# Parse USSD message body
|
54
|
+
ussd_body = result.split(/[\r\n]+/).last.split(",")[1].gsub('"','')
|
53
55
|
port.close
|
54
|
-
|
56
|
+
# Encode USSD message from broken ucs2 to utf-8
|
57
|
+
ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join
|
55
58
|
rescue
|
56
59
|
-1
|
57
60
|
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
answer << chr
|
66
|
-
end
|
67
|
-
answer.split(/[\r\n]+/)
|
62
|
+
def send(cmd, read_timeout = 0.25)
|
63
|
+
@sp.write "#{ cmd }\r\n"
|
64
|
+
answer = ''
|
65
|
+
while IO.select [@sp], [], [], read_timeout
|
66
|
+
chr = @sp.getc.chr
|
67
|
+
answer << chr
|
68
68
|
end
|
69
|
-
|
69
|
+
answer.split(/[\r\n]+/)
|
70
|
+
end
|
70
71
|
end
|
71
72
|
|
72
73
|
end
|
data/lib/smartware/version.rb
CHANGED