using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class McpsDataIndicationInfo : PacketInfoBase
{
	public override string Name => "Mcps Data Indication";

	public override string DisplayGroup => "MLME Indication Packets";

	public McpsDataIndicationInfo(McpsDataIndication packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		McpsDataIndication mcpsDataIndication = (McpsDataIndication)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mcpsDataIndication.UserFields.Packetlength, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ProtocolID", "ProtocolID\r\n\r\n" + ProtocolIdInfo.ProtocolIdToDescription(), 8, FormatValue(mcpsDataIndication.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mcpsDataIndication.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mcpsDataIndication.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mcpsDataIndication.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mcpsDataIndication.UserFields.Length, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SrcAddrMode", "The source addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mcpsDataIndication.UserFields.Srcaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mcpsDataIndication.UserFields.Srcaddrmode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SrcPANId", "The 16-bit PAN identifier of the device from which the frame was received or to which the frame was being sent.", 16, FormatValue(mcpsDataIndication.UserFields.Srcpanid, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SrcAddr", "The individual device address of the entity from which the frame causing the error originated.", 64, FormatValue(mcpsDataIndication.UserFields.Srcaddr, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstAddrMode", "The destination addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mcpsDataIndication.UserFields.Dstaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mcpsDataIndication.UserFields.Dstaddrmode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstPANId", "The 16-bit PAN identifier of the entity to which the MSDU is being transferred.", 16, FormatValue(mcpsDataIndication.UserFields.Dstpanid, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstAddr", "The individual device address of the entity to which the MSDU is being transferred", 64, FormatValue(mcpsDataIndication.UserFields.Dstaddr, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("msduLength", "The number of octets contained in the MSDU to be transmitted by the MAC sublayer entity.", 8, FormatValue(mcpsDataIndication.UserFields.Msdulength, 8), "", "", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MPDULinkQuality", "LQI value measured during reception of the MPDU.Lower values represent lower LQI", 16, FormatValue(mcpsDataIndication.UserFields.Mpdulinkquality, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DSN", "The DSN of the received data frame", 8, FormatValue(mcpsDataIndication.UserFields.Dsn, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Timestamp", "", 32, FormatValue(mcpsDataIndication.UserFields.Timestamp, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SecurityLevel", "The security level to be used\r\n\r\n" + SecurityLevelOptionsInfo.SecurityLevelOptionsToDescription(), 8, FormatValue(mcpsDataIndication.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mcpsDataIndication.UserFields.Securitylevel)), "0", "7", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIdMode", "The mode used to identify the key to be used. This parameter is ignored if the SecurityLevel parameter is set to 0x00", 8, FormatValue(mcpsDataIndication.UserFields.Keyidmode, 8), "", "0", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeySource", "The originator of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 64, FormatValue(mcpsDataIndication.UserFields.Keysource, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIndex", "The index of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 8, FormatValue(mcpsDataIndication.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MSDUData", "MSDU data based on msduLength", mcpsDataIndication.UserFields.MsdudataList.Count * 8, FormatValue(mcpsDataIndication.UserFields.MsdudataList, mcpsDataIndication.UserFields.MsdudataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		McpsDataIndication mcpsDataIndication = (McpsDataIndication)packet;
		int num = -1;
		if (index == ++num)
		{
			mcpsDataIndication.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mcpsDataIndication.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			mcpsDataIndication.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Srcaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Srcpanid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Srcaddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Dstaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Dstpanid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Dstaddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Msdulength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Mpdulinkquality = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Dsn = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Timestamp = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataIndication.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, mcpsDataIndication.UserFields.MsdudataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				mcpsDataIndication.UserFields.MsdudataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
