Skip to content

Commit

Permalink
Remote node configuration over MQTT fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Apr 8, 2024
1 parent b92a12e commit 8f3061f
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 129 deletions.
6 changes: 3 additions & 3 deletions src/cdlgtxedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,18 @@ CDlgTxEdit::setName(const QString& str)
// getCount
//

uint8_t
uint16_t
CDlgTxEdit::getCount(void)
{
return (uint8_t)ui->spinCount->value();
return (uint16_t)ui->spinCount->value();
}

///////////////////////////////////////////////////////////////////////////////
// setCount
//

void
CDlgTxEdit::setCount(uint8_t cnt)
CDlgTxEdit::setCount(uint16_t cnt)
{
ui->spinCount->setValue(cnt);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cdlgtxedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class CDlgTxEdit : public QDialog
/*!
Setters/getters for count
*/
uint8_t getCount(void);
void setCount(uint8_t count);
uint16_t getCount(void);
void setCount(uint16_t count);

/*!
Setters/getters for VSCP class/type
Expand Down
19 changes: 15 additions & 4 deletions src/cdlgtxedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,26 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Number of this event to send when triggered</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>255.000000000000000</double>
<double>9999.000000000000000</double>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::AdaptiveDecimalStepType</enum>
</property>
<property name="value">
<double>1.000000000000000</double>
Expand Down Expand Up @@ -317,7 +326,8 @@
<string>...</string>
</property>
<property name="icon">
<iconset theme="help"/>
<iconset theme="help">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
<widget class="QToolButton" name="btnTypeHelp">
Expand All @@ -336,7 +346,8 @@
<string>...</string>
</property>
<property name="icon">
<iconset theme="help"/>
<iconset theme="help">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</widget>
Expand Down
99 changes: 90 additions & 9 deletions src/cfrmnodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
vscpworks* pworks = (vscpworks*)QCoreApplication::instance();
pworks->newChildWindow(this);

m_bFullLevel2 = false; // Deafult is level I
m_nUpdates = 0; // No update operations yet
m_StandardRegTopPage = nullptr; // No standard registers
ui->treeWidgetRegisters->clear(); // Clear the tree
Expand Down Expand Up @@ -346,7 +347,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
* If bFullLevel2 is true only GUID textbox is shown.
* If false the interface combo plus nickname spinnbox is shown.
*/
bool bFullLevel2 = m_connObject["bfull-l2"].toBool();
m_bFullLevel2 = m_connObject["bfull-l2"].toBool();

switch (m_vscpConnType) {

Expand All @@ -359,7 +360,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)

case CVscpClient::connType::TCPIP:

if (bFullLevel2) {
if (m_bFullLevel2) {
// GUID
m_guidConfig = new QLineEdit();
ui->mainToolBar->addWidget(new QLabel(" GUID: "));
Expand Down Expand Up @@ -466,10 +467,66 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
break;

case CVscpClient::connType::MQTT:
// if (true /*bFullLevel2*/) {

m_btnFullLevel2 = new QCheckBox(tr(" Level II"));
ui->mainToolBar->addWidget(m_btnFullLevel2);
connect(m_btnFullLevel2, SIGNAL(clicked()), this, SLOT(checkFullLevel2()));
ui->mainToolBar->addSeparator();

m_nodeidConfig = new QSpinBox();
m_nodeidConfig->setRange(0, 0xff);
m_nodeidConfig->setValue(1);
ui->mainToolBar->addWidget(new QLabel(" node id:"));
ui->mainToolBar->addWidget(m_nodeidConfig);
ui->mainToolBar->addSeparator();

// GUID
m_guidConfig = new QLineEdit();
ui->mainToolBar->addWidget(new QLabel(" GUID: "));
ui->mainToolBar->addWidget(m_guidConfig);
m_guidConfig->setText("00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01");

m_btnSetGUID = new QPushButton(tr(" Set GUID"));
ui->mainToolBar->addWidget(m_btnSetGUID);
connect(m_btnSetGUID, SIGNAL(clicked()), this, SLOT(selectGuid()));

if (m_bFullLevel2) {
m_nodeidConfig->setEnabled(false);
}
else {
m_guidConfig->setEnabled(false);
m_btnSetGUID->setEnabled(false);
}

// }
// else {
// // Interface
// m_comboInterface = new QComboBox();
// ui->mainToolBar->addWidget(new QLabel(" If: "));
// ui->mainToolBar->addWidget(m_comboInterface);
// m_comboInterface->addItem(tr("---"));

// std::string _str;
// size_t sz = json_if_array.size();
// foreach (const QJsonValue& value, json_if_array) {
// m_comboInterface->addItem(value.toObject().value("if-item").toString());
// }

// m_comboInterface->setCurrentText(interface.c_str());
// // std::cout << "interface = " << interface << std::endl;

// // Nickname
// m_nodeidConfig = new QSpinBox();
// m_nodeidConfig->setRange(1, 0xfd);
// ui->mainToolBar->addWidget(new QLabel(" node id:"));
// ui->mainToolBar->addWidget(m_nodeidConfig);
// m_nodeidConfig->setValue(1);
// }
// GUID
m_vscpClient = new vscpClientMqtt();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
//m_vscpClient->setCallback(eventReceived, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand Down Expand Up @@ -1203,6 +1260,27 @@ CFrmNodeConfig::selectGuid(void)
m_guidConfig->setText(guid.toString().c_str());
}

///////////////////////////////////////////////////////////////////////////////
// checkFullLevel2
//

void
CFrmNodeConfig::checkFullLevel2(void)
{
m_bFullLevel2 = m_btnFullLevel2->isChecked();

if (m_bFullLevel2) {
m_nodeidConfig->setEnabled(false);
m_guidConfig->setEnabled(true);
m_btnSetGUID->setEnabled(true);
}
else {
m_nodeidConfig->setEnabled(true);
m_guidConfig->setEnabled(false);
m_btnSetGUID->setEnabled(false);
}
}

///////////////////////////////////////////////////////////////////////////////
// disableColors
//
Expand Down Expand Up @@ -1317,8 +1395,11 @@ CFrmNodeConfig::onNodeIdChange(int nodeid)
void
CFrmNodeConfig::update(void)
{
if (m_connObject["bfull-l2"].toBool()) {
;
if (m_bFullLevel2) {
QMessageBox::information(this,
tr(APPNAME),
tr("Fyll level II configuration is not implemented yet."),
QMessageBox::Ok);
}
else {

Expand Down Expand Up @@ -5922,10 +6003,10 @@ CFrmNodeConfig::onSearchRemoteVariable(void)
flags |= Qt::MatchCaseSensitive;
}

m_registerSearchPos = 0;
m_searchListRemoteVars = ui->treeWidgetRemoteVariables->findItems(dlg.getSearchText().c_str(),
flags,
static_cast<int>(REMOTEVAR_COL_NAME));
m_registerSearchPos = 0;
m_searchListRemoteVars = ui->treeWidgetRemoteVariables->findItems(dlg.getSearchText().c_str(),
flags,
static_cast<int>(REMOTEVAR_COL_NAME));
std::cout << m_searchListRemoteVars.size() << std::endl;

foreach (QTreeWidgetItem* item, m_searchListRemoteVars) {
Expand Down
13 changes: 13 additions & 0 deletions src/cfrmnodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class QSpinBox;
class QMenu;
class QMenuBar;
class QPushButton;
class QCheckBox;
class QTextEdit;
class QTextBrowser;
class QToolBar;
Expand Down Expand Up @@ -338,6 +339,12 @@ class CFrmNodeConfig : public QMainWindow
*/
void selectGuid(void); // std::string strguid = "-"

/*!
ui checkbox for full Level II has been clicked. Assign
value to
*/
void checkFullLevel2(void);

/*!
Disable/enable MDF colors
*/
Expand Down Expand Up @@ -808,6 +815,9 @@ class CFrmNodeConfig : public QMainWindow

private:

/// True if full Level II handling
bool m_bFullLevel2;

/// MDF definitions
CMDF m_mdf;

Expand Down Expand Up @@ -900,6 +910,9 @@ class CFrmNodeConfig : public QMainWindow
/// Button to open GUID selections dialog
QPushButton *m_btnSetGUID;

// Button to mark handling to be full Level II
QCheckBox *m_btnFullLevel2;

/// Spin box for configuration nodeid
QSpinBox *m_nodeidConfig;

Expand Down
20 changes: 0 additions & 20 deletions src/cfrmnodescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ CFrmNodeScan::CFrmNodeScan(QWidget* parent, QJsonObject* pconn)
m_vscpClient = new vscpClientTcp();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

Expand All @@ -234,9 +233,6 @@ CFrmNodeScan::CFrmNodeScan(QWidget* parent, QJsonObject* pconn)
tr("Failed to initialize CANAL driver. See log for more details."));
return;
}
// We donät use a callback
//m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
// m_connObject["selected-interface"] = "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00";
connectToRemoteHost(true);
break;
Expand All @@ -252,8 +248,6 @@ CFrmNodeScan::CFrmNodeScan(QWidget* parent, QJsonObject* pconn)
"log for more details."));
return;
}
// m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;
#endif
Expand All @@ -262,79 +256,68 @@ CFrmNodeScan::CFrmNodeScan(QWidget* parent, QJsonObject* pconn)
m_vscpClient = new vscpClientWs1();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::WS2:
m_vscpClient = new vscpClientWs2();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::MQTT:
m_vscpClient = new vscpClientMqtt();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::UDP:
m_vscpClient = new vscpClientUdp();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::MULTICAST:
m_vscpClient = new vscpClientMulticast();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::REST:
m_vscpClient = new vscpClientRest();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::RS232:
m_vscpClient = new vscpClientRs232();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::RS485:
m_vscpClient = new vscpClientRs485();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::RAWCAN:
m_vscpClient = new vscpClientRawCan();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::RAWMQTT:
m_vscpClient = new vscpClientRawMqtt();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallback(eventReceived, this);
// m_connectActToolBar->setChecked(true);
connectToRemoteHost(true);
break;
}
Expand All @@ -351,9 +334,6 @@ CFrmNodeScan::CFrmNodeScan(QWidget* parent, QJsonObject* pconn)
// Scan has been selected in the menu
connect(ui->actionScan, SIGNAL(triggered()), this, SLOT(doScan()));

// Scan button has been clicked
// connect(ui->btnScan, SIGNAL(pressed()), this, SLOT(doScan()));

// Load MDF has been selected in the menu
connect(ui->actionLoadMdf, SIGNAL(triggered()), this, SLOT(loadSelectedMdf()));

Expand Down
Loading

0 comments on commit 8f3061f

Please sign in to comment.