From 15f7f664d7c2ab072d0350af7ceb3fb4eae4efb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anian=20B=C3=BChler?=
 <anian.buehler@reutlingen-university.de>
Date: Fri, 9 Jul 2021 12:19:27 +0200
Subject: [PATCH] changed Data to Payload

---
 src/didacticNet.cpp | 48 ++++++++++++++++++++++-----------------------
 src/didacticNet.h   | 24 +++++++++++------------
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/didacticNet.cpp b/src/didacticNet.cpp
index d1608ab..50c78b4 100644
--- a/src/didacticNet.cpp
+++ b/src/didacticNet.cpp
@@ -100,7 +100,7 @@ int didacticPSNet::checkData(){
 bool  didacticPSNet::recieveData() {
 	static int msgCounter = 0;
 	static int topicCounter = 0;
-	static int dataCounter = 0;
+	static int payloadCounter = 0;
 	//if(msgCounter == NULL){	msgCounter = 0;	}
 	//if(topicCounter == NULL){ topicCounter = 0; }
 	//if(dataCounter == NULL){ dataCounter = 0; }
@@ -109,7 +109,7 @@ bool  didacticPSNet::recieveData() {
 		if (localBuffer == MSG_PRELIMITER) {
 			msgCounter = 0;
 			topicCounter = 0;
-			dataCounter = 0;
+			payloadCounter = 0;
 			_readBufferMessage[msgCounter] = localBuffer;
     }
 		else if (localBuffer == MSG_DELIMITER && _readBufferMessage[0] == MSG_PRELIMITER) {
@@ -139,14 +139,14 @@ didacticPSNetClient::didacticPSNetClient(){}
 
 didacticPSNetClient::~didacticPSNetClient(){}
 
-bool didacticPSNetClient::publish(char* topic,  char* data){
+bool didacticPSNetClient::publish(char* topic,  char* payload){
 	int topicLength =  strlen(topic);
-	int dataLength = strlen(data);
+	int payloadLength = strlen(payload);
 	_sendBufferMessage[0] = MSG_PRELIMITER;
 	_sendBufferMessage[1] = MSG_PUBLISH;
 	_sendBufferMessage[2+topicLength] = MSG_SEPARATOR;
-	_sendBufferMessage[2+topicLength+1+dataLength] = MSG_DELIMITER;
-	_sendBufferMessage[2+topicLength+1+dataLength+1] = '\0';
+	_sendBufferMessage[2+topicLength+1+payloadLength] = MSG_DELIMITER;
+	_sendBufferMessage[2+topicLength+1+payloadLength+1] = '\0';
 
 	if(topicLength <= MAX_LEN_TOPICS){
 		for(int i = 0; i < topicLength; i++){
@@ -156,9 +156,9 @@ bool didacticPSNetClient::publish(char* topic,  char* data){
     _dataToSend = false;
 		return false;
 	}
-	if(dataLength <= MAX_LEN_PAYLOAD){
-		for(int i = 0; i < dataLength; i++){
-			_sendBufferMessage[2+topicLength+1+i] = data[i];
+	if(payloadLength <= MAX_LEN_PAYLOAD){
+		for(int i = 0; i < payloadLength; i++){
+			_sendBufferMessage[2+topicLength+1+i] = payload[i];
 		}
 	}else {
     _dataToSend = false;
@@ -168,12 +168,12 @@ bool didacticPSNetClient::publish(char* topic,  char* data){
 	return true;
 }
 
-bool didacticPSNetClient::publish(char* topic, int topicLength, char* data , int dataLength){
+bool didacticPSNetClient::publish(char* topic, int topicLength, char* payload , int payloadLength){
 	_sendBufferMessage[0] = MSG_PRELIMITER;
 	_sendBufferMessage[1] = MSG_PUBLISH;
 	_sendBufferMessage[2+topicLength] = MSG_SEPARATOR;
-	_sendBufferMessage[2+topicLength+1+dataLength] = MSG_DELIMITER;
-	_sendBufferMessage[2+topicLength+1+dataLength+1] = '\0';
+	_sendBufferMessage[2+topicLength+1+payloadLength] = MSG_DELIMITER;
+	_sendBufferMessage[2+topicLength+1+payloadLength+1] = '\0';
 
 	if(topicLength <= MAX_LEN_TOPICS){
 		for(int i = 0; i < topicLength; i++){
@@ -183,9 +183,9 @@ bool didacticPSNetClient::publish(char* topic, int topicLength, char* data , int
     _dataToSend = false;
 		return false;
 	}
-	if(dataLength <= MAX_LEN_PAYLOAD){
-		for(int i = 0; i < dataLength; i++){
-			_sendBufferMessage[2+topicLength+1+i] = data[i];
+	if(payloadLength <= MAX_LEN_PAYLOAD){
+		for(int i = 0; i < payloadLength; i++){
+			_sendBufferMessage[2+topicLength+1+i] = payload[i];
 		}
 	}else {
     _dataToSend = false;
@@ -302,22 +302,22 @@ bool didacticPSNetClient::getMessageFilter(char messageType){
   return messageType == MSG_UPDATE;
 }
 
-bool didacticPSNetClient::saveData(char* buffer, int position){
-  strcpy(_data[position], buffer);
+bool didacticPSNetClient::savePayload(char* buffer, int position){
+  strcpy(_payload[position], buffer);
   return true;
 }
 
 bool didacticPSNetClient::handleData(){
   int currentTopicNr = 0;
   int topicLength = 0;
-  int dataLength = 0;
+  int payloadLength = 0;
   topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR);
   if(topicLength > 0){
     currentTopicNr = getTopicNr(_bufferTopic);
-    dataLength  = extractData(topicLength+3, MAX_LEN_PAYLOAD, _bufferData, MSG_DELIMITER);
+    payloadLength  = extractData(topicLength+3, MAX_LEN_PAYLOAD, _bufferPayload, MSG_DELIMITER);
     if( currentTopicNr >= 0){
-      saveData( _bufferData, currentTopicNr);
-      callback(_topic[currentTopicNr], topicLength, _data[currentTopicNr], dataLength);
+      savePayload( _bufferPayload, currentTopicNr);
+      callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength);
     }
   }
   return true;
@@ -354,7 +354,7 @@ bool didacticPSNetBroker::getMessageFilter(char messageType){
   return (messageType == MSG_PUBLISH || messageType == MSG_SUBSCRIBE);
 }
 
-bool didacticPSNetBroker::saveData(char* buffer, int position){
+bool didacticPSNetBroker::savePayload(char* buffer, int position){
   strcpy(_data[position], buffer);
   return true;
 }
@@ -374,9 +374,9 @@ bool didacticPSNetBroker::handleData(){
     topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR);
     if(topicLength > 0){
       currentTopicNr = getTopicNr(_bufferTopic);
-      dataLength  = extractData(topicLength+3, MAX_LEN_PAYLOAD, _bufferData, MSG_DELIMITER);
+      dataLength  = extractData(topicLength+3, MAX_LEN_PAYLOAD, _bufferPayload, MSG_DELIMITER);
       if( currentTopicNr >= 0){
-        writeDataToTopic(currentTopicNr, _bufferTopic, _bufferData);
+        writeDataToTopic(currentTopicNr, _bufferTopic, _bufferPayload);
         update(_topic[currentTopicNr], topicLength, _data[currentTopicNr], dataLength);
       }
     }
diff --git a/src/didacticNet.h b/src/didacticNet.h
index 632e2d4..5143396 100644
--- a/src/didacticNet.h
+++ b/src/didacticNet.h
@@ -25,14 +25,14 @@
 #define MSG_TOPIC_MULTI     '*'
 
 #define CSMA_CHECK_DELAY_US 400
-#define CSMA_MIN_DELAY_MS 10
-#define CSMA_MID_DELAY_MS 20
-#define CSMA_MAX_DELAY_MS 30
+#define CSMA_MIN_DELAY_MS    10
+#define CSMA_MID_DELAY_MS    20
+#define CSMA_MAX_DELAY_MS    30
 
-#define MAX_NR_TOPICS_CLIENT  5
+#define MAX_NR_TOPICS_CLIENT   5
 #define MAX_NR_TOPICS_BROKER  20
-#define MAX_LEN_TOPICS 10
-#define MAX_LEN_PAYLOAD   20
+#define MAX_LEN_TOPICS 		  10
+#define MAX_LEN_PAYLOAD       20
 
 class didacticPSNet
 {
@@ -42,14 +42,14 @@ class didacticPSNet
 		PSNET_CALLBACK_SIGNATURE;
 
 		char _bufferTopic[MAX_LEN_TOPICS+1] = {0};
-		char _bufferData[MAX_LEN_PAYLOAD+1] = {0};
+		char _bufferPayload[MAX_LEN_PAYLOAD+1] = {0};
 		char _readBufferMessage[MAX_LEN_TOPICS + MAX_LEN_PAYLOAD +4+1];
 		char _sendBufferMessage[MAX_LEN_TOPICS + MAX_LEN_PAYLOAD +4+1];
 
 		bool _dataToSend = false; // int Data to send for queue?
 		unsigned long _waitingTime = 0L;
 		int _currentTopicLength = 0;
-		int _currentDataLength  = 0;
+		int _currentPayloadLength  = 0;
 
 		didacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE);
 		void setStream(Stream& _port);
@@ -62,7 +62,7 @@ class didacticPSNet
 		virtual int getTopicNr(char*)=0;
 		virtual int getFreeTopicNr()=0;
 		virtual bool getMessageFilter(char)=0;
-		virtual bool saveData(char*, int)=0;
+		virtual bool savePayload(char*, int)=0;
 		virtual bool handleData()=0;
 
 	public:
@@ -81,9 +81,9 @@ class didacticPSNetClient : public  didacticPSNet
 	private:
 
 	char _topic[MAX_NR_TOPICS_CLIENT][MAX_LEN_TOPICS+1] = { { 0 } };
-	char _data[MAX_NR_TOPICS_CLIENT][MAX_LEN_PAYLOAD+1] = { { 0 } };
+	char _payload[MAX_NR_TOPICS_CLIENT][MAX_LEN_PAYLOAD+1] = { { 0 } };
 
-	bool saveData(char*, int);
+	bool savePayload(char*, int);
 	bool getMessageFilter(char);
 	bool handleData();
 	int getTopicNr(char*);
@@ -110,7 +110,7 @@ class didacticPSNetBroker: public  didacticPSNet
 	char _topic[MAX_NR_TOPICS_BROKER][MAX_LEN_TOPICS+1] = { { 0 } };
 	char _data[MAX_NR_TOPICS_BROKER][MAX_LEN_PAYLOAD+1] = { { 0 } };
 
-	bool saveData(char*, int);
+	bool savePayload(char*, int);
 	bool getMessageFilter(char);
 	void writeDataToTopic(int, char*, char*);
 	bool handleData();
-- 
GitLab