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
0b3ad2a5
Commit
0b3ad2a5
authored
4 years ago
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
added error return tu subscribe
parent
e5db9571
No related branches found
No related tags found
2 merge requests
!3
Dev to master
,
!2
Dev to Master
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/sPSN_Chat/sPSN_Chat.ino
+2
-3
2 additions, 3 deletions
examples/sPSN_Chat/sPSN_Chat.ino
keywords.txt
+5
-0
5 additions, 0 deletions
keywords.txt
src/didacticNet.cpp
+33
-14
33 additions, 14 deletions
src/didacticNet.cpp
src/didacticNet.h
+2
-5
2 additions, 5 deletions
src/didacticNet.h
with
42 additions
and
22 deletions
examples/sPSN_Chat/sPSN_Chat.ino
+
2
−
3
View file @
0b3ad2a5
...
@@ -75,14 +75,14 @@ void loop() {
...
@@ -75,14 +75,14 @@ void loop() {
int
nrOfAscii
=
readSerialData
(
Serial
,
readData
,
13
);
//Einlesen der Nutzereingabe am SerialMonitor (Rueckgabewert = Anzahl der gelesenen Zeichen)
int
nrOfAscii
=
readSerialData
(
Serial
,
readData
,
13
);
//Einlesen der Nutzereingabe am SerialMonitor (Rueckgabewert = Anzahl der gelesenen Zeichen)
if
(
nrOfAscii
>
0
)
{
//Wenn Daten fertig eingelesen wurden
if
(
nrOfAscii
>
0
)
{
//Wenn Daten fertig eingelesen wurden
if
(
readData
[
0
]
==
'@'
)
{
//Wenn '@' vorne steht, dann neuer Chatpartner anlegen (neues Topic abonnieren)
if
(
readData
[
0
]
==
'@'
)
{
//Wenn '@' vorne steht, dann neuer Chatpartner anlegen (neues Topic abonnieren)
strcpy
(
readData
,
readData
+
1
);
//verschiebe um ein Zeichen (entferne '@')
strcpy
(
readData
,
readData
+
1
);
//verschiebe um ein Zeichen (entferne '@')
psnClient
.
subscribe
(
readData
);
//Lege fest zu welchem Topic Daten empfangen werden sollen (den Namen des Chatpartners)
psnClient
.
subscribe
(
readData
);
//Lege fest zu welchem Topic Daten empfangen werden sollen (den Namen des Chatpartners)
Serial
.
print
(
"Nachrichten von "
);
//Ausgabe welches Topic abonniert wurde
Serial
.
print
(
"Nachrichten von "
);
//Ausgabe welches Topic abonniert wurde
Serial
.
print
(
readData
);
Serial
.
print
(
readData
);
Serial
.
println
(
" abonniert"
);
Serial
.
println
(
" abonniert
.
"
);
}
}
else
if
(
readData
[
0
]
==
'#'
)
{
//Wenn '#' vorne steht, dann neuer eigener Name (neues Topic unter dem gesendet wird)
else
if
(
readData
[
0
]
==
'#'
)
{
//Wenn '#' vorne steht, dann neuer eigener Name (neues Topic unter dem gesendet wird)
...
@@ -98,7 +98,6 @@ void loop() {
...
@@ -98,7 +98,6 @@ void loop() {
Serial
.
print
(
"Ich:
\t
"
);
//Ausgabe was unter deinem Topic veröffentlicht wird
Serial
.
print
(
"Ich:
\t
"
);
//Ausgabe was unter deinem Topic veröffentlicht wird
Serial
.
println
(
readData
);
Serial
.
println
(
readData
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
keywords.txt
+
5
−
0
View file @
0b3ad2a5
...
@@ -16,6 +16,7 @@ didacticPSNetClient KEYWORD1
...
@@ -16,6 +16,7 @@ didacticPSNetClient KEYWORD1
edgeDetected KEYWORD2
edgeDetected KEYWORD2
valueChanged KEYWORD2
valueChanged KEYWORD2
timeElapsed KEYWORD2
timeElapsed KEYWORD2
readSerialData KEYWORD2
setCallback KEYWORD2
setCallback KEYWORD2
setStream KEYWORD2
setStream KEYWORD2
...
@@ -42,3 +43,7 @@ MAX_NR_TOPICS_CLIENT LITERAL1
...
@@ -42,3 +43,7 @@ MAX_NR_TOPICS_CLIENT LITERAL1
MAX_NR_TOPICS_BROKER LITERAL1
MAX_NR_TOPICS_BROKER LITERAL1
MAX_LEN_TOPICS LITERAL1
MAX_LEN_TOPICS LITERAL1
MAX_LEN_PAYLOAD LITERAL1
MAX_LEN_PAYLOAD LITERAL1
DN_ERROR_NOERROR LITERAL1
DN_ERROR_TOPIC_LEN LITERAL1
DN_ERROR_PAYLOAD_LEN LITERAL1
This diff is collapsed.
Click to expand it.
src/didacticNet.cpp
+
33
−
14
View file @
0b3ad2a5
...
@@ -302,8 +302,16 @@ int didacticPSNetClient::publish(char* topic, int topicLength, char* payload , i
...
@@ -302,8 +302,16 @@ int didacticPSNetClient::publish(char* topic, int topicLength, char* payload , i
return
error
;
return
error
;
}
}
bool
didacticPSNetClient
::
subscribe
(
char
*
topic
){
int
didacticPSNetClient
::
subscribe
(
char
*
topic
){
int
error
=
DN_ERROR_NOERROR
;
int
topicLength
=
strlen
(
topic
);
int
topicLength
=
strlen
(
topic
);
if
(
topicLength
>
MAX_LEN_TOPICS
){
topicLength
=
MAX_LEN_TOPICS
;
error
=
DN_ERROR_TOPIC_LEN
;
}
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
_sendBufferMessage
[
1
]
=
MSG_SUBSCRIBE
;
_sendBufferMessage
[
1
]
=
MSG_SUBSCRIBE
;
_sendBufferMessage
[
2
+
topicLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
]
=
MSG_DELIMITER
;
...
@@ -315,7 +323,8 @@ bool didacticPSNetClient::subscribe(char* topic){
...
@@ -315,7 +323,8 @@ bool didacticPSNetClient::subscribe(char* topic){
if
(
topicNumber
<
0
){
if
(
topicNumber
<
0
){
topicNumber
=
0
;
topicNumber
=
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
++
){
_topic
[
topicNumber
][
i
]
=
topic
[
i
];
_topic
[
topicNumber
][
i
]
=
topic
[
i
];
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
...
@@ -323,28 +332,36 @@ bool didacticPSNetClient::subscribe(char* topic){
...
@@ -323,28 +332,36 @@ bool didacticPSNetClient::subscribe(char* topic){
_topic
[
topicNumber
][
topicLength
]
=
'\0'
;
_topic
[
topicNumber
][
topicLength
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_dataToSend
=
true
;
_dataToSend
=
true
;
}
/*
}
else {
else {
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}*/
}
}
else
{
else
{
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
];
}
}
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_dataToSend
=
true
;
_dataToSend
=
true
;
}
//
}
}
}
while
(
_dataToSend
){
while
(
_dataToSend
){
handleNetwork
();
handleNetwork
();
}
}
return
true
;
return
error
;
}
}
bool
didacticPSNetClient
::
subscribe
(
char
*
topic
,
int
topicLength
){
int
didacticPSNetClient
::
subscribe
(
char
*
topic
,
int
topicLength
){
int
error
=
DN_ERROR_NOERROR
;
if
(
topicLength
>
MAX_LEN_TOPICS
){
topicLength
=
MAX_LEN_TOPICS
;
error
=
DN_ERROR_TOPIC_LEN
;
}
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
_sendBufferMessage
[
0
]
=
MSG_PRELIMITER
;
_sendBufferMessage
[
1
]
=
MSG_SUBSCRIBE
;
_sendBufferMessage
[
1
]
=
MSG_SUBSCRIBE
;
_sendBufferMessage
[
2
+
topicLength
]
=
MSG_DELIMITER
;
_sendBufferMessage
[
2
+
topicLength
]
=
MSG_DELIMITER
;
...
@@ -356,7 +373,8 @@ bool didacticPSNetClient::subscribe(char* topic, int topicLength){
...
@@ -356,7 +373,8 @@ bool didacticPSNetClient::subscribe(char* topic, int topicLength){
if
(
topicNumber
<
0
){
if
(
topicNumber
<
0
){
topicNumber
=
0
;
topicNumber
=
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
++
){
_topic
[
topicNumber
][
i
]
=
topic
[
i
];
_topic
[
topicNumber
][
i
]
=
topic
[
i
];
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
_sendBufferMessage
[
2
+
i
]
=
topic
[
i
];
...
@@ -364,25 +382,26 @@ bool didacticPSNetClient::subscribe(char* topic, int topicLength){
...
@@ -364,25 +382,26 @@ bool didacticPSNetClient::subscribe(char* topic, int topicLength){
_topic
[
topicNumber
][
topicLength
]
=
'\0'
;
_topic
[
topicNumber
][
topicLength
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_dataToSend
=
true
;
_dataToSend
=
true
;
}
/*
}
else {
else {
_dataToSend = false;
_dataToSend = false;
return false;
return false;
}
}*/
}
}
else
{
else
{
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
];
}
}
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_sendBufferMessage
[
2
+
topicLength
+
1
]
=
'\0'
;
_dataToSend
=
true
;
_dataToSend
=
true
;
}
//
}
}
}
while
(
_dataToSend
){
while
(
_dataToSend
){
handleNetwork
();
handleNetwork
();
}
}
return
true
;
return
error
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/didacticNet.h
+
2
−
5
View file @
0b3ad2a5
...
@@ -94,7 +94,6 @@ class didacticPSNet
...
@@ -94,7 +94,6 @@ class didacticPSNet
class
didacticPSNetClient
:
public
didacticPSNet
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
_payload
[
MAX_NR_TOPICS_CLIENT
][
MAX_LEN_PAYLOAD
+
1
]
=
{
{
0
}
};
char
_payload
[
MAX_NR_TOPICS_CLIENT
][
MAX_LEN_PAYLOAD
+
1
]
=
{
{
0
}
};
...
@@ -110,18 +109,16 @@ class didacticPSNetClient : public didacticPSNet
...
@@ -110,18 +109,16 @@ class didacticPSNetClient : public didacticPSNet
int
publish
(
char
*
,
char
*
);
int
publish
(
char
*
,
char
*
);
int
publish
(
char
*
,
int
,
char
*
,
int
);
int
publish
(
char
*
,
int
,
char
*
,
int
);
bool
subscribe
(
char
*
);
int
subscribe
(
char
*
);
bool
subscribe
(
char
*
,
int
);
int
subscribe
(
char
*
,
int
);
bool
unsubscribe
(
char
*
);
bool
unsubscribe
(
char
*
);
bool
unsubscribe
(
char
*
,
int
);
bool
unsubscribe
(
char
*
,
int
);
};
};
class
didacticPSNetBroker
:
public
didacticPSNet
class
didacticPSNetBroker
:
public
didacticPSNet
{
{
private:
private:
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
}
};
...
...
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