Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fmg005
clasim
Commits
31991328
Commit
31991328
authored
Mar 14, 2018
by
fmg005
Browse files
Removing hardcoded configuration paths 2
parent
2f85d4c2
Changes
8
Hide whitespace changes
Inline
Side-by-side
simsrc/mcps2018/algo1/Controller.cpp
View file @
31991328
...
...
@@ -54,31 +54,13 @@ void Controller::update(std::unique_ptr<PhysiologyEngine>& engine) {
};
// End Controller update()
void
Controller
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
char
*
file_path
)
{
void
Controller
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
)
{
try
{
// Read configration file
cfg
.
readFile
(
file_path
);
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file."
<<
std
::
endl
;
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
// Extract the rate and assign it to m_rate_Hz
controller_rate_Hz
=
cf
g
.
lookup
(
"controller.rate"
);
controller_rate_Hz
=
cf
->
lookup
(
"controller.rate"
);
Setting
&
root
=
cf
g
.
getRoot
();
Setting
&
root
=
cf
->
getRoot
();
Setting
&
enabled
=
root
[
"controller"
][
"patientData"
][
"enabled"
];
...
...
@@ -105,8 +87,8 @@ void Controller::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const cha
time_step
=
engine
->
GetTimeStep
(
TimeUnit
::
s
);
//MAX_RATE_Hz = 1/time_step;
WAIT_10_MIN
=
cf
g
.
lookup
(
"controller.algorithm.wait_10"
);
WAIT_5_MIN
=
cf
g
.
lookup
(
"controller.algorithm.wait_5"
);
WAIT_10_MIN
=
cf
->
lookup
(
"controller.algorithm.wait_10"
);
WAIT_5_MIN
=
cf
->
lookup
(
"controller.algorithm.wait_5"
);
WAIT_10_MIN
=
(
60
*
WAIT_10_MIN
)
/
time_step
;
// 10 min
WAIT_5_MIN
=
(
60
*
WAIT_5_MIN
)
/
time_step
;
// 5 min
...
...
simsrc/mcps2018/algo1/Monitor.cpp
View file @
31991328
...
...
@@ -66,26 +66,10 @@ void Monitor::update(std::unique_ptr<PhysiologyEngine>& engine) {
}
void
Monitor
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
char
*
file_path
)
{
void
Monitor
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
)
{
try
{
// Read configration file
m_cfg
.
readFile
(
file_path
);
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file."
<<
std
::
endl
;
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
// Grab the monitor rates from config file
m_rate_Hz
=
m_cfg
.
lookup
(
"monitor.input_rate"
);
output_rate_Hz
=
m_cfg
.
lookup
(
"monitor.output_rate"
);
m_rate_Hz
=
cf
->
lookup
(
"monitor.input_rate"
);
output_rate_Hz
=
cf
->
lookup
(
"monitor.output_rate"
);
// Get engine time step/period
time_step
=
engine
->
GetTimeStep
(
TimeUnit
::
s
);
...
...
simsrc/mcps2018/algo1/Pump.cpp
View file @
31991328
...
...
@@ -61,26 +61,13 @@ void Pump::update(std::unique_ptr<PhysiologyEngine>& engine) {
}
void
Pump
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
char
*
file_path
)
{
void
Pump
::
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
)
{
try
{
// Read configration file
m_cfg
.
readFile
(
file_path
);
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file."
<<
std
::
endl
;
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
// Grab pump settings from config file
pump_rate_Hz
=
m_cfg
.
lookup
(
"pump.rate"
);
pump_delay
=
m_cfg
.
lookup
(
"pump.delay"
);
pump_rate_Hz
=
cf
->
lookup
(
"pump.rate"
);
pump_delay
=
cf
->
lookup
(
"pump.delay"
);
// Probably make these global
...
...
simsrc/mcps2018/algo1/SimEngine.cpp
View file @
31991328
...
...
@@ -50,8 +50,11 @@
using
namespace
libconfig
;
int
main
(
int
argc
,
const
char
*
argv
[]){
if
(
argc
<
2
)
int
main
(
int
argc
,
char
*
argv
[]){
string
f_path
=
argv
[
1
];
const
char
*
filepath
=
f_path
.
c_str
();
if
(
argc
<
2
)
{
cout
<<
"Error: must provide a configuration file
\n
"
;
cout
<<
"Usage: ./clasim configfile
\n
"
;
...
...
@@ -65,7 +68,7 @@ int main(int argc, const char * argv[]){
try
{
cf
->
readFile
(
argv
[
1
]
);
cf
->
readFile
(
filepath
);
}
catch
(
const
FileIOException
&
fioex
)
{
...
...
@@ -141,24 +144,24 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cf)
//Iintialize Pump
Pump
pump_saline
(
&
sim_env
,
&
data
,
"Saline"
);
pump_saline
.
LoadConfig
(
pe
,
f
name
);
pump_saline
.
LoadConfig
(
pe
,
c
f
);
Pump
pump_bpdrug
(
&
sim_env
,
&
data
,
"Norepinephrine"
);
pump_bpdrug
.
LoadConfig
(
pe
,
f
name
);
pump_bpdrug
.
LoadConfig
(
pe
,
c
f
);
pumps
.
insert
(
make_pair
(
"saline"
,
&
pump_saline
));
pumps
.
insert
(
make_pair
(
"bpdrug"
,
&
pump_bpdrug
));
//Initialize Controller
Controller
controller
(
&
sim_env
,
&
data
,
pumps
);
controller
.
LoadConfig
(
pe
,
f
name
);
controller
.
LoadConfig
(
pe
,
c
f
);
//Initialize Monitor
Monitor
monitor
(
&
sim_env
,
&
data
);
// Call this member function before 'update member function'
// to load new rate value from the config file
monitor
.
LoadConfig
(
pe
,
f
name
);
monitor
.
LoadConfig
(
pe
,
c
f
);
//logger
...
...
@@ -242,20 +245,6 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cf)
void
Global_LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
,
CMD
::
Environment
*
env
)
{
/* read the configuration file */
try
{
cf
->
readFile
(
file_path
);
// Read configration file
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file."
<<
file_path
<<
std
::
endl
;
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
/* get the simulation run time */
try
...
...
simsrc/mcps2018/include/Controller.h
View file @
31991328
...
...
@@ -121,7 +121,7 @@ class Controller {
// Load the configuration file to capture controller rate
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
char
*
);
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
std
::
shared_ptr
<
Config
>&
);
static
void
SendValues
(
PhysiologyData
&
);
...
...
simsrc/mcps2018/include/Monitor.h
View file @
31991328
...
...
@@ -56,7 +56,7 @@ class Monitor : public MedicalDevice {
virtual
void
update
(
std
::
unique_ptr
<
PhysiologyEngine
>&
);
// Load the configuration file to capture device rate
virtual
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
char
*
);
virtual
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
std
::
shared_ptr
<
Config
>&
);
// Method to transfer physiological data to Controller
void
SendData
(
PhysiologyData
&
);
...
...
simsrc/mcps2018/include/Pump.h
View file @
31991328
...
...
@@ -74,7 +74,7 @@ class Pump : public MedicalDevice {
virtual
void
update
(
std
::
unique_ptr
<
PhysiologyEngine
>&
);
// Load all pump configurations
virtual
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
char
*
);
virtual
void
LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
std
::
shared_ptr
<
Config
>&
);
void
SetInfusionRate
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
double
);
...
...
simsrc/mcps2018/include/SimEngine.h
View file @
31991328
...
...
@@ -3,10 +3,11 @@
#define SIMENGINE_H
#include
<string>
void
Simulation
(
const
std
::
string
);
void
Simulation
(
const
std
::
string
,
const
std
::
shared_ptr
<
Config
>&
cf
);
void
Global_LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
std
::
shared_ptr
<
Config
>&
,
const
char
*
,
CMD
::
Environment
*
);
void
Global_LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
const
std
::
shared_ptr
<
Config
>&
,
CMD
::
Environment
*
);
vector
<
string
>
get_global_patients
(
const
char
*
,
const
std
::
shared_ptr
<
Config
>&
);
vector
<
string
>
get_global_patients
(
const
std
::
shared_ptr
<
Config
>&
);
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment