Line | Branch | Exec | Source |
---|---|---|---|
1 | #pragma once | ||
2 | |||
3 | #include "safety_declarations.h" | ||
4 | |||
5 | 56320 | void default_rx_hook(const CANPacket_t *to_push) { | |
6 | UNUSED(to_push); | ||
7 | 56320 | } | |
8 | |||
9 | // *** no output safety mode *** | ||
10 | |||
11 | 22 | static safety_config nooutput_init(uint16_t param) { | |
12 | UNUSED(param); | ||
13 | 22 | return (safety_config){NULL, 0, NULL, 0}; | |
14 | } | ||
15 | |||
16 | // GCOV_EXCL_START | ||
17 | // cppcheck-suppress misra-c2012-2.1; Unreachable by design (no msgs match). | ||
18 | − | static bool nooutput_tx_hook(const CANPacket_t *to_send) { | |
19 | UNUSED(to_send); | ||
20 | − | return false; | |
21 | } | ||
22 | // GCOV_EXCL_STOP | ||
23 | |||
24 | 33792 | static int default_fwd_hook(int bus_num, int addr) { | |
25 | UNUSED(bus_num); | ||
26 | UNUSED(addr); | ||
27 | 33792 | return -1; | |
28 | } | ||
29 | |||
30 | const safety_hooks nooutput_hooks = { | ||
31 | .init = nooutput_init, | ||
32 | .rx = default_rx_hook, | ||
33 | .tx = nooutput_tx_hook, | ||
34 | .fwd = default_fwd_hook, | ||
35 | }; | ||
36 | |||
37 | // *** all output safety mode *** | ||
38 | |||
39 | // Enables passthrough mode where relay is open and bus 0 gets forwarded to bus 2 and vice versa | ||
40 | static bool alloutput_passthrough = false; | ||
41 | |||
42 | 14 | static safety_config alloutput_init(uint16_t param) { | |
43 | // Enables passthrough mode where relay is open and bus 0 gets forwarded to bus 2 and vice versa | ||
44 | 14 | const uint16_t ALLOUTPUT_PARAM_PASSTHROUGH = 1; | |
45 | 14 | controls_allowed = true; | |
46 | 14 | alloutput_passthrough = GET_FLAG(param, ALLOUTPUT_PARAM_PASSTHROUGH); | |
47 | 14 | return (safety_config){NULL, 0, NULL, 0}; | |
48 | } | ||
49 | |||
50 | 22528 | static bool alloutput_tx_hook(const CANPacket_t *to_send) { | |
51 | UNUSED(to_send); | ||
52 | 22528 | return true; | |
53 | } | ||
54 | |||
55 | 16896 | static int alloutput_fwd_hook(int bus_num, int addr) { | |
56 | 16896 | int bus_fwd = -1; | |
57 | UNUSED(addr); | ||
58 | |||
59 |
2/2✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 8448 times.
|
16896 | if (alloutput_passthrough) { |
60 |
2/2✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 5632 times.
|
8448 | if (bus_num == 0) { |
61 | 2816 | bus_fwd = 2; | |
62 | } | ||
63 |
2/2✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 5632 times.
|
8448 | if (bus_num == 2) { |
64 | 2816 | bus_fwd = 0; | |
65 | } | ||
66 | } | ||
67 | |||
68 | 16896 | return bus_fwd; | |
69 | } | ||
70 | |||
71 | const safety_hooks alloutput_hooks = { | ||
72 | .init = alloutput_init, | ||
73 | .rx = default_rx_hook, | ||
74 | .tx = alloutput_tx_hook, | ||
75 | .fwd = alloutput_fwd_hook, | ||
76 | }; | ||
77 |