Matalb处理arxml 连线问题存储问题。
matlab储存下面信息用什么数据合适? 两个都在的接口: <ASSEMBLY-SW-CONNECTOR UUID="0F39C1F4-472A-4759-8BFE-675881C7D79E"> <SHORT-NAME>VehSpd_vAbsAvgVehicleSpeed_LifeCycle_vAbsAvgVehicleSpeed</SHORT-NAME> <PROVIDER-IREF> <CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/ComponentTypes/Application/VehSpd</CONTEXT-COMPONENT-REF> <TARGET-P-PORT-REF DEST="P-PORT-PROTOTYPE">/ComponentTypes/VehicleSpeedCalculation/vAbsAvgVehicleSpeed</TARGET-P-PORT-REF> </PROVIDER-IREF> <REQUESTER-IREF> <CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/ComponentTypes/Application/LifeCycle</CONTEXT-COMPONENT-REF> <TARGET-R-PORT-REF DEST="R-PORT-PROTOTYPE">/ComponentTypes/LifeCycle/vAbsAvgVehicleSpeed</TARGET-R-PORT-REF> </REQUESTER-IREF> </ASSEMBLY-SW-CONNECTOR> 只有输出outport: <DELEGATION-SW-CONNECTOR UUID="62BBAA41-0500-44A7-9547-8DFDE6043BDC"> <SHORT-NAME>EngState_sEngingRunningState_sEngingRunningState</SHORT-NAME> <INNER-PORT-IREF> <P-PORT-IN-COMPOSITION-INSTANCE-REF> <CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/ComponentTypes/Application/EngState</CONTEXT-COMPONENT-REF> <TARGET-P-PORT-REF DEST="P-PORT-PROTOTYPE">/ComponentTypes/EngineRunning/sEngineRunningState</TARGET-P-PORT-REF> </P-PORT-IN-COMPOSITION-INSTANCE-REF> </INNER-PORT-IREF> <OUTER-PORT-REF DEST="P-PORT-PROTOTYPE">/ComponentTypes/Application/sEngineRunningState</OUTER-PORT-REF> </DELEGATION-SW-CONNECTOR>
% 小工具:构造引用
ref = @(dest, path) struct('Dest', string(dest), 'Path', string(path));
bind = @(ctxDest, ctxPath, tgtDest, tgtPath) struct( ...'Context', ref(ctxDest, ctxPath), ...'TargetPort', ref(tgtDest, tgtPath));connectors = struct( ...'Type', {}, ...'UUID', {}, ...'ShortName',{}, ...'Provider', {}, ...'Requester',{}, ...'InnerPort',{}, ...'OuterPort',{} );% 1) ASSEMBLY-SW-CONNECTOR(双方端口都在)
connectors(1).Type = "Assembly";
connectors(1).UUID = "0F39C1F4-472A-4759-8BFE-675881C7D79E";
connectors(1).ShortName = "VehSpd_vAbsAvgVehicleSpeed_LifeCycle_vAbsAvgVehicleSpeed";
connectors(1).Provider = bind( ...'SW-COMPONENT-PROTOTYPE', '/ComponentTypes/Application/VehSpd', ...'P-PORT-PROTOTYPE', '/ComponentTypes/VehicleSpeedCalculation/vAbsAvgVehicleSpeed');
connectors(1).Requester = bind( ...'SW-COMPONENT-PROTOTYPE', '/ComponentTypes/Application/LifeCycle', ...'R-PORT-PROTOTYPE', '/ComponentTypes/LifeCycle/vAbsAvgVehicleSpeed');
connectors(1).InnerPort = struct([]);
connectors(1).OuterPort = struct([]);% 2) DELEGATION-SW-CONNECTOR(只有外部 Outport)
connectors(2).Type = "Delegation";
connectors(2).UUID = "62BBAA41-0500-44A7-9547-8DFDE6043BDC";
connectors(2).ShortName = "EngState_sEngingRunningState_sEngingRunningState";
connectors(2).Provider = struct([]);
connectors(2).Requester = struct([]);
connectors(2).InnerPort = bind( ...'SW-COMPONENT-PROTOTYPE', '/ComponentTypes/Application/EngState', ...'P-PORT-PROTOTYPE', '/ComponentTypes/EngineRunning/sEngineRunningState');
connectors(2).OuterPort = ref( ...'P-PORT-PROTOTYPE', '/ComponentTypes/Application/sEngineRunningState');
% 按类型筛选
isAssembly = strcmp({connectors.Type}, 'Assembly');
isDelegation = strcmp({connectors.Type}, 'Delegation');% 提取路径中最后一级名(如端口名)
extractLast = @(p) regexp(string(p), '[^/]+$', 'match', 'once');% 取第1个连接器的 Provider 目标端口名
provTgtName = extractLast(connectors(1).Provider.TargetPort.Path);% 若需建立快速索引(按 ShortName)
idxMap = containers.Map( ...{connectors.ShortName}, ...num2cell(1:numel(connectors)));
为什么这种结构合适
- 贴合 AUTOSAR 语义:Provider/Requester 与 Inner/Outer 的层次清晰。
- 易扩展:后续可加入 DataElement、InterfaceType、PortPrototype 属性等。
- 易于与 Simulink/AUTOSAR 工具链对接:Path/DEST 信息完整,便于解析与映射。
- 便于程序化处理:MATLAB 对 struct 数组支持良好,检索、过滤、映射都方便。
补充
- 若后续需要强类型校验与方法(如验证 DEST 合法性、自动拆解 Path),可进一步封装为 class(Connector、PortBinding、PortRef),但在多数数据处理场景下,struct 已足够轻量实用。
