Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : #include "can/filter/IntervalFilter.h" 4 : 5 : #include <etl/algorithm.h> 6 : #include <etl/utility.h> 7 : 8 : namespace can 9 : { 10 17 : IntervalFilter::IntervalFilter() : _from(MAX_ID), _to(0U) {} 11 : 12 4 : IntervalFilter::IntervalFilter(uint32_t const from, uint32_t const to) : IntervalFilter() 13 : { 14 4 : IntervalFilter::add(from, to); 15 4 : } 16 : 17 : // virtual 18 6 : void IntervalFilter::add(uint32_t const filterId) { add(filterId, filterId); } 19 : 20 26 : void IntervalFilter::add(uint32_t from, uint32_t to) 21 : { 22 26 : if (from > MAX_ID) 23 : { 24 1 : from = MAX_ID; 25 : } 26 26 : if (to > MAX_ID) 27 : { 28 2 : to = MAX_ID; 29 : } 30 : // assert order 31 26 : if (from > to) 32 : { 33 1 : ::ETL_OR_STD::swap(from, to); 34 : } 35 : // adjust lower bound 36 26 : _from = ::etl::min(_from, from); 37 : // adjust upper bound 38 26 : _to = ::etl::max(_to, to); 39 26 : } 40 : 41 : // virtual 42 37138 : bool IntervalFilter::match(uint32_t const filterId) const 43 : { 44 37138 : return (filterId >= _from) && (filterId <= _to); 45 : } 46 : 47 11 : void IntervalFilter::clear() 48 : { 49 11 : _from = MAX_ID; 50 11 : _to = 0U; 51 11 : } 52 : 53 1 : void IntervalFilter::open() 54 : { 55 1 : _from = 0x00U; 56 1 : _to = MAX_ID; 57 1 : } 58 : 59 : } /*namespace can*/