PDA

View Full Version : Qt4/C++ - QProcess output to QList<uint>



jimbo
29th August 2015, 14:29
linux - Qt 4.8.2

Hello,

I've managed to use QProcess to get data from an eeprom and convert to a QList<uint>.
Just seems unnecessarily complex, is it just me (trying to learn) or is there an easier way?
Thanks for reading.

Regards


QString p_stdOut;
QString p_stdErr;
QList<uint> pages = QList<uint>() << 128 << 256 << 512 << 1024 << 2048 << 4096;
QList<uint> data = QList<uint>();
QStringList list;

//eeprog-tear -xf /dev/i2c-1 0x50 -x -16 -r 0x8160:0x20 - read last 32 bytes of eeprom
cmd = "eeprog-tear -xf /dev/i2c-1 0x50 -x -16 -r 0x" + (QString::number((pages[i] - 1) * 32)) + ":0x20";
process->start(cmd);
process->waitForFinished(-1);

p_stdOut = process->readAllStandardOutput();
qDebug() << "1 - " << p_stdOut;

p_stdOut = p_stdOut.right(p_stdOut.length() - ((p_stdOut.indexOf("|")) + 1)); //get rid of first address
qDebug() << "2 - " << p_stdOut;

p_stdOut.replace((p_stdOut.indexOf("|") - 5), 6, ""); //get rid of second sddress
qDebug() << "3 - " << p_stdOut;

p_stdOut.replace((p_stdOut.indexOf("\n") ), 1, ""); //get rid of linefeed
qDebug() << "4 - " << p_stdOut;

p_stdOut = p_stdOut.simplified().replace(" ", ","); //get rid of extra spaces, add commas
qDebug() << "5 - " << p_stdOut;

QRegExp rx(",");
list = p_stdOut.split(rx, QString::SkipEmptyParts);
qDebug() << "6 list - " << list;

for (int j = 0; j < list.length() - 1; j++) data << list[j].toUInt(&ok, 16);
qDebug() << "7 uint - " << data;
Output
******
1 - "
4064| 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
4074| 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00

"
2 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
4074| 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00

"
3 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00

"
4 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00

"
5 - "64,6d,e8,02,00,01,00,20,00,00,00,62,02,00,00,00,00 ,00,00,80,00,00,00,a1,00,00,00,00,00,00,00,00"
6 list - ("64", "6d", "e8", "02", "00", "01", "00", "20", "00", "00", "00", "62", "02", "00", "00", "00", "00", "00", "00", "80", "00", "00", "00", "a1", "00", "00", "00", "00", "00", "00", "00", "00")
7 uint - (100, 109, 232, 2, 0, 1, 0, 32, 0, 0, 0, 98, 2, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0)

jimbo
31st August 2015, 12:30
Hello,

I'm writing data to an eeprom. Piping data from the date command. OK

process = new QProcess(this);
process->start("bash", QStringList() << "-c" << "date | eeprog-tear -f -16 -w 0x00 -t 5 /dev/i2c-1 0x50");
process->waitForFinished(-1);
p_stdOut = process->readAllStandardOutput();
qDebug() << "22 - " << p_stdOut;
p_stdErr = process->readAllStandardError();
qDebug() << "33 - " << p_stdErr << "\n\n";
***Output***
22 - ""
33 - "eeprog 0.7.6-tear12, a 24Cxx EEPROM reader/writer
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
Copyright (c) 2011 by Kris Rusocki - All rights reserved.
Bus: /dev/i2c-1, Address: 0x50, Mode: 16bit
Operation: write at offset 0, Input file: <stdin>
Write cycle time: 5 milliseconds
Writing <stdin> starting at address 0x0
.............................

"
What I would like to do is pipe the values from a QList<uint>.
I could save the values to a file and write the file to the eeprom, I know how to do this.
Is there a way to pipe the QList<uint> values directly?

Regards

ChrisW67
31st August 2015, 22:37
If the eeprom writer program is expecting a raw stream of bytes on its stdin then you would be better off storing the data in a QByteArray and simply calling process.write() to send it.

jimbo
1st September 2015, 14:26
Hello ChrisW67

Thanks, I'll have a play and see how far I get. (process.write())

Regards

jimbo
6th September 2015, 14:25
Hello,

I'm getting somewhere with QProcess.write, but.....

I use 'i2cdump -y -f 1 0x50 c' to check the eeprom. I can write data to the eeprom,
but nothing shows until a powerdown and boot, a soft reboot does not update.

uint num = 0xac; //172;
int8_t _bytes [1] {0x0A}; //line feed

process->start("eeprog-tear -f -16 -w 0xc2 -t 5 /dev/i2c-1 0x50");

process->write(QString::number(num).toLocal8Bit()); //writes 31 37 32
process->write((char *)_bytes, 1); //line feed

fflush(stdout);
process->waitForBytesWritten();

process->waitForFinished();
p_stdOut = process->readAllStandardOutput();
qDebug() << "99 - " << p_stdOut;
p_stdErr = process->readAllStandardError();
qDebug() << "100 - " << p_stdErr;
process->close();//->terminate();

i2cdump -y -f 1 0x50 c
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
...
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
c0: ff ff 31 37 32 0a ff ff ff ff ff ff ff ff ff ff ..172?..........
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
...

Output:-
99 - ""
100 - "eeprog 0.7.6-tear12, a 24Cxx EEPROM reader/writer
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
Copyright (c) 2011 by Kris Rusocki - All rights reserved.
Bus: /dev/i2c-1, Address: 0x50, Mode: 16bit
Operation: write at offset 194, Input file: <stdin>
Write cycle time: 5 milliseconds
Writing <stdin> starting at address 0xc2

The GUI I'm running from becomes un-responsive for about the same time as it would normally take to write the total eeprom.
I'm guessing that I'm not appplying the line feed properly.

Any suggestions would be greatly appreciated.

Regards

jimbo
7th September 2015, 19:32
Hello,

I've solved the line feed problem.

uint num = 0xad; //172;
stringstream strs;
strs << num;
string tmp = strs.str();
char * pchar = new char[tmp.size() + 1]; //reserve space for line feed
strcpy(pchar, tmp.c_str());

process->start("eeprog-tear -f -16 -w 0xa0 -t 5 /dev/i2c-1 0x50");

process->write(pchar); //writes 31 37 32
delete(pchar);Just the problem of not showing, until shutdown & boot.

Regards