private void UpdateDebugData(DebugData data) { StringBuilder profilerString = new StringBuilder(); if (data.Profiler.Entries != null) { for (int i = 0; i < data.Profiler.Entries.Length; i++) { DebugProfiler.Entry entry = data.Profiler.Entries[i]; profilerString.AppendFormat("{0} {1}ms ({2}ms)", entry.Name.PadLeft(25), Formatting.FormatDecimal(entry.Time.TotalMilliseconds, 1, 4), Formatting.FormatDecimal(entry.TimeMax.TotalMilliseconds, 1, 4)); profilerString.AppendLine(); } profilerData.Text = profilerString.ToString(); } }
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; } } }
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; } } }
public DebugDataChangedEventArgs(Drone drone) { this.DebugData = drone.DebugData; }