using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetConnectionlessSlaveBroadcastReceiveInfo : PacketInfoBase
{
	public override string Name => "Set Connectionless Slave Broadcast Receive";

	public override string DisplayGroup => "Link Control";

	public SetConnectionlessSlaveBroadcastReceiveInfo(SetConnectionlessSlaveBroadcastReceive packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetConnectionlessSlaveBroadcastReceive setConnectionlessSlaveBroadcastReceive = (SetConnectionlessSlaveBroadcastReceive)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Enable", SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.EnableInfo.EnableToDescription(), 8, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.Enable, 8), SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.EnableInfo.EnableToString(SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.EnableInfo.ValueToEnable(setConnectionlessSlaveBroadcastReceive.UserFields.Enable)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR of the Connectionless Slave Broadcast transmitter", 48, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LT_ADDR", SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.LtAddrInfo.LtAddrToDescription(), 8, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.LtAddr, 8), SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.LtAddrInfo.LtAddrToString(SetConnectionlessSlaveBroadcastReceive.UserFieldsWrapper.LtAddrInfo.ValueToLtAddr(setConnectionlessSlaveBroadcastReceive.UserFields.LtAddr)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interval", "Interval between Connectionless Slave Broadcast packets instants in slots (only even values are valid).", 16, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.Interval, 16), "", "0002", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock_Offset", "(CLKNslave - CLK) modulo 2^28.", 32, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.ClockOffset, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Next_Connectionless_Slave_Broadcast_Clock", "CLK for next Connectionless Slave Broadcast instant.", 32, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.NextConnectionlessSlaveBroadcastClock, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CSB_supervisionTO", "Duration in slots to continue listening for Connectionless Slave Broadcast packets after the last successfully received Connectionless Slave Broadcast packet (only even values are valid).", 16, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.CsbSupervisionto, 16), "", "0002", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Remote_Timing_Accuracy", "Timing accuracy of the master in ppm. Typical values are 20ppm and 250ppm.", 8, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.RemoteTimingAccuracy, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Skip", "Number of Connectionless Slave Broadcast instants to skip after successfully receiving a Broadcast packet.", 8, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.Skip, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Type", AclPacketTypeInfo.AclPacketTypeToDescription(), 16, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.PacketType, 16), AclPacketTypeInfo.AclPacketTypeToString(AclPacketTypeInfo.ValueToAclPacketType(setConnectionlessSlaveBroadcastReceive.UserFields.PacketType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AFH_Channel_Map", "This parameter contains 80 1-bit fields. The nth such field (in the range 0 to 78) contains the value for channel n: Channel n is bad = 0, Channel n is unknown = 1. The most significant bit (bit 79) is reserved and shall be set to 0", setConnectionlessSlaveBroadcastReceive.UserFields.AfhChannelMapList.Count * 8, FormatValue(setConnectionlessSlaveBroadcastReceive.UserFields.AfhChannelMapList, setConnectionlessSlaveBroadcastReceive.UserFields.AfhChannelMapList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetConnectionlessSlaveBroadcastReceive setConnectionlessSlaveBroadcastReceive = (SetConnectionlessSlaveBroadcastReceive)packet;
		int num = -1;
		if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.Enable = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.LtAddr = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.Interval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.ClockOffset = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.NextConnectionlessSlaveBroadcastClock = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.CsbSupervisionto = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.RemoteTimingAccuracy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.Skip = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setConnectionlessSlaveBroadcastReceive.UserFields.PacketType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, setConnectionlessSlaveBroadcastReceive.UserFields.AfhChannelMapList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				setConnectionlessSlaveBroadcastReceive.UserFields.AfhChannelMapList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
