Exemple #1
0
        public Form1()
        {
            //
            // Windows 窗体设计器支持所必需的
            //
            InitializeComponent();

            //
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            //

            responseFrame          = new ControlFrame();
            responseFrame.sym      = new byte[] { (byte)'*', (byte)'*' };
            responseFrame.desAddr  = 1;
            responseFrame.srcAddr  = 0;
            responseFrame.response = Form1.RECEIVE_SUCCESS_TOKEN;
            responseFrame.seq      = Form1.FRAME_SEQUENCE_VALUE;
            responseFrame.computeCheckSum();

            handleComClass = new HandleComClass();
            handleComClass.Start(Form1.COM1_PORT_NUMBER, Form1.COM_BAUD_RATE, 1);
            handleComClass.DataArrived += new _IHandleComEvents_DataArrivedEventHandler(handleComClass_DataArrived);

            handleComData = new HandleComData(this.InsertMorningCheckData);
        }
        /// <summary>
        /// Parses HTTP headers of Http2 control frame.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="data">The data.</param>
        /// <param name="offset">Offset of HTTP headers in the data.</param>
        private void ParseControlFrameHeaders(ref ControlFrame frame, byte[] data, int offset)
        {
            var headers = new byte[data.Length - offset];

            Array.Copy(data, offset, headers, 0, headers.Length);
            if (headers.Length > 0)
            {
                ProcessorRun(ref headers, DirectionProcessType.Inbound, frame.Flags);
            }

            int headersOffset    = 0;
            int numberOfKeyValue = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(headers, headersOffset, 4));

            headersOffset += 4;

            for (int i = 0; i < numberOfKeyValue; ++i)
            {
                int nameLength = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(headers, headersOffset, 4));
                headersOffset += 4;
                string name = Encoding.UTF8.GetString(headers, headersOffset, nameLength);
                headersOffset += nameLength;

                int valLength = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(headers, headersOffset, 4));
                headersOffset += 4;
                string val = Encoding.UTF8.GetString(headers, headersOffset, valLength);
                headersOffset += valLength;
                // Ensure no duplicates.
                if (frame.Headers.ContainsKey(name))
                {
                    throw new ProtocolExeption(StatusCode.InternalError);
                }

                frame.Headers.Add(name, val);
            }
        }
Exemple #3
0
        /// <summary>
        /// ToDo: pass IRequest instead of IRouter + the Frame
        /// </summary>
        /// <param name="pConnection"></param>
        /// <param name="pFrame"></param>
        public void Process(IRouter pConnection, RoutingFrame pFrame)
        {
            //If a request is received start processing the request
            //If a response is received, let the request manager handle
            //setting the response
            ControlFrame objFame;

            try {
                objFame = new ControlFrame(pFrame.Data);
            } catch {
                Log.Error("Invalid data received, ignoring...");
                return;
            }

            try {
                if (objFame.FrameType == MessageType.Request)
                {
                    ActionManager.Process(pConnection, objFame);
                }
                else if (objFame.FrameType == MessageType.Response)
                {
                    RequestManager.Receive(pConnection, pFrame);
                }
            } catch (Exception ex) {
                Log.Error($"Unable to process control frame: {ex.Message}, ignoring...");
                return;
            }
        }
Exemple #4
0
        /// <summary>
        /// Deserializes the data into control frame.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>Deserialized frame.</returns>
        private BaseFrame DeserializeControlFrame(byte[] data)
        {
            var frame = new ControlFrame();

            ParseControlFrameHeader(ref frame, data);

            switch (frame.Type)
            {
            case FrameType.RTS:
                frame.StatusCode = (StatusCode)BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                break;

            case FrameType.Headers:
            case FrameType.SynReply:
                ParseControlFrameHeaders(ref frame, data, 12);
                break;

            case FrameType.SynStream:
                frame.Priority = (byte)(data[9] >> 5);
                ParseControlFrameHeaders(ref frame, data, 12);
                break;

            case FrameType.CreditUpdate:
                ((CreditUpdateFrame)frame).CreditAddition = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                break;
            }

            return(frame);
        }
