1 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
|
---|
2 | // DBC Decriptor //
|
---|
3 | // //
|
---|
4 | // Made by Pierre Hudelaine //
|
---|
5 | // //
|
---|
6 | // Contact: pierre.hudelaine@hds.utc.fr //
|
---|
7 | // //
|
---|
8 | // Translate a DBC file to Pacpus code //
|
---|
9 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
|
---|
10 |
|
---|
11 | #include "mainwindow.h"
|
---|
12 | #include "ui_mainwindow.h"
|
---|
13 | #include <iostream>
|
---|
14 | #include <math.h>
|
---|
15 |
|
---|
16 | #include <QString>
|
---|
17 | #include <QFileDialog>
|
---|
18 | #include <QTextStream>
|
---|
19 | #include <QDebug>
|
---|
20 | #include <QDate>
|
---|
21 |
|
---|
22 |
|
---|
23 | //----------------------------------------------------------------------------//
|
---|
24 | // Constructor //
|
---|
25 | //----------------------------------------------------------------------------//
|
---|
26 | MainWindow::MainWindow(QWidget *parent) :
|
---|
27 | QMainWindow(parent),
|
---|
28 | ui(new Ui::MainWindow)
|
---|
29 | {
|
---|
30 | ui->setupUi(this);
|
---|
31 |
|
---|
32 | connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openDBCFile()));
|
---|
33 | connect(ui->actionClose_all_files, SIGNAL(triggered()), this, SLOT(clearDBC()));
|
---|
34 | connect(ui->actionQuitter, SIGNAL(triggered()), this, SLOT(close()));
|
---|
35 | connect(ui->pushButton_open_file, SIGNAL(clicked()), this, SLOT(openDBCFile()));
|
---|
36 |
|
---|
37 | ui->label_file_error->setText("");
|
---|
38 | ui->label_value_frame_id->setText("");
|
---|
39 | ui->label_value_frame_name->setText("");
|
---|
40 | ui->label_value_number_of_signals->setText("");
|
---|
41 | ui->label_value_total_frames->setText("0");
|
---|
42 | ui->label_value_total_signals->setText("0");
|
---|
43 | ui->lineEdit_output_path->setText(QApplication::applicationDirPath());
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | //----------------------------------------------------------------------------//
|
---|
48 | // Destructor //
|
---|
49 | //----------------------------------------------------------------------------//
|
---|
50 | MainWindow::~MainWindow()
|
---|
51 | {
|
---|
52 | delete ui;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | //----------------------------------------------------------------------------//
|
---|
57 | // Open the DBC file //
|
---|
58 | //----------------------------------------------------------------------------//
|
---|
59 | void MainWindow::openDBCFile()
|
---|
60 | {
|
---|
61 | clearDBC();
|
---|
62 |
|
---|
63 | dbcFiles_.fileName = QFileDialog::getOpenFileName(this, "Open dbc file", "", "dbc files (*.dbc);;Text files (*.txt);;All files (*.*)");
|
---|
64 |
|
---|
65 | QFile file(dbcFiles_.fileName);
|
---|
66 |
|
---|
67 | if (!file.open(QIODevice::ReadOnly))
|
---|
68 | {
|
---|
69 | ui->label_file_error->setText("<font color=\"#C80000\">Can not open the file</font>");
|
---|
70 | }
|
---|
71 | else
|
---|
72 | {
|
---|
73 | QTextStream stream(&file);
|
---|
74 | dbcFiles_.content = stream.readAll().split('\n');
|
---|
75 |
|
---|
76 | QStringList signalName;
|
---|
77 | bool frameFound = false;
|
---|
78 | StructFrame tmpFrame;
|
---|
79 | tmpFrame.frameID = 0;
|
---|
80 | tmpFrame.frameName = "";
|
---|
81 | tmpFrame.numberOfSignals = 0;
|
---|
82 |
|
---|
83 | for (int i = 0; i < dbcFiles_.content.size(); i++)
|
---|
84 | {
|
---|
85 | if (frameFound)
|
---|
86 | {
|
---|
87 | // " SG_" is the beginning if a line containing a signal information
|
---|
88 | if (dbcFiles_.content[i].startsWith(" SG_"))
|
---|
89 | {
|
---|
90 | tmpFrame.numberOfSignals++;
|
---|
91 | getSignalParameters(dbcFiles_.content[i], &tmpFrame);
|
---|
92 | }
|
---|
93 | else
|
---|
94 | frameFound = false;
|
---|
95 | }
|
---|
96 |
|
---|
97 | // "BO_" is the beginning of a line containing a frame information and all signals are following
|
---|
98 | if (dbcFiles_.content[i].startsWith("BO_"))
|
---|
99 | {
|
---|
100 | int numberOfSpace = 0, j = 0;
|
---|
101 | QString tmp;
|
---|
102 |
|
---|
103 | frameFound = true;
|
---|
104 |
|
---|
105 | // Get the ID of the frame
|
---|
106 | while(numberOfSpace != 2)
|
---|
107 | {
|
---|
108 | if (dbcFiles_.content[i][j] == ' ')
|
---|
109 | numberOfSpace++;
|
---|
110 | if (numberOfSpace == 1)
|
---|
111 | tmp.append(dbcFiles_.content[i][j]);
|
---|
112 | j++;
|
---|
113 | }
|
---|
114 |
|
---|
115 | tmpFrame.frameID = tmp.toInt();
|
---|
116 |
|
---|
117 | tmp = "";
|
---|
118 |
|
---|
119 | // Get the name of the frame
|
---|
120 | while(dbcFiles_.content[i][j] != ':')
|
---|
121 | {
|
---|
122 | tmp.append(dbcFiles_.content[i][j]);
|
---|
123 | j++;
|
---|
124 | }
|
---|
125 |
|
---|
126 | tmpFrame.frameName = tmp;
|
---|
127 | }
|
---|
128 | else if (dbcFiles_.content[i].startsWith("CM_"))
|
---|
129 | {
|
---|
130 | // Get the comment at the end of the DBC file
|
---|
131 | findComment(i);
|
---|
132 | }
|
---|
133 | else if (dbcFiles_.content[i].startsWith("VAL_"))
|
---|
134 | {
|
---|
135 | // Get the value descritpion at the end of the DBC file
|
---|
136 | findValueDescription(i);
|
---|
137 | }
|
---|
138 |
|
---|
139 | // If a hole frame has been treated it's registered in the vector
|
---|
140 | if (tmpFrame.numberOfSignals != 0 && !frameFound)
|
---|
141 | {
|
---|
142 | dbcFiles_.canFrames.append(tmpFrame);
|
---|
143 | ui->label_value_total_frames->setText(QString().setNum(ui->label_value_total_frames->text().toInt() + 1));
|
---|
144 | ui->label_value_total_signals->setText(QString().setNum(ui->label_value_total_signals->text().toInt() + tmpFrame.numberOfSignals));
|
---|
145 | tmpFrame.frameID = 0;
|
---|
146 | tmpFrame.frameName = "";
|
---|
147 | tmpFrame.numberOfSignals = 0;
|
---|
148 | tmpFrame.signalsVector.clear();
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | // Frames are added in the list
|
---|
153 | for (int i = 0; i < dbcFiles_.canFrames.size(); i++)
|
---|
154 | {
|
---|
155 | if (dbcFiles_.canFrames[i].frameID >= 255)
|
---|
156 | signalName.append("0x" + QString().setNum(dbcFiles_.canFrames[i].frameID, 16).toUpper() + " " + dbcFiles_.canFrames[i].frameName);
|
---|
157 | else
|
---|
158 | signalName.append("0x0" + QString().setNum(dbcFiles_.canFrames[i].frameID, 16).toUpper() + " " + dbcFiles_.canFrames[i].frameName);
|
---|
159 | }
|
---|
160 |
|
---|
161 | ui->listWidget_signals->addItems(signalName);
|
---|
162 | file.close();
|
---|
163 |
|
---|
164 | //printAllFrames();
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | //----------------------------------------------------------------------------//
|
---|
170 | // Print the parameters for a specific frame //
|
---|
171 | //----------------------------------------------------------------------------//
|
---|
172 | void MainWindow::printFrame(int i, int j)
|
---|
173 | {
|
---|
174 | qDebug() << dbcFiles_.canFrames[i].signalsVector[j].signalName << " "
|
---|
175 | << dbcFiles_.canFrames[i].signalsVector[j].startBit << " "
|
---|
176 | << dbcFiles_.canFrames[i].signalsVector[j].length << " "
|
---|
177 | << ((dbcFiles_.canFrames[i].signalsVector[j].order) ? "Motorola" : "Intel")
|
---|
178 | << " " << ((dbcFiles_.canFrames[i].signalsVector[j].valueType) ? "Signed" : "Unsigned")
|
---|
179 | << " " << dbcFiles_.canFrames[i].signalsVector[j].gain << " "
|
---|
180 | << dbcFiles_.canFrames[i].signalsVector[j].offset << " "
|
---|
181 | << dbcFiles_.canFrames[i].signalsVector[j].min << " "
|
---|
182 | << dbcFiles_.canFrames[i].signalsVector[j].max << " "
|
---|
183 | << ((dbcFiles_.canFrames[i].signalsVector[j].unit != "") ? dbcFiles_.canFrames[i].signalsVector[j].unit : "")
|
---|
184 | << dbcFiles_.canFrames[i].signalsVector[j].comment;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | //----------------------------------------------------------------------------//
|
---|
189 | // Print the parameters of all frames //
|
---|
190 | //----------------------------------------------------------------------------//
|
---|
191 | void MainWindow::printAllFrames()
|
---|
192 | {
|
---|
193 | for (int i = 0; i < dbcFiles_.canFrames.size(); i++)
|
---|
194 | {
|
---|
195 | for (int j = 0; j < dbcFiles_.canFrames[i].signalsVector.size(); j++)
|
---|
196 | {
|
---|
197 | printFrame(i, j);
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | //----------------------------------------------------------------------------//
|
---|
204 | // Get the the signals informations in the DBC file //
|
---|
205 | //----------------------------------------------------------------------------//
|
---|
206 | void MainWindow::getSignalParameters(QString actualLine, StructFrame * actualCanFrame)
|
---|
207 | {
|
---|
208 | StructSignal tmpSignal;
|
---|
209 |
|
---|
210 | tmpSignal.order = true;
|
---|
211 | tmpSignal.gain = 0.0;
|
---|
212 | tmpSignal.length = 0;
|
---|
213 | tmpSignal.offset = 0.0;
|
---|
214 | tmpSignal.signalName = "";
|
---|
215 | tmpSignal.valueType = true;
|
---|
216 | tmpSignal.startBit = 0;
|
---|
217 | tmpSignal.unit = "";
|
---|
218 | tmpSignal.comment = "";
|
---|
219 | tmpSignal.description = "";
|
---|
220 |
|
---|
221 | // Removing the untreated and unsued caracters
|
---|
222 | actualLine.remove('(');
|
---|
223 | actualLine.remove(')');
|
---|
224 | actualLine.remove('[');
|
---|
225 | actualLine.remove(']');
|
---|
226 | QStringList cutLine = actualLine.split(' ');
|
---|
227 |
|
---|
228 | // Get the name
|
---|
229 | tmpSignal.signalName = cutLine.at(2);
|
---|
230 | cutLine = actualLine.split(" : ");
|
---|
231 |
|
---|
232 | // Get the second part with the signal parameters for example : 63|8@0+ // 63 = startBit; 8 = length; 0 = Motorola order; + = Unsigned value
|
---|
233 | QStringList cutLineValue = cutLine.at(1).split(' ');
|
---|
234 | tmpSignal.startBit = cutLineValue.at(0).split('|').at(0).toInt();
|
---|
235 | tmpSignal.length = cutLineValue.at(0).split('|').at(1).split('@').at(0).toInt();
|
---|
236 | if (cutLineValue.at(0).split('|').at(1).split('@').at(1).at(0) == '1')
|
---|
237 | tmpSignal.order = false;
|
---|
238 | if (cutLineValue.at(0).split('|').at(1).split('@').at(1).at(1) == '+')
|
---|
239 | tmpSignal.valueType = false;
|
---|
240 |
|
---|
241 | // Get the offset and the gain for example : (0.05,2) // 0.05 = gain; 2 = offset;
|
---|
242 | tmpSignal.gain = cutLineValue.at(1).split(',').at(0).toDouble();
|
---|
243 | tmpSignal.offset = cutLineValue.at(1).split(',').at(1).toDouble();
|
---|
244 |
|
---|
245 | // Get the max and min for exemple : [-6.4|6.35] // -6.4 = max; 6.35 = max;
|
---|
246 | tmpSignal.min = cutLineValue.at(2).split('|').at(0).toDouble();
|
---|
247 | tmpSignal.max = cutLineValue.at(2).split('|').at(1).toDouble();
|
---|
248 |
|
---|
249 | // Get the unit for example : "m/s" // m/s = unit
|
---|
250 | tmpSignal.unit = cutLineValue.at(3);
|
---|
251 | tmpSignal.unit.remove('"');
|
---|
252 |
|
---|
253 | actualCanFrame->signalsVector.append(tmpSignal);
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | //----------------------------------------------------------------------------//
|
---|
258 | // Find a comment and associate it to the signal //
|
---|
259 | //----------------------------------------------------------------------------//
|
---|
260 | void MainWindow::findComment(int k)
|
---|
261 | {
|
---|
262 | for (int i = 0; i < dbcFiles_.canFrames.size(); i++)
|
---|
263 | {
|
---|
264 | for (int j = 0; j < dbcFiles_.canFrames[i].signalsVector.size(); j++)
|
---|
265 | {
|
---|
266 | if (dbcFiles_.content[k].contains(dbcFiles_.canFrames[i].signalsVector[j].signalName))
|
---|
267 | {
|
---|
268 | dbcFiles_.canFrames[i].signalsVector[j].comment = dbcFiles_.content[k].split('"').at(1);
|
---|
269 |
|
---|
270 | while (dbcFiles_.content[k].at(dbcFiles_.content[k].size() - 2) != ';')
|
---|
271 | {
|
---|
272 | k++;
|
---|
273 | dbcFiles_.canFrames[i].signalsVector[j].comment += dbcFiles_.content[k];
|
---|
274 | }
|
---|
275 | return;
|
---|
276 | }
|
---|
277 | }
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | //----------------------------------------------------------------------------//
|
---|
283 | // Find the value description and associate it to the signal //
|
---|
284 | //----------------------------------------------------------------------------//
|
---|
285 | void MainWindow::findValueDescription(int k)
|
---|
286 | {
|
---|
287 | for (int i = 0; i < dbcFiles_.canFrames.size(); i++)
|
---|
288 | {
|
---|
289 | for (int j = 0; j < dbcFiles_.canFrames[i].signalsVector.size(); j++)
|
---|
290 | {
|
---|
291 | if (dbcFiles_.content[k].contains(dbcFiles_.canFrames[i].signalsVector[j].signalName))
|
---|
292 | {
|
---|
293 | dbcFiles_.canFrames[i].signalsVector[j].description = dbcFiles_.content[k].right(dbcFiles_.content[k].length() - (dbcFiles_.content[k].indexOf(dbcFiles_.canFrames[i].signalsVector[j].signalName) + dbcFiles_.canFrames[i].signalsVector[j].signalName.length()));
|
---|
294 | return;
|
---|
295 | }
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 |
|
---|
301 | //----------------------------------------------------------------------------//
|
---|
302 | // Called from the HMI to clear the last information //
|
---|
303 | //----------------------------------------------------------------------------//
|
---|
304 | void MainWindow::clearDBC()
|
---|
305 | {
|
---|
306 | dbcFiles_.canFrames.clear();
|
---|
307 | dbcFiles_.content.clear();
|
---|
308 | dbcFiles_.fileName = "";
|
---|
309 | ui->listWidget_signals->clear();
|
---|
310 |
|
---|
311 | ui->label_file_error->setText("");
|
---|
312 | ui->label_value_frame_id->setText("");
|
---|
313 | ui->label_value_frame_name->setText("");
|
---|
314 | ui->label_value_number_of_signals->setText("");
|
---|
315 | ui->label_value_total_frames->setText("0");
|
---|
316 | ui->label_value_total_signals->setText("0");
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | //----------------------------------------------------------------------------//
|
---|
321 | // Actualize the HMI with the last information //
|
---|
322 | //----------------------------------------------------------------------------//
|
---|
323 | void MainWindow::on_listWidget_signals_currentRowChanged(int currentRow)
|
---|
324 | {
|
---|
325 | if (currentRow >= 0)
|
---|
326 | {
|
---|
327 | if (dbcFiles_.canFrames[currentRow].frameID >= 255)
|
---|
328 | ui->label_value_frame_id->setText("0x" + QString().setNum(dbcFiles_.canFrames[currentRow].frameID, 16).toUpper());
|
---|
329 | else
|
---|
330 | ui->label_value_frame_id->setText("0x0" + QString().setNum(dbcFiles_.canFrames[currentRow].frameID, 16).toUpper());
|
---|
331 |
|
---|
332 | ui->label_value_frame_name->setText(dbcFiles_.canFrames[currentRow].frameName);
|
---|
333 | ui->label_value_number_of_signals->setText(QString().setNum(dbcFiles_.canFrames[currentRow].numberOfSignals));
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | //----------------------------------------------------------------------------//
|
---|
339 | // Generate the c++ files from the dbc information previouly registered //
|
---|
340 | //----------------------------------------------------------------------------//
|
---|
341 | void MainWindow::on_pushButton_generate_clicked()
|
---|
342 | {
|
---|
343 | QDate date(QDate::currentDate());
|
---|
344 |
|
---|
345 | // Creating the beginnig of the structure file
|
---|
346 | QString outputStructFile = templateStructFile;
|
---|
347 | outputStructFile.insert(outputStructFile.indexOf("created:") + 8, " " + QString().setNum(date.year()) + "/" + QString().setNum(date.month()) + "/" + QString().setNum(date.day()));
|
---|
348 | outputStructFile.insert(outputStructFile.indexOf("#ifndef __STRUCTURECAN") + 22, ui->lineEdit_export_name->text().toUpper());
|
---|
349 | outputStructFile.insert(outputStructFile.indexOf("#define __STRUCTURECAN") + 22, ui->lineEdit_export_name->text().toUpper());
|
---|
350 |
|
---|
351 | for (int i = 0; i < dbcFiles_.canFrames.size(); i++)
|
---|
352 | {
|
---|
353 | QString outputCPPFile = templateCPPFile;
|
---|
354 | QString outputHFile = templateHFile;
|
---|
355 |
|
---|
356 | // Creating the beginning of each c++ files
|
---|
357 | outputCPPFile.insert(outputCPPFile.indexOf("created:") + 8, " " + QString().setNum(date.year()) + "/" + QString().setNum(date.month()) + "/" + QString().setNum(date.day()));
|
---|
358 | outputCPPFile.insert(outputCPPFile.indexOf("#include \"CanFrame.h\"") + 18, dbcFiles_.canFrames[i].frameName);
|
---|
359 | outputCPPFile.insert(outputCPPFile.indexOf("void CanFrame") + 13, dbcFiles_.canFrames[i].frameName);
|
---|
360 |
|
---|
361 | // Creating the beginning of each h files
|
---|
362 | outputHFile.insert(outputHFile.indexOf("created:") + 8, " " + QString().setNum(date.year()) + "/" + QString().setNum(date.month()) + "/" + QString().setNum(date.day()));
|
---|
363 | outputHFile.insert(outputHFile.indexOf("#ifndef __CanFrame") + 18, dbcFiles_.canFrames[i].frameName);
|
---|
364 | outputHFile.insert(outputHFile.indexOf("#define __CanFrame") + 18, dbcFiles_.canFrames[i].frameName);
|
---|
365 | outputHFile.insert(outputHFile.indexOf("#include \"structureCan") + 22, ui->lineEdit_export_name->text());
|
---|
366 | outputHFile.insert(outputHFile.indexOf("class CAN") + 9, ui->lineEdit_export_name->text().toUpper());
|
---|
367 | outputHFile.insert(outputHFile.indexOf("_API CanFrame") + 13, dbcFiles_.canFrames[i].frameName);
|
---|
368 | outputHFile.insert(outputHFile.indexOf("CanFrame()") + 8, dbcFiles_.canFrames[i].frameName);
|
---|
369 | outputHFile.insert(outputHFile.indexOf("~CanFrame()") + 9, dbcFiles_.canFrames[i].frameName);
|
---|
370 | outputHFile.insert(outputHFile.indexOf("Struct data_;") + 6, dbcFiles_.canFrames[i].frameName);
|
---|
371 | outputHFile.insert(outputHFile.indexOf("return sizeof(Struct)") + 20, dbcFiles_.canFrames[i].frameName);
|
---|
372 |
|
---|
373 | // Adding the structure of frames
|
---|
374 | outputStructFile.insert(outputStructFile.indexOf("#include \"Pacpus/kernel/road_time.h") + 36, "\n\ntypedef struct\n{\n} Struct" + dbcFiles_.canFrames[i].frameName + ";");
|
---|
375 |
|
---|
376 | for (int j = 0; j < dbcFiles_.canFrames[i].signalsVector.size(); j++)
|
---|
377 | {
|
---|
378 | QString tmpCpp = "\n";
|
---|
379 |
|
---|
380 | // If variables are bool
|
---|
381 | if (dbcFiles_.canFrames[i].signalsVector[j].length == 1)
|
---|
382 | {
|
---|
383 | tmpCpp.append(" data_." + dbcFiles_.canFrames[i].signalsVector[j].signalName + " = mDecodeToBool(d_.frame.data, " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].startBit) + ");");
|
---|
384 | if (dbcFiles_.canFrames[i].signalsVector[j].description != "")
|
---|
385 | outputStructFile.insert(outputStructFile.indexOf("} Struct" + dbcFiles_.canFrames[i].frameName), " bool " + dbcFiles_.canFrames[i].signalsVector[j].signalName + "; /// " + dbcFiles_.canFrames[i].signalsVector[j].description + "\n");
|
---|
386 | else
|
---|
387 | outputStructFile.insert(outputStructFile.indexOf("} Struct" + dbcFiles_.canFrames[i].frameName), " bool " + dbcFiles_.canFrames[i].signalsVector[j].signalName + ";\n");
|
---|
388 | }
|
---|
389 | else
|
---|
390 | {
|
---|
391 | // If variables are Motorola or Intel
|
---|
392 | if (dbcFiles_.canFrames[i].signalsVector[j].order)
|
---|
393 | tmpCpp.append(" if (mDecodeTo");
|
---|
394 | else
|
---|
395 | tmpCpp.append(" if (iDecodeTo");
|
---|
396 |
|
---|
397 | // If variables are signed...
|
---|
398 | if (dbcFiles_.canFrames[i].signalsVector[j].valueType)
|
---|
399 | {
|
---|
400 | if (dbcFiles_.canFrames[i].signalsVector[j].length <= 8)
|
---|
401 | tmpCpp.append("I8(&ctmp, ");
|
---|
402 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 16)
|
---|
403 | tmpCpp.append("I16(&stmp, ");
|
---|
404 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 32)
|
---|
405 | tmpCpp.append("I32(<mp, ");
|
---|
406 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 64)
|
---|
407 | tmpCpp.append("I64(&lltmp, ");
|
---|
408 | }
|
---|
409 | else // ...Or not signed
|
---|
410 | {
|
---|
411 | if (dbcFiles_.canFrames[i].signalsVector[j].length <= 8)
|
---|
412 | tmpCpp.append("UI8(&uctmp, ");
|
---|
413 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 16)
|
---|
414 | tmpCpp.append("UI16(&ustmp, ");
|
---|
415 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 32)
|
---|
416 | tmpCpp.append("UI32(&ultmp, ");
|
---|
417 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 64)
|
---|
418 | tmpCpp.append("UI64(&ulltmp, ");
|
---|
419 | }
|
---|
420 |
|
---|
421 | // Code c++ added in the QString
|
---|
422 | tmpCpp.append("d_.frame.data, " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].startBit) + ", " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].length) + "))\n");
|
---|
423 | tmpCpp.append(" data_." + dbcFiles_.canFrames[i].signalsVector[j].signalName + " = ");
|
---|
424 |
|
---|
425 | // Find the c++ type between double or integer
|
---|
426 | if (floor(dbcFiles_.canFrames[i].signalsVector[j].gain) == dbcFiles_.canFrames[i].signalsVector[j].gain)
|
---|
427 | {
|
---|
428 | // If it's need a brace in c++
|
---|
429 | if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1 && dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
430 | tmpCpp.append("(");
|
---|
431 |
|
---|
432 | // Define the type of the pointer which will store temporally the data
|
---|
433 | if (!dbcFiles_.canFrames[i].signalsVector[j].valueType)
|
---|
434 | tmpCpp.append("u");
|
---|
435 |
|
---|
436 | if (dbcFiles_.canFrames[i].signalsVector[j].length <= 8)
|
---|
437 | tmpCpp.append("ctmp");
|
---|
438 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 16)
|
---|
439 | tmpCpp.append("stmp");
|
---|
440 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 32)
|
---|
441 | tmpCpp.append("ltmp");
|
---|
442 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 64)
|
---|
443 | tmpCpp.append("lltmp");
|
---|
444 |
|
---|
445 | // Setting the gain and the offset
|
---|
446 | if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1 && dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
447 | tmpCpp.append(" * " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].gain) + ") + " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].offset) + ";");
|
---|
448 | else if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1)
|
---|
449 | tmpCpp.append(" * " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].gain) + ";");
|
---|
450 | else if (dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
451 | tmpCpp.append(" + " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].offset) + ";");
|
---|
452 | else
|
---|
453 | tmpCpp.append(";");
|
---|
454 |
|
---|
455 | // Adding the value in the structure
|
---|
456 | QString tmp;
|
---|
457 |
|
---|
458 | // Find the c++ variable type /!\ May differ from the signal !!!!
|
---|
459 | if (dbcFiles_.canFrames[i].signalsVector[j].offset < 0 && !dbcFiles_.canFrames[i].signalsVector[j].valueType)
|
---|
460 | tmp.append(" int");
|
---|
461 | else
|
---|
462 | tmp.append(" uint");
|
---|
463 |
|
---|
464 | if (dbcFiles_.canFrames[i].signalsVector[j].length <= 8)
|
---|
465 | tmp.append("8_t " + dbcFiles_.canFrames[i].signalsVector[j].signalName + ";");
|
---|
466 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 16)
|
---|
467 | tmp.append("16_t " + dbcFiles_.canFrames[i].signalsVector[j].signalName + ";");
|
---|
468 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 32)
|
---|
469 | tmp.append("32_t " + dbcFiles_.canFrames[i].signalsVector[j].signalName + ";");
|
---|
470 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 64)
|
---|
471 | tmp.append("64_t " + dbcFiles_.canFrames[i].signalsVector[j].signalName + ";");
|
---|
472 |
|
---|
473 | if (dbcFiles_.canFrames[i].signalsVector[j].description != "")
|
---|
474 | tmp.append(" /// " + dbcFiles_.canFrames[i].signalsVector[j].description);
|
---|
475 |
|
---|
476 | outputStructFile.insert(outputStructFile.indexOf("} Struct" + dbcFiles_.canFrames[i].frameName), tmp + "\n");
|
---|
477 | }
|
---|
478 | else
|
---|
479 | {
|
---|
480 | tmpCpp.append("static_cast<double>(");
|
---|
481 |
|
---|
482 | if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1 && dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
483 | tmpCpp.append("(");
|
---|
484 |
|
---|
485 | if (!dbcFiles_.canFrames[i].signalsVector[j].valueType)
|
---|
486 | tmpCpp.append("u");
|
---|
487 |
|
---|
488 | if (dbcFiles_.canFrames[i].signalsVector[j].length <= 8)
|
---|
489 | tmpCpp.append("ctmp");
|
---|
490 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 16)
|
---|
491 | tmpCpp.append("stmp");
|
---|
492 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 32)
|
---|
493 | tmpCpp.append("ltmp");
|
---|
494 | else if (dbcFiles_.canFrames[i].signalsVector[j].length <= 64)
|
---|
495 | tmpCpp.append("lltmp");
|
---|
496 |
|
---|
497 | if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1 && dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
498 | tmpCpp.append(" * " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].gain) + ") + " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].offset) + ");");
|
---|
499 | else if (dbcFiles_.canFrames[i].signalsVector[j].gain != 1)
|
---|
500 | tmpCpp.append(" * " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].gain) + ");");
|
---|
501 | else if (dbcFiles_.canFrames[i].signalsVector[j].offset != 0)
|
---|
502 | tmpCpp.append(" + " + QString().setNum(dbcFiles_.canFrames[i].signalsVector[j].offset) + ");");
|
---|
503 | else
|
---|
504 | tmpCpp.append(");");
|
---|
505 |
|
---|
506 | QString tmp = "";
|
---|
507 | if (dbcFiles_.canFrames[i].signalsVector[j].description != "")
|
---|
508 | tmp.append(" /// " + dbcFiles_.canFrames[i].signalsVector[j].description);
|
---|
509 |
|
---|
510 | outputStructFile.insert(outputStructFile.indexOf("} Struct" + dbcFiles_.canFrames[i].frameName), " double " + dbcFiles_.canFrames[i].signalsVector[j].signalName + "; " + tmp + "\n");
|
---|
511 | }
|
---|
512 | }
|
---|
513 | if (dbcFiles_.canFrames[i].signalsVector[j].comment != "")
|
---|
514 | tmpCpp.append(" /*" + dbcFiles_.canFrames[i].signalsVector[j].comment + "*/");
|
---|
515 | outputCPPFile.insert(outputCPPFile.indexOf("unsigned char uctmp = 0") + 24, tmpCpp);
|
---|
516 | }
|
---|
517 | outputStructFile.insert(outputStructFile.indexOf("Struct" + dbcFiles_.canFrames[i].frameName + ";") + dbcFiles_.canFrames[i].frameName.size() + 7, "\n\ntypedef struct\n{\n road_time_t time;\n road_timerange_t timerange;\n Struct" + dbcFiles_.canFrames[i].frameName + " d;\n} TimeStampedStruct" + dbcFiles_.canFrames[i].frameName + ";");
|
---|
518 |
|
---|
519 | QFile canFrameCpp(ui->lineEdit_output_path->text() + "/CanFrame" + dbcFiles_.canFrames[i].frameName + ".cpp");
|
---|
520 | canFrameCpp.open(QIODevice::WriteOnly);
|
---|
521 | QTextStream cppOut(&canFrameCpp);
|
---|
522 | cppOut << outputCPPFile;
|
---|
523 | canFrameCpp.close();
|
---|
524 |
|
---|
525 | QFile canFrameH(ui->lineEdit_output_path->text() + "/CanFrame" + dbcFiles_.canFrames[i].frameName + ".h");
|
---|
526 | canFrameH.open(QIODevice::WriteOnly);
|
---|
527 | QTextStream hOut(&canFrameH);
|
---|
528 | hOut << outputHFile;
|
---|
529 | canFrameH.close();
|
---|
530 | }
|
---|
531 |
|
---|
532 | QFile struc(ui->lineEdit_output_path->text() + "/strucureCan" + ui->lineEdit_export_name->text() + ".h");
|
---|
533 | struc.open(QIODevice::WriteOnly);
|
---|
534 | QTextStream strucOut(&struc);
|
---|
535 | strucOut << outputStructFile;
|
---|
536 | struc.close();
|
---|
537 | }
|
---|
538 |
|
---|
539 |
|
---|
540 | //----------------------------------------------------------------------------//
|
---|
541 | // Unlock the pushButton "Generate" when a string is registerer //
|
---|
542 | //----------------------------------------------------------------------------//
|
---|
543 | void MainWindow::on_lineEdit_export_name_textChanged(const QString &arg1)
|
---|
544 | {
|
---|
545 | if (arg1 == "")
|
---|
546 | ui->pushButton_generate->setEnabled(false);
|
---|
547 | else
|
---|
548 | ui->pushButton_generate->setEnabled(true);
|
---|
549 | }
|
---|
550 |
|
---|
551 |
|
---|
552 | //----------------------------------------------------------------------------//
|
---|
553 | // Select the output directory //
|
---|
554 | //----------------------------------------------------------------------------//
|
---|
555 | void MainWindow::on_pushButton_output_path_clicked()
|
---|
556 | {
|
---|
557 | QString tmp = "";
|
---|
558 | if ((tmp = QFileDialog::getExistingDirectory(0, 0, ui->lineEdit_output_path->text())) != "")
|
---|
559 | ui->lineEdit_output_path->setText(tmp);
|
---|
560 | }
|
---|