예제 #1
0
        /// <summary>
        /// 写文本文件
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public static bool Writer(string Content, string FilePath)
        {
            bool check = false;

            if (!File.Exists(FilePath))
            {
                return(false);
            }
            StreamWriter Sw;

            Sw = File.AppendText(FilePath);
            try
            {
                Sw.WriteLine(Content);
                check = true;
            }
            catch
            {
                check = false;
            }
            finally
            {
                Sw.Close();
                Sw = null;
            }

            return(check);
        }
예제 #2
0
 /// <summary>
 /// 输出组信息命令流
 /// </summary>
 void ExptGroups()
 {
     Sw.WriteLine("*GROUP");
     for (int i = 0; i < Model.Groups.Count; i++)
     {
         string     groupi_name = Model.Groups[i].Gname;
         List <int> groupi_no   = Model.Groups[i].Ele_no;
         groupi_no.Sort();
         List <string> groupi_DomList  = FunctionClass.GetDomain(groupi_no);
         List <string> groupi_DomList2 = FunctionClass.mergeList(groupi_DomList, 60);//单元列表改为每一行60个字符
         string        cmd             = null;
         for (int j = 0; j < groupi_DomList2.Count; j++)
         {
             if (j == 0)
             {
                 cmd = groupi_name + "," + " " + "," + groupi_DomList2[0];
             }
             else
             {
                 cmd = groupi_DomList2[j];
             }
             Sw.WriteLine(cmd);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Generates defines liens for generic and specific types. One line for each define:
 /// </summary>
 private void Generate_SpecificDevice()
 {
     if (GenericDeviceList != null)
     {
         foreach (GenericDevice gDev in GenericDeviceList)
         {
             //if (gDev.KeyId < 0xE0 || gDev.KeyId >= 0xFF)
             {
                 Sw.WriteLine("/* Device class {0} */",
                     Tools.CutUpperUnderscoreToMixedUpperLower(gDev.Name, Options1.ChGenericDeviceNamePrefix,
                         " "));
                 Generate_DefineLine(gDev, 0);
                 if (CommonSpecificDeviceList != null)
                     foreach (SpecificDevice entrySpecific in CommonSpecificDeviceList)
                     {
                         Generate_DefineLine(entrySpecific, 0);
                     }
                 if (gDev.SpecificDevice != null)
                     foreach (SpecificDevice entrySpecific in gDev.SpecificDevice)
                     {
                         Generate_DefineLine(entrySpecific, 0);
                     }
                 Sw.WriteLine("");
             }
         }
     }
 }
예제 #4
0
 private static void LogMessage(string message)
 {
     if (null != Sw)
     {
         Sw.WriteLine(message);
     }
     Console.Error.WriteLine(message);
 }
예제 #5
0
 private void Save()
 {
     if (mSettingsNeedSaving)
     {
         string       newSettings = Path.Combine(Path.GetDirectoryName(mSettingsFile), "new." + Path.GetFileName(mSettingsFile));
         StreamWriter Sw;
         Sw = File.CreateText(newSettings);
         foreach (KeyValuePair <string, string> setting in mSettings)
         {
             Sw.WriteLine(setting.Key + mSeparator + setting.Value);
         }
         Sw.Close();
     }
 }
예제 #6
0
        void Write(LogLevel logLevel, EventId eventId, string message, Exception ex)
        {
            EnsureInitFile();

            //TODO 提高效率 队列写!!!
            var log = String.Concat(DateTime.Now.ToString("HH:mm:ss"), '[', logLevel.ToString(), ']', '[',
                                    Thread.CurrentThread.ManagedThreadId.ToString(), ',', eventId.Id.ToString(), ',', eventId.Name, ']',
                                    Delimiter, message, Delimiter, ex?.ToString());

            lock (this)
            {
                Sw.WriteLine(log);
            }
        }
예제 #7
0
 /// <summary>
 /// 输出梁单元荷载
 /// </summary>
 void ExptBLoad()
 {
     Sw.WriteLine("*STLDCASE");
     Sw.WriteLine("    DeadLoad,D,");
     Sw.WriteLine("    LiveLoad,L,");
     Sw.WriteLine("*USE-STLD,DeadLoad");
     Sw.WriteLine("*SELFWEIGHT");
     Sw.WriteLine("0,0,-1");
     Sw.WriteLine("*BEAMLOAD");
     for (int i = 0; i < Model.BeamLoads.Count; i++)
     {
         BeamLoadCls loadi = Model.BeamLoads[i];
         Sw.WriteLine("   {0},Beam,UNILOAD,{1},NO,NO,aDir[1], , , , 0,{2},1,{2},0,0,0,0,,NO,0,0,NO,", loadi.EleNo, loadi.CoordDir, loadi.Value);
     }
 }
 public void Write()
 {
     Sw.WriteLine("infoText:{0}", InfoText);
     Sw.WriteLine();
     Sw.WriteLine("dictionaryAbbreviation:{0}", DictionaryAbbreviation);
     Sw.WriteLine("numberOfAvailableLanguages:2");
     Sw.WriteLine();
     Sw.WriteLine(@"indexFileSeparationCharacter:'\t'");
     Sw.WriteLine(@"searchListFileSeparationCharacter:'\t'");
     Sw.WriteLine(@"dictionaryFileSeparationCharacter:'\t'");
     Sw.WriteLine(@"dictionaryGenerationSeparatorCharacter:'\t'");
     Sw.WriteLine();
     Sw.WriteLine("dictionaryGenerationInputCharEncoding:UTF-8");
     Sw.WriteLine("indexCharEncoding:UTF-8");
     Sw.WriteLine("searchListCharEncoding:UTF-8");
     Sw.WriteLine("dictionaryCharEncoding:UTF-8");
     Sw.WriteLine();
     Sw.WriteLine("dictionaryGenerationOmitParFromIndex:true");
     Sw.WriteLine();
     Sw.WriteLine("language1DisplayText:{0}", _displayText[1]);
     Sw.WriteLine("language1FilePostfix:{0}", _filePostfix[1]);
     Sw.WriteLine();
     Sw.WriteLine("language1IsSearchable:true");
     Sw.WriteLine("language1GenerateIndex:true");
     Sw.WriteLine("language1HasSeparateDictionaryFile:false");
     Sw.WriteLine();
     Sw.WriteLine("language2DisplayText:{0}", _displayText[2]);
     Sw.WriteLine("language2FilePostfix:{0}", _filePostfix[2]);
     Sw.WriteLine();
     Sw.WriteLine("language2IsSearchable:true");
     Sw.WriteLine("language2GenerateIndex:true");
     Sw.WriteLine("language2HasSeparateDictionaryFile:false");
     Sw.WriteLine();
     Sw.WriteLine("language1NumberOfContentDeclarations:{0}", Language1NumberOfContentDeclarations);
     Sw.WriteLine("language2NumberOfContentDeclarations:1");
     for (int n = 1; n <= Language1NumberOfContentDeclarations; n++)
     {
         Sw.WriteLine("language1Content{0:D2}DisplayText:{1}", n, _styles.DisplayText(n));
         Sw.WriteLine("language1Content{0:D2}FontColour:{1}", n, _styles.FontColor(n));
         Sw.WriteLine("language1Content{0:D2}FontStyle:{1}", n, _styles.ContentStyle(n));
         Sw.WriteLine("language1Content{0:D2}DisplaySelectable:true", n);
     }
     Sw.WriteLine();
     Sw.WriteLine("language2Content01DisplayText:Gloss");
     Sw.WriteLine("language2Content01FontColour:128,0,0");
     Sw.WriteLine("language2Content01FontStyle:plain");
     Sw.WriteLine("language2Content01DisplaySelectable:true");
 }
예제 #9
0
 /// <summary>
 /// 输出壳元命令流
 /// </summary>
 void ExptShells()
 {
     for (int k = 0; k < Model.ShellElements.Count; k++)
     {
         ShellElementCls shellk          = Model.ShellElements[k];
         List <int>      shellK_nodesInd = shellk.Nodes_no;
         if (shellK_nodesInd.Count == 3)
         {
             Sw.WriteLine("    {0},PLATE,{1},{2},{3},{4},{5},0,3,0", shellk.Ele_no, shellk.Mat, shellk.Prop, shellK_nodesInd[0] + 1, shellK_nodesInd[1] + 1, shellK_nodesInd[2] + 1);
         }
         if (shellK_nodesInd.Count == 4)
         {
             Sw.WriteLine("    {0},PLATE,{1},{2},{3},{4},{5},{6},3,0", shellk.Ele_no, shellk.Mat, shellk.Prop, shellK_nodesInd[0] + 1, shellK_nodesInd[1] + 1, shellK_nodesInd[2] + 1, shellK_nodesInd[3] + 1);
         }
     }
 }
예제 #10
0
        public override bool WrtFile(string logString, string logLevel, string module, DateTime date)
        {
            var file = new FileInfo(NameFile);

            if (!file.Exists)
            {
                file.Create().Dispose();
            }
            lock (LockObj)
            {
                Sw = File.AppendText(NameFile);
                Sw.WriteLine($"{date} | {logLevel} | {logString} | {module}");
            }


            return(true);
        }
예제 #11
0
 /// <summary>
 /// 输出节点和梁单元命令流
 /// </summary>
 void ExptNodesBeams()
 {
     //输出节点信息
     Sw.WriteLine("*UNIT");
     Sw.WriteLine("N,MM,J,C");
     Sw.WriteLine("*NODE");
     for (int i = 0; i < Model.Nodes.Count; i++)
     {
         Sw.WriteLine("    {0},{1},{2},{3}", i + 1, Model.Nodes[i].X, Model.Nodes[i].Y, Model.Nodes[i].Z);
     }
     //输出梁单元信息
     Sw.WriteLine("*ELEMENT");
     for (int j = 0; j < Model.BeamElements.Count; j++)
     {
         BeamElementCls beami         = Model.BeamElements[j];
         List <int>     beamiNodesInd = beami.Nodes_no;
         if (beamiNodesInd.Count == 2)
         {
             Sw.WriteLine("    {0},BEAM,{1},{2},{3},{4},{5},{6}", beami.Ele_no, beami.Mat, beami.Prop, beamiNodesInd[0] + 1, beamiNodesInd[1] + 1, beami.Beta, 0);
         }
     }
 }
예제 #12
0
    public void WriteToExcel_By_DS(DataSet DS1, string path, string filename)
    {
        //  this function is used for wiring data in excel..... ds will be called which is alrady filled.  Waheed
        // Try
        StreamWriter Sw;
        DataRow      DR;
        // Dim str, fn, s As String
        string str = "";
        string s;
        int    I;
        int    J;
        int    x;
        int    i1;
        int    i2;
        int    no;
        int    page;
        string PATH1 = (path + "\\");

        no   = 1;
        page = 0;
        x    = DS1.Tables[0].Columns.Count;
        J    = DS1.Tables[0].Rows.Count;
        if (J == 0)
        {
            return;
        }
        //if (J != 0)
        //{
        Sw = File.CreateText((PATH1 + (filename + ".xls")));
        for (i2 = 0; (i2 <= (x - 1)); i2++)
        {
            str = str + DS1.Tables[0].Columns[i2].ColumnName + "\t";
        }
        Sw.WriteLine(str);
        //}
        //else
        //{
        for (I = 0; (I <= (J - 1)); I++)
        {
            if ((((page % 60000) == 0) || (page == 0)))
            {
                if ((page != 0))
                {
                    Sw.Close();
                }
                if ((no > 1))
                {
                    Sw = File.CreateText((PATH1 + (filename + (no + (" - " + (DateTime.UtcNow.AddHours(5.5).ToString("dd-MMM-yy") + ".xls"))))));
                }
                else
                {
                    Sw = File.CreateText((PATH1 + (filename + (" - " + (DateTime.UtcNow.AddHours(5.5).ToString("dd-MMM-yy") + ".xls")))));
                }
                // If page <> 0 Then
                //     Sw.Close()
                // End If
                no = (no + 1);
                for (i2 = 0; (i2 <= (x - 1)); i2++)
                {
                    str = str + DS1.Tables[0].Columns[i2].ColumnName + "\t";
                }
                Sw.WriteLine(str);
                str = "";
            }
            page = (page + 1);
            DR   = DS1.Tables[0].Rows[I];
            for (i1 = 0; (i1 <= (x - 1)); i1++)
            {
                if (Information.IsDBNull(DR[i1]))
                {
                    s = " ";
                }
                else
                {
                    s = DR[i1].ToString();
                }
                if (Information.IsNumeric(s))
                {
                    if ((Math.Round(Convert.ToDouble(s), 0).ToString().Length > 10))
                    {
                        str = str + "\'" + s + "\t";
                    }
                    else
                    {
                        str = str + "" + s + "\t";
                    }
                }
                else
                {
                    str = str + "" + s + "\t";
                }
            }
            Sw.WriteLine(str);
            str = "";
        }
        //}
        Sw.Close();
        Sw.Dispose();
        // Catch ex As Exception
        // Finally
        //   If con.State = ConnectionState.Open Then con.Close()
        // End Try
    }
예제 #13
0
 /// <summary>
 /// Writes a define line using the stream writer instance by calling Generate_DefineLineStr.
 /// For arguments documentation see Generate_DefineLineStr 
 /// </summary>
 private void Generate_DefineLine(string name, byte key, string comment, int version)
 {
     Sw.WriteLine(Generate_DefineLineStr(name, key, comment, version));
 }
예제 #14
0
 /// <summary>
 /// Generates current date time stamp comment
 /// </summary>
 private void Generate_Info()
 {
     Sw.WriteLine(LineComment + "Generated on: " + DateTime.Now);
 }
예제 #15
0
 private void Generate_Version(string version)
 {
     Sw.WriteLine($" * @version {version}");
 }
예제 #16
0
        /// <summary>
        /// Generates Command Defines in the following format
        /// </summary>
        /// <code>
        /// /* xxxx command class commands */
        /// #define XXXX_VERSION   0xHH
        /// </code>
        /// <example>
        /// For param key of type STRUCT_uint8_t the following is generated:
        /// <code>
        /// /* Values used for xxxx command */
        /// #define YYYY_ZZZZ_MASK 0x3F
        /// #define YYYY_ZZZZ_BIT_MASK 0x80
        /// #define YYYY_ZZZZ_SHIFT 0x05
        /// </code>
        /// For param key of type ENUM the following is generated
        /// <code>
        /// #define YYYY_ZZZZ_WWWW VVVV
        /// </code>
        /// For param key of type CONST the following is generated
        /// <code>
        /// #define YYYY_FLAGNAME FLAGMASK
        /// </code>
        /// where,<br/>
        /// XXXX is the command class name.<br/>
        /// YYYY is the command name.<br/>
        /// ZZZZ is the is the field name  (ParamField.Name).<br/>
        /// _BIT is added if ParamField.fieldName equals "bitflag".<br/>
        /// WWWW is the name of the enum (name attribute).<br/>
        /// VVVV is the hexadecimal value of the key attribute.<br/>
        /// FLAGNAME is the value of the flagname attribute in the const tag.<br/>
        /// FLAGMASK is the value of the flagmask attribute in the const tag.<br/>
        /// </example>        
        private void Generate_Command_Def(bool keepLegacyExceptions)
        {
            //Sw.WriteLine(Generate_DefineLineStr("APP_SMODE", 0x00, "application specific", 1));
            //Sw.WriteLine(Generate_DefineLineStr("TX_SMODE", 0x01, "sending node: support; receiving node: control", 1));
            //Sw.WriteLine(Generate_DefineLineStr("RX_SMODE", 0x02, "sending node: control; receiving node: support", 1));
            //Sw.WriteLine(Generate_DefineLineStr("TX_RX_SMODE", 0x03, "sending node: support; receiving node: support", 1));
            //Sw.WriteLine();
            foreach (CommandClass cmdClass in CommandClassList)
            {
                if (cmdClass.KeyId == 0x59)
                {
                }
                if (cmdClass.KeyId == 0 || cmdClass.KeyId >= 0x20)
                {
                    Sw.WriteLine("/* {0} command class commands */",
                        Tools.CutUpperUnderscoreToMixedUpperLower(cmdClass.Name, Options1.ChCommandClassPrefix, " "));
                    Generate_DefineLine(
                        Tools.CutString(cmdClass.Name, Options1.ChCommandClassPrefix) +
                        Options1.ChCommandClassVersionPostfix, cmdClass.Version, "", cmdClass.Version);
                    Generate_Defines(cmdClass.Command);

                    if (!keepLegacyExceptions)
                    {
                        if (cmdClass.DefineSet != null && cmdClass.DefineSet.Count > 0)
                        {
                            Sw.WriteLine("/* Values used for {0} command class */",
                                Tools.UpperUnderscoreToMixedUpperLower(cmdClass.Name, " "));
                            foreach (DefineSet dSet in cmdClass.DefineSet)
                            {
                                bool isMultiarray = dSet.Define.Aggregate(true, (current, df) => current & df.Define1 != null);
                                if (isMultiarray)
                                {
                                    foreach (var groupItem in dSet.Define)
                                    {
                                        foreach (var item in groupItem.Define1)
                                        {
                                            Sw.WriteLine(Generate_DefineLineStr(
                                                cmdClass.Name + "_" + Tools.MakeLegalUpperCaseIdentifier(dSet.Name) +
                                                "_" + Tools.MakeLegalUpperCaseIdentifier(item.Name), item.KeyId, "",
                                                cmdClass.Version));
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var item in dSet.Define)
                                    {
                                        Sw.WriteLine(Generate_DefineLineStr(
                                            cmdClass.Name + "_" + Tools.MakeLegalUpperCaseIdentifier(dSet.Name) + "_" +
                                            Tools.MakeLegalUpperCaseIdentifier(item.Name), item.KeyId, "",
                                            cmdClass.Version));
                                    }
                                }
                            }
                        }
                    }

                    if (cmdClass.Command != null)
                        foreach (Command cmd in cmdClass.Command)
                        {
                            //DCP_LIST_SET
                            ArrayList defineLines = new ArrayList();
                            if (cmd.Bits > 0 && cmd.Bits < 8)
                            {
                                defineLines.Add(Generate_DefineLineStr(cmd.Name + "_MASK",
                                    Tools.GetMaskFromBits(cmd.Bits, (byte)(8 - cmd.Bits)), "", cmdClass.Version));
                            }
                            if (cmd.Param != null)
                                foreach (Param param in cmd.Param)
                                {
                                    if (cmd.Bits > 0 && cmd.Bits < 8 && param.Order == 0 && param.Param1 != null &&
                                        param.Param1.Count > 0)
                                    {
                                        defineLines.Add(Generate_DefineLineStr(
                                            cmd.Name + "_" + Tools.MakeLegalUpperCaseIdentifier(param.Param1[0].Text) +
                                            Options1.ChMaskPostfix, Tools.GetMaskFromBits((byte)(8 - cmd.Bits), 0),
                                            param.Comment, cmdClass.Version));
                                    }
                                    else if (param.Type == zwParamType.MARKER)
                                    {
                                        defineLines.Add(Generate_DefineLineStr(
                                            cmd.Name + "_" + Tools.MakeLegalUpperCaseIdentifier(param.Text),
                                            param.DefaultValue, param.Comment, cmdClass.Version));
                                    }
                                    else if (param.Param1 != null)
                                    {
                                        switch (param.Mode)
                                        {
                                            case ParamModes.Property:
                                                byte shifter = 0;
                                                foreach (var prm1 in param.Param1)
                                                {
                                                    string postfix = Options1.ChMaskPostfix;
                                                    if (prm1.Bits == 1)
                                                    {
                                                        postfix = Options1.ChBitPostfix + Options1.ChMaskPostfix;
                                                    }
                                                    defineLines.Add(Generate_DefineLineStr(
                                                        cmd.Name + "_" + Tools.MakeLegalUpperCaseIdentifier(param.Text) +
                                                        "_" + Tools.MakeLegalUpperCaseIdentifier(prm1.Text) + postfix,
                                                        Tools.GetMaskFromBits(prm1.Bits, shifter), param.Comment,
                                                        cmdClass.Version));

                                                    // shift definitions
                                                    if (prm1.Bits > 1 && shifter != 0 && shifter != 8)
                                                    {
                                                        defineLines.Add(Generate_DefineLineStr(
                                                            cmd.Name + "_" +
                                                            Tools.MakeLegalUpperCaseIdentifier(param.Text) + "_" +
                                                            Tools.MakeLegalUpperCaseIdentifier(prm1.Text) +
                                                            Options1.ChShiftPostfix, shifter, "", cmdClass.Version));
                                                    }
                                                    shifter += prm1.Bits;
                                                    if (keepLegacyExceptions)
                                                    {
                                                        if (prm1.Defines != null)
                                                        {
                                                            FillDefines(cmdClass, cmd, defineLines, prm1);
                                                        }
                                                    }
                                                }
                                                break;
                                            case ParamModes.VariantGroup:
                                                foreach (var prm1 in param.Param1)
                                                {
                                                    if (keepLegacyExceptions)
                                                    {
                                                        if (prm1.Defines != null)
                                                        {
                                                            FillDefines(cmdClass, cmd, defineLines, prm1);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    if (keepLegacyExceptions)
                                    {
                                        if (param.Defines != null)
                                        {
                                            FillDefines(cmdClass, cmd, defineLines, param);
                                        }
                                    }
                                }

                            if (defineLines.Count > 0)
                            {
                                Sw.WriteLine("/* Values used for {0} command */",
                                    Tools.UpperUnderscoreToMixedUpperLower(cmd.Name, " "));
                                foreach (string s in defineLines)
                                {
                                    Sw.WriteLine(s);
                                }
                            }
                        }
                    Sw.WriteLine("");
                }
            }
        }
예제 #17
0
 void ExptEnd()
 {
     Sw.WriteLine("*ENDDATA");
     Sw.Dispose();
 }
예제 #18
0
        private void Structs(CommandClass cmdClass, Command cmd, Param vgParam)
        {
            const string structPrefixVg = "VG";
            const string structPostfixVg = "VG";
            string structPrefix = cmd == null && vgParam != null ? structPrefixVg : "ZW";
            string structPostfix = cmd == null && vgParam != null ? structPostfixVg : "FRAME";

            const string structFieldFormat = "{0}{1,-10}{2,-30}{3}";
            if (cmd == null || cmd.Name == "CRC_16_ENCAP" ||
                !cmd.Name.EndsWith(Options1.ChEncapsulatedCommandIdentifier))
            {
                // determine if the command has Param.ParamType.VARIANT or Param.ParamType.BITMASK

                #region Determine count params and groups

                int structCount = 1;
                var list = new SortedList<string, Param>();
                list.Add("", null);

                IList<Param> parameters = null;
                if (cmd != null)
                {
                    parameters = cmd.Param;
                }
                else if (vgParam != null)
                {
                    parameters = vgParam.Param1;
                }

                if (parameters != null)
                    foreach (Param param in parameters)
                    {
                        if (param.SkipField)
                            continue;
                        if (param.Param1 != null && param.Param1.Count > 0 &&
                            (param.Size > 1 || param.SizeReference != null))
                        {
                            structCount = 4;
                            Structs(cmdClass, null, param);
                        }
                        else
                        {
                            if (param.Bits >= 8)
                            {
                                if (!list.ContainsKey(param.Name))
                                    list.Add(param.Name, param);
                                else
                                    throw new ApplicationException("Command " + cmd != null
                                        ? cmd.Name
                                        : vgParam.Name + " already has parameter " + param.Name);
                            }
                            if (param.Type == zwParamType.BITMASK && param.Size != 1 ||
                                param.SizeReference != null)
                            {
                                if (structCount == 4)
                                {
                                    SystemLogSingleton.Instance.DoAddLogLine(
                                        SystemLogSingleton.Category.Warning,
                                        SystemLogSingleton.Action.CodeGeneration,
                                        Tools.FormatStr("Multiple VARIANT/BITMASK found in command {0}",
                                            cmd != null ? cmd.Name : vgParam.Name)
                                    );
                                    break;
                                }
                                structCount = 4;
                            }
                        }
                    }

                #endregion

                string versionPostfix = "";
                if (cmdClass.Version > 1) versionPostfix = "_V" + cmdClass.Version;
                for (int structIdx = 1; structIdx <= structCount; structIdx++)
                {
                    string byteStr = "";
                    if (structCount > 1)
                    {
                        byteStr = "_" + structIdx + "BYTE";
                    }

                    Sw.WriteLine("/{0}/", DuplicateStr("*", 60));
                    if (cmd != null)
                    {
                        Sw.WriteLine("{0,-60}", GetTypeStructCaptionCmd(cmdClass, cmd, byteStr, versionPostfix));
                    }
                    else if (vgParam != null)
                    {
                        Sw.WriteLine("{0,-60}", GetTypeStructCaptionVg(cmdClass, vgParam, byteStr, versionPostfix));
                    }
                    Sw.WriteLine("/{0}/", DuplicateStr("*", 60));
                    if (cmd != null)
                    {
                        Sw.WriteLine("typedef struct _{0}_{1}_{2}_", structPrefix,
                            GetTypeStructNameCmd(cmdClass, cmd, byteStr, versionPostfix), structPostfix);
                    }
                    else if (vgParam != null)
                    {
                        Sw.WriteLine("typedef struct _{0}_{1}_{2}_", structPrefix,
                            GetTypeStructNameVg(cmdClass, vgParam, byteStr, versionPostfix), structPostfix);
                    }
                    Sw.WriteLine("{");
                    string tab1 = MakeTabs(1);
                    if (cmd != null)
                    {
                        Sw.WriteLine(structFieldFormat, tab1, "uint8_t", "cmdClass;", "/* The command class */");
                        string cmdName = "cmd;";
                        string cmdComment = "/* The command */";
                        if (cmd.Bits > 0 && cmd.Bits < 8)
                        {
                            if (cmd.Param != null && cmd.Param.Count > 0)
                            {
                                cmdName = "cmd_" + Tools.MakeLegalMixCaseIdentifier(cmd.Param[0].Param1[0].Text) +
                                          ";";
                                cmdComment = "/* The command + parameter " + cmd.Param[0].Param1[0].Text + " */";
                            }
                        }
                        Sw.WriteLine(structFieldFormat, tab1, "uint8_t", cmdName, cmdComment);
                    }

                    #region foreach params

                    parameters = cmd != null ? cmd.Param : vgParam.Param1;
                    if (parameters != null)
                        foreach (Param param in parameters)
                        {
                            if (cmd != null && cmd.Name.StartsWith("SECURITY_MESSAGE_ENCAPSULATION") &&
                                param.Name == "commandClassIdentifier")
                                continue;
                            if (cmd != null && cmd.Name.StartsWith("SECURITY_MESSAGE_ENCAPSULATION") &&
                                param.Name == "commandIdentifier")
                                continue;
                            if (param.SkipField)
                                continue;
                            if (cmd != null && cmd.Bits > 0 && cmd.Bits < 8 && param.Order == 0 &&
                                param.Param1 != null && param.Param1.Count > 0)
                            {
                            }
                            else if (param.Param1 != null && param.Param1.Count > 0 &&
                                     (param.Size > 1 || param.SizeReference != null))
                            {
                                for (int i = 1; i <= structIdx; i++)
                                {
                                    Sw.WriteLine(
                                        structFieldFormat,
                                        tab1,
                                        Tools.FormatStr("{0}_{1}_{2} ", structPrefixVg,
                                            GetTypeStructNameCmd(cmdClass, cmd, _lastVgByteStr, versionPostfix),
                                            structPostfixVg),
                                        Tools.MakeLegalMixCaseIdentifier("variantGroup" + i) + ";",
                                        "/*" + param.Comment + "*/");
                                }
                            }
                            else
                            {
                                string comment = "/*" + param.Comment + "*/";
                                if (param.Param1 != null && param.Param1.Count > 0 && param.Bits > 1)
                                {
                                    comment = "/* masked byte */";
                                }
                                int byteFieldCount = 0;
                                if (param.Type == zwParamType.BITMASK && param.Size != 1 ||
                                    param.SizeReference != null)
                                {
                                    byteFieldCount = structIdx;
                                }

                                else if (param.Bits % 8 == 0)
                                {
                                    if (param.Bits == 8 && param.Size <= 1)
                                    {
                                        byteFieldCount = 0;
                                        Sw.WriteLine(structFieldFormat, tab1, "uint8_t",
                                            Tools.MakeLegalMixCaseIdentifier(param.Text) + ";", comment);
                                    }
                                    else
                                    {
                                        byteFieldCount = param.Size <= 1
                                            ? param.Bits / 8
                                            : param.Size * (param.Bits / 8);
                                    }
                                }
                                //if (byteFieldCount > 0 && param.Size > 1 &&
                                //    !((param.Type == zwParamType.BITMASK && param.Size != 1) || param.SizeReference != null))
                                //{
                                //    sw.WriteLine(StructFieldFormat, tab1, "uint8_t", Tools.MakeLegalMixCaseIdentifier(param.Text) + "[" + byteFieldCount.ToString() + "];", comment);
                                //}
                                //else
                                //{
                                if (cmd != null && cmd.Name.StartsWith("SECURITY_MESSAGE_ENCAPSULATION") &&
                                    param.Name == "commandByte")
                                {
                                    Sw.WriteLine(structFieldFormat, tab1, "uint8_t", "commandClassIdentifier" + ";",
                                        "/**/");
                                    Sw.WriteLine(structFieldFormat, tab1, "uint8_t", "commandIdentifier" + ";",
                                        "/**/");
                                }
                                for (int i = 1; i <= byteFieldCount; i++)
                                {
                                    if (i == 1 && byteFieldCount > 1)
                                    {
                                        comment = "/* MSB */";
                                    }
                                    else if (i == byteFieldCount && byteFieldCount > 1)
                                    {
                                        comment = "/* LSB */";
                                    }
                                    else
                                    {
                                        comment = "";
                                    }
                                    if (param.Text.StartsWith("Receiver’s Entropy Input"))
                                    {
                                    }
                                    Sw.WriteLine(structFieldFormat, tab1, "uint8_t",
                                        Tools.MakeLegalMixCaseIdentifier(param.Text) + i + ";", comment);
                                }
                                //}
                            }
                        }

                    #endregion

                    Sw.Write("}");
                    if (cmd != null)
                    {
                        Sw.WriteLine(" {0}_{1}_{2};", structPrefix,
                            GetTypeStructNameCmd(cmdClass, cmd, byteStr, versionPostfix), structPostfix);
                    }
                    else
                    {
                        _lastVgByteStr = byteStr;
                        Sw.WriteLine(" {0}_{1}_{2};", structPrefix,
                            GetTypeStructNameVg(cmdClass, vgParam, byteStr, versionPostfix), structPostfix);
                    }
                    Sw.WriteLine("");
                }
            }
        }
예제 #19
0
 public void OutPutFile()
 {
     Sw.WriteLine("Hello this is abaqus inp ,under construction");
     Sw.Dispose();
 }