sim_card 0.0.2 → 0.0.3
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.
- data/lib/sim_card/signal_quality.rb +33 -0
- data/lib/sim_card/sim.rb +21 -14
- data/lib/sim_card.rb +6 -3
- metadata +4 -3
@@ -0,0 +1,33 @@
|
|
1
|
+
class SimCard
|
2
|
+
class SignalQuality
|
3
|
+
attr_reader :signal_strength
|
4
|
+
|
5
|
+
def initialize raw_sim_output
|
6
|
+
@raw_sim_output = raw_sim_output
|
7
|
+
@signal_strength = nil
|
8
|
+
@bit_error_rate_min = nil
|
9
|
+
@bit_error_rate_max = nil
|
10
|
+
parse
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def parse
|
15
|
+
a = @raw_sim_output.split("\n")
|
16
|
+
if a[1] && a[1].include?('+CSQ: ')
|
17
|
+
b = a[1].match /(\d+),(\d+)/
|
18
|
+
if b.size == 3
|
19
|
+
raw_signal_strength = b[1].to_i
|
20
|
+
parse_signal_strength raw_signal_strength
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_signal_strength raw_signal_strength
|
26
|
+
if raw_signal_strength >= 0 && raw_signal_strength <= 31
|
27
|
+
@signal_strength = (2 * raw_signal_strength) - 113
|
28
|
+
elsif raw_signal_strength == 99
|
29
|
+
# not known
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/sim_card/sim.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class SimCard
|
2
2
|
|
3
|
-
# code below is based on:
|
4
|
-
# http://www.dzone.com/snippets/send-and-receive-sms-text
|
3
|
+
# code below is based on:
|
4
|
+
# http://www.dzone.com/snippets/send-and-receive-sms-text
|
5
5
|
|
6
6
|
class Sim
|
7
7
|
|
@@ -15,12 +15,12 @@ class SimCard
|
|
15
15
|
options = default_options.merge user_options
|
16
16
|
|
17
17
|
@port = SerialPort.new(options[:port], options[:speed])
|
18
|
-
|
19
|
-
|
18
|
+
send_raw_at_command("AT")
|
19
|
+
send_raw_at_command("AT+CPIN=\"#{options[:pin]}\"")
|
20
20
|
# Set to text mode
|
21
|
-
|
21
|
+
send_raw_at_command("AT+CMGF=1")
|
22
22
|
# Set SMSC number
|
23
|
-
|
23
|
+
send_raw_at_command("AT+CSCA=\"#{options[:sms_center_no]}\"") if options[:sms_center_no]
|
24
24
|
end
|
25
25
|
|
26
26
|
# correctly disconnect from SIM card
|
@@ -29,32 +29,39 @@ class SimCard
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def send_sms number, message_text
|
32
|
-
|
33
|
-
|
32
|
+
send_raw_at_command("AT+CMGS=\"#{number}\"")
|
33
|
+
send_raw_at_command("#{message_text[0..140]}#{26.chr}\r\r")
|
34
34
|
sleep 3
|
35
35
|
wait
|
36
|
-
|
36
|
+
send_raw_at_command("AT")
|
37
37
|
end
|
38
38
|
|
39
39
|
# list SMS messages in SIM memory
|
40
40
|
def sms_messages
|
41
|
-
raw_sim_output =
|
41
|
+
raw_sim_output = send_raw_at_command("AT+CMGL=\"ALL\"")
|
42
42
|
ReceivedSmsMessage.to_messages raw_sim_output
|
43
43
|
end
|
44
44
|
|
45
45
|
# remove SMS message from SIM card memory
|
46
46
|
# * sms_message: instance of SimCard::SmsMessage to be deleted
|
47
47
|
def delete_sms_message sms_message
|
48
|
-
|
48
|
+
send_raw_at_command("AT+CMGD=#{sms_message.message_id}")
|
49
49
|
end
|
50
|
-
|
51
|
-
|
52
|
-
def
|
50
|
+
|
51
|
+
# in dBm. -60 is almost perfect signal, -112 is very poor (call dropping bad)
|
52
|
+
def signal_strength
|
53
|
+
raw_sim_output = send_raw_at_command 'AT+CSQ'
|
54
|
+
sq = SimCard::SignalQuality.new raw_sim_output
|
55
|
+
return sq.signal_strength
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_raw_at_command cmd
|
53
59
|
# puts "SIM CMD IN:#{cmd}"
|
54
60
|
@port.write(cmd + "\r")
|
55
61
|
wait
|
56
62
|
end
|
57
63
|
|
64
|
+
private
|
58
65
|
def wait
|
59
66
|
buffer = ''
|
60
67
|
while IO.select([@port], [], [], 0.25)
|
data/lib/sim_card.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
# see README
|
1
|
+
# see README or visit https://github.com/petervojtek/sim_card.gem
|
2
2
|
class SimCard
|
3
3
|
end
|
4
4
|
|
5
5
|
require 'date'
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
root = File.join(File.dirname(__FILE__), 'sim_card')
|
8
|
+
require File.join(root, 'received_sms_message.rb')
|
9
|
+
require File.join(root, 'sim.rb')
|
10
|
+
require File.join(root, 'signal_quality.rb')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sim_card
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -20,7 +20,8 @@ files:
|
|
20
20
|
- lib/sim_card.rb
|
21
21
|
- lib/sim_card/sim.rb
|
22
22
|
- lib/sim_card/received_sms_message.rb
|
23
|
-
|
23
|
+
- lib/sim_card/signal_quality.rb
|
24
|
+
homepage: https://github.com/petervojtek/sim_card.gem
|
24
25
|
licenses:
|
25
26
|
- MIT
|
26
27
|
post_install_message:
|