Ejemplo n.º 1
0
        // __ Helpers _____________________________________________________________


        private string GetClassName(MessageData m)
        {
            return string.Format("{0}{1}", DefaultMessageClassPrefix, Utils.GetPascalStyleString(m.Name));
        }
Ejemplo n.º 2
0
 private void WritePrivateFields(MessageData m)
 {
     foreach (FieldData f in m.Fields)
     {
         WL("        private {0}{1} {2}{3};",
            GetCSharpType(f), GetArrayModifier(f, false),
            GetPrivateFieldName(f), GetDefaultValue(f));
     }
 }
Ejemplo n.º 3
0
 private void WriteClassFooter(MessageData m)
 {
     WL("    }");
     WL();
 }
Ejemplo n.º 4
0
        private void WriteToString(MessageData m)
        {
            WL("        public override string ToString()");
            WL("        {");
            WL("            System.Text.StringBuilder sb = new System.Text.StringBuilder();");
            WL();
            WL("            sb.Append(\"{0} \\n\");", Utils.GetPascalStyleString(m.Name));

            foreach (FieldData f in m.Fields)
            {
                if (f.NumElements == 1)
                {
                    WL("            sb.AppendFormat(\"    {0}: {{0}}\\n\", {1});", GetFieldName(f), GetPrivateFieldName(f));
                }
                else
                {
                    WL("            sb.Append(\"    {0}\\n\");", GetFieldName(f));
                    for (int i = 0; i < f.NumElements; ++i)
                    {
                        WL("            sb.AppendFormat(\"        [{1}]: {{0}}\\n\", {2}[{1}]);", GetFieldName(f), i, GetPrivateFieldName(f));
                    }
                }
            }

            WL();
            WL("            return sb.ToString();");
            WL("        }");
            WL();
        }
Ejemplo n.º 5
0
        private void WriteInitMetadata(MessageData m)
        {
            WL("        protected override void InitMetadata()");
            WL("        {");
            WL("            mMetadata = new UasMessageMetadata() {");
            WL("                Description = \"{0}\"", GetSanitizedComment(m.Description));
            WL("            };");
            WL();

            foreach (FieldData f in m.Fields)
            {
                WL("            mMetadata.Fields.Add(new UasFieldMetadata() {");
                WL("                Name = \"{0}\",", GetFieldName(f));
                WL("                Description = \"{0}\",", GetSanitizedComment(f.Description));
                WL("                NumElements = {0},", f.NumElements);
                
                if (f.IsEnum)
                {
                    EnumData en = mProtocolData.Enumerations[f.EnumType];

                    if (en == null) continue;

                    WL("                EnumMetadata = UasSummary.GetEnumMetadata(\"{0}\"),", GetEnumName(en.Name));
                }
                
                WL("            });");
                WL();
            }

            WL("        }");
            WL();
        }
Ejemplo n.º 6
0
        private void WriteSerialize(MessageData m)
        {
            WL("        internal override void SerializeBody(BinaryWriter s)");
            WL("        {");

            foreach (FieldData f in m.Fields)
            {
                if (f.NumElements <= 1)
                {
                    WL("            s.Write({0}{1});", GetSerializeTypeCast(f), GetPrivateFieldName(f));
                }
                else
                {
                    for (int i = 0; i < f.NumElements; ++i)
                    {
                        WL("            s.Write({0}{1}[{2}]); ",
                           GetSerializeTypeCast(f), GetPrivateFieldName(f), i);
                    }
                }
            }

            WL("        }");
            WL();
        }
Ejemplo n.º 7
0
        private void WriteDeserialize(MessageData m)
        {
            WL("        internal override void DeserializeBody(BinaryReader s)");
            WL("        {");

            foreach (FieldData f in m.Fields)
            {
                int numElements = f.NumElements;

                if (numElements <= 1)
                {
                    WL("            this.{0} = {1}s.{2}();",
                       GetPrivateFieldName(f), GetEnumTypeCast(f), GetReadOperation(f));
                }
                else
                {
                    for (int i = 0; i < numElements; ++i)
                    {
                        WL("            this.{0}[{1}] = {2}s.{3}();",
                           GetPrivateFieldName(f), i, GetEnumTypeCast(f), GetReadOperation(f));
                    }
                }
            }

            WL("        }");
            WL();
        }
Ejemplo n.º 8
0
        private void WriteProperties(MessageData m)
        {
            foreach (FieldData f in m.Fields)
            {
                if (f.Description != null)
                {
                    WL("        /// <summary>");
                    WL("        /// {0}", GetSanitizedComment(f.Description));
                    WL("        /// </summary>");
                }

                WL("        public {0}{1} {2} {{", GetCSharpType(f), GetArrayModifier(f, false), GetFieldName(f));
                WL("            get {{ return {0}; }}", GetPrivateFieldName(f));
                WL("            set {{ {0} = value; NotifyUpdated(); }}", GetPrivateFieldName(f));
                WL("        }");
                WL();
            }
        }
Ejemplo n.º 9
0
 private void WriteConstructor(MessageData m)
 {
     WL("        public {0}()", GetClassName(m));
     WL("        {");
     WL("            mMessageId = {0};", m.Id);
     WL("            CrcExtra = {0};", GetMessageExtraCrc(m));
     WL("        }");
     WL();
 }
Ejemplo n.º 10
0
        // __ Impl _______________________________________________________


        private void Parse(XmlTextReader reader, ProtocolData result)
        {
            ProtocolObject currentObject = null;
            MessageData currentMsg = null;
            FieldData currentField = null;
            EnumData currentEnum = null;
            EnumEntry currentEntry = null;
            EnumEntryParameter currentParam = null;
            int currentEnumValue = 0;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                        case "include":
                            ProcessInclude(reader.ReadElementContentAsString(), result);
                            break;
                        case "version":
                            result.Version = reader.ReadElementContentAsInt();
                            break;
                        case "message":
                            if (currentMsg != null) SortFields(currentMsg);
                            currentMsg = new MessageData();
                            currentObject = currentMsg;
                            currentMsg.Name = reader.GetAttribute("name");
                            currentMsg.Id = GetIntFromString(reader.GetAttribute("id"));
                            result.Messages.Add(currentMsg.Name, currentMsg);
                            break;
                        case "description": 
                            currentObject.Description = reader.ReadString();
                            break;
                        case "field":
                            currentField = new FieldData();
                            currentField.Name = reader.GetAttribute("name");
                            currentField.TypeString = reader.GetAttribute("type");
                            currentField.Type = GetFieldTypeFromString(currentField.TypeString);
                            currentField.NumElements = GetFieldTypeNumElements(currentField.TypeString);
                            currentField.Description = reader.ReadElementContentAsString();
                            UpdateEnumFields(result, currentField);
                            currentMsg.Fields.Add(currentField);
                            break;
                        case "enum":
                            currentEnum = GetEnumDataForName(result, reader.GetAttribute("name"));
                            currentObject = currentEnum;
                            result.Enumerations[currentEnum.Name] = currentEnum;
                            currentEnumValue = 0;
                            break;
                        case "entry":
                            currentEntry = new EnumEntry();
                            currentObject = currentEntry;
                            currentEntry.Name = reader.GetAttribute("name");
                            currentEntry.Value = GetIntFromString(reader.GetAttribute("value"), ++currentEnumValue);
                            currentEnumValue = currentEntry.Value;
                            currentEnum.Entries.Add(currentEntry);
                            break;
                        case "param":
                            currentParam = new EnumEntryParameter();
                            currentParam.Index = GetIntFromString(reader.GetAttribute("index"));
                            currentParam.Description = reader.ReadElementContentAsString();
                            currentEntry.Parameters.Add(currentParam);
                            break;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        // __ Code generators class ___________________________________________


        private void WriteClassHeader(MessageData m)
        {
            WL();
            WL("    // ___________________________________________________________________________________");
            WL();
            WL();

            if (m.Description != null)
            {
                WL("    /// <summary>");
                WL("    /// {0}", GetSanitizedComment(m.Description));
                WL("    /// </summary>");
            }

            WL("    public class {0}: UasMessage", GetClassName(m));
            WL("    {");
        }
Ejemplo n.º 12
0
        private static void SortFields(MessageData obj)
        {
            // Sort by field size first, then by the order the fields already have. 

            List<FieldData> L8 = new List<FieldData>();
            List<FieldData> L4 = new List<FieldData>();
            List<FieldData> L2 = new List<FieldData>();
            List<FieldData> L1 = new List<FieldData>();

            foreach (FieldData f in obj.Fields)
            {
                switch (f.Type)
                {
                    case FieldDataType.CHAR:
                    case FieldDataType.INT8:
                    case FieldDataType.UINT8:
                        L1.Add(f);
                        break;
                    case FieldDataType.INT16:
                    case FieldDataType.UINT16:
                        L2.Add(f);
                        break;
                    case FieldDataType.INT64:
                    case FieldDataType.UINT64:
                    case FieldDataType.DOUBLE:
                        L8.Add(f);
                        break;
                    default: 
                        L4.Add(f);
                        break;
                }
            }

            List<FieldData> result = new List<FieldData>();
            result.AddRange(L8);
            result.AddRange(L4);
            result.AddRange(L2);
            result.AddRange(L1);

            obj.Fields = result;
        }
Ejemplo n.º 13
0
        // __ Helpers _____________________________________________________________


        private string GetClassName(MessageData m)
        {
            return(string.Format("{0}{1}", DefaultMessageClassPrefix, Utils.GetPascalStyleString(m.Name)));
        }
Ejemplo n.º 14
0
 private void WriteClassFooter(MessageData m)
 {
     WL("    }");
     WL();
 }
Ejemplo n.º 15
0
        // __ Impl _______________________________________________________


        private void Parse(XmlTextReader reader, ProtocolData result)
        {
            ProtocolObject     currentObject = null;
            MessageData        currentMsg    = null;
            FieldData          currentField  = null;
            EnumData           currentEnum   = null;
            EnumEntry          currentEntry  = null;
            EnumEntryParameter currentParam  = null;
            int currentEnumValue             = 0;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "include":
                        ProcessInclude(reader.ReadElementContentAsString(), result);
                        break;

                    case "version":
                        result.Version = reader.ReadElementContentAsInt();
                        break;

                    case "message":
                        // if (currentMsg != null) SortFields(currentMsg);   //<--- if condition deleted
                        currentMsg      = new MessageData();
                        currentObject   = currentMsg;
                        currentMsg.Name = reader.GetAttribute("name");
                        currentMsg.Id   = GetIntFromString(reader.GetAttribute("id"));
                        if (currentMsg.Id < 256)        // Msg id field is a byte, discard anything beyond 255
                        {
                            result.Messages.Add(currentMsg.Name, currentMsg);
                        }
                        break;

                    case "description":
                        currentObject.Description = reader.ReadString();
                        break;

                    case "field":
                        currentField             = new FieldData();
                        currentField.Name        = reader.GetAttribute("name");
                        currentField.TypeString  = reader.GetAttribute("type");
                        currentField.Type        = GetFieldTypeFromString(currentField.TypeString);
                        currentField.NumElements = GetFieldTypeNumElements(currentField.TypeString);
                        currentField.Description = reader.ReadElementContentAsString();
                        UpdateEnumFields(result, currentField);
                        currentMsg.Fields.Add(currentField);
                        break;

                    case "enum":
                        currentEnum   = GetEnumDataForName(result, reader.GetAttribute("name"));
                        currentObject = currentEnum;
                        result.Enumerations[currentEnum.Name] = currentEnum;
                        currentEnumValue = 0;
                        break;

                    case "entry":
                        currentEntry       = new EnumEntry();
                        currentObject      = currentEntry;
                        currentEntry.Name  = reader.GetAttribute("name");
                        currentEntry.Value = GetIntFromString(reader.GetAttribute("value"), ++currentEnumValue);
                        currentEnumValue   = currentEntry.Value;
                        currentEnum.Entries.Add(currentEntry);
                        break;

                    case "param":
                        currentParam             = new EnumEntryParameter();
                        currentParam.Index       = GetIntFromString(reader.GetAttribute("index"));
                        currentParam.Description = reader.ReadElementContentAsString();
                        currentEntry.Parameters.Add(currentParam);
                        break;
                    }
                }
                else     //<----- Else condition added to control closing of the current node; *** BEGIN ****
                {
                    if (reader.Name == "message")
                    {
                        if (currentMsg != null)
                        {
                            SortFields(currentMsg);
                        }
                    }
                } //<----- *** END ***
            }
        }
