Beispiel #1
0
        /// <summary>
        /// Reads the combo setting specific parameters from the XML element and fills the given
        /// combo setting with them.
        /// </summary>
        /// <param name="settingElement">The XML element to read the specific parameters from.</param>
        /// <param name="comboSetting">The combo setting to be filled.</param>
        private static void FillComboSetting(XElement settingElement, XBeeSettingCombo comboSetting)
        {
            List <string> comboItems = new List <string>();

            XElement comboItemsElement = settingElement.Element(XMLFirmwareConstants.ITEM_ITEMS);

            if (comboItemsElement == null)
            {
                return;
            }

            List <XElement> comboItemsList = new List <XElement>();

            foreach (XElement element in comboItemsElement.Elements())
            {
                if (element.Name.ToString().Equals(XMLFirmwareConstants.ITEM_ITEM))
                {
                    comboItemsList.Add(element);
                }
            }
            if (comboItemsList == null || comboItemsList.Count == 0)
            {
                return;
            }

            for (int i = 0; i < comboItemsList.Count; i++)
            {
                string index = ParsingUtils.IntegerToHexString(i, 1);
                while (index.StartsWith("0"))
                {
                    if (index.Length == 1)
                    {
                        break;
                    }

                    index = index.Substring(1);
                }
                comboItems.Add(comboItemsList[i].Value + " [" + index + "]");
            }
            comboSetting.Items = comboItems;
        }
Beispiel #2
0
        /// <summary>
        /// Parse the given setting element assuming it is an AT setting. Return the setting object
        /// corresponding to the XML element.
        /// </summary>
        /// <param name="settingElement">The XML element to parse.</param>
        /// <param name="parentCategory">The parent category (where the setting will be placed).</param>
        /// <param name="ownerFirmware">The owner firmware of the settings to parse.</param>
        /// <returns>The setting object corresponding to the given XML element.</returns>
        private static AbstractXBeeSetting ParseATSetting(XElement settingElement, XBeeCategory parentCategory,
                                                          XBeeFirmware ownerFirmware)
        {
            AbstractXBeeSetting xbeeSetting = null;

            // As this is an AT command setting, read the AT command.
            string atCommand = null;

            if (settingElement.Attribute(XMLFirmwareConstants.ATTRIBUTE_COMMAND) != null)
            {
                atCommand = settingElement.Attribute(XMLFirmwareConstants.ATTRIBUTE_COMMAND).Value;
            }

            string name         = null;
            string description  = null;
            string defaultValue = null;
            string controlType  = null;

            int numNetworks = 1;

            // Necessary items to parse and create an AT setting, if they are not defined, return a
            // null setting.
            if (settingElement.Element(XMLFirmwareConstants.ITEM_NAME) == null ||
                settingElement.Element(XMLFirmwareConstants.ITEM_DESCRIPTION) == null ||
                settingElement.Element(XMLFirmwareConstants.ITEM_CONTROL_TYPE) == null)
            {
                return(null);
            }

            name        = settingElement.Element(XMLFirmwareConstants.ITEM_NAME).Value.Trim();
            description = settingElement.Element(XMLFirmwareConstants.ITEM_DESCRIPTION).Value.Trim();
            controlType = settingElement.Element(XMLFirmwareConstants.ITEM_CONTROL_TYPE).Value.Trim();
            // Check if the setting has the number of networks field.
            if (settingElement.Element(XMLFirmwareConstants.ITEM_NETWORKS) != null)
            {
                int.TryParse(settingElement.Element(XMLFirmwareConstants.ITEM_NETWORKS).Value.Trim(), out numNetworks);
            }

            // There are settings that may not have a default value defined.
            if (settingElement.Element(XMLFirmwareConstants.ITEM_DEFAULT_VALUE) != null)
            {
                defaultValue = settingElement.Element(XMLFirmwareConstants.ITEM_DEFAULT_VALUE).Value;
                if (defaultValue.ToLower().StartsWith("0x"))
                {
                    defaultValue = defaultValue.Substring(2);
                }
            }

            // Only the button setting is allowed to not have an AT command associated, so
            // if the read AT command is <c>null</c>, return null.
            if (!controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_BUTTON) && atCommand == null)
            {
                return(null);
            }

            // Generate the setting object and fill it depending on the control type.
            if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_BUTTON))
            {
                xbeeSetting = new XBeeSettingButton(name, description, parentCategory, ownerFirmware, numNetworks);
                FillButtonSetting(settingElement, (XBeeSettingButton)xbeeSetting);
            }
            else if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_COMBO))
            {
                xbeeSetting = new XBeeSettingCombo(atCommand, name, description, defaultValue, parentCategory, ownerFirmware, numNetworks);
                FillComboSetting(settingElement, (XBeeSettingCombo)xbeeSetting);
            }
            else if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_NONE))
            {
                xbeeSetting = new XBeeSettingNoControl(atCommand, name, description, defaultValue, parentCategory, ownerFirmware, numNetworks);
                FillNoControlSetting(settingElement, (XBeeSettingNoControl)xbeeSetting);
            }
            else if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_NON_EDITABLE_STRING))
            {
                xbeeSetting = new XBeeSettingNoControl(atCommand, name, description, defaultValue, parentCategory, ownerFirmware, numNetworks);
                FillNoControlSetting(settingElement, (XBeeSettingNoControl)xbeeSetting);
                ((XBeeSettingNoControl)xbeeSetting).Format = Format.ASCII;
            }
            else if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_NUMBER))
            {
                xbeeSetting = new XBeeSettingNumber(atCommand, name, description, defaultValue, parentCategory, ownerFirmware, numNetworks);
                FillNumberSetting(settingElement, (XBeeSettingNumber)xbeeSetting);
            }
            else if (controlType.Equals(XMLFirmwareConstants.SETTING_TYPE_TEXT))
            {
                xbeeSetting = new XBeeSettingText(atCommand, name, description, defaultValue, parentCategory, ownerFirmware, numNetworks);
                FillTextSetting(settingElement, (XBeeSettingText)xbeeSetting);
            }

            return(xbeeSetting);
        }