##// END OF EJS Templates
Sync
Jeandet Alexis -
r57:d1a982ae47e5 default
parent child
Show More
@@ -0,0 +1,62
1 #include "genericbinaryfilewidget.h"
2 #include "ui_genericbinaryfilewidget.h"
3 #include <QFileDialog>
4 #include <QFile>
5 #include "srec/srecfile.h"
6
7 genericBinaryFileWidget::genericBinaryFileWidget(QWidget *parent) :
8 QWidget(parent),
9 ui(new Ui::genericBinaryFileWidget)
10 {
11 ui->setupUi(this);
12 }
13
14 genericBinaryFileWidget::~genericBinaryFileWidget()
15 {
16 delete ui;
17 }
18
19 void genericBinaryFileWidget::openFile()
20 {
21 QStringList filesNames = QFileDialog::getOpenFileNames(
22 this,
23 "Select one or more files to open",
24 NULL,
25 "Binary Files (*.bin);;SREC Files (*.srec);;Elf Files (*)");
26
27 for(int i=0;i<filesNames.count();i++)
28 {
29 QFile file(filesNames.at(i));
30 if(file.open(QIODevice::ReadOnly))
31 {
32 char magic[4];
33 file.read(magic,4);
34 QString line;
35 switch((int)magic[0])
36 {
37 case 'e':
38 if((magic[1]=='l') && (magic[2]=='f'))
39 {
40 files.append(new FileListElement(filesNames.at(i),false,Type_Elf,NULL));
41 }
42 break;
43 case 'S':
44 file.seek(0);
45 line = file.readLine();
46 if(srecFile::checkSum(line))
47 {
48 files.append(new FileListElement(filesNames.at(i),false,Type_SREC,NULL));
49 }
50 break;
51 default:
52 files.append(new FileListElement(filesNames.at(i),false,Type_Bin,NULL));
53 break;
54 }
55 }
56 }
57
58 }
59
60
61
62
@@ -0,0 +1,42
1 #ifndef GENERICBINARYFILEWIDGET_H
2 #define GENERICBINARYFILEWIDGET_H
3
4 #include <QWidget>
5 #include <QString>
6 #include <QStringList>
7 #include <abstractbinfile.h>
8
9 namespace Ui {
10 class genericBinaryFileWidget;
11 }
12
13 typedef enum {Type_SREC,Type_Bin,Type_Elf}FileTypeEnum;
14 class FileListElement
15 {
16 public:
17 FileListElement() {}
18 FileListElement(QString fileName,bool isOpened,FileTypeEnum FileType,abstractBinFileWidget* viewer)
19 :fileName(fileName),isOpened(isOpened),FileType(FileType),viewer(viewer){}
20 QString fileName;
21 bool isOpened;
22 FileTypeEnum FileType;
23 abstractBinFileWidget* viewer;
24 };
25
26 class genericBinaryFileWidget : public QWidget
27 {
28 Q_OBJECT
29
30 public:
31 explicit genericBinaryFileWidget(QWidget *parent = 0);
32 ~genericBinaryFileWidget();
33
34 public slots:
35 void openFile();
36
37 private:
38 Ui::genericBinaryFileWidget *ui;
39 QList<FileListElement*> files;
40 };
41
42 #endif // GENERICBINARYFILEWIDGET_H
@@ -0,0 +1,103
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>genericBinaryFileWidget</class>
4 <widget class="QWidget" name="genericBinaryFileWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>878</width>
10 <height>360</height>
11 </rect>
12 </property>
13 <property name="acceptDrops">
14 <bool>false</bool>
15 </property>
16 <property name="windowTitle">
17 <string>Form</string>
18 </property>
19 <layout class="QGridLayout" name="gridLayout_2">
20 <item row="0" column="0">
21 <widget class="QSplitter" name="splitter">
22 <property name="orientation">
23 <enum>Qt::Horizontal</enum>
24 </property>
25 <widget class="QWidget" name="widget" native="true">
26 <layout class="QGridLayout" name="gridLayout">
27 <item row="1" column="0">
28 <widget class="QPushButton" name="openFileQpb">
29 <property name="text">
30 <string/>
31 </property>
32 <property name="icon">
33 <iconset resource="../SocExplorerCommon.qrc">
34 <normaloff>:/images/add.svg</normaloff>:/images/add.svg</iconset>
35 </property>
36 <property name="iconSize">
37 <size>
38 <width>32</width>
39 <height>32</height>
40 </size>
41 </property>
42 </widget>
43 </item>
44 <item row="1" column="1">
45 <widget class="QPushButton" name="removeFileQpb">
46 <property name="text">
47 <string/>
48 </property>
49 <property name="icon">
50 <iconset resource="../SocExplorerCommon.qrc">
51 <normaloff>:/images/trash.svg</normaloff>:/images/trash.svg</iconset>
52 </property>
53 <property name="iconSize">
54 <size>
55 <width>32</width>
56 <height>32</height>
57 </size>
58 </property>
59 </widget>
60 </item>
61 <item row="1" column="2">
62 <spacer name="horizontalSpacer">
63 <property name="orientation">
64 <enum>Qt::Horizontal</enum>
65 </property>
66 <property name="sizeHint" stdset="0">
67 <size>
68 <width>40</width>
69 <height>20</height>
70 </size>
71 </property>
72 </spacer>
73 </item>
74 <item row="0" column="0" colspan="3">
75 <widget class="QTableWidget" name="tableWidget">
76 <column>
77 <property name="text">
78 <string>File</string>
79 </property>
80 </column>
81 <column>
82 <property name="text">
83 <string>Type</string>
84 </property>
85 </column>
86 </widget>
87 </item>
88 </layout>
89 </widget>
90 <widget class="QTabWidget" name="fileViewerTab">
91 <property name="currentIndex">
92 <number>-1</number>
93 </property>
94 </widget>
95 </widget>
96 </item>
97 </layout>
98 </widget>
99 <resources>
100 <include location="../SocExplorerCommon.qrc"/>
101 </resources>
102 <connections/>
103 </ui>
@@ -5,13 +5,13
5 5 #include "qhexedit/qhexedit.h"
6 6 #include "SocExplorerPlot.h"
7 7 #include "tcp_terminal_client.h"
8 #include "elf/elfparser.h"
9 #include "abstractbinfile.h"
10 #include "elf/elffile.h"
11 #include "elf/elffilewidget.h"
12 #include "elf/elfinfowdgt.h"
13 8 #include "QCustomPlot/qcustomplot.h"
14 #include "srec/srecfile.h"
15 #include "srec/srecfilewidget.h"
16 #include "BinFile/binaryfile.h"
17 #include "BinFile/binaryfilewidget.h"
9 #include "genericBinaryFiles/abstractbinfile.h"
10 #include "genericBinaryFiles/elf/elfparser.h"
11 #include "genericBinaryFiles/elf/elffile.h"
12 #include "genericBinaryFiles/elf/elffilewidget.h"
13 #include "genericBinaryFiles/elf/elfinfowdgt.h"
14 #include "genericBinaryFiles/srec/srecfile.h"
15 #include "genericBinaryFiles/srec/srecfilewidget.h"
16 #include "genericBinaryFiles/BinFile/binaryfile.h"
17 #include "genericBinaryFiles/BinFile/binaryfilewidget.h"
@@ -96,7 +96,8 HEADERS += \
96 96 genericBinaryFiles/srec/srecfilewidget.h \
97 97 genericBinaryFiles/abstractbinfile.h \
98 98 genericBinaryFiles/BinFile/binaryfile.h \
99 genericBinaryFiles/BinFile/binaryfilewidget.h
99 genericBinaryFiles/BinFile/binaryfilewidget.h \
100 genericBinaryFiles/genericbinaryfilewidget.h
100 101
101 102
102 103 SOURCES += \
@@ -120,12 +121,14 SOURCES += \
120 121 genericBinaryFiles/srec/srecfilewidget.cpp \
121 122 genericBinaryFiles/abstractbinfile.cpp \
122 123 genericBinaryFiles/BinFile/binaryfile.cpp \
123 genericBinaryFiles/BinFile/binaryfilewidget.cpp
124 genericBinaryFiles/BinFile/binaryfilewidget.cpp \
125 genericBinaryFiles/genericbinaryfilewidget.cpp
124 126
125 127 FORMS += \
126 128 genericBinaryFiles/elf/elffilewidget.ui \
127 129 genericBinaryFiles/srec/srecfilewidget.ui \
128 genericBinaryFiles/BinFile/binaryfilewidget.ui
130 genericBinaryFiles/BinFile/binaryfilewidget.ui \
131 genericBinaryFiles/genericbinaryfilewidget.ui
129 132
130 133 OTHER_FILES += \
131 134 ./pythongenerator.sh \
@@ -133,3 +136,5 OTHER_FILES += \
133 136
134 137
135 138
139
140
@@ -25,15 +25,18
25 25
26 26 srecFile::srecFile()
27 27 {
28 p_mergingRecords = true;
28 29 }
29 30
30 31 srecFile::srecFile(const QString &File)
31 32 {
33 p_mergingRecords = true;
32 34 openFile(File);
33 35 }
34 36
35 37 srecFile::srecFile(const QStringList &Files)
36 38 {
39 p_mergingRecords = true;
37 40 openFiles(Files);
38 41 }
39 42
@@ -101,9 +104,9 bool srecFile::toSrec(QList<codeFragment
101 104 for(int i=0;i<fragments.count();i++)
102 105 {
103 106 codeFragment *fragment = fragments.at(i);
104 for(int j=0;j<((int)(fragment->size));j+=16)
107 for(int j=0;j<((int)(fragment->size)/16);j++)
105 108 {
106 stream << buildRecord(3,fragment->address+j,fragment->data+j,16);
109 stream << buildRecord(3,fragment->address+(j*16),fragment->data+(j*16),16);
107 110 }
108 111 int rem = fragment->size % 16;
109 112 if(rem)
@@ -186,6 +189,16 bool srecFile::getFragmentData(int index
186 189 return false;
187 190 }
188 191
192 bool srecFile::mergingRecords()
193 {
194 return p_mergingRecords;
195 }
196
197 void srecFile::setMergingRecords(bool enabled)
198 {
199 p_mergingRecords = enabled;
200 }
201
189 202 bool srecFile::isSREC()
190 203 {
191 204 return p_isSrec & isopened();
@@ -205,6 +218,7 bool srecFile::isSREC(const QString &Fil
205 218 return false;
206 219 }
207 220
221
208 222 void srecFile::parseFile(QFile *file)
209 223 {
210 224 if(file->isOpen())
@@ -212,6 +226,7 void srecFile::parseFile(QFile *file)
212 226 this->p_lineCount = 0;
213 227 file->seek(0);
214 228 codeFragment* fragment=NULL;
229 bool newFragment=true;
215 230 char* data;
216 231 quint64 size=0;
217 232 quint64 address=-1;
@@ -233,22 +248,16 void srecFile::parseFile(QFile *file)
233 248 {
234 249 if((rectype>=1) && (rectype<=3))
235 250 {
236 bool merged = false;
251 if(p_mergingRecords)
252 {
237 253 //Could I merge it with an other fragment?
238 // TODO should make merging optionnal
254 bool merged = false;
239 255 for(int i=0;i<p_fragments.count();i++)
240 256 {
241 257 codeFragment* frag = p_fragments.at(i);
242 258 if(((frag->address+frag->size)==address) && (merged==false) && (size!=0))
243 259 {
244 char* mergedData=(char*)malloc(size+frag->size);
245 memcpy(mergedData,frag->data,frag->size);
246 memcpy(mergedData+frag->size,data,size);
247 free(frag->data);
248 free(data);
249 frag->data = mergedData;
250 frag->size = frag->size+size;
251 merged = true;
260 merged = mergeFragment(frag,data,size);
252 261 }
253 262 }
254 263 if(!merged)
@@ -260,12 +269,33 void srecFile::parseFile(QFile *file)
260 269 }
261 270 else
262 271 {
272 if(newFragment)
273 {
274 fragment = new codeFragment(data,size,address);
275 fragment->header = header;
276 p_fragments.append(fragment);
277 newFragment = false;
278 }
279 else
280 {
281 codeFragment* frag = p_fragments.last();
282 mergeFragment(frag,data,size);
283 }
284 }
263 285
264 286 }
287 else
288 {
289 if((rectype>=7) && (rectype<=9))
290 {
291 newFragment = true;
292 }
265 293 }
266 294 }
267 295 }
268 296 }
297 }
298
269 299
270 300 int srecFile::parseLine(const QString &record, quint64 *address, char **data, quint64 *size)
271 301 {
@@ -340,6 +370,7 int srecFile::parseLine(const QString &r
340 370 return recType;
341 371 }
342 372
373
343 374 char srecFile::lineCheckSum(const QString &line)
344 375 {
345 376 char sum=0;
@@ -363,8 +394,14 bool srecFile::checkSum(const QString &l
363 394 scp.remove('\r');
364 395 char ck2 = (char)scp.mid(scp.count()-2,2).toInt(0,16);
365 396 char ck=lineCheckSum(scp.remove(scp.count()-2,2));
366 return (ck2==ck);
397 if(ck==ck2)
398 {
399 return true;
367 400 }
401 return false;
402 // return (ck2==ck);
403 }
404
368 405
369 406 QString srecFile::buildRecord(int recType, int address,const char *data, int size)
370 407 {
@@ -401,3 +438,19 QString srecFile::buildRecord(int recTyp
401 438 return record.toUpper();
402 439 }
403 440
441 bool srecFile::mergeFragment(codeFragment *fragment, char *data, int size)
442 {
443 char* mergedData=(char*)malloc(size+fragment->size);
444 if(mergedData!=NULL)
445 {
446 memcpy(mergedData,fragment->data,fragment->size);
447 memcpy(mergedData+fragment->size,data,size);
448 free(fragment->data);
449 free(data);
450 fragment->data = mergedData;
451 fragment->size = fragment->size+size;
452 return true;
453 }
454 return false;
455 }
456
@@ -51,8 +51,11 public:
51 51 QString getFragmentHeader(int index);
52 52 bool getFragmentData(int index, char **buffer);
53 53
54 bool mergingRecords();
55 void setMergingRecords(bool enabled);
54 56 bool isSREC();
55 57 static bool isSREC(const QString& File);
58 static bool checkSum(const QString& line);
56 59 signals:
57 60
58 61 public slots:
@@ -60,13 +63,14 private:
60 63 void parseFile(QFile* file);
61 64 static int parseLine(const QString& record, quint64 *address, char** data, quint64 *size);
62 65 static char lineCheckSum(const QString& line);
63 static bool checkSum(const QString& line);
64 66 static QString buildRecord(int recType,int address,const char* data,int size);
67 static bool mergeFragment(codeFragment* fragment, char* data, int size);
65 68 QStringList p_fileNames;
66 69 QList<QFile*>p_files;
67 70 QList<codeFragment*> p_fragments;
68 71 int p_lineCount;
69 72 bool p_isSrec;
73 bool p_mergingRecords;
70 74
71 75 };
72 76
@@ -46,6 +46,12
46 46 <property name="contextMenuPolicy">
47 47 <enum>Qt::ActionsContextMenu</enum>
48 48 </property>
49 <attribute name="horizontalHeaderVisible">
50 <bool>true</bool>
51 </attribute>
52 <attribute name="verticalHeaderVisible">
53 <bool>false</bool>
54 </attribute>
49 55 <column>
50 56 <property name="text">
51 57 <string>Index</string>
@@ -7701,6 +7701,11 int PythonQtWrapper_srecFile::lineCount
7701 7701 return ( theWrappedObject->lineCount());
7702 7702 }
7703 7703
7704 bool PythonQtWrapper_srecFile::mergingRecords(srecFile* theWrappedObject)
7705 {
7706 return ( theWrappedObject->mergingRecords());
7707 }
7708
7704 7709 bool PythonQtWrapper_srecFile::openFile(srecFile* theWrappedObject, const QString& File)
7705 7710 {
7706 7711 return ( ((PythonQtPublicPromoter_srecFile*)theWrappedObject)->promoted_openFile(File));
@@ -7711,6 +7716,11 bool PythonQtWrapper_srecFile::openFile
7711 7716 return ( theWrappedObject->openFiles(Files));
7712 7717 }
7713 7718
7719 void PythonQtWrapper_srecFile::setMergingRecords(srecFile* theWrappedObject, bool enabled)
7720 {
7721 ( theWrappedObject->setMergingRecords(enabled));
7722 }
7723
7714 7724 bool PythonQtWrapper_srecFile::toBinary(srecFile* theWrappedObject, const QString& File)
7715 7725 {
7716 7726 return ( ((PythonQtPublicPromoter_srecFile*)theWrappedObject)->promoted_toBinary(File));
@@ -778,12 +778,12 codeFragment* new_codeFragment(char* da
778 778 void delete_codeFragment(codeFragment* obj) { delete obj; }
779 779 void py_set_size(codeFragment* theWrappedObject, quint64 size){ theWrappedObject->size = size; }
780 780 quint64 py_get_size(codeFragment* theWrappedObject){ return theWrappedObject->size; }
781 void py_set_address(codeFragment* theWrappedObject, quint64 address){ theWrappedObject->address = address; }
782 quint64 py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; }
783 void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; }
784 char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; }
781 785 void py_set_header(codeFragment* theWrappedObject, QString header){ theWrappedObject->header = header; }
782 786 QString py_get_header(codeFragment* theWrappedObject){ return theWrappedObject->header; }
783 void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; }
784 char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; }
785 void py_set_address(codeFragment* theWrappedObject, quint64 address){ theWrappedObject->address = address; }
786 quint64 py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; }
787 787 };
788 788
789 789
@@ -976,8 +976,10 void delete_srecFile(srecFile* obj) { de
976 976 bool static_srecFile_isSREC(const QString& File);
977 977 bool isopened(srecFile* theWrappedObject);
978 978 int lineCount(srecFile* theWrappedObject);
979 bool mergingRecords(srecFile* theWrappedObject);
979 980 bool openFile(srecFile* theWrappedObject, const QString& File);
980 981 bool openFiles(srecFile* theWrappedObject, const QStringList& Files);
982 void setMergingRecords(srecFile* theWrappedObject, bool enabled);
981 983 bool toBinary(srecFile* theWrappedObject, const QString& File);
982 984 bool static_srecFile_toSrec(QList<codeFragment* > fragments, const QString& File);
983 985 bool toSrec(srecFile* theWrappedObject, const QString& File);
@@ -3,4 +3,4
3 3 #export QTDIR=/usr/include
4 4 #export QTDIR=/usr/include/qt5
5 5
6 pythonqt_generator --include-paths=./genericBinaryFiles/elf:./genericBinaryFiles/srec:./genericBinaryFiles/BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt
6 pythonqt_generator --include-paths=./genericBinaryFiles/:./genericBinaryFiles/elf:./genericBinaryFiles/srec:./genericBinaryFiles/BinFile:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut PySocExplorer.h pythonQtgeneratorCfg.txt
General Comments 0
You need to be logged in to leave comments. Login now