Commit 6a6a9a47 authored by fmg005's avatar fmg005

Bug fixes

parent 7f693f54
......@@ -19,13 +19,14 @@ void HardwareSimulator::update(std::unique_ptr<PhysiologyEngine>& engine) {
m_start = system_clock::now();
engine->AdvanceModelTime(advance_time, TimeUnit::s);
m_end = system_clock::now();
m_command_start = system_clock::now();
systolic_pressure = engine->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg);
diastolic_pressure = engine->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg);
double hr = engine->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min);
heart_rate = engine->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min);
/* send patient data to monitor */
SetIBP(1, systolic_pressure, diastolic_pressure);
SetHeartRate(hr);
SetHeartRate(heart_rate);
m_command_end = system_clock::now();
/* start time for the next execution */
......@@ -42,10 +43,10 @@ void HardwareSimulator::update(std::unique_ptr<PhysiologyEngine>& engine) {
/* wait until start time of next execution is reached i.e., time:s of real-time */
while(true) {
m_delta = m_real_time - system_clock::to_time_t(system_clock::now());
if (m_delta <= 0)
break;
std::this_thread::sleep_for(milliseconds(m_delta));
m_delta = m_real_time - system_clock::to_time_t(system_clock::now());
if (m_delta <= 0)
break;
std::this_thread::sleep_for(milliseconds(m_delta));
}
/* track data */
engine->GetEngineTracker()->TrackData(engine->GetSimulationTime(TimeUnit::s));
......@@ -61,6 +62,7 @@ void HardwareSimulator::LoadConfig(const char* file_path) {
catch(const ParseException &pex) {
m_logger->error("Error parsing configuration file");
}
/* grab values from the configuration file */
advance_time = cfg.lookup("pulse.advance_time");
real_time = cfg.lookup("prosim.real_time");
}
......@@ -76,7 +78,7 @@ void HardwareSimulator::SetHeartRate(double rate) {
SendCommand("NSRA=0"+to_string(heart_rate));
m_logger->info("Heart rate set to "+to_string(heart_rate)+" bpm");
}
else if (rate > 100 ) {
else if (rate > 99 && rate <= 360) {
SendCommand("NSRA="+to_string(heart_rate));
m_logger->info("Heart rate set to "+to_string(heart_rate)+" bpm");
}
......@@ -87,10 +89,14 @@ void HardwareSimulator::SetHeartRate(double rate) {
/* RR range: 10-150 */
void HardwareSimulator::SetRespRate(double rate) {
if (rate >= 10 && rate <= 150) {
if (rate >= 10 && rate < 100 ) {
SendCommand("RESPRATE=0"+std::to_string(rate));
m_logger->info("Respiratory rate set to "+to_string(rate)+"bprm");
}
else if(rate > 99 && rate <=150) {
SendCommand("RESPRATE="+std::to_string(rate));
m_logger->info("Respiratory rate set to "+to_string(rate)+"bprm");
}
else {
m_logger->warning("Respiratory rate value: "+to_string(rate)+" not within acceptable range 10-150");
}
......@@ -101,18 +107,16 @@ void HardwareSimulator::SetOxygenSat(double rate) {
int i_rate = rate - 1;
std::string s_rate = std::to_string(i_rate);
if (rate >= 0 && rate <= 100) {
if (rate < 10) {
s_rate = "0" + s_rate;
}
else if(rate > 99) {
SendCommand("SAT="+s_rate);
m_logger->info("Oxygen saturation set to " + to_string(rate));
}
else {
SendCommand("SAT=0"+s_rate);
m_logger->info("Oxygen saturation set to " + to_string(rate));
}
if (rate < 10) {
s_rate = "0" + s_rate;
}
else if(rate > 10 && rate < 100 ) {
SendCommand("SAT=0"+s_rate);
m_logger->info("Oxygen saturation set to " + to_string(rate));
}
else if(rate == 100 ) {
SendCommand("SAT="+s_rate);
m_logger->info("Oxygen saturation set to " + to_string(rate));
}
else {
m_logger->warning("Oxygen saturation value: "+to_string(rate)+" not within acceptable range 0-100");
......@@ -200,4 +204,7 @@ void HardwareSimulator::Clear() {
HardwareSimulator::~HardwareSimulator() {
SetLocalMode();// Switch back device to LOCAL mode when done
Clear();
delete m_serial;
delete m_logger;
delete m_env;
}
......@@ -4,14 +4,14 @@
#include <string>
#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <libconfig.h++>
#include "serial/serial.h"
#include "CLA_Logger.h"
#include "Environment.h"
/* Pulse stuff */
/* Pulse header files */
#include "CommonDataModel.h"
#include "PulsePhysiologyEngine.h"
#include "properties/SEScalarTime.h"
......@@ -35,6 +35,7 @@ private:
string GetResponse();
double systolic_pressure;
double diastolic_pressure;
double heart_rate;
double advance_time;
double real_time;
Config cfg; // API for accessing configuration files
......
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