Ejemplo n.º 16
0
        // __ Impl _______________________________________________________


        private void Parse(XmlTextReader reader, ProtocolData result)
        {
            ProtocolObject     currentObject = null;
            MessageData        currentMsg    = null;
            FieldData          currentField  = null;
            EnumData           currentEnum   = null;
            EnumEntry          currentEntry  = null;
            EnumEntryParameter currentParam  = null;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "include":
                        ProcessInclude(reader.ReadElementContentAsString(), result);
                        break;

                    case "version":
                        result.Version = reader.ReadElementContentAsInt();
                        break;

                    case "message":
                        if (currentMsg != null)
                        {
                            SortFields(currentMsg);
                        }
                        currentMsg      = new MessageData();
                        currentObject   = currentMsg;
                        currentMsg.Name = reader.GetAttribute("name");
                        currentMsg.Id   = GetIntFromString(reader.GetAttribute("id"));
                        result.Messages.Add(currentMsg.Name, currentMsg);
                        break;

                    case "description":
                        currentObject.Description = reader.ReadString();
                        break;

                    case "field":
                        currentField             = new FieldData();
                        currentField.Name        = reader.GetAttribute("name");
                        currentField.TypeString  = reader.GetAttribute("type");
                        currentField.Type        = GetFieldTypeFromString(currentField.TypeString);
                        currentField.NumElements = GetFieldTypeNumElements(currentField.TypeString);
                        currentField.Description = reader.ReadElementContentAsString();
                        UpdateEnumFields(result, currentField);
                        currentMsg.Fields.Add(currentField);
                        break;

                    case "enum":
                        currentEnum   = GetEnumDataForName(result, reader.GetAttribute("name"));
                        currentObject = currentEnum;
                        result.Enumerations[currentEnum.Name] = currentEnum;
                        break;

                    case "entry":
                        currentEntry       = new EnumEntry();
                        currentObject      = currentEntry;
                        currentEntry.Name  = reader.GetAttribute("name");
                        currentEntry.Value = GetIntFromString(reader.GetAttribute("value"));
                        currentEnum.Entries.Add(currentEntry);
                        break;

                    case "param":
                        currentParam             = new EnumEntryParameter();
                        currentParam.Index       = GetIntFromString(reader.GetAttribute("index"));
                        currentParam.Description = reader.ReadElementContentAsString();
                        currentEntry.Parameters.Add(currentParam);
                        break;
                    }
                }
            }
        }