Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CoincellExperimentController
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
CoincellExperimentController
Commits
2123696e
Commit
2123696e
authored
1 year ago
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
Add a timeout to biocontrol waiting, and retry if biocontrol fails
parent
56bdb82a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
biocontrol.cpp
+30
-13
30 additions, 13 deletions
biocontrol.cpp
biocontrol.h
+4
-4
4 additions, 4 deletions
biocontrol.h
with
34 additions
and
17 deletions
biocontrol.cpp
+
30
−
13
View file @
2123696e
#include
"biocontrol.h"
#include
<chrono>
#include
<string>
#include
<thread>
#include
<unistd.h>
#include
<errno.h>
#include
<stdexcept>
...
...
@@ -11,6 +13,7 @@
#include
<errno.h>
#include
<sstream>
#include
<fstream>
#include
<signal.h>
#include
"log.h"
...
...
@@ -52,6 +55,11 @@ void BioControl::execBiocontrol(const std::string& command, const std::string& u
{
int
biopipe
=
open
(
biopipefilename
,
O_RDONLY
|
O_CLOEXEC
);
if
(
biopipe
<
0
)
{
kill
(
childPid
,
SIGTERM
);
throw
std
::
runtime_error
(
std
::
string
(
__func__
)
+
": unable to open pipe: "
+
std
::
string
(
strerror
(
errno
)));
}
if
(
biopipe
>=
0
)
{
...
...
@@ -65,21 +73,29 @@ void BioControl::execBiocontrol(const std::string& command, const std::string& u
Log
(
Log
::
DEBUG
)
<<
"Wating for biocontrol to exit"
;
int
exitCode
;
waitpid
(
childPid
,
&
exitCode
,
0
);
int
timeout
=
7200
*
2
;
ret
=
0
;
while
((
ret
=
waitpid
(
childPid
,
&
exitCode
,
WNOHANG
))
==
0
&&
--
timeout
>
0
)
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
500
));
if
(
ret
==
0
)
{
kill
(
childPid
,
SIGKILL
);
throw
std
::
runtime_error
(
std
::
string
(
__func__
)
+
": biocontol has hanged"
);
}
if
(
exitCode
!=
0
)
{
close
(
biopipe
);
throw
std
::
runtime_error
(
std
::
string
(
__func__
)
+
": biocontol failed with: "
+
std
::
to_string
(
exitCode
));
}
if
(
biopipe
<
0
)
throw
std
::
runtime_error
(
std
::
string
(
__func__
)
+
": unable to open pipe: "
+
std
::
string
(
strerror
(
errno
)));
}
}
bool
BioControl
::
measure_eis
(
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
)
bool
BioControl
::
measure_eis
(
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
)
{
std
::
string
mesurement
;
try
{
execBiocontrol
(
"geis"
,
userstr
,
mesurement
);
...
...
@@ -87,7 +103,8 @@ bool BioControl::measure_eis(const std::filesystem::path& outPath, const std::st
catch
(
const
std
::
runtime_error
&
err
)
{
Log
(
Log
::
ERROR
)
<<
err
.
what
();
return
false
;
return
retry
?
measure_eis
(
outPath
,
userstr
,
false
)
:
false
;
}
std
::
fstream
file
(
outPath
,
std
::
ios_base
::
out
);
...
...
@@ -103,7 +120,7 @@ bool BioControl::measure_eis(const std::filesystem::path& outPath, const std::st
return
true
;
}
bool
BioControl
::
measure_ocv
(
float
&
ocv
)
bool
BioControl
::
measure_ocv
(
float
&
ocv
,
bool
retry
)
{
std
::
string
mesurement
;
try
...
...
@@ -114,12 +131,12 @@ bool BioControl::measure_ocv(float& ocv)
catch
(
const
std
::
runtime_error
&
err
)
{
Log
(
Log
::
ERROR
)
<<
err
.
what
();
return
false
;
return
retry
?
measure_ocv
(
ocv
,
false
)
:
false
;
}
catch
(
const
std
::
invalid_argument
&
err
)
{
Log
(
Log
::
ERROR
)
<<
"Could not convert "
<<
mesurement
<<
": "
<<
err
.
what
();
return
false
;
return
retry
?
measure_ocv
(
ocv
,
false
)
:
false
;
}
return
true
;
...
...
@@ -132,12 +149,12 @@ bool BioControl::shorted(bool& shorted)
return
true
;
}
bool
BioControl
::
charge
(
float
fraction
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
)
bool
BioControl
::
charge
(
float
fraction
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
)
{
return
chargeToVoltage
(
3.1
+
fraction
*
(
4.2
-
3.1
),
current
,
outPath
,
userstr
);
return
chargeToVoltage
(
3.1
+
fraction
*
(
4.2
-
3.1
),
current
,
outPath
,
userstr
,
retry
);
}
bool
BioControl
::
chargeToVoltage
(
float
voltage
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
)
bool
BioControl
::
chargeToVoltage
(
float
voltage
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
)
{
float
ocv
;
bool
ret
=
measure_ocv
(
ocv
);
...
...
@@ -163,7 +180,7 @@ bool BioControl::chargeToVoltage(float voltage, float current, const std::filesy
catch
(
const
std
::
runtime_error
&
err
)
{
Log
(
Log
::
ERROR
)
<<
err
.
what
();
return
false
;
return
retry
?
chargeToVoltage
(
voltage
,
current
,
outPath
,
userstr
,
false
)
:
false
;
}
std
::
fstream
file
(
outPath
,
std
::
ios_base
::
out
);
...
...
This diff is collapsed.
Click to expand it.
biocontrol.h
+
4
−
4
View file @
2123696e
...
...
@@ -16,9 +16,9 @@ public:
BioControl
()
=
default
;
BioControl
(
const
std
::
filesystem
::
path
&
exepath
,
const
std
::
string
&
ipAddr
);
bool
measure_eis
(
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
);
bool
measure_ocv
(
float
&
ocv
);
bool
measure_eis
(
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
=
true
);
bool
measure_ocv
(
float
&
ocv
,
bool
retry
=
true
);
bool
shorted
(
bool
&
shorted
);
bool
charge
(
float
fraction
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
);
bool
chargeToVoltage
(
float
voltage
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
);
bool
charge
(
float
fraction
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
=
true
);
bool
chargeToVoltage
(
float
voltage
,
float
current
,
const
std
::
filesystem
::
path
&
outPath
,
const
std
::
string
&
userstr
,
bool
retry
=
true
);
};
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