Пример #1
0
        private static void ParseMessage(XmlReader rdr, MavlinkMessageModel messageItem)
        {
            var depth          = rdr.Depth + 1;
            var extendedFields = false;

            do
            {
                rdr.Read();
                switch (rdr.Name)
                {
                case "description":
                    messageItem.Desc = ConvertDesc(rdr.ReadElementContentAsString());
                    break;

                case "field":
                    ParseMessageFields(rdr, messageItem, extendedFields);
                    break;

                case "extensions":
                    extendedFields = true;
                    break;
                }
            } while (rdr.Depth >= depth);

            messageItem.ReorderFieldsAndClacCrc();
            messageItem.CalculateLargestArray();
        }
Пример #2
0
        /// <summary>
        /// It's for Variable Length Arrays calculation
        /// </summary>
        /// <param name="src"></param>
        public static void CalculateLargestArray(this MavlinkMessageModel src)
        {
            var largestArray = src.Fields.Where(_ => _.IsArray).OrderByDescending(_ => _.FieldByteSize).FirstOrDefault();

            if (largestArray != null)
            {
                largestArray.IsTheLargestArrayInMessage = true;
            }
        }
Пример #3
0
        public static void ReorderFieldsAndClacCrc(this MavlinkMessageModel src)
        {
            src.Fields = src.Fields.OrderByDescending(_ => _.FieldTypeByteSize).ToList();

            var crc = X25Crc.Accumulate($"{src.Name} ", X25Crc.CrcSeed);

            crc          = src.Fields.Aggregate(crc, (acc, field) => field.CalculateCrc(acc));
            src.CrcExtra = (byte)((crc & 0xFF) ^ (crc >> 8));
        }
Пример #4
0
        private static void ParseMessagesSection(XmlReader rdr, IList <MavlinkMessageModel> protocolEnums)
        {
            var depth = rdr.Depth + 1;

            do
            {
                rdr.Read();
                if (rdr.Name == "message")
                {
                    var messageItem = new MavlinkMessageModel
                    {
                        Id   = int.Parse(rdr.GetAttribute("id")),
                        Name = rdr.GetAttribute("name"),
                    };
                    protocolEnums.Add(messageItem);
                    ParseMessage(rdr, messageItem);
                }
            } while (rdr.Depth >= depth);
        }
Пример #5
0
        private static void ParseMessageFields(XmlReader rdr, MavlinkMessageModel msg, bool extendedFields)
        {
            bool   isArray;
            byte   arrayLength;
            string baseTypeName;
            var    type   = ParseFieldType(rdr.GetAttribute("type"), out baseTypeName, out isArray, out arrayLength);
            var    fields = extendedFields ?  msg.ExtendedFields : msg.Fields;

            fields.Add(new MessageFieldModel
            {
                IsExtended        = extendedFields,
                Type              = type,
                TypeName          = FieldTypeToString(type),
                FieldTypeByteSize = type.GetFieldTypeByteSize(),
                IsArray           = isArray,
                ArrayLength       = arrayLength,
                Name              = rdr.GetAttribute("name"),
                Units             = rdr.GetAttribute("units"),
                Enum              = rdr.GetAttribute("enum"),
                Desc              = ConvertDesc(rdr.ReadElementContentAsString()),
            });
        }
Пример #6
0
 public static IEnumerable <MessageFieldModel> GetAllFields(this MavlinkMessageModel src)
 {
     return(src.Fields.Concat(src.ExtendedFields));
 }