32 [[nodiscard]]
size_t MaxSamples()
const {
return value_list_.size();}
38 [[nodiscard]] uint64_t
Time(
size_t index)
const;
41 [[nodiscard]] uint32_t
CanId(
size_t index)
const;
53 bool ChannelValue(
size_t index, uint64_t& ns1970, V& value)
const;
65 bool EngValue(
size_t index, uint64_t& ns1970, V& value)
const;
72 [[nodiscard]]
size_t NofSamples()
const {
return nof_samples_;}
80 [[nodiscard]] std::pair<size_t, bool>
TimeToIndex(uint64_t time)
const;
88 struct ChannelSample {
94 [[nodiscard]] uint8_t Source()
const {
95 return static_cast<uint8_t
>(can_id & 0xFF);
98 const Signal& signal_;
99 std::vector<ChannelSample> value_list_;
101 size_t sample_index_ = 0;
102 size_t nof_samples_ = 0;
103 bool attached_ =
false;
109 if (index >= value_list_.size()) {
112 const auto& sample = value_list_[index];
113 bool valid = sample.value.valid;
114 ns1970 = sample.ns1970;
121 const auto temp = sample.value.signed_value;
122 value =
static_cast<V
>(temp);
123 }
catch (
const std::exception&) {
138 const auto temp = sample.value.unsigned_value;
139 value =
static_cast<V
>(temp);
140 }
catch (
const std::exception&) {
150 const auto temp = sample.value.float_value;
151 value =
static_cast<V
>(temp);
152 }
catch (
const std::exception&) {
166 std::string& value)
const;
171 if (index >= value_list_.size()) {
174 const auto& sample = value_list_[index];
175 bool valid = sample.value.valid;
176 ns1970 = sample.ns1970;
180 bool need_to_convert =
true;
183 need_to_convert =
false;
186 if (signal_.
Scale() == 1.0 && signal_.
Offset() == 0) {
187 need_to_convert =
false;
195 if (need_to_convert) {
196 auto temp =
static_cast<double>(channel);
197 temp *= signal_.
Scale();
199 value =
static_cast<V
>(temp);
201 value =
static_cast<V
>(channel);
207 uint64_t channel = 0;
209 if (need_to_convert) {
210 auto temp =
static_cast<double>(channel);
211 temp *= signal_.
Scale();
213 value =
static_cast<V
>(temp);
215 value =
static_cast<V
>(channel);
223 if (need_to_convert) {
224 auto temp =
static_cast<double>(channel);
225 temp *= signal_.
Scale();
227 value =
static_cast<V
>(temp);
229 value =
static_cast<V
>(channel);
237 if (need_to_convert) {
239 temp *= signal_.
Scale();
241 value =
static_cast<V
>(temp);
243 value =
static_cast<V
>(channel);
257 std::string& value)
const;
Interface that handles samples. Internal usage.
Definition: isampleobserver.h:13
Interface against a DBC signal configuration.
Definition: signal.h:68
void BitLength(size_t length)
Sets the bit length.
Definition: signal.h:111
void Offset(double offset)
Sets the offset.
Definition: signal.h:123
void Scale(double scale)
Sets the scaling constant.
Definition: signal.h:120
void EnumList(const std::map< int64_t, std::string > &enum_list)
Sets the enumeration.
void DataType(SignalDataType type)
Sets the data type.
Definition: signal.h:88
The sample observer hold a number of samples.
Definition: signalobserver.h:23
void OnSample() override
On sample callback handler.
size_t NofValidSamples() const
Returns number of valid samples.
uint64_t Time(size_t index) const
Returns the absolute time for a sample.
void ResetSampleIndex()
Reset the sample index.
bool ChannelValue(size_t index, uint64_t &ns1970, V &value) const
Returns the unscaled signal value.
Definition: signalobserver.h:107
size_t FirstIndex() const
First sample.
SignalObserver()=delete
Default constructor.
void MaxSamples(size_t max_nof_samples)
Sets the maximum number of samples.
~SignalObserver() override
Default destructor.
void DetachObserver() override
Detach an observer.
const Signal & GetSignal() const
Returns the signal object.
Definition: signalobserver.h:35
std::pair< size_t, bool > TimeToIndex(uint64_t time) const
Sample time to internal index.
size_t MaxSamples() const
Returns the max number of samples.
Definition: signalobserver.h:32
size_t NofSamples() const
Returns number of samples.
Definition: signalobserver.h:72
uint32_t CanId(size_t index) const
Returns the CAN ID for a sample.
bool EngValue(size_t index, uint64_t &ns1970, V &value) const
Returns the scaled signal value.
Definition: signalobserver.h:169
size_t SampleToIndex(size_t sample) const
Sample number (0..) to internal index.
SignalObserver(const Signal &signal)
Constructor.
size_t LastIndex() const
Last sample.
Internal object that define an observer interface that handle samples.
Main namespace for the DBC library.
Definition: attribute.h:13
@ SignedData
Signed integer.
@ DoubleData
Double value.
@ UnsignedData
Unsigned integer.
std::vector< std::unique_ptr< SignalObserver > > SignalObserverList
List of observer.
Definition: signalobserver.h:260
Interface against a DBC signal configuration.
Support function that holds the channel value for a signal.
Definition: signal.h:18