Beispiel #1
0
 public ATFrame(string command, ATCommandType commandType, Stream dataStream, string inParameters)
 {
     this.command = command;
     this.commandType = commandType;
     this.dataStream = dataStream;
     this.inParameters = inParameters;
 }
Beispiel #2
0
 public ATFrame(string command, ATCommandType commandType, Stream dataStream, string inParameters)
 {
     this.command      = command;
     this.commandType  = commandType;
     this.dataStream   = dataStream;
     this.inParameters = inParameters;
 }
Beispiel #3
0
 public ATFrame(string command, ATCommandType commandType, Stream dataStream, bool unsolicited, string result, string outParameters)
 {
     this.command       = command;
     this.commandType   = commandType;
     this.dataStream    = dataStream;
     this.unsolicited   = unsolicited;
     this.result        = result;
     this.outParameters = outParameters;
 }
Beispiel #4
0
 public ATFrame(string command, ATCommandType commandType, Stream dataStream, bool unsolicited, string result, string outParameters)
 {
     this.command = command;
     this.commandType = commandType;
     this.dataStream = dataStream;
     this.unsolicited = unsolicited;
     this.result = result;
     this.outParameters = outParameters;
 }
Beispiel #5
0
        public override ATParserResult ParseResponse(string command, ATCommandType commandType, byte[] buffer, int index, int count)
        {
            ATFrameParser frameParser = (ATFrameParser)this.frameParsers[
                this.GetFrameParserKey(command, commandType)];

            if (frameParser == null)
                return null;

            return frameParser.Parse(buffer, index, count);
        }
Beispiel #6
0
 protected void AddRegexFrameParser(string command, ATCommandType commandType, Regex regex, int regexParametersGroup, int regexResultGroup)
 {
     this.AddFrameParser(new RegexATFrameParser()
     {
         Command              = command,
         CommandType          = commandType,
         Regex                = regex,
         RegexParametersGroup = regexParametersGroup,
         RegexResultGroup     = regexResultGroup
     });
 }
Beispiel #7
0
 protected void AddRegexFrameParser(string command, ATCommandType commandType, Regex regex, int regexParametersGroup, int regexResultGroup)
 {
     this.AddFrameParser(new RegexATFrameParser()
     {
         Command = command,
         CommandType = commandType,
         Regex = regex,
         RegexParametersGroup = regexParametersGroup,
         RegexResultGroup = regexResultGroup
     });
 }
Beispiel #8
0
        public static ATFrame GetInstance(string command, ATCommandType commandType, Stream dataStream, string inParameters)
        {
            ATFrame instance = requestInstance;

            instance.command     = command;
            instance.commandType = commandType;
            instance.dataStream  = dataStream;

            instance.inParameters = inParameters;

            return(instance);
        }
Beispiel #9
0
        public override ATParserResult ParseResponse(string command, ATCommandType commandType, byte[] buffer, int index, int count)
        {
            ATFrameParser frameParser = (ATFrameParser)this.frameParsers[
                this.GetFrameParserKey(command, commandType)];


            if (frameParser == null)
            {
                return(null);
            }

            return(frameParser.Parse(buffer, index, count));
        }
Beispiel #10
0
        public static ATFrame GetInstance(string command, ATCommandType commandType, Stream dataStream, bool unsolicited, string result, string outParameters)
        {
            ATFrame instance = unsolicited ? unsolicitedResponseInstance : responseInstance;

            instance.command     = command;
            instance.commandType = commandType;
            instance.dataStream  = dataStream;

            instance.unsolicited   = unsolicited;
            instance.result        = result;
            instance.outParameters = outParameters;

            return(instance);
        }
Beispiel #11
0
        public IAsyncResult BeginProcess(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback, Object state)
        {
            lock (this.syncRoot)
            {
                lock (this.waitingLock)
                {
                    this.waitingEcho        = this.echoEnabled;
                    this.waitingResponse    = waitResponse;
                    this.waitingTimeout     = Environment.TickCount + timeout;
                    this.waitingCommand     = frame.Command;
                    this.waitingCommandType = frame.CommandType;

                    this.waitingCallback               = callback;
                    this.waitingAsyncResult            = WaitingAsyncResult.GetInstance();
                    this.waitingAsyncResult.AsyncState = state;
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

#if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
#endif


                    return(this.waitingAsyncResult);
                }
                catch
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho     = false;
                        this.waitingResponse = false;
                    }

                    throw new ATModemException(ATModemError.Generic);
                }
            }
        }
Beispiel #12
0
        public ATFrame Process(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback)
        {
            lock (this.syncRoot)
            {
                if (waitResponse)
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho = this.echoEnabled;
                        this.waitingResponse = true;
                        this.waitingTimeout = Environment.TickCount + timeout;
                        this.waitingCommand = frame.Command;
                        this.waitingCommandType = frame.CommandType;

                        this.waitingCallback = null;

                        this.waitingEchoEvent.Reset();
                        this.waitingResponseEvent.Reset();
                    }
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

            #if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
            #endif

                    if (this.waitingEcho && !this.waitingEchoEvent.WaitOne(defaultEchoTimeout, true))
                        throw new ATModemException(ATModemError.Timeout);

                    if (!waitResponse)
                        return null;

                    if (this.waitingResponseEvent.WaitOne(timeout, true))
                    {
                        return this.waitingFrame;
                    }

                    throw new ATModemException(ATModemError.Timeout);
                }
                finally
                {
                    if (waitResponse)
                    {
                        lock (this.waitingLock)
                        {
                            this.waitingEcho = false;
                            this.waitingResponse = false;
                        }
                    }
                }
            }
        }
Beispiel #13
0
 public ATFrame CreateRequestFrame(string command, ATCommandType commandType, string inParameters)
 {
     return ATFrame.GetInstance(command, commandType, ATRequestDataStream.GetInstance(this), inParameters);
 }
Beispiel #14
0
        public IAsyncResult BeginProcess(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback, Object state)
        {
            lock (this.syncRoot)
            {
                lock (this.waitingLock)
                {
                    this.waitingEcho = this.echoEnabled;
                    this.waitingResponse = waitResponse;
                    this.waitingTimeout = Environment.TickCount + timeout;
                    this.waitingCommand = frame.Command;
                    this.waitingCommandType = frame.CommandType;

                    this.waitingCallback = callback;
                    this.waitingAsyncResult = WaitingAsyncResult.GetInstance();
                    this.waitingAsyncResult.AsyncState = state;
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

            #if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
            #endif

                    return this.waitingAsyncResult;
                }
                catch
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho = false;
                        this.waitingResponse = false;
                    }

                    throw new ATModemException(ATModemError.Generic);
                }
            }
        }
Beispiel #15
0
 private string GetFrameParserKey(string command, ATCommandType commandType)
 {
     return(String.Concat(commandType, "+", command));
 }
Beispiel #16
0
        public static ATFrame GetInstance(string command, ATCommandType commandType, Stream dataStream, bool unsolicited, string result, string outParameters)
        {
            ATFrame instance = unsolicited ? unsolicitedResponseInstance : responseInstance;

            instance.command = command;
            instance.commandType = commandType;
            instance.dataStream = dataStream;

            instance.unsolicited = unsolicited;
            instance.result = result;
            instance.outParameters = outParameters;

            return instance;
        }
Beispiel #17
0
        public static ATFrame GetInstance(string command, ATCommandType commandType, Stream dataStream, string inParameters)
        {
            ATFrame instance = requestInstance;

            instance.command = command;
            instance.commandType = commandType;
            instance.dataStream = dataStream;

            instance.inParameters = inParameters;

            return instance;
        }
Beispiel #18
0
        private void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                string line = "";
                while ((line = serial.ReadLine()) != null)
                {
                    ATCommandType cmdType = GetCmdType(line);
                    switch (cmdType)
                    {
                    case ATCommandType.ReceivedMessage:
                        string   meta  = line;
                        string   data  = serial.ReadLine();
                        string[] items = meta.Remove(0, 6).Replace("\"", "").Split(',');
                        string   num   = FormatNumber(items[0]);
                        string   time  = items[2] + "," + items[3];
                        NotifyNewMessage(num, data, time);
                        break;

                    case ATCommandType.CallingLineIdentification:
                        if (!gotIncomingNum)
                        {
                            Invoke(new Action(() =>
                            {
                                newCallNumber.Text = "Incoming call: " + line.Split('"')[1];
                                Util.Animate(callNotification, Util.Effect.Slide, 150, 90);
                            }));
                            gotIncomingNum = true;
                        }
                        break;

                    case ATCommandType.ConnectedLineIdentification:
                        Invoke(new Action(() =>
                        {
                            newCallNumber.Text = numberToReply;
                        }));
                        break;

                    case ATCommandType.CallEnd:
                        Invoke(new Action(() =>
                        {
                            Util.Animate(callNotification, Util.Effect.Slide, 150, 90);
                        }));
                        gotIncomingNum = false;
                        break;

                    case ATCommandType.OK:
                        if (answeredCall)
                        {
                            answeredCall = false;
                        }
                        break;

                    case ATCommandType.SubscriberNumber:
                        string[] newdata = line.Split('"');
                        myNum = FormatNumber(newdata[3]);
                        Console.WriteLine(myNum);
                        gotOwnNumber = true;
                        break;
                    }
                }
            }
            catch (System.IO.IOException io)
            {
                Console.WriteLine("Error: " + io.Message);
            }
        }
Beispiel #19
0
 public abstract ATParserResult ParseResponse(string command, ATCommandType commandType, byte[] buffer, int index, int count);
Beispiel #20
0
 public ATFrame CreateRequestFrame(string command, ATCommandType commandType, string inParameters)
 {
     return(ATFrame.GetInstance(command, commandType, ATRequestDataStream.GetInstance(this), inParameters));
 }
Beispiel #21
0
 private string GetFrameParserKey(string command, ATCommandType commandType)
 {
     return String.Concat(commandType, "+", command);
 }
Beispiel #22
0
        public ATFrame Process(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback)
        {
            lock (this.syncRoot)
            {
                if (waitResponse)
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho        = this.echoEnabled;
                        this.waitingResponse    = true;
                        this.waitingTimeout     = Environment.TickCount + timeout;
                        this.waitingCommand     = frame.Command;
                        this.waitingCommandType = frame.CommandType;

                        this.waitingCallback = null;

                        this.waitingEchoEvent.Reset();
                        this.waitingResponseEvent.Reset();
                    }
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

#if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
#endif


                    if (this.waitingEcho && !this.waitingEchoEvent.WaitOne(defaultEchoTimeout, true))
                    {
                        throw new ATModemException(ATModemError.Timeout);
                    }


                    if (!waitResponse)
                    {
                        return(null);
                    }

                    if (this.waitingResponseEvent.WaitOne(timeout, true))
                    {
                        return(this.waitingFrame);
                    }

                    throw new ATModemException(ATModemError.Timeout);
                }
                finally
                {
                    if (waitResponse)
                    {
                        lock (this.waitingLock)
                        {
                            this.waitingEcho     = false;
                            this.waitingResponse = false;
                        }
                    }
                }
            }
        }
Beispiel #23
0
 public abstract ATParserResult ParseResponse(string command, ATCommandType commandType, byte[] buffer, int index, int count);