Add +CMGF? support and text_mode? method
parent
c0a3fe8ef0
commit
b4f49569bb
|
@ -40,6 +40,11 @@ module Biju
|
||||||
at_command('+CMGF', enabled)[:status]
|
at_command('+CMGF', enabled)[:status]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def text_mode?(force = false)
|
||||||
|
@text_mode = at_command('+CMGF?')[:result] if @text_mode.nil? || force
|
||||||
|
@text_mode
|
||||||
|
end
|
||||||
|
|
||||||
def extended_error(enabled = true)
|
def extended_error(enabled = true)
|
||||||
at_command('+CMEE', enabled)[:status]
|
at_command('+CMEE', enabled)[:status]
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Biju
|
||||||
|
|
||||||
# RESPONSE
|
# RESPONSE
|
||||||
rule(:response) { cr >> crlf >> (status | command) >> crlf }
|
rule(:response) { cr >> crlf >> (status | command) >> crlf }
|
||||||
rule(:command) { mgl | pms | mserror }
|
rule(:command) { mgl | pms | mgf | mserror }
|
||||||
|
|
||||||
rule(:mserror) { str('+CMS ERROR').as(:cmd) >> str(': ') >> message }
|
rule(:mserror) { str('+CMS ERROR').as(:cmd) >> str(': ') >> message }
|
||||||
rule(:mgl) do
|
rule(:mgl) do
|
||||||
|
@ -24,6 +24,9 @@ module Biju
|
||||||
str('+CPMS').as(:cmd) >> str(': ') >> str('(').maybe >> array >> str(')').maybe >>
|
str('+CPMS').as(:cmd) >> str(': ') >> str('(').maybe >> array >> str(')').maybe >>
|
||||||
crlf >> crlf >> status
|
crlf >> crlf >> status
|
||||||
end
|
end
|
||||||
|
rule(:mgf) do
|
||||||
|
str('+CMGF').as(:cmd) >> str(': ') >> boolean.as(:result) >> crlf >> crlf >> status
|
||||||
|
end
|
||||||
|
|
||||||
rule(:array) do
|
rule(:array) do
|
||||||
(data >> (comma >> data).repeat).as(:array)
|
(data >> (comma >> data).repeat).as(:array)
|
||||||
|
@ -47,6 +50,7 @@ module Biju
|
||||||
rule(:empty_string) { str('').as(:empty_string) }
|
rule(:empty_string) { str('').as(:empty_string) }
|
||||||
rule(:string) { quote >> match('[^\"]').repeat.as(:string) >> quote }
|
rule(:string) { quote >> match('[^\"]').repeat.as(:string) >> quote }
|
||||||
rule(:int) { match('[0-9]').repeat(1).as(:int) }
|
rule(:int) { match('[0-9]').repeat(1).as(:int) }
|
||||||
|
rule(:boolean) { match('[01]').as(:boolean) }
|
||||||
|
|
||||||
rule(:datetime) { quote >> (date >> str(',') >> time).as(:datetime) >> quote }
|
rule(:datetime) { quote >> (date >> str(',') >> time).as(:datetime) >> quote }
|
||||||
rule(:date) do
|
rule(:date) do
|
||||||
|
@ -65,9 +69,13 @@ module Biju
|
||||||
rule(cmd: simple(:cmd), array: subtree(:array)) do
|
rule(cmd: simple(:cmd), array: subtree(:array)) do
|
||||||
{cmd: cmd.to_s, array: array}
|
{cmd: cmd.to_s, array: array}
|
||||||
end
|
end
|
||||||
|
rule(cmd: simple(:cmd), result: simple(:result)) do
|
||||||
|
{cmd: cmd.to_s, result: result}
|
||||||
|
end
|
||||||
|
|
||||||
rule(empty_string: simple(:empty_string)) { '' }
|
rule(empty_string: simple(:empty_string)) { '' }
|
||||||
rule(int: simple(:int)) { int.to_i }
|
rule(int: simple(:int)) { int.to_i }
|
||||||
|
rule(boolean: simple(:boolean)) { boolean.to_i > 0 }
|
||||||
rule(string: simple(:string)) { string.to_s }
|
rule(string: simple(:string)) { string.to_s }
|
||||||
rule(datetime: simple(:datetime)) { DateTime.strptime(datetime.to_s, "%y/%m/%d,%T%Z") }
|
rule(datetime: simple(:datetime)) { DateTime.strptime(datetime.to_s, "%y/%m/%d,%T%Z") }
|
||||||
rule(array: subtree(:array)) { array }
|
rule(array: subtree(:array)) { array }
|
||||||
|
|
|
@ -4,19 +4,20 @@ require 'biju/parser'
|
||||||
describe Biju::ATParser do
|
describe Biju::ATParser do
|
||||||
context "status" do
|
context "status" do
|
||||||
it "returns ok status" do
|
it "returns ok status" do
|
||||||
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("OK\r\n"))
|
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("AT\r\r\nOK\r\n"))
|
||||||
expect(result).to include(status: true)
|
expect(result).to include(status: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns error status" do
|
it "returns error status" do
|
||||||
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("ERROR\r\n"))
|
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("AT\r\r\nERROR\r\n"))
|
||||||
expect(result).to include(status: false)
|
expect(result).to include(status: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "response" do
|
context "response" do
|
||||||
it "parses messages list" do
|
it "parses messages list" do
|
||||||
messages = "+CMGL: 0,1,,23\r\n" <<
|
messages = "AT+CMGL=1\r\r\n" <<
|
||||||
|
"+CMGL: 0,1,,23\r\n" <<
|
||||||
"07913396050066F3040B91336789\r\n" <<
|
"07913396050066F3040B91336789\r\n" <<
|
||||||
"+CMGL: 3,1,,74\r\n" <<
|
"+CMGL: 3,1,,74\r\n" <<
|
||||||
"BD60B917ACC68AC17431982E066BC5642205F3C95400\r\n" <<
|
"BD60B917ACC68AC17431982E066BC5642205F3C95400\r\n" <<
|
||||||
|
@ -33,7 +34,7 @@ describe Biju::ATParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gets messages storage" do
|
it "gets messages storage" do
|
||||||
pms = "+CPMS: ((\"SM\",\"BM\",\"SR\"),(\"SM\"))\r\n"
|
pms = "AT+CPMS=?\r\r\n+CPMS: ((\"SM\",\"BM\",\"SR\"),(\"SM\"))\r\n\r\nOK\r\n"
|
||||||
|
|
||||||
result = Biju::ATTransform.new.apply(
|
result = Biju::ATTransform.new.apply(
|
||||||
Biju::ATParser.new.parse(pms))
|
Biju::ATParser.new.parse(pms))
|
||||||
|
@ -42,6 +43,27 @@ describe Biju::ATParser do
|
||||||
expect(result[:array]).to have(2).storage
|
expect(result[:array]).to have(2).storage
|
||||||
expect(result[:array][0]).to have(3).storage
|
expect(result[:array][0]).to have(3).storage
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets specified message storage infos" do
|
||||||
|
pms = "AT+CPMS=\"MT\"\r\r\n+CPMS: 23,23,7,100,7,100\r\n\r\nOK\r\n"
|
||||||
|
|
||||||
|
result = Biju::ATTransform.new.apply(
|
||||||
|
Biju::ATParser.new.parse(pms))
|
||||||
|
|
||||||
|
expect(result).to include(status: true)
|
||||||
|
expect(result[:array]).to have(6).storage
|
||||||
|
expect(result[:array]).to eq([23, 23, 7, 100, 7, 100])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "parses +CMGF? response" do
|
||||||
|
mgf = "AT+CMGF?\r\r\n+CMGF: 0\r\n\r\nOK\r\n"
|
||||||
|
|
||||||
|
result = Biju::ATTransform.new.apply(
|
||||||
|
Biju::ATParser.new.parse(mgf))
|
||||||
|
|
||||||
|
expect(result).to include(status: true)
|
||||||
|
expect(result[:result]).to be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises ParseFailed exception" do
|
it "raises ParseFailed exception" do
|
||||||
|
|
Loading…
Reference in New Issue