ace_server/sim_node.rs
1// region: Imports
2
3use crate::{
4 handler::ServerHandler,
5 security_provider::SecurityProvider,
6 server::{ServerError, UdsServer},
7 MAX_FRAME, MAX_OUTBOX,
8};
9use ace_sim::node::SimNode;
10
11// endregion: Imports
12
13// region: SimNode for UdsServer
14
15impl<H, S> SimNode<MAX_FRAME, MAX_OUTBOX> for UdsServer<H, S>
16where
17 H: ServerHandler,
18 S: SecurityProvider,
19{
20 type Error = ServerError<H::Error>;
21
22 fn address(&self) -> &ace_sim::io::NodeAddress {
23 UdsServer::address(self)
24 }
25
26 /// Delivers a raw UDS frame to the server.
27 ///
28 /// The SimRunner calls this after the SimBus delivers a message. Errors are returned to
29 /// the runner - in simulation these are observed and recorded. In production the transport
30 /// layer decides whether to reset or continue.
31 fn handle(
32 &mut self,
33 src: &ace_sim::io::NodeAddress,
34 data: &[u8],
35 now: ace_sim::clock::Instant,
36 ) -> Result<(), Self::Error> {
37 UdsServer::handle(self, src, data, now)
38 }
39
40 /// Advances internal timers.
41 ///
42 /// Called by the SimRunner on every tick regardless of whether any messages were
43 /// delivered. Drives the S3 watchdog and periodic DID scheduling.
44 fn tick(&mut self, now: ace_sim::clock::Instant) -> Result<(), Self::Error> {
45 UdsServer::tick(self, now)
46 }
47
48 /// Drains pending outbound frames into `out`.
49 ///
50 /// The SimRunner collects these after every handle and tick call and routes them back onto
51 /// the SimBus.
52 fn drain_outbox(
53 &mut self,
54 out: &mut heapless::Vec<
55 (ace_sim::io::NodeAddress, heapless::Vec<u8, MAX_FRAME>),
56 MAX_OUTBOX,
57 >,
58 ) -> usize {
59 UdsServer::drain_outbox(self, out)
60 }
61}
62
63// endregion: SimNode for UdsServer