using System;
using System.Runtime.InteropServices;

namespace QC.QMSLPhone;

public class LogLTEAGC : LogMessage
{
	[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 8)]
	public struct LogLTEAGCType
	{
		public uint first32bits;

		public uint second32bits;
	}

	private const int lteAgcLogSize = 8;

	public LogLTEAGCType LTEAgcLog;

	private GCHandle pinnedPacket;

	private IntPtr p;

	private IntPtr pLTEAgcLog;

	public LogLTEAGC(LogMessage msgVal)
		: base(msgVal.msgID, msgVal.message, displayRawVal: false)
	{
		message = msgVal.message;
		pinnedPacket = GCHandle.Alloc(message, GCHandleType.Pinned);
		p = pinnedPacket.AddrOfPinnedObject();
		pLTEAgcLog = new IntPtr(p.ToInt64() + 16);
		LTEAgcLog = (LogLTEAGCType)Marshal.PtrToStructure(pLTEAgcLog, typeof(LogLTEAGCType));
	}

	public int getRxPath()
	{
		ulong num = LTEAgcLog.first32bits << 9;
		num >>= 31;
		int num2 = Convert.ToInt16(num);
		byte[] array = BitConverter.GetBytes(LTEAgcLog.first32bits);
		if (BitConverter.IsLittleEndian)
		{
			array = ReverseBytes(array);
		}
		if ((array[1] & 0x40) > 0)
		{
			return 1;
		}
		return 0;
	}

	public double getRssi()
	{
		byte[] bytes = BitConverter.GetBytes(LTEAgcLog.second32bits);
		if (BitConverter.IsLittleEndian)
		{
			bytes = ReverseBytes(bytes);
		}
		return 0.0;
	}

	private byte[] ReverseBytes(byte[] inArray)
	{
		int num = inArray.Length - 1;
		for (int i = 0; i < inArray.Length / 2; i++)
		{
			byte b = inArray[i];
			inArray[i] = inArray[num];
			inArray[num] = b;
			num--;
		}
		return inArray;
	}
}
