/// <summary> /// Returns the XBee value (value stored in the XBee module) of the stop bits setting of the /// firmware. /// </summary> /// <returns>The XBee value of the stop bits setting of the firmware.</returns> public int GetSerialStopBits() { AbstractXBeeSetting atSetting = GetAtSetting(SERIAL_SETTING_STOP_BITS); if (atSetting != null) { // Do not specify the network stack of the SB 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.IsInteger(atSetting.GetXBeeValue())) { return(DEFAULT_SERIAL_STOP_BITS); } switch (int.Parse(settingValue)) { case 0: return(1); case 1: return(2); default: return(DEFAULT_SERIAL_STOP_BITS); } } return(DEFAULT_SERIAL_STOP_BITS); }
/// <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 the setting corresponding to the provided <paramref name="atCommand"/> in any category /// of the firmware. /// </summary> /// <param name="atCommand">The AT command corresponding to the setting to get.</param> /// <returns>The setting corresponding to the provided AT command.</returns> public AbstractXBeeSetting GetAtSetting(string atCommand) { foreach (XBeeCategory category in Categories) { AbstractXBeeSetting atSetting = GetAtSetting(atCommand, category); if (atSetting != null) { return(atSetting); } } return(null); }
/// <summary> /// Returns the setting corresponding to the provided <paramref name="atCommand"/> and located /// in the given <paramref name="category"/>. /// </summary> /// <param name="atCommand">The AT command corresponding to the setting to get.</param> /// <param name="category">The configuration category where the setting should be found.</param> /// <returns>The setting corresponding to the provided AT command and category.</returns> /// <seealso cref="AbstractXBeeSetting"/> /// <seealso cref="XBeeCategory"/> private AbstractXBeeSetting GetAtSetting(string atCommand, XBeeCategory category) { foreach (AbstractXBeeSetting xbeeSetting in category.Settings) { if (xbeeSetting.AtCommand != null && xbeeSetting.AtCommand.ToUpper().Equals(atCommand.ToUpper())) { return(xbeeSetting); } } foreach (XBeeCategory subCategory in category.Categories) { AbstractXBeeSetting atSetting = GetAtSetting(atCommand, subCategory); if (atSetting != null) { return(atSetting); } } return(null); }
/// <summary> /// Clones and returns the setting object. /// </summary> /// <param name="parentCategory">The parent category where the cloned setting should be placed.</param> /// <param name="ownerFirmware">The owner firmware of the cloned setting.</param> /// <returns>The cloned setting object.</returns> public AbstractXBeeSetting CloneSetting(XBeeCategory parentCategory, XBeeFirmware ownerFirmware) { AbstractXBeeSetting clonedSetting = (AbstractXBeeSetting)Clone(); clonedSetting.ParentCategory = parentCategory; clonedSetting.OwnerFirmware = ownerFirmware; // Clone the list of current values. List <string> clonedCurrentValues = new List <string>(); clonedCurrentValues.AddRange(CurrentValues); clonedSetting.CurrentValues = clonedCurrentValues; // Clone the list of XBee values. List <string> clonedXBeeValues = new List <string>(); clonedXBeeValues.AddRange(XBeeValues); clonedSetting.XBeeValues = clonedXBeeValues; return(clonedSetting); }
/// <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); }