using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using System.Xml.Serialization;
using DebugToolInstrumentInterface;
using QC.QMSLPhone;
using QRCT_modem_RF_Debug_tool;

namespace QFDT_Components;

public partial class Wlan_WCN36XX : UserControl, IComponentConnector
{
	public delegate void SendDebugMessage(MessageLevel level, string message);

	public delegate bool GetCheckBoxStatusCB(CheckBox cbx);

	public delegate Visibility GetComponentVisibilityCB<T>(T c) where T : Control;

	public delegate retTypeOfComboBox<T> GetTextBoxValueCB<T>(TextBox tbx);

	public delegate retTypeOfComboBox<T> GetComboBoxItemCB<T>(ComboBox cbx);

	public delegate void SetButtonEnableCB(bool bEnable);

	public delegate void SetTextBoxCotentCB(string content);

	public const string strRxEnabled = "Receive Enabled";

	public const string strTxEnabled = "Transmit Enabled";

	public const string strPhyChainR0On = "PHY_CHAIN_SEL_R0_ON";

	public const string strPhyChainR0R1On = "PHY_CHAIN_SEL_R0R1_ON";

	public const string strPhyChainT00n = "PHY_CHAIN_SEL_T0_ON";

	public const string strPhyChainT0R1On = "PHY_CHAIN_SEL_T0_R1_ON";

	public const string strPhyChainR1On = "PHY_CHAIN_SEL_R1_ON";

	public const string str_ChannelBonding_None = "None";

	public const string str_40MHz_BW_Primary_LOW = "40MHz BW Primary LOW";

	public const string str_40MHz_BW_Primary_CENTERED = "40MHz BW Primary CENTERED";

	public const string str_40MHz_BW_Primary_HIGH = "40MHz BW Primary HIGH";

	public const string str_80MHz_BW_20_40MHZ_LOW_40_80MHZ_CENTERED = "80MHz BW 20/40MHZ LOW 40/80MHZ CENTERED";

	public const string str_80MHz_BW_20_40MHZ_CENTERED_40_80MHZ_CENTERED = "80MHz BW 20/40MHZ CENTERED 40/80MHZ CENTERED";

	public const string str_80MHz_BW_20_40MHZ_HIGH_40_80MHZ_CENTERED = "80MHz BW 20/40MHZ HIGH 40/80MHZ CENTERED";

	public const string str_80MHz_BW_20_40MHZ_LOW_40_80MHZ_LOW = "80MHz BW 20/40MHZ LOW 40/80MHZ LOW";

	public const string str_80MHz_BW_20_40MHZ_HIGH_40_80MHZ_LOW = "80MHz BW 20/40MHZ HIGH 40/80MHZ LOW";

	public const string str_80MHz_BW_20_40MHZ_LOW_40_80MHZ_HIGH = "80MHz BW 20/40MHZ LOW 40/80MHZ HIGH";

	public const string str_80MHz_BW_20_40MHZ_HIGH_40_80MHZ_HIGH = "80MHz BW 20/40MHZ HIGH 40/80MHZ HIGH";

	public SendDebugMessage DebugMessageCB;

	public wlan_CfgParams cfgParams;

	private bool bHideMostOfComponentMode = true;

	private Dictionary<string, uint> ChainDict;

	private Dictionary<string, int> ChannelBondingDict;

	private BaseBandSupportedType baseBandType;

	private WLAN_iPreamble iPreamble;

	private WayToStartWlanAppEnum wayToLaunchWlanApp;

	private List<WLAN_Scenario> scenarioList;

	private WLAN_Scenario m_CurTxScenario;

	public ChainOriention m_ChainOrientation;

	public bool m_bContinueFlag;

	public Phone phone;

	public ISignalGenerator pSG;

	public ISpectrumAnalyzer pSA;

	public PCF m_PCF;

	private Thread thread;

	private Thread thread_adb;

	public string m_PCFPath { get; set; }

	public void Register_DebugMessageCB(SendDebugMessage me)
	{
		DebugMessageCB = me;
	}

	public bool GetCheckBoxStatus(CheckBox cbx)
	{
		bool result = false;
		if (cbx.Dispatcher.CheckAccess())
		{
			if (cbx.IsChecked == true)
			{
				result = true;
			}
		}
		else
		{
			GetCheckBoxStatusCB method = GetCheckBoxStatus;
			result = (bool)base.Dispatcher.Invoke(method, cbx);
		}
		return result;
	}

	public Visibility GetComponentVisibility<T>(T c) where T : Control
	{
		Visibility visibility = Visibility.Collapsed;
		if (c.Dispatcher.CheckAccess())
		{
			return c.Visibility;
		}
		GetComponentVisibilityCB<T> method = GetComponentVisibility;
		return (Visibility)base.Dispatcher.Invoke(method, c);
	}

	public retTypeOfComboBox<double> GetTextBoxValue_double(TextBox tbx)
	{
		retTypeOfComboBox<double> retTypeOfComboBox2 = new retTypeOfComboBox<double>();
		if (tbx.Dispatcher.CheckAccess())
		{
			if (double.TryParse(tbx.Text, out var result))
			{
				retTypeOfComboBox2.bNull = false;
				retTypeOfComboBox2.value = result;
			}
			else
			{
				retTypeOfComboBox2.bNull = true;
			}
		}
		else
		{
			GetTextBoxValueCB<double> method = GetTextBoxValue_double;
			retTypeOfComboBox2 = (retTypeOfComboBox<double>)base.Dispatcher.Invoke(method, tbx);
		}
		return retTypeOfComboBox2;
	}

	public retTypeOfComboBox<int> GetTextBoxValue_int(TextBox tbx)
	{
		retTypeOfComboBox<int> retTypeOfComboBox2 = new retTypeOfComboBox<int>();
		if (tbx.Dispatcher.CheckAccess())
		{
			if (int.TryParse(tbx.Text, out var result))
			{
				retTypeOfComboBox2.bNull = false;
				retTypeOfComboBox2.value = result;
			}
			else
			{
				retTypeOfComboBox2.bNull = true;
			}
		}
		else
		{
			GetTextBoxValueCB<int> method = GetTextBoxValue_int;
			retTypeOfComboBox2 = (retTypeOfComboBox<int>)base.Dispatcher.Invoke(method, tbx);
		}
		return retTypeOfComboBox2;
	}

	public retTypeOfComboBox<uint> GetTextBoxValue_uint(TextBox tbx)
	{
		retTypeOfComboBox<uint> retTypeOfComboBox2 = new retTypeOfComboBox<uint>();
		if (tbx.Dispatcher.CheckAccess())
		{
			if (uint.TryParse(tbx.Text, out var result))
			{
				retTypeOfComboBox2.bNull = false;
				retTypeOfComboBox2.value = result;
			}
			else
			{
				retTypeOfComboBox2.bNull = true;
			}
		}
		else
		{
			GetTextBoxValueCB<uint> method = GetTextBoxValue_uint;
			retTypeOfComboBox2 = (retTypeOfComboBox<uint>)base.Dispatcher.Invoke(method, tbx);
		}
		return retTypeOfComboBox2;
	}

	public retTypeOfComboBox<T> GetComboBoxItem<T>(ComboBox cbx)
	{
		retTypeOfComboBox<T> retTypeOfComboBox2 = new retTypeOfComboBox<T>();
		if (cbx.Dispatcher.CheckAccess())
		{
			if (cbx.SelectedItem != null)
			{
				retTypeOfComboBox2.value = (T)cbx.SelectedItem;
				retTypeOfComboBox2.bNull = false;
			}
			else
			{
				retTypeOfComboBox2.bNull = true;
			}
		}
		else
		{
			GetComboBoxItemCB<T> method = GetComboBoxItem<T>;
			retTypeOfComboBox2 = (retTypeOfComboBox<T>)base.Dispatcher.Invoke(method, cbx);
		}
		return retTypeOfComboBox2;
	}

	private void UpdateRates()
	{
		iPreamble = WLAN_iPreamble.LONGB;
		if (cboTxPacketMode.SelectedValue == null)
		{
			return;
		}
		switch (cboTxPacketMode.SelectedValue.ToString())
		{
		case "11b":
			if (cboTxPacketRate.SelectedItem != null)
			{
				switch (cboTxPacketRate.SelectedItem.ToString())
				{
				case "11b LONG 1 Mbps":
				case "11b LONG 2 Mbps":
				case "11b LONG 5.5 Mbps":
				case "11b LONG 11 Mbps":
					iPreamble = WLAN_iPreamble.LONGB;
					break;
				case "11b SHORT 2 Mbps":
				case "11b SHORT 5.5 Mbps":
				case "11b SHORT 11 Mbps":
					iPreamble = WLAN_iPreamble.SHORTB;
					break;
				}
			}
			break;
		case "11g":
		case "11a/g":
			iPreamble = WLAN_iPreamble.OFDM;
			break;
		case "11n":
			iPreamble = WLAN_iPreamble.MIXED;
			break;
		case "11ac":
			iPreamble = WLAN_iPreamble.MIXED;
			break;
		}
	}

	public Wlan_WCN36XX()
	{
		cfgParams = new wlan_CfgParams();
		ChainDict = new Dictionary<string, uint>();
		ChainDict.Add("Receive Enabled", 4u);
		ChainDict.Add("Transmit Enabled", 6u);
		ChainDict.Add("PHY_CHAIN_SEL_R0_ON", 4u);
		ChainDict.Add("PHY_CHAIN_SEL_R0R1_ON", 5u);
		ChainDict.Add("PHY_CHAIN_SEL_T0_ON", 6u);
		ChainDict.Add("PHY_CHAIN_SEL_T0_R1_ON", 7u);
		ChainDict.Add("PHY_CHAIN_SEL_R1_ON", 8u);
		ChannelBondingDict = new Dictionary<string, int>();
		ChannelBondingDict.Add("None", 0);
		ChannelBondingDict.Add("40MHz BW Primary LOW", 1);
		ChannelBondingDict.Add("40MHz BW Primary CENTERED", 2);
		ChannelBondingDict.Add("40MHz BW Primary HIGH", 3);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ LOW 40/80MHZ CENTERED", 4);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ CENTERED 40/80MHZ CENTERED", 5);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ CENTERED", 6);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ LOW 40/80MHZ LOW", 7);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ LOW", 8);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ LOW 40/80MHZ HIGH", 9);
		ChannelBondingDict.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ HIGH", 10);
		InitializeComponent();
		HiddenDefault.Visibility = Visibility.Collapsed;
		InitUserInterface();
	}

	private void InitCboAntenna()
	{
		cboAntennaSelect.Items.Clear();
		cboAntennaSelect.Items.Add(0u);
		cboAntennaSelect.Items.Add(1u);
	}

	private void FTM_Start()
	{
		if (phone != null)
		{
			byte b = byte.MaxValue;
			int intValueOfWlanID = getIntValueOfWlanID();
			if (intValueOfWlanID != 0)
			{
				b = phone.GET_RETVALUE_FTM_WLAN_GEN6_START(intValueOfWlanID);
				if (b == byte.MaxValue || b == 0)
				{
					throw new PhoneException("QLIB_FTM_WLAN_GEN6_START fail, please check ptt_socket_app status");
				}
				if (b >= 2)
				{
					baseBandType = BaseBandSupportedType.Pronto;
					DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_START Success - Pronto");
				}
				else
				{
					baseBandType = BaseBandSupportedType.Riva;
					DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_START Success - Riva");
				}
			}
			return;
		}
		throw new PhoneException("Inconrrect phonehandle!");
	}

	private void FTM_Stop()
	{
		if (phone != null)
		{
			phone.FTM_WLAN_GEN6_STOP();
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_STOP Success");
			return;
		}
		throw new PhoneException("Inconrrect phonehandle!");
	}

	private void InitCboTxPwrCtrlMode()
	{
		cboPwrCtrlMode.Items.Clear();
		cboPwrCtrlMode.Items.Add("OPEN LOOP");
		cboPwrCtrlMode.Items.Add("SCPC");
		cboPwrCtrlMode.Items.Add("CLPC");
		cboPwrCtrlMode.Items.Add("AUTO");
		cboPwrCtrlMode.Items.Add("AUTO-SAR");
	}

	private void DefaultVisibleSet()
	{
		spTx.Visibility = Visibility.Visible;
		sPanelTxScenario.Visibility = Visibility.Visible;
		sPanelPwrCtrl.Visibility = Visibility.Visible;
		spRx.Visibility = Visibility.Collapsed;
		cbLdpcRateEnable.Visibility = Visibility.Collapsed;
	}

	private void SetDefaultValue()
	{
		UpdateComponentsAccordingToWlanID();
		UpdateComponentsAccordingToChain();
		cboAntennaSelect.SelectedValue = 0u;
		cboChanBonding.SelectedValue = "None";
		cboRFChannel.SelectedValue = "RF_CHAN_1(2412)";
		cboTxPacketMode.SelectedValue = "11a/g";
		txtFrame.Text = "0";
		txtPayloadSize.Text = "1000";
		cboPayloadType.SelectedIndex = 2;
		txtSpacing.Text = "200";
		cbxFCSCalculated.IsChecked = true;
		txtRFGain.Text = "0";
		txtDigitalGain.Text = "0";
		txtTxPower.Text = "10";
		cboPwrCtrlMode.SelectedValue = "CLPC";
		UpdateComponentsAccordingToPwrCtrlMode();
		cboPwrIndexSource.SelectedIndex = 1;
		cbxControlSA_TxPkt.IsChecked = true;
		UpdateComponentsAccordingToPktPwrCtrlSA();
		cbxRxCtrlEquipment.IsChecked = true;
		txtSGPower.Text = "-60";
		cboRssiCfg.SelectedIndex = 2;
		UpdateCtrlSGAccordingToRSSICfg();
		cbx11bFrames.IsChecked = true;
		cbx11gnFrames.IsChecked = true;
		cbx11nFrames.IsChecked = true;
		cbx11acFrames.IsChecked = true;
		btStopTx.IsEnabled = false;
	}

	private void updateProductList()
	{
		lbxProductWlanInfo.Items.Clear();
		lbxProductWlanInfo.Items.Add("WLAN Chip: " + m_PCF.WLANConfiguraion.WCNchipID);
		lbxProductWlanInfo.Items.Add("Way To Launch Wlan app: " + wayToLaunchWlanApp);
		lbxProductWlanInfo.Items.Add("Baseband Type: " + baseBandType);
	}

	public void UpdateUIFromLoadedPCF()
	{
		if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null && m_PCF.WLANConfiguraion.WCN36xxConfig != null)
		{
			if (m_PCF.WLANConfiguraion.WCN36xxConfig.WayToLaunchProcess == WayToStartWlanAppEnum.ADB_COMMANDS.ToString())
			{
				wayToLaunchWlanApp = WayToStartWlanAppEnum.ADB_COMMANDS;
			}
			else if (m_PCF.WLANConfiguraion.WCN36xxConfig.WayToLaunchProcess == WayToStartWlanAppEnum.DIAG_FTM_AP_UTILITY.ToString())
			{
				wayToLaunchWlanApp = WayToStartWlanAppEnum.DIAG_FTM_AP_UTILITY;
			}
			if (m_PCF.WLANConfiguraion.WCN36xxConfig.BasebandType == BaseBandSupportedType.Pronto.ToString())
			{
				baseBandType = BaseBandSupportedType.Pronto;
			}
			else if (m_PCF.WLANConfiguraion.WCN36xxConfig.BasebandType == BaseBandSupportedType.Riva.ToString())
			{
				baseBandType = BaseBandSupportedType.Riva;
			}
			updateProductList();
			SetDefaultValue();
			loadPCFScenario();
			ChangeChainComboBox();
		}
	}

	private void updateCurrentTxScenarioUI()
	{
		if (m_CurTxScenario == null || m_CurTxScenario.txScenario == null)
		{
			return;
		}
		WCN36xx_TxScenario wCN36xx_TxScenario = m_CurTxScenario.txScenario.DeepCopy();
		string chanText = WCN36xxStatic.getChanText(wCN36xx_TxScenario.chan);
		WlanConst.SetSelectedItem(cboRFChannel, chanText);
		WlanConst.SetSelectedItem(cboTxPacketMode, wCN36xx_TxScenario.mode);
		RateEnumEntry rateInstance = WCN36xxStatic.getRateInstance(m_PCF.WLANConfiguraion.WCNchipID, baseBandType, wCN36xx_TxScenario.mode, wCN36xx_TxScenario.rate);
		WlanConst.SetSelectedItem(cboTxPacketRate, rateInstance);
		if (wCN36xx_TxScenario.power_ctrl_mode == "OpenLoop" || wCN36xx_TxScenario.power_ctrl_mode == "ClosedLoop")
		{
			cbClosedLoop.Visibility = Visibility.Visible;
			cboPwrCtrlMode.Visibility = Visibility.Collapsed;
			if (wCN36xx_TxScenario.power_ctrl_mode == "OpenLoop")
			{
				cbClosedLoop.IsChecked = false;
				spTxOpenLoopGain.Visibility = Visibility.Visible;
				spTargetPwr.Visibility = Visibility.Collapsed;
				txtRFGain.Text = wCN36xx_TxScenario.rfGain.ToString();
				txtDigitalGain.Text = wCN36xx_TxScenario.DigGain.ToString();
			}
			else if (wCN36xx_TxScenario.power_ctrl_mode == "ClosedLoop")
			{
				cbClosedLoop.IsChecked = true;
				spTxOpenLoopGain.Visibility = Visibility.Collapsed;
				spTargetPwr.Visibility = Visibility.Visible;
				txtTxPower.Text = wCN36xx_TxScenario.TargetPower.ToString();
			}
		}
		else
		{
			cbClosedLoop.Visibility = Visibility.Collapsed;
			cboPwrCtrlMode.Visibility = Visibility.Visible;
			cboPwrCtrlMode.SelectedItem = wCN36xx_TxScenario.power_ctrl_mode;
			if (wCN36xx_TxScenario.power_ctrl_mode == "OPEN LOOP")
			{
				spTxOpenLoopGain.Visibility = Visibility.Visible;
				spTargetPwr.Visibility = Visibility.Collapsed;
				txtRFGain.Text = wCN36xx_TxScenario.rfGain.ToString();
				txtDigitalGain.Text = wCN36xx_TxScenario.DigGain.ToString();
			}
			else
			{
				spTxOpenLoopGain.Visibility = Visibility.Collapsed;
				spTargetPwr.Visibility = Visibility.Visible;
				txtTxPower.Text = wCN36xx_TxScenario.TargetPower.ToString();
			}
		}
	}

	private void InitUserInterface()
	{
		DefaultVisibleSet();
		InitCboAntenna();
		InitCboTxPwrCtrlMode();
	}

	private void UpdateComponentsAccordingToPwrCtrlMode()
	{
		spTxOpenLoopGain.Visibility = Visibility.Visible;
		txtTxPower.Visibility = Visibility.Collapsed;
		lbTxPower.Visibility = Visibility.Collapsed;
		if (cbClosedLoop.Visibility == Visibility.Visible)
		{
			if (cbClosedLoop.IsChecked == true)
			{
				txtTxPower.Visibility = Visibility.Visible;
				lbTxPower.Visibility = Visibility.Visible;
				spTxOpenLoopGain.Visibility = Visibility.Collapsed;
			}
		}
		else if (cboPwrCtrlMode.Visibility == Visibility.Visible && cboPwrCtrlMode.SelectedValue != null && cboPwrCtrlMode.SelectedValue.ToString() != "OPEN LOOP")
		{
			txtTxPower.Visibility = Visibility.Visible;
			lbTxPower.Visibility = Visibility.Visible;
			spTxOpenLoopGain.Visibility = Visibility.Collapsed;
		}
	}

	private void UpdateComponentsAccordingToChain()
	{
		if (cboChainSelect.SelectedItem != null)
		{
			WLAN_Scenario wLAN_Scenario = (WLAN_Scenario)cboChainSelect.SelectedItem;
			if (wLAN_Scenario.strChain == "Receive Enabled" || wLAN_Scenario.strChain == "PHY_CHAIN_SEL_R0_ON" || wLAN_Scenario.strChain == "PHY_CHAIN_SEL_R0R1_ON" || wLAN_Scenario.strChain == "PHY_CHAIN_SEL_R1_ON")
			{
				spTx.Visibility = Visibility.Collapsed;
				sPanelTxScenario.Visibility = Visibility.Collapsed;
				sPanelPwrCtrl.Visibility = Visibility.Collapsed;
				spRx.Visibility = Visibility.Visible;
			}
			else if (wLAN_Scenario.strChain == "Transmit Enabled" || wLAN_Scenario.strChain == "PHY_CHAIN_SEL_T0_ON")
			{
				spTx.Visibility = Visibility.Visible;
				sPanelTxScenario.Visibility = Visibility.Visible;
				sPanelPwrCtrl.Visibility = Visibility.Visible;
				spRx.Visibility = Visibility.Collapsed;
			}
			else if (wLAN_Scenario.strChain == "PHY_CHAIN_SEL_T0_R1_ON")
			{
				spTx.Visibility = Visibility.Visible;
				sPanelTxScenario.Visibility = Visibility.Visible;
				sPanelPwrCtrl.Visibility = Visibility.Visible;
				spRx.Visibility = Visibility.Visible;
			}
		}
	}

	private void ConfigureChannelBonding()
	{
		cboChanBonding.Items.Clear();
		cboChanBonding.Items.Add("None");
		if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null)
		{
			if (m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3610/15/20")
			{
				cboChanBonding.Items.Add("40MHz BW Primary LOW");
				cboChanBonding.Items.Add("40MHz BW Primary HIGH");
			}
			else if (m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B")
			{
				cboChanBonding.Items.Add("40MHz BW Primary LOW");
				cboChanBonding.Items.Add("40MHz BW Primary CENTERED");
				cboChanBonding.Items.Add("40MHz BW Primary HIGH");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ LOW 40/80MHZ CENTERED");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ CENTERED 40/80MHZ CENTERED");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ CENTERED");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ LOW 40/80MHZ LOW");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ LOW");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ LOW 40/80MHZ HIGH");
				cboChanBonding.Items.Add("80MHz BW 20/40MHZ HIGH 40/80MHZ HIGH");
			}
		}
	}

	private void LoadChannelList()
	{
		string text = null;
		if (cboRFChannel.SelectedItem != null)
		{
			text = (string)cboRFChannel.SelectedItem;
		}
		cboRFChannel.Items.Clear();
		cboRFChannel.Items.Add("NOT SET");
		int num = 0;
		if (cboChanBonding.SelectedValue != null && ChannelBondingDict.Keys.Contains(cboChanBonding.SelectedValue.ToString()))
		{
			num = ChannelBondingDict[cboChanBonding.SelectedValue.ToString()];
		}
		switch (num)
		{
		case 0:
			cboRFChannel.Items.Add("RF_CHAN_1(2412)");
			cboRFChannel.Items.Add("RF_CHAN_2(2417)");
			cboRFChannel.Items.Add("RF_CHAN_3(2422)");
			cboRFChannel.Items.Add("RF_CHAN_4(2427)");
			cboRFChannel.Items.Add("RF_CHAN_5(2432)");
			cboRFChannel.Items.Add("RF_CHAN_6(2437)");
			cboRFChannel.Items.Add("RF_CHAN_7(2442)");
			cboRFChannel.Items.Add("RF_CHAN_8(2447)");
			cboRFChannel.Items.Add("RF_CHAN_9(2452)");
			cboRFChannel.Items.Add("RF_CHAN_10(2457)");
			cboRFChannel.Items.Add("RF_CHAN_11(2462)");
			cboRFChannel.Items.Add("RF_CHAN_12(2467)");
			cboRFChannel.Items.Add("RF_CHAN_13(2472)");
			cboRFChannel.Items.Add("RF_CHAN_14(2484)");
			if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null && (m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B"))
			{
				cboRFChannel.Items.Add("RF_CHAN_36(5180)");
				cboRFChannel.Items.Add("RF_CHAN_40(5200)");
				cboRFChannel.Items.Add("RF_CHAN_44(5220)");
				cboRFChannel.Items.Add("RF_CHAN_48(5240)");
				cboRFChannel.Items.Add("RF_CHAN_52(5260)");
				cboRFChannel.Items.Add("RF_CHAN_56(5280)");
				cboRFChannel.Items.Add("RF_CHAN_60(5300)");
				cboRFChannel.Items.Add("RF_CHAN_64(5320)");
				cboRFChannel.Items.Add("RF_CHAN_100(5500)");
				cboRFChannel.Items.Add("RF_CHAN_104(5520)");
				cboRFChannel.Items.Add("RF_CHAN_108(5540)");
				cboRFChannel.Items.Add("RF_CHAN_112(5560)");
				cboRFChannel.Items.Add("RF_CHAN_116(5580)");
				cboRFChannel.Items.Add("RF_CHAN_120(5600)");
				cboRFChannel.Items.Add("RF_CHAN_124(5620)");
				cboRFChannel.Items.Add("RF_CHAN_128(5640)");
				cboRFChannel.Items.Add("RF_CHAN_132(5660)");
				cboRFChannel.Items.Add("RF_CHAN_136(5680)");
				cboRFChannel.Items.Add("RF_CHAN_140(5700)");
				cboRFChannel.Items.Add("RF_CHAN_144(5720)");
				cboRFChannel.Items.Add("RF_CHAN_149(5745)");
				cboRFChannel.Items.Add("RF_CHAN_153(5765)");
				cboRFChannel.Items.Add("RF_CHAN_157(5785)");
				cboRFChannel.Items.Add("RF_CHAN_161(5805)");
				cboRFChannel.Items.Add("RF_CHAN_165(5825)");
			}
			break;
		case 1:
		case 2:
		case 3:
			cboRFChannel.Items.Add("RF_CHAN_3(2422)");
			cboRFChannel.Items.Add("RF_CHAN_4(2427)");
			cboRFChannel.Items.Add("RF_CHAN_5(2432)");
			cboRFChannel.Items.Add("RF_CHAN_6(2437)");
			cboRFChannel.Items.Add("RF_CHAN_7(2442)");
			cboRFChannel.Items.Add("RF_CHAN_8(2447)");
			cboRFChannel.Items.Add("RF_CHAN_9(2452)");
			cboRFChannel.Items.Add("RF_CHAN_10(2457)");
			cboRFChannel.Items.Add("RF_CHAN_11(2462)");
			if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null && (m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B"))
			{
				cboRFChannel.Items.Add("RF_CHAN_38(5190)");
				cboRFChannel.Items.Add("RF_CHAN_42(5210)");
				cboRFChannel.Items.Add("RF_CHAN_46(5230)");
				cboRFChannel.Items.Add("RF_CHAN_50(5250)");
				cboRFChannel.Items.Add("RF_CHAN_54(5270)");
				cboRFChannel.Items.Add("RF_CHAN_58(5290)");
				cboRFChannel.Items.Add("RF_CHAN_62(5310)");
				cboRFChannel.Items.Add("RF_CHAN_102(5510)");
				cboRFChannel.Items.Add("RF_CHAN_106(5530)");
				cboRFChannel.Items.Add("RF_CHAN_110(5550)");
				cboRFChannel.Items.Add("RF_CHAN_114(5570)");
				cboRFChannel.Items.Add("RF_CHAN_118(5590)");
				cboRFChannel.Items.Add("RF_CHAN_122(5610)");
				cboRFChannel.Items.Add("RF_CHAN_126(5630)");
				cboRFChannel.Items.Add("RF_CHAN_130(5650)");
				cboRFChannel.Items.Add("RF_CHAN_134(5670)");
				cboRFChannel.Items.Add("RF_CHAN_138(5690)");
				cboRFChannel.Items.Add("RF_CHAN_142(5710)");
				cboRFChannel.Items.Add("RF_CHAN_151(5755)");
				cboRFChannel.Items.Add("RF_CHAN_155(5775)");
				cboRFChannel.Items.Add("RF_CHAN_159(5795)");
				cboRFChannel.Items.Add("RF_CHAN_163(5815)");
			}
			break;
		default:
			if (num >= 4 && num <= 10 && m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null && (m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B"))
			{
				cboRFChannel.Items.Add("RF_CHAN_42(5210)");
				cboRFChannel.Items.Add("RF_CHAN_46(5230)");
				cboRFChannel.Items.Add("RF_CHAN_50(5250)");
				cboRFChannel.Items.Add("RF_CHAN_54(5270)");
				cboRFChannel.Items.Add("RF_CHAN_58(5290)");
				cboRFChannel.Items.Add("RF_CHAN_106(5530)");
				cboRFChannel.Items.Add("RF_CHAN_110(5550)");
				cboRFChannel.Items.Add("RF_CHAN_114(5570)");
				cboRFChannel.Items.Add("RF_CHAN_118(5590)");
				cboRFChannel.Items.Add("RF_CHAN_122(5610)");
				cboRFChannel.Items.Add("RF_CHAN_126(5630)");
				cboRFChannel.Items.Add("RF_CHAN_130(5650)");
				cboRFChannel.Items.Add("RF_CHAN_134(5670)");
				cboRFChannel.Items.Add("RF_CHAN_138(5690)");
				cboRFChannel.Items.Add("RF_CHAN_155(5775)");
				cboRFChannel.Items.Add("RF_CHAN_159(5795)");
			}
			break;
		}
		if (cboRFChannel.Items.Contains(text))
		{
			cboRFChannel.SelectedItem = text;
		}
	}

	private void updateRxComponents()
	{
		lblRssiCfg.Visibility = Visibility.Visible;
		cboRssiCfg.Visibility = Visibility.Visible;
		cbx11acFrames.Visibility = Visibility.Collapsed;
		lblRssi1.Visibility = Visibility.Collapsed;
		txtRssi1.Visibility = Visibility.Collapsed;
		int intValueOfWlanID = getIntValueOfWlanID();
		if (intValueOfWlanID == 3680)
		{
			cbx11acFrames.Visibility = Visibility.Visible;
		}
		if (intValueOfWlanID == 1312 || intValueOfWlanID == 1314)
		{
			lblRssiCfg.Visibility = Visibility.Collapsed;
			cboRssiCfg.Visibility = Visibility.Collapsed;
			if (intValueOfWlanID == 1312)
			{
				lblRssi1.Visibility = Visibility.Visible;
				txtRssi1.Visibility = Visibility.Visible;
			}
		}
	}

	private void loadPCFScenario()
	{
		if (m_PCF == null || m_PCF.WLANConfiguraion == null || m_PCF.WLANConfiguraion.WCNchipID == null || m_PCF.WLANConfiguraion.WCN36xxConfig == null || m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList == null || m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario == null || m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario.Length <= 0)
		{
			return;
		}
		List<WLAN_Scenario> list = new List<WLAN_Scenario>();
		foreach (WLAN_Scenario scenario in scenarioList)
		{
			list.Add(scenario.DeepCopy());
		}
		scenarioList = new List<WLAN_Scenario>();
		for (int i = 0; i < m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario.Length; i++)
		{
			WLAN_Scenario wLAN_Scenario = new WLAN_Scenario();
			if (m_PCF.WLANConfiguraion.WCNchipID == "WCN1314" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3610/15/20" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B")
			{
				wLAN_Scenario.strChain = "Transmit Enabled";
			}
			else
			{
				wLAN_Scenario.strChain = "PHY_CHAIN_SEL_T0_ON";
			}
			wLAN_Scenario.txScenario = m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario[i].DeepCopy();
			wLAN_Scenario.strScenarioDesc = "Tx_" + wLAN_Scenario.txScenario.scenarioDesc;
			scenarioList.Add(wLAN_Scenario);
		}
		foreach (WLAN_Scenario item in list)
		{
			if (!(item.strChain == "Transmit Enabled") && !(item.strChain == "PHY_CHAIN_SEL_T0_ON"))
			{
				scenarioList.Add(item.DeepCopy());
			}
		}
	}

	private void initScenarioListAccordingToWlanID()
	{
		scenarioList = new List<WLAN_Scenario>();
		if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null)
		{
			if (m_PCF.WLANConfiguraion.WCNchipID == "WCN1314" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3610/15/20" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B")
			{
				scenarioList.Add(new WLAN_Scenario("Transmit Enabled", "Tx"));
				scenarioList.Add(new WLAN_Scenario("Receive Enabled", "Rx"));
				return;
			}
			scenarioList.Add(new WLAN_Scenario("PHY_CHAIN_SEL_T0_ON", "Tx"));
			scenarioList.Add(new WLAN_Scenario("PHY_CHAIN_SEL_R0_ON", "PHY_CHAIN_SEL_R0_ON"));
			scenarioList.Add(new WLAN_Scenario("PHY_CHAIN_SEL_R0R1_ON", "PHY_CHAIN_SEL_R0R1_ON"));
			scenarioList.Add(new WLAN_Scenario("PHY_CHAIN_SEL_R1_ON", "PHY_CHAIN_SEL_R1_ON"));
		}
	}

	private void ChangeChainComboBox()
	{
		bool flag = false;
		WLAN_Scenario selectedScenario = null;
		if (cboChainSelect.SelectedItem != null)
		{
			flag = true;
			selectedScenario = (WLAN_Scenario)cboChainSelect.SelectedItem;
		}
		cboChainSelect.Items.Clear();
		foreach (WLAN_Scenario scenario in scenarioList)
		{
			cboChainSelect.Items.Add(scenario);
		}
		if (!flag || !SetSelectedScenario(selectedScenario))
		{
			cboChainSelect.SelectedIndex = 0;
		}
	}

	private bool SetSelectedScenario(WLAN_Scenario scenarioItem)
	{
		bool result = false;
		foreach (WLAN_Scenario item in (IEnumerable)cboChainSelect.Items)
		{
			if (item.IsEqual(scenarioItem))
			{
				cboChainSelect.SelectedItem = item;
				result = true;
				break;
			}
		}
		return result;
	}

	private void UpdateComponentsAccordingToWlanID()
	{
		ConfigureChannelBonding();
		LoadChannelList();
		updateTxPacketMode();
		updateRxComponents();
		cbClosedLoop.Visibility = Visibility.Visible;
		cboPwrCtrlMode.Visibility = Visibility.Collapsed;
		initScenarioListAccordingToWlanID();
		ChangeChainComboBox();
		if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null)
		{
			if (m_PCF.WLANConfiguraion.WCNchipID == "WCN1314")
			{
				cbClosedLoop.Visibility = Visibility.Visible;
				cboPwrCtrlMode.Visibility = Visibility.Collapsed;
			}
			else if (m_PCF.WLANConfiguraion.WCNchipID == "WCN3610/15/20" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3660/A/B" || m_PCF.WLANConfiguraion.WCNchipID == "WCN3680/B")
			{
				cbClosedLoop.Visibility = Visibility.Collapsed;
				cboPwrCtrlMode.Visibility = Visibility.Visible;
			}
			else
			{
				cbClosedLoop.Visibility = Visibility.Visible;
				cboPwrCtrlMode.Visibility = Visibility.Collapsed;
			}
		}
		UpdateComponentsAccordingToPwrCtrlMode();
		updateTxPktGainCombos();
	}

	private int? getIntValueOfChanBondingState()
	{
		int? result = null;
		if (bHideMostOfComponentMode)
		{
			result = 0;
		}
		else if (cboChanBonding.SelectedValue != null && ChannelBondingDict.Keys.Contains(cboChanBonding.SelectedValue.ToString()))
		{
			result = ChannelBondingDict[cboChanBonding.SelectedValue.ToString()];
		}
		return result;
	}

	private string getStringValueOfTxMode()
	{
		retTypeOfComboBox<string> comboBoxItem = GetComboBoxItem<string>(cboTxPacketMode);
		string result = null;
		if (!comboBoxItem.bNull && comboBoxItem.value != null)
		{
			result = comboBoxItem.value;
		}
		return result;
	}

	private uint? getUintValueOfTxRate()
	{
		retTypeOfComboBox<RateEnumEntry> comboBoxItem = GetComboBoxItem<RateEnumEntry>(cboTxPacketRate);
		uint? result = null;
		if (!comboBoxItem.bNull && comboBoxItem.value != null)
		{
			RateEnumEntry value = comboBoxItem.value;
			switch (getIntValueOfWlanID())
			{
			case 1312:
			case 1314:
				result = (uint)value.wcn131xEnum;
				break;
			case 3620:
			case 3660:
				result = (uint)value.wcn3660Enum;
				break;
			case 3680:
				result = (uint)value.wcn3680Enum;
				break;
			}
		}
		return result;
	}

	private double? getDoubleValueOfTargetPwr()
	{
		retTypeOfComboBox<double> textBoxValue_double = GetTextBoxValue_double(txtTxPower);
		double? result = null;
		if (!textBoxValue_double.bNull)
		{
			result = textBoxValue_double.value;
		}
		return result;
	}

	private uint? getUintValueOfRFGain()
	{
		retTypeOfComboBox<int> textBoxValue_int = GetTextBoxValue_int(txtRFGain);
		uint? result = null;
		if (!textBoxValue_int.bNull)
		{
			result = (uint)textBoxValue_int.value;
		}
		return result;
	}

	private int? getIntValueOfDigGain()
	{
		retTypeOfComboBox<int> textBoxValue_int = GetTextBoxValue_int(txtDigitalGain);
		int? result = null;
		if (!textBoxValue_int.bNull)
		{
			result = textBoxValue_int.value;
		}
		return result;
	}

	public byte? getByteValueOfPayloadType()
	{
		byte? result = null;
		if (bHideMostOfComponentMode)
		{
			result = 2;
		}
		else if (cboPayloadType.SelectedItem != null)
		{
			result = cboPayloadType.SelectedIndex switch
			{
				0 => 0, 
				1 => 1, 
				2 => 2, 
				3 => 3, 
				_ => 2, 
			};
		}
		return result;
	}

	private wlan_TxPowerCtrlClass getTxPwrCtrlParams()
	{
		wlan_TxPowerCtrlClass wlan_TxPowerCtrlClass2 = new wlan_TxPowerCtrlClass();
		if (GetComponentVisibility(cbClosedLoop) == Visibility.Visible)
		{
			wlan_TxPowerCtrlClass2.bMultiCtrlModeSelection = false;
			if (GetCheckBoxStatus(cbClosedLoop))
			{
				wlan_TxPowerCtrlClass2.bClosedloop = true;
			}
		}
		else if (GetComponentVisibility(cboPwrCtrlMode) == Visibility.Visible)
		{
			wlan_TxPowerCtrlClass2.bMultiCtrlModeSelection = true;
			retTypeOfComboBox<string> comboBoxItem = GetComboBoxItem<string>(cboPwrCtrlMode);
			if (!comboBoxItem.bNull && comboBoxItem.value != null)
			{
				wlan_TxPowerCtrlClass2.sPwrCtrlSelection = comboBoxItem.value;
			}
			if (bHideMostOfComponentMode)
			{
				wlan_TxPowerCtrlClass2.sPwrIndexSource = "Fixed";
			}
			else if (cboPwrIndexSource.SelectedValue != null)
			{
				if (cboPwrIndexSource.SelectedIndex == 0)
				{
					wlan_TxPowerCtrlClass2.sPwrIndexSource = "Regulatory";
				}
				else if (cboPwrIndexSource.SelectedIndex == 1)
				{
					wlan_TxPowerCtrlClass2.sPwrIndexSource = "Fixed";
				}
			}
		}
		return wlan_TxPowerCtrlClass2;
	}

	private void getInfoOfChan(ref uint? channel, ref string chanDesc)
	{
		retTypeOfComboBox<string> comboBoxItem = GetComboBoxItem<string>(cboRFChannel);
		if (!comboBoxItem.bNull && comboBoxItem.value != null && WCN36xxStatic.ChannelDict.Keys.Contains(comboBoxItem.value.ToString()))
		{
			chanDesc = comboBoxItem.value.ToString();
			channel = WCN36xxStatic.ChannelDict[chanDesc];
		}
	}

	private uint? getUintValueOfAntenna()
	{
		uint? result = null;
		if (bHideMostOfComponentMode)
		{
			result = 0u;
		}
		else if (cboAntennaSelect.SelectedValue != null)
		{
			result = (uint)cboAntennaSelect.SelectedValue;
		}
		return result;
	}

	private uint? getUintValueOfChain()
	{
		retTypeOfComboBox<WLAN_Scenario> comboBoxItem = GetComboBoxItem<WLAN_Scenario>(cboChainSelect);
		uint? result = null;
		if (!comboBoxItem.bNull && comboBoxItem.value != null)
		{
			WLAN_Scenario value = comboBoxItem.value;
			if (ChainDict.Keys.Contains(value.strChain))
			{
				result = ChainDict[value.strChain];
			}
		}
		return result;
	}

	private int getIntValueOfWlanID()
	{
		int result = 0;
		if (m_PCF != null && m_PCF.WLANConfiguraion != null && m_PCF.WLANConfiguraion.WCNchipID != null && WCN36xxStatic.wlanIDDict.Keys.Contains(m_PCF.WLANConfiguraion.WCNchipID))
		{
			result = WCN36xxStatic.wlanIDDict[m_PCF.WLANConfiguraion.WCNchipID];
		}
		return result;
	}

	private void setRateComboBoxContents()
	{
		bool flag = false;
		bool flag2 = false;
		RateEnumEntry rateEnumEntry = new RateEnumEntry(null, 0, 0, 0, 0, BaseBandSupportedType.Both, null);
		if (cboTxPacketRate.SelectedItem != null)
		{
			flag = true;
			rateEnumEntry.mode = ((RateEnumEntry)cboTxPacketRate.SelectedItem).mode;
			rateEnumEntry.comboString = ((RateEnumEntry)cboTxPacketRate.SelectedItem).comboString;
			rateEnumEntry.bandWidth = ((RateEnumEntry)cboTxPacketRate.SelectedItem).bandWidth;
			rateEnumEntry.wcn131xEnum = ((RateEnumEntry)cboTxPacketRate.SelectedItem).wcn131xEnum;
			rateEnumEntry.wcn3660Enum = ((RateEnumEntry)cboTxPacketRate.SelectedItem).wcn3660Enum;
			rateEnumEntry.wcn3680Enum = ((RateEnumEntry)cboTxPacketRate.SelectedItem).wcn3680Enum;
			rateEnumEntry.type = ((RateEnumEntry)cboTxPacketRate.SelectedItem).type;
		}
		cboTxPacketRate.Items.Clear();
		int num = getIntValueOfWlanID();
		switch (num)
		{
		case 1312:
			num = 1314;
			break;
		case 3620:
			num = 3660;
			break;
		}
		int num2 = 0;
		if (cboChanBonding.SelectedValue != null && ChannelBondingDict.Keys.Contains(cboChanBonding.SelectedValue.ToString()))
		{
			num2 = ChannelBondingDict[cboChanBonding.SelectedValue.ToString()];
		}
		int num3 = 20;
		if (num2 >= 1 && num2 <= 3)
		{
			num3 = 40;
		}
		else if (num2 >= 4 && num2 <= 10)
		{
			num3 = 80;
		}
		string text = "";
		if (cboTxPacketMode.SelectedValue != null)
		{
			text = cboTxPacketMode.SelectedValue.ToString();
		}
		foreach (RateEnumEntry item in WCN36xxStatic.rateTable)
		{
			if (item.bandWidth > num3 || !(item.mode == text) || (item.type != baseBandType && item.type != BaseBandSupportedType.Both))
			{
				continue;
			}
			int num4 = 0;
			switch (num)
			{
			case 1312:
			case 1314:
				num4 = item.wcn131xEnum;
				break;
			case 3660:
				num4 = item.wcn3660Enum;
				break;
			case 3680:
				num4 = item.wcn3680Enum;
				break;
			}
			if (num4 >= 0)
			{
				cboTxPacketRate.Items.Add(item);
				if (flag && item.mode == rateEnumEntry.mode && item.comboString == rateEnumEntry.comboString && item.bandWidth == rateEnumEntry.bandWidth && item.wcn131xEnum == rateEnumEntry.wcn131xEnum && item.wcn3660Enum == rateEnumEntry.wcn3660Enum && item.wcn3680Enum == rateEnumEntry.wcn3680Enum && item.type == rateEnumEntry.type)
				{
					flag2 = true;
					cboTxPacketRate.SelectedItem = item;
				}
			}
		}
		if (!flag2)
		{
			cboTxPacketRate.SelectedIndex = 0;
		}
		if ((num == 3660 || num == 3680) && baseBandType == BaseBandSupportedType.Pronto && (text == "11n" || text == "11ac"))
		{
			cbLdpcRateEnable.Visibility = Visibility.Visible;
		}
		else
		{
			cbLdpcRateEnable.Visibility = Visibility.Collapsed;
		}
	}

	private void updateTxPacketMode()
	{
		string text = null;
		if (cboTxPacketMode.SelectedItem != null)
		{
			text = (string)cboTxPacketMode.SelectedItem;
		}
		cboTxPacketMode.Items.Clear();
		switch (getIntValueOfWlanID())
		{
		case 3620:
		case 3660:
			if (!WCN36xxStatic.Is5GChannelSelected(cboRFChannel))
			{
				cboTxPacketMode.Items.Add("11b");
			}
			cboTxPacketMode.Items.Add("11a/g");
			cboTxPacketMode.Items.Add("11n");
			break;
		case 3680:
			if (!WCN36xxStatic.Is5GChannelSelected(cboRFChannel))
			{
				cboTxPacketMode.Items.Add("11b");
			}
			cboTxPacketMode.Items.Add("11a/g");
			cboTxPacketMode.Items.Add("11n");
			cboTxPacketMode.Items.Add("11ac");
			break;
		default:
			if (!WCN36xxStatic.Is5GChannelSelected(cboRFChannel))
			{
				cboTxPacketMode.Items.Add("11b");
			}
			cboTxPacketMode.Items.Add("11a/g");
			cboTxPacketMode.Items.Add("11n");
			break;
		}
		if (cboTxPacketMode.Items.Contains(text))
		{
			cboTxPacketMode.SelectedItem = text;
		}
		else
		{
			cboTxPacketMode.SelectedValue = "11a/g";
		}
		setRateComboBoxContents();
		UpdateRates();
	}

	private void updateTxPktGainCombos()
	{
		txtDigitalGain.Text = "";
		txtRFGain.Text = "";
		switch (getIntValueOfWlanID())
		{
		case 3620:
		case 3660:
		case 3680:
			txtDigitalGain.Text = "0";
			txtRFGain.Text = "0";
			break;
		case 1314:
			txtDigitalGain.Text = "12";
			txtRFGain.Text = "5";
			break;
		case 1312:
			txtDigitalGain.Text = "0";
			txtRFGain.Text = "0";
			break;
		}
	}

	private void UpdateComponentsAccordingToPktPwrCtrlSA()
	{
		lblTxPktPwr.Visibility = Visibility.Collapsed;
		txtTxPktPwr.Visibility = Visibility.Collapsed;
		if (cbxControlSA_TxPkt.IsChecked == true)
		{
			lblTxPktPwr.Visibility = Visibility.Visible;
			txtTxPktPwr.Visibility = Visibility.Visible;
		}
	}

	private void UpdateCtrlSGAccordingToRSSICfg()
	{
		cbxRxCtrlEquipment.Visibility = Visibility.Collapsed;
		txtSGPower.Visibility = Visibility.Collapsed;
		if (cboRssiCfg.SelectedIndex == 2)
		{
			cbxRxCtrlEquipment.Visibility = Visibility.Visible;
			txtSGPower.Visibility = Visibility.Visible;
		}
	}

	private void cbCtrlSA_PktPwr_Checked(object sender, RoutedEventArgs e)
	{
		UpdateComponentsAccordingToPktPwrCtrlSA();
	}

	private void cbClosedLoop_Checked(object sender, RoutedEventArgs e)
	{
		UpdateComponentsAccordingToPwrCtrlMode();
	}

	private void cboPwtCtrlMode_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		UpdateComponentsAccordingToPwrCtrlMode();
	}

	private WCN36xx_TxScenario getTxScenarioObjFromUI()
	{
		WCN36xx_TxScenario curScenario = new WCN36xx_TxScenario();
		if (cboRFChannel.SelectedItem != null && WCN36xxStatic.ChannelDict.Keys.Contains(cboRFChannel.SelectedItem.ToString()))
		{
			curScenario.chan = WCN36xxStatic.ChannelDict[cboRFChannel.SelectedItem.ToString()];
		}
		if (cboTxPacketMode.SelectedItem != null)
		{
			curScenario.mode = cboTxPacketMode.SelectedItem.ToString();
		}
		if (cboTxPacketRate.SelectedItem != null)
		{
			curScenario.rate = cboTxPacketRate.SelectedItem.ToString();
		}
		double result;
		int result2;
		if (cbClosedLoop.Visibility == Visibility.Visible)
		{
			if (cbClosedLoop.IsChecked == true)
			{
				curScenario.power_ctrl_mode = "ClosedLoop";
				if (double.TryParse(txtTxPower.Text, out result))
				{
					curScenario.TargetPower = result;
				}
			}
			else
			{
				curScenario.power_ctrl_mode = "OpenLoop";
				if (int.TryParse(txtRFGain.Text, out result2))
				{
					curScenario.rfGain = result2;
				}
				if (int.TryParse(txtDigitalGain.Text, out result2))
				{
					curScenario.DigGain = result2;
				}
			}
		}
		else if (cboPwrCtrlMode.Visibility == Visibility.Visible)
		{
			if (cboPwrCtrlMode.SelectedItem != null)
			{
				curScenario.power_ctrl_mode = cboPwrCtrlMode.SelectedItem.ToString();
			}
			if (curScenario.power_ctrl_mode == "OPEN LOOP")
			{
				if (int.TryParse(txtRFGain.Text, out result2))
				{
					curScenario.rfGain = result2;
				}
				if (int.TryParse(txtDigitalGain.Text, out result2))
				{
					curScenario.DigGain = result2;
				}
			}
			else if (double.TryParse(txtTxPower.Text, out result))
			{
				curScenario.TargetPower = result;
			}
		}
		WCN36xxStatic.genWCN36xxScenarioName(ref curScenario);
		return curScenario;
	}

	private void AddCurTxScenarioToList()
	{
		WCN36xx_TxScenario txScenarioObjFromUI = getTxScenarioObjFromUI();
		if (m_PCF == null || m_PCF.WLANConfiguraion == null || m_PCF.WLANConfiguraion.WCN36xxConfig == null)
		{
			return;
		}
		List<WCN36xx_TxScenario> list = new List<WCN36xx_TxScenario>();
		if (m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList == null)
		{
			m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList = new WCN36xx_TxScenarioList();
		}
		else if (m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario != null)
		{
			for (int i = 0; i < m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario.Length; i++)
			{
				list.Add(m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario[i]);
			}
		}
		if (WlanConst.CheckExist(list, txScenarioObjFromUI))
		{
			return;
		}
		list.Add(txScenarioObjFromUI);
		m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario = new WCN36xx_TxScenario[list.Count];
		for (int j = 0; j < list.Count; j++)
		{
			m_PCF.WLANConfiguraion.WCN36xxConfig.ScenarioList.Scenario[j] = list[j].DeepCopy();
		}
		loadPCFScenario();
		ChangeChainComboBox();
		foreach (WLAN_Scenario scenario in scenarioList)
		{
			if (scenario.txScenario != null && scenario.txScenario.IsEqual(txScenarioObjFromUI))
			{
				SetSelectedScenario(scenario);
				break;
			}
		}
		XmlSerializer xmlSerializer = new XmlSerializer(typeof(PCF));
		XmlWriter xmlWriter = XmlWriter.Create(m_PCFPath, new XmlWriterSettings
		{
			Indent = true
		});
		xmlSerializer.Serialize(xmlWriter, m_PCF);
		xmlWriter.Close();
	}

	private void btAddCurTxScenarioToList_Click(object sender, RoutedEventArgs e)
	{
		AddCurTxScenarioToList();
	}

	private void cboChainSelect_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		UpdateComponentsAccordingToChain();
		if (cboChainSelect.SelectedItem != null)
		{
			WLAN_Scenario wLAN_Scenario = (WLAN_Scenario)cboChainSelect.SelectedItem;
			if (wLAN_Scenario.strChain == "Transmit Enabled" || wLAN_Scenario.strChain == "PHY_CHAIN_SEL_T0_ON")
			{
				m_CurTxScenario = wLAN_Scenario.DeepCopy();
				updateCurrentTxScenarioUI();
				m_ChainOrientation = ChainOriention.Tx;
			}
			else
			{
				m_ChainOrientation = ChainOriention.Rx;
			}
		}
	}

	private void cboChanBonding_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		LoadChannelList();
		setRateComboBoxContents();
	}

	private void cboTxPacketMode_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		setRateComboBoxContents();
	}

	private void cboRFChannel_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		updateTxPacketMode();
	}

	private void cboTxPacketRate_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		UpdateRates();
	}

	private void cboRSSIconfig_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		UpdateCtrlSGAccordingToRSSICfg();
	}

	private void btRunWlanApp_Click(object sender, RoutedEventArgs e)
	{
		SetRunWlanAppButtonEnable(bEnable: false);
		thread_adb = new Thread(runStartWlanApp);
		thread_adb.Name = "Start ptt_socket_app";
		thread_adb.Start();
	}

	private void btTxPacketStop_Click(object sender, RoutedEventArgs e)
	{
		m_bContinueFlag = false;
	}

	private void btStopGetRssi_Click(object sender, RoutedEventArgs e)
	{
		m_bContinueFlag = false;
	}

	private void btGetRssi_Click(object sender, RoutedEventArgs e)
	{
		SetbtGetRssiEnable(bEnable: false);
		SetbtStopGetRssiEnable(bEnable: true);
		SetRssi0Result("");
		SetRssi1Result("");
		getAllParamsFromUI();
		m_bContinueFlag = true;
		thread = new Thread(runGetRssi);
		thread.Name = "Rx Get RSSI";
		thread.Start();
	}

	private void btTxPacketStart_Click(object sender, RoutedEventArgs e)
	{
		SetTxPktStartButtonEnable(bEnable: false);
		SetTxPktStopButtonEnable(bEnable: true);
		getAllParamsFromUI();
		m_bContinueFlag = true;
		thread = new Thread(runTxPacketStart);
		thread.Name = "Tx Packet Start";
		thread.Start();
	}

	public void SetRssi0Result(string content)
	{
		if (txtRssi0.Dispatcher.CheckAccess())
		{
			txtRssi0.Text = content;
			return;
		}
		SetTextBoxCotentCB method = SetRssi0Result;
		base.Dispatcher.BeginInvoke(method, content);
	}

	public void SetRssi1Result(string content)
	{
		if (txtRssi1.Dispatcher.CheckAccess())
		{
			txtRssi1.Text = content;
			return;
		}
		SetTextBoxCotentCB method = SetRssi1Result;
		base.Dispatcher.BeginInvoke(method, content);
	}

	public void SetPktPowetResult(string content)
	{
		if (txtTxPktPwr.Dispatcher.CheckAccess())
		{
			txtTxPktPwr.Text = content;
			return;
		}
		SetTextBoxCotentCB method = SetPktPowetResult;
		base.Dispatcher.BeginInvoke(method, content);
	}

	public void SetbtStopGetRssiEnable(bool bEnable)
	{
		if (btStopGetRssi.Dispatcher.CheckAccess())
		{
			btStopGetRssi.IsEnabled = bEnable;
			btStopGetRssi.Visibility = ((!bEnable) ? Visibility.Collapsed : Visibility.Visible);
		}
		else
		{
			SetButtonEnableCB method = SetbtStopGetRssiEnable;
			base.Dispatcher.BeginInvoke(method, bEnable);
		}
	}

	public void SetbtGetRssiEnable(bool bEnable)
	{
		if (btGetRssi.Dispatcher.CheckAccess())
		{
			btGetRssi.IsEnabled = bEnable;
			btGetRssi.Visibility = ((!bEnable) ? Visibility.Collapsed : Visibility.Visible);
		}
		else
		{
			SetButtonEnableCB method = SetbtGetRssiEnable;
			base.Dispatcher.BeginInvoke(method, bEnable);
		}
	}

	public void SetRunWlanAppButtonEnable(bool bEnable)
	{
		if (btRunWlanApp.Dispatcher.CheckAccess())
		{
			btRunWlanApp.IsEnabled = bEnable;
			return;
		}
		SetButtonEnableCB method = SetRunWlanAppButtonEnable;
		base.Dispatcher.BeginInvoke(method, bEnable);
	}

	public void SetTxPktStartButtonEnable(bool bEnable)
	{
		if (btStartTx.Dispatcher.CheckAccess())
		{
			btStartTx.IsEnabled = bEnable;
			btStartTx.Visibility = ((!bEnable) ? Visibility.Collapsed : Visibility.Visible);
		}
		else
		{
			SetButtonEnableCB method = SetTxPktStartButtonEnable;
			base.Dispatcher.BeginInvoke(method, bEnable);
		}
	}

	public void SetTxPktStopButtonEnable(bool bEnable)
	{
		if (btStopTx.Dispatcher.CheckAccess())
		{
			btStopTx.IsEnabled = bEnable;
			btStopTx.Visibility = ((!bEnable) ? Visibility.Collapsed : Visibility.Visible);
		}
		else
		{
			SetButtonEnableCB method = SetTxPktStopButtonEnable;
			base.Dispatcher.BeginInvoke(method, bEnable);
		}
	}

	private void SetLanguageDictionary()
	{
		ResourceDictionary resourceDictionary = new ResourceDictionary();
		string text = Thread.CurrentThread.CurrentCulture.ToString();
		try
		{
			resourceDictionary.Source = new Uri(Thread.GetDomain().BaseDirectory + "..\\Resources\\UI_" + text + ".xaml", UriKind.Absolute);
		}
		catch
		{
		}
		base.Resources.MergedDictionaries.Add(resourceDictionary);
	}

	public void SetLanguage(string culture)
	{
		ResourceDictionary resourceDictionary = new ResourceDictionary();
		try
		{
			resourceDictionary.Source = new Uri(Thread.GetDomain().BaseDirectory + "\\Resources\\UI_" + culture + ".xaml", UriKind.Absolute);
		}
		catch
		{
			resourceDictionary.Source = new Uri(Thread.GetDomain().BaseDirectory + "..\\Resources\\UI_en-US.xaml", UriKind.Absolute);
		}
		base.Resources.MergedDictionaries.Clear();
		base.Resources.MergedDictionaries.Add(resourceDictionary);
	}

	private double? getFrequencyMHz(string strChan)
	{
		double? result = null;
		if (strChan != null)
		{
			string pattern = "\\(\\d{3,5}\\)";
			MatchCollection matchCollection = Regex.Matches(strChan, pattern);
			if (matchCollection.Count > 0)
			{
				int length = matchCollection[0].Value.Length;
				string s = matchCollection[0].Value.Substring(1, length - 2);
				if (double.TryParse(s, out var result2))
				{
					result = result2;
				}
			}
		}
		return result;
	}

	private void getAllParamsFromUI()
	{
		cfgParams.Clear();
		cfgParams.wlanID = getIntValueOfWlanID();
		cfgParams.rfChanBondingState = getIntValueOfChanBondingState();
		uint? channel = null;
		string chanDesc = null;
		getInfoOfChan(ref channel, ref chanDesc);
		cfgParams.rfChannel = channel;
		cfgParams.strChannel = chanDesc;
		cfgParams.rfChain = getUintValueOfChain();
		cfgParams.rfAntenna = getUintValueOfAntenna();
		cfgParams.txPacket_Mode = getStringValueOfTxMode();
		cfgParams.txPacket_Rate = getUintValueOfTxRate();
		cfgParams.txPacket_PayloadType = getByteValueOfPayloadType();
		cfgParams.txPacket_Preamble = (uint)iPreamble;
		if (cbLdpcRateEnable.Visibility == Visibility.Visible && cbLdpcRateEnable.IsChecked == true)
		{
			cfgParams.txPacket_Preamble |= 16u;
		}
		uint result;
		if (bHideMostOfComponentMode)
		{
			cfgParams.txPacket_NumOfFrame = 0u;
		}
		else if (uint.TryParse(txtFrame.Text, out result))
		{
			cfgParams.txPacket_NumOfFrame = result;
		}
		if (bHideMostOfComponentMode)
		{
			cfgParams.txPacket_FrameSpacing = 200u;
		}
		else if (uint.TryParse(txtSpacing.Text, out result))
		{
			cfgParams.txPacket_FrameSpacing = result;
		}
		ushort result2;
		if (bHideMostOfComponentMode)
		{
			cfgParams.txPacket_PayloadSize = 1000;
		}
		else if (ushort.TryParse(txtPayloadSize.Text, out result2))
		{
			cfgParams.txPacket_PayloadSize = result2;
		}
		if (cbxFCSCalculated.IsChecked == true || bHideMostOfComponentMode)
		{
			cfgParams.txPacket_FCSCal = 1;
		}
		else
		{
			cfgParams.txPacket_FCSCal = 0;
		}
		cfgParams.txPacket_txPwr = getDoubleValueOfTargetPwr();
		cfgParams.txPacket_rfGain = getUintValueOfRFGain();
		cfgParams.txPacket_digGain = getIntValueOfDigGain();
		cfgParams.txPacket_pwrCtrlMode = getTxPwrCtrlParams();
		if (bHideMostOfComponentMode)
		{
			cfgParams.rx_RssiCfg = "Enabled CW";
		}
		else if (cboRssiCfg.Visibility == Visibility.Visible && cboRssiCfg.SelectedValue != null)
		{
			switch (cboRssiCfg.SelectedIndex)
			{
			case 0:
				cfgParams.rx_RssiCfg = "Normal";
				break;
			case 1:
				cfgParams.rx_RssiCfg = "Enable MAC Filtering";
				break;
			case 2:
				cfgParams.rx_RssiCfg = "Enabled CW";
				break;
			}
		}
		if (bHideMostOfComponentMode)
		{
			cfgParams.rxMask_11bFrames = true;
			cfgParams.rxMask_11gnFrames = true;
			cfgParams.rxMask_11nHT40Frames = true;
			cfgParams.rxMask_11acVHT80Frames = true;
		}
		else
		{
			if (cbx11bFrames.Visibility == Visibility.Visible)
			{
				cfgParams.rxMask_11bFrames = cbx11bFrames.IsChecked != false;
			}
			if (cbx11gnFrames.Visibility == Visibility.Visible)
			{
				cfgParams.rxMask_11gnFrames = cbx11gnFrames.IsChecked != false;
			}
			if (cbx11nFrames.Visibility == Visibility.Visible)
			{
				cfgParams.rxMask_11nHT40Frames = cbx11nFrames.IsChecked != false;
			}
			if (cbx11acFrames.Visibility == Visibility.Visible)
			{
				cfgParams.rxMask_11acVHT80Frames = cbx11acFrames.IsChecked != false;
			}
		}
		if (cbxControlSA_TxPkt.Visibility == Visibility.Visible)
		{
			cfgParams.txPacket_CtrlSA = GetCheckBoxStatus(cbxControlSA_TxPkt);
		}
		if (cbxRxCtrlEquipment.Visibility == Visibility.Visible)
		{
			cfgParams.rx_CtrlSG = cbxRxCtrlEquipment.IsChecked == true;
			if (cfgParams.rx_CtrlSG && double.TryParse(txtSGPower.Text, out var result3))
			{
				cfgParams.rx_SGPower = result3;
			}
		}
	}

	private void SetChannel()
	{
		if (!cfgParams.rfChannel.HasValue)
		{
			return;
		}
		uint channel = cfgParams.rfChannel.Value;
		uint state = 0u;
		if (cfgParams.wlanID.HasValue && (cfgParams.wlanID.Value == 3620 || cfgParams.wlanID.Value == 3660 || cfgParams.wlanID.Value == 3680) && cfgParams.rfChanBondingState.HasValue)
		{
			switch (cfgParams.rfChanBondingState.Value)
			{
			case 1:
				state = 1u;
				channel = cfgParams.rfChannel.Value - 2;
				break;
			case 2:
				state = 2u;
				break;
			case 3:
				state = 3u;
				channel = cfgParams.rfChannel.Value + 2;
				break;
			case 4:
				state = 4u;
				channel = cfgParams.rfChannel.Value - 2;
				break;
			case 5:
				state = 5u;
				break;
			case 6:
				state = 6u;
				channel = cfgParams.rfChannel.Value + 2;
				break;
			case 7:
				state = 7u;
				channel = cfgParams.rfChannel.Value - 6;
				break;
			case 8:
				state = 8u;
				channel = cfgParams.rfChannel.Value - 2;
				break;
			case 9:
				state = 9u;
				channel = cfgParams.rfChannel.Value + 2;
				break;
			case 10:
				state = 10u;
				channel = cfgParams.rfChannel.Value + 6;
				break;
			}
		}
		phone.FTM_WLAN_GEN6_SET_CHANNEL_V2(channel, (Phone.WLAN_Gen6_ChannelBondingState)state);
		DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_CHANNEL_V2 success");
	}

	private void enableChains()
	{
		if (cfgParams.rfChain.HasValue)
		{
			phone.FTM_WLAN_GEN6_ENABLE_CHAINS((Phone.WLAN_Gen6_PHY_ChainSelect)cfgParams.rfChain.Value);
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_ENABLE_CHAINS success");
		}
		if (cfgParams.rfAntenna.HasValue)
		{
			phone.FTM_WLAN_WCN_ANTENNA_SELECT(cfgParams.rfAntenna.Value);
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_WCN_ANTENNA_SELECT success");
		}
	}

	private void CommonCfgChainAndChannel()
	{
		SetChannel();
		enableChains();
	}

	private void setTxFrame(SetTxFrameVersion ver)
	{
		if (cfgParams.txPacket_NumOfFrame.HasValue && cfgParams.txPacket_Rate.HasValue && cfgParams.txPacket_Preamble.HasValue && cfgParams.txPacket_Mode != null && cfgParams.txPacket_PayloadSize.HasValue && cfgParams.txPacket_PayloadType.HasValue && cfgParams.txPacket_FrameSpacing.HasValue && cfgParams.txPacket_FCSCal.HasValue)
		{
			uint num = cfgParams.txPacket_NumOfFrame.Value;
			if (num > 65535)
			{
				num = 65535u;
			}
			byte iPayloadFillByte = 165;
			ushort num2 = cfgParams.txPacket_PayloadSize.Value;
			switch (cfgParams.txPacket_Mode)
			{
			case "11b":
			case "11g":
			case "11a/g":
			case "11n":
				if (num2 > 4091)
				{
					num2 = 4091;
				}
				break;
			case "11ac":
				if (num2 > 756)
				{
					num2 = 756;
				}
				break;
			}
			if (num2 < 1)
			{
				num2 = 1;
			}
			uint num3 = cfgParams.txPacket_FrameSpacing.Value;
			if (num3 > 209715)
			{
				num3 = 209715u;
			}
			else if (num3 < 10)
			{
				num3 = 10u;
			}
			if (ver == SetTxFrameVersion.V2)
			{
				phone.FTM_WLAN_GEN6_SET_TX_FRAME_V2(num, num2, cfgParams.txPacket_PayloadType.Value, iPayloadFillByte, num3, cfgParams.txPacket_FCSCal.Value, cfgParams.txPacket_Rate.Value, cfgParams.txPacket_Preamble.Value);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_TX_FRAME_V2 success");
			}
			else
			{
				phone.FTM_WLAN_GEN6_SET_TX_FRAME_ORIGIN_PARAMS(num, num2, num3, cfgParams.txPacket_FCSCal.Value, cfgParams.txPacket_Rate.Value, cfgParams.txPacket_Preamble.Value);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_TX_FRAME success");
			}
			return;
		}
		throw new Exception("Some of the Tx frame parameters are empty or incorrect!");
	}

	private void ConfigPower()
	{
		setTxPowerCtrolMode();
		if (cfgParams.txPacket_pwrCtrlMode.bMultiCtrlModeSelection == false)
		{
			if (cfgParams.txPacket_pwrCtrlMode.bClosedloop == false)
			{
				setForcedPktGain();
			}
			else if (cfgParams.txPacket_pwrCtrlMode.bClosedloop == true)
			{
				setTxClpcPower();
			}
			return;
		}
		bool? bMultiCtrlModeSelection = cfgParams.txPacket_pwrCtrlMode.bMultiCtrlModeSelection;
		if (bMultiCtrlModeSelection.GetValueOrDefault() && bMultiCtrlModeSelection.HasValue && cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection != null)
		{
			byte b = byte.MaxValue;
			if (WCN36xxStatic.PwrCtrlModeDict.Keys.Contains(cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection))
			{
				b = WCN36xxStatic.PwrCtrlModeDict[cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection];
			}
			switch (b)
			{
			case 0:
				setForcedPktGain();
				break;
			default:
				setTxClpcPower();
				break;
			case byte.MaxValue:
				break;
			}
		}
	}

	private void setTxClpcPower()
	{
		double powerDb = 16.0;
		if (cfgParams.txPacket_txPwr.HasValue)
		{
			powerDb = cfgParams.txPacket_txPwr.Value;
		}
		phone.FTM_WLAN_GEN6_SET_CLOSED_LOOP_POWER(powerDb);
		DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_CLOSED_LOOP_POWER success");
	}

	private void TxPacketStart()
	{
		if (cfgParams.wlanID.HasValue && (cfgParams.wlanID.Value == 3620 || cfgParams.wlanID.Value == 3680 || cfgParams.wlanID.Value == 3660) && cfgParams.txPacket_pwrCtrlMode.bMultiCtrlModeSelection == true)
		{
			setTxFrame(SetTxFrameVersion.V1);
			if (cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection == "CLPC" || cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection == "SCPC")
			{
				uint num = 0u;
				if (cfgParams.txPacket_pwrCtrlMode.sPwrIndexSource == "Regulatory")
				{
					num = 3u;
				}
				else if (cfgParams.txPacket_pwrCtrlMode.sPwrIndexSource == "Fixed")
				{
					num = 2u;
				}
				if (num != 0)
				{
					phone.FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE(num);
					DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE success");
				}
			}
			else if (cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection == "AUTO" || cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection == "AUTO-SAR")
			{
				phone.FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE(3u);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE success");
			}
		}
		TxPktGenOnOff(bOn: true);
	}

	private void TxPktGenOnOff(bool bOn)
	{
		phone.FTM_WLAN_GEN6_TX_PKT_START_STOP(bOn);
		DebugMessageCB(MessageLevel.SUCCESS, string.Format("QLIB_FTM_WLAN_GEN6_TX_PKT_START_STOP({0}) success", bOn ? "1" : "0"));
	}

	private void startWlanApp_ADB()
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		dictionary.Add("adb root", "adb root");
		dictionary.Add("adb shell pkill ptt_socket_app", "kill old app");
		dictionary.Add("adb shell ptt_socket_app -v -d -f", "wlan App launched");
		string[] array = new string[3] { "adb root", "adb shell pkill ptt_socket_app", "adb shell ptt_socket_app -v -d -f" };
		for (int i = 0; i < array.Length; i++)
		{
			_ = dictionary[array[i]];
			Process process = new Process();
			char[] separator = new char[1] { ' ' };
			process.StartInfo.FileName = array[i].Split(separator)[0];
			string text = "";
			for (int j = 1; j < array[i].Split(separator).Length; j++)
			{
				text = text + array[i].Split(separator)[j] + " ";
			}
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.UseShellExecute = false;
			process.StartInfo.Arguments = text;
			process.StartInfo.CreateNoWindow = true;
			DebugMessageCB(MessageLevel.SUCCESS, "Send Command: " + array[i]);
			process.Start();
			Thread.Sleep(2000);
			string text2 = process.StandardOutput.ReadToEnd();
			if (text2 != null)
			{
				DebugMessageCB(MessageLevel.SUCCESS, "return: " + text2);
			}
			process.WaitForExit();
			if (array[i] == "adb shell ptt_socket_app -v -d -f")
			{
				SetRunWlanAppButtonEnable(bEnable: true);
			}
			Thread.Sleep(2000);
		}
	}

	private void runStartWlanApp()
	{
		if (phone != null)
		{
			try
			{
				if (wayToLaunchWlanApp == WayToStartWlanAppEnum.ADB_COMMANDS)
				{
					startWlanApp_ADB();
				}
				else if (wayToLaunchWlanApp == WayToStartWlanAppEnum.DIAG_FTM_AP_UTILITY)
				{
					WlanConst.SendDebugMessage funcCB = DebugMessageCB.Invoke;
					WlanConst.startWlanApp_Diag(phone, funcCB);
				}
			}
			catch (PhoneException ex)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "PhoneException " + ex.Message);
			}
			catch (Exception ex2)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "Unkonwn Exception " + ex2.Message);
			}
		}
		SetRunWlanAppButtonEnable(bEnable: true);
	}

	private void DoRSSIConfig()
	{
		if ((cfgParams.wlanID == 3620 || cfgParams.wlanID == 3660 || cfgParams.wlanID == 3680) && cfgParams.rx_RssiCfg != null)
		{
			uint conf = 0u;
			if (cfgParams.rx_RssiCfg == "Normal")
			{
				conf = 0u;
			}
			else if (cfgParams.rx_RssiCfg == "Enable MAC Filtering")
			{
				conf = 1u;
			}
			else if (cfgParams.rx_RssiCfg == "Enabled CW")
			{
				conf = 2u;
			}
			phone.FTM_WLAN_GEN6_GET_UNICAST_MAC_PKT_RSSI_CONF(conf);
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_GET_UNICAST_MAC_PKT_RSSI_CONF success");
		}
	}

	private void SetRxDisableMode()
	{
		uint num = 0u;
		if (cfgParams.rxMask_11bFrames == false)
		{
			num++;
		}
		if (cfgParams.rxMask_11gnFrames == false)
		{
			num += 2;
		}
		if (cfgParams.rxMask_11nHT40Frames == false)
		{
			num += 4;
		}
		if (cfgParams.rxMask_11acVHT80Frames == false)
		{
			num += 8;
		}
		phone.FTM_WLAN_GEN6_SET_RX_DISABLE_MODE_V2(num);
		DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_RX_DISABLE_MODE_V2 success");
	}

	public short[] GetRSSIValue()
	{
		short[] array = null;
		if ((cfgParams.wlanID == 3660 || cfgParams.wlanID == 3620 || cfgParams.wlanID == 3680) && (cfgParams.rx_RssiCfg == "Enable MAC Filtering" || cfgParams.rx_RssiCfg == "Enabled CW"))
		{
			array = phone.FTM_WLAN_GEN6_GET_UNICAST_MAC_PKT_RSSI();
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_GET_UNICAST_MAC_PKT_RSSI success");
		}
		else
		{
			array = phone.FTM_WLAN_GEN6_GET_RX_RSSI_VAL();
			DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_GET_RX_RSSI_VAL success");
		}
		return array;
	}

	private void ShowRSSIResult(short[] r)
	{
		if (r != null)
		{
			SetRssi0Result(r[0].ToString());
			if (cfgParams.wlanID == 1312)
			{
				SetRssi1Result(r[1].ToString());
			}
		}
	}

	private void runGetRssi()
	{
		if (phone != null)
		{
			try
			{
				FTM_Start();
				bool bContinueFlag = m_bContinueFlag;
				bool flag = ((cfgParams.rfChain != ChainDict["Transmit Enabled"] && cfgParams.rfChain != ChainDict["PHY_CHAIN_SEL_T0_ON"]) ? true : false);
				bContinueFlag = bContinueFlag && flag;
				while (bContinueFlag)
				{
					CommonCfgChainAndChannel();
					DoRSSIConfig();
					if (cfgParams.rx_RssiCfg == "Normal")
					{
						SetRxDisableMode();
					}
					if (cfgParams.rx_CtrlSG)
					{
						double num = 1.0;
						double? frequencyMHz = getFrequencyMHz(cfgParams.strChannel);
						if (!frequencyMHz.HasValue)
						{
							throw new Exception("Can't get the correct frequency to set up SA/SG");
						}
						if (!cfgParams.rx_SGPower.HasValue)
						{
							throw new Exception("Incorrect Signal Generator Power Level! ");
						}
						WlanConst.SendDebugMessage funcCB = DebugMessageCB.Invoke;
						WlanConst.ConfigSigGen(pSG, frequencyMHz.Value + num, cfgParams.rx_SGPower.Value, funcCB);
					}
					short[] rSSIValue = GetRSSIValue();
					ShowRSSIResult(rSSIValue);
					Thread.Sleep(400);
					cfgParams.rfChain = getUintValueOfChain();
					uint? channel = null;
					string chanDesc = null;
					getInfoOfChan(ref channel, ref chanDesc);
					cfgParams.rfChannel = channel;
					cfgParams.strChannel = chanDesc;
					cfgParams.rx_CtrlSG = GetCheckBoxStatus(cbxRxCtrlEquipment);
					if (cfgParams.rx_CtrlSG)
					{
						retTypeOfComboBox<double> textBoxValue_double = GetTextBoxValue_double(txtSGPower);
						cfgParams.rx_SGPower = null;
						if (!textBoxValue_double.bNull)
						{
							cfgParams.rx_SGPower = textBoxValue_double.value;
						}
					}
					bContinueFlag = m_bContinueFlag && ((cfgParams.rfChain != ChainDict["Transmit Enabled"] && cfgParams.rfChain != ChainDict["PHY_CHAIN_SEL_T0_ON"]) ? true : false);
				}
				FTM_Stop();
				SetbtGetRssiEnable(bEnable: true);
				SetbtStopGetRssiEnable(bEnable: false);
			}
			catch (PhoneException ex)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "PhoneException " + ex.Message);
				SetbtGetRssiEnable(bEnable: true);
				SetbtStopGetRssiEnable(bEnable: false);
			}
			catch (Exception ex2)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "Unkonwn Exception " + ex2.Message);
				SetbtGetRssiEnable(bEnable: true);
				SetbtStopGetRssiEnable(bEnable: false);
			}
		}
		SetbtGetRssiEnable(bEnable: true);
		SetbtStopGetRssiEnable(bEnable: false);
	}

	public void WCN36xx_Unloaded(object sender, RoutedEventArgs e)
	{
		m_bContinueFlag = false;
	}

	private void runTxPacketStart()
	{
		if (phone != null)
		{
			try
			{
				SetPktPowetResult("");
				FTM_Start();
				bool bContinueFlag = m_bContinueFlag;
				bool flag = ((cfgParams.rfChain == ChainDict["Transmit Enabled"] || cfgParams.rfChain == ChainDict["PHY_CHAIN_SEL_T0_ON"]) ? true : false);
				bContinueFlag = bContinueFlag && flag;
				bool flag2 = true;
				while (bContinueFlag)
				{
					if (flag2)
					{
						CommonCfgChainAndChannel();
						setTxFrame(SetTxFrameVersion.V2);
						ConfigPower();
						TxPacketStart();
					}
					if (cfgParams.txPacket_CtrlSA)
					{
						double? frequencyMHz = getFrequencyMHz(cfgParams.strChannel);
						if (!frequencyMHz.HasValue)
						{
							throw new Exception("Can't get the correct frequency to set up SA/SG");
						}
						if (pSA == null)
						{
							throw new Exception("SA/SG handle is null!");
						}
						pSA.SetupMeasurement(Technology.NONE);
						pSA.SetSpan(10.0);
						pSA.SetCenterFrequency(frequencyMHz.Value);
						double referenceLevel = cfgParams.txPacket_txPwr.Value + 5.0;
						pSA.SetReferenceLevel(referenceLevel);
						SetPktPowetResult(pSA.GetPower());
					}
					Thread.Sleep(400);
					uint? uintValueOfChain = getUintValueOfChain();
					uint? channel = null;
					string chanDesc = null;
					getInfoOfChan(ref channel, ref chanDesc);
					uint? num = channel;
					string text = chanDesc;
					string stringValueOfTxMode = getStringValueOfTxMode();
					uint? uintValueOfTxRate = getUintValueOfTxRate();
					wlan_TxPowerCtrlClass txPwrCtrlParams = getTxPwrCtrlParams();
					uint? uintValueOfRFGain = getUintValueOfRFGain();
					int? intValueOfDigGain = getIntValueOfDigGain();
					double? doubleValueOfTargetPwr = getDoubleValueOfTargetPwr();
					if (uintValueOfChain == cfgParams.rfChain)
					{
						uint? num2 = num;
						uint? rfChannel = cfgParams.rfChannel;
						if (num2.GetValueOrDefault() == rfChannel.GetValueOrDefault() && num2.HasValue == rfChannel.HasValue && text == cfgParams.strChannel && stringValueOfTxMode == cfgParams.txPacket_Mode)
						{
							uint? num3 = uintValueOfTxRate;
							uint? txPacket_Rate = cfgParams.txPacket_Rate;
							if (num3.GetValueOrDefault() == txPacket_Rate.GetValueOrDefault() && num3.HasValue == txPacket_Rate.HasValue && txPwrCtrlParams.IsEqual(cfgParams.txPacket_pwrCtrlMode) && uintValueOfRFGain == cfgParams.txPacket_rfGain)
							{
								int? num4 = intValueOfDigGain;
								int? txPacket_digGain = cfgParams.txPacket_digGain;
								if (num4.GetValueOrDefault() == txPacket_digGain.GetValueOrDefault() && num4.HasValue == txPacket_digGain.HasValue && doubleValueOfTargetPwr == cfgParams.txPacket_txPwr)
								{
									flag2 = false;
									goto IL_03eb;
								}
							}
						}
					}
					flag2 = true;
					cfgParams.rfChain = uintValueOfChain;
					cfgParams.rfChannel = num;
					cfgParams.strChannel = text;
					cfgParams.txPacket_Mode = stringValueOfTxMode;
					cfgParams.txPacket_Rate = uintValueOfTxRate;
					cfgParams.txPacket_pwrCtrlMode = txPwrCtrlParams;
					cfgParams.txPacket_rfGain = uintValueOfRFGain;
					cfgParams.txPacket_digGain = intValueOfDigGain;
					cfgParams.txPacket_txPwr = doubleValueOfTargetPwr;
					goto IL_03eb;
					IL_03eb:
					cfgParams.txPacket_CtrlSA = GetCheckBoxStatus(cbxControlSA_TxPkt);
					bContinueFlag = m_bContinueFlag && ((cfgParams.rfChain == ChainDict["Transmit Enabled"] || cfgParams.rfChain == ChainDict["PHY_CHAIN_SEL_T0_ON"]) ? true : false);
					if (flag2 || !bContinueFlag)
					{
						TxPktGenOnOff(bOn: false);
					}
				}
				FTM_Stop();
				SetTxPktStartButtonEnable(bEnable: true);
				SetTxPktStopButtonEnable(bEnable: false);
				return;
			}
			catch (PhoneException ex)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "PhoneException " + ex.Message);
				SetTxPktStartButtonEnable(bEnable: true);
				SetTxPktStopButtonEnable(bEnable: false);
				return;
			}
			catch (Exception ex2)
			{
				DebugMessageCB(MessageLevel.EXCEPTION, "Unkonwn Exception " + ex2.Message);
				SetTxPktStartButtonEnable(bEnable: true);
				SetTxPktStopButtonEnable(bEnable: false);
				return;
			}
		}
		SetTxPktStartButtonEnable(bEnable: true);
		SetTxPktStopButtonEnable(bEnable: false);
	}

	private void setTxPowerCtrolMode()
	{
		if (cfgParams.txPacket_pwrCtrlMode.bMultiCtrlModeSelection == true)
		{
			byte mode = 0;
			if (cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection != null)
			{
				if (WCN36xxStatic.PwrCtrlModeDict.Keys.Contains(cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection))
				{
					mode = WCN36xxStatic.PwrCtrlModeDict[cfgParams.txPacket_pwrCtrlMode.sPwrCtrlSelection];
				}
				phone.FTM_WLAN_GEN6_CLOSE_TPC_LOOP_V2(mode);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_CLOSE_TPC_LOOP_V2 success");
			}
			uint num = 0u;
			if (cfgParams.txPacket_pwrCtrlMode.sPwrIndexSource == "Regulatory")
			{
				num = 3u;
			}
			else if (cfgParams.txPacket_pwrCtrlMode.sPwrIndexSource == "Fixed")
			{
				num = 2u;
			}
			if (num != 0)
			{
				phone.FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE(num);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_PWR_INDEX_SOURCE success");
			}
		}
		else
		{
			bool? bMultiCtrlModeSelection = cfgParams.txPacket_pwrCtrlMode.bMultiCtrlModeSelection;
			if (!bMultiCtrlModeSelection.GetValueOrDefault() && bMultiCtrlModeSelection.HasValue && cfgParams.txPacket_pwrCtrlMode.bClosedloop.HasValue)
			{
				phone.FTM_WLAN_GEN6_CLOSE_TPC_LOOP(cfgParams.txPacket_pwrCtrlMode.bClosedloop.Value);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_CLOSE_TPC_LOOP success");
			}
		}
	}

	private void setForcedPktGain()
	{
		int num = 0;
		if (cfgParams.wlanID.HasValue)
		{
			num = cfgParams.wlanID.Value;
		}
		if (num != 3660)
		{
			switch (num)
			{
			case 3660:
			case 3680:
				break;
			case 1312:
			case 1314:
			{
				uint num2 = 0u;
				if (cfgParams.txPacket_rfGain.HasValue)
				{
					num2 = cfgParams.txPacket_rfGain.Value;
				}
				uint num3 = 0u;
				if (cfgParams.txPacket_digGain.HasValue)
				{
					num3 = (uint)cfgParams.txPacket_digGain.Value;
				}
				byte gain = (byte)((num2 << 4) | num3);
				phone.FTM_WLAN_GEN6_FORCE_PKT_TX_GAIN(0, gain);
				DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_FORCE_PKT_TX_GAIN success");
				return;
			}
			default:
				return;
			}
		}
		uint num4 = 0u;
		int num5 = 0;
		try
		{
			if (cfgParams.txPacket_rfGain.HasValue)
			{
				num4 = cfgParams.txPacket_rfGain.Value;
			}
			if (num4 > 31)
			{
				num4 = 31u;
			}
		}
		catch (Exception)
		{
			num4 = 0u;
		}
		try
		{
			if (cfgParams.txPacket_digGain.HasValue)
			{
				num5 = cfgParams.txPacket_digGain.Value;
			}
			if (num5 > 23)
			{
				num5 = 23;
			}
			if (num5 < -39)
			{
				num5 = -39;
			}
		}
		catch (Exception)
		{
			num5 = 0;
		}
		uint num6 = 0u;
		num6 = (uint)((num5 >= 0) ? num5 : (-num5 + 128));
		phone.FTM_WLAN_GEN6_SET_TX_WAVEFORM_GAIN_V2(num4, num6);
		DebugMessageCB(MessageLevel.SUCCESS, "QLIB_FTM_WLAN_GEN6_SET_TX_WAVEFORM_GAIN_V2 success");
	}
}
