Extending A Data Model Tutorial

### 1. Adding a DTC We begin by opening the IDL file that ships with the PolySync release package, and add a new Diagnostic Trouble Code (DTC): ```bash $ gedit $PSYNC_HOME/modules/dtc/dtc.idl ``` PolySync has reserved the lower 32-bits of the available `ps_dtc` IDs. This means that custom DTCs must have an ID with a value of 4,294,967,296 >= x <= 18,446,744,073,709,551,615. We will add a custom DTC to the IDL with our custom description and macro name: ```bash /** @brief Ibeo Lux device has overheated and cannot operate. * Data will not be reported until the temperature matches the normal operating range. */ const ps_dtc DTC_IBEO_LUX_OVERHEATED = 4294967296; ``` DTCs are intended to represent a specific state of an application. Rather than saying hardware error, a DTC could indicate very specifically that the Ethernet sensor is overheated. Another DTC could indicate that the mirror is dirty, and so on. ### 2. Generate the data model Once all changes have been saved, the PolySync PDM tool is used to generate the data model with the DTC built into the API. ```bash $ cd $PSYNC_HOME $ pdm-gen modules/dtc/dtc.idl modules/sensor/sensor.idl modules/navigation/navigation.idl modules/control/contorl.idl > pdm/version.txt $ cp pdm/*.so $PSYNC_HOME/lib ``` Applications need to be rebuilt against the new API files before the new DTC is available at runtime, and can be used to indicate the diagnostic status. The same process can be applied to any of the data model modules to extend or add new types and messages. [note] If any of the existing types or messages are removed, PolySync provided nodes may behave unexpectedly. [/note] ### Conclusion As you've worked through this tutorial, you've learned how to extend the DTC module to demonstrate how to extend the PolySync data model. #### Next tutorial Ready for more? The [Data Generation Tutorial](https://help.polysync.io/releases/2.0.7//articles/data-generation-tutorial/) expands on filling messages and publishing data to the PolySync bus, as well as working with multiple message types.