Skip to content
Snippets Groups Projects
Verified Commit 9a56f5ae authored by Anian Bühler's avatar Anian Bühler
Browse files

removed defines from header files

parent 03ceaa3a
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,7 @@
#include "Arduino.h"
#define DN_MSG_PRELIMITER '<'
#define DN_MSG_DELIMITER '>'
#define DN_MSG_SEPARATOR '|'
//<@topic|payload>
#define DN_LEN_OVERHEAD 4
#define DN_MAX_LEN_TELEGRAM 40
#include "DidacticNetTransmit.h"
#include "DidacticNetPSN.h"
#endif
\ No newline at end of file
......@@ -6,7 +6,7 @@
/**************************************************************************/
#include "Arduino.h"
#include "DidacticNetPSN.h"
//**************************************************************************
// CLIENT
//**************************************************************************
......@@ -16,13 +16,20 @@ DidacticNetPSNClient::~DidacticNetPSNClient() {}
// ##########################################
void DidacticNetPSNClient::begin(Stream &_port) // TODO: check if CLientMode is necessary or an unset callback ist not a problem
{
DidacticNetTransmit::begin(_port);
_clientMode = CLIENT_MODE_BASIC;
DidacticNetPSNClient::begin(_port);
_clientMode = PS_CLIENT_MODE_BASIC;
}
void DidacticNetPSNClient::begin(Stream &_port, PSNET_CALLBACK_SIGNATURE)
{
DidacticNetTransmit::begin(_port, callback);
setStream(_port);
setCallback(callback);
}
DidacticNetPSNClient &DidacticNetPSNClient::setCallback(PSNET_CALLBACK_SIGNATURE)
{
this->callback = callback;
return *this;
}
bool DidacticNetPSNClient::available()
......@@ -95,7 +102,7 @@ int DidacticNetPSNClient::publish(char *topic, char *payload)
int DidacticNetPSNClient::publish(char *topic, int topicLength, char *payload, int payloadLength)
{
int error = DN_PUBLISH_SUCCESSULL;
int error = PS_PUBLISH_SUCCESSULL;
_sendBufferMessage[0] = DN_MSG_PRELIMITER;
_sendBufferMessage[1] = PS_MSG_PUBLISH;
......@@ -104,14 +111,14 @@ int DidacticNetPSNClient::publish(char *topic, int topicLength, char *payload, i
_sendBufferMessage[2 + topicLength + 1 + payloadLength + 1] = '\0';
// TODO: check
if (topicLength > MAX_LEN_TOPICS)
if (topicLength > PS_MAX_LEN_TOPICS)
{
topicLength = MAX_LEN_TOPICS;
topicLength = PS_MAX_LEN_TOPICS;
error += PS_ERROR_TOPIC_LEN;
}
if (payloadLength > MAX_LEN_PAYLOAD)
if (payloadLength > PS_MAX_LEN_PAYLOAD)
{
payloadLength = MAX_LEN_PAYLOAD;
payloadLength = PS_MAX_LEN_PAYLOAD;
error += PS_ERROR_PAYLOAD_LEN;
}
......@@ -130,7 +137,7 @@ int DidacticNetPSNClient::publish(char *topic, int topicLength, char *payload, i
int DidacticNetPSNClient::publish(char *topic, int data)
{
char sendPayload[MAX_LEN_PAYLOAD];
char sendPayload[PS_MAX_LEN_PAYLOAD];
itoa(data, sendPayload, 10);
return publish(topic, sendPayload);
......@@ -177,9 +184,9 @@ int DidacticNetPSNClient::subscribe(char *topic, int topicLength)
{
int error = PS_ERROR_NO_ERROR;
if (topicLength > MAX_LEN_TOPICS)
if (topicLength > PS_MAX_LEN_TOPICS)
{
topicLength = MAX_LEN_TOPICS;
topicLength = PS_MAX_LEN_TOPICS;
error = PS_ERROR_TOPIC_LEN;
}
......@@ -253,18 +260,18 @@ bool DidacticNetPSNClient::handleData()
int currentTopicNr = 0;
int topicLength = 0;
int payloadLength = 0;
topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, DN_MSG_SEPARATOR);
topicLength = extractData(2, PS_MAX_LEN_TOPICS, _bufferTopic, DN_MSG_SEPARATOR);
if (topicLength > 0)
{
currentTopicNr = getTopicNr(_bufferTopic);
payloadLength = extractData(topicLength + 3, MAX_LEN_PAYLOAD, _bufferPayload, DN_MSG_DELIMITER);
payloadLength = extractData(topicLength + 3, PS_MAX_LEN_PAYLOAD, _bufferPayload, DN_MSG_DELIMITER);
if (currentTopicNr >= 0)
{
savePayload(_bufferPayload, currentTopicNr);
_newMessageAvailable = true;
_newMessageTopicNr = currentTopicNr;
if (_clientMode == CLIENT_MODE_ADVANCED)
if (_clientMode == PS_CLIENT_MODE_ADVANCED)
{
#ifdef CALLBACK_W_LENGTH
callback(_bufferTopic, topicLength, _bufferPayload, payloadLength);
......@@ -356,11 +363,11 @@ bool DidacticNetPSNBroker::handleData()
if (_readBufferMessage[1] == PS_MSG_PUBLISH)
{
topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, DN_MSG_SEPARATOR);
topicLength = extractData(2, PS_MAX_LEN_TOPICS, _bufferTopic, DN_MSG_SEPARATOR);
if (topicLength > 0)
{
currentTopicNr = getTopicNr(_bufferTopic);
dataLength = extractData(topicLength + 3, MAX_LEN_PAYLOAD, _bufferPayload, DN_MSG_DELIMITER);
dataLength = extractData(topicLength + 3, PS_MAX_LEN_PAYLOAD, _bufferPayload, DN_MSG_DELIMITER);
if (currentTopicNr >= 0)
{
writeDataToTopic(currentTopicNr, _bufferTopic, _bufferPayload);
......@@ -370,7 +377,7 @@ bool DidacticNetPSNBroker::handleData()
}
else if (_readBufferMessage[1] == PS_MSG_SUBSCRIBE)
{
topicLength = extractData(2, MAX_LEN_TOPICS, _bufferTopic, DN_MSG_DELIMITER);
topicLength = extractData(2, PS_MAX_LEN_TOPICS, _bufferTopic, DN_MSG_DELIMITER);
if (topicLength > 0)
{
currentTopicNr = getTopicNr(_bufferTopic);
......@@ -391,7 +398,7 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int
_sendBufferMessage[2 + topicLength + 1 + dataLength] = DN_MSG_DELIMITER;
_sendBufferMessage[2 + topicLength + 1 + dataLength + 1] = '\0';
if (topicLength <= MAX_LEN_TOPICS)
if (topicLength <= PS_MAX_LEN_TOPICS)
{
for (int i = 0; i < topicLength; i++)
{
......@@ -403,7 +410,7 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int
_dataToSend = false;
return false;
}
if (dataLength <= MAX_LEN_PAYLOAD)
if (dataLength <= PS_MAX_LEN_PAYLOAD)
{
for (int i = 0; i < dataLength; i++)
{
......
......@@ -3,56 +3,33 @@
@author anian buehler @ letsgoING
**************************************************************************/
#include "Detector.h"
// PubSub
#ifdef CALLBACK_W_LENGTH
// callback(topic, topicLength, payload, payloadLength)
#define PSNET_CALLBACK_SIGNATURE void (*callback)(char *, int, char *, int)
#else
// callback(topic, payload)
#define PSNET_CALLBACK_SIGNATURE void (*callback)(char *, char *)
#endif
#define PS_CLIENT_MODE_BASIC false
#define PS_CLIENT_MODE_ADVANCED true
//@ publish → on publish check topic, then send topic-update
//? subscribe → subscribe starts update, topic filter @client
// # update → update to specific topic Broker to client
#define PS_MSG_PUBLISH '@'
#define PS_MSG_SUBSCRIBE '?'
#define PS_MSG_UPDATE '#'
#define PS_MSG_TOPIC_MULTI '*'
#define PS_MAX_NR_TOPICS_CLIENT 10
#define PS_MAX_NR_TOPICS_BROKER 20
#define PS_MAX_LEN_TOPICS 10
#define PS_MAX_LEN_PAYLOAD 20
#define PS_PUBLISH_SUCCESSULL 1
#define PS_ERROR_NO_ERROR 0
#define PS_ERROR_TOPIC_LEN -1
#define PS_ERROR_PAYLOAD_LEN -2
#define PS_ERROR_NO_TOPIC -3
#ifndef _DIDACTICNET_PSN_
#define _DIDACTICNET_PSN_
#define PS_INTERVAL_CLIENT 500L
#define PS_INTERVAL_BROKER 0L
#include "Arduino.h"
#include "Config.h"
#include "DidacticNetTransmit.h"
#include "Detector.h"
class DidacticPSNetClient : public DidacticNetTransmit
class DidacticNetPSNClient : public DidacticNetTransmit
{
private:
EdgeDetector eDetector;
ChangeDetector cDetector;
PSNET_CALLBACK_SIGNATURE;
char _topic[PS_MAX_NR_TOPICS_CLIENT][PS_MAX_LEN_TOPICS + 1] = {{0}};
char _payload[PS_MAX_NR_TOPICS_CLIENT][PS_MAX_LEN_PAYLOAD + 1] = {{0}};
char _bufferTopic[PS_MAX_LEN_TOPICS + 1] = {0};
char _bufferPayload[PS_MAX_LEN_TOPICS + 1] = {0};
bool _clientMode = PS_CLIENT_MODE_ADVANCED;
bool _newMessageAvailable = false;
int _newMessageTopicNr = 0;
char _currentTopic[MAX_LEN_TOPICS + 1] = {0};
char _currentPayload[MAX_LEN_PAYLOAD + 1] = {0};
char _currentTopic[PS_MAX_LEN_TOPICS + 1] = {0};
char _currentPayload[PS_MAX_LEN_PAYLOAD + 1] = {0};
bool savePayload(char *, int);
bool getMessageFilter(char);
......@@ -63,13 +40,17 @@ private:
int edgeDetected(bool);
bool valueChanged(int, int);
DidacticNetPSNClient &setCallback(PSNET_CALLBACK_SIGNATURE);
public:
DidacticPSNetClient();
~DidacticPSNetClient();
DidacticNetPSNClient();
~DidacticNetPSNClient();
void begin(Stream &_port);
void begin(Stream &_port, PSNET_CALLBACK_SIGNATURE);
DidacticNetPSNClient setCallback();
bool available();
int readLatestTopicNr();
void readTopic(char *);
......@@ -95,12 +76,15 @@ public:
bool unsubscribe(char *, int);
};
class DidacticPSNetBroker : public DidacticNetTransmit
class DidacticNetPSNBroker : public DidacticNetTransmit
{
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}};
char _topic[PS_MAX_NR_TOPICS_BROKER][PS_MAX_LEN_TOPICS + 1] = {{0}};
char _data[PS_MAX_NR_TOPICS_BROKER][PS_MAX_LEN_PAYLOAD + 1] = {{0}};
char _bufferTopic[PS_MAX_LEN_TOPICS + 1] = {0};
char _bufferPayload[PS_MAX_LEN_TOPICS + 1] = {0};
bool _isVerbose = false;
......@@ -114,8 +98,8 @@ private:
bool printVerbose(char *);
public:
DidacticPSNetBroker();
~DidacticPSNetBroker();
DidacticNetPSNBroker();
~DidacticNetPSNBroker();
void setVerbose(Stream &_port);
void setNoneVerbose();
......
......@@ -15,18 +15,6 @@ void DidacticNetTransmit::begin(Stream &_port)
setStream(_port);
}
void DidacticNetTransmit::begin(Stream &_port, PSNET_CALLBACK_SIGNATURE)
{
setStream(_port);
setCallback(callback);
}
DidacticNetTransmit &DidacticNetTransmit::setCallback(PSNET_CALLBACK_SIGNATURE)
{
this->callback = callback;
return *this;
}
void DidacticNetTransmit::setStream(Stream &stream)
{
_port = &stream;
......@@ -43,13 +31,13 @@ bool DidacticNetTransmit::handleNetwork()
handleData();
}
}
_waitingTimeCSMA = millis() + random(CSMA_MIN_DELAY_MS, CSMA_MAX_DELAY_MS);
_waitingTimeCSMA = millis() + random(DNT_CSMA_MIN_DELAY_MS, DNT_CSMA_MAX_DELAY_MS);
}
if (_dataToSend && _waitingTimeSend <= millis() && _waitingTimeCSMA <= millis())
{
// send data to network
unsigned long delayStartTime = micros();
while (micros() < delayStartTime + CSMA_CHECK_DELAY_US)
while (micros() < delayStartTime + DNT_CSMA_CHECK_DELAY_US)
;
if (!dataAvailable())
{
......@@ -74,7 +62,7 @@ bool DidacticNetTransmit::sendData()
bool messageSent = false;
while (!messageSent)
{
if (counter >= DN_MAX_LEN_TELEGRAM - 1)
if (counter >= DNT_MAX_LEN_TELEGRAM - 1)
{
_sendBufferMessage[counter] = DN_MSG_DELIMITER; // cut message and stop sending
messageSent = true;
......@@ -146,7 +134,7 @@ bool DidacticNetTransmit::recieveData()
}
else if (_readBufferMessage[0] == DN_MSG_PRELIMITER && localBuffer != DN_MSG_DELIMITER)
{
if (msgCounter > DN_MAX_LEN_TELEGRAM)
if (msgCounter > DNT_MAX_LEN_TELEGRAM)
{
msgCounter == 0;
_readBufferMessage[0] = '\0';
......
......@@ -3,29 +3,19 @@
@author anian buehler @ letsgoING
**************************************************************************/
#ifndef _DIDACTICNETTRANSMIT_
#define _DIDACTICNETTRANSMIT_
#ifndef _DIDACTICNET_TRANSMIT_
#define _DIDACTICNET_TRANSMIT_
#include "Arduino.h"
#define DN_LEN_OVERHEAD 4
#define DNT_CSMA_CHECK_DELAY_US 400
#define DNT_CSMA_MIN_DELAY_MS 10
#define DNT_CSMA_MID_DELAY_MS 20
#define DNT_CSMA_MAX_DELAY_MS 30
#include "Config.h"
class DidacticNetTransmit
{
protected:
Stream *_port;
PSNET_CALLBACK_SIGNATURE;
char _bufferTopic[MAX_LEN_TOPICS + 1] = {0};
char _bufferPayload[MAX_LEN_PAYLOAD + 1] = {0};
char _readBufferMessage[DN_MAX_LEN_TELEGRAM + 1];
char _sendBufferMessage[DN_MAX_LEN_TELEGRAM + 1];
char _readBufferMessage[DNT_MAX_LEN_TELEGRAM + 1];
char _sendBufferMessage[DNT_MAX_LEN_TELEGRAM + 1];
bool _dataToSend = false; // int Data to send for queue?
unsigned long _waitingTimeSend = 0L;
......@@ -34,11 +24,9 @@ protected:
int _currentTopicLength = 0;
int _currentPayloadLength = 0;
DidacticNetTransmit &setCallback(PSNET_CALLBACK_SIGNATURE);
void setStream(Stream &_port);
int checkData();
int dataAvailable();
bool recieveData();
bool sendData();
int extractData(int, int, char *, char);
......@@ -54,7 +42,7 @@ public:
~DidacticNetTransmit();
void begin(Stream &_port);
void begin(Stream &_port, PSNET_CALLBACK_SIGNATURE);
// void begin(Stream &_port, PSNET_CALLBACK_SIGNATURE);
bool handleNetwork();
bool isDataToSend();
......
......@@ -5,7 +5,7 @@
*/
/**************************************************************************/
#include SerialUI.h
#include "SerialUI.h"
SerialReader::SerialReader() {}
SerialReader::~SerialReader() {}
......@@ -49,12 +49,12 @@ char serialMonitorUI::extractCommand(char *userInput)
strcpy(userInput, &userInput[1]);
return command;
}
return DN_ASCII_EOS;
return SUI_ASCII_EOS;
}
bool serialMonitorUI::available()
{
if (SerialReader::readSerialData(_currentInput, DN_ASCII_CR) > 0)
if (SerialReader::readSerialData(_currentInput, SUI_ASCII_CR) > 0)
{
_currentCommand = extractCommand(_currentInput);
return true;
......
......@@ -7,14 +7,7 @@
#define _LGI_SERIALUI_
#include "Arduino.h"
#define SUI_MAX_LEN_USERINPUT 41
// little helpers
#define SUI_ASCII_EOS 0
#define SUI_ASCII_CR 13
#define SUI_ASCII_NL 10
#define SUI_ASCII_DEL 127
#include "Config.h"
class SerialReader
{
......
......@@ -5,7 +5,7 @@
*/
/**************************************************************************/
#include UnblockingTimer.h
#include "UnblockingTimer.h"
UnblockingTimer::UnblockingTimer() {}
UnblockingTimer::~UnblockingTimer() {}
......
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