smartware 0.1.18 → 0.1.19
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.
@@ -54,23 +54,20 @@ module Smartware
|
|
54
54
|
# Valid ussd answer sample: ["", "+CUSD: 2,\"003100310035002C003000300440002E00320031002E00330031002004310430043B002E0020\",72", "OK"]
|
55
55
|
#
|
56
56
|
def ussd(code="*100#")
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
sleep 3
|
58
|
+
res = self.send("AT+CUSD=1,\"*100#\",15").reject{|i| i[0..4] != '+CUSD'}[0]
|
59
|
+
if res
|
60
|
+
ussd_body = res.split(",")[1].gsub('"','') # Parse USSD message body
|
61
|
+
ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join.strip # Encode USSD message from broken ucs2 to utf-8
|
62
|
+
else
|
63
|
+
@error = ERRORS["10"]
|
64
|
+
false
|
65
|
+
end
|
63
66
|
end
|
64
67
|
|
65
68
|
def send(cmd)
|
66
|
-
read_port @sp # Port clear
|
67
|
-
|
68
|
-
@sp.write "AT\r\n"
|
69
|
-
check_ability = read_port @sp
|
70
|
-
return ERRORS["-1"] unless check_ability == ["AT", "OK"]
|
71
|
-
|
72
69
|
@sp.write "#{ cmd }\r\n"
|
73
|
-
|
70
|
+
read_port(@sp)
|
74
71
|
end
|
75
72
|
|
76
73
|
def read_port(io, read_timeout = 0.25)
|
@@ -50,8 +50,8 @@ module Smartware
|
|
50
50
|
t = Thread.new do
|
51
51
|
loop do
|
52
52
|
@status[:signal_level] = @device.signal_level
|
53
|
-
@status[:model]
|
54
|
-
@status[:error]
|
53
|
+
@status[:model] = @device.model
|
54
|
+
@status[:error] = @device.error
|
55
55
|
|
56
56
|
balance = @device.ussd("*100#")
|
57
57
|
@status[:balance] = balance unless balance
|
data/lib/smartware/version.rb
CHANGED