Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DidacticNetwork
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
Libraries
DidacticNetwork
Commits
15f7f664
Commit
15f7f664
authored
4 years ago
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
changed Data to Payload
parent
7438fa3c
No related branches found
Branches containing commit
No related tags found
2 merge requests
!3
Dev to master
,
!2
Dev to Master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/didacticNet.cpp
+24
-24
24 additions, 24 deletions
src/didacticNet.cpp
src/didacticNet.h
+12
-12
12 additions, 12 deletions
src/didacticNet.h
with
36 additions
and
36 deletions
src/didacticNet.cpp
+
24
−
24
View file @
15f7f664
...
@@ -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
data
Counter
=
0
;
static
int
payload
Counter
=
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
;
data
Counter
=
0
;
payload
Counter
=
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
data
Length
=
strlen
(
data
);
int
payload
Length
=
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
+
data
Length
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payload
Length
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
data
Length
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payload
Length
+
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
(
data
Length
<=
MAX_LEN_PAYLOAD
){
if
(
payload
Length
<=
MAX_LEN_PAYLOAD
){
for
(
int
i
=
0
;
i
<
data
Length
;
i
++
){
for
(
int
i
=
0
;
i
<
payload
Length
;
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
data
Length
){
bool
didacticPSNetClient
::
publish
(
char
*
topic
,
int
topicLength
,
char
*
payload
,
int
payload
Length
){
_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
+
data
Length
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payload
Length
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
data
Length
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payload
Length
+
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
(
data
Length
<=
MAX_LEN_PAYLOAD
){
if
(
payload
Length
<=
MAX_LEN_PAYLOAD
){
for
(
int
i
=
0
;
i
<
data
Length
;
i
++
){
for
(
int
i
=
0
;
i
<
payload
Length
;
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
::
save
Data
(
char
*
buffer
,
int
position
){
bool
didacticPSNetClient
::
save
Payload
(
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
data
Length
=
0
;
int
payload
Length
=
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
);
data
Length
=
extractData
(
topicLength
+
3
,
MAX_LEN_PAYLOAD
,
_buffer
Data
,
MSG_DELIMITER
);
payload
Length
=
extractData
(
topicLength
+
3
,
MAX_LEN_PAYLOAD
,
_buffer
Payload
,
MSG_DELIMITER
);
if
(
currentTopicNr
>=
0
){
if
(
currentTopicNr
>=
0
){
save
Data
(
_buffer
Data
,
currentTopicNr
);
save
Payload
(
_buffer
Payload
,
currentTopicNr
);
callback
(
_topic
[
currentTopicNr
],
topicLength
,
_
data
[
currentTopicNr
],
data
Length
);
callback
(
_topic
[
currentTopicNr
],
topicLength
,
_
payload
[
currentTopicNr
],
payload
Length
);
}
}
}
}
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
::
save
Data
(
char
*
buffer
,
int
position
){
bool
didacticPSNetBroker
::
save
Payload
(
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
,
_buffer
Data
,
MSG_DELIMITER
);
dataLength
=
extractData
(
topicLength
+
3
,
MAX_LEN_PAYLOAD
,
_buffer
Payload
,
MSG_DELIMITER
);
if
(
currentTopicNr
>=
0
){
if
(
currentTopicNr
>=
0
){
writeDataToTopic
(
currentTopicNr
,
_bufferTopic
,
_buffer
Data
);
writeDataToTopic
(
currentTopicNr
,
_bufferTopic
,
_buffer
Payload
);
update
(
_topic
[
currentTopicNr
],
topicLength
,
_data
[
currentTopicNr
],
dataLength
);
update
(
_topic
[
currentTopicNr
],
topicLength
,
_data
[
currentTopicNr
],
dataLength
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/didacticNet.h
+
12
−
12
View file @
15f7f664
...
@@ -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
_buffer
Data
[
MAX_LEN_PAYLOAD
+
1
]
=
{
0
};
char
_buffer
Payload
[
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
_current
Data
Length
=
0
;
int
_current
Payload
Length
=
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
save
Data
(
char
*
,
int
)
=
0
;
virtual
bool
save
Payload
(
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
save
Data
(
char
*
,
int
);
bool
save
Payload
(
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
save
Data
(
char
*
,
int
);
bool
save
Payload
(
char
*
,
int
);
bool
getMessageFilter
(
char
);
bool
getMessageFilter
(
char
);
void
writeDataToTopic
(
int
,
char
*
,
char
*
);
void
writeDataToTopic
(
int
,
char
*
,
char
*
);
bool
handleData
();
bool
handleData
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment