diff --git a/lib/biju/parser.rb b/lib/biju/parser.rb index 7c9b57e..4d46530 100644 --- a/lib/biju/parser.rb +++ b/lib/biju/parser.rb @@ -17,7 +17,7 @@ module Biju # RESPONSE rule(:response) { ((command.maybe >> status) | merror) >> crlf | 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 (str('+CME ERROR') | str('+CMS ERROR')).as(:cmd) >> str(': ') >> @@ -32,10 +32,6 @@ module Biju (str('+CNUM').as(:cmd) >> str(': ') >> array >> crlf) .repeat.as(:phone_numbers) >> crlf >> crlf end - rule(:pms) do - str('+CPMS').as(:cmd) >> str(': ') >> str('(').maybe >> array >> str(')').maybe >> - crlf >> crlf - end rule(:mgf) do str('+CMGF').as(:cmd) >> str(': ') >> boolean.as(:result) >> crlf >> crlf end @@ -45,6 +41,10 @@ module Biju rule(:mgs) do str('+CMGS').as(:cmd) >> str(': ') >> int.as(:result) >> crlf >> crlf end + rule(:generic_response) do + match('[^:]').repeat.as(:cmd) >> str(': ') >> array >> + crlf >> crlf + end rule(:array) do (data >> (comma >> data).repeat).as(:array) diff --git a/spec/biju/parser_spec.rb b/spec/biju/parser_spec.rb index 4f7b4ea..86f7c77 100644 --- a/spec/biju/parser_spec.rb +++ b/spec/biju/parser_spec.rb @@ -33,6 +33,20 @@ describe Biju::ATParser do end 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 mgs = "AT+CMGS=18\r\r\n> "