Exemple #5
0
        /// <summary>
        /// Process SM control frame.
        /// </summary>
        /// <param name="frame">The control frame.</param>
        private void ProcessControlFrame(ControlFrame frame)
        {
            if (frame.Version != Version)
            {
                throw new SMProtocolExeption(StatusCode.UnsupportedVersion);
            }

            SMStream stream = this.streamsStore.GetStreamById(frame.StreamId);

            // if this is rst frame - don't send error or it will go in rst loop
            if (stream == null && frame.Type != FrameType.RTS)
            {
                this.SendRST(frame.StreamId, StatusCode.InvalidStream);
                return;
            }

            switch (frame.Type)
            {
            case FrameType.CreditUpdate:
            case FrameType.SynStream:
            case FrameType.SynReply:
                this.OnSessionFrame(this, new ControlFrameEventArgs(frame));
                break;

            case FrameType.Headers:
                this.OnStreamFrame(this, new HeadersEventArgs(this.streamsStore.GetStreamById(frame.StreamId), frame.Headers));
                break;

            case FrameType.RTS:
                this.OnStreamFrame(this, new RSTEventArgs(this.streamsStore.GetStreamById(frame.StreamId), frame.StatusCode));
                break;
            }
        }
        public void CreateWithParametersTest()
        {
            //Arrange
            byte[] arrID   = Encoding.ASCII.GetBytes("MyID");
            byte[] arrName = Encoding.UTF32.GetBytes("MyCustomName");
            byte[] arrData = new byte[] { 1, 2, 3, 4, 5 };

            var lstFrame = new List <byte>();

            lstFrame.Add((byte)MessageType.Response);
            lstFrame.Add((byte)arrID.Length);
            lstFrame.AddRange(arrID);
            lstFrame.Add((byte)arrName.Length);
            lstFrame.AddRange(arrName);
            lstFrame.AddRange(arrData);

            //Act
            var objFrame = new ControlFrame(MessageType.Response, "MyCustomName", "MyID", arrData);

            //Assert
            Assert.AreEqual(MessageType.Response, objFrame.FrameType);
            Assert.AreEqual("MyID", objFrame.RequestID);
            Assert.AreEqual("MyCustomName", objFrame.MessageName);
            Assert.IsTrue(objFrame.Data.SequenceEqual(arrData));
            Assert.IsTrue(objFrame.GetBytes().SequenceEqual(lstFrame.ToArray()));
        }
Exemple #7
0
        /// <summary>
        /// Process Protocol control frame.
        /// </summary>
        /// <param name="frame">The control frame.</param>
        private void ProcessControlFrame(ControlFrame frame)
        {
            if (frame.Version != Version)
            {
                throw new ProtocolExeption(StatusCode.UnsupportedVersion);
            }

            if (frame.Type == FrameType.GoAway)
            {
                GoAwayFrame goAway = (GoAwayFrame)frame;
                CloseInternal(goAway.Status, goAway.LastSeenGoodStreamId, false);
            }
            else
            {
                Http2Stream stream = this.streamsStore.GetStreamById(frame.StreamId);

                // if this is rst frame - don't send error or it will go in rst loop
                if (stream == null && frame.Type != FrameType.RTS && frame.Type != FrameType.Settings && frame.Type != FrameType.SynStream)
                {
                    this.SendRST(frame.StreamId, StatusCode.InvalidStream);
                    return;
                }

                switch (frame.Type)
                {
                case FrameType.SynStream:
                    //TODO validate syn_stream and send syn_reply or rst
                    this.OnSessionFrame(this, new ControlFrameEventArgs(frame));
                    break;

                case FrameType.SynReply:
                    this.OnSessionFrame(this, new ControlFrameEventArgs(frame));
                    break;

                case FrameType.Headers:
                    this.OnStreamFrame(this, new HeadersEventArgs(this.streamsStore.GetStreamById(frame.StreamId), frame.Headers));
                    break;

                case FrameType.RTS:
                    this.OnStreamFrame(this, new RSTEventArgs(this.streamsStore.GetStreamById(frame.StreamId), frame.StatusCode));
                    break;

                case FrameType.Ping:
                    this.OnSocketPing(this, new PingEventArgs(frame.StreamId));
                    break;

                case FrameType.Settings:
                    OnSessionFrame(this, new SettingsEventArgs(frame));
                    break;

                case FrameType.WindowUpdate:
                    Http2Stream http2Stream = this.streamsStore.GetStreamById(frame.StreamId);
                    http2Stream.UpdateWindowBalance(frame.DeltaWindowSize);
                    break;
                }
            }
        }
