Add support for +CPIN? and use SIM status before entering PIN

develop
Guillaume DOTT 2013-09-11 17:27:56 +02:00
parent aabb2027b0
commit 550a2b4d3d
3 changed files with 20 additions and 2 deletions

View File

@ -79,8 +79,12 @@ module Biju
nil
end
def pin_status
at_command('+CPIN?')[:result]
end
def unlock_pin(pin)
at_command('+CPIN', pin)[:status]
at_command('+CPIN', pin)[:status] if pin_status == 'SIM PIN'
end
def messages(which = :all)

View File

@ -17,7 +17,7 @@ module Biju
# RESPONSE
rule(:response) { ((command.maybe >> status) | merror) >> crlf | prompt }
rule(:prompt) { str('> ').as(:prompt) }
rule(:command) { mgl | num | pms | mgf | mgs }
rule(:command) { mgl | num | pin | pms | mgf | mgs }
rule(:merror) do
(str('+CME ERROR') | str('+CMS ERROR')).as(:cmd) >> str(': ') >>
@ -39,6 +39,9 @@ module Biju
rule(:mgf) do
str('+CMGF').as(:cmd) >> str(': ') >> boolean.as(:result) >> crlf >> crlf
end
rule(:pin) do
str('+CPIN').as(:cmd) >> str(': ') >> eol.as(:result) >> crlf >> crlf
end
rule(:mgs) do
str('+CMGS').as(:cmd) >> str(': ') >> int.as(:result) >> crlf >> crlf
end
@ -66,6 +69,7 @@ module Biju
rule(:string) { quote >> match('[^\"]').repeat.as(:string) >> quote }
rule(:int) { match('[0-9]').repeat(1).as(:int) }
rule(:boolean) { match('[01]').as(:boolean) }
rule(:eol) { (crlf.absent? >> any).repeat.as(:string) }
rule(:datetime) { quote >> (date >> str(',') >> time).as(:datetime) >> quote }
rule(:date) do

View File

@ -93,6 +93,16 @@ describe Biju::ATParser do
expect(result[:array]).to eq([23, 23, 7, 100, 7, 100])
end
it "gets pin status" do
pin = "AT+CPIN?\r\r\n+CPIN: READY\r\n\r\nOK\r\n"
result = Biju::ATTransform.new.apply(
Biju::ATParser.new.parse(pin))
expect(result).to include(status: true)
expect(result[:result]).to eq("READY")
end
it "parses +CMGF? response" do
mgf = "AT+CMGF?\r\r\n+CMGF: 0\r\n\r\nOK\r\n"