MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
isamplereduction.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
12#pragma once
13
14#include "mdf/iblock.h"
15#include <string>
16#include "mdf/ichannel.h"
17namespace mdf {
18class IChannelGroup;
19
23enum class SrSyncType : uint8_t {
24 Undefined = 0,
25 Time = 1,
26 Angle = 2,
27 Distance = 3,
28 Index = 4,
29};
30
31namespace SrFlag {
32
33constexpr uint8_t InvalidationByte = 0x01;
34constexpr uint8_t DominantBit = 0x02;
35
36} // End namespace SrFlag
37
42template <typename T>
43struct SrValue {
44 T MeanValue = {};
45 T MinValue = {};
46 T MaxValue = {};
47 bool MeanValid = false;
48 bool MinValid = false;
49 bool MaxValid = false;
50};
51
58class ISampleReduction : public IBlock {
59public:
64 virtual void NofSamples(uint64_t nof_samples) = 0;
65
70 [[nodiscard]] virtual uint64_t NofSamples() const = 0;
71
78 virtual void Interval(double interval) = 0;
79
84 [[nodiscard]] virtual double Interval() const = 0;
85
90 virtual void SyncType(SrSyncType type);
91
93 [[nodiscard]] virtual SrSyncType SyncType() const;
94
95 virtual void Flags(uint8_t flags);
96 [[nodiscard]] virtual uint8_t Flags() const;
97
99 [[nodiscard]] virtual const IChannelGroup* ChannelGroup() const = 0;
100
109 template <typename T>
110 void GetChannelValue( const IChannel& channel, uint64_t sample,
111 uint64_t array_index, SrValue<T>& value ) const;
112
121 template <typename T>
122 void GetEngValue( const IChannel& channel, uint64_t sample,
123 uint64_t array_index, SrValue<T>& value ) const;
124
125 virtual void ClearData() = 0;
126
127 protected:
129 virtual void GetChannelValueUint( const IChannel& channel, uint64_t sample,
130 uint64_t array_index, SrValue<uint64_t>& value ) const = 0;
131
133 virtual void GetChannelValueInt( const IChannel& channel, uint64_t sample,
134 uint64_t array_index, SrValue<int64_t>& value ) const = 0;
136 virtual void GetChannelValueDouble( const IChannel& channel, uint64_t sample,
137 uint64_t array_index, SrValue<double>& value ) const = 0;
138};
139
140template<typename T>
141void ISampleReduction::GetChannelValue( const IChannel& channel, uint64_t sample,
142 uint64_t array_index, SrValue<T>& value ) const {
143 value = {};
144 switch (channel.DataType()) {
148 GetChannelValueUint(channel, sample, array_index, temp);
149 value.MeanValue = static_cast<T>(temp.MeanValue);
150 value.MinValue = static_cast<T>(temp.MinValue);
151 value.MaxValue = static_cast<T>(temp.MaxValue);
152 value.MeanValid = temp.MeanValid;
153 value.MinValid = temp.MinValid;
154 value.MaxValid = temp.MaxValid;
155 break;
156 }
157
160 SrValue<int64_t> temp;
161 GetChannelValueInt(channel, sample, array_index, temp);
162 value.MeanValue = static_cast<T>(temp.MeanValue);
163 value.MinValue = static_cast<T>(temp.MinValue);
164 value.MaxValue = static_cast<T>(temp.MaxValue);
165 value.MeanValid = temp.MeanValid;
166 value.MinValid = temp.MinValid;
167 value.MaxValid = temp.MaxValid;
168 break;
169 }
170
173 SrValue<double> temp;
174 GetChannelValueDouble(channel, sample, array_index, temp);
175 value.MeanValue = static_cast<T>(temp.MeanValue);
176 value.MinValue = static_cast<T>(temp.MinValue);
177 value.MaxValue = static_cast<T>(temp.MaxValue);
178 value.MeanValid = temp.MeanValid;
179 value.MinValid = temp.MinValid;
180 value.MaxValid = temp.MaxValid;
181 break;
182 }
183
184 default:
185 break;
186 }
187}
188
190template<>
191void ISampleReduction::GetChannelValue( const IChannel& channel, uint64_t sample,
192 uint64_t array_index, SrValue<std::string>& value) const;
193
194
195
196template<typename T>
197void ISampleReduction::GetEngValue( const IChannel& channel, uint64_t sample,
198 uint64_t array_index, SrValue<T>& value ) const {
199 value = {};
200
201 const auto* channel_conversion = channel.ChannelConversion();
202
203 switch (channel.DataType()) {
207 GetChannelValueUint(channel, sample, array_index, temp);
208 if (channel_conversion != 0) {
209 const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);
210 const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);
211 const bool max_valid = channel_conversion->Convert(temp.MaxValue, value.MaxValue);
212 value.MeanValid = temp.MeanValid && mean_valid;
213 value.MinValid = temp.MinValid && min_valid;
214 value.MaxValid = temp.MaxValid && max_valid;
215 } else {
216 value.MeanValue = static_cast<T>(temp.MeanValue);
217 value.MinValue = static_cast<T>(temp.MinValue);
218 value.MaxValue = static_cast<T>(temp.MaxValue);
219 value.MeanValid = temp.MeanValid;
220 value.MinValid = temp.MinValid;
221 value.MaxValid = temp.MaxValid;
222 }
223 break;
224 }
225
228 SrValue<int64_t> temp;
229 GetChannelValueInt(channel, sample, array_index, temp);
230 if (channel_conversion != 0) {
231 const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);
232 const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);
233 const bool max_valid = channel_conversion->Convert(temp.MaxValue, value.MaxValue);
234 value.MeanValid = temp.MeanValid && mean_valid;
235 value.MinValid = temp.MinValid && min_valid;
236 value.MaxValid = temp.MaxValid && max_valid;
237 } else {
238 value.MeanValue = static_cast<T>(temp.MeanValue);
239 value.MinValue = static_cast<T>(temp.MinValue);
240 value.MaxValue = static_cast<T>(temp.MaxValue);
241 value.MeanValid = temp.MeanValid;
242 value.MinValid = temp.MinValid;
243 value.MaxValid = temp.MaxValid;
244 }
245 break;
246 }
247
250 SrValue<double> temp;
251 GetChannelValueDouble(channel, sample, array_index, temp);
252 if (channel_conversion != 0) {
253 const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);
254 const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);
255 const bool max_valid = channel_conversion->Convert(temp.MaxValue, value.MaxValue);
256 value.MeanValid = temp.MeanValid && mean_valid;
257 value.MinValid = temp.MinValid && min_valid;
258 value.MaxValid = temp.MaxValid && max_valid;
259 } else {
260 value.MeanValue = static_cast<T>(temp.MeanValue);
261 value.MinValue = static_cast<T>(temp.MinValue);
262 value.MaxValue = static_cast<T>(temp.MaxValue);
263 value.MeanValid = temp.MeanValid;
264 value.MinValid = temp.MinValid;
265 value.MaxValid = temp.MaxValid;
266 }
267 break;
268 }
269
270 default:
271 break;
272 }
273}
274
276template<>
277void ISampleReduction::GetEngValue( const IChannel& channel, uint64_t sample,
278 uint64_t array_index, SrValue<std::string>& value ) const;
279} // mdf
Base class for all MDF blocks.
Definition iblock.h:19
Interface against a channel group (CG) block.
Definition ichannelgroup.h:66
Defines a MDF channel (CN) block.
Definition ichannel.h:126
virtual IChannelConversion * ChannelConversion() const =0
Returns the conversion block, if any.
virtual void DataType(ChannelDataType type)=0
Sets the data type.
Defines an interface to a sample reduction (SR) block.
Definition isamplereduction.h:58
virtual void NofSamples(uint64_t nof_samples)=0
Sets number of samples in the block.
virtual void Flags(uint8_t flags)
Sets SR flags.
virtual double Interval() const =0
Returns the interval value.
virtual uint8_t Flags() const
Returns the SR flags.
virtual void Interval(double interval)=0
Sets the interval value.
virtual void GetChannelValueUint(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< uint64_t > &value) const =0
virtual void ClearData()=0
Resets the internal SR data bytes.
virtual void SyncType(SrSyncType type)
Synchronization type. Example Time or number of samples.
virtual SrSyncType SyncType() const
return type of synchronization.
virtual const IChannelGroup * ChannelGroup() const =0
Returns its channel group.
void GetEngValue(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< T > &value) const
Returns the scaled SR value.
Definition isamplereduction.h:197
void GetChannelValue(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< T > &value) const
Returns the channel value for a specific sample.
Definition isamplereduction.h:141
virtual uint64_t NofSamples() const =0
Returns number of samples.
virtual void GetChannelValueDouble(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< double > &value) const =0
virtual void GetChannelValueInt(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< int64_t > &value) const =0
All MDF blocks inherits from the IBlock class. The interface class is used internally in lists....
The define an interface against a channel block (CN).
constexpr uint8_t InvalidationByte
The block contains an invalidation byte.
Definition isamplereduction.h:33
constexpr uint8_t DominantBit
Dominant invalidation flag.
Definition isamplereduction.h:34
Main namespace for the MDF library.
Definition canmessage.h:17
@ Distance
Distance type.
@ Angle
Angle type.
@ Index
Sample number.
@ SignedIntegerBe
Signed integer, big endian.
@ UnsignedIntegerLe
Unsigned integer, little endian.
@ FloatLe
Float, little endian.
@ FloatBe
Float, big endian.
@ SignedIntegerLe
Signed integer, little endian.
@ UnsignedIntegerBe
Unsigned integer, big endian.
SrSyncType
Type of master for a sample reduction (SR) block.
Definition isamplereduction.h:23
Template class that is used to handle reduction sample.
Definition isamplereduction.h:43
T MeanValue
Mean value.
Definition isamplereduction.h:44
T MinValue
Min value.
Definition isamplereduction.h:45
bool MaxValid
Max value valid.
Definition isamplereduction.h:49
T MaxValue
Max value.
Definition isamplereduction.h:46
bool MeanValid
Mean value valid.
Definition isamplereduction.h:47
bool MinValid
Min value valid.
Definition isamplereduction.h:48