void ConfigureTx(TxConfiguration txConfiguration, float bw) { var packetsPer10ms_fullPayload = (int)Math.Floor(bw * 0.01f / (LocalLogicConfiguration.IpAndUdpHeadersSizeBytes + _payloadPacket.Length) / 8); var udpBytesPerPacket10ms = (int)Math.Floor(bw * 0.01f / 8 - LocalLogicConfiguration.IpAndUdpHeadersSizeBytes); if (packetsPer10ms_fullPayload < 5 && udpBytesPerPacket10ms <= _payloadPacket.Length) { if (udpBytesPerPacket10ms > PayloadPacketHeaderSizeBytes && udpBytesPerPacket10ms > 200) { txConfiguration.PacketsPer10ms = 1; txConfiguration.UdpBytesPerPacket10ms = udpBytesPerPacket10ms; } else { // not 10ms, go with 100ms period ConfigureTx_100ms_1s(txConfiguration, bw); } } else // large bandwidths { txConfiguration.PacketsPer10ms = packetsPer10ms_fullPayload; txConfiguration.UdpBytesPerPacket10ms = _payloadPacket.Length; // precise adjustment var remainderBw = bw - 100.0f * txConfiguration.PacketsPer10ms * (txConfiguration.UdpBytesPerPacket10ms + LocalLogicConfiguration.IpAndUdpHeadersSizeBytes) * 8; ConfigureTx_100ms_1s(txConfiguration, remainderBw); } }
void ConfigureTx_100ms_1s(TxConfiguration txConfiguration, float bw) { var packetsPer100ms_fullPayload = (int)Math.Floor(bw * 0.1f / (LocalLogicConfiguration.IpAndUdpHeadersSizeBytes + _payloadPacket.Length) / 8); var udpBytesPerPacket100ms = (int)Math.Floor(bw * 0.1f / 8 - LocalLogicConfiguration.IpAndUdpHeadersSizeBytes); if (packetsPer100ms_fullPayload < 5 && udpBytesPerPacket100ms <= _payloadPacket.Length) { if (udpBytesPerPacket100ms > PayloadPacketHeaderSizeBytes && udpBytesPerPacket100ms > 200) { txConfiguration.PacketsPer100ms = 1; txConfiguration.UdpBytesPerPacket100ms = udpBytesPerPacket100ms; } else { // not 100ms, go with 1s period var packetsPer1s_fullPayload = (int)Math.Floor(bw / (LocalLogicConfiguration.IpAndUdpHeadersSizeBytes + _payloadPacket.Length) / 8); var udpBytesPerPacket1s = (int)Math.Floor(bw / 8 - LocalLogicConfiguration.IpAndUdpHeadersSizeBytes); if (packetsPer1s_fullPayload < 5 && udpBytesPerPacket1s <= _payloadPacket.Length) { if (udpBytesPerPacket1s > PayloadPacketHeaderSizeBytes) { txConfiguration.PacketsPer1s = 1; txConfiguration.UdpBytesPerPacket1s = udpBytesPerPacket1s; } else { // lowest bandwidth txConfiguration.PacketsPer1s = 1; txConfiguration.UdpBytesPerPacket1s = PayloadPacketHeaderSizeBytes; } } else { txConfiguration.PacketsPer1s = packetsPer1s_fullPayload; txConfiguration.UdpBytesPerPacket1s = _payloadPacket.Length; // todo more exact } } } else { txConfiguration.PacketsPer100ms = packetsPer100ms_fullPayload; txConfiguration.UdpBytesPerPacket100ms = _payloadPacket.Length; // todo precise adjustment } }