Skip to content

Commit ffd2d4e

Browse files
committed
qt: changed write command to use serial port async read/write
1 parent 3a49463 commit ffd2d4e

File tree

6 files changed

+215
-214
lines changed

6 files changed

+215
-214
lines changed

qt/main_window.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,17 @@ void MainWindow::slotProgRead()
237237
std::placeholders::_1), readBuf, START_ADDRESS, readBufSize);
238238
}
239239

240+
void MainWindow::writeChipCb(int status)
241+
{
242+
if (!status)
243+
qInfo() << "Data has been successfully written";
244+
delete writeBuf;
245+
}
246+
240247
void MainWindow::slotProgWrite()
241248
{
242249
bool convIsOk;
243250
QStringList sl;
244-
std::unique_ptr< uint8_t[] > buf;
245251
uint32_t bufSize, bufIter = 0;
246252
uint32_t rowCount = ui->bufferTableWidget->rowCount() - HEADER_ROW_NUM;
247253

@@ -252,8 +258,8 @@ void MainWindow::slotProgWrite()
252258
}
253259

254260
bufSize = rowCount * ROW_DATA_SIZE;
255-
buf = std::unique_ptr< uint8_t[] >(new (std::nothrow) uint8_t[bufSize]);
256-
if (!buf.get())
261+
writeBuf = new (std::nothrow) uint8_t[bufSize];
262+
if (!writeBuf)
257263
{
258264
qCritical() << "Failed to allocate memory for write buffer";
259265
return;
@@ -266,7 +272,7 @@ void MainWindow::slotProgWrite()
266272

267273
for (int j = 0; j < sl.size(); j++)
268274
{
269-
buf[bufIter++] = sl.at(j).toUInt(&convIsOk, 16);
275+
writeBuf[bufIter++] = sl.at(j).toUInt(&convIsOk, 16);
270276
if (!convIsOk)
271277
{
272278
qCritical() << "Failed to convert row item to byte";
@@ -275,8 +281,8 @@ void MainWindow::slotProgWrite()
275281
}
276282
}
277283

278-
if (!prog->writeChip(buf.get(), START_ADDRESS, bufIter))
279-
qInfo() << "Data has been successfully written";
284+
prog->writeChip(std::bind(&MainWindow::writeChipCb, this,
285+
std::placeholders::_1), writeBuf, START_ADDRESS, bufIter);
280286
}
281287

282288
void MainWindow::selectChipCb()

qt/main_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ class MainWindow : public QMainWindow
2626
Ui::MainWindow *ui;
2727
uint8_t *readBuf;
2828
uint32_t readBufSize;
29+
uint8_t *writeBuf;
2930

3031
void insertBufferRow(quint8 *readBuf, quint32 size, quint32 rowNum,
3132
quint32 address);
3233
void readChipIdCb(ChipId id);
3334
void selectChipCb();
3435
void eraseChipCb();
3536
void readChipCb(int status);
37+
void writeChipCb(int status);
3638

3739
public slots:
3840
void slotFileOpen();

0 commit comments

Comments
 (0)