rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
can_listener.h
Go to the documentation of this file.
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
13public:
14 CanListener(uint32_t id)
15 : m_id(id)
16 {
17 }
18
19 CanListener* processFrame(const size_t busIndex, const CANRxFrame& frame, efitick_t nowNt) {
20 if (acceptFrame(busIndex, frame)) {
21 decodeFrame(frame, nowNt);
22 }
23
24 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 virtual bool acceptFrame(const size_t busIndex, const CANRxFrame& frame) const {
46 /* accept from all buses */
47 (void)busIndex;
48
49 return CAN_ID(frame) == m_id;
50 }
51
52protected:
53 virtual void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) = 0;
54
55private:
56 CanListener* m_next = nullptr;
57
58 const uint32_t m_id;
59};
CanListener * processFrame(const size_t busIndex, const CANRxFrame &frame, efitick_t nowNt)
virtual void decodeFrame(const CANRxFrame &frame, efitick_t nowNt)=0
bool hasNext() const
virtual CanListener * request()
uint32_t getId()
CanListener(uint32_t id)
const uint32_t m_id
virtual bool acceptFrame(const size_t busIndex, const CANRxFrame &frame) const
CanListener * m_next
void setNext(CanListener *next)