当前位置: 首页 > news >正文

ARXML处理 - C#的解析代码(一)

目的

本文介绍通过AUTOSAR组织提供的xsd文件,自动生成对应的C#解析代码的框架。

自动生成方法:Microsoft SDKs\Windows\v7.0A\bin\xsd.exe

命令:xsd.exe AUTOSAR_4-0-3.xsd /c /l:CS /n:AUTOSAR4

AUTOSAR_4-0-3.xsd 是需要生成代码的xsd文件。

在C#环境下固定几个版本没有问题,其他AUTOSAR版本的xsd会在生成过程中产生循环组引用错误,不能生成代码。

适用版本

AUTOSAR版本XSD生成的C#库文件
4.0.3

【免费】AUTOSAR4.0.3的ARXML文件解析资源-CSDN文库

4.2.2【免费】AUTOSAR4.2.2的ARXML文件解析资源-CSDN文库
4.4.0

解析库的使用方法

// XmlFilePath: ARXML 文件路径
public static AUTOSAR ReadXmlToClass(string XmlFilePath)
{XmlSerializer xs = new XmlSerializer(typeof(AUTOSAR));using (FileStream fs = new FileStream(XmlFilePath, FileMode.Open)){return (AUTOSAR)xs.Deserialize(fs);}
}

生成的代码

代码头

以下是生成的代码头部部分,我们后续需要用到这个命名空间和类。当然直接生成的代码还是需要做补充,修改等操作。后续篇章会陆续进行介绍。

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行库版本:2.0.50727.3082
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------// 
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
// 
namespace AUTOSAR4 
{using System.Xml.Serialization;using System.Collections.ObjectModel;using System;/// <remarks/>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")][System.SerializableAttribute()][System.Diagnostics.DebuggerStepThroughAttribute()][System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(Namespace="http://autosar.org/schema/r4.0")][System.Xml.Serialization.XmlRootAttribute(Namespace="http://autosar.org/schema/r4.0",IsNullable=false)][System.Xml.Serialization.XmlSchemaProvider("http://autosar.org/schema/r4.0 AUTOSAR_4-0-3.xsd")]public partial class AUTOSAR {# 代码较大,此处省略.....}
}

配置模版关键类

AUTOSAR的ECU配置分成两个模型,即用来定义配置模版(M1)和配置数据(M0)。每个应用代码都是用配置数据来表示,配置数据里会引用到配置模版中。配置数据的解析在后续章节说明

如下图所示,这个配置数据是参考标准库的配置模版进行使用的。

        <ECUC-MODULE-CONFIGURATION-VALUES UUID="5327e39a-f8d9-423c-ba83-53c8806e66f9"><SHORT-NAME>CanIf</SHORT-NAME><DEFINITION-REF DEST="ECUC-MODULE-DEF">/AUTOSAR/EcucDefs/CanIf</DEFINITION-REF>

模块 MODULE (ECUCMODULEDEF)

该类用于处理模块,如CanIf, Com等。

    /// <remarks/>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")][System.SerializableAttribute()][System.Diagnostics.DebuggerStepThroughAttribute()][System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(TypeName="ECUC-MODULE-DEF", Namespace="http://autosar.org/schema/r4.0")]public partial class ECUCMODULEDEF {/// <remarks/>[System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCCHOICECONTAINERDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCPARAMCONFCONTAINERDEF), IsNullable=false)]# 容器集合,保护多个配置集;可以是参数容器,也可以是选择容器public object[] CONTAINERS {get {return this.cONTAINERSField;}set {this.cONTAINERSField = value;}}}

参数容器(ECUCPARAMCONFCONTAINERDEF)

相当于配置的文件夹

    /// <remarks/>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")][System.SerializableAttribute()][System.Diagnostics.DebuggerStepThroughAttribute()][System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(TypeName="ECUC-PARAM-CONF-CONTAINER-DEF", Namespace="http://autosar.org/schema/r4.0")]public partial class ECUCPARAMCONFCONTAINERDEF {/// <remarks/>[System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCADDINFOPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCBOOLEANPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCENUMERATIONPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCFLOATPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCFUNCTIONNAMEDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCINTEGERPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCLINKERSYMBOLDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCMULTILINESTRINGPARAMDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCSTRINGPARAMDEF), IsNullable=false)]# 配置参数集合public object[] PARAMETERS {get {return this.pARAMETERSField;}set {this.pARAMETERSField = value;}}/// <remarks/>[System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCCHOICEREFERENCEDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCFOREIGNREFERENCEDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCINSTANCEREFERENCEDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCREFERENCEDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCSYMBOLICNAMEREFERENCEDEF), IsNullable=false)]# 参考参数集合public object[] REFERENCES {get {return this.rEFERENCESField;}set {this.rEFERENCESField = value;}}/// <remarks/>[System.Xml.Serialization.XmlArrayAttribute("SUB-CONTAINERS")][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCCHOICECONTAINERDEF), IsNullable=false)][System.Xml.Serialization.XmlArrayItemAttribute(typeof(ECUCPARAMCONFCONTAINERDEF), IsNullable=false)]# 子容器集合,可以是参数容器,也可以是选择容器public object[] SUBCONTAINERS {get {return this.sUBCONTAINERSField;}set {this.sUBCONTAINERSField = value;}}}

选择容器(ECUCCHOICECONTAINERDEF)

可以选择不同类型的参数容器

    /// <remarks/>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")][System.SerializableAttribute()][System.Diagnostics.DebuggerStepThroughAttribute()][System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(TypeName="ECUC-CHOICE-CONTAINER-DEF", Namespace="http://autosar.org/schema/r4.0")]public partial class ECUCCHOICECONTAINERDEF {/// <remarks/>[System.Xml.Serialization.XmlArrayItemAttribute(IsNullable=false)]# 可选的参数容器集合,AUTOSAR配置过程中只能在这个集合中选择一个public ECUCPARAMCONFCONTAINERDEF[] CHOICES {get {return this.cHOICESField;}set {this.cHOICESField = value;}}
}

http://www.lryc.cn/news/335566.html

相关文章:

  • OJ 栓奶牛【C】【Python】【二分算法】
  • Spring6-单元测试:JUnit
  • ubuntu系统安装k8s1.28精简步骤
  • 探讨Java和Go语言的缺点
  • 短剧在线搜索PHP网站源码
  • Python map遍历
  • 数据结构—红黑树
  • MES实施之工控机和电脑的选择
  • 京东云服务器4核8G主机租用价格418元一年,1899元3年
  • 【多模态融合】MetaBEV 解决传感器故障 3D检测、BEV分割任务
  • [通俗易懂]《动手学强化学习》学习笔记1-第1章 初探强化学习
  • centOS如何升级python
  • 【MYSQL锁】透彻地理解MYSQL锁
  • 【静态分析】静态分析笔记01 - Introduction
  • 使用的sql
  • 【ZZULIOJ】1052: 数列求和4(Java)
  • 【Linux】tcpdump P3 - 过滤和组织返回信息
  • vscode免费登录ssh ,linux git配置免密码
  • Netty 心跳(heartbeat)——服务源码剖析(上)(四十一)
  • C语言—每日选择题—Day65
  • 【环境变量】基本概念理解 | 查看环境变量echo | PATH的应用和修改
  • 5.7Python之元组
  • Python 基于 OpenCV 视觉图像处理实战 之 OpenCV 简单视频处理实战案例 之一 简单视频放大抖动效果
  • 如何通过VPN访问内网?
  • RabbitMQ3.13.0起支持MQTT5.0协议及MQTT5.0特性功能列表
  • 常用脚本01 - 生成证书
  • 【jQuery】jQuery框架
  • 使用OMP复原一维信号(MATLAB)
  • Linux安装最新版Docker完整教程
  • iOS object-c self关键字总结