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(){
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);
}
}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment