Commit 31991328 authored by fmg005's avatar fmg005

Removing hardcoded configuration paths 2

parent 2f85d4c2
......@@ -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 = cfg.lookup("controller.rate");
controller_rate_Hz = cf->lookup("controller.rate");
Setting& root = cfg.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 = cfg.lookup("controller.algorithm.wait_10");
WAIT_5_MIN = cfg.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
......
......@@ -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);
......
......@@ -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
......
......@@ -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, fname);
pump_saline.LoadConfig(pe, cf);
Pump pump_bpdrug(&sim_env, &data, "Norepinephrine");
pump_bpdrug.LoadConfig(pe, fname);
pump_bpdrug.LoadConfig(pe, cf);
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, fname);
controller.LoadConfig(pe, cf);
//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, fname);
monitor.LoadConfig(pe, cf);
//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
......
......@@ -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&);
......
......@@ -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&);
......
......@@ -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);
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment