Skip to main content

ace_server/
sim_node.rs

1// region: Imports
2
3use crate::{
4    handler::ServerHandler,
5    security_provider::SecurityProvider,
6    server::{ServerError, UdsServer},
7};
8use ace_core::Vec;
9use ace_sim::node::SimNode;
10
11// endregion: Imports
12
13// region: SimNode for UdsServer
14
15impl<
16        const MAX_FRAME: usize,
17        const MAX_OUTBOX: usize,
18        const MAX_SESSIONS: usize,
19        const MAX_SERVICES: usize,
20        const MAX_DIDS: usize,
21        const MAX_SECURITY_LEVELS: usize,
22        const DEFAULT_S3: u64,
23        const DEFAULT_P2: u64,
24        const DEFAULT_P2_EXT: u64,
25        const DEFAULT_LOCKOUT: u64,
26        const DEFAULT_MAX_SECURITY_ATTEMPTS: u8,
27        const MAX_SEED: usize,
28        const MAX_PERIODIC: usize,
29        H,
30        S,
31    > SimNode<MAX_FRAME, MAX_OUTBOX>
32    for UdsServer<
33        MAX_FRAME,
34        MAX_OUTBOX,
35        MAX_SESSIONS,
36        MAX_SERVICES,
37        MAX_DIDS,
38        MAX_SECURITY_LEVELS,
39        DEFAULT_S3,
40        DEFAULT_P2,
41        DEFAULT_P2_EXT,
42        DEFAULT_LOCKOUT,
43        DEFAULT_MAX_SECURITY_ATTEMPTS,
44        MAX_SEED,
45        MAX_PERIODIC,
46        H,
47        S,
48    >
49where
50    H: ServerHandler,
51    S: SecurityProvider,
52{
53    type Error = ServerError<H::Error>;
54
55    fn address(&self) -> &ace_sim::io::NodeAddress {
56        UdsServer::address(self)
57    }
58
59    /// Delivers a raw UDS frame to the server.
60    ///
61    /// The SimRunner calls this after the SimBus delivers a message. Errors are returned to
62    /// the runner - in simulation these are observed and recorded. In production the transport
63    /// layer decides whether to reset or continue.
64    fn handle(
65        &mut self,
66        src: &ace_sim::io::NodeAddress,
67        data: &[u8],
68        now: ace_sim::clock::Instant,
69    ) -> Result<(), Self::Error> {
70        UdsServer::handle(self, src, data, now)
71    }
72
73    /// Advances internal timers.
74    ///
75    /// Called by the SimRunner on every tick regardless of whether any messages were
76    /// delivered. Drives the S3 watchdog and periodic DID scheduling.
77    fn tick(&mut self, now: ace_sim::clock::Instant) -> Result<(), Self::Error> {
78        UdsServer::tick(self, now)
79    }
80
81    /// Drains pending outbound frames into `out`.
82    ///
83    /// The SimRunner collects these after every handle and tick call and routes them back onto
84    /// the SimBus.
85    fn drain_outbox(
86        &mut self,
87        out: &mut Vec<(ace_sim::io::NodeAddress, Vec<u8, MAX_FRAME>), MAX_OUTBOX>,
88    ) -> usize {
89        UdsServer::drain_outbox(self, out)
90    }
91}
92
93// endregion: SimNode for UdsServer