コード例 #1
0
 /// <summary>
 /// Reads the button setting specific parameters from the XML element and fills the given button
 /// setting with them.
 /// </summary>
 /// <param name="settingElement">The XML element to read the specific parameters from.</param>
 /// <param name="buttonSetting">The button setting to be filled.</param>
 private static void FillButtonSetting(XElement settingElement, XBeeSettingButton buttonSetting)
 {
     if (settingElement.Element(XMLFirmwareConstants.ITEM_FUNCTION_NUMBER) != null &&
         ParsingUtils.IsInteger(settingElement.Element(XMLFirmwareConstants.ITEM_FUNCTION_NUMBER).Value.Trim()))
     {
         buttonSetting.FunctionNumber = int.Parse(settingElement.Element(XMLFirmwareConstants.ITEM_FUNCTION_NUMBER).Value.Trim());
     }
 }
コード例 #2
0
        /// <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>
        /// <seealso cref="AbstractXBeeSetting"/>
        public new AbstractXBeeSetting CloneSetting(XBeeCategory parentCategory, XBeeFirmware ownerFirmware)
        {
            XBeeSettingButton clonedSetting = (XBeeSettingButton)base.CloneSetting(parentCategory, ownerFirmware);

            // Clone the attributes of this object.
            clonedSetting.FunctionNumber = FunctionNumber;

            return(clonedSetting);
        }
コード例 #3
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);
        }