public void TransmitLargeObject()
        {
            int expected_byte_count = 20000;

            byte[] raw_bytes = new byte[expected_byte_count];
            Random rnd       = new Random();

            for (int i = 0; i < expected_byte_count; i++)
            {
                //raw_bytes[i] = (byte)rnd.Next();
                raw_bytes[i] = (byte)'x';
            }
            using (RelayController ctrl_send = RelayController.ConnectSerial("COM4"))
            {
                using (RelayController ctrl_rcv = RelayController.ConnectSerial("COM6"))
                {
                    ctrl_send.Clear();
                    ulong  long_address  = 0x0013A20041B764AD;
                    ushort short_address = ctrl_send.Discover(long_address);
                    // receive "Discover" emission
                    List <byte> rcv_bytes = ctrl_rcv.ReceiveBytes();
                    Assert.AreEqual("Discover".Length, rcv_bytes.Count);
                    // send actual data
                    try
                    {
                        ctrl_send.Transmit(short_address, raw_bytes);
                    }
                    catch
                    {
                        // ignored
                        Console.WriteLine("Transmission failed");
                    }
                    List <EmissionDescriptor> emissions = ctrl_send.GetAllEmissions();
                    foreach (EmissionDescriptor descriptor in emissions)
                    {
                        Console.WriteLine($"Unused emission with frame type {descriptor.Header.FrameType}");
                    }
                    // receive actual data
                    byte[] rcv_data_bytes = ctrl_rcv.ReceiveTransmission(0);
                    Assert.AreEqual(expected_byte_count, rcv_data_bytes.Length);
                    for (int i = 0; i < expected_byte_count; i++)
                    {
                        Assert.AreEqual(raw_bytes[i], rcv_data_bytes[i]);
                    }
                }
            }
        }
        public void ScrambleAndTransmit()
        {
            int  expected_byte_count = 1000;
            uint expected_object_id  = 5;

            byte[] raw_bytes = new byte[expected_byte_count];
            for (int i = 0; i < expected_byte_count; i++)
            {
                raw_bytes[i] = (byte)i;
            }
            using (RelayController ctrl_send = RelayController.ConnectSerial("COM4"))
            {
                using (RelayController ctrl_rcv = RelayController.ConnectSerial("COM6"))
                {
                    ctrl_send.Clear();
                    ulong  long_address  = 0x0013A20041B764AD;
                    ushort short_address = ctrl_send.Discover(long_address);
                    // receive "Discover" emission
                    List <byte> rcv_bytes = ctrl_rcv.ReceiveBytes();
                    Assert.AreEqual("Discover".Length, rcv_bytes.Count);
                    // send actual data
                    try
                    {
                        TransmissionObject xm           = transmissionFactory.Create(raw_bytes, expected_object_id);
                        byte[]             header_bytes = xm.Header.Pack().ToArray();
                        ctrl_send.SendRawBytes(short_address, header_bytes);
                        int    total_byte_count = header_bytes.Length;
                        Random rnd = new Random();
                        IEnumerable <TransmissionChunk> chunks = xm.Chunks.OrderBy(c => rnd.Next());
                        foreach (TransmissionChunk chunk in chunks)
                        {
                            byte[] packet_bytes = chunk.Pack().ToArray();
                            try
                            {
                                ctrl_send.SendRawBytes(short_address, packet_bytes);
                                total_byte_count += packet_bytes.Length;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine($"Failed at packet {chunk.Header.ID} after {total_byte_count} bytes");
                                throw e;
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                        Console.WriteLine("Transmission failed");
                    }
                    List <EmissionDescriptor> emissions = ctrl_send.GetAllEmissions();
                    foreach (EmissionDescriptor descriptor in emissions)
                    {
                        Console.WriteLine($"Unused emission with frame type {descriptor.Header.FrameType}");
                    }
                    // receive actual data
                    byte[] rcv_data_bytes = ctrl_rcv.ReceiveTransmission(expected_object_id);
                    Assert.AreEqual(expected_byte_count, rcv_data_bytes.Length);
                    for (int i = 0; i < expected_byte_count; i++)
                    {
                        Assert.AreEqual(raw_bytes[i], rcv_data_bytes[i]);
                    }
                }
            }
        }