• AUTOSAR配置工具开发教程 – 改造篇(方法创建)


    1、目的

    本文介绍在ARXML的自动解析库基础上如何进行修改,以支持配置工具的操作。

    2、模块配置模版 ECUCMODULEDEF

    2.1、ECUCMODULEDEF()

    ECUCMODULEDEF moduleDef:用于创建的模型模版

    ECUCMODULECONFIGURATIONVALUES moduleData:非空时,支持从配置数据创建

    string moduleDefParentPath:用于创建的父路径

    格式:/AUTOSAR/EcucDefs/CanIf/CanIfInitCfg

    1. public partial class ECUCMODULEDEF : INotifyPropertyChanged
    2. {
    3. public ECUCMODULEDEF(ECUCMODULEDEF moduleDef, ECUCMODULECONFIGURATIONVALUES moduleData, string moduleDefParentPath)
    4. {
    5. if (moduleDef != null)
    6. {
    7. this.PARAMTER_DEF_SHORT_NAME = moduleDef.SHORTNAME.Value;
    8. }
    9. if (moduleData != null)
    10. {
    11. this.SHORTNAME = moduleData.SHORTNAME;
    12. this.PARAMTER_DEF_FULL_URL_PATH = moduleData.DEFINITIONREF.Value;
    13. this.cONFIGURATIONVALUESField = moduleData;
    14. this.cONFIGURATIONCLASSField = moduleData.IMPLEMENTATIONCONFIGVARIANT;
    15. }
    16. else
    17. {
    18. this.SHORTNAME = moduleDef.SHORTNAME;
    19. this.PARAMTER_DEF_FULL_URL_PATH = moduleDefParentPath + "/" + moduleDef.SHORTNAME.Value;
    20. cONFIGURATIONVALUESField = new ECUCMODULECONFIGURATIONVALUES(moduleDef.SHORTNAME.Value, PARAMTER_DEF_FULL_URL_PATH);
    21. }
    22. this.LOWERMULTIPLICITY = moduleDef.LOWERMULTIPLICITY;
    23. this.UPPERMULTIPLICITY = moduleDef.UPPERMULTIPLICITY;
    24. this.UPPERMULTIPLICITYINFINITE = moduleDef.UPPERMULTIPLICITYINFINITE;
    25. this.REFINEDMODULEDEFREF = moduleDef.REFINEDMODULEDEFREF;
    26. this.DESC = moduleDef.DESC;
    27. this.INTRODUCTION = moduleDef.INTRODUCTION;
    28. this.LONGNAME = moduleDef.LONGNAME;
    29. this.SUPPORTEDCONFIGVARIANTS = moduleDef.SUPPORTEDCONFIGVARIANTS;
    30. CreateContainers(moduleDef, moduleData, moduleDefParentPath);
    31. }
    32. }

     2.2、CreateContainers()

    ECUCMODULEDEF moduleDef:用于创建的模型模版

    ECUCMODULECONFIGURATIONVALUES moduleData:非空时,支持从配置数据创建

    string moduleDefParentPath:用于创建的父路径

    1. public void CreateContainers(ECUCMODULEDEF moduleDef, ECUCMODULECONFIGURATIONVALUES moduleData, string moduleDefParentPath)
    2. {
    3. // 检查多重性为 (1:1)的子容器
    4. if (moduleDef.CONTAINERS != null)
    5. {
    6. //ObservableCollection containers = new ObservableCollection();
    7. //List containers = new List();
    8. this.CONTAINERS = new ObservableCollection();
    9. foreach (object container in moduleDef.CONTAINERS)
    10. {
    11. string containerType = container.GetType().ToString();
    12. if (containerType == Common.AR_NAME_SPACE + ".ECUCCHOICECONTAINERDEF")
    13. {
    14. if (Common.IsMultiplicityObject(container))
    15. {
    16. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCCHOICECONTAINERDEF)container,
    17. this.PARAMTER_DEF_FULL_URL_PATH,
    18. ((ECUCCHOICECONTAINERDEF)container).SHORTNAME.Value);
    19. paramContainer.IS_TOP_CONTAINER = true;
    20. CONTAINERS.Add(paramContainer);
    21. }
    22. }
    23. else if (containerType == Common.AR_NAME_SPACE + ".ECUCPARAMCONFCONTAINERDEF")
    24. {
    25. if (Common.IsMultiplicityObject(container))
    26. {
    27. // 创建虚拟容器
    28. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCPARAMCONFCONTAINERDEF)container,
    29. this.PARAMTER_DEF_FULL_URL_PATH,
    30. ((ECUCPARAMCONFCONTAINERDEF)container).SHORTNAME.Value);
    31. paramContainer.IS_TOP_CONTAINER = true;
    32. CONTAINERS.Add(paramContainer);
    33. }
    34. else if (Common.IsMandatoryObject(container))
    35. {
    36. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCPARAMCONFCONTAINERDEF)container,
    37. null,
    38. this.PARAMTER_DEF_FULL_URL_PATH,
    39. ((ECUCPARAMCONFCONTAINERDEF)container).SHORTNAME.Value, 1);
    40. paramContainer.IS_TOP_CONTAINER = true;
    41. CONTAINERS.Add(paramContainer);
    42. }
    43. }
    44. }
    45. }
    46. }
    47. 3、参数容器配置模版 ECUCPARAMCONFCONTAINERDEF

      多重性大于1时,需要为视图创建一个虚拟容器,用于包含所有集合实例:

      3.1、构造一:为多重性大于1的容器创建父容器,导入数据时调用 

      ECUCPARAMCONFCONTAINERDEF containerDef:配置模版参数容器

      ECUCCONTAINERVALUE containterData:配置数据参数容器

      1. public ECUCPARAMCONFCONTAINERDEF(ECUCPARAMCONFCONTAINERDEF containerDef, ECUCCONTAINERVALUE containterData)
      2. {
      3. if (containerDef != null)
      4. {
      5. this.SHORTNAME = new IDENTIFIER(containerDef.SHORTNAME.Value);
      6. string url = containterData.DEFINITIONREF.Value;/// +"/" + containerDef.SHORTNAME.Value;
      7. this.PARAMTER_DEF_FULL_URL_PATH = url;
      8. CONFIGURATIONVALUES = new ECUCCONTAINERVALUE(containerDef.SHORTNAME.Value, url);
      9. }
      10. MultConfcontainerBuildCommon(containerDef);
      11. }

      3.2、构造二:为多重性大于1的容器创建父容器,添加数据时调用 

      ECUCPARAMCONFCONTAINERDEF containerDef:配置模版参数容器

      string containerDefParentPath: 配置模版父容器路径

      string newName:新建容器名称

      1. public ECUCPARAMCONFCONTAINERDEF(ECUCPARAMCONFCONTAINERDEF containerDef, string containerDefParentPath, string newName)
      2. {
      3. if (containerDef != null)
      4. {
      5. this.SHORTNAME = new IDENTIFIER(newName);
      6. string url = containerDefParentPath + "/" + containerDef.SHORTNAME.Value;
      7. this.PARAMTER_DEF_FULL_URL_PATH = url;
      8. CONFIGURATIONVALUES = new ECUCCONTAINERVALUE(containerDef.SHORTNAME.Value, url);
      9. }
      10. MultConfcontainerBuildCommon(containerDef);
      11. }

      3.3、构造三:创建参数容器实例 

      ECUCPARAMCONFCONTAINERDEF containerDef:配置模版参数容器

      ECUCCONTAINERVALUE containterData:配置数据参数容器

      string containerDefParentPath:配置模版父容器路径

      string newName:新建容器名称

      1. public ECUCPARAMCONFCONTAINERDEF(ECUCPARAMCONFCONTAINERDEF containerDef, ECUCCONTAINERVALUE containterData, string containerDefParentPath, string newName)
      2. {
      3. if (containerDef != null)
      4. {
      5. bool isMultFlg = false;
      6. if (containerDef.SHORTNAME.Value == UrlHandle.GetAbsolutePathLastStringName(containerDefParentPath))
      7. {
      8. isMultFlg = true;
      9. }
      10. if (containerDef.PARAMETERS != null)
      11. {
      12. //List paramers = new List();
      13. this.PARAMETERS = new ObservableCollection<object>();
      14. foreach (Object defObject in containerDef.PARAMETERS)
      15. {
      16. Object paramer = ObjectHandle.CloneObject(defObject, Common.AR_DLL_NAME.GetType());
      17. IDENTIFIER shortName = (IDENTIFIER)(defObject.GetType().GetProperty("SHORTNAME").GetValue(defObject, null));
      18. string fullUrl = containerDefParentPath + "/" + shortName.Value;
      19. if (!isMultFlg)
      20. {
      21. fullUrl = containerDefParentPath + "/" + containerDef.SHORTNAME.Value + "/" + shortName.Value;
      22. }
      23. ((ECUCPARAMERSDEFBase)paramer).PARAMTER_DEF_FULL_URL_PATH = fullUrl;
      24. ((ECUCPARAMERSDEFBase)paramer).LoadDefaultValueIntoSetValue();
      25. this.PARAMETERS.Add(paramer);
      26. }
      27. //this.PARAMETERS = paramers.ToArray();
      28. }
      29. if (containerDef.REFERENCES != null)
      30. {
      31. List references = new List();
      32. foreach (Object defObject in containerDef.REFERENCES)
      33. {
      34. Object reference = ObjectHandle.CloneObject(defObject, Common.AR_DLL_NAME.GetType());
      35. IDENTIFIER shortName = (IDENTIFIER)(defObject.GetType().GetProperty("SHORTNAME").GetValue(defObject, null));
      36. string fullUrl = containerDefParentPath + "/" + shortName.Value;
      37. if (!isMultFlg)
      38. {
      39. fullUrl = containerDefParentPath + "/" + containerDef.SHORTNAME.Value + "/" + shortName.Value;
      40. }
      41. ((REFERENCESBase)reference).PARAMTER_DEF_FULL_URL_PATH = fullUrl;
      42. //((ECUCPARAMERSDEFBase)paramer).LoadDefaultValueIntoSetValue();
      43. if (reference != null)
      44. {
      45. references.Add(reference);
      46. }
      47. }
      48. this.REFERENCES = new ObservableCollection<object>();
      49. foreach (object obj in references)
      50. {
      51. this.REFERENCES.Add(obj);
      52. }
      53. }
      54. this.PARAMTER_DEF_SHORT_NAME = containerDef.SHORTNAME.Value;
      55. if (containterData != null) // 由数据加载到定义
      56. {
      57. this.SHORTNAME = containterData.SHORTNAME;
      58. string cTemplateStr = containterData.DEFINITIONREF.Value;
      59. this.PARAMTER_DEF_FULL_URL_PATH = cTemplateStr;
      60. this.CONFIGURATIONVALUES = containterData;
      61. }
      62. else
      63. {
      64. this.SHORTNAME = new IDENTIFIER(newName);
      65. // 多重性容器,补丁
      66. if (isMultFlg)
      67. {
      68. this.PARAMTER_DEF_FULL_URL_PATH = containerDefParentPath;
      69. // 该部分与module调用的构造函数不同之处
      70. this.LOWERMULTIPLICITY = containerDef.LOWERMULTIPLICITY;// TODO: 只有【1, 1】复杂度
      71. string[] LowerMulitplicityValue = { "1" };
      72. string[] UpperMulitplicityValue = { "1" };
      73. string[] UpperMulitplicityInfiniteValue = { "false" };
      74. POSITIVEINTEGERVALUEVARIATIONPOINT LowerMulitplicity = new POSITIVEINTEGERVALUEVARIATIONPOINT();
      75. LowerMulitplicity.Text = LowerMulitplicityValue;
      76. this.LOWERMULTIPLICITY = LowerMulitplicity;
      77. POSITIVEINTEGERVALUEVARIATIONPOINT UpperMulitplicity = new POSITIVEINTEGERVALUEVARIATIONPOINT();
      78. UpperMulitplicity.Text = UpperMulitplicityValue;
      79. this.UPPERMULTIPLICITY = UpperMulitplicity;
      80. BOOLEANVALUEVARIATIONPOINT UpperMulitplicityInfinite = new BOOLEANVALUEVARIATIONPOINT();
      81. UpperMulitplicityInfinite.Text = UpperMulitplicityInfiniteValue;
      82. }
      83. else
      84. {
      85. this.PARAMTER_DEF_FULL_URL_PATH = containerDefParentPath + "/" + containerDef.SHORTNAME.Value;
      86. this.LOWERMULTIPLICITY = containerDef.LOWERMULTIPLICITY;// TODO: 只有【1, 1】复杂度
      87. this.UPPERMULTIPLICITY = containerDef.UPPERMULTIPLICITY;
      88. this.UPPERMULTIPLICITYINFINITE = containerDef.UPPERMULTIPLICITYINFINITE;
      89. }
      90. this.INTRODUCTION = containerDef.INTRODUCTION;
      91. this.DESC = containerDef.DESC;
      92. CONFIGURATIONVALUES = new ECUCCONTAINERVALUE(containerDef.SHORTNAME.Value, PARAMTER_DEF_FULL_URL_PATH);
      93. }
      94. CreateSubContainer(containerDef, containterData, containerDefParentPath, newName);
      95. }
      96. }
      97. 3.4、创建子容器集

        ECUCPARAMCONFCONTAINERDEF containerDef:配置模版参数容器

        ECUCCONTAINERVALUE containterData:配置数据参数容器

        string containerDefParentPath:配置模版父容器路径

        string newNam:新建容器名称

        1. public void CreateSubContainer(ECUCPARAMCONFCONTAINERDEF containerDef, ECUCCONTAINERVALUE containterData, string containerDefParentPath, string newName)
        2. {
        3. // 检查多重性为 (1:1)的子容器
        4. if (containerDef.SUBCONTAINERS != null)
        5. {
        6. //List containers = new List();
        7. SUBCONTAINERS = new ObservableCollection<object>();
        8. foreach (object container in containerDef.SUBCONTAINERS)
        9. {
        10. string containerType = container.GetType().ToString();
        11. if (containerType == Common.AR_NAME_SPACE + ".ECUCCHOICECONTAINERDEF")
        12. {
        13. if (Common.IsMultiplicityObject(container))
        14. {
        15. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCCHOICECONTAINERDEF)container,
        16. this.PARAMTER_DEF_FULL_URL_PATH,
        17. ((ECUCCHOICECONTAINERDEF)container).SHORTNAME.Value);
        18. SUBCONTAINERS.Add(paramContainer);
        19. }
        20. else if (Common.IsMandatoryObject(container))
        21. {
        22. string newCondName = ((ECUCCHOICECONTAINERDEF)container).SHORTNAME.Value;
        23. ECUCCHOICECONTAINERDEF paramContainer = new ECUCCHOICECONTAINERDEF((ECUCCHOICECONTAINERDEF)container,
        24. null,
        25. this.PARAMTER_DEF_FULL_URL_PATH, newCondName);
        26. SUBCONTAINERS.Add(paramContainer);
        27. }
        28. }
        29. else if (containerType == Common.AR_NAME_SPACE + ".ECUCPARAMCONFCONTAINERDEF")
        30. {
        31. if (Common.IsMultiplicityObject(container))
        32. {
        33. if (containterData != null) // 加载配置数据时功能分支
        34. {
        35. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCPARAMCONFCONTAINERDEF)container,
        36. containterData.DEFINITIONREF.Value,
        37. ((ECUCPARAMCONFCONTAINERDEF)container).SHORTNAME.Value);
        38. SUBCONTAINERS.Add(paramContainer);
        39. }
        40. else // 无加载配置数据时功能分支
        41. {
        42. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCPARAMCONFCONTAINERDEF)container,
        43. this.PARAMTER_DEF_FULL_URL_PATH,
        44. ((ECUCPARAMCONFCONTAINERDEF)container).SHORTNAME.Value);
        45. SUBCONTAINERS.Add(paramContainer);
        46. }
        47. }
        48. else if (Common.IsMandatoryObject(container)) // Must create one.
        49. {
        50. string newCondName = ((ECUCPARAMCONFCONTAINERDEF)container).SHORTNAME.Value;
        51. ECUCPARAMCONFCONTAINERDEF paramContainer = new ECUCPARAMCONFCONTAINERDEF((ECUCPARAMCONFCONTAINERDEF)container, null, this.PARAMTER_DEF_FULL_URL_PATH, newCondName);
        52. SUBCONTAINERS.Add(paramContainer);
        53. }
        54. }
        55. }
        56. }
        57. }
        58. 相关阅读:
          538. 把二叉搜索树转换为累加树
          EditorConfig + Prettier + ESLint 代码规范化
          SpringBoot - Post请求-接收参数
          Socks5代理IP在跨境电商与网络游戏中的网络安全应用
          CentOS7系统下安装OpenOffice
          _cpp AVL树(map、set等关联式容器的底层结构)
          【历史上的今天】8 月 5 日:微信 5.0 发布;百度上市;LinkedIn 创始人诞生
          Java中的日期类整理
          智慧燃气巡检管理系统解决燃气管理问题
          九、多项式朴素贝叶斯算法(Multinomial NB,Multinomial Naive Bayes)(有监督学习)
        59. 原文地址:https://blog.csdn.net/xianghuaizi/article/details/137978155