Back to Serial Studio

MDF Lib: include/mdf/isamplereduction.h Source File

lib/mdflib/docs/manual/html/isamplereduction_8h_source.html

3.2.728.9 KB
Original Source

| 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,

25Time = 1,

26Angle = 2,

27Distance = 3,

28Index = 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 = {};

47bool MeanValid = false;

48bool MinValid = false;

49bool MaxValid = false;

50};

51

58class ISampleReduction : public IBlock {

59public:

64virtual void NofSamples(uint64_t nof_samples) = 0;

65

70 [[nodiscard]] virtual uint64_t NofSamples() const = 0;

71

78virtual void Interval(double interval) = 0;

79

84 [[nodiscard]] virtual double Interval() const = 0;

85

90virtual void SyncType(SrSyncType type);

91

93 [[nodiscard]] virtual SrSyncType SyncType() const;

94

95virtual void Flags(uint8_t flags);

96 [[nodiscard]] virtual uint8_t Flags() const;

97

99 [[nodiscard]] virtual const IChannelGroup* ChannelGroup() const = 0;

100

109template <typename T>

110void GetChannelValue( const IChannel& channel, uint64_t sample,

111 uint64_t array_index, SrValue<T>& value ) const;

112

121template <typename T>

122void GetEngValue( const IChannel& channel, uint64_t sample,

123 uint64_t array_index, SrValue<T>& value ) const;

124

125virtual void ClearData() = 0;

126

127 protected:

129virtual void GetChannelValueUint( const IChannel& channel, uint64_t sample,

130 uint64_t array_index, SrValue<uint64_t>& value ) const = 0;

131

133virtual void GetChannelValueInt( const IChannel& channel, uint64_t sample,

134 uint64_t array_index, SrValue<int64_t>& value ) const = 0;

136virtual 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 = {};

144switch (channel.DataType()) {

145case ChannelDataType::UnsignedIntegerLe:

146case ChannelDataType::UnsignedIntegerBe: {

147SrValue<uint64_t> temp;

148GetChannelValueUint(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;

155break;

156 }

157

158case ChannelDataType::SignedIntegerLe:

159case ChannelDataType::SignedIntegerBe: {

160SrValue<int64_t> temp;

161GetChannelValueInt(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;

168break;

169 }

170

171case ChannelDataType::FloatLe:

172case ChannelDataType::FloatBe: {

173SrValue<double> temp;

174GetChannelValueDouble(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;

181break;

182 }

183

184default:

185break;

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

201const auto* channel_conversion = channel.ChannelConversion();

202

203switch (channel.DataType()) {

204case ChannelDataType::UnsignedIntegerLe:

205case ChannelDataType::UnsignedIntegerBe: {

206SrValue<uint64_t> temp;

207GetChannelValueUint(channel, sample, array_index, temp);

208if (channel_conversion != 0) {

209const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);

210const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);

211const 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 }

223break;

224 }

225

226case ChannelDataType::SignedIntegerLe:

227case ChannelDataType::SignedIntegerBe: {

228SrValue<int64_t> temp;

229GetChannelValueInt(channel, sample, array_index, temp);

230if (channel_conversion != 0) {

231const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);

232const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);

233const 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 }

245break;

246 }

247

248case ChannelDataType::FloatLe:

249case ChannelDataType::FloatBe: {

250SrValue<double> temp;

251GetChannelValueDouble(channel, sample, array_index, temp);

252if (channel_conversion != 0) {

253const bool mean_valid = channel_conversion->Convert(temp.MeanValue, value.MeanValue);

254const bool min_valid = channel_conversion->Convert(temp.MinValue, value.MinValue);

255const 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 }

267break;

268 }

269

270default:

271break;

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

mdf::IBlock

Base class for all MDF blocks.

Definition iblock.h:19

mdf::IChannelGroup

Interface against a channel group (CG) block.

Definition ichannelgroup.h:66

mdf::IChannel

Defines a MDF channel (CN) block.

Definition ichannel.h:126

mdf::IChannel::ChannelConversion

virtual IChannelConversion * ChannelConversion() const =0

Returns the conversion block, if any.

mdf::IChannel::DataType

virtual void DataType(ChannelDataType type)=0

Sets the data type.

mdf::ISampleReduction

Defines an interface to a sample reduction (SR) block.

Definition isamplereduction.h:58

mdf::ISampleReduction::NofSamples

virtual void NofSamples(uint64_t nof_samples)=0

Sets number of samples in the block.

mdf::ISampleReduction::Flags

virtual void Flags(uint8_t flags)

Sets SR flags.

mdf::ISampleReduction::Interval

virtual double Interval() const =0

Returns the interval value.

mdf::ISampleReduction::Flags

virtual uint8_t Flags() const

Returns the SR flags.

mdf::ISampleReduction::Interval

virtual void Interval(double interval)=0

Sets the interval value.

mdf::ISampleReduction::GetChannelValueUint

virtual void GetChannelValueUint(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< uint64_t > &value) const =0

mdf::ISampleReduction::ClearData

virtual void ClearData()=0

Resets the internal SR data bytes.

mdf::ISampleReduction::SyncType

virtual void SyncType(SrSyncType type)

Synchronization type. Example Time or number of samples.

mdf::ISampleReduction::SyncType

virtual SrSyncType SyncType() const

return type of synchronization.

mdf::ISampleReduction::ChannelGroup

virtual const IChannelGroup * ChannelGroup() const =0

Returns its channel group.

mdf::ISampleReduction::GetEngValue

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

mdf::ISampleReduction::GetChannelValue

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

mdf::ISampleReduction::NofSamples

virtual uint64_t NofSamples() const =0

Returns number of samples.

mdf::ISampleReduction::GetChannelValueDouble

virtual void GetChannelValueDouble(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< double > &value) const =0

mdf::ISampleReduction::GetChannelValueInt

virtual void GetChannelValueInt(const IChannel &channel, uint64_t sample, uint64_t array_index, SrValue< int64_t > &value) const =0

iblock.h

All MDF blocks inherits from the IBlock class. The interface class is used internally in lists....

ichannel.h

The define an interface against a channel block (CN).

mdf::SrFlag::InvalidationByte

constexpr uint8_t InvalidationByte

The block contains an invalidation byte.

Definition isamplereduction.h:33

mdf::SrFlag::DominantBit

constexpr uint8_t DominantBit

Dominant invalidation flag.

Definition isamplereduction.h:34

mdf

Main namespace for the MDF library.

Definition canmessage.h:17

mdf::ChannelSyncType::Distance

@ Distance

Distance type.

mdf::ChannelSyncType::Angle

@ Angle

Angle type.

mdf::ChannelSyncType::Index

@ Index

Sample number.

mdf::ChannelSyncType::Time

@ Time

Time type.

mdf::ChannelDataType::SignedIntegerBe

@ SignedIntegerBe

Signed integer, big endian.

mdf::ChannelDataType::UnsignedIntegerLe

@ UnsignedIntegerLe

Unsigned integer, little endian.

mdf::ChannelDataType::FloatLe

@ FloatLe

Float, little endian.

mdf::ChannelDataType::FloatBe

@ FloatBe

Float, big endian.

mdf::ChannelDataType::SignedIntegerLe

@ SignedIntegerLe

Signed integer, little endian.

mdf::ChannelDataType::UnsignedIntegerBe

@ UnsignedIntegerBe

Unsigned integer, big endian.

mdf::SrSyncType

SrSyncType

Type of master for a sample reduction (SR) block.

Definition isamplereduction.h:23

mdf::SrValue

Template class that is used to handle reduction sample.

Definition isamplereduction.h:43

mdf::SrValue::MeanValue

T MeanValue

Mean value.

Definition isamplereduction.h:44

mdf::SrValue::MinValue

T MinValue

Min value.

Definition isamplereduction.h:45

mdf::SrValue::MaxValid

bool MaxValid

Max value valid.

Definition isamplereduction.h:49

mdf::SrValue::MaxValue

T MaxValue

Max value.

Definition isamplereduction.h:46

mdf::SrValue::MeanValid

bool MeanValid

Mean value valid.

Definition isamplereduction.h:47

mdf::SrValue::MinValid

bool MinValid

Min value valid.

Definition isamplereduction.h:48


Generated by 1.12.0