Commit de102db9 authored by fmg005's avatar fmg005

publish systolic and diastolic to dummy /monitor

parent 82682699
......@@ -4,8 +4,7 @@ HardwareSimulator::HardwareSimulator( std::shared_ptr<CLA::LOGGER>& logger,
serial::Serial* my_serial,CLA::Environment& env, std::map<std::string, CLA::Pump*>&
pumps) : m_serial(my_serial), m_logger(logger), m_env(env),
m_pumps(pumps), m_action(logger, pumps) {
m_monitor = new CLA::Monitor(logger, "/monitor", "std_msgs/Float64");
m_monitor = new CLA::Monitor(logger, "/monitor", "std_msgs/String");
}
void HardwareSimulator::update(std::unique_ptr<PhysiologyEngine>& engine) {
......@@ -23,22 +22,23 @@ void HardwareSimulator::update(std::unique_ptr<PhysiologyEngine>& engine) {
heart_rate = engine->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min);
resp_rate = engine->GetRespiratorySystem()->GetRespirationRate(FrequencyUnit::Per_min);
oxygen_sat = engine->GetBloodChemistrySystem()->GetOxygenSaturation();
MAP = engine->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg);
/* send patient data to monitor */
SetIBP(1, systolic_pressure, diastolic_pressure);
SetHeartRate(heart_rate);
SetRespRate(resp_rate);
SetOxygenSat(oxygen_sat);
m_command_end = system_clock::now();
/*publish to dummy monitor topic for algorithm to capture */
m_monitor->send_patient_data(MAP);
/*publish to dummy monitor topic for algorithm to capture
* i.e. systolic/diastolic
*/
m_monitor->publish_patient_data(to_string(systolic_pressure)+"/" \
+to_string(diastolic_pressure));
/* perform infusions whenever the pump rate changes */
m_infusion_start = system_clock::now();
m_action.infuse_drug(engine);
m_infusion_end = system_clock::now();
m_infusion_end = system_clock::now();// end
/* start time for the next execution */
m_next_update_time = system_clock::to_time_t(m_start) + m_next_start_in.count();
......@@ -79,7 +79,7 @@ void HardwareSimulator::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine) {
advance_time = m_env.pulse_advance_time;
/* advance in realtime the `secs` rate*/
secs = m_env.prosim_advance_time;
m_next_start_in = duration<double>(secs); /* cast to duration seconds */
m_next_start_in = duration<double>(secs); /* convert to duration seconds */
/*intialize action -> prepare for infusions */
m_action.initialize(engine);
}
......
......@@ -13,8 +13,8 @@ string& type) : m_logger(logger), m_tcp_monitor_client(logger, topic, type) {
m_tcp_monitor_client.setup_connection(); /* connection setup to server via tcp socket */
}
void Monitor::send_patient_data (double data) {
m_tcp_monitor_client.send_patient_data(data);
void Monitor::publish_patient_data (const string& data) {
m_tcp_monitor_client.publish_patient_data(data);
}
Monitor::~Monitor() {
......
......@@ -45,7 +45,6 @@ class HardwareSimulator {
double heart_rate;
double resp_rate;
double oxygen_sat;
double MAP;
double advance_time;
double secs;
string mode;
......
......@@ -13,7 +13,7 @@ namespace CLA {
Monitor( std::shared_ptr<CLA::LOGGER>&);
Monitor( std::shared_ptr<CLA::LOGGER>&, const string&, const string&);
~Monitor();
void send_patient_data(double);
void publish_patient_data(const string&);
};
}
......
......@@ -40,6 +40,7 @@ namespace CLA {
int SOCKET_TIMEOUT_uSEC;
socklen_t addrlen;
Document document; /* to parse json data */
Value m_patient_data;
StringBuffer strbuf;
fd_set set; /* descriptor read set*/
std::shared_ptr<CLA::LOGGER> m_logger;
......@@ -48,8 +49,8 @@ namespace CLA {
tcp_monitor_client(std::shared_ptr<CLA::LOGGER>&, const string&, const string&);
~tcp_monitor_client();
void setup_connection();
void send_data_to_server(double);
void send_patient_data(double);
void send_data_to_server(const string&);
void publish_patient_data(const string&);
void waiting_to_send();
void clear();
};
......
......@@ -9,8 +9,8 @@ tcp_monitor_client::tcp_monitor_client(std::shared_ptr<CLA::LOGGER>& logger) : m
json_message = "{\"op\":\"advertise\", \"topic\":\"/monitor\", \"type\":\"std_msgs/Float64\"}";
m_host = "localhost"; /* rosbridge server runs on localhost */
port = 9090; /* rosbridge server uses this port number */
SOCKET_TIMEOUT_SEC = 1;
SOCKET_TIMEOUT_uSEC = 0;
SOCKET_TIMEOUT_SEC = 0;
SOCKET_TIMEOUT_uSEC = 5000000;
}
tcp_monitor_client::tcp_monitor_client(std::shared_ptr<CLA::LOGGER>& logger,
......@@ -19,8 +19,8 @@ m_logger(logger) {
json_message = "{\"op\":\"advertise\", \"topic\": \""+m_topic+"\", \"type\": \""+m_type+"\"}";
m_host = "localhost"; /* rosbridge server runs on localhost */
port = 9090; /* rosbridge server uses this port number */
SOCKET_TIMEOUT_SEC = 1;
SOCKET_TIMEOUT_uSEC = 0;
SOCKET_TIMEOUT_SEC = 0;
SOCKET_TIMEOUT_uSEC = 500000;
}
void tcp_monitor_client::setup_connection() {
......@@ -63,7 +63,7 @@ void tcp_monitor_client::setup_connection() {
m_logger->debug("Advertise request to "+m_topic+" sent to rosbridge server");
}
void tcp_monitor_client::send_patient_data(double p_data) {
void tcp_monitor_client::publish_patient_data(const string& p_data) {
timeout.tv_sec = SOCKET_TIMEOUT_SEC;
timeout.tv_usec = SOCKET_TIMEOUT_uSEC;
FD_ZERO(&set); /* initialize set */
......@@ -84,14 +84,15 @@ void tcp_monitor_client::send_patient_data(double p_data) {
}
}
void tcp_monitor_client::send_data_to_server(double p_data) {
void tcp_monitor_client::send_data_to_server(const string& p_data) {
/* rapidjson storing reference to string */
m_patient_data = StringRef(p_data.c_str(), strlen(p_data.c_str()));
document.SetObject();
Document::AllocatorType& allocator = document.GetAllocator();
Value object(kObjectType);
document.AddMember("op", "publish", allocator);
document.AddMember("topic", "/monitor", allocator);
object.AddMember("data", p_data, allocator);
object.AddMember("data", m_patient_data, allocator);
document.AddMember("msg", object, allocator);
Writer<StringBuffer> writer(strbuf);
......
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