Esempio n. 1
0
 public DataChangedEventArgs(Drone drone)
 {
     this.Data = drone.Data;
 }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
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;
                }
            }
        }