Skip to content
Snippets Groups Projects
Commit 15f7f664 authored by Anian Bühler's avatar Anian Bühler
Browse files

changed Data to Payload

parent 7438fa3c
No related branches found
No related tags found
2 merge requests!3Dev to master,!2Dev to Master
...@@ -100,7 +100,7 @@ int didacticPSNet::checkData(){ ...@@ -100,7 +100,7 @@ int didacticPSNet::checkData(){
bool didacticPSNet::recieveData() { bool didacticPSNet::recieveData() {
static int msgCounter = 0; static int msgCounter = 0;
static int topicCounter = 0; static int topicCounter = 0;
static int dataCounter = 0; static int payloadCounter = 0;
//if(msgCounter == NULL){ msgCounter = 0; } //if(msgCounter == NULL){ msgCounter = 0; }
//if(topicCounter == NULL){ topicCounter = 0; } //if(topicCounter == NULL){ topicCounter = 0; }
//if(dataCounter == NULL){ dataCounter = 0; } //if(dataCounter == NULL){ dataCounter = 0; }
...@@ -109,7 +109,7 @@ bool didacticPSNet::recieveData() { ...@@ -109,7 +109,7 @@ bool didacticPSNet::recieveData() {
if (localBuffer == MSG_PRELIMITER) { if (localBuffer == MSG_PRELIMITER) {
msgCounter = 0; msgCounter = 0;
topicCounter = 0; topicCounter = 0;
dataCounter = 0; payloadCounter = 0;
_readBufferMessage[msgCounter] = localBuffer; _readBufferMessage[msgCounter] = localBuffer;
} }
else if (localBuffer == MSG_DELIMITER && _readBufferMessage[0] == MSG_PRELIMITER) { else if (localBuffer == MSG_DELIMITER && _readBufferMessage[0] == MSG_PRELIMITER) {
...@@ -139,14 +139,14 @@ didacticPSNetClient::didacticPSNetClient(){} ...@@ -139,14 +139,14 @@ didacticPSNetClient::didacticPSNetClient(){}
didacticPSNetClient::~didacticPSNetClient(){} didacticPSNetClient::~didacticPSNetClient(){}
bool didacticPSNetClient::publish(char* topic, char* data){ bool didacticPSNetClient::publish(char* topic, char* payload){
int topicLength = strlen(topic); int topicLength = strlen(topic);
int dataLength = strlen(data); int payloadLength = strlen(payload);
_sendBufferMessage[0] = MSG_PRELIMITER; _sendBufferMessage[0] = MSG_PRELIMITER;
_sendBufferMessage[1] = MSG_PUBLISH; _sendBufferMessage[1] = MSG_PUBLISH;
_sendBufferMessage[2+topicLength] = MSG_SEPARATOR; _sendBufferMessage[2+topicLength] = MSG_SEPARATOR;
_sendBufferMessage[2+topicLength+1+dataLength] = MSG_DELIMITER; _sendBufferMessage[2+topicLength+1+payloadLength] = MSG_DELIMITER;
_sendBufferMessage[2+topicLength+1+dataLength+1] = '\0'; _sendBufferMessage[2+topicLength+1+payloadLength+1] = '\0';
if(topicLength <= MAX_LEN_TOPICS){ if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){ for(int i = 0; i < topicLength; i++){
...@@ -156,9 +156,9 @@ bool didacticPSNetClient::publish(char* topic, char* data){ ...@@ -156,9 +156,9 @@ bool didacticPSNetClient::publish(char* topic, char* data){
_dataToSend = false; _dataToSend = false;
return false; return false;
} }
if(dataLength <= MAX_LEN_PAYLOAD){ if(payloadLength <= MAX_LEN_PAYLOAD){
for(int i = 0; i < dataLength; i++){ for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = data[i]; _sendBufferMessage[2+topicLength+1+i] = payload[i];
} }
}else { }else {
_dataToSend = false; _dataToSend = false;
...@@ -168,12 +168,12 @@ bool didacticPSNetClient::publish(char* topic, char* data){ ...@@ -168,12 +168,12 @@ bool didacticPSNetClient::publish(char* topic, char* data){
return true; 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[0] = MSG_PRELIMITER;
_sendBufferMessage[1] = MSG_PUBLISH; _sendBufferMessage[1] = MSG_PUBLISH;
_sendBufferMessage[2+topicLength] = MSG_SEPARATOR; _sendBufferMessage[2+topicLength] = MSG_SEPARATOR;
_sendBufferMessage[2+topicLength+1+dataLength] = MSG_DELIMITER; _sendBufferMessage[2+topicLength+1+payloadLength] = MSG_DELIMITER;
_sendBufferMessage[2+topicLength+1+dataLength+1] = '\0'; _sendBufferMessage[2+topicLength+1+payloadLength+1] = '\0';
if(topicLength <= MAX_LEN_TOPICS){ if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){ for(int i = 0; i < topicLength; i++){
...@@ -183,9 +183,9 @@ bool didacticPSNetClient::publish(char* topic, int topicLength, char* data , int ...@@ -183,9 +183,9 @@ bool didacticPSNetClient::publish(char* topic, int topicLength, char* data , int
_dataToSend = false; _dataToSend = false;
return false; return false;
} }
if(dataLength <= MAX_LEN_PAYLOAD){ if(payloadLength <= MAX_LEN_PAYLOAD){
for(int i = 0; i < dataLength; i++){ for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = data[i]; _sendBufferMessage[2+topicLength+1+i] = payload[i];
} }
}else { }else {
_dataToSend = false; _dataToSend = false;
...@@ -302,22 +302,22 @@ bool didacticPSNetClient::getMessageFilter(char messageType){ ...@@ -302,22 +302,22 @@ bool didacticPSNetClient::getMessageFilter(char messageType){
return messageType == MSG_UPDATE; return messageType == MSG_UPDATE;
} }
bool didacticPSNetClient::saveData(char* buffer, int position){ bool didacticPSNetClient::savePayload(char* buffer, int position){
strcpy(_data[position], buffer); strcpy(_payload[position], buffer);
return true; return true;
} }
bool didacticPSNetClient::handleData(){ bool didacticPSNetClient::handleData(){
int currentTopicNr = 0; int currentTopicNr = 0;
int topicLength = 0; int topicLength = 0;
int dataLength = 0; int payloadLength = 0;
topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR); topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR);
if(topicLength > 0){ if(topicLength > 0){
currentTopicNr = getTopicNr(_bufferTopic); 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){ if( currentTopicNr >= 0){
saveData( _bufferData, currentTopicNr); savePayload( _bufferPayload, currentTopicNr);
callback(_topic[currentTopicNr], topicLength, _data[currentTopicNr], dataLength); callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength);
} }
} }
return true; return true;
...@@ -354,7 +354,7 @@ bool didacticPSNetBroker::getMessageFilter(char messageType){ ...@@ -354,7 +354,7 @@ bool didacticPSNetBroker::getMessageFilter(char messageType){
return (messageType == MSG_PUBLISH || messageType == MSG_SUBSCRIBE); 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); strcpy(_data[position], buffer);
return true; return true;
} }
...@@ -374,9 +374,9 @@ bool didacticPSNetBroker::handleData(){ ...@@ -374,9 +374,9 @@ bool didacticPSNetBroker::handleData(){
topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR); topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, MSG_SEPARATOR);
if(topicLength > 0){ if(topicLength > 0){
currentTopicNr = getTopicNr(_bufferTopic); 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){ if( currentTopicNr >= 0){
writeDataToTopic(currentTopicNr, _bufferTopic, _bufferData); writeDataToTopic(currentTopicNr, _bufferTopic, _bufferPayload);
update(_topic[currentTopicNr], topicLength, _data[currentTopicNr], dataLength); update(_topic[currentTopicNr], topicLength, _data[currentTopicNr], dataLength);
} }
} }
......
...@@ -25,14 +25,14 @@ ...@@ -25,14 +25,14 @@
#define MSG_TOPIC_MULTI '*' #define MSG_TOPIC_MULTI '*'
#define CSMA_CHECK_DELAY_US 400 #define CSMA_CHECK_DELAY_US 400
#define CSMA_MIN_DELAY_MS 10 #define CSMA_MIN_DELAY_MS 10
#define CSMA_MID_DELAY_MS 20 #define CSMA_MID_DELAY_MS 20
#define CSMA_MAX_DELAY_MS 30 #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_NR_TOPICS_BROKER 20
#define MAX_LEN_TOPICS 10 #define MAX_LEN_TOPICS 10
#define MAX_LEN_PAYLOAD 20 #define MAX_LEN_PAYLOAD 20
class didacticPSNet class didacticPSNet
{ {
...@@ -42,14 +42,14 @@ class didacticPSNet ...@@ -42,14 +42,14 @@ class didacticPSNet
PSNET_CALLBACK_SIGNATURE; PSNET_CALLBACK_SIGNATURE;
char _bufferTopic[MAX_LEN_TOPICS+1] = {0}; 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 _readBufferMessage[MAX_LEN_TOPICS + MAX_LEN_PAYLOAD +4+1];
char _sendBufferMessage[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? bool _dataToSend = false; // int Data to send for queue?
unsigned long _waitingTime = 0L; unsigned long _waitingTime = 0L;
int _currentTopicLength = 0; int _currentTopicLength = 0;
int _currentDataLength = 0; int _currentPayloadLength = 0;
didacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE); didacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE);
void setStream(Stream& _port); void setStream(Stream& _port);
...@@ -62,7 +62,7 @@ class didacticPSNet ...@@ -62,7 +62,7 @@ class didacticPSNet
virtual int getTopicNr(char*)=0; virtual int getTopicNr(char*)=0;
virtual int getFreeTopicNr()=0; virtual int getFreeTopicNr()=0;
virtual bool getMessageFilter(char)=0; virtual bool getMessageFilter(char)=0;
virtual bool saveData(char*, int)=0; virtual bool savePayload(char*, int)=0;
virtual bool handleData()=0; virtual bool handleData()=0;
public: public:
...@@ -81,9 +81,9 @@ class didacticPSNetClient : public didacticPSNet ...@@ -81,9 +81,9 @@ class didacticPSNetClient : public didacticPSNet
private: private:
char _topic[MAX_NR_TOPICS_CLIENT][MAX_LEN_TOPICS+1] = { { 0 } }; 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 getMessageFilter(char);
bool handleData(); bool handleData();
int getTopicNr(char*); int getTopicNr(char*);
...@@ -110,7 +110,7 @@ class didacticPSNetBroker: public didacticPSNet ...@@ -110,7 +110,7 @@ class didacticPSNetBroker: public didacticPSNet
char _topic[MAX_NR_TOPICS_BROKER][MAX_LEN_TOPICS+1] = { { 0 } }; char _topic[MAX_NR_TOPICS_BROKER][MAX_LEN_TOPICS+1] = { { 0 } };
char _data[MAX_NR_TOPICS_BROKER][MAX_LEN_PAYLOAD+1] = { { 0 } }; char _data[MAX_NR_TOPICS_BROKER][MAX_LEN_PAYLOAD+1] = { { 0 } };
bool saveData(char*, int); bool savePayload(char*, int);
bool getMessageFilter(char); bool getMessageFilter(char);
void writeDataToTopic(int, char*, char*); void writeDataToTopic(int, char*, char*);
bool handleData(); bool handleData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment