/// <summary> /// Returns whether or not the current value of the provided network index is valid. /// </summary> /// <returns><c>true</c> if the value is valid, <c>false</c> otherwise.</returns> public override bool ValidateSetting(int networkIndex) { // Special fix to avoid errors on settings that don't have a default value configured. // This is a firmware miss-specification error. // TODO: Verify if it is necessary to use: FirmwareAddon.isValidateDefaultEmptySettingsEnabled() if ((DefaultValue == null || DefaultValue.Length == 0) && (GetCurrentValue(networkIndex) == null || GetCurrentValue(networkIndex).Length == 0)) { return(true); } if (GetCurrentValue(networkIndex) == null || GetCurrentValue(networkIndex).Length == 0) { ValidationErrorMessage = "Value cannot be empty."; return(false); } if (!ParsingUtils.IsHexadecimal(GetCurrentValue(networkIndex))) { ValidationErrorMessage = "Value is not a valid hexadecimal number."; return(false); } // Get the current value. BigInteger intValue = ParsingUtils.GetBigInt(GetCurrentValue(networkIndex)); // Special fix to avoid errors on LT setting due to firmware miss-specification error. if (AtCommand != null && string.Compare(AtCommand, LT_SETTING, StringComparison.OrdinalIgnoreCase) == 0 && BigInteger.Compare(intValue, new BigInteger(0)) == 0) { ValidationErrorMessage = null; return(true); } // Check if the value is any of the additional values. foreach (string additionalValue in AdditionalValues) { BigInteger validValue = ParsingUtils.GetBigInt(additionalValue); if (validValue.CompareTo(intValue) == 0) { ValidationErrorMessage = null; return(true); } } // Check if value is in any of the possible ranges. foreach (Range range in Ranges) { BigInteger rangeMinInt; BigInteger rangeMaxInt; if (ParsingUtils.IsHexadecimal(range.RangeMin)) { rangeMinInt = ParsingUtils.GetBigInt(range.RangeMin); } else { // [XCTUNG-1180] Range may contain a reference to another AT command. AbstractXBeeSetting setting = OwnerFirmware.GetAtSetting(range.RangeMin); rangeMinInt = ParsingUtils.GetBigInt(setting != null ? (string.IsNullOrEmpty(setting.GetCurrentValue()) ? "0" : setting.GetCurrentValue()) : GetCurrentValue()); } if (ParsingUtils.IsHexadecimal(range.RangeMax)) { rangeMaxInt = ParsingUtils.GetBigInt(range.RangeMax); } else { AbstractXBeeSetting setting = OwnerFirmware.GetAtSetting(range.RangeMax); rangeMaxInt = ParsingUtils.GetBigInt(setting != null ? (string.IsNullOrEmpty(setting.GetCurrentValue()) ? "0" : setting.GetCurrentValue()) : GetCurrentValue()); } if (BigInteger.Compare(intValue, rangeMinInt) >= 0 && BigInteger.Compare(intValue, rangeMaxInt) <= 0) { ValidationErrorMessage = null; return(true); } } ValidationErrorMessage = GenerateValidationErrorMsg(); return(false); }