Skip to content

Commit 4684cb9

Browse files
committed
plugins: Added regmap API
Signed-off-by: Alexandru Lie <[email protected]>
1 parent a3e0c1b commit 4684cb9

File tree

11 files changed

+195
-1
lines changed

11 files changed

+195
-1
lines changed

plugins/datalogger/js/test.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Time, xadc:voltage0, xadc:voltage1
2+
19/08/2024 16:27:26, 1.01587, 1.7981
3+
19/08/2024 16:27:27, 1.01587, 1.7981
4+
19/08/2024 16:27:28, 1.01587, 1.7981
5+
19/08/2024 16:27:29, 1.01587, 1.7981
6+
19/08/2024 16:27:30, 1.01587, 1.7981
7+
19/08/2024 16:27:31, 1.01587, 1.7981
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
#ifndef SCOPY_IIODEBUG_EXPORT_H
3+
#define SCOPY_IIODEBUG_EXPORT_H
4+
5+
#ifdef SCOPY_IIODEBUG_STATIC_DEFINE
6+
#define SCOPY_IIODEBUG_EXPORT
7+
#define SCOPY_IIODEBUG_NO_EXPORT
8+
#else
9+
#ifndef SCOPY_IIODEBUG_EXPORT
10+
#ifdef scopy_iiodebug_EXPORTS
11+
/* We are building this library */
12+
#define SCOPY_IIODEBUG_EXPORT __attribute__((visibility("default")))
13+
#else
14+
/* We are using this library */
15+
#define SCOPY_IIODEBUG_EXPORT __attribute__((visibility("default")))
16+
#endif
17+
#endif
18+
19+
#ifndef SCOPY_IIODEBUG_NO_EXPORT
20+
#define SCOPY_IIODEBUG_NO_EXPORT __attribute__((visibility("hidden")))
21+
#endif
22+
#endif
23+
24+
#ifndef SCOPY_IIODEBUG_DEPRECATED
25+
#define SCOPY_IIODEBUG_DEPRECATED __attribute__((__deprecated__))
26+
#endif
27+
28+
#ifndef SCOPY_IIODEBUG_DEPRECATED_EXPORT
29+
#define SCOPY_IIODEBUG_DEPRECATED_EXPORT SCOPY_IIODEBUG_EXPORT SCOPY_IIODEBUG_DEPRECATED
30+
#endif
31+
32+
#ifndef SCOPY_IIODEBUG_DEPRECATED_NO_EXPORT
33+
#define SCOPY_IIODEBUG_DEPRECATED_NO_EXPORT SCOPY_IIODEBUG_NO_EXPORT SCOPY_IIODEBUG_DEPRECATED
34+
#endif
35+
36+
#if 0 /* DEFINE_NO_DEPRECATED */
37+
#ifndef SCOPY_IIODEBUG_NO_DEPRECATED
38+
#define SCOPY_IIODEBUG_NO_DEPRECATED
39+
#endif
40+
#endif
41+
42+
#endif /* SCOPY_IIODEBUG_EXPORT_H */

plugins/regmap/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ configure_file(
7777
)
7878
set(SRC_LIST ${SRC_LIST} ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/scopy-${SCOPY_MODULE}_config.h)
7979

80-
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES})
80+
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES}
81+
src/regmap_api.h
82+
src/regmap_api.cpp)
8183

8284
generate_export_header(
8385
${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h

plugins/regmap/include/regmap/regmapplugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ namespace regmap {
2424

2525
class RegisterMapTool;
2626
class JsonFormatedElement;
27+
class RegMap_API;
2728

2829
class SCOPY_REGMAP_EXPORT RegmapPlugin : public QObject, public PluginBase
2930
{
31+
friend class RegMap_API;
3032
Q_OBJECT
3133
SCOPY_PLUGIN;
3234

@@ -59,6 +61,8 @@ public Q_SLOTS:
5961
struct iio_device *getIioDevice(iio_context *ctx, const char *dev_name);
6062
bool isBufferCapable(iio_device *dev);
6163
RegisterMapTool *registerMapTool;
64+
void InitApi();
65+
RegMap_API *api;
6266
};
6367
} // namespace regmap
6468
} // namespace scopy

plugins/regmap/src/deviceregistermap.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ bool DeviceRegisterMap::hasTemplate()
220220
return false;
221221
}
222222

223+
bool DeviceRegisterMap::getAutoread(){
224+
return autoread;
225+
}
226+
223227
void DeviceRegisterMap::initSettings()
224228
{
225229
QObject::connect(this, &DeviceRegisterMap::requestRead, registerMapValues, &RegisterMapValues::requestRead);

plugins/regmap/src/deviceregistermap.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RegisterMapTable;
2424

2525
class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
2626
{
27+
friend class RegMap_API;
2728
Q_OBJECT
2829
public:
2930
explicit DeviceRegisterMap(RegisterMapTemplate *registerMapTemplate = nullptr,
@@ -34,6 +35,7 @@ class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
3435
void toggleAutoread(bool toggled);
3536
void applyFilters(QString filter);
3637
bool hasTemplate();
38+
bool getAutoread();
3739

3840
private:
3941
ToolTemplate *tool;

plugins/regmap/src/registermapsettingsmenu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace regmap {
1515
class RegisterMapSettingsMenu : public QWidget
1616
{
1717
friend class RegmapStyleHelper;
18+
friend class RegMap_API;
1819

1920
Q_OBJECT
2021

plugins/regmap/src/registermaptool.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SearchBarWidget;
2323

2424
class SCOPY_REGMAP_EXPORT RegisterMapTool : public QWidget
2525
{
26+
friend class RegMap_API;
2627
Q_OBJECT
2728
public:
2829
explicit RegisterMapTool(QWidget *parent = nullptr);

plugins/regmap/src/regmap_api.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include "regmap_api.h"
2+
3+
using namespace scopy::regmap;
4+
5+
Q_LOGGING_CATEGORY(CAT_REGMAP_API, "RegMap_API")
6+
7+
RegMap_API::RegMap_API(RegmapPlugin *regMapPlugin)
8+
: ApiObject()
9+
, m_regMapPlugin(regMapPlugin)
10+
{}
11+
12+
RegMap_API::~RegMap_API() {}
13+
14+
void RegMap_API::write(QString addr, QString val){
15+
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
16+
Q_EMIT devRegMap->registerMapValues->requestWrite(addr.toUInt(nullptr, 16), val.toUInt(nullptr, 16));
17+
}
18+
19+
QStringList RegMap_API::getAvailableDevicesName(){
20+
QStringList devicesName;
21+
if(m_regMapPlugin->m_deviceList->size() != 0){
22+
for(const auto& dev : *(m_regMapPlugin->m_deviceList)){
23+
devicesName.append(iio_device_get_name(dev));
24+
}
25+
} else{
26+
qWarning(CAT_REGMAP_API) << "No devices available";
27+
}
28+
return devicesName;
29+
}
30+
31+
bool RegMap_API::setDevice(QString device){
32+
m_regMapPlugin->registerMapTool->updateActiveRegisterMap(device);
33+
QString currentRegMap = m_regMapPlugin->registerMapTool->activeRegisterMap;
34+
if(currentRegMap == device){
35+
return true;
36+
}
37+
qWarning(CAT_REGMAP_API) << "Device " << device << " was not set";
38+
return false;
39+
}
40+
41+
QStringList RegMap_API::search(QString searchParam){
42+
QList<uint32_t> resultIndexes;
43+
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
44+
resultIndexes = Search::searchForRegisters(devRegMap->registerMapTemplate->getRegisterList(), searchParam);
45+
46+
QStringList resultList;
47+
for(int i = 0; i < resultIndexes.size(); i++){
48+
RegisterModel *model = devRegMap->registerMapTemplate->getRegisterTemplate(resultIndexes[i]);
49+
resultList.append(model->getName());
50+
}
51+
return resultList;
52+
}
53+
54+
QStringList RegMap_API::readInterval(QString startAddr, QString stopAddr){
55+
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
56+
uint32_t start = startAddr.toUInt(nullptr, 16);
57+
uint32_t stop = stopAddr.toUInt(nullptr, 16);
58+
QStringList readValues;
59+
for(int i = start; i < stop; i++){
60+
Q_EMIT readValues.append(devRegMap->registerMapValues->requestRead(i));
61+
}
62+
}
63+
64+
bool RegMap_API::enableAutoread(bool enable){
65+
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
66+
devRegMap->toggleAutoread(enable);
67+
if(devRegMap->getAutoread() == enable){
68+
return true;
69+
}
70+
qWarning(CAT_REGMAP_API) << "Autoread was not changed to " << enable;
71+
return false;
72+
}
73+
74+
bool RegMap_API::isAutoreadEnabled(){
75+
DeviceRegisterMap *devRegMap = getActiveDevRegMap();
76+
return devRegMap->getAutoread();
77+
}
78+
79+
DeviceRegisterMap* RegMap_API::getActiveDevRegMap(){
80+
return m_regMapPlugin->registerMapTool->deviceList->value(m_regMapPlugin->registerMapTool->activeRegisterMap);
81+
}
82+
83+
84+

plugins/regmap/src/regmap_api.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef REGMAP_API_H
2+
#define REGMAP_API_H
3+
4+
#include "scopy-regmap_export.h"
5+
6+
#include <regmapplugin.h>
7+
#include <deviceregistermap.hpp>
8+
#include <registermaptool.hpp>
9+
#include <register/registermodel.hpp>
10+
#include <registermapvalues.hpp>
11+
#include "search.hpp"
12+
13+
namespace scopy::regmap{
14+
15+
class SCOPY_REGMAP_EXPORT RegMap_API : public ApiObject{
16+
17+
Q_OBJECT
18+
19+
public:
20+
explicit RegMap_API(RegmapPlugin *regMapPlugin);
21+
~RegMap_API();
22+
23+
Q_INVOKABLE void write(QString addr, QString val);
24+
Q_INVOKABLE QStringList getAvailableDevicesName();
25+
Q_INVOKABLE bool setDevice(QString device);
26+
Q_INVOKABLE QStringList search (QString searchParam);
27+
Q_INVOKABLE QStringList readInterval(QString startAddr, QString stopAddr);
28+
Q_INVOKABLE bool enableAutoread(bool enable);
29+
Q_INVOKABLE bool isAutoreadEnabled();
30+
Q_INVOKABLE void registerDump(QString filePath);
31+
Q_INVOKABLE void writeFromFile(QString filePath);
32+
33+
private:
34+
RegmapPlugin *m_regMapPlugin;
35+
DeviceRegisterMap * getActiveDevRegMap();
36+
};
37+
}
38+
#endif // REGMAP_API_H

plugins/regmap/src/regmapplugin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
#include <readwrite/fileregisterreadstrategy.hpp>
2828
#include <readwrite/fileregisterwritestrategy.hpp>
2929
#include "logging_categories.h"
30+
#include <regmap_api.h>
3031

3132
#include "iioutil/connectionprovider.h"
3233
#include "jsonformatedelement.hpp"
3334
#include "scopy-regmap_config.h"
3435
#include "utils.hpp"
3536
#include "utils.hpp"
37+
#include <pluginbase/scopyjs.h>
3638
#if defined __APPLE__
3739
#include <QApplication>
3840
#endif
@@ -185,6 +187,7 @@ bool RegmapPlugin::onConnect()
185187

186188
m_toolList[0]->setEnabled(true);
187189
m_toolList[0]->setTool(m_registerMapWidget);
190+
InitApi();
188191

189192
return true;
190193
}
@@ -275,4 +278,10 @@ bool RegmapPlugin::isBufferCapable(iio_device *dev)
275278
return false;
276279
}
277280

281+
void RegmapPlugin::InitApi(){
282+
api = new RegMap_API(this);
283+
ScopyJS *js = ScopyJS::GetInstance();
284+
api->setObjectName("regmap");
285+
js->registerApi(api);
286+
}
278287
#include "moc_regmapplugin.cpp"

0 commit comments

Comments
 (0)