public void EnqueueFrame(ATCommandFrame frame, Callback callback)
        {
            int frameID = UnusedFrameId;
            if (frameID == NOTFOUND)
            {
                waitingForSendingQueue.Enqueue(frame, callback);
                return;
            }

            if (callback != null)
            {
                frame.FrameID = (byte)frameID;
                waitingForResponseQueue.Enqueue(frame, callback);

                if (waitingForResponseQueue.Count > MaxWaitingForResponseNumber)
                {
                    Callback kickOutcallback = waitingForResponseQueue.CallbackForFrameAtIndex(0);
                    if (kickOutcallback != null)
                    {
                        kickOutcallback(null);
                    }
                    waitingForResponseQueue.RemoveAt(0);
                }
            }
            else
            {
                frame.FrameID = 0;
            }

            SendFrame(frame);
        }
 private void setATCommandRequestValues(byte[] bytes, ATCommandFrame frame)
 {
     byte[] commandName = Encoding.UTF8.GetBytes(frame.ATCommandName);
     bytes[5] = commandName[0];
     bytes[6] = commandName[1];
     if (frame.ATCommandData != null)
     {
         Array.Copy(frame.ATCommandData, 0, bytes, 7, frame.ATCommandData.Length);
     }
 }
        public void EnqueueFrame(ATCommandFrame frame, Callback callback)
        {
            int frameID = UnusedFrameId;
            if (frameID == NOTFOUND)
            {
                waitingForSendingQueue.Enqueue(frame, callback);
                return;
            }

            if (callback != null)
            {
                frame.FrameID = (byte)frameID;
                waitingForResponseQueue.Enqueue(frame, callback);
            }
            else
            {
                frame.FrameID = 0;
            }

            SendFrame(frame);
        }
Esempio n. 4
0
 public void EnqueueFrame(ATCommandFrame frame, Callback callback)
 {
     RequestResponseService.EnqueueFrame(frame, callback);
 }
        private bool isResponseForRequest(ATCommandFrame response, ATCommandFrame request)
        {
            if (request.ATCommandName != response.ATCommandName)
            {
                return false;
            }

            if (request is RemoteATCommandRequestFrame)
            {
                return (Frame.isEqualAddress((request as RemoteATCommandRequestFrame).DestinationAddress16Bit, new byte[] { 0xFF, 0xFE }) &&
                    Frame.isEqualAddress((request as RemoteATCommandRequestFrame).DestinationAddress64Bit, (response as RemoteATCommandResponseFrame).SourceAddress64Bit)) ||
                    Frame.isEqualAddress((request as RemoteATCommandRequestFrame).DestinationAddress16Bit, (response as RemoteATCommandResponseFrame).SourceAddress16Bit);
            }

            if (request is ATCommandRequestFrame)
            {
                return true;
            }

            return false;
        }
        public void ResponseReceived(ATCommandFrame response)
        {
            int index = waitingForResponseQueue.IndexOfFramePassingTest(delegate(Frame frame) {
                return (frame.FrameID == response.FrameID) && isResponseForRequest(response, (frame as ATCommandFrame));
            });

            if (index == NOTFOUND) { return; }

            Callback callback = waitingForResponseQueue.CallbackForFrameAtIndex(index);
            if (callback != null && callback(response))
            {
                waitingForResponseQueue.RemoveAt(index);
            }
        }