smartware 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ module Smartware
21
21
  end
22
22
 
23
23
  def error
24
- false
24
+ @error ||= false
25
25
  end
26
26
 
27
27
  def model
@@ -30,7 +30,7 @@ module Smartware
30
30
  res.pop
31
31
  res.join(' ')
32
32
  rescue
33
- ERRORS["20"]
33
+ @error = ERRORS["20"]
34
34
  end
35
35
 
36
36
  #
@@ -41,7 +41,7 @@ module Smartware
41
41
  value = res[1].gsub("+CSQ: ",'').split(',')[0].to_i
42
42
  "#{(-113 + value * 2)} dbm"
43
43
  rescue
44
- ERRORS["21"]
44
+ @error = ERRORS["21"]
45
45
  end
46
46
 
47
47
  #
@@ -53,15 +53,18 @@ module Smartware
53
53
  # Valid ussd answer sample: ["", "+CUSD: 2,\"003100310035002C003000300440002E00320031002E00330031002004310430043B002E0020\",72", "OK"]
54
54
  #
55
55
  def ussd(code="*100#")
56
- res = self.send "AT+CUSD=1,\"#{code}\",15\r\n"
57
- return ERRORS["11"] unless res.size >= 3
56
+ res = self.send "AT+CUSD=1,\"#{code}\",15"
57
+ unless res[1][0..4] == "+CUSD"
58
+ @error = ERRORS["11"]
59
+ return false
60
+ end
58
61
 
59
62
  ussd_body = res[1].split(",")[1].gsub('"','') # Parse USSD message body
60
- result = ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join # Encode USSD message from broken ucs2 to utf-8
63
+ result = ussd_body.scan(/\w{4}/).map{|i| [i.hex].pack("U") }.join.strip # Encode USSD message from broken ucs2 to utf-8
61
64
  port.close
62
65
  result
63
66
  rescue
64
- ERRORS["10"]
67
+ @error = ERRORS["10"]
65
68
  end
66
69
 
67
70
  def send(cmd, read_timeout = 0.25)
@@ -1,3 +1,3 @@
1
1
  module Smartware
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.12"
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.10
4
+ version: 0.1.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-26 00:00:00.000000000 Z
13
+ date: 2012-12-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: serialport