Exemplo n.º 1
0
        /// <summary>
        /// 尝试让服务器转发一个文件,
        /// </summary>
        /// <param name="FileName">文件地址</param>
        /// <param name="FromNum">来自</param>
        /// <param name="ToNum">去往</param>
        /// <param name="PacketType">数据包类型</param>
        /// <param name="PrintFileName">输出后的文件名称</param>
        /// <returns>传过去的大小</returns>
        public static long TCPSendFile(String FileName, long FromNum, long ToNum, DataPacketType PacketType, out String PrintFileName)
        {
            Socket SocketBuffer = new Socket(SocketType.Stream, ProtocolType.Tcp);

            SocketBuffer.Connect(StaticResource.ServerIpaddress);
            long   res          = 0;
            String DateFileName = DateTime.Now.Ticks + IoTool.GetFileType(FileName);

            //String DateFileName = StaticResource.DateTimeLoginNumber(FromNum) + IoTool.GetFileType(FileName);
            IoTool.GetFileByteBlockALL(FileName, (int)DefaultMaxDataPacketSize, (content, filenmae, islast, count) =>
            {
                MessageModel msg = new MessageModel()
                {
                    FromIpaddress   = IPV4Address.ToString(),
                    FromLoginNumber = FromNum,
                    ToLoginNumber   = ToNum,
                    MessageType     = MessageType.DataPacket,
                    SendDateTime    = DateTime.UtcNow.ToString(),
                    MessageContent  = new MessageContent_DataPacket(content, DateFileName, islast, count, PacketType),
                };
                res += SocketBuffer.Send(MessageModel.ToBytes(msg));
                Thread.Sleep(50);
            });
            SocketBuffer.Close();
            SocketBuffer.Dispose();
            PrintFileName = DateFileName;
            return(res);
        }
Exemplo n.º 2
0
        protected static DataPacket InstanceNotifyPacket(DataPacketType packetType, Int32 notify)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BitConverter.GetBytes((Int32)packetType), 0, 4);
            Byte[] buffer = BitConverter.GetBytes(notify);
            Int32  length = buffer.Length;

            stream.Write(BitConverter.GetBytes(length), 0, 4);
            stream.Write(buffer, 0, length);
            DataPacket packet = new DataPacket(packetType, stream.GetBuffer());

            stream.Close();
            return(packet);
        }
Exemplo n.º 3
0
        protected static DataPacket InstanceMessagePacket(DataPacketType packetType, String message)
        {
            MemoryStream stream = new MemoryStream();

            stream.Write(BitConverter.GetBytes((Int32)packetType), 0, 4);
            Byte[] buffer = Encoding.ASCII.GetBytes(message);
            Int32  length = buffer.Length;

            stream.Write(BitConverter.GetBytes(length), 0, 4);
            stream.Write(buffer, 0, length);
            DataPacket packet = new DataPacket(packetType, stream.GetBuffer());

            stream.Close();
            return(packet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 成功返回结果显示
        /// </summary>
        private void retuViewVisi(byte[] ID, DataPacketType dpType, Label lab)
        {
            DP_TYPE_LABEL dpLabel = new DP_TYPE_LABEL(dpType, lab);

            SetDataResuleView.getInstance().returnSuccess(dpLabel);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 设置结果显示
        /// </summary>
        private void setViewVisi(DataPacketType dpType, Label lab)
        {
            DP_TYPE_LABEL dpLabel = new DP_TYPE_LABEL(dpType, lab);

            SetDataResuleView.getInstance().insertSet(dpLabel);
        }
Exemplo n.º 6
0
 public DataUpdateMessage(string message, DataPacketType dataPacket, object packet = null)
 {
     Message    = message;
     DataPacket = dataPacket;
     Packet     = packet;
 }
Exemplo n.º 7
0
        private void HandleDataPacket(byte[] packet)
        {
            using (MemoryStream stream = new MemoryStream(packet))
            {
                PacketBuffer buffer = new PacketBuffer(stream);
                if (buffer.Size < 3 || buffer.ReadByte() != 'F' || buffer.ReadByte() != 'L' || buffer.ReadByte() != 'Y')
                {
                    return;
                }

                int            revision = buffer.ReadInt();
                DataPacketType type     = (DataPacketType)buffer.ReadByte();

                lastDataTime = Environment.TickCount;

                switch (type)
                {
                case DataPacketType.Drone:
                    if (!CheckRevision(lastDataDroneRevision, revision))
                    {
                        return;
                    }

                    DroneState state = (DroneState)buffer.ReadByte();

                    QuadMotorValues motorValues = new QuadMotorValues(buffer);
                    GyroData        gyro        = new GyroData(buffer);

                    float batteryVoltage = buffer.ReadFloat();

                    int wifiRssi = buffer.ReadInt();

                    Data = new DroneData(state, motorValues, gyro, batteryVoltage, wifiRssi);

                    lastDataDroneRevision = revision;
                    break;

                case DataPacketType.Log:
                    if (!CheckRevision(lastDataLogRevision, revision))
                    {
                        return;
                    }

                    int lines = buffer.ReadInt();

                    for (int i = 0; i < lines; i++)
                    {
                        string msg = buffer.ReadString();

                        if (OnLogMessage == null)
                        {
                            Log.Info("[Drone] " + msg);
                        }
                        else
                        {
                            OnLogMessage(msg + Environment.NewLine);
                        }
                    }

                    lastDataLogRevision = revision;
                    break;

                case DataPacketType.Debug:
                    if (!CheckRevision(lastDataDebugRevision, revision))
                    {
                        return;
                    }

                    DebugData             = new DebugData(buffer);
                    lastDataDebugRevision = revision;
                    break;
                }
            }
        }
Exemplo n.º 8
0
 public DP_TYPE_LABEL(DataPacketType dpType, Label lab)
 {
     this.dpType = dpType;
     this.lab    = lab;
 }
Exemplo n.º 9
0
 protected static DataPacket InstanceScreenPacket(DataPacketType packetType)
 {
     return(null);
 }
Exemplo n.º 10
0
        public static DataPacket InstanceSendClosePacket(String reason)
        {
            DataPacketType packetType = DataPacketType.Close;

            return(InstanceMessagePacket(packetType, reason));
        }
Exemplo n.º 11
0
 public DataPacket(DataPacketType packetType, Byte[] buffer)
 {
     this.packetType = packetType;
     this.buffer     = buffer;
 }
Exemplo n.º 12
0
 public MessageContent_DataPacket(byte[] Content, String FileName, bool IsLastPacket, int PacketIndex, DataPacketType PacketType)
 {
     this.Content      = Content;
     this.FileName     = FileName;
     this.IsLastPacket = IsLastPacket;
     this.PacketIndex  = PacketIndex;
     this.PacketType   = PacketType;
     //this.FileToken = $"{StaticResource.DateTimeString}-{Content.Length}-{PacketIndex}-{FileName}";
 }
Exemplo n.º 13
0
        private void HandleDataPacket(byte[] packet)
        {
            using (MemoryStream stream = new MemoryStream(packet))
            {
                PacketBuffer buffer = new PacketBuffer(stream);
                if (buffer.Size < 3 || buffer.ReadByte() != 'F' || buffer.ReadByte() != 'L' || buffer.ReadByte() != 'Y')
                {
                    return;
                }

                int            revision = buffer.ReadInt();
                DataPacketType type     = (DataPacketType)buffer.ReadByte();

                lastDataTime = Environment.TickCount;

                switch (type)
                {
                case DataPacketType.Drone:
                    if (!CheckRevision(lastDataDroneRevision, revision))
                    {
                        return;
                    }

                    DroneState      state       = (DroneState)buffer.ReadByte();
                    QuadMotorValues motorValues = new QuadMotorValues(buffer);
                    SensorData      sensor      = new SensorData(buffer);

                    float batteryVoltage = buffer.ReadFloat();
                    int   wifiRssi       = buffer.ReadInt();

                    Data = new DroneData(state, motorValues, sensor, batteryVoltage, wifiRssi);

                    lastDataDroneRevision = revision;
                    break;

                case DataPacketType.Log:
                    if (!CheckRevision(lastDataLogRevision, revision))
                    {
                        return;
                    }

                    int lines = buffer.ReadInt();

                    for (int i = 0; i < lines; i++)
                    {
                        string msg = buffer.ReadString();

                        DroneLog.AddLine(msg);
                    }

                    lastDataLogRevision = revision;
                    break;

                case DataPacketType.DebugOutput:
                    if (!CheckRevision(lastDataOutputRevision, revision))
                    {
                        return;
                    }

                    DebugOutputData        = new OutputData(buffer);
                    lastDataOutputRevision = revision;

                    NotifyDebugDataChanged();
                    break;

                case DataPacketType.DebugProfiler:
                    if (!CheckRevision(lastDataProfilerRevision, revision))
                    {
                        return;
                    }

                    DebugProfilerData        = new ProfilerData(buffer);
                    lastDataProfilerRevision = revision;

                    NotifyDebugDataChanged();
                    break;
                }
            }
        }