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