Exemple #8
0
        public IControlAction GetAction(IRouter pConnection, ControlFrame pFrame)
        {
            var objInfo = Actions.Where(a => a.RequestType.Name == pFrame.MessageName).FirstOrDefault();

            if (objInfo != null)
            {
                return((IControlAction)Activator.CreateInstance(objInfo.ActionType, pConnection, GetMessage(pFrame)));
            }
            return(null);
        }
        /// <summary>
        /// Parses HTTP header of Http2 control frame.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="data">The data.</param>
        private static void ParseControlFrameHeader(ref ControlFrame frame, byte[] data)
        {
            frame.Version = BinaryHelper.Int16FromBytes(data[0], data[1], 1);
            frame.Type    = (FrameType)BinaryHelper.Int16FromBytes(data[2], data[3]);

            frame.Flags = data[4]; //  it would be always 4 th byte for flags in spec.

            frame.Length  = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 5, 3));
            frame.IsFinal = (frame.Flags & 0x01) != 0;
        }
        private static int Serialize(ControlFrame frame, BinaryWriter writer)
        {
            writer.Write(frame.Start);
            writer.Write(frame.Length);
            writer.Write(frame.Length);
            writer.Write(frame.Start);
            writer.Write(frame.Crc);
            writer.Write(frame.Stop);

            return(6);
        }
Exemple #11
0
        /// <summary>
        /// Sends the frame.
        /// </summary>
        /// <param name="frame">The control frame.</param>
        private void SendFrame(ControlFrame frame)
        {
            byte[] frameBinary = this.serializer.Serialize(frame);
            frame.Length = frameBinary.Length;

            SendMessage(frameBinary);

            if (this.OnFrameSent != null)
            {
                this.OnFrameSent(this, new FrameEventArgs(frame));
            }
        }
        public void Dispose()
        {
            Jelly.Dispose();
            ControlFrame.Dispose();

            Jelly                = null;
            ControlFrame         = null;
            WireframeRenderer    = null;
            JellyRenderer        = null;
            ControlFrameRenderer = null;
            JellyController      = null;
        }
Exemple #13
0
        /// <summary>
        /// Parses HTTP header of SM control frame.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <param name="data">The data.</param>
        private static void ParseControlFrameHeader(ref ControlFrame frame, byte[] data)
        {
            frame.Version = BinaryHelper.Int16FromBytes(data[0], data[1], 1);
            frame.Type    = (FrameType)BinaryHelper.Int16FromBytes(data[2], data[3]);

            frame.StreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 4, 4), 0);

            frame.Flags = data[8];

            //	frame.Length = BinaryHelper.Int32FromBytes(new ArraySegment<byte>(data, 5, 3));
            frame.IsFinal = (frame.Flags & 0x01) != 0;
        }
