Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the text setting specific parameters from the XML element and fills
        /// the given text setting with them.
        /// </summary>
        /// <param name="settingElement">The XML element to read the specific parameters from.</param>
        /// <param name="textSetting">The text setting to be filled.</param>
        private static void FillTextSetting(XElement settingElement, XBeeSettingText textSetting)
        {
            if (settingElement.Element(XMLFirmwareConstants.ITEM_MIN_CHARS) != null &&
                ParsingUtils.IsInteger(settingElement.Element(XMLFirmwareConstants.ITEM_MIN_CHARS).Value.Trim()))
            {
                textSetting.MinChars = int.Parse(settingElement.Element(XMLFirmwareConstants.ITEM_MIN_CHARS).Value.Trim());
            }

            if (settingElement.Element(XMLFirmwareConstants.ITEM_MAX_CHARS) != null &&
                ParsingUtils.IsInteger(settingElement.Element(XMLFirmwareConstants.ITEM_MAX_CHARS).Value.Trim()))
            {
                textSetting.MaxChars = int.Parse(settingElement.Element(XMLFirmwareConstants.ITEM_MAX_CHARS).Value.Trim());
            }

            if (settingElement.Element(XMLFirmwareConstants.ITEM_FORMAT) != null)
            {
                string formatString = settingElement.Element(XMLFirmwareConstants.ITEM_FORMAT).Value.ToUpper();
                Format format       = Format.UNKNOWN.Get(formatString);
                if (format == Format.UNKNOWN)
                {
                    format = Format.ASCII;
                }

                textSetting.Format = format;
            }
            if (settingElement.Element(XMLFirmwareConstants.ITEM_EXCEPTION) != null)
            {
                textSetting.ExceptionValue = settingElement.Element(XMLFirmwareConstants.ITEM_EXCEPTION).Value;
            }
        }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the given file and returns the XBee firmware objects found.
        /// </summary>
        /// <param name="file">File to parse.</param>
        /// <param name="fullParse">Determines if the parsing process will also include the categories with
        /// settings and configuration commands (true) or will only parse the firmware's basic
        /// information (false).</param>
        /// <returns>A list with the XBee firmware objects found in the file, <c>null</c> if error.</returns>
        /// <exception cref="ParsingException">If there is any problem parsing the firmware XML file.</exception>
        public static List <XBeeFirmware> ParseFile(FileInfo file, bool fullParse)
        {
            List <XBeeFirmware> xbeeFirmwares = new List <XBeeFirmware>();

            XDocument document = XDocument.Load(file.FullName);

            // Verify if the file has the expected contents and there is any
            // XBee firmware defined inside.
            XElement firmwaresElement = document.Root;

            if (firmwaresElement == null || !firmwaresElement.Name.ToString().Equals(XMLFirmwareConstants.ITEM_FIRMWARES))
            {
                throw new ParsingException(string.Format(ERROR_INVALID_XML_CONTENTS, file.FullName, MSG_FIRMWARES_NOT_FOUND));
            }

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

            foreach (XElement element in firmwaresElement.Elements())
            {
                if (element.Name.ToString().Equals(XMLFirmwareConstants.ITEM_FIRMWARE))
                {
                    firmwaresList.Add(element);
                }
            }
            if (firmwaresList == null || firmwaresList.Count == 0)
            {
                throw new ParsingException(ERROR_FIRMWARE_NOT_FOUND);
            }

            foreach (XElement firmwareElement in firmwaresList)
            {
                // This is the list of necessary items to define a firmware. If any of them is
                // not defined discard this firmware.
                string firmwareVersion = firmwareElement.Attribute(XMLFirmwareConstants.ATTRIBUTE_FW_VERSION).Value;
                if (firmwareVersion == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_FAMILY) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_PRODUCT_NAME) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_HW_VERSION) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_COMPATIBILITY_NUM) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_CONFIG_BUFFER_LOC) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_FLASH_PAGE_SIZE) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_CRC_BUFFER_LEN) == null ||
                    firmwareElement.Element(XMLFirmwareConstants.ITEM_FUNCTION) == null)
                {
                    continue;
                }

                string family      = firmwareElement.Element(XMLFirmwareConstants.ITEM_FAMILY).Value;
                string productName = firmwareElement.Element(XMLFirmwareConstants.ITEM_PRODUCT_NAME).Value;
                string hwVersion   = firmwareElement.Element(XMLFirmwareConstants.ITEM_HW_VERSION).Value;
                if (!hwVersion.ToUpper().StartsWith(ParsingUtils.HEXADECIMAL_PREFIX))
                {
                    if (!ParsingUtils.IsInteger(hwVersion))
                    {
                        hwVersion = MXIHardwareVersionDictionary.GetDictionaryValue(hwVersion.ToUpper());
                    }
                    else
                    {
                        string prefix = hwVersion.Length > 1 ? "0x" : "0x0";
                        hwVersion = prefix + hwVersion;
                    }
                }
                string compatibilityNumber  = firmwareElement.Element(XMLFirmwareConstants.ITEM_COMPATIBILITY_NUM).Value;
                string configBufferLocation = firmwareElement.Element(XMLFirmwareConstants.ITEM_CONFIG_BUFFER_LOC).Value;
                string flashPageSize        = firmwareElement.Element(XMLFirmwareConstants.ITEM_FLASH_PAGE_SIZE).Value;
                string crcBufferLength      = firmwareElement.Element(XMLFirmwareConstants.ITEM_CRC_BUFFER_LEN).Value;
                string functionSet          = firmwareElement.Element(XMLFirmwareConstants.ITEM_FUNCTION).Value;

                // Check if Region item exists.
                string region = "99";
                if (firmwareElement.Element(XMLFirmwareConstants.ITEM_REGION) != null)
                {
                    region = firmwareElement.Element(XMLFirmwareConstants.ITEM_REGION).Value;
                }

                // Generate the XBee firmware object.
                XBeeFirmware xbeeFirmware = new XBeeFirmware(family, productName, hwVersion,
                                                             compatibilityNumber, firmwareVersion, configBufferLocation, flashPageSize,
                                                             crcBufferLength, functionSet)
                {
                    // Set the region of the firmware.
                    Region = region,

                    // Set the content of the firmware.
                    DefinitionFileContent = new StreamReader(file.OpenRead()).ReadToEnd()
                };

                // Set the path of the definition file in the XBee firmware.
                xbeeFirmware.SetDefinitionFilePath(file.FullName);

                // Check if Modem item exists.
                if (firmwareElement.Element(XMLFirmwareConstants.ITEM_MODEM) != null)
                {
                    XElement modemElement = firmwareElement.Element(XMLFirmwareConstants.ITEM_MODEM);
                    if (modemElement.Element(XMLFirmwareConstants.ITEM_MODEM_VERISON) != null)
                    {
                        xbeeFirmware.ModemVersion = modemElement.Element(XMLFirmwareConstants.ITEM_MODEM_VERISON).Value;
                        if (modemElement.Element(XMLFirmwareConstants.ITEM_MODEM_URL) != null)
                        {
                            xbeeFirmware.ModemUrl = modemElement.Element(XMLFirmwareConstants.ITEM_MODEM_URL).Value;
                        }
                    }
                }

                // If a full parse is not needed, continue.
                if (!fullParse)
                {
                    xbeeFirmwares.Add(xbeeFirmware);
                    continue;
                }

                xbeeFirmware.Initialized = true;

                // Parse and add the categories with their corresponding settings.
                XElement categoriesElement = firmwareElement.Element(XMLFirmwareConstants.ITEM_CATEGORIES);
                if (categoriesElement != null)
                {
                    List <XBeeCategory> xbeeCategories = ParseCategories(categoriesElement, null, xbeeFirmware);
                    if (xbeeCategories != null && xbeeCategories.Count > 0)
                    {
                        xbeeFirmware.Categories = xbeeCategories;
                    }
                }

                xbeeFirmwares.Add(xbeeFirmware);
            }

            return(xbeeFirmwares);
        }