Skip to content

Commit 6ea62a2

Browse files
committed
qt: implemented write of file dump to chip
1 parent fd48f92 commit 6ea62a2

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

qt/main_window.cpp

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
#include <QDebug>
1111
#include <QFileDialog>
1212
#include <QFile>
13+
#include <QStringList>
14+
#include <memory>
1315

1416
#define ROW_DATA_SIZE 16
17+
#define HEADER_ROW_NUM 1
18+
#define HEADER_HEX_COL 1
1519

1620
static void initBufferTable(QTableWidget *bufTable)
1721
{
@@ -187,13 +191,43 @@ void MainWindow::slotProgRead()
187191

188192
void MainWindow::slotProgWrite()
189193
{
190-
uint32_t i;
191-
uint8_t buf[2048];
194+
bool convIsOk;
195+
QStringList sl;
196+
std::unique_ptr< uint8_t[] > buf;
197+
uint32_t bufSize, bufIter = 0;
198+
uint32_t rowCount = ui->bufferTableWidget->rowCount() - HEADER_ROW_NUM;
199+
200+
if (!rowCount)
201+
{
202+
qInfo() << "Buffer is empty";
203+
return;
204+
}
205+
206+
bufSize = rowCount * ROW_DATA_SIZE;
207+
buf = std::unique_ptr< uint8_t[] >(new (std::nothrow) uint8_t[bufSize]);
208+
if (!buf.get())
209+
{
210+
qCritical() << "Failed to allocate memory for write buffer";
211+
return;
212+
}
213+
214+
for (uint32_t i = HEADER_ROW_NUM; i <= rowCount; i++)
215+
{
216+
sl = ui->bufferTableWidget->item(i, HEADER_HEX_COL)->
217+
text().split(QChar(' '), QString::SkipEmptyParts);
192218

193-
for (i = 0; i < sizeof(buf); i++)
194-
buf[i] = i;
219+
for (int j = 0; j < sl.size(); j++)
220+
{
221+
buf[bufIter++] = sl.at(j).toUInt(&convIsOk, 16);
222+
if (!convIsOk)
223+
{
224+
qCritical() << "Failed to convert row item to byte";
225+
return;
226+
}
227+
}
228+
}
195229

196-
if (prog->writeChip(buf, 0x00000000, sizeof(buf)))
230+
if (prog->writeChip(buf.get(), 0x00000000, bufIter))
197231
log(tr("Failed to write chip\n"));
198232
else
199233
log(tr("Data has been successfully written\n"));

0 commit comments

Comments
 (0)