X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/70d2e24643727ab1ea48e1793d609d27b7d21fed..cc77948bedbd851e009ad3b8a421dea93c3ceeff:/Model/src/pump.cpp diff --git a/Model/src/pump.cpp b/Model/src/pump.cpp index 086138f..93b8b72 100644 --- a/Model/src/pump.cpp +++ b/Model/src/pump.cpp @@ -4,35 +4,44 @@ using namespace PlaQui::Model; -Pump::Pump(const std::string &_name):Source(_name) +Pump::Pump(const std::string &_name):Source(_name),Control(_name) { in_slots = 0; out_slots = 1; active = true; open = true; max_flow = actual_flow = 0.0f; + input = new ByPass(); + output = new ByPass(); + ((ByPass *)output)->set_control(this); } Pump::~Pump() { + delete input; + delete output; } void Pump::update(int dir) { if (updated) return; + // Me fijo si me tengo que apagar automaticamente + open = input->get_output(); + std::cout << name << " open = " << (open?"true":"false") << std::endl; if (active && open) actual_flow = max_flow; else actual_flow = 0; - updated = true; + send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, (void *)&actual_flow); + updated = true; } void Pump::simulate() { - std::cout << name << "::Flujo actual = " << ((active && open)?actual_flow:0) \ - << " de " << max_flow; +#ifdef DEBUG std::cout << ((active && open)?" (funcionando)":" (apagada)") << std::endl; +#endif updated = false; } @@ -48,18 +57,9 @@ bool Pump::get_output() void Pump::recieve_msg(int msg, IConector *who, void *data) { switch (msg) { - case MSG_QUERY_MAX_FLOW_OUT: { - // Me preguntan por el flujo máximo. - // Primero me actualizo, y luego respondo - // TODO la bomba nunca deberia ser consultada,pues el flujo sale ella - /* update(); - float tmp; - tmp = (actual_flowrecieve_msg(MSG_RESPONSE_MAX_FLOW, this, &tmp);*/ - } - break; case MSG_RESPONSE_MAX_FLOW: { float tmp = *((float *)data); + if (max_flow < tmp) tmp = max_flow; if (tmp < actual_flow) actual_flow = tmp; } break; @@ -69,3 +69,14 @@ void Pump::recieve_msg(int msg, IConector *who, void *data) } +void Pump::get_state_as_xml(std::stringstream &out) +{ + // Saco el item basico por XML + PlantItem::get_state_as_xml(out); + + // Saco lo importante de este item + out << "\t" << std::endl; + out << "\t\t" << ((open&&active)?"true":"false") << "" << std::endl; + out << "\t" << std::endl; +} +