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
Automate
Agent sessions
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
Libraries
DidacticNetwork
Commits
e5db9571
Commit
e5db9571
authored
Jul 13, 2021
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
added length error publish
parent
ff6ff78b
Branches
Branches containing commit
No related tags found
2 merge requests
!3
Dev to master
,
!2
Dev to Master
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/didacticNet.cpp
+55
-12
55 additions, 12 deletions
src/didacticNet.cpp
src/didacticNet.h
+14
-10
14 additions, 10 deletions
src/didacticNet.h
with
69 additions
and
22 deletions
src/didacticNet.cpp
+
55
−
12
View file @
e5db9571
...
@@ -150,11 +150,13 @@ int didacticPSNet::extractData(int startCounter, int maxLength, char* buffer, ch
...
@@ -150,11 +150,13 @@ int didacticPSNet::extractData(int startCounter, int maxLength, char* buffer, ch
buffer
[
counter
-
startCounter
]
=
_readBufferMessage
[
counter
];
buffer
[
counter
-
startCounter
]
=
_readBufferMessage
[
counter
];
counter
++
;
counter
++
;
if
((
counter
-
startCounter
)
>
maxLength
){
if
((
counter
-
startCounter
)
>
maxLength
){
return
-
1
;
//return -1;
Serial
.
print
(
"
\n
extractData - Return on MAX length
\n
"
);
break
;
//if > maxLenght -> leave while and return
}
}
}
}
buffer
[
counter
-
startCounter
]
=
'\0'
;
buffer
[
counter
-
startCounter
]
=
'\0'
;
return
counter
-
startCounter
;
//length
of Topic
return
counter
-
startCounter
;
//length
}
}
int
didacticPSNet
::
checkData
(){
int
didacticPSNet
::
checkData
(){
...
@@ -203,7 +205,9 @@ didacticPSNetClient::didacticPSNetClient(){}
...
@@ -203,7 +205,9 @@ didacticPSNetClient::didacticPSNetClient(){}
didacticPSNetClient
::~
didacticPSNetClient
(){}
didacticPSNetClient
::~
didacticPSNetClient
(){}
bool
didacticPSNetClient
::
publish
(
char
*
topic
,
char
*
payload
){
int
didacticPSNetClient
::
publish
(
char
*
topic
,
char
*
payload
){
int
error
=
DN_ERROR_NOERROR
;
int
topicLength
=
strlen
(
topic
);
int
topicLength
=
strlen
(
topic
);
int
payloadLength
=
strlen
(
payload
);
int
payloadLength
=
strlen
(
payload
);
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
...
@@ -212,11 +216,28 @@ bool didacticPSNetClient::publish(char* topic, char* payload){
...
@@ -212,11 +216,28 @@ bool didacticPSNetClient::publish(char* topic, char* payload){
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
+
1
]
=
'\0'
;
//TODO: check
if
(
topicLength
>
MAX_LEN_TOPICS
){
topicLength
=
MAX_LEN_TOPICS
;
error
+=
DN_ERROR_TOPIC_LEN
;
}
if
(
payloadLength
>
MAX_LEN_PAYLOAD
){
payloadLength
=
MAX_LEN_PAYLOAD
;
error
+=
DN_ERROR_PAYLOAD_LEN
;
}
for
(
int
i
=
0
;
i
<
topicLength
;
i
++
){
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
}
for
(
int
i
=
0
;
i
<
payloadLength
;
i
++
){
_sendBufferMessage
[
2
+
topicLength
+
1
+
i
]
=
payload
[
i
];
}
/*
if(topicLength <= MAX_LEN_TOPICS){
if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i] = topic[i];
_sendBufferMessage[2+i] = topic[i];
}
}
}
else
{
}else {
//cut topic if longer than max
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}
...
@@ -224,26 +245,47 @@ bool didacticPSNetClient::publish(char* topic, char* payload){
...
@@ -224,26 +245,47 @@ bool didacticPSNetClient::publish(char* topic, char* payload){
for(int i = 0; i < payloadLength; i++){
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
}
}
else
{
}else {
//cut message if longer than max
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}
*/
_dataToSend
=
true
;
_dataToSend
=
true
;
return
true
;
return
error
;
}
}
bool
didacticPSNetClient
::
publish
(
char
*
topic
,
int
topicLength
,
char
*
payload
,
int
payloadLength
){
int
didacticPSNetClient
::
publish
(
char
*
topic
,
int
topicLength
,
char
*
payload
,
int
payloadLength
){
int
error
=
DN_ERROR_NOERROR
;
_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
+
payloadLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
+
payloadLength
+
1
]
=
'\0'
;
//TODO: check
if
(
topicLength
>
MAX_LEN_TOPICS
){
topicLength
=
MAX_LEN_TOPICS
;
error
+=
DN_ERROR_TOPIC_LEN
;
}
if
(
payloadLength
>
MAX_LEN_PAYLOAD
){
payloadLength
=
MAX_LEN_PAYLOAD
;
error
+=
DN_ERROR_PAYLOAD_LEN
;
}
for
(
int
i
=
0
;
i
<
topicLength
;
i
++
){
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
}
for
(
int
i
=
0
;
i
<
payloadLength
;
i
++
){
_sendBufferMessage
[
2
+
topicLength
+
1
+
i
]
=
payload
[
i
];
}
/*
if(topicLength <= MAX_LEN_TOPICS){
if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i] = topic[i];
_sendBufferMessage[2+i] = topic[i];
}
}
}
else
{
}else {
//cut topic if longer than max
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}
...
@@ -251,12 +293,13 @@ bool didacticPSNetClient::publish(char* topic, int topicLength, char* payload ,
...
@@ -251,12 +293,13 @@ bool didacticPSNetClient::publish(char* topic, int topicLength, char* payload ,
for(int i = 0; i < payloadLength; i++){
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
}
}
else
{
}else {
//cut message if longer than max
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}
*/
_dataToSend
=
true
;
_dataToSend
=
true
;
return
true
;
return
error
;
}
}
bool
didacticPSNetClient
::
subscribe
(
char
*
topic
){
bool
didacticPSNetClient
::
subscribe
(
char
*
topic
){
...
@@ -389,7 +432,7 @@ bool didacticPSNetClient::handleData(){
...
@@ -389,7 +432,7 @@ bool didacticPSNetClient::handleData(){
int
didacticPSNetClient
::
getTopicNr
(
char
*
topic
){
int
didacticPSNetClient
::
getTopicNr
(
char
*
topic
){
for
(
int
i
=
0
;
i
<
MAX_NR_TOPICS_CLIENT
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_NR_TOPICS_CLIENT
;
i
++
)
{
if
(
strcmp
(
_topic
[
i
],
topic
)
==
0
)
{
if
(
strcmp
(
_topic
[
i
],
topic
)
==
0
||
_topic
[
i
][
0
]
==
MSG_TOPIC_MULTI
)
{
//TODO: check ... or equal MSG_TOPIC_MULTI
return
i
;
return
i
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/didacticNet.h
+
14
−
10
View file @
e5db9571
...
@@ -15,20 +15,17 @@
...
@@ -15,20 +15,17 @@
#define MSG_DELIMITER '>'
#define MSG_DELIMITER '>'
#define MSG_SEPARATOR '|'
#define MSG_SEPARATOR '|'
//@ publish → on publish check topic, then send topic-update
//@ publish → on publish check topic, then send topic-update
//? subscribe → subscribe starts update, topic filter @client
//? subscribe → subscribe starts update, topic filter @client
//# update → update to specific topic Broker to client
//# update → update to specific topic Broker to client
#define MSG_PUBLISH '@'
#define MSG_PUBLISH '@'
#define MSG_SUBSCRIBE '?'
#define MSG_SUBSCRIBE '?'
#define MSG_UPDATE '#'
#define MSG_UPDATE '#'
#define MSG_TOPIC_MULTI '*'
//<@topic|payload>
//<@topic|payload>
#define LEN_OVERHEAD 4
#define LEN_OVERHEAD 4
#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
...
@@ -39,7 +36,14 @@
...
@@ -39,7 +36,14 @@
#define MAX_LEN_TOPICS 10
#define MAX_LEN_TOPICS 10
#define MAX_LEN_PAYLOAD 20
#define MAX_LEN_PAYLOAD 20
#define DN_ERROR_NOERROR 0
#define DN_ERROR_TOPIC_LEN -1
#define DN_ERROR_PAYLOAD_LEN -2
//little helpers
//little helpers
#define ASCII_CR 13
#define ASCII_NL 10
int
edgeDetected
(
bool
);
int
edgeDetected
(
bool
);
bool
valueChanged
(
int
,
int
);
bool
valueChanged
(
int
,
int
);
bool
timeElapsed
(
long
);
bool
timeElapsed
(
long
);
...
@@ -54,8 +58,8 @@ class didacticPSNet
...
@@ -54,8 +58,8 @@ class didacticPSNet
char
_bufferTopic
[
MAX_LEN_TOPICS
+
1
]
=
{
0
};
char
_bufferTopic
[
MAX_LEN_TOPICS
+
1
]
=
{
0
};
char
_bufferPayload
[
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
+
LEN_OVERHEAD
+
1
];
char
_sendBufferMessage
[
MAX_LEN_TOPICS
+
MAX_LEN_PAYLOAD
+
4
+
1
];
char
_sendBufferMessage
[
MAX_LEN_TOPICS
+
MAX_LEN_PAYLOAD
+
LEN_OVERHEAD
+
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
;
...
@@ -104,8 +108,8 @@ class didacticPSNetClient : public didacticPSNet
...
@@ -104,8 +108,8 @@ class didacticPSNetClient : public didacticPSNet
didacticPSNetClient
();
didacticPSNetClient
();
~
didacticPSNetClient
();
~
didacticPSNetClient
();
bool
publish
(
char
*
,
char
*
);
int
publish
(
char
*
,
char
*
);
bool
publish
(
char
*
,
int
,
char
*
,
int
);
int
publish
(
char
*
,
int
,
char
*
,
int
);
bool
subscribe
(
char
*
);
bool
subscribe
(
char
*
);
bool
subscribe
(
char
*
,
int
);
bool
subscribe
(
char
*
,
int
);
bool
unsubscribe
(
char
*
);
bool
unsubscribe
(
char
*
);
...
...
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
sign in
to comment