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