From c871d10524f1b61214bd9fe6ffd052145710aa95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anian=20B=C3=BChler?=
 <anian.buehler@reutlingen-university.de>
Date: Wed, 13 Mar 2024 17:45:47 +0100
Subject: [PATCH] added Broker -verbose Mode

---
 src/DidacticNet.cpp | 31 +++++++++++++++++++++++++++++++
 src/DidacticNet.h   |  8 +++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/DidacticNet.cpp b/src/DidacticNet.cpp
index 3649719..76dc62e 100644
--- a/src/DidacticNet.cpp
+++ b/src/DidacticNet.cpp
@@ -515,6 +515,9 @@ bool DidacticPSNetBroker::handleData()
   int currentTopicNr = 0;
   int topicLength = 0;
   int dataLength = 0;
+
+  printVerbose(_readBufferMessage);
+
   if (_readBufferMessage[1] == MSG_PUBLISH)
   {
     topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR);
@@ -604,6 +607,34 @@ int DidacticPSNetBroker::getFreeTopicNr()
   return -1;
 }
 
+void DidacticPSNetBroker::setVerbose(Stream &verbosePort) // TEST: new & untested
+{
+  _isVerbose = true;
+  _verbosePort = &verbosePort;
+}
+
+void DidacticPSNetBroker::setNoneVerbose() // TEST: new & untested
+{
+  _isVerbose = false;
+}
+
+bool DidacticPSNetBroker::printVerbose(char *recievedData) // TEST: new & untested
+{
+  char signBuffer = 0;
+  int signCounter = 0;
+
+  if (_isVerbose)
+  {
+    while (signBuffer != MSG_DELIMITER)
+    {
+      signBuffer = recievedData[signCounter];
+      _verbosePort->write(signBuffer);
+      signCounter++;
+    }
+  }
+  return _isVerbose;
+}
+
 //**************************************************************************
 // LITTLE HELPERS FOR CLIENTS ;-)
 //*************************************************************************
diff --git a/src/DidacticNet.h b/src/DidacticNet.h
index fe97293..5812f7a 100644
--- a/src/DidacticNet.h
+++ b/src/DidacticNet.h
@@ -223,21 +223,27 @@ public:
 class DidacticPSNetBroker : public DidacticPSNet
 {
 private:
+	Stream *_verbosePort;
 	char _topic[MAX_NR_TOPICS_BROKER][MAX_LEN_TOPICS + 1] = {{0}};
 	char _data[MAX_NR_TOPICS_BROKER][MAX_LEN_PAYLOAD + 1] = {{0}};
 
+	bool _isVerbose = false;
+
 	bool savePayload(char *, int);
 	bool getMessageFilter(char);
 	void writeDataToTopic(int, char *, char *);
 	bool handleData();
 	int getTopicNr(char *);
 	int getFreeTopicNr();
+	bool update(char *, int, char *, int); // TEST: moved from public
+	bool printVerbose(char *);			   // TEST: new & untested
 
 public:
 	DidacticPSNetBroker();
 	~DidacticPSNetBroker();
 
-	bool update(char *, int, char *, int);
+	void setVerbose(Stream &_port); // TEST: new & untested
+	void setNoneVerbose();			// TEST: new & untested
 };
 
 #endif
-- 
GitLab