Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /** | |||
2 | * @file can_listener.h | |||
3 | * | |||
4 | * @date March 31, 2021 | |||
5 | * @author Matthew Kennedy, (c) 2021 | |||
6 | */ | |||
7 | ||||
8 | #pragma once | |||
9 | ||||
10 | #include "can.h" | |||
11 | ||||
12 | class CanListener { | |||
13 | public: | |||
14 | 12 | CanListener(uint32_t id) | ||
15 | 12 | : m_id(id) | ||
16 | { | |||
17 | 12 | } | ||
18 | ||||
19 | 14 | CanListener* processFrame(const size_t busIndex, const CANRxFrame& frame, efitick_t nowNt) { | ||
20 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 time.
|
2/2✓ Decision 'true' taken 13 times.
✓ Decision 'false' taken 1 time.
|
14 | if (acceptFrame(busIndex, frame)) { |
21 | 13 | decodeFrame(frame, nowNt); | ||
22 | } | |||
23 | ||||
24 | 13 | return m_next; | ||
25 | } | |||
26 | ||||
27 | uint32_t getId() { | |||
28 | return m_id; | |||
29 | } | |||
30 | ||||
31 | void setNext(CanListener* next) { | |||
32 | m_next = next; | |||
33 | } | |||
34 | ||||
35 | ✗ | virtual CanListener* request() { | ||
36 | ✗ | return m_next; | ||
37 | } | |||
38 | ||||
39 | bool hasNext() const { | |||
40 | return m_next; | |||
41 | } | |||
42 | ||||
43 | // Return true if the provided frame should be accepted for processing by the listener. | |||
44 | // Override if you need more complex logic than comparing to a single ID. | |||
45 | 2 | virtual bool acceptFrame(const size_t busIndex, const CANRxFrame& frame) const { | ||
46 | /* accept from all buses */ | |||
47 | (void)busIndex; | |||
48 | ||||
49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | return CAN_ID(frame) == m_id; | |
50 | } | |||
51 | ||||
52 | protected: | |||
53 | virtual void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) = 0; | |||
54 | ||||
55 | private: | |||
56 | CanListener* m_next = nullptr; | |||
57 | ||||
58 | const uint32_t m_id; | |||
59 | }; | |||
60 |