62 [[nodiscard]]
bool InRange(
size_t value)
const;
73 void Name(
const std::string& name) { name_ = name; }
75 [[nodiscard]]
const std::string&
Name()
const {
return name_; }
78 void Unit(
const std::string& unit) { unit_ = unit; }
80 [[nodiscard]]
const std::string&
Unit()
const {
return unit_; }
83 void Comment(
const std::string& comment) { comment_ = comment; }
85 [[nodiscard]]
const std::string&
Comment()
const {
return comment_; }
103 [[nodiscard]]
int MuxValue()
const {
return mux_value_; }
106 void BitStart(
size_t start) { bit_start_ = start; }
108 [[nodiscard]]
size_t BitStart()
const {
return bit_start_; }
113 [[nodiscard]]
size_t BitLength()
const {
return bit_length_; }
120 void Scale(
double scale) { scale_ = scale; }
121 [[nodiscard]]
double Scale()
const {
return scale_; }
123 void Offset(
double offset) { offset_ = offset; }
124 [[nodiscard]]
double Offset()
const {
return offset_; }
126 void Min(
double min) { min_ = min; }
127 [[nodiscard]]
double Min()
const {
return min_; }
129 void Max(
double max) { max_ = max; }
130 [[nodiscard]]
double Max()
const {
return max_; }
133 void EnumList(
const std::map<int64_t, std::string>& enum_list);
135 [[nodiscard]]
const std::map<int64_t, std::string>&
EnumList()
const;
138 void Receivers(
const std::vector<std::string>& receiver_list);
140 [[nodiscard]]
const std::vector<std::string>&
Receivers()
const;
143 [[nodiscard]]
const std::vector<Attribute>&
Attributes()
const {
144 return attribute_list_;
148 void MessageId(uint64_t message_id) { message_id_ = message_id;}
150 [[nodiscard]] uint64_t
MessageId()
const {
return message_id_; }
162 void ParseMessage(
const std::vector<uint8_t>& message, uint64_t ns1970,
174 [[nodiscard]] uint64_t
SampleTime()
const {
return sample_time_;}
179 [[nodiscard]] uint64_t
SampleCanId()
const {
return sample_can_id_;}
181 void Valid(
bool valid) {valid_ = valid;}
182 [[nodiscard]]
bool Valid()
const {
return valid_;}
185 template <
typename T>
189 template <
typename T>
198 std::string comment_;
201 std::vector<std::string> receiver_list_;
205 size_t bit_start_ = 0;
206 size_t bit_length_ = 0;
207 bool little_endian_ =
true;
210 double offset_ = 0.0;
215 std::vector<Attribute> attribute_list_;
216 std::map<int64_t, std::string> enum_list_;
220 uint64_t message_id_ = 0;
221 mutable size_t sample_counter_ = 0;
223 uint64_t sample_time_ = 0;
224 uint32_t sample_can_id_ = 0;
226 mutable std::vector<ISampleObserver*> observer_list_;
236 switch (data_type_) {
240 value =
static_cast<T
>(temp);
241 }
catch (
const std::exception&) {
248 size_t bytes = bit_length_ / 8;
249 if ((bit_length_ % 8) != 0) {
257 value =
static_cast<T
>(temp);
258 }
catch (
const std::exception&) {
269 value =
static_cast<T
>(temp);
270 }
catch (
const std::exception&) {
296 bool need_to_convert =
true;
298 if (!enum_list_.empty()) {
299 need_to_convert =
false;
302 if (scale_ == 1.0 && offset_ == 0) {
303 need_to_convert =
false;
306 switch (data_type_) {
311 if (need_to_convert) {
312 auto temp =
static_cast<double>(channel);
315 value =
static_cast<T
>(temp);
317 value =
static_cast<T
>(channel);
323 uint64_t channel = 0;
325 if (need_to_convert) {
326 auto temp =
static_cast<double>(channel);
329 value =
static_cast<T
>(temp);
331 value =
static_cast<T
>(channel);
339 if (need_to_convert) {
340 auto temp =
static_cast<double>(channel);
343 value =
static_cast<T
>(temp);
345 value =
static_cast<T
>(channel);
353 if (need_to_convert) {
357 value =
static_cast<T
>(temp);
359 value =
static_cast<T
>(channel);
All DBC network objects may have attributes attached to them.
Support class for handling attributes of network objects.
Definition: attribute.h:49
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
int MuxValue() const
Returns the multiplexor value.
Definition: signal.h:103
size_t BitLength() const
Returns the bit length.
Definition: signal.h:113
bool EngValue(T &value) const
Returns the scaled engineering value.
Definition: signal.h:293
std::string DataTypeAsString() const
Returns the data type as text.
double Offset() const
Return offset.
Definition: signal.h:124
void Offset(double offset)
Sets the offset.
Definition: signal.h:123
void Mux(MuxType type)
Sets the multiplexer type.
Definition: signal.h:95
void Max(double max)
Sets the max range.
Definition: signal.h:129
void SampleCanId(uint32_t can_id)
Sets the CAN ID for the sample.
Definition: signal.h:177
void SampleTime(uint64_t ns1970)
Sets the sample time.
Definition: signal.h:172
Attribute & CreateAttribute(const Attribute &definition)
Creates an attribute.
uint64_t SampleCanId() const
Returns the CAN ID for latest sample.
Definition: signal.h:179
bool IsMultiplexed() const
True if multiplexed signal.
uint64_t MessageId() const
Returns the message ID that the signal belongs to.
Definition: signal.h:150
const std::vector< Attribute > & Attributes() const
Returns the attribute list.
Definition: signal.h:143
size_t SampleCounter() const
Returns the sample counter.
Definition: signal.h:169
std::string GetEnumString(int64_t index) const
Returns the enumerate text for an index.
bool Valid() const
Trie if value is valid.
Definition: signal.h:182
void MuxValue(int value)
Sets the multiplexor value.
Definition: signal.h:101
void Unit(const std::string &unit)
Sets the unit of measure.
Definition: signal.h:78
void AttachObserver(ISampleObserver *observer) const
Attach a sample observer.
const std::vector< std::string > & Receivers() const
Return the receiver list.
bool ChannelValue(T &value) const
Returns the channel value.
Definition: signal.h:232
virtual ~Signal()
Destructor.
ExtendedMux & GetExtendedMux()
Creates an extended multiplexor struct.
void Scale(double scale)
Sets the scaling constant.
Definition: signal.h:120
void ResetSampleCounter() const
Resets the sample counter.
Definition: signal.h:165
size_t BitStart() const
Returns the start bit.
Definition: signal.h:108
uint64_t SampleTime() const
Returns the sample time.
Definition: signal.h:174
const std::string & Unit() const
Returns the unit of measure.
Definition: signal.h:80
void DetachObserver(const ISampleObserver *observer) const
Detach a sample observer.
MuxType Mux() const
Returns the multiplexer type.
Definition: signal.h:97
void Name(const std::string &name)
Sets the signal name.
Definition: signal.h:73
void BitStart(size_t start)
Sets the start bit.
Definition: signal.h:106
void EnumList(const std::map< int64_t, std::string > &enum_list)
Sets the enumeration.
double Scale() const
Scaling constant.
Definition: signal.h:121
SignalDataType DataType() const
Returns the data type.
Definition: signal.h:90
void Receivers(const std::vector< std::string > &receiver_list)
Sets the receiver list.
void Min(double min)
Sets min range.
Definition: signal.h:126
void Valid(bool valid)
Set to true if valid value.
Definition: signal.h:181
const std::string & Comment() const
Returns the descriptive text.
Definition: signal.h:85
const std::map< int64_t, std::string > & EnumList() const
Returns the enumeration.
void DataType(SignalDataType type)
Sets the data type.
Definition: signal.h:88
std::string MuxAsString() const
Returns the multiplexer type as text.
bool LittleEndian() const
Return true if little endian byte order.
Definition: signal.h:118
void StepSampleCounter() const
Steps the sample counter.
Definition: signal.h:167
const std::string & Name() const
Returns the signal name.
Definition: signal.h:75
double Max() const
Max range.
Definition: signal.h:130
double Min() const
Min range.
Definition: signal.h:127
void Comment(const std::string &comment)
Sets the descriptive text.
Definition: signal.h:83
void MessageId(uint64_t message_id)
Sets the signals message ID.
Definition: signal.h:148
void ParseMessage(const std::vector< uint8_t > &message, uint64_t ns1970, uint32_t can_id)
Parse out the signal value from a message data buffer.
void LittleEndian(bool endian)
Set true if little endian byte order.
Definition: signal.h:116
Internal object that define an observer interface that handle samples.
Main namespace for the DBC library.
Definition: attribute.h:13
SignalDataType
Signal data type.
Definition: signal.h:35
@ SignedData
Signed integer.
@ DoubleData
Double value.
@ UnsignedData
Unsigned integer.
MuxType
Multiplexer type.
Definition: signal.h:48
@ Multiplexor
Multiplexor signal.
@ Multiplexed
Multiplexed signal.
@ NotMultiplexed
Normal signal.
@ ExtendedMultiplexor
Extended multiplexor signal.
std::pair< size_t, size_t > RangePair
Min and Max range definition.
Definition: signal.h:56
Support function for the extended multiplexor functionality.
Definition: signal.h:59
bool InRange(size_t value) const
True if value is active.
std::vector< RangePair > range_list
Active range for the multiplexor.
Definition: signal.h:61
std::string multiplexor
Signal name of the multiplexor.
Definition: signal.h:60
Support function that holds the channel value for a signal.
Definition: signal.h:18
bool valid
True if the value is valid.
Definition: signal.h:19
void Clear()
Resets the value.
Definition: signal.h:25
std::vector< uint8_t > array_value
Array or string value.
Definition: signal.h:23
int64_t signed_value
Integer value.
Definition: signal.h:20
uint64_t unsigned_value
Unsigned value.
Definition: signal.h:21
double float_value
Float value.
Definition: signal.h:22