Commit cd801ba0 authored by fmg005's avatar fmg005

Run simulated monitor and prosim independently

parent 31a9398c
......@@ -2,35 +2,29 @@
#include <string>
#include <map>
#include <memory>
#include <libconfig.h++>
#include "serial/serial.h"
#include "HardwareSimulator.h"
#include "SimMonitor.h"
#include "Prosim.h"
#include "CLA_Logger.h"
#include "SimulationEngine.h"
#include "Timer.h"
#include "Pump.h"
// Include the various Pulse types you will be using in your code
//types Pulse types will be using
#include "scenario/SEDataRequestManager.h"
#include "patient/actions/SEHemorrhage.h"
#include "patient/actions/SESubstanceCompoundInfusion.h"
#include "system/physiology/SEBloodChemistrySystem.h"
#include "system/physiology/SECardiovascularSystem.h"
#include "system/physiology/SEEnergySystem.h"
#include "system/physiology/SERespiratorySystem.h"
#include "substance/SESubstanceManager.h"
#include "substance/SESubstanceCompound.h"
#include "properties/SEScalar0To1.h"
#include "properties/SEScalarFrequency.h"
#include "properties/SEScalarMass.h"
#include "properties/SEScalarMassPerVolume.h"
#include "properties/SEScalarPressure.h"
#include "properties/SEScalarTemperature.h"
#include "properties/SEScalarTime.h"
#include "properties/SEScalarVolume.h"
#include "properties/SEScalarVolumePerTime.h"
#include "engine/SEEngineTracker.h"
#include "compartment/SECompartmentManager.h"
using namespace libconfig;
int main() {
CLA::Timer timer; /* time how long the simulation takes to run*/
......@@ -81,46 +75,23 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg)
std::shared_ptr<CLA::LOGGER> logger = std::make_shared<CLA::LOGGER>(patient_name,patient_name);
//logger->setLevel("INFO");/*DEFAULT: DEBUG */
Global_LoadConfig(logger, pe, cfg, sim_env);
/*serial instance arguments*/
std::string port = "/dev/ttyACM0"; // arbitrary port
uint32_t baudrate = 115200;
serial::Timeout timeout = serial::Timeout();
serial::bytesize_t bytesize = serial::eightbits;
serial::parity_t parity = serial::parity_none;
serial::stopbits_t stopbits = serial::stopbits_one;
serial::flowcontrol_t flowcontrol = serial::flowcontrol_hardware;
/*end serial instance arguments*/
serial::Serial myserial(port, baudrate, timeout, bytesize, parity, stopbits, flowcontrol);
std::map<std::string, CLA::Pump*> my_pumps; /* pumps */
/* Params: drug name, pump topic to subscribe to, type of data published on that topic*/
CLA::Pump bpdrug_pump(logger, "Norepinephrine", "/bpdrug_pumpout", "std_msgs/Float64");
CLA::Pump saline_pump(logger, "Saline", "/saline_pumpout", "std_msgs/Float64");
my_pumps["bpdrug"] = &bpdrug_pump;
my_pumps["saline"] = &saline_pump;
/* prosim hardware */
HardwareSimulator prosim(logger, &myserial, sim_env, my_pumps);
prosim.LoadConfig(pe);
/*handle keyboard interrupt*/
interrupt_handler = [&logger, &prosim](int sig) {
logger->error("Keyboard interruption, simulation exited");
prosim.SetLocalMode();
exit(EXIT_FAILURE);
};
struct sigaction act;
/*set handler in act struct*/
act.sa_handler = [](int sig){ interrupt_handler(sig);};
/* set the sa_mask to empty
* i.e.no signal will be blocked while handler is running.
*/
sigemptyset(&act.sa_mask);
/* make sure there are no flags bits set*/
act.sa_flags = 0;
/* process the SIGINT->keyboard when it occurs */
sigaction(SIGINT, &act, 0);
/* end handle keyboard interrupt */
/* simulated monitor */
SimMonitor sim_monitor(logger, sim_env, my_pumps);
sim_monitor.LoadConfig(pe);
/* prosim hardware */
//Prosim prosim(logger, sim_env, my_pumps);
//prosim.LoadConfig(pe);
//prosim.SetRemoteMode(); /* switch remote mode */
prosim.SetRemoteMode(); /* switch remote mode */
// stop when the set time is reached
while (sim_env.time_index <= sim_env.simulation_timesteps ) {
currentMAP = pe->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg);
......@@ -152,7 +123,7 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg)
}
/* We both track data and advance engine inside the update method */
if (START_DEVICES) {
prosim.update(pe);
sim_monitor.update(pe);
}
/* This stops running once realtime starts */
if (!START_DEVICES) {
......@@ -209,6 +180,20 @@ engine, const std::shared_ptr<Config>& cf, CLA::Environment& env) {
logger->error("Setting Not Found: prosim.real_time");
exit(EXIT_FAILURE);
}
try {
env.port = cf->lookup("prosim.port");
}
catch(const SettingNotFoundException) {
logger->error("Setting Not Found: prosim.port");
exit(EXIT_FAILURE);
}
try {
env.baudrate = cf->lookup("prosim.baudrate");
}
catch(const SettingNotFoundException) {
logger->error("Setting Not Found: prosim.baudrate");
exit(EXIT_FAILURE);
}
env.time_index = 0; // initialize the time index
env.engine_timestep = engine->GetTimeStep(TimeUnit::s);
env.simulation_timesteps = env.simulation_time/env.engine_timestep;
......
......@@ -43,6 +43,7 @@ set(libconfig++_INCLUDE_DIR ${install_dir}/include)
#prosim depends on pulse this will call will give you access to pulse directories
#needed by prosim
find_package(Pulse REQUIRED NO_MODULE)
add_subdirectory(lib)
set(PROSIM_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources/)
set(PROSIM_RESULTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/results/)
......@@ -67,23 +68,29 @@ set( my_srcs
Pump.cpp
tcp_monitor_client.cpp
Monitor.cpp
SimMonitor.cpp
PatientOut.cpp
)
find_library(PROSIM_LIB libprosim PATHS "${CMAKE_CURRENT_SOURCE_DIR}/lib")
add_executable(prosim ${my_srcs})
#include directories
target_include_directories(prosim PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/include
${serial_INCLUDE_DIR}
${serial_INCLUDE_DIR}
${Pulse_INCLUDE_DIRS}
${libconfig++_INCLUDE_DIR})
#libraries
target_link_libraries(prosim debug "${Pulse_DEBUG_LIBS}")
target_link_libraries(prosim optimized
${Pulse_LIBS}
libconfig++
libserial)
${Pulse_LIBS}
libconfig++
libserial
libprosim
${PROSIM_LIB})
install(TARGETS prosim DESTINATION ${Pulse_INSTALL}/bin)
#install(FILES ${Pulse_INSTALL}/bin/UCEDefs.txt DESITINATION ${CMAKE_CURRENT_SOURCE_DIR}/builds)
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