Exemple #14
0
        /// <summary>
        /// Serializes the control frame.
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <returns>Serialized control frame.</returns>
        private byte[] SerializeControlFrame(ControlFrame frame)
        {
            var byteList = new List <byte>();

            byteList.Add((byte)(((frame.Version & 0xFF00) >> 8) | 0x80));
            byteList.Add((byte)(frame.Version & 0x00FF));

            byteList.Add((byte)(((Int16)frame.Type & 0xFF00) >> 8));
            byteList.Add((byte)((Int16)frame.Type & 0x00FF));

            byteList.AddRange(BinaryHelper.Int32ToBytes(frame.StreamId));

            var headersArray = new byte[0];

            switch (frame.Type)
            {
            case FrameType.SynStream:
                byteList.Add(Convert.ToByte(frame.Flags | (frame.IsFinal ? 0x01 : 0x00)));
                byteList.Add(Convert.ToByte(frame.Priority >> 5));
                byteList.Add(Unused);
                byteList.Add(Unused);
                headersArray = SerializeControlFrameHeaders(frame.Headers);
                break;

            case FrameType.RTS:
                byteList.AddRange(BinaryHelper.Int32ToBytes((int)frame.StatusCode));
                break;

            case FrameType.SynReply:
                byteList.Add(frame.Flags);
                byteList.Add(Unused);
                byteList.Add(Unused);
                byteList.Add(Unused);
                headersArray = SerializeControlFrameHeaders(frame.Headers);
                break;

            case FrameType.CreditUpdate:
                byteList.AddRange(BinaryHelper.Int64ToBytes(((CreditUpdateFrame)frame).CreditAddition));
                break;
            }

            if (headersArray.Length > 0)
            {
                ProcessorRun(ref headersArray, DirectionProcessType.Outbound, frame.Flags);
            }

            byteList.AddRange(headersArray);
            return(byteList.ToArray());
        }
Exemple #15
0
        public ControlMessage GetMessage(ControlFrame pFrame)
        {
            ControlMessage objMessage = null;

            if (pFrame.FrameType == MessageType.Request)
            {
                if (Requests.ContainsKey(pFrame.MessageName))
                {
                    objMessage = (ControlMessage)Activator.CreateInstance(Requests[pFrame.MessageName], pFrame);
                }
            }
            else
            {
                if (Responses.ContainsKey(pFrame.MessageName))
                {
                    objMessage = (ControlMessage)Activator.CreateInstance(Responses[pFrame.MessageName], pFrame);
                }
            }
            return(objMessage);
        }
Exemple #16
0
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器
        /// 修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.timerTimeSynch     = new System.Timers.Timer();
            this.timer_ReceiveReply = new System.Timers.Timer();
            ((System.ComponentModel.ISupportInitialize)(this.timerTimeSynch)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.timer_ReceiveReply)).BeginInit();
            //
            // timerTimeSynch
            //
            timerTimeSynch.Interval      = CPTT.SystemFramework.Util.TIMESYNCH_TIMER_INTERVAL;       //设置时间同步timer
            this.timerTimeSynch.Elapsed += new System.Timers.ElapsedEventHandler(this.timerTimeSynch_Elapsed);
            //
            // timer_ReceiveReply
            //
            this.timer_ReceiveReply.Enabled  = false;
            this.timer_ReceiveReply.Interval = 40000;
            this.timer_ReceiveReply.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReceiveReply_Elapsed);
            //
            // AutoService
            //
            this.CanPauseAndContinue = true;
            this.CanShutdown         = true;
            this.ServiceName         = "CPTT4.0AutoService";
            ((System.ComponentModel.ISupportInitialize)(this.timerTimeSynch)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.timer_ReceiveReply)).EndInit();

            handleComClass = new HandleComClass();
            handleComClass.Start(CPTT.SystemFramework.Util.COM1_PORT_NUMBER, CPTT.SystemFramework.Util.COM_BAUD_RATE, 1);
            handleComClass.DataArrived += new _IHandleComEvents_DataArrivedEventHandler(handleComClass_DataArrived);

            machineSystem = new MachineSystem();

            responseFrame = new ControlFrame();

            responseFrame.sym      = new byte[] { (byte)'*', (byte)'*' };
            responseFrame.srcAddr  = 0;
            responseFrame.response = CPTT.SystemFramework.Util.RECEIVE_SUCCESS_TOKEN;
            responseFrame.seq      = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE;

            handleComData = new HandleComData(this.InsertMorningCheckData);
        }
Exemple #17
0
        public void Process(IRouter pConnection, ControlFrame pFrame)
        {
            var obj = ControlFactory.Provider.GetAction(pConnection, pFrame);

            if (obj == null)
            {
                Log.Error($"Failed to create message {pFrame.MessageName}");
                return;
            }
            if (!Actions.TryAdd(pFrame.RequestID, obj))
            {
                Log.Error($"Failed adding {pFrame.MessageName}({pFrame.RequestID}) action to collection, ignoring action");
            }
            else
            {
                try {
                    var objResponse = (IControlResponse)obj.GetType().GetMethod("Start").Invoke(obj, new object[0]);
                    Log.Debug($"Response gotten for RequestID {pFrame.RequestID}");
                    ControlFrame objControlFrame = objResponse.GetFrame();
                    if (objResponse != null)
                    {
                        pConnection.Transmit(
                            new RoutingFrame(
                                RoutingFrameType.Control,
                                MessageType.Response,
                                pFrame.RequestID,
                                pConnection.ConnectionID,
                                "",
                                objResponse.GetFrame().GetBytes()
                                ).GetBytes()
                            );
                    }
                } catch (Exception ex) {
                    Log.Error(ex);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsEventArgs"/> class.
 /// </summary>
 /// <param name="stream">The settings name/value pairs.</param>
 public SettingsEventArgs(ControlFrame settingsFrame)
     : base(settingsFrame)
 {
     this.SettingsHeaders = settingsFrame.SettingsHeaders;
 }
 public CanStartActionResponse(ControlFrame pFrame) : base(pFrame.RequestID)
 {
     CanStart = (pFrame.Data[0] == 1);
 }
        /// <summary>
        /// Builds the control frame.
        /// </summary>
        /// <param name="type">The frame type.</param>
        /// <param name="streamId">The SM stream id.</param>
        /// <param name="headers">The headers.</param>
        /// <returns>Returns Control frame object.</returns>
        private static ControlFrame BuildControlFrame(FrameType type, int streamId, SMHeaders headers)
        {
            ControlFrame frame = new ControlFrame(headers);
            frame.StreamId = streamId;
            frame.Type = type;
            frame.Priority = ControlPriority;

            return frame;
        }
        /// <summary>
        /// Builds the RST Frame.
        /// </summary>
        /// <param name="streamId">The stream id.</param>
        /// <param name="reason">The reason for RST.</param>
        /// <returns>RST frame.</returns>
        public ControlFrame BuildRSTFrame(int streamId, StatusCode reason)
        {
            ControlFrame frame = new ControlFrame();
            frame.StreamId = streamId;
            frame.Type = FrameType.RTS;
            frame.StatusCode = reason;
            frame.Priority = RSTPriority;

            return frame;
        }
Exemple #22
0
 //------ status frame period changes ----------//
 public ErrorCode SetControlFramePeriod(ControlFrame frame, int periodMs)
 {
     return(_ll.SetControlFramePeriod(frame, periodMs));
 }
Exemple #23
0
 public static ControlFrameEnhanced Promote(ControlFrame controlFrame)
 {
     return((ControlFrameEnhanced)controlFrame);
 }
        public INetworkPacket Deserialize(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            INetworkPacket packet = null;

            var start1 = reader.ReadByte();

            switch (start1)
            {
            case Constants.MBUS_FRAME_ACK_START:
            {
                packet = new AckFrame();
            }
            break;

            case Constants.MBUS_FRAME_SHORT_START:
            {
                //if (stream.Length != 5)
                //    return false;

                if (start1 != Constants.MBUS_FRAME_SHORT_START)
                {
                    return(packet);
                }

                var control = reader.ReadByte();
                var address = reader.ReadByte();
                var crc     = reader.ReadByte();

                if (crc != new byte[] { control, address }.CheckSum())
                {
                    return(packet);
                }

                var stop = reader.ReadByte();

                if (stop != Constants.MBUS_FRAME_STOP)
                {
                    return(packet);
                }

                packet = new ShortFrame(control, address);
            }
            break;

            case Constants.MBUS_FRAME_LONG_START:
            {
                const int MBUS_FRAME_FIXED_SIZE_LONG = 6;

                var length1 = reader.ReadByte();
                var length2 = reader.ReadByte();

                if (length1 < 3)
                {
                    return(packet);
                }

                if (length1 != length2)
                {
                    return(packet);
                }

                //if (stream.Length < length1 + MBUS_FRAME_FIXED_SIZE_LONG)
                //    return false;

                var start2 = reader.ReadByte();

                if (start2 != Constants.MBUS_FRAME_LONG_START)
                {
                    return(packet);
                }

                var control            = reader.ReadByte();
                var address            = reader.ReadByte();
                var controlInformation = reader.ReadByte();

                var data = reader.ReadBytes(length1 - 3);

                if (data.Length != length1 - 3)
                {
                    return(packet);
                }

                var crc  = reader.ReadByte();
                var stop = reader.ReadByte();

                if (crc != new byte[] { control, address, controlInformation }.Merge(data).CheckSum())
                {
                    return(packet);
                }

                if (length1 - 3 == 0)
                {
                    packet = new ControlFrame(control, controlInformation, address);
                }
                else if ((ControlInformation)controlInformation == ControlInformation.RESP_VARIABLE)
                {
                    packet = new VariableDataLongFrame(control, controlInformation, address, data, length1);
                }
                else if ((ControlInformation)controlInformation == ControlInformation.RESP_FIXED)
                {
                    packet = new FixedDataLongFrame(control, controlInformation, address, data, length1);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            break;
            }

            return(packet);
        }
Exemple #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WindowUpdateEventArgs" /> class.
 /// </summary>
 /// <param name="deltaWindowSize">Size of the delta window.</param>
 public WindowUpdateEventArgs(ControlFrame frame)
     : base(frame)
 {
     this.DeltaWindowSize = frame.DeltaWindowSize;
 }
Exemple #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControlFrameEventArgs"/> class.
 /// </summary>
 /// <param name="frame">The frame.</param>
 public ControlFrameEventArgs(ControlFrame frame)
 {
     this.Frame = frame;
 }
Exemple #27
0
 public GetMessageStatusRequest(ControlFrame pFrame)
 {
     ID        = pFrame.RequestID;
     RequestID = Encoding.ASCII.GetString(pFrame.Data);
 }
Exemple #28
0
        //问询指令
        private void SendQuery()
        {
            while (true)
            {
                if (!comPortIsBusy)
                {
                    if (machineAddrList != null)
                    {
                        if (machineAddrList.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow machineAddr in machineAddrList.Tables[0].Rows)
                            {
                                ControlFrame controlFrame = new ControlFrame();
                                controlFrame.sym      = new byte[] { (byte)'*', (byte)'*' };
                                controlFrame.desAddr  = Convert.ToByte(machineAddr["machine_address"]);
                                controlFrame.srcAddr  = 0;
                                controlFrame.response = CPTT.SystemFramework.Util.QUERY_TOKEN;
                                controlFrame.seq      = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE;
                                controlFrame.computeCheckSum();

                                Monitor.Enter(handleComClass);
                                handleComClass.WriteSerialCmd(CPTT.SystemFramework.Util.CONTROL_FRAME_LENGTH, controlFrame.convertToBytes());                               //发送问询帧
                                Monitor.Exit(handleComClass);

//								Thread.Sleep(3000);
                                Thread.Sleep(CPTT.SystemFramework.Util.QUERY_TIMER_INTERVAL);
                            }

                            if (_lastSyncDate.AddMinutes(10) <= DateTime.Now)
                            {
                                foreach (DataRow machineAddr in machineAddrList.Tables[0].Rows)
                                {
                                    SynchDate(machineAddr["machine_address"]);
                                }

                                _lastSyncDate = DateTime.Now;
                            }
                        }
                        else
                        {
                            Thread.Sleep(CPTT.SystemFramework.Util.QUERY_NULL_INTERVAL);
                        }
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }

//					if ( _alAuthenticatedHardWare.Count > 0 )
//					{
//						foreach(object o in _alAuthenticatedHardWare)
//						{
//							ControlFrame controlFrame = new ControlFrame();
//							controlFrame.sym = new byte[]{(byte)'*',(byte)'*'};
//							controlFrame.desAddr = Convert.ToByte(o.ToString());
//							controlFrame.srcAddr = 0;
//							controlFrame.response = CPTT.SystemFramework.Util.QUERY_TOKEN;
//							controlFrame.seq = CPTT.SystemFramework.Util.FRAME_SEQUENCE_VALUE;
//							controlFrame.computeCheckSum();
//
//							Monitor.Enter(handleComClass);
//							handleComClass.WriteSerialCmd(CPTT.SystemFramework.Util.CONTROL_FRAME_LENGTH,controlFrame.convertToBytes());//发送问询帧
//							Monitor.Exit(handleComClass);
//
//							Thread.Sleep(CPTT.SystemFramework.Util.QUERY_TIMER_INTERVAL);
//						}
//					}
//					else Thread.Sleep(CPTT.SystemFramework.Util.QUERY_NULL_INTERVAL);
                }
            }
        }
        /// <summary>
        /// Deserializes the data into control frame.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>Deserialized frame.</returns>
        private BaseFrame DeserializeControlFrame(byte[] data)
        {
            FrameType    type  = GetFrameType(data);
            ControlFrame frame = new ControlFrame();

            switch (type)
            {
            case FrameType.RTS:
                frame.StreamId   = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame.StatusCode = (StatusCode)BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                break;

            case FrameType.Headers:
            case FrameType.SynReply:
                ParseControlFrameHeader(ref frame, data);

                frame.StreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));

                ParseControlFrameHeaders(ref frame, data, 12);
                break;

            case FrameType.SynStream:
                ParseControlFrameHeader(ref frame, data);

                frame.StreamId             = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame.AssociatedToStreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                frame.Priority             = (byte)(data[16] >> 5);
                frame.Slot = data[17];

                ParseControlFrameHeaders(ref frame, data, 18);
                break;

            case FrameType.Settings:
                int numberOfEntries = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame = new SettingsFrame(numberOfEntries);
                int headersOffset = 12;

                for (int i = 0; i < numberOfEntries; i++)
                {
                    int key = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, headersOffset, 4));
                    headersOffset += 4;
                    int value = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, headersOffset, 4));
                    headersOffset += 4;

                    frame.SettingsHeaders.Add(key, value);
                }

                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.GoAway:
                int        lastSeenGoodStreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                StatusCode status = StatusCode.Success;

                if (data.Length > 12)
                {
                    status = (StatusCode)BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                }

                frame = new GoAwayFrame(lastSeenGoodStreamId, status);
                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.Ping:
                int streamID = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 4, 4));
                frame = new ControlFrame {
                    StreamId = streamID
                };

                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.WindowUpdate:
                int streamId        = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 4, 4));
                int deltaWindowSize = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame = new WindowUpdateFrame(streamId, deltaWindowSize);

                ParseControlFrameHeader(ref frame, data);
                break;
            }
            frame.Type = type;

            return(frame);
        }
 public GetMessageStatusResponse(ControlFrame pFrame) : base(pFrame.RequestID)
 {
     IsAlive = (pFrame.Data[0] == 1);
 }
Exemple #31
0
 public PongResponse(ControlFrame pFrame) : base(pFrame.RequestID)
 {
 }
Exemple #32
0
 public CanStartActionRequest(ControlFrame pFrame)
 {
     ID        = pFrame.RequestID;
     RequestID = Encoding.ASCII.GetString(pFrame.Data);
 }