Add generic rule for responses in parser
parent
001cbacfca
commit
a0757a9c69
|
@ -17,7 +17,7 @@ module Biju
|
||||||
# RESPONSE
|
# RESPONSE
|
||||||
rule(:response) { ((command.maybe >> status) | merror) >> crlf | prompt }
|
rule(:response) { ((command.maybe >> status) | merror) >> crlf | prompt }
|
||||||
rule(:prompt) { str('> ').as(:prompt) }
|
rule(:prompt) { str('> ').as(:prompt) }
|
||||||
rule(:command) { mgl | num | pin | pms | mgf | mgs }
|
rule(:command) { mgl | num | pin | mgf | mgs | generic_response }
|
||||||
|
|
||||||
rule(:merror) do
|
rule(:merror) do
|
||||||
(str('+CME ERROR') | str('+CMS ERROR')).as(:cmd) >> str(': ') >>
|
(str('+CME ERROR') | str('+CMS ERROR')).as(:cmd) >> str(': ') >>
|
||||||
|
@ -32,10 +32,6 @@ module Biju
|
||||||
(str('+CNUM').as(:cmd) >> str(': ') >> array >> crlf)
|
(str('+CNUM').as(:cmd) >> str(': ') >> array >> crlf)
|
||||||
.repeat.as(:phone_numbers) >> crlf >> crlf
|
.repeat.as(:phone_numbers) >> crlf >> crlf
|
||||||
end
|
end
|
||||||
rule(:pms) do
|
|
||||||
str('+CPMS').as(:cmd) >> str(': ') >> str('(').maybe >> array >> str(')').maybe >>
|
|
||||||
crlf >> crlf
|
|
||||||
end
|
|
||||||
rule(:mgf) do
|
rule(:mgf) do
|
||||||
str('+CMGF').as(:cmd) >> str(': ') >> boolean.as(:result) >> crlf >> crlf
|
str('+CMGF').as(:cmd) >> str(': ') >> boolean.as(:result) >> crlf >> crlf
|
||||||
end
|
end
|
||||||
|
@ -45,6 +41,10 @@ module Biju
|
||||||
rule(:mgs) do
|
rule(:mgs) do
|
||||||
str('+CMGS').as(:cmd) >> str(': ') >> int.as(:result) >> crlf >> crlf
|
str('+CMGS').as(:cmd) >> str(': ') >> int.as(:result) >> crlf >> crlf
|
||||||
end
|
end
|
||||||
|
rule(:generic_response) do
|
||||||
|
match('[^:]').repeat.as(:cmd) >> str(': ') >> array >>
|
||||||
|
crlf >> crlf
|
||||||
|
end
|
||||||
|
|
||||||
rule(:array) do
|
rule(:array) do
|
||||||
(data >> (comma >> data).repeat).as(:array)
|
(data >> (comma >> data).repeat).as(:array)
|
||||||
|
|
|
@ -33,6 +33,20 @@ describe Biju::ATParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "response" do
|
context "response" do
|
||||||
|
it "parses generic response" do
|
||||||
|
resp = "AT+COPS\r\r\n+COPS: 1,\"two\",(3,4)\r\n\r\nOK\r\n"
|
||||||
|
|
||||||
|
result = Biju::ATTransform.new.apply(
|
||||||
|
Biju::ATParser.new.parse(resp))
|
||||||
|
|
||||||
|
expect(result[:cmd]).to eq('+COPS')
|
||||||
|
expect(result[:array]).to have(3).fields
|
||||||
|
|
||||||
|
expect(result[:array]).to include(1)
|
||||||
|
expect(result[:array]).to include('two')
|
||||||
|
expect(result[:array]).to include([3,4])
|
||||||
|
end
|
||||||
|
|
||||||
it "parses cmgs prompt" do
|
it "parses cmgs prompt" do
|
||||||
mgs = "AT+CMGS=18\r\r\n> "
|
mgs = "AT+CMGS=18\r\r\n> "
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue