1 #ifndef DBC_CLASSES_H
2 #define DBC_CLASSES_H
3 
4 #include <QColor>
5 #include <QString>
6 #include <QStringList>
7 #include <QVariant>
8 #include "can_structs.h"
9 
10 /*classes to encapsulate data from a DBC file. Really, the stuff of interest
11   are the nodes, messages, signals, attributes, and comments.
12 
13   These things sort of form a hierarchy. Nodes send and receive messages.
14   Messages are comprised of signals. Nodes, signals, and messages potentially have attribute values.
15   All of them can have comments.
16 */
17 
18 enum DBC_SIG_VAL_TYPE
19 {
20     UNSIGNED_INT,
21     SIGNED_INT,
22     SP_FLOAT,
23     DP_FLOAT,
24     STRING
25 };
26 
27 enum DBC_ATTRIBUTE_VAL_TYPE
28 {
29     ATTR_INT,
30     ATTR_FLOAT,
31     ATTR_STRING,
32     ATTR_ENUM,
33 };
34 
35 enum DBC_ATTRIBUTE_TYPE
36 {
37     ATTR_TYPE_GENERAL,
38     ATTR_TYPE_NODE,
39     ATTR_TYPE_MESSAGE,
40     ATTR_TYPE_SIG,
41     ATTR_TYPE_ANY
42 };
43 
44 class DBC_ATTRIBUTE
45 {
46 public:
47     QString name;
48     DBC_ATTRIBUTE_VAL_TYPE valType;
49     DBC_ATTRIBUTE_TYPE attrType;
50     double upper, lower;
51     QStringList enumVals;
52     QVariant defaultValue;
53 };
54 
55 class DBC_ATTRIBUTE_VALUE
56 {
57 public:
58     QString attrName;
59     QVariant value;
60 };
61 
62 class DBC_VAL_ENUM_ENTRY
63 {
64 public:
65     int value;
66     QString descript;
67 };
68 
69 class DBC_NODE
70 {
71 public:
72     QString name;
73     QString comment;
74     QList<DBC_ATTRIBUTE_VALUE> attributes;
75 
76     DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
77     DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
78 
79     friend bool operator<(const DBC_NODE& l, const DBC_NODE& r)
80     {
81         return (l.name.toLower() < r.name.toLower());
82     }
83 };
84 
85 class DBC_MESSAGE; //forward reference so that DBC_SIGNAL can compile before we get to real definition of DBC_MESSAGE
86 class DBC_SIGNAL;
87 
88 class DBC_SIGNAL
89 {
90 public: //TODO: this is sloppy. It shouldn't all be public!
91     QString name;
92     int startBit;
93     int signalSize;
94     bool intelByteOrder; //true is obviously little endian. False is big endian
95     bool isMultiplexor;
96     bool isMultiplexed;
97     int multiplexHighValue;
98     int multiplexLowValue;
99     DBC_SIG_VAL_TYPE valType;
100     double factor;
101     double bias;
102     double min;
103     double max;
104     DBC_NODE *receiver; //it is fast to have a pointer but dangerous... Make sure to walk the whole tree and delete everything so nobody has stale references.
105     DBC_MESSAGE *parentMessage;
106     QString unitName;
107     QString comment;
108     QVariant cachedValue;
109     QList<DBC_ATTRIBUTE_VALUE> attributes;
110     QList<DBC_VAL_ENUM_ENTRY> valList;
111     QList<DBC_SIGNAL *> multiplexedChildren;
112     DBC_SIGNAL *multiplexParent;
113 
114     DBC_SIGNAL();
115     bool processAsText(const CANFrame &frame, QString &outString, bool outputName = true);
116     bool processAsInt(const CANFrame &frame, int32_t &outValue);
117     bool processAsDouble(const CANFrame &frame, double &outValue);
118     bool getValueString(int64_t intVal, QString &outString);
119     QString makePrettyOutput(double floatVal, int64_t intVal, bool outputName = true, bool isInteger = false);
120     QString processSignalTree(const CANFrame &frame);
121     DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
122     DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
123     bool isSignalInMessage(const CANFrame &frame);
124 
125     friend bool operator<(const DBC_SIGNAL& l, const DBC_SIGNAL& r)
126     {
127         return (l.name.toLower() < r.name.toLower());
128     }
129 };
130 
131 class DBCSignalHandler; //forward declaration to keep from having to include dbchandler.h in this file and thus create a loop
132 
133 class DBC_MESSAGE
134 {
135 public:
136     DBC_MESSAGE();
137 
138     uint32_t ID;
139     bool extendedID;
140     QString name;
141     QString comment;
142     unsigned int len;
143     DBC_NODE *sender;
144     QColor bgColor;
145     QColor fgColor;
146     QList<DBC_ATTRIBUTE_VALUE> attributes;
147     DBCSignalHandler *sigHandler;
148     DBC_SIGNAL* multiplexorSignal;
149 
150     DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
151     DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
152 
153     friend bool operator<(const DBC_MESSAGE& l, const DBC_MESSAGE& r)
154     {
155         return (l.name.toLower() < r.name.toLower());
156     }
157 };
158 
159 
160 #endif // DBC_CLASSES_H
161 
162