-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexandru Lie <[email protected]>
- Loading branch information
Showing
10 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include "regmap_api.h" | ||
|
||
using namespace scopy::regmap; | ||
|
||
Q_LOGGING_CATEGORY(CAT_REGMAP_API, "RegMap_API") | ||
|
||
RegMap_API::RegMap_API(RegmapPlugin *regMapPlugin) | ||
: ApiObject() | ||
, m_regMapPlugin(regMapPlugin) | ||
{} | ||
|
||
RegMap_API::~RegMap_API() {} | ||
|
||
void RegMap_API::write(QString addr, QString val) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
Q_EMIT devRegMap->registerMapValues->requestWrite(addr.toUInt(nullptr, 16), val.toUInt(nullptr, 16)); | ||
} | ||
|
||
QStringList RegMap_API::getAvailableDevicesName() | ||
{ | ||
QStringList devicesName; | ||
auto devices = m_regMapPlugin->registerMapTool->deviceList; | ||
return devices->keys(); | ||
} | ||
|
||
bool RegMap_API::setDevice(QString device) | ||
{ | ||
m_regMapPlugin->registerMapTool->updateActiveRegisterMap(device); | ||
QString currentRegMap = m_regMapPlugin->registerMapTool->activeRegisterMap; | ||
if(currentRegMap == device) { | ||
return true; | ||
} | ||
qWarning(CAT_REGMAP_API) << "Device " << device << " was not set"; | ||
return false; | ||
} | ||
|
||
QList<uint32_t> RegMap_API::search(QString searchParam) | ||
{ | ||
QList<uint32_t> resultIndexes; | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
resultIndexes = Search::searchForRegisters(devRegMap->registerMapTemplate->getRegisterList(), searchParam); | ||
return resultIndexes; | ||
} | ||
|
||
void RegMap_API::readInterval(QString startAddr, QString stopAddr) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
uint32_t start = Utils::convertQStringToUint32(startAddr); | ||
uint32_t stop = Utils::convertQStringToUint32(stopAddr); | ||
for(int i = start; i <= stop; i++) { | ||
Q_EMIT devRegMap->requestRead(i); | ||
} | ||
} | ||
|
||
bool RegMap_API::enableAutoread(bool enable) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
devRegMap->toggleAutoread(enable); | ||
if(devRegMap->getAutoread() == enable) { | ||
return true; | ||
} | ||
qWarning(CAT_REGMAP_API) << "Autoread was not changed to " << enable; | ||
return false; | ||
} | ||
|
||
bool RegMap_API::isAutoreadEnabled() | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
return devRegMap->getAutoread(); | ||
} | ||
|
||
void RegMap_API::registerDump(QString filePath) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
Q_EMIT devRegMap->registerMapValues->registerDump(filePath); | ||
} | ||
|
||
void RegMap_API::setPath(QString filePath) { m_regMapPlugin->registerMapTool->settings->filePath->setText(filePath); } | ||
|
||
void RegMap_API::writeFromFile(QString filePath) | ||
{ | ||
setPath(filePath); | ||
Q_EMIT m_regMapPlugin->registerMapTool->settings->writeListOfValuesButton->clicked(); | ||
} | ||
|
||
void RegMap_API::readRegister(QString addr) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
Q_EMIT devRegMap->requestRead(Utils::convertQStringToUint32(addr)); | ||
} | ||
|
||
QString RegMap_API::getValueOfRegister(QString addr) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
uint32_t address = Utils::convertQStringToUint32(addr); | ||
QMap<uint32_t, uint32_t> *values = devRegMap->registerMapValues->getRegisterReadValues(); | ||
if(values->keys().contains(address)) { | ||
return Utils::convertToHexa(values->value(address), 16); | ||
} | ||
qWarning(CAT_REGMAP_API) << "Value not read"; | ||
return ""; | ||
} | ||
|
||
DeviceRegisterMap *RegMap_API::getActiveDevRegMap() | ||
{ | ||
return m_regMapPlugin->registerMapTool->deviceList->value(m_regMapPlugin->registerMapTool->activeRegisterMap); | ||
} | ||
|
||
QStringList RegMap_API::getRegisterInfo(QString addr) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
QStringList regInfo; | ||
RegisterModel *regModel = | ||
devRegMap->registerMapTableWidget->registerModels->value(Utils::convertQStringToUint32(addr)); | ||
if(regModel != nullptr) { | ||
regInfo.append("Name:" + regModel->getName()); | ||
regInfo.append("Address:" + Utils::convertToHexa(regModel->getAddress(), 16)); | ||
regInfo.append("Description:" + regModel->getDescription()); | ||
regInfo.append("Notes:" + regModel->getNotes()); | ||
} | ||
return regInfo; | ||
} | ||
|
||
QStringList RegMap_API::getRegisterBitFieldsInfo(QString addr) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
QStringList bitFieldsDetails; | ||
RegisterModel *regModel = | ||
devRegMap->registerMapTableWidget->registerModels->value(Utils::convertQStringToUint32(addr)); | ||
QVector<BitFieldModel *> *bitField = regModel->getBitFields(); | ||
|
||
for(BitFieldModel *bf : *bitField) { | ||
bitFieldsDetails.append("Name:" + bf->getName()); | ||
bitFieldsDetails.append("Description:" + bf->getDescription()); | ||
bitFieldsDetails.append("Notes:" + bf->getNotes()); | ||
bitFieldsDetails.append("Default value:" + Utils::convertToHexa(bf->getDefaultValue(), 16)); | ||
bitFieldsDetails.append(";"); | ||
} | ||
return bitFieldsDetails; | ||
} | ||
|
||
QStringList RegMap_API::getBitFieldInfo(QString addr, QString bitName) | ||
{ | ||
DeviceRegisterMap *devRegMap = getActiveDevRegMap(); | ||
QStringList bitDetails; | ||
RegisterModel *regModel = | ||
devRegMap->registerMapTableWidget->registerModels->value(Utils::convertQStringToUint32(addr)); | ||
QVector<BitFieldModel *> *bitField = regModel->getBitFields(); | ||
|
||
for(BitFieldModel *bf : *bitField) { | ||
if(bf->getName() == bitName) { | ||
bitDetails.append("Name:" + bf->getName()); | ||
bitDetails.append("Description:" + bf->getDescription()); | ||
bitDetails.append("Notes:" + bf->getNotes()); | ||
bitDetails.append("Default value:" + Utils::convertToHexa(bf->getDefaultValue(), 16)); | ||
break; | ||
} | ||
} | ||
return bitDetails; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef REGMAP_API_H | ||
#define REGMAP_API_H | ||
|
||
#include "scopy-regmap_export.h" | ||
|
||
#include <regmapplugin.h> | ||
#include <deviceregistermap.hpp> | ||
#include <registermaptool.hpp> | ||
#include <register/registermodel.hpp> | ||
#include <registermapvalues.hpp> | ||
#include <recyclerview/registermaptable.hpp> | ||
#include <utils.hpp> | ||
#include <register/bitfield/bitfieldmodel.hpp> | ||
#include <readwrite/fileregisterreadstrategy.hpp> | ||
#include <registermapsettingsmenu.hpp> | ||
#include <qlineedit.h> | ||
#include "search.hpp" | ||
|
||
namespace scopy::regmap { | ||
|
||
class SCOPY_REGMAP_EXPORT RegMap_API : public ApiObject | ||
{ | ||
|
||
Q_OBJECT | ||
|
||
public: | ||
explicit RegMap_API(RegmapPlugin *regMapPlugin); | ||
~RegMap_API(); | ||
|
||
Q_INVOKABLE void write(QString addr, QString val); | ||
Q_INVOKABLE QStringList getAvailableDevicesName(); | ||
Q_INVOKABLE bool setDevice(QString device); | ||
Q_INVOKABLE QList<uint32_t> search(QString searchParam); | ||
Q_INVOKABLE void readInterval(QString startAddr, QString stopAddr); | ||
Q_INVOKABLE bool enableAutoread(bool enable); | ||
Q_INVOKABLE bool isAutoreadEnabled(); | ||
Q_INVOKABLE void registerDump(QString filePath); | ||
Q_INVOKABLE void setPath(QString filePath); | ||
Q_INVOKABLE void writeFromFile(QString filePath); | ||
Q_INVOKABLE void readRegister(QString addr); | ||
Q_INVOKABLE QString getValueOfRegister(QString addr); | ||
Q_INVOKABLE QStringList getRegisterInfo(QString addr); | ||
Q_INVOKABLE QStringList getRegisterBitFieldsInfo(QString addr); | ||
Q_INVOKABLE QStringList getBitFieldInfo(QString addr, QString bitName); | ||
|
||
private: | ||
RegmapPlugin *m_regMapPlugin; | ||
DeviceRegisterMap *getActiveDevRegMap(); | ||
}; | ||
} // namespace scopy::regmap | ||
#endif // REGMAP_API_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters