Commit 91bc991c authored by fmg005's avatar fmg005

Bug fixes and modified a few methods

parent c00a3922
......@@ -9,25 +9,36 @@ my_serial, CLA::LOGGER* logger):m_serial(my_serial), m_logger(logger) {
HardwareSimulator::HardwareSimulator(serial::Serial*
my_serial, CLA::LOGGER* logger, CLA::Environment* env):m_serial(my_serial), m_logger(logger), m_env(env) {
nextUpdateTime = 0;
respondToData = &HardwareSimulator::updateIBP;
respondToData = &HardwareSimulator::SetInitialIBP;
}
void HardwareSimulator::update(std::unique_ptr<PhysiologyEngine>& engine) {
systolic_pressure =
engine->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg);
((this)->*respondToData)(engine);
}
void HardwareSimulator::SetInitialIBP(std::unique_ptr<PhysiologyEngine>& engine) {
systolic_pressure = engine->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg);
diastolic_pressure = engine->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg);
((this)->*respondToData)(systolic_pressure, diastolic_pressure);
SetIBP(1, systolic_pressure, diastolic_pressure);
nextUpdateTime = m_env->time_index + DELAY_5_SECONDS;
//cout<< engine->GetSimulationTime(TimeUnit::s)<<endl;
respondToData = &HardwareSimulator::updateIBP;
}
void HardwareSimulator::updateIBP(double syst, double diast) {
void HardwareSimulator::updateIBP(std::unique_ptr<PhysiologyEngine>& engine) {
if(m_env->time_index == nextUpdateTime) {
SetIBP(1, syst, diast);
nextUpdateTime += DELAY_5_SECONDS;
systolic_pressure = engine->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg);
diastolic_pressure = engine->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg);
SetIBP(1, systolic_pressure, diastolic_pressure);
nextUpdateTime = m_env->time_index + DELAY_5_SECONDS;
//cout<< engine->GetSimulationTime(TimeUnit::s)<<endl;
respondToData = &HardwareSimulator::updateIBP;
}
}
void HardwareSimulator::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const char* file_path) {
void HardwareSimulator::LoadConfig(const char* file_path) {
try {
cfg.readFile(file_path); // Read configration file
}
......@@ -37,9 +48,9 @@ void HardwareSimulator::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, co
catch(const ParseException &pex) {
m_logger->error("Error parsing configuration file");
}
double time_step = engine->GetTimeStep(TimeUnit::s);
DELAY_5_SECONDS = cfg.lookup("prosim.delay_5_sec");
DELAY_5_SECONDS = DELAY_5_SECONDS/time_step; // 5 seconds delay
DELAY_5_SECONDS = DELAY_5_SECONDS/m_env->engine_timestep; // 5 seconds delay
}
bool HardwareSimulator::isOpen() {
......@@ -92,7 +103,9 @@ void HardwareSimulator::SetOxygenSat(double rate) {
}
/* IBP range: 0-300 */
void HardwareSimulator::SetIBP(int channel, double syst, double diast ) {
void HardwareSimulator::SetIBP(int channel, double systolic_p, double diastolic_p ) {
int syst = static_cast<int>(systolic_p);
int diast = static_cast<int>(diastolic_p);
string s_syst = to_string(syst);
string s_diast = to_string(diast);
string s_channel = to_string(channel);
......
......@@ -13,7 +13,7 @@ int main() {
/*serial instance arguments*/
std::string port = "/dev/ttySB0"; // arbitrary port
std::string port = "/dev/ttyUSB0"; // arbitrary port
uint32_t baudrate = 115200;
serial::Timeout timeout = serial::Timeout();
serial::bytesize_t bytesize = serial::eightbits;
......
......@@ -47,10 +47,11 @@ public:
void SetRemoteMode();
void SetLocalMode();
string GetCurrentMode();
void updateIBP(double, double);
void (HardwareSimulator::*respondToData)(double, double);
void updateIBP(std::unique_ptr<PhysiologyEngine>&);
void SetInitialIBP(std::unique_ptr<PhysiologyEngine>&);
void (HardwareSimulator::*respondToData)(std::unique_ptr<PhysiologyEngine>&);
void update(std::unique_ptr<PhysiologyEngine>&);
void LoadConfig(std::unique_ptr<PhysiologyEngine>&, const char*);
void LoadConfig(const char*);
};
#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