autosar_data_abstraction/communication/physical_channel/
lin.rs

1use crate::{
2    AbstractionElement, AutosarAbstractionError, IdentifiableAbstractionElement, abstraction_element,
3    communication::{
4        AbstractPhysicalChannel, LinCluster, LinCommunicationConnector, LinFrameTriggering, PhysicalChannel,
5    },
6};
7use autosar_data::{Element, ElementName};
8
9//##################################################################
10
11/// The `LinPhysicalChannel` contains all of the communication on a LIN network
12#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub struct LinPhysicalChannel(Element);
14abstraction_element!(LinPhysicalChannel, LinPhysicalChannel);
15impl IdentifiableAbstractionElement for LinPhysicalChannel {}
16
17impl LinPhysicalChannel {
18    /// get the cluster containing this physical channel
19    ///
20    /// # Example
21    ///
22    /// ```
23    /// # use autosar_data::*;
24    /// # use autosar_data_abstraction::*;
25    /// # use autosar_data_abstraction::communication::*;
26    /// # fn main() -> Result<(), AutosarAbstractionError> {
27    /// # let model = AutosarModelAbstraction::create("filename", AutosarVersion::Autosar_00048);
28    /// # let package = model.get_or_create_package("/pkg1")?;
29    /// # let system = package.create_system("System", SystemCategory::SystemExtract)?;
30    /// # let cluster = system.create_lin_cluster("Cluster", &package)?;
31    /// let channel = cluster.create_physical_channel("Channel")?;
32    /// let cluster_2 = channel.cluster()?;
33    /// assert_eq!(cluster, cluster_2);
34    /// # Ok(())}
35    /// ```
36    pub fn cluster(&self) -> Result<LinCluster, AutosarAbstractionError> {
37        let cluster_elem = self.0.named_parent()?.unwrap();
38        LinCluster::try_from(cluster_elem)
39    }
40
41    /// iterate over all frame triggerings of this physical channel
42    pub fn frame_triggerings(&self) -> impl Iterator<Item = LinFrameTriggering> + Send + use<> {
43        self.0
44            .get_sub_element(ElementName::FrameTriggerings)
45            .into_iter()
46            .flat_map(|elem| elem.sub_elements())
47            .filter_map(|elem| LinFrameTriggering::try_from(elem).ok())
48    }
49}
50
51impl From<LinPhysicalChannel> for PhysicalChannel {
52    fn from(channel: LinPhysicalChannel) -> Self {
53        PhysicalChannel::Lin(channel)
54    }
55}
56
57impl AbstractPhysicalChannel for LinPhysicalChannel {
58    type CommunicationConnectorType = LinCommunicationConnector;
59}