So in the above example, this message has a CAN frame ID of ``608``, is named "TEMPERATURE_RH", is ``8`` bytes in length and is sent by a CAN network node named "UNITB".
| Within the "TEMERATURE_RH" message, a number of "signals" (aka message fields) are defined, using ``SG_``.
Since these specify the specific signal/message they apply to, you can place them anywhere in a DBC file. Note comments can span multiple lines.
Specifying default values for signals
-------------------------------------
Sometimes it can be helpful to define default initial values of certain signals in a message. This can be done using an "Attribute" named "GenSigStartValue".
In order to use attributes, you need to first define them using ``BA_DEF_``. Its format looks like this:
The data in ``[Config]`` is dependent on the ``<DataType>``. of the attribute being defined. "GenSigStartValue" is a ``INT`` type, so the format of ``[Config]`` will be ``<min> <max>``.
I think in the case of "GenSigStartValue", the min and max values dont really matter (at least it doesnt when using a lenient parser like `cantools <https://github.com/cantools/cantools>`_ )
You can define a default value for an attribute using ``BA_DEF_DEF_``.
..code-block:: dbc
BA_DEF_ SG_ "GenSigStartValue" INT -100000 100000;
BA_DEF_DEF_ "GenSigStartValue" 0;
This definitions need only be made once per DBC file.
Once you've defined the attribute, you can use it to set default/initial values for signals. For instance, using our message from earlier:
..code-block:: dbc
BA_ "GenSigStartValue" SG_ 608 TEMP1 -32768;
BA_ "GenSigStartValue" SG_ 608 RH1 255;
BA_ "GenSigStartValue" SG_ 608 RH2 254;
Using this information to generate a C++ struct representation may look something like this:
..code-block:: cpp
:linenos:
struct TemperatureRh {
uint8_t TMPD : 1;
uint8_t RHD : 1;
uint8_t FLT1 : 1;
uint8_t FLT2 : 1;
uint16_t _reserved : 12;
int16_t TEMP1 = -32768;
int16_t TEMP2;
uint8_t RH1 = 255;
uint8_t RH2 = 254;
constexpr size_t WIRE_SIZE_BYTES = 8;
} __attribute__((packed));
Bringing it all together
------------------------
We've now defined, commented, and set some default values for a single message. If this were the only message in a DBC file, the file would look like this:
..code-block:: dbc
:linenos:
VERSION ""
BA_DEF_ SG_ "GenSigStartValue" INT -100000 100000;