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)
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)