Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : /** 4 : * Contains IntervalFilter class. 5 : * \file IntervalFilter.h 6 : * \ingroup filter 7 : */ 8 : #ifndef GUARD_F66B083F_F756_481B_A1D9_A9B2B549F8EE 9 : #define GUARD_F66B083F_F756_481B_A1D9_A9B2B549F8EE 10 : 11 : #include "can/canframes/CANFrame.h" 12 : #include "can/filter/IFilter.h" 13 : #include "can/filter/IMerger.h" 14 : 15 : #include <platform/estdint.h> 16 : 17 : namespace can 18 : { 19 : /** 20 : * Cpp2CAN IntervalFilter 21 : * 22 : * 23 : * \see IFilter 24 : */ 25 : class IntervalFilter : public IFilter 26 : { 27 : public: 28 : /** maximum id the filter may take */ 29 : static uint32_t const MAX_ID = CanId::Extended<CANFrame::MAX_FRAME_ID_EXTENDED>::value; 30 : 31 : /** 32 : * constructor 33 : * \post getLowerBound() == MAX_ID 34 : * \post getUpperBound() == 0x0 35 : * 36 : * Nothing wil be accepted by default 37 : */ 38 : IntervalFilter(); 39 : 40 : /** 41 : * constructor initializing an interval 42 : * \param from first id that will be accepted 43 : * \param to last id that will be accepted 44 : * \pre from <= MAX_ID 45 : * \pre to <= MAX_ID 46 : * \post getLowerBound() == from 47 : * \post getUpperBound() == to 48 : * 49 : * \note * If from or to exceed MAX_ID, they will be set to MAX_ID. 50 : */ 51 : explicit IntervalFilter(uint32_t from, uint32_t to); 52 : 53 : /** 54 : * \see IFilter::add() 55 : * \param filterId id to add to filter 56 : * \pre filterId <= MAX_ID, otherwise no effect 57 : * \post getLowerBound() == min(filterId, getLowerBound()) 58 : * \post getUpperBound() == max(filterId, getUpperBound()) 59 : * 60 : * \note * This call is equal to add(filterId, filterId). 61 : */ 62 : void add(uint32_t filterId) override; 63 : 64 : /** 65 : * \see IFilter::add() 66 : * \param from lower bound of interval to add 67 : * \param to upper bound of interval to add 68 : * \pre from <= MAX_ID 69 : * \pre to <= MAX_ID 70 : * \post getLowerBound() == min(from, getLowerBound()) 71 : * \post getUpperBound() == max(to, getUpperBound()) 72 : * 73 : * If from or to exceed MAX_ID, they will be set to MAX_ID. 74 : * 75 : * This call will not replace the current filter configuration, but 76 : * adjust lower and upper bound of the filter according to the parameters. 77 : */ 78 : void add(uint32_t from, uint32_t to) override; 79 : 80 : /** 81 : * checks if an id matches the filter 82 : * \param filterId id to check 83 : * \return * - true: filter matches filterId 84 : * - false: filterId is not in filters range 85 : */ 86 : bool match(uint32_t filterId) const override; 87 : 88 : /** 89 : * \see IFilter::acceptMerger() 90 : */ 91 6 : void acceptMerger(IMerger& merger) override { merger.mergeWithInterval(*this); } 92 : 93 : /** 94 : * \see IFilter::clear(); 95 : */ 96 : void clear() override; 97 : 98 : /** 99 : * \see IFilter::open(); 100 : */ 101 : void open() override; 102 : 103 : /** 104 : * \return lower bound of filter 105 : */ 106 22 : uint32_t getLowerBound() const { return _from; } 107 : 108 : /** 109 : * \return upper bound of filter 110 : */ 111 21 : uint32_t getUpperBound() const { return _to; } 112 : 113 : private: 114 : // fields 115 : uint32_t _from; 116 : uint32_t _to; 117 : }; 118 : 119 : } /*namespace can*/ 120 : 121 : #endif // GUARD_F66B083F_F756_481B_A1D9_A9B2B549F8EE