示例#1
0
        public List <SlowPacket> LoadSlowBinaryFile(String slowBinFileName)
        {
            List <SlowPacket> packetList = new List <SlowPacket>();

            if (!File.Exists(slowBinFileName))
            {
                return(packetList);
            }
            using (FileStream fileStream = File.Open(slowBinFileName, FileMode.Open))
            {
                BinaryReader binaryReader = new BinaryReader(fileStream);
                while (binaryReader.BaseStream.Position <= binaryReader.BaseStream.Length - 1)
                {
                    byte[]          headerBytes = binaryReader.ReadBytes(Marshal.SizeOf(typeof(EnvPacketHeader)));
                    EnvPacketHeader header      = Tool.ByteToStruct <EnvPacketHeader>(headerBytes, 0, headerBytes.Length);
                    if (header.syncHeader.EqualBytes(EnvProtocol.SyncHeader) && header.dataType == (byte)EnvProtocol.DataType.DataTypeSlow)
                    {
                        byte[]     buffer = binaryReader.ReadBytes(Marshal.SizeOf(typeof(SlowPacket)));
                        SlowPacket packet;
                        if (SlowParser.Parse(buffer, out packet))
                        {
                            packetList.Add(packet);
                        }
                    }
                }
            }
            return(packetList);
        }
示例#2
0
        private void ParseData(byte[] buffer)
        {
            if (buffer.Length <= Marshal.SizeOf(typeof(EnvPacketHeader)))
            {
                return;
            }
            EnvPacketHeader header = Tool.ByteToStruct <EnvPacketHeader>(buffer, 0, Marshal.SizeOf(typeof(EnvPacketHeader)));

            if (!Enumerable.SequenceEqual(header.syncHeader, EnvProtocol.SyncHeader))
            {
                return;
            }
            byte[] body = new byte[buffer.Length - Marshal.SizeOf(typeof(EnvPacketHeader))];
            Array.Copy(buffer, Marshal.SizeOf(typeof(EnvPacketHeader)), body, 0, body.Length);
            switch ((EnvProtocol.DataType)header.dataType)
            {
            case EnvProtocol.DataType.DataTypeSlow:
                SlowPacket slowPacket;
                if (SlowParser.Parse(body, out slowPacket))
                {
                    IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SlowPacket)));
                    Marshal.StructureToPtr(slowPacket, ptr, true);
                    WinApi.PostMessage(mainWindowHandle, WinApi.WM_SLOW_DATA, 0, ptr);
                }
                else
                {
                    WinApi.PostMessage(mainWindowHandle, WinApi.WM_SLOW_DATA, 0, IntPtr.Zero);
                }
                if (IsStartLogData)
                {
                    dataLogger.WriteSlowPacket(buffer);
                }
                break;

            case EnvProtocol.DataType.DataTypeFast:
                FastPacket fastPacket;
                if (FastParser.Parse(body, out fastPacket))
                {
                    IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FastPacket)));
                    Marshal.StructureToPtr(fastPacket, ptr, true);
                    WinApi.PostMessage(mainWindowHandle, WinApi.WM_FAST_DATA, 0, ptr);
                }
                else
                {
                    WinApi.PostMessage(mainWindowHandle, WinApi.WM_FAST_DATA, 0, IntPtr.Zero);
                }
                if (IsStartLogData)
                {
                    dataLogger.WriteFastPacket(buffer);
                }
                break;

            case EnvProtocol.DataType.DataTypeTail:
                List <TailPacketRs> tailPacketRs = tailParser.Parse(body);
                if (tailPacketRs.Count > 0)
                {
                    foreach (TailPacketRs packet in tailPacketRs)
                    {
                        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TailPacketRs)));
                        Marshal.StructureToPtr(packet, ptr, true);
                        WinApi.PostMessage(mainWindowHandle, WinApi.WM_TAIL_DATA, 0, ptr);
                    }
                }
                else
                {
                    WinApi.PostMessage(mainWindowHandle, WinApi.WM_TAIL_DATA, 0, IntPtr.Zero);
                }
                if (IsStartLogData)
                {
                    dataLogger.WriteTailPacket(buffer);
                }
                break;

            default:
                break;
            }
        }