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

implementet addresses

parent 79008bb6
Branches dev_AddAppl
No related tags found
No related merge requests found
...@@ -3,28 +3,30 @@ ...@@ -3,28 +3,30 @@
@author anian buehler @ letsgoING @author anian buehler @ letsgoING
**************************************************************************/ **************************************************************************/
// APPLICATION // NETWORK
#define DN_MSG_PRELIMITER '<' #define DN_MSG_PRELIMITER '<'
#define DN_MSG_DELIMITER '>' #define DN_MSG_DELIMITER '>'
#define DN_MSG_SEPARATOR '|' #define DN_MSG_SEPARATOR '|'
#define DN_NETWORK_ADDRESS_BROADCAST 0
#define DN_APPLICATION_PUBSUB 1
#define DN_APPLICATION_PEERTOPEER 2
// NEW FRAME // NEW FRAME
// // IMMER BEIDE ADDRESSEN!!!!
// < APP ADD-R SERV TOPIC1-n | DATA1-n > /PSN // < APP ADD-R ADD_S SERV TOPIC1-n | DATA1-n > /PSN
// < APP ADD-R ADD-S APP DATA1-n > /P2P // < APP ADD-R ADD-S APP DATA1-n > /P2P
// Address 1 byte 0-F // Address 1 byte 0-F
// Applications 0-9 -> 1 PSN / 2 P2P / tbd // Applications 0-9 -> 1 PSN / 2 P2P / tbd
#define DN_APPLICATION_LEN_OVERHEAD 6 #define DNN_LEN_OVERHEAD 6
#define DNN_POS_APPL 1
#define DNN_POS_ADD_REC 2
#define DNN_POS_ADD_SND 3
#define DNN_POS_PS_SERVIS 4
#define DNN_ADDRESS_BROADCAST '0'
#define DN_APPLICATION_POS_APPL 1 // APPLICATIONS
#define DN_APPLICATION_POS_ADD_REC 2 #define DNN_APP_NONE 0
#define DN_APPLICATION_POS_ADD_SND 3 #define DNN_APP_PUBSUB 1
#define DN_APPLICATION_POS_PS_SERV 3 #define DNN_APP_PEERTOPEER 2
// PUBSUB APPLICATION // PUBSUB APPLICATION
//************************/ //************************/
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// NEW FRAME // NEW FRAME
// //
// < APP ADD-R SERV TOPIC1-n | DATA1-n > /PSN // < APP ADD-R ADD-S SERV TOPIC1-n | DATA1-n > /PSN
// < APP ADD-R ADD-S APP DATA1-n > /P2P // < APP ADD-R ADD-S APP DATA1-n > /P2P
// Address 1 byte 0-F // Address 1 byte 0-F
// Applications 0-9 -> 1 PSN / 2 P2P / tbd // Applications 0-9 -> 1 PSN / 2 P2P / tbd
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
void DidacticNetNetwork::handleRawData(char *_rawData) void DidacticNetNetwork::handleRawData(char *_rawData)
{ {
if ((_rawData[DN_APPLICATION_POS_ADD_REC] == _networkAddress || _rawData[DN_APPLICATION_POS_ADD_REC] == DN_NETWORK_ADDRESS_BROADCAST) && _rawData[DN_APPLICATION_POS_APPL] == _networkApplication) if ((_rawData[DNN_POS_ADD_REC] == _networkAddress || _rawData[DNN_POS_ADD_REC] == DNN_ADDRESS_BROADCAST) && _rawData[DNN_POS_APPL] == _networkApplication)
{ {
handleData(_rawData); handleData(_rawData);
} }
...@@ -17,10 +17,20 @@ void DidacticNetNetwork::setNetworkAddress(char networkAddress) ...@@ -17,10 +17,20 @@ void DidacticNetNetwork::setNetworkAddress(char networkAddress)
{ {
_networkAddress = networkAddress; _networkAddress = networkAddress;
} }
void DidacticNetNetwork::setNetworkAddress(int networkAddress)
{
char networkAddressBuffer;
itoa(networkAddress, networkAddressBuffer, 10);
setNetworkAddress(networkAddressBuffer);
}
char DidacticNetNetwork::getNetworkAddress() char DidacticNetNetwork::getNetworkAddress()
{ {
return _networkAddress; return _networkAddress;
} }
void DidacticNetNetwork::setNetworkApplication(int networkApplication) void DidacticNetNetwork::setNetworkApplication(int networkApplication)
{ {
_networkApplication = networkApplication; _networkApplication = networkApplication;
...@@ -32,12 +42,19 @@ int DidacticNetNetwork::getNetworkApplication() ...@@ -32,12 +42,19 @@ int DidacticNetNetwork::getNetworkApplication()
} }
bool DidacticNetNetwork::setTelegram(char *data, char addressReceiver) bool DidacticNetNetwork::setTelegram(char *data, char addressReceiver)
{
if (strlen(data) + DNN_LEN_OVERHEAD <= DNT_MAX_LEN_TELEGRAM)
{ {
_sendBufferMessage[0] = DN_MSG_PRELIMITER; _sendBufferMessage[0] = DN_MSG_PRELIMITER;
_sendBufferMessage[DN_APPLICATION_POS_APPL] = getNetworkApplication(); _sendBufferMessage[DNN_POS_APPL] = _networkApplication;
_sendBufferMessage[DN_APPLICATION_POS_ADD_REC] = addressReceiver; _sendBufferMessage[DNN_POS_ADD_REC] = addressReceiver;
strcpy(&_sendBufferMessage[DN_APPLICATION_POS_ADD_REC + 1], data); _sendBufferMessage[DNN_POS_ADD_SND] = _networkAddress;
_sendBufferMessage[DN_APPLICATION_POS_ADD_REC + 1 + strlen(data)] = DN_MSG_DELIMITER; strcpy(&_sendBufferMessage[DNN_POS_ADD_SND + 1], data);
_sendBufferMessage[DNN_POS_ADD_SND + 1 + strlen(data)] = DN_MSG_DELIMITER;
_dataToSend = true; _dataToSend = true;
return true;
}
return false;
} }
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
class DidacticNetNetwork : public DidacticNetTransmit class DidacticNetNetwork : public DidacticNetTransmit
{ {
protected: protected:
char _networkAddress = '0'; char _networkAddress = DNN_ADDRESS_BROADCAST; // ADDR in HEX 0-F
int _networkApplication = 0; int _networkApplication = DNN_APP_NONE;
void handleRawData(char *); void handleRawData(char *);
void setNetworkApplication(int); void setNetworkApplication(int);
...@@ -26,6 +26,7 @@ protected: ...@@ -26,6 +26,7 @@ protected:
public: public:
void setNetworkAddress(char); void setNetworkAddress(char);
void setNetworkAddress(int);
char getNetworkAddress(); char getNetworkAddress();
int getNetworkApplication(); int getNetworkApplication();
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
//************************************************************************** //**************************************************************************
// CLIENT // CLIENT
//************************************************************************** //**************************************************************************
DidacticNetPSNClient::DidacticNetPSNClient()
{
_intervalTime = PS_INTERVAL_CLIENT;
setNetworkApplication(DNN_APP_PUBSUB);
}
DidacticNetPSNClient::~DidacticNetPSNClient() {} DidacticNetPSNClient::~DidacticNetPSNClient() {}
// NEW easy interface for non advanced users // NEW easy interface for non advanced users
...@@ -100,11 +106,6 @@ int DidacticNetPSNClient::readPayloadParseInt() ...@@ -100,11 +106,6 @@ int DidacticNetPSNClient::readPayloadParseInt()
} }
// ########################################## // ##########################################
DidacticNetPSNClient::DidacticNetPSNClient()
{
_intervalTime = PS_INTERVAL_CLIENT;
}
int DidacticNetPSNClient::publish(char *topic, char *payload) int DidacticNetPSNClient::publish(char *topic, char *payload)
{ {
return publish(topic, strlen(topic), payload, strlen(payload)); return publish(topic, strlen(topic), payload, strlen(payload));
...@@ -138,6 +139,11 @@ int DidacticNetPSNClient::publish(char *topic, int topicLength, char *payload, i ...@@ -138,6 +139,11 @@ int DidacticNetPSNClient::publish(char *topic, int topicLength, char *payload, i
publishBuffer[1 + topicLength + 1 + i] = payload[i]; publishBuffer[1 + topicLength + 1 + i] = payload[i];
} }
// DEBUG
Serial.print("DBG: publish: ");
Serial.println(publishBuffer);
//! DEBUG
setTelegram(publishBuffer, _brokerAddress); setTelegram(publishBuffer, _brokerAddress);
return error; return error;
...@@ -229,6 +235,12 @@ int DidacticNetPSNClient::subscribe(char *topic, int topicLength) ...@@ -229,6 +235,12 @@ int DidacticNetPSNClient::subscribe(char *topic, int topicLength)
subscribeBuffer[1 + topicLength + 1] = '\0'; subscribeBuffer[1 + topicLength + 1] = '\0';
} }
// DEBUG
Serial.print("DBG: subscribe: ");
Serial.println(subscribeBuffer);
Serial.print("DBG: subscribe: ");
//! DEBUG
setTelegram(subscribeBuffer, _brokerAddress); setTelegram(subscribeBuffer, _brokerAddress);
while (_dataToSend) while (_dataToSend)
...@@ -339,6 +351,7 @@ int DidacticNetPSNClient::getMaxNrTopics() ...@@ -339,6 +351,7 @@ int DidacticNetPSNClient::getMaxNrTopics()
DidacticNetPSNBroker::DidacticNetPSNBroker() DidacticNetPSNBroker::DidacticNetPSNBroker()
{ {
_intervalTime = PS_INTERVAL_BROKER; _intervalTime = PS_INTERVAL_BROKER;
setNetworkApplication(DNN_APP_PUBSUB);
} }
DidacticNetPSNBroker::~DidacticNetPSNBroker() {} DidacticNetPSNBroker::~DidacticNetPSNBroker() {}
...@@ -402,17 +415,16 @@ bool DidacticNetPSNBroker::handleData(char *bufferedMessage) // change to handle ...@@ -402,17 +415,16 @@ bool DidacticNetPSNBroker::handleData(char *bufferedMessage) // change to handle
bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int dataLength) bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int dataLength)
{ {
_sendBufferMessage[0] = DN_MSG_PRELIMITER; char updateBuffer[DNT_MAX_LEN_TELEGRAM] = {0};
_sendBufferMessage[1] = PS_MSG_UPDATE; updateBuffer[0] = PS_MSG_UPDATE;
_sendBufferMessage[2 + topicLength] = DN_MSG_SEPARATOR; updateBuffer[1 + topicLength] = DN_MSG_SEPARATOR;
_sendBufferMessage[2 + topicLength + 1 + dataLength] = DN_MSG_DELIMITER; updateBuffer[1 + topicLength + 1 + dataLength] = '\0';
_sendBufferMessage[2 + topicLength + 1 + dataLength + 1] = '\0';
if (topicLength <= PS_MAX_LEN_TOPICS) if (topicLength <= PS_MAX_LEN_TOPICS)
{ {
for (int i = 0; i < topicLength; i++) for (int i = 0; i < topicLength; i++)
{ {
_sendBufferMessage[2 + i] = topic[i]; _sendBufferMessage[1 + i] = topic[i];
} }
} }
else else
...@@ -424,7 +436,7 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int ...@@ -424,7 +436,7 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int
{ {
for (int i = 0; i < dataLength; i++) for (int i = 0; i < dataLength; i++)
{ {
_sendBufferMessage[2 + topicLength + 1 + i] = data[i]; _sendBufferMessage[1 + topicLength + 1 + i] = data[i];
} }
} }
else else
...@@ -432,6 +444,8 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int ...@@ -432,6 +444,8 @@ bool DidacticNetPSNBroker::update(char *topic, int topicLength, char *data, int
_dataToSend = false; _dataToSend = false;
return false; return false;
} }
setTelegram(updateBuffer, DNN_ADDRESS_BROADCAST); // Broadcast on update
_dataToSend = true; _dataToSend = true;
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment