private void HandleCmdNetworkPacket(NetworkPacket networkPacket) { // the drone tends to send not one, but several commands at once. // they are aggregated and chained from head to tail. (or tail to head, whatever) int idx = DjiPacket.GetWhSize(networkPacket.Payload); while (idx < networkPacket.Payload.Length) { bool instSetRes = InstSetRes(networkPacket, out DjiCmdPacket packet, idx); if (instSetRes) { // set the head of the next packet to the current tail idx += packet.DumlSize; } else if (packet.DumlSize != default(ushort)) { // the command didn't resolve, but the chain is still intact Trace.TraceWarning($"Faulty cmd received. Chain successfully recovered. " + $"Faulty cmd {networkPacket.Payload[idx..(idx + packet.DumlSize)].ToHexString(false, false)}");
protected override void ProcessNetworkPacket(NetworkPacket networkPacket) { var packetType = typeof(DjiEmptyPacket); byte wifiSize = DjiPacket.GetWhSize(networkPacket.Payload); // we did receive a wifi-packet with cmd data attached. // ensure that the delimiter is indeed 0x55 before we declare it a command. if (wifiSize < networkPacket.Payload.Length && networkPacket.Payload[wifiSize] == DjiDUMLPacket.DELIMITER) { packetType = typeof(DjiCmdPacket); } DjiPacket djiPacket = (DjiPacket)Activator.CreateInstance(packetType); if (djiPacket.Set(networkPacket.Payload)) { Resolve(networkPacket.Wrap(djiPacket, packetType)); } else { Trace.TraceError($"{nameof(DjiDronePacketResolver)} - Unprocessable packet {packetType.Name}: {networkPacket.Payload.ToHexString(false, false)}"); } }