Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Temperature Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Pascal Engeler
RBComb Temperature Control
Commits
70bb59fb
Commit
70bb59fb
authored
1 year ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Added supervision checking
parent
f0172b24
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/drivers/communicator/communicator.cpp
+23
-2
23 additions, 2 deletions
firmware/drivers/communicator/communicator.cpp
firmware/drivers/communicator/communicator.hpp
+7
-0
7 additions, 0 deletions
firmware/drivers/communicator/communicator.hpp
with
30 additions
and
2 deletions
firmware/drivers/communicator/communicator.cpp
+
23
−
2
View file @
70bb59fb
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include
<pid_controller.hpp>
#include
<pid_controller.hpp>
#include
<cstdlib>
//std::strtod
#include
<cstdlib>
//std::strtod
#include
<algorithm>
//This is necessary to fix a bug that cost me 4h.
#include
<algorithm>
//This is necessary to fix a bug that cost me 4h.
#include
<Arduino.h>
/*
/*
As I tracked down, a (standard) string library calls std::min() in some functions (like compare).
As I tracked down, a (standard) string library calls std::min() in some functions (like compare).
...
@@ -14,16 +15,28 @@
...
@@ -14,16 +15,28 @@
Holy fucking shit.
Holy fucking shit.
*/
*/
unsigned
long
Communicator
::
timeout_us_
=
20000
;
//timeout 20ms
unsigned
long
Communicator
::
timeout_us_
=
20000
u
;
//timeout 20ms
char
Communicator
::
outbuf_
[
256
];
//out buffer
char
Communicator
::
outbuf_
[
256
];
//out buffer
char
Communicator
::
cmd_
=
'X'
;
//command received
char
Communicator
::
cmd_
=
'X'
;
//command received
std
::
vector
<
char
>
Communicator
::
arg_
=
std
::
vector
<
char
>
(
256
,
'\0'
);
//arguments received
std
::
vector
<
char
>
Communicator
::
arg_
=
std
::
vector
<
char
>
(
256
,
'\0'
);
//arguments received
unsigned
long
Communicator
::
last_transaction_ms_
=
0u
;
//time of last transaction
unsigned
long
Communicator
::
interval_assume_eow_ms_
=
1800000u
;
//no transaction for 30 minutes means we shut down
bool
Communicator
::
communicate
(){
bool
Communicator
::
communicate
(){
if
(
!
serialCharAvailable_
()){
if
(
!
serialCharAvailable_
()){
//no communication
if
(
msElapsedSinceLastTransaction_
()
>
interval_assume_eow_ms_
){
//no sign of supervision for 30 minutes, shut down
Pid_controller
::
turn_off
();
}
else
{
//have supervision, turn PID Controller on
Pid_controller
::
turn_on
();
}
return
false
;
return
false
;
}
}
else
{
else
{
startTransactionTimer_
();
Pid_controller
::
turn_on
();
//have supervision, make sure PID Controller is enabled
cmd_
=
getSerialChar_
();
cmd_
=
getSerialChar_
();
if
(
isSetCommand_
()){
if
(
isSetCommand_
()){
//read argument
//read argument
...
@@ -223,3 +236,11 @@ void Communicator::handleInvalidCommand_(){
...
@@ -223,3 +236,11 @@ void Communicator::handleInvalidCommand_(){
sendBuf_
();
sendBuf_
();
return
;
return
;
}
}
void
Communicator
::
startTransactionTimer_
(){
last_transaction_ms_
=
millis
();
}
unsigned
long
Communicator
::
msElapsedSinceLastTransaction_
(){
return
static_cast
<
unsigned
long
>
(
millis
()
-
last_transaction_ms_
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
firmware/drivers/communicator/communicator.hpp
+
7
−
0
View file @
70bb59fb
...
@@ -24,6 +24,9 @@ private:
...
@@ -24,6 +24,9 @@ private:
static
void
handleSetCommand_
();
static
void
handleSetCommand_
();
static
void
handleNopCommand_
();
static
void
handleNopCommand_
();
static
void
handleInvalidCommand_
();
static
void
handleInvalidCommand_
();
static
void
startTransactionTimer_
();
static
unsigned
long
msElapsedSinceLastTransaction_
();
/*Data Members*/
/*Data Members*/
...
@@ -31,6 +34,10 @@ private:
...
@@ -31,6 +34,10 @@ private:
static
char
outbuf_
[
256
];
static
char
outbuf_
[
256
];
static
char
cmd_
;
static
char
cmd_
;
static
std
::
vector
<
char
>
arg_
;
static
std
::
vector
<
char
>
arg_
;
//Note: The timer only works for timeouts that last shorter than 50 days
static
unsigned
long
last_transaction_ms_
;
static
unsigned
long
interval_assume_eow_ms_
;
};
};
#endif
#endif
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