Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ArduBlock2
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
ArduBlock Source
ArduBlock2
Commits
5efedc7e
Verified
Commit
5efedc7e
authored
2 years ago
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
added updated DidacticNet library
parent
b606eacb
No related branches found
No related tags found
1 merge request
!1
dev_prefereences to master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/resources/com/ardublock/libraries/DidacticNet.cpp
+15
-7
15 additions, 7 deletions
src/main/resources/com/ardublock/libraries/DidacticNet.cpp
src/main/resources/com/ardublock/libraries/DidacticNet.h
+18
-9
18 additions, 9 deletions
src/main/resources/com/ardublock/libraries/DidacticNet.h
with
33 additions
and
16 deletions
src/main/resources/com/ardublock/libraries/
d
idacticNet.cpp
→
src/main/resources/com/ardublock/libraries/
D
idacticNet.cpp
+
15
−
7
View file @
5efedc7e
/**************************************************************************/
/*!
@file
d
idacticNet.cpp
@file
D
idacticNet.cpp
@author anian buehler @ letsgoING.org
*/
/**************************************************************************/
#include
"Arduino.h"
#include
"
d
idacticNet.h"
#include
"
D
idacticNet.h"
//**************************************************************************
//ROOT
...
...
@@ -43,13 +43,15 @@ bool DidacticPSNet::handleNetwork(){
handleData
();
}
}
_waitingTime
=
millis
()
+
random
(
CSMA_MIN_DELAY_MS
,
CSMA_MAX_DELAY_MS
);
_waitingTime
CSMA
=
millis
()
+
random
(
CSMA_MIN_DELAY_MS
,
CSMA_MAX_DELAY_MS
);
}
//else if(_dataToSend){
if
(
_dataToSend
&&
_waitingTime
<=
millis
()){
if
(
_dataToSend
&&
_waitingTime
Send
<=
millis
()
&&
_waitingTimeCSMA
<=
millis
()){
//send data to network
//TODO: test added CSMA_CHECKDELAY + 2nd checkData()
delayMicroseconds
(
CSMA_CHECK_DELAY_US
);
unsigned
long
delayStartTime
=
micros
();
while
(
micros
()
<
delayStartTime
+
CSMA_CHECK_DELAY_US
);
//delayMicroseconds(CSMA_CHECK_DELAY_US); //removed: blocking SoftSerial-interrupts
if
(
!
checkData
()){
if
(
!
sendData
()){
return
false
;
...
...
@@ -57,7 +59,7 @@ bool DidacticPSNet::handleNetwork(){
else
{
_dataToSend
=
false
;
//_waitingTime = millis()+ random(CSMA_MID_DELAY_MS, CSMA_MAX_DELAY_MS);
_waitingTime
=
millis
()
+
_intervalTime
;
//random(CSMA_MID_DELAY_MS, CSMA_MAX_DELAY_MS);
_waitingTime
Send
=
millis
()
+
_intervalTime
;
//random(CSMA_MID_DELAY_MS, CSMA_MAX_DELAY_MS);
}
}
}
...
...
@@ -299,7 +301,13 @@ bool DidacticPSNetClient::handleData(){
payloadLength
=
extractData
(
topicLength
+
3
,
MAX_LEN_PAYLOAD
,
_bufferPayload
,
MSG_DELIMITER
);
if
(
currentTopicNr
>=
0
){
savePayload
(
_bufferPayload
,
currentTopicNr
);
callback
(
_topic
[
currentTopicNr
],
topicLength
,
_payload
[
currentTopicNr
],
payloadLength
);
//callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength);
#ifdef CALLBACK_W_LENGTH
callback
(
_bufferTopic
,
topicLength
,
_bufferPayload
,
payloadLength
);
#else
callback
(
_bufferTopic
,
_bufferPayload
);
#endif
}
}
return
true
;
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/com/ardublock/libraries/
d
idacticNet.h
→
src/main/resources/com/ardublock/libraries/
D
idacticNet.h
+
18
−
9
View file @
5efedc7e
/**************************************************************************
@file
d
idacticNet.h
@file
D
idacticNet.h
@author anian buehler @ letsgoING
**************************************************************************/
...
...
@@ -8,8 +8,14 @@
#define _DIDACTICNET_
#include
"Arduino.h"
//callback(topic, topicLength, data, dataLength)
#define PSNET_CALLBACK_SIGNATURE void (*callback)(char*, int, char*, int)
#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 MSG_PRELIMITER '<'
#define MSG_DELIMITER '>'
...
...
@@ -18,10 +24,10 @@
//@ 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 MSG_PUBLISH '@'
#define MSG_SUBSCRIBE '?'
#define MSG_UPDATE '#'
#define MSG_TOPIC_MULTI
'*'
#define MSG_PUBLISH
'@'
#define MSG_SUBSCRIBE
'?'
#define MSG_UPDATE
'#'
#define MSG_TOPIC_MULTI '*'
//<@topic|payload>
#define LEN_OVERHEAD 4
...
...
@@ -34,7 +40,7 @@
#define INTERVAL_CLIENT 500L
#define INTERVAL_BROKER 0L
#define MAX_NR_TOPICS_CLIENT
5
#define MAX_NR_TOPICS_CLIENT
10
#define MAX_NR_TOPICS_BROKER 20
#define MAX_LEN_TOPICS 10
#define MAX_LEN_PAYLOAD 20
...
...
@@ -110,12 +116,14 @@ class DidacticPSNet
char
_sendBufferMessage
[
MAX_LEN_TOPICS
+
MAX_LEN_PAYLOAD
+
LEN_OVERHEAD
+
1
];
bool
_dataToSend
=
false
;
// int Data to send for queue?
unsigned
long
_waitingTime
=
0L
;
unsigned
long
_waitingTimeSend
=
0L
;
unsigned
long
_waitingTimeCSMA
=
0L
;
unsigned
long
_intervalTime
=
0L
;
int
_currentTopicLength
=
0
;
int
_currentPayloadLength
=
0
;
DidacticPSNet
&
setCallback
(
PSNET_CALLBACK_SIGNATURE
);
void
setStream
(
Stream
&
_port
);
int
checkData
();
...
...
@@ -135,6 +143,7 @@ class DidacticPSNet
void
begin
(
Stream
&
_port
);
void
begin
(
Stream
&
_port
,
PSNET_CALLBACK_SIGNATURE
);
bool
handleNetwork
();
bool
isDataToSend
();
...
...
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