from ....Internal.Core import Core
from ....Internal.CommandsGroup import CommandsGroup
from ....Internal import Conversions
from .... import enums


# noinspection PyPep8Naming,PyAttributeOutsideInit,SpellCheckingInspection
class AwgnCls:
	"""Awgn commands group definition. 20 total commands, 4 Subgroups, 5 group commands"""

	def __init__(self, core: Core, parent):
		self._core = core
		self._cmd_group = CommandsGroup("awgn", core, parent)

	@property
	def bandwidth(self):
		"""bandwidth commands group. 1 Sub-classes, 3 commands."""
		if not hasattr(self, '_bandwidth'):
			from .Bandwidth import BandwidthCls
			self._bandwidth = BandwidthCls(self._core, self._cmd_group)
		return self._bandwidth

	@property
	def disp(self):
		"""disp commands group. 0 Sub-classes, 2 commands."""
		if not hasattr(self, '_disp'):
			from .Disp import DispCls
			self._disp = DispCls(self._core, self._cmd_group)
		return self._disp

	@property
	def frequency(self):
		"""frequency commands group. 0 Sub-classes, 2 commands."""
		if not hasattr(self, '_frequency'):
			from .Frequency import FrequencyCls
			self._frequency = FrequencyCls(self._core, self._cmd_group)
		return self._frequency

	@property
	def power(self):
		"""power commands group. 2 Sub-classes, 3 commands."""
		if not hasattr(self, '_power'):
			from .Power import PowerCls
			self._power = PowerCls(self._core, self._cmd_group)
		return self._power

	def get_brate(self) -> float:
		"""SCPI: [SOURce<HW>]:AWGN:BRATe \n
		Snippet: value: float = driver.source.awgn.get_brate() \n
		Sets the bit rate which is used for calculation of bit energy to noise power ratio from carrier/noise ratio for Digital
		Standard signals. Valid units are bps, kbps and mabps as well as b/s, kb/s and mab/s. \n
			:return: brate: float Range: 400 bps to 250E6 bps
		"""
		response = self._core.io.query_str('SOURce<HwInstance>:AWGN:BRATe?')
		return Conversions.str_to_float(response)

	def set_brate(self, brate: float) -> None:
		"""SCPI: [SOURce<HW>]:AWGN:BRATe \n
		Snippet: driver.source.awgn.set_brate(brate = 1.0) \n
		Sets the bit rate which is used for calculation of bit energy to noise power ratio from carrier/noise ratio for Digital
		Standard signals. Valid units are bps, kbps and mabps as well as b/s, kb/s and mab/s. \n
			:param brate: float Range: 400 bps to 250E6 bps
		"""
		param = Conversions.decimal_value_to_str(brate)
		self._core.io.write(f'SOURce<HwInstance>:AWGN:BRATe {param}')

	def get_cn_ratio(self) -> float:
		"""SCPI: [SOURce<HW>]:AWGN:CNRatio \n
		Snippet: value: float = driver.source.awgn.get_cn_ratio() \n
		In Additive Noise and CW Interferer (SOUR:AWGN:MODE ADD|CW) mode, sets the carrier/interferer ratio. The value range
		depends on the selected AWGN mode. \n
			:return: cn_ratio: float Range: -50 to 40, Unit: dB
		"""
		response = self._core.io.query_str('SOURce<HwInstance>:AWGN:CNRatio?')
		return Conversions.str_to_float(response)

	def set_cn_ratio(self, cn_ratio: float) -> None:
		"""SCPI: [SOURce<HW>]:AWGN:CNRatio \n
		Snippet: driver.source.awgn.set_cn_ratio(cn_ratio = 1.0) \n
		In Additive Noise and CW Interferer (SOUR:AWGN:MODE ADD|CW) mode, sets the carrier/interferer ratio. The value range
		depends on the selected AWGN mode. \n
			:param cn_ratio: float Range: -50 to 40, Unit: dB
		"""
		param = Conversions.decimal_value_to_str(cn_ratio)
		self._core.io.write(f'SOURce<HwInstance>:AWGN:CNRatio {param}')

	def get_en_ratio(self) -> float:
		"""SCPI: [SOURce<HW>]:AWGN:ENRatio \n
		Snippet: value: float = driver.source.awgn.get_en_ratio() \n
		In Additive Noise mode, sets the ratio of bit energy to noise power density. For Digital Standard signals, the bit rate
		used for calculation of Eb/N0 value from C/N value is defined with command SOUR:AWGN:BRAT. \n
			:return: en_ratio: float Range: -50 to depends on hardware, Unit: dB
		"""
		response = self._core.io.query_str('SOURce<HwInstance>:AWGN:ENRatio?')
		return Conversions.str_to_float(response)

	def set_en_ratio(self, en_ratio: float) -> None:
		"""SCPI: [SOURce<HW>]:AWGN:ENRatio \n
		Snippet: driver.source.awgn.set_en_ratio(en_ratio = 1.0) \n
		In Additive Noise mode, sets the ratio of bit energy to noise power density. For Digital Standard signals, the bit rate
		used for calculation of Eb/N0 value from C/N value is defined with command SOUR:AWGN:BRAT. \n
			:param en_ratio: float Range: -50 to depends on hardware, Unit: dB
		"""
		param = Conversions.decimal_value_to_str(en_ratio)
		self._core.io.write(f'SOURce<HwInstance>:AWGN:ENRatio {param}')

	# noinspection PyTypeChecker
	def get_mode(self) -> enums.NoisAwgnMode:
		"""SCPI: [SOURce<HW>]:AWGN:MODE \n
		Snippet: value: enums.NoisAwgnMode = driver.source.awgn.get_mode() \n
		Selects the mode for generating the interfering signal. \n
			:return: mode: ONLY| ADD| CW ADD The AWGN noise signal is added to the baseband signal. ONLY The pure AWGN noise signal is modulated to the carrier. The connection to the baseband is interrupted. CW The sine interfering signal is added to the baseband signal.
		"""
		response = self._core.io.query_str('SOURce<HwInstance>:AWGN:MODE?')
		return Conversions.str_to_scalar_enum(response, enums.NoisAwgnMode)

	def set_mode(self, mode: enums.NoisAwgnMode) -> None:
		"""SCPI: [SOURce<HW>]:AWGN:MODE \n
		Snippet: driver.source.awgn.set_mode(mode = enums.NoisAwgnMode.ADD) \n
		Selects the mode for generating the interfering signal. \n
			:param mode: ONLY| ADD| CW ADD The AWGN noise signal is added to the baseband signal. ONLY The pure AWGN noise signal is modulated to the carrier. The connection to the baseband is interrupted. CW The sine interfering signal is added to the baseband signal.
		"""
		param = Conversions.enum_scalar_to_str(mode, enums.NoisAwgnMode)
		self._core.io.write(f'SOURce<HwInstance>:AWGN:MODE {param}')

	def get_state(self) -> bool:
		"""SCPI: [SOURce<HW>]:AWGN:STATe \n
		Snippet: value: bool = driver.source.awgn.get_state() \n
		Activates or deactivates the white noise (AWGN = Averaged White Gaussian Noise) . Use the command [:SOURce<hw>]:AWGN:MODE
		to define the mode the AWGN generator is working in. \n
			:return: state: 0| 1| OFF| ON
		"""
		response = self._core.io.query_str('SOURce<HwInstance>:AWGN:STATe?')
		return Conversions.str_to_bool(response)

	def set_state(self, state: bool) -> None:
		"""SCPI: [SOURce<HW>]:AWGN:STATe \n
		Snippet: driver.source.awgn.set_state(state = False) \n
		Activates or deactivates the white noise (AWGN = Averaged White Gaussian Noise) . Use the command [:SOURce<hw>]:AWGN:MODE
		to define the mode the AWGN generator is working in. \n
			:param state: 0| 1| OFF| ON
		"""
		param = Conversions.bool_to_str(state)
		self._core.io.write(f'SOURce<HwInstance>:AWGN:STATe {param}')

	def clone(self) -> 'AwgnCls':
		"""Clones the group by creating new object from it and its whole existing subgroups
		Also copies all the existing default Repeated Capabilities setting,
		which you can change independently without affecting the original group"""
		new_group = AwgnCls(self._core, self._cmd_group.parent)
		self._cmd_group.synchronize_repcaps(new_group)
		return new_group
