Exemplo n.º 1
0
 public virtual void ResetParser()
 {
     ClearBuffer();
     _parserState = eParserState.COLLECT_ALL;
     _parsedData  = new List <string>();
     _parsedEcho  = null;
 }
Exemplo n.º 2
0
        public void ParseChar(char c)
        {
            _sb.Append(c);

            var data = _sb.ToString();

            if (data.EndsWith(TokenRing))
            {
                MatchedRing();
            }
            switch (_parserState)
            {
            case eParserState.COLLECT_ALL:
                if (data.EndsWith(TokenOk))
                {
                    MatchedOk();
                }
                else if (data.EndsWith(TokenBusy))
                {
                    MatchedBusy();
                }
                else if (data.EndsWith(TokenConnect))
                {
                    MatchedConnect();
                }
                else if (data.EndsWith(TokenError))
                {
                    MatchedError();
                }
                else if (data.EndsWith(TokenNoAnswer))
                {
                    MatchedNoAnswer();
                }
                else if (data.EndsWith(TokenNoCarrier))
                {
                    MatchedNoCarrier();
                }
                else if (data.EndsWith(TokenNoDialtone))
                {
                    MatchedNoDialtone();
                }
                else if (data.EndsWith(TokenCrLf))
                {
                    if (FindLastToken(TokenConnectWithText) >= 0)
                    {
                        MatchedConnectWithText();
                    }
                }
                else if (data.EndsWith(TokenAT))
                {
                    _parserState = eParserState.COLLECT_CMD_ECHO;
                    if (_sb.Length > TokenAT.Length)
                    {
                        MatchedGarbage(_sb.Length - TokenAT.Length);
                    }
                    break;
                }
                //else
                //{
                //    if (this.Modem.Connection != null)
                //    {
                //        this.Modem.Connection.ReceiveData(_sb.ToString());
                //        ClearBuffer();
                //    }
                //}
                break;

            case eParserState.COLLECT_CMD_ECHO:
                if (data.EndsWith(TokenCrCrLf))
                {
                    _parsedEcho  = _sb.ToString().Substring(0, _sb.Length - TokenCrCrLf.Length);
                    _parsedData  = new List <string>();
                    _parserState = eParserState.COLLECT_DATA_OR_RESPONSE;
                    ClearBuffer();
                }
                break;

            case eParserState.COLLECT_DATA_OR_RESPONSE:
                if (_parsedData.Count == 0 && data.EndsWith(TokenPrompt))
                {
                    MatchedPrompt();
                }
                else if (data.EndsWith(TokenOk))
                {
                    MatchedOk();
                }
                else if (data.EndsWith(TokenBusy))
                {
                    MatchedBusy();
                }
                else if (data.EndsWith(TokenConnect))
                {
                    MatchedConnect();
                }
                else if (data.EndsWith(TokenError))
                {
                    MatchedError();
                }
                else if (data.EndsWith(TokenNoAnswer))
                {
                    MatchedNoAnswer();
                }
                else if (data.EndsWith(TokenNoCarrier))
                {
                    MatchedNoCarrier();
                }
                else if (data.EndsWith(TokenNoDialtone))
                {
                    MatchedNoDialtone();
                }
                else if (data.EndsWith(TokenCrLf))
                {
                    if (FindLastToken(TokenConnectWithText) >= 0)
                    {
                        MatchedConnectWithText();
                    }
                    else
                    {
                        _parsedData.Add(_sb.ToString().Substring(0, _sb.Length - TokenCrLf.Length));
                        ClearBuffer();
                    }
                }
                break;

            default:
                throw new Exception("UNKNOWN PARSER STATE");
            }
        }