Skip to content

Commit

Permalink
Added retain clear method for MQTT publish topics
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Apr 4, 2024
1 parent d6b85ca commit e127f71
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 110 deletions.
73 changes: 73 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# VSCP Works + -- Things to do


## MQTT
- Handel string, binary, json and xml content
- First character is not 0x00, "<" or "{" ==> STRING
- First character 0x00 and content len > 0 ==> BINARY (UDP format)
- First non white space character "<" ==> XML
- First non white space character "{" ==> JSON

## LOCAL Dialog
- TODO Add log file types

### CANAL - dialog


## SOCKETCAN - dialog


## UDP - dialog
- TODO test connection needs to be implemented.

## MULTICAST - dialog
- TODO test connection needs to be implemented.

## GUID database
- TODO GUID to name (database, DNS).
- TODO Load/save GUID sets

## RAW CANAL
- TODO Collect id's and allow to filtering on them (SavveyCAN).
- TODO Two views (ID frequency, messages) a'la PEAK.

## Session window
- TODO Colormarking from filter. Match set filter/icon.
- TODO Set filter from recived event.
- Undefined events should be possible to display info for as user defined evenst
- Received event cloned to transmit
- Received event cloned to filter and !filter
- Toolbar: connect | filter active | filter combo | base combo
- Define your own data rendering (Javascript/mustasch)
- Custom data rendering for any event from db.
- Config device from session window.
- Change line and status info when GUID symbolic or sensor symbolic has been updated
- MQTT: activate/deactivate subscription on the fly. (publish topics also maybe)
- Better and more flexible sizing

## Configuration window
- search register / next
- search remote variable /next
- Remove ctrl+0/1/2... from menu keep functionality.

## Scan window


## Bootloader window


## MDF editor window
Encoding/decoding of strings to match JSON/XML.


## GUID Known nodes Dialog
TODO Dialog with add/edit/delete of known GUID's. CDlgGuid.ui

## Dialog log viewer
TODO Dialog with log viewing/filtering CDlgLog

## Misc.
Generate code for web page interfaces

## FUTURE
https://github.com/mguentner/cannelloni
85 changes: 0 additions & 85 deletions src/TODO.todo

This file was deleted.

39 changes: 26 additions & 13 deletions src/cdlgselectmqtttopics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ CDlgSelectMqttTopics::CDlgSelectMqttTopics(QWidget* parent)
// this,
// &CDlgSelectMqttTopics::onRowDoubleClicked);

m_bSubscriptionTopics = true; // Subscription topics is default
m_pvscpClient = nullptr; // No client yet
m_type = CDlgSelectMqttTopics::SUBSCRIBE; // Subscription topics is default
m_pvscpClient = nullptr; // No client yet
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -150,21 +150,34 @@ CDlgSelectMqttTopics::fillPublishTopics(void)
// init
//

void
CDlgSelectMqttTopics::init(bool bSubscription, const CVscpClient* pvscpClient)
int
CDlgSelectMqttTopics::init(CDlgSelectMqttTopics::dlgtype type, const CVscpClient* pvscpClient)
{
m_bSubscriptionTopics = bSubscription;
m_pvscpClient = (vscpClientMqtt*)pvscpClient;
m_type = type;

// Check pointer
if (nullptr == pvscpClient) {
return VSCP_ERROR_INVALID_POINTER;
}

m_pvscpClient = (vscpClientMqtt*)pvscpClient;

// Fill the table with data
if (bSubscription) {
if (CDlgSelectMqttTopics::SUBSCRIBE == type) {
setWindowTitle("MQTT Subscription topics");
fillSubscriptionTopics();
}
else {
else if (CDlgSelectMqttTopics::PUBLISH == type) {
setWindowTitle("MQTT Publish topics");
fillPublishTopics();
}
else if (CDlgSelectMqttTopics::CLRRETAIN == type) {
setWindowTitle("MQTT clear retain publish topics");
fillPublishTopics();
}

QIcon icon(":/check-mark-red.png");
return VSCP_ERROR_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -194,22 +207,22 @@ void
CDlgSelectMqttTopics::accepted(void)
{
int pos = 0;
if (m_bSubscriptionTopics) {
if (CDlgSelectMqttTopics::SUBSCRIBE == m_type) {
std::list<subscribeTopic*>* plist = m_pvscpClient->getSubscribeList();
for (std::list<subscribeTopic*>::iterator it = plist->begin(); it != plist->end(); ++it) {
subscribeTopic* psub = *it;
psub->setActive(isActive(pos));
pos++;
}
}
else {
pos = 0;
else if (CDlgSelectMqttTopics::PUBLISH == m_type) {
pos = 0;
std::list<publishTopic*>* plist = m_pvscpClient->getPublishList();
for (std::list<publishTopic*>::iterator it = plist->begin(); it != plist->end(); ++it) {
publishTopic* ppub = *it;
ppub->setActive(isActive(pos));
std::string str = ppub->getTopic();
m_pvscpClient->clearRetain4Topic(str);
pos++;
}
}
}

22 changes: 16 additions & 6 deletions src/cdlgselectmqtttopics.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class CDlgSelectMqttTopics : public QDialog {
~CDlgSelectMqttTopics();

public:
// const int SUBSCRIBE = 0;
// const int PUBLISH = 1;
// const int CLRRETAIN = 2;
typedef enum {
SUBSCRIBE,
PUBLISH,
CLRRETAIN
} dlgtype;

/*!
Fill table with subscription topics
*/
Expand All @@ -60,8 +69,9 @@ class CDlgSelectMqttTopics : public QDialog {
false to handel publiosh topics
@param pvscpClient Pointer to client object. Is expected
to be initialized and opened.
@return VSCP_ERROR_SUCCESS if OK otherwise errorcode
*/
void init(bool bSubscription, const CVscpClient* pvscpClient);
int init(dlgtype type, const CVscpClient* pvscpClient);

/*!
Get state for a row in the table widget list
Expand All @@ -72,21 +82,21 @@ public slots:

/*!
Called when the accepted button is pressed
Will update the subscribe/publish list with
Will update the subscribe/publish list with
the active/inactive content from the list
*/
void accepted(void);

/*!
Double click is used to select or deselect topics
*/
//void onRowDoubleClicked(void);
// void onRowDoubleClicked(void);

private:
Ui::CDlgSelectMqttTopics* ui;

/// Subscription topics
bool m_bSubscriptionTopics;
/// Topics types
bool m_type;

/// Pointer to client object
vscpClientMqtt* m_pvscpClient;
Expand Down
34 changes: 28 additions & 6 deletions src/cfrmsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
#include <vscp_client_rs232.h>
#include <vscp_client_rs485.h>

#include "cdlgselectmqtttopics.h"
#include "cdlgknownguid.h"
#include "cdlgselectmqtttopics.h"
#include "cdlgsessionfilter.h"
#include "cfrmsession.h"

Expand Down Expand Up @@ -562,8 +562,8 @@ CFrmSession::createMenu()

// * * * Connection menu * * *

//m_connMenu = new QMenu(tr("&Connection"), this);
// m_connMenu = new QMenu(tr("&Connection"), this);

// m_connectAct = m_connMenu->addAction(tr("Connect to interface..."),
// this,
// &CFrmSession::menu_connect);
Expand All @@ -574,7 +574,7 @@ CFrmSession::createMenu()
// m_pauseAct = m_connMenu->addAction(tr("Pause host"));
// m_addHostAct = m_connMenu->addAction(tr("Add host..."));

//m_menuBar->addMenu(m_connMenu);
// m_menuBar->addMenu(m_connMenu);

// * * * VSCP menu * * *
m_vscpMenu = new QMenu(tr("&VSCP"), this);
Expand Down Expand Up @@ -605,6 +605,9 @@ CFrmSession::createMenu()
m_mqttPublishTopics = m_mqttMenu->addAction(tr("MQTT publish topics..."),
this,
&CFrmSession::openMqttPublishTopics);
m_mqttPublishTopics = m_mqttMenu->addAction(tr("Clear MQTT retain topics..."),
this,
&CFrmSession::openClearMqttRetainPublishTopics);
m_menuBar->addMenu(m_mqttMenu);
}

Expand Down Expand Up @@ -1011,6 +1014,8 @@ CFrmSession::menu_clear_rxlist(void)
QApplication::setOverrideCursor(Qt::WaitCursor);
QApplication::processEvents();

m_infoArea->clear();

m_rxTable->setCurrentCell(-1, -1); // unselect all

m_mutexRxList.lock();
Expand Down Expand Up @@ -1401,8 +1406,11 @@ CFrmSession::sendTxEvent(void)

CTxWidgetItem* itemEvent = (CTxWidgetItem*)m_txTable->item(it->row(), txrow_event);
vscpEvent* pev = itemEvent->m_tx.getEvent();
pev->timestamp = vscp_makeTimeStamp(); // Set timestamp
vscp_setEventToNow(pev); // Set time information to "now"

for (int i = 0; i < itemEvent->m_tx.getCount(); i++) {
// Send Event
if (VSCP_ERROR_SUCCESS != m_vscpClient->send(*pev)) {
spdlog::error(std::string(tr("Session: Unable to send event").toStdString()));
QMessageBox::information(
Expand Down Expand Up @@ -3624,7 +3632,7 @@ void
CFrmSession::openMqttSubscribeTopics(void)
{
CDlgSelectMqttTopics dlg;
dlg.init(true, m_vscpClient);
dlg.init(CDlgSelectMqttTopics::SUBSCRIBE, m_vscpClient);
if (QDialog::Accepted == dlg.exec()) {
// Disconnect
connectToRemoteHost(false);
Expand All @@ -3641,7 +3649,7 @@ void
CFrmSession::openMqttPublishTopics(void)
{
CDlgSelectMqttTopics dlg;
dlg.init(false, m_vscpClient);
dlg.init(CDlgSelectMqttTopics::PUBLISH, m_vscpClient);
if (QDialog::Accepted == dlg.exec()) {
// Disconnect
connectToRemoteHost(false);
Expand All @@ -3650,6 +3658,20 @@ CFrmSession::openMqttPublishTopics(void)
}
}

///////////////////////////////////////////////////////////////////////////////
// openClearMqttRetainPublishTopics
//

void
CFrmSession::openClearMqttRetainPublishTopics(void)
{
CDlgSelectMqttTopics dlg;
dlg.init(CDlgSelectMqttTopics::CLRRETAIN, m_vscpClient);
if (QDialog::Accepted == dlg.exec()) {
// Noting to do
}
}

///////////////////////////////////////////////////////////////////////////////
// getClassInfo
//
Expand Down
Loading

0 comments on commit e127f71

Please sign in to comment.