예제 #1
0
 public void ParsedResultCode(Parser p, ResultCodeToken r)
 {
     _lastResultCode = r;
     if (r.Connect)
     {
         Connection = new DefaultConnection(this);
         if (_callState == CallState.DialPending && WaitingOutgoingCall != null)
         {
             WaitingOutgoingCall.Connect(this, Connection);
         }
         else if (_callState == CallState.AnswerPending && this.IncommingCallHandler != null)
         {
             this.IncommingCallHandler.Connect(this, Connection);
         }
         Monitor.PulseAll(this);
         _callState = CallState.callEstablished;
     }
     else
     {
         if (_callState == CallState.DialPending && WaitingOutgoingCall != null)
         {
             WaitingOutgoingCall.ParsedResultCode(this, r);
         }
         else if (_callState == CallState.AnswerPending && this.IncommingCallHandler != null)
         {
             this.IncommingCallHandler.ParsedResultCode(this, r);
         }
         Monitor.PulseAll(this);
         _callState      = CallState.Idle;
         this.Connection = null;
     }
 }
예제 #2
0
        protected internal virtual bool WaitForOK(int waitTime)
        {
            long            t = DateTimeHelperClass.CurrentUnixTimeMillis();
            ResultCodeToken e = WaitForResult(waitTime);

            if (e == null || !e.Ok)
            {
                log.InfoFormat("Timeout waiting ({0} ms) for OK resCode=\"{1}\"", new object[] { DateTimeHelperClass.CurrentUnixTimeMillis() - t, e != null ? e.ResultCode : "e == null" });
            }
            else
            {
                log.InfoFormat("Waited {0} ms for OK result: {1} ", new object[] { DateTimeHelperClass.CurrentUnixTimeMillis() - t, e.ResultCode, e.ResultCode });
                return(e.Ok);
            }
            return((e == null) ? false : e.Ok);
        }
예제 #3
0
        private ResultCodeToken WaitForResult(int waitTime)
        {
            long t = DateTimeHelperClass.CurrentUnixTimeMillis();

            if (this._lastResultCode == null)
            {
                Monitor.Wait(this, TimeSpan.FromMilliseconds(waitTime));
            }
            ResultCodeToken result = _lastResultCode;

            _lastResultCode = null;
            if (result == null)
            {
                log.InfoFormat("{0} ms waited > NO RESULT: \"{1}\"", new object[] { DateTimeHelperClass.CurrentUnixTimeMillis() - t, Parser.GetBuffer() });
            }
            return(result);
        }
예제 #4
0
 public List <string> SendAndExtractData(string cmdLine, int trys, int waitTime)
 {
     for (int i = 0; i < trys; i++)
     {
         ResetParser();
         SendCommandLine(cmdLine);
         ResultCodeToken e = WaitForResult(waitTime);
         if (e == null || !e.Ok)
         {
         }
         else
         {
             return(e.Data);
         }
     }
     throw new Exception("Error during " + cmdLine);
 }
예제 #5
0
 public IConnection Dial(string number)
 {
     if (_callState != CallState.Idle)
     {
         throw new Exception("Line busy: " + _callState);
     }
     _callState = CallState.DialPending;
     for (int i = 0; i < _defaultTrys; i++)
     {
         if (_callState != CallState.DialPending)
         {
             break;
         }
         ResetParser();
         string commandline = "ATD " + number;
         SendCommandLine(commandline);
         Thread.Sleep(_defaultWaitTime);
         string buffer = Parser.GetBuffer();
         //if (buffer == null || !buffer.Contains(commandline)) // !buffer.Contains(commandline + Parser.CR))
         //{
         //    log.InfoFormat("Retransmitt CMD! \"{0}\"", buffer);
         //    SendCommandLine(commandline);
         //}
         ResultCodeToken e = WaitForResult(_defaultDialWaitTime); // 30 s
         if (e == null)
         {
         }
         else if (Parser.IsOnlineDataMode())
         {
             System.Diagnostics.Debug.WriteLine(string.Format("Caller: connected {0}", DateTime.Now));
             _callState = CallState.callEstablished;
             return(this.Connection);
         }
     }
     throw new Exception("NOT Connected");
 }
예제 #6
0
 private void ResetParser()
 {
     Parser.ResetParser();
     _lastEcho       = null;
     _lastResultCode = null;
 }