/// <summary> /// Adds a new range to the list of ranges of the numeric setting. /// </summary> /// <param name="numberSetting">The XBee number setting to add the range to.</param> /// <param name="rangeMinValue">The minimum valid value of the range.</param> /// <param name="rangeMaxValue">The maximum valid value of the range.</param> private static void AddRange(XBeeSettingNumber numberSetting, string rangeMinValue, string rangeMaxValue) { Range range = new Range(rangeMinValue, rangeMaxValue); if (!range.RangeMin.ToLower().StartsWith("0x")) { // [XCTUNG-1180] Range may contain a reference to another AT command. if (ParsingUtils.IsHexadecimal(range.RangeMin)) { range.RangeMin = "0x" + range.RangeMin; } else { // The min range depends on another AT command, so add the dependency. numberSetting.OwnerFirmware.AddDependency(range.RangeMin, numberSetting.AtCommand); } } if (!range.RangeMax.ToLower().StartsWith("0x")) { // [XCTUNG-1180] Range may contain a reference to another AT command. if (ParsingUtils.IsHexadecimal(range.RangeMax)) { range.RangeMax = "0x" + range.RangeMax; } else { // The max range depends on another AT command, so add the dependency. numberSetting.OwnerFirmware.AddDependency(range.RangeMax, numberSetting.AtCommand); } } numberSetting.AddRange(range); }
/// <summary> /// Returns the default selected index. /// </summary> /// <returns>The default selected index.</returns> public int GetDefaultSelectedIndex() { if (!ParsingUtils.IsHexadecimal(DefaultValue)) { return(0); } return(ParsingUtils.HexStringToInt(DefaultValue)); }
/// <summary> /// Returns the XBee value (value stored in the XBee module) of the baud rate setting of the firmware. /// </summary> /// <returns>The XBee value of the baud rate setting of the firmware.</returns> public int GetSerialBaudRate() { AbstractXBeeSetting atSetting = GetAtSetting(SERIAL_SETTING_BAUD_RATE); if (atSetting != null) { // Do not specify the network stack of the BD parameter by the moment (it's a common value). // TODO: [DUAL] When this setting is implemented individually for each network stack, update this code to // specify the network ID from which this parameter should be read. string settingValue = atSetting.GetXBeeValue(); if (!ParsingUtils.IsHexadecimal(atSetting.GetXBeeValue())) { return(DEFAULT_SERIAL_BAUD_RATE); } switch (ParsingUtils.HexStringToInt(settingValue)) { case 0: return(1200); case 1: return(2400); case 2: return(4800); case 3: return(9600); case 4: return(19200); case 5: return(38400); case 6: return(57600); case 7: return(115200); case 8: return(230400); case 9: return(460800); case 10: return(921600); default: return(DEFAULT_SERIAL_BAUD_RATE); } } return(DEFAULT_SERIAL_BAUD_RATE); }
/// <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) { if (GetCurrentValue(networkIndex) == null) { ValidationErrorMessage = "You must select one of the possible values."; return(false); } if (!ParsingUtils.IsHexadecimal(GetCurrentValue(networkIndex))) { ValidationErrorMessage = "Invalid selection value."; return(false); } ValidationErrorMessage = null; return(true); }
/// <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: Is this necessary FirmwareAddon.isValidateDefaultEmptySettingsEnabled()? if ((DefaultValue == null || DefaultValue.Length == 0) && (GetCurrentValue(networkIndex) == null || GetCurrentValue(networkIndex).Length == 0)) { return(true); } // Special fix to avoid errors on KY setting due to firmware miss-specification error. if (string.Compare(AtCommand, KY_SETTING, StringComparison.OrdinalIgnoreCase) == 0) { if (GetCurrentValue(networkIndex) != null && GetCurrentValue(networkIndex).Length > 0) { if (GetCurrentValue(networkIndex).Trim().Equals("0") || GetCurrentValue(networkIndex).Trim().Equals("1")) { return(true); } } } if (GetCurrentValue(networkIndex) == null) { ValidationErrorMessage = "Value cannot be empty."; return(false); } if (GetCurrentValue(networkIndex).Length == 0 && MinChars == 0) { ValidationErrorMessage = null; return(true); } if (MinChars == MaxChars && GetCurrentValue(networkIndex).Length != MinChars) { ValidationErrorMessage = "Value must have " + MinChars + " characters."; return(false); } if (GetCurrentValue(networkIndex).Length < MinChars) { ValidationErrorMessage = "Value must have at least " + MinChars + " characters."; return(false); } if (GetCurrentValue(networkIndex).Length > MaxChars) { ValidationErrorMessage = "Value must have less than " + (MaxChars + 1) + " characters."; return(false); } if (Format == Format.HEX) { if (!ParsingUtils.IsHexadecimal(GetCurrentValue(networkIndex))) { ValidationErrorMessage = "Value can only contain hexadecimal characters"; return(false); } } if (Format == Format.IPV4) { if (!Regex.IsMatch(GetCurrentValue(networkIndex), IP_V4_PATTERN)) { ValidationErrorMessage = "Value must follow the IPv4 format: x.x.x.x (where x must be a decimal value between 0 and 255)."; return(false); } } if (Format == Format.IPV6) { if (!Regex.IsMatch(GetCurrentValue(networkIndex), IP_V6_PATTERN)) { ValidationErrorMessage = "Value must follow the IPv6 format: 'xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx' " + "or 'xxxx:xxxx:xxxx:xxxx' (or without ':'), where x must be an hexadecimal value."; return(false); } } if (Format == Format.PHONE) { if (!Regex.IsMatch(GetCurrentValue(networkIndex), PHONE_PATTERN)) { ValidationErrorMessage = "Value can only contain numeric characters (0-9) and plus sign '+' prefix."; return(false); } } ValidationErrorMessage = null; return(true); }
/// <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); }