Skip to content

Commit

Permalink
Support base / implementation / application data types
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielT committed Aug 5, 2024
1 parent cfbdf03 commit f15ac5d
Show file tree
Hide file tree
Showing 17 changed files with 1,809 additions and 57 deletions.
46 changes: 45 additions & 1 deletion autosar-data-abstraction/src/communication/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ pub trait AbstractCluster: AbstractionElement {
let path = self.element().path().ok()?;
let refs = model.get_references_to(&path);

for system in refs
if let Some(system) = refs
.iter()
.filter_map(|weak| weak.upgrade())
.filter(|elem| elem.element_name() == ElementName::FibexElementRef)
.filter_map(|elem| elem.named_parent().ok().flatten())
.filter_map(|parent| System::try_from(parent).ok())
.next()
{
return Some(system);
}
Expand Down Expand Up @@ -76,3 +77,46 @@ impl From<FlexrayCluster> for Cluster {
Cluster::FlexRay(value)
}
}

//##################################################################

#[cfg(test)]
mod tests {
use super::*;
use crate::ArPackage;
use autosar_data::{AutosarModel, AutosarVersion};

#[test]
fn cluster_system() {
let model = AutosarModel::new();
let _file = model.create_file("test.arxml", AutosarVersion::LATEST).unwrap();
let package = ArPackage::get_or_create(&model, "/Test").unwrap();
let system = System::new("System", &package, crate::SystemCategory::EcuExtract).unwrap();
let settings = CanClusterSettings::default();
let can_cluster = CanCluster::new("CanCluster", &package, &settings).unwrap();

assert!(can_cluster.system().is_none());
system.create_fibex_element_ref(can_cluster.element()).unwrap();
assert_eq!(can_cluster.system().unwrap(), system);
}

#[test]
fn cluster_conversion() {
let model = AutosarModel::new();
let _file = model.create_file("test.arxml", AutosarVersion::LATEST).unwrap();
let package = ArPackage::get_or_create(&model, "/Test").unwrap();
let can_settings = CanClusterSettings::default();
let can_cluster = CanCluster::new("CanCluster", &package, &can_settings).unwrap();
let ethernet_cluster = EthernetCluster::new("EthernetCluster", &package).unwrap();
let flexray_settings = FlexrayClusterSettings::default();
let flexray_cluster = FlexrayCluster::new("FlexrayCluster", &package, &flexray_settings).unwrap();

let can: Cluster = can_cluster.into();
let ethernet: Cluster = ethernet_cluster.into();
let flexray: Cluster = flexray_cluster.into();

assert_eq!(can.element().item_name().unwrap(), "CanCluster");
assert_eq!(ethernet.element().item_name().unwrap(), "EthernetCluster");
assert_eq!(flexray.element().item_name().unwrap(), "FlexrayCluster");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl EthernetCommunicationController {
.get_or_create_sub_element(ElementName::VlanMemberships)
.and_then(|vms| vms.create_sub_element(ElementName::VlanMembership))
.and_then(|vm| vm.create_sub_element(ElementName::VlanRef))
.and_then(|vr| vr.set_reference_target(&eth_channel.element()))?;
.and_then(|vr| vr.set_reference_target(eth_channel.element()))?;
}
}

Expand Down
28 changes: 28 additions & 0 deletions autosar-data-abstraction/src/communication/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,31 @@ impl From<FlexrayCommunicationController> for CommunicationController {
CommunicationController::Flexray(value)
}
}

//##################################################################

#[cfg(test)]
mod tests {
use crate::{ArPackage, EcuInstance};
use super::*;
use autosar_data::{AutosarModel, AutosarVersion};

#[test]
fn test_communication_controller() {
let model = AutosarModel::new();
let _file = model.create_file("test.arxml", AutosarVersion::LATEST).unwrap();
let package = ArPackage::get_or_create(&model, "/test").unwrap();
let ecu = EcuInstance::new("ecu", &package).unwrap();
let can = CanCommunicationController::new("can", &ecu).unwrap();
let ethernet = EthernetCommunicationController::new("ethernet", &ecu, None).unwrap();
let flexray = FlexrayCommunicationController::new("flexray", &ecu).unwrap();

let can_cc: CommunicationController = can.into();
let ethernet_cc: CommunicationController = ethernet.into();
let flexray_cc: CommunicationController = flexray.into();

assert_eq!(can_cc.element().item_name().unwrap(), "can");
assert_eq!(ethernet_cc.element().item_name().unwrap(), "ethernet");
assert_eq!(flexray_cc.element().item_name().unwrap(), "flexray");
}
}
11 changes: 5 additions & 6 deletions autosar-data-abstraction/src/communication/pdu/isignal_idpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ impl ISignalIPdu {
if self
.mapped_signals()
.filter_map(|mapping| mapping.signal_group())
.find(|grp| grp == &signal_group)
.is_none()
.any(|grp| grp == signal_group)
{
return Err(AutosarAbstractionError::InvalidParameter(
"Cannot map signal to pdu, because it is part of an unmapped signal group.".to_string(),
Expand All @@ -83,7 +82,7 @@ impl ISignalIPdu {

// add a pdu triggering for the newly mapped PDU to each frame triggering of this frame
for pt in self.pdu_triggerings() {
let st = pt.add_signal_triggering(&signal)?;
let st = pt.add_signal_triggering(signal)?;
for pdu_port in pt.pdu_ports() {
if let (Some(ecu), Some(direction)) = (pdu_port.ecu(), pdu_port.communication_direction()) {
st.connect_to_ecu(&ecu, direction)?;
Expand All @@ -103,7 +102,7 @@ impl ISignalIPdu {
ISignalToIPduMapping::new(
&name,
&mappings,
&signal,
signal,
start_position,
byte_order,
update_bit,
Expand All @@ -122,7 +121,7 @@ impl ISignalIPdu {

// add a pdu triggering for the newly mapped PDU to each frame triggering of this frame
for pt in self.pdu_triggerings() {
let st = pt.add_signal_group_triggering(&signal_group)?;
let st = pt.add_signal_group_triggering(signal_group)?;
for pdu_port in pt.pdu_ports() {
if let (Some(ecu), Some(direction)) = (pdu_port.ecu(), pdu_port.communication_direction()) {
st.connect_to_ecu(&ecu, direction)?;
Expand All @@ -139,7 +138,7 @@ impl ISignalIPdu {
.element()
.get_or_create_sub_element(ElementName::ISignalToPduMappings)?;

ISignalToIPduMapping::new_group(&name, &mappings, &signal_group)
ISignalToIPduMapping::new_group(&name, &mappings, signal_group)
}

pub fn pdu_triggerings(&self) -> PduTriggeringsIterator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ impl EthernetPhysicalChannel {

//##################################################################

///
/// A SocketConnectionBundle describes a connection between a server port and multiple client ports.
/// It contains multiple bundled connections, each transporting one or more PDUs.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SocketConnectionBundle(Element);
abstraction_element!(SocketConnectionBundle, SocketConnectionBundle);
Expand Down Expand Up @@ -458,7 +459,7 @@ impl SocketConnectionBundle {

//##################################################################

///
/// A socketConnection inside a SocketConnectionBundle describes a single connection to a specific client port.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SocketConnection(Element);
abstraction_element!(SocketConnection, SocketConnection);
Expand Down Expand Up @@ -675,7 +676,9 @@ impl SocketConnection {

//##################################################################

///
/// A static socket connection is a connection between two sockets.
///
/// This is the new way to establish a connection. It was introduced in Autosar 4.5.0 (AUTOSAR_00048).
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StaticSocketConnection(Element);
abstraction_element!(StaticSocketConnection, StaticSocketConnection);
Expand Down Expand Up @@ -738,7 +741,7 @@ impl StaticSocketConnection {

//##################################################################

///
/// A SocketConnectionIpduIdentifierSet contains a set of SoConIPduIdentifiers, which are used in static socket connections.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SocketConnectionIpduIdentifierSet(Element);
abstraction_element!(SocketConnectionIpduIdentifierSet, SocketConnectionIpduIdentifierSet);
Expand Down Expand Up @@ -777,7 +780,7 @@ impl SocketConnectionIpduIdentifierSet {

//##################################################################

///
/// A SoConIPduIdentifier describes a PDU that is transported over a static socket connection.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SoConIPduIdentifier(Element);
abstraction_element!(SoConIPduIdentifier, SoConIPduIdentifier);
Expand Down Expand Up @@ -898,6 +901,7 @@ impl SoConIPduIdentifier {

//##################################################################

/// The role of a TCP connection in a static socket connection cna either be `Connect` (=client) or `Listen` (=server).
pub enum TcpRole {
Connect,
Listen,
Expand Down
Loading

0 comments on commit f15ac5d

Please sign in to comment.