Skip to content

Commit

Permalink
regmap: added read all for file read
Browse files Browse the repository at this point in the history
when writing from file we need a way to read all values from the file

Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Sep 12, 2024
1 parent 62c3253 commit b15ce3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
18 changes: 18 additions & 0 deletions plugins/regmap/src/readwrite/fileregisterreadstrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ void FileRegisterReadStrategy::read(uint32_t address)
}
}
}

void FileRegisterReadStrategy::readAll()
{
QFile file(path);
if(!file.open(QIODevice::ReadOnly)) {
qDebug(CAT_IIO_OPERATION) << "device read error " << file.errorString();
Q_EMIT readError("device read error");
} else {
while(!file.atEnd()) {
QString line(file.readLine());
uint32_t address = Utils::convertQStringToUint32(line.split(',').first());
uint32_t value = Utils::convertQStringToUint32(line.split(',').at(1));

Q_EMIT readDone(address, value);
qDebug(CAT_IIO_OPERATION) << "device read success for " << address << " with value " << value;
}
}
}
4 changes: 4 additions & 0 deletions plugins/regmap/src/readwrite/fileregisterreadstrategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class FileRegisterReadStrategy : public IRegisterReadStrategy
{
public:
FileRegisterReadStrategy(QString path);
// read a value from file from given address
void read(uint32_t address);
// read all values from file
void readAll();

Q_SIGNALS:

private:
Expand Down
7 changes: 1 addition & 6 deletions plugins/regmap/src/registermapsettingsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,12 @@ RegisterMapSettingsMenu::RegisterMapSettingsMenu(QWidget *parent)
writeListOfValuesButton->setEnabled(false);

QObject::connect(writeListOfValuesButton, &QPushButton::clicked, this, [=]() {
int startInterval = Utils::convertQStringToUint32(startReadInterval->text());
int endInterval = Utils::convertQStringToUint32(endReadInterval->text());

FileRegisterReadStrategy *fileRead = new FileRegisterReadStrategy(filePath->text());

QObject::connect(fileRead, &FileRegisterReadStrategy::readDone, this,
&RegisterMapSettingsMenu::requestWrite);

for(int i = startInterval; i <= endInterval; i++) {
fileRead->read(i);
}
fileRead->readAll();
});

menuSection->contentLayout()->addWidget(writeListOfValuesButton);
Expand Down

0 comments on commit b15ce3b

Please sign in to comment.