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
- res = self.send "AT+CUSD=1,\"#{code}\",15"
58
- ussd_body = res[1].split(",")[1].gsub('"','') # Parse USSD message body
59
- ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join.strip # Encode USSD message from broken ucs2 to utf-8
60
- rescue
61
- @error = ERRORS["10"]
62
- return false
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
- answer = read_port @sp
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] = @device.model
54
- @status[:error] = @device.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
@@ -1,3 +1,3 @@
1
1
  module Smartware
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: