using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeTransmitterTestV4Info : PacketInfoBase
{
	public override string Name => "Le Transmitter Test V4";

	public override string DisplayGroup => "LE Controller";

	public LeTransmitterTestV4Info(LeTransmitterTestV4 packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeTransmitterTestV4 leTransmitterTestV = (LeTransmitterTestV4)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("TX_Channel", "Channel number. N = (F - 2402) / 2; 0x00 = 2402MHz; 0x27 = 2480MHz", 8, FormatValue(leTransmitterTestV.UserFields.TxChannel, 8), CteFrequencyValueExpression.CteFrequencyValueToString(leTransmitterTestV.UserFields.TxChannel), "", "27", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Test_Data_Length", "Length in bytes of payload data in each packet", 8, FormatValue(leTransmitterTestV.UserFields.TestDataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Payload", LeTransmitterTestV4.UserFieldsWrapper.PacketPayloadInfo.PacketPayloadToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.PacketPayload, 8), LeTransmitterTestV4.UserFieldsWrapper.PacketPayloadInfo.PacketPayloadToString(LeTransmitterTestV4.UserFieldsWrapper.PacketPayloadInfo.ValueToPacketPayload(leTransmitterTestV.UserFields.PacketPayload)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY", LeTransmitterTestV4.UserFieldsWrapper.PhyInfo.PhyToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.Phy, 8), LeTransmitterTestV4.UserFieldsWrapper.PhyInfo.PhyToString(LeTransmitterTestV4.UserFieldsWrapper.PhyInfo.ValueToPhy(leTransmitterTestV.UserFields.Phy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CTE_Length", LeTransmitterTestV4.UserFieldsWrapper.CteLengthInfo.CteLengthToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.CteLength, 8), LeTransmitterTestV4.UserFieldsWrapper.CteLengthInfo.CteLengthToString(LeTransmitterTestV4.UserFieldsWrapper.CteLengthInfo.ValueToCteLength(leTransmitterTestV.UserFields.CteLength)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CTE_Type", LeTransmitterTestV4.UserFieldsWrapper.CteTypeInfo.CteTypeToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.CteType, 8), LeTransmitterTestV4.UserFieldsWrapper.CteTypeInfo.CteTypeToString(LeTransmitterTestV4.UserFieldsWrapper.CteTypeInfo.ValueToCteType(leTransmitterTestV.UserFields.CteType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Switching_Pattern_Length", LeTransmitterTestV4.UserFieldsWrapper.SwitchingPatternLengthInfo.SwitchingPatternLengthToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.SwitchingPatternLength, 8), LeTransmitterTestV4.UserFieldsWrapper.SwitchingPatternLengthInfo.SwitchingPatternLengthToString(LeTransmitterTestV4.UserFieldsWrapper.SwitchingPatternLengthInfo.ValueToSwitchingPatternLength(leTransmitterTestV.UserFields.SwitchingPatternLength)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leTransmitterTestV.UserFields.AntennaIdsSetList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Antenna_IDs[" + i + "]", "", 8, FormatValue(leTransmitterTestV.UserFields.AntennaIdsSetList[i].AntennaIds, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		fieldInfoList.Add(new PacketFieldInfo("Transmit_Power_Level", LeTransmitterTestV4.UserFieldsWrapper.TransmitPowerLevelInfo.TransmitPowerLevelToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.TransmitPowerLevel, 8), LeTransmitterTestV4.UserFieldsWrapper.TransmitPowerLevelInfo.TransmitPowerLevelToString(LeTransmitterTestV4.UserFieldsWrapper.TransmitPowerLevelInfo.ValueToTransmitPowerLevel(leTransmitterTestV.UserFields.TransmitPowerLevel)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeTransmitterTestV4 leTransmitterTestV = (LeTransmitterTestV4)packet;
		int num = -1;
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.TxChannel = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.TestDataLength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.PacketPayload = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.Phy = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.CteLength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.CteType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.SwitchingPatternLength = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leTransmitterTestV.UserFields.AntennaIdsSetList.Count; i++)
		{
			if (index == ++num)
			{
				leTransmitterTestV.UserFields.AntennaIdsSetList[i].AntennaIds = Convert.ToUInt32(value, 16);
				return;
			}
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.TransmitPowerLevel = Convert.ToUInt32(value, 16);
		}
	}
}
