147 virtual void Name(
const std::string& name);
148 [[nodiscard]]
virtual std::string
Name()
const;
153 virtual void Unit(
const std::string& unit) = 0;
154 [[nodiscard]]
virtual std::string
Unit()
const = 0;
163 [[nodiscard]]
virtual uint8_t
Decimals()
const = 0;
171 virtual void Range(
double min,
double max);
172 [[nodiscard]]
virtual std::optional<std::pair<double, double>>
Range()
176 [[nodiscard]]
virtual uint16_t
Flags()
const;
185 virtual void Formula(
const std::string& formula);
187 [[nodiscard]]
virtual const std::string&
Formula()
const;
227 virtual void Reference(uint16_t index,
const std::string& text);
230 [[nodiscard]]
virtual std::string
Reference(uint16_t index)
const;
248 template <
typename T,
typename V>
249 bool Convert(
const T& channel_value, V& eng_value)
const;
261 template <
typename T,
typename V = std::
string>
262 bool Convert(
const T& channel_value, std::string& eng_value)
const;
265 template <
typename T = std::
string,
typename V =
double>
266 bool Convert(
const std::string& channel_value,
double& eng_value)
const;
269 template <
typename T = std::
string,
typename V = std::
string>
270 bool Convert(
const std::string& channel_value, std::string& eng_value)
const {
274 eng_value = channel_value;
309 double& eng_value)
const;
311 double& eng_value)
const;
313 double& eng_value)
const;
316 std::string& eng_value)
const;
318 std::string& eng_value)
const;
320 double& eng_value)
const;
322 std::string& eng_value)
const;
326 double& eng_value)
const;
328 double& eng_value)
const;
331template <
typename T,
typename V>
333 V& eng_value)
const {
338 valid =
ConvertLinear(
static_cast<double>(channel_value), value);
339 eng_value =
static_cast<V
>(value);
345 eng_value =
static_cast<V
>(value);
351 eng_value =
static_cast<V
>(value);
357 static_cast<double>(channel_value), value);
358 eng_value =
static_cast<V
>(value);
364 eng_value =
static_cast<V
>(value);
371 eng_value =
static_cast<V
>(value);
378 std::istringstream s(text);
387 std::istringstream s(text);
394 eng_value =
static_cast<V
>(value);
400 eng_value =
static_cast<V
>(value);
406 eng_value =
static_cast<V
>(value);
411 eng_value =
static_cast<V
>(channel_value);
419template <
typename T,
typename V>
421 std::string& eng_value)
const {
426 valid =
ConvertLinear(
static_cast<double>(channel_value), value);
448 static_cast<double>(channel_value), value);
513template <
typename T,
typename V>
515 double& eng_value)
const {
519 eng_value = std::stod(channel_value);
Base class for all MDF blocks.
Definition iblock.h:19
Defines a channel conversion (CC) block.
Definition ichannelconversion.h:142
virtual uint8_t Decimals() const =0
Number of decimals.
virtual std::optional< std::pair< double, double > > Range() const
Returns the range if exist.
virtual bool ConvertValueToValueInterpolate(double channel_value, double &eng_value) const
Value to value interpolation conversion.
virtual std::string Name() const
Name.
bool IsChannelInteger() const
Returns true if channel is an integer.
virtual bool ConvertRational(double channel_value, double &eng_value) const
Rational conversion.
virtual void Range(double min, double max)
Sets the range.
virtual bool IsDecimalUsed() const =0
True if decimal is used.
virtual bool ConvertExponential(double channel_value, double &eng_value) const
Exponential conversion (MDF3).
virtual void Flags(uint16_t flags)
Sets the CcFlag.
virtual bool ConvertTextToValue(const std::string &channel_value, double &eng_value) const
Text to value conversion.
virtual bool ConvertValueToText(double channel_value, std::string &eng_value) const
Value to text conversion.
virtual bool ConvertLogarithmic(double channel_value, double &eng_value) const
Logarithmic conversion (MDF3).
uint16_t nof_values_
Number of parameter values (MDF3).
Definition ichannelconversion.h:282
virtual std::string Unit() const =0
Unit of measure.
virtual void Unit(const std::string &unit)=0
Sets the unit.
double Parameter(uint16_t index) const
Returns the parameter (double)
std::vector< TextConversion > text_conversion_list_
MDF3.
Definition ichannelconversion.h:294
virtual bool IsUnitValid() const =0
True if unit exist.
std::string formula_
Formula string (MDF3).
Definition ichannelconversion.h:293
virtual void Reference(uint16_t index, const std::string &text)
Sets text reference (TX) block.
virtual bool ConvertTextToTranslation(const std::string &channel_value, std::string &eng_value) const
Text to text conversion.
bool Convert(const T &channel_value, V &eng_value) const
Converts a channel value to an engineering (scaled) value.
Definition ichannelconversion.h:332
virtual ConversionType Type() const =0
Conversion type.
uint64_t ParameterUint(uint16_t index) const
Returns the parameter as a bit field (uint64_t)
virtual void Formula(const std::string &formula)
Sets the formula string.
virtual bool ConvertAlgebraic(double channel_value, double &eng_value) const
Algebraic conversion.
virtual bool ConvertValueRangeToText(double channel_value, std::string &eng_value) const
Value range to text value.
virtual bool ConvertValueToValue(double channel_value, double &eng_value) const
Value to value conversion.
virtual uint16_t NofReferences() const
Number of references in the block.
virtual void Decimals(uint8_t decimals)
Sets number of decimals.
ParameterList value_list_
List of parameters.
Definition ichannelconversion.h:287
virtual const std::string & Formula() const
Returns formula string.
std::vector< TextRangeConversion > text_range_conversion_list_
MDF3.
Definition ichannelconversion.h:295
virtual uint16_t Flags() const
Returns CcFlag.
std::vector< std::variant< uint64_t, double > > ParameterList
List of floating point constants.
Definition ichannelconversion.h:285
void Parameter(uint16_t index, double parameter)
Sets a floating point parameter value.
virtual std::string Reference(uint16_t index) const
Returns the reference string by its index.
uint8_t channel_data_type_
The channels data type. Needed by some conversions.
Definition ichannelconversion.h:288
virtual bool ConvertLinear(double channel_value, double &eng_value) const
Linear conversion.
bool IsChannelFloat() const
Returns true if the channel is a float.
virtual IMetaData * MetaData() const
Returns the meta-data block.
void ChannelDataType(uint8_t channel_data_type)
Sets the CN block data type.
uint16_t NofParameters() const
Returns number of parameters in the block.
bool Convert(const std::string &channel_value, std::string &eng_value) const
Converts from string to string.
Definition ichannelconversion.h:270
virtual void Description(const std::string &desc)
Sets the description.
void ParameterUint(uint16_t index, uint64_t parameter)
Sets an unsigned integer parameter value.
virtual IChannelConversion * Inverse() const
Returns the inverse conversion block. Seldom in use.
virtual bool ConvertValueRangeToValue(double channel_value, double &eng_value) const
Value range to value conversion.
virtual IChannelConversion * CreateInverse()
Creates an inverse conversion block.
virtual IMetaData * CreateMetaData()
Creates a meta-data (MD) block.
virtual void Type(ConversionType type)=0
Sets the conversion type.
virtual void Name(const std::string &name)
Sets the CC name.
virtual bool ConvertPolynomial(double channel_value, double &eng_value) const
Polynomial conversion (MDF3).
virtual std::string Description() const
Description.
static std::string FormatDouble(double value, uint8_t decimals, bool fixed=false, const std::string &unit={})
Converts a float to a string.
All MDF blocks inherits from the IBlock class. The interface class is used internally in lists....
Support class for the MDF library.
constexpr uint16_t StatusString
Status string flag.
Definition ichannelconversion.h:129
constexpr uint16_t PrecisionValid
Precision is used.
Definition ichannelconversion.h:127
constexpr uint16_t RangeValid
Range is used.
Definition ichannelconversion.h:128
Main namespace for the MDF library.
Definition canmessage.h:17
ConversionType
Type of conversion formula.
Definition ichannelconversion.h:29
@ TextToTranslation
Text to text conversion. Defines a list of text string to text conversion. Ref(2*n) key to Ref(2*(n+1...
@ BitfieldToText
Bitfield to text conversion Currently unsupported conversion.
@ Rational
Rational function conversion. 6 parameters. Eng = (Par(0)*Ch^2 + Par(1)*Ch + Par(2)) / (Par(3)*Ch^2 +...
@ ValueToValue
Value to value conversion without interpolation. Defined by a list of Key value pairs....
@ Polynomial
MDF 3 polynomial conversion.
@ NoConversion
1:1 conversion. No parameters needed.
@ Logarithmic
MDF 3 logarithmic conversion.
@ Linear
Linear conversion. 2 parameters. Eng = Ch * Par(1) + Par(0).
@ ValueToText
Value to text conversion. Defined by a list of key values to text string conversions....
@ TextToValue
Text to value conversion. Defines a list of text string to value conversion. Ref(n) key to Par(n) val...
@ ValueToValueInterpolation
Value to value conversion with interpolation. Defined by a list of Key value pairs....
@ TimeConversion
MDF 3 Time conversion.
@ DateConversion
MDF 3 Date conversion.
@ Exponential
MDF 3 exponential conversion.
@ ValueRangeToText
Value range to text conversion. Defined by a list of key min/max values to text string conversions....
@ ValueRangeToValue
Value range to value conversion without interpolation. Defined by a list of Key min/max value triplet...
MDF 3 text conversion structure. Not used in MDF 4. Key to text conversion.
Definition ichannelconversion.h:108
std::string text
Text string.
Definition ichannelconversion.h:110
double value
Key.
Definition ichannelconversion.h:109
MDF 3 range conversion structure. Not used in MDF 4. Key min/max to text conversion.
Definition ichannelconversion.h:116
double upper
Key max value.
Definition ichannelconversion.h:118
uint32_t link_text
File position of the text value.
Definition ichannelconversion.h:119
std::string text
The text value.
Definition ichannelconversion.h:120
double lower
Key min value.
Definition ichannelconversion.h:117