1 #ifndef DBCHANDLER_H
2 #define DBCHANDLER_H
3 
4 #include <QObject>
5 #include "dbc_classes.h"
6 #include "can_structs.h"
7 
8     typedef enum
9     {
10         EXACT,
11         J1939,
12         GMLAN
13     } MatchingCriteria_t;
14 
15 /*
16  * TODO:
17  * Finish coding up the decoupled design
18  *
19 */
20 class DBCSignalHandler: public QObject
21 {
22     Q_OBJECT
23 public:
24     DBC_SIGNAL *findSignalByName(QString name);
25     DBC_SIGNAL *findSignalByIdx(int idx);
26     bool addSignal(DBC_SIGNAL &sig);
27     bool removeSignal(DBC_SIGNAL *sig);
28     bool removeSignal(int idx);
29     bool removeSignal(QString name);
30     void removeAllSignals();
31     int getCount();
32     void sort();
33 
34 private:
35     QList<DBC_SIGNAL> sigs; //signals is a reserved word or I'd have used that
36 };
37 
38 class DBCMessageHandler: public QObject
39 {
40     Q_OBJECT
41 public:
42     DBC_MESSAGE *findMsgByID(uint32_t id);
43     DBC_MESSAGE *findMsgByIdx(int idx);
44     DBC_MESSAGE *findMsgByName(QString name);
45     DBC_MESSAGE *findMsgByPartialName(QString name);
46     bool addMessage(DBC_MESSAGE &msg);
47     bool removeMessage(DBC_MESSAGE *msg);
48     bool removeMessageByIndex(int idx);
49     bool removeMessage(uint32_t ID);
50     bool removeMessage(QString name);
51     void removeAllMessages();
52     int getCount();
53     MatchingCriteria_t getMatchingCriteria();
54     void setMatchingCriteria(MatchingCriteria_t mc);
55     void setFilterLabeling( bool labelFiltering );
56     bool filterLabeling();
57     void sort();
58 
59 private:
60     QList<DBC_MESSAGE> messages;
61     MatchingCriteria_t matchingCriteria;
62     bool filterLabelingEnabled;
63 };
64 
65 //technically there should be a node handler too but I'm sort of treating nodes as second class
66 //citizens since they aren't really all that important (to me anyway)
67 class DBCFile: public QObject
68 {
69     Q_OBJECT
70 public:
71     DBCFile();
72     DBCFile(const DBCFile& cpy);
73     DBCFile& operator=(const DBCFile& cpy);
74     DBC_NODE *findNodeByName(QString name);
75     DBC_NODE *findNodeByIdx(int idx);
76     DBC_ATTRIBUTE *findAttributeByName(QString name, DBC_ATTRIBUTE_TYPE type = ATTR_TYPE_ANY);
77     DBC_ATTRIBUTE *findAttributeByIdx(int idx);
78     void findAttributesByType(DBC_ATTRIBUTE_TYPE typ, QList<DBC_ATTRIBUTE> *list);
79     bool saveFile(QString);
80     bool loadFile(QString);
81     QString getFullFilename();
82     QString getFilename();
83     QString getPath();
84     int getAssocBus();
85     void setAssocBus(int bus);
86     void setDirtyFlag();
87     bool getDirtyFlag();
88     void sort();
89 
90     DBCMessageHandler *messageHandler;
91     QList<DBC_NODE> dbc_nodes;
92     QList<DBC_ATTRIBUTE> dbc_attributes;
93 private:
94     QString fileName;
95     QString filePath;
96     int assocBuses; //-1 = all buses, 0 = first bus, 1 = second bus, etc.
97     bool isDirty; //has the file been modified?
98 
99     bool parseAttribute(QString inpString, DBC_ATTRIBUTE &attr);
100     QVariant processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ);
101     DBC_SIGNAL* parseSignalLine(QString line, DBC_MESSAGE *msg);
102     bool parseSignalMultiplexValueLine(QString line);
103     DBC_MESSAGE* parseMessageLine(QString line);
104     bool parseValueLine(QString line);
105     bool parseAttributeLine(QString line);
106     bool parseDefaultAttrLine(QString line);
107 };
108 
109 class DBCHandler: public QObject
110 {
111     Q_OBJECT
112 public:
113     DBCFile* loadDBCFile(QString filename);
114     DBCFile* loadDBCFile(int);
115     void saveDBCFile(int);
116     void removeDBCFile(int);
117     void removeAllFiles();
118     void swapFiles(int pos1, int pos2);
119     DBC_MESSAGE* findMessage(const CANFrame &frame);
120     DBC_MESSAGE* findMessage(const QString msgName);
121     DBC_MESSAGE* findMessage(uint32_t id);
122     DBC_MESSAGE* findMessageForFilter(uint32_t id, MatchingCriteria_t * matchingCriteria);
123     int getFileCount();
124     DBCFile* getFileByIdx(int idx);
125     DBCFile* getFileByName(QString name);
126     int createBlankFile();
127     DBCFile* loadJSONFile(QString);
128     static DBCHandler *getReference();
129 
130 private:
131     QList<DBCFile> loadedFiles;
132 
133     DBCHandler();
134     static DBCHandler *instance;
135 };
136 
137 #endif // DBCHANDLER_H
138