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();
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;
}
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_flow<max_flow)?actual_flow:max_flow;
- who->recieve_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;
}
+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<pump name=\"" << name << "\">" << std::endl;
+ out << "\t\t<active>" << ((open&&active)?"true":"false") << "</active>" << std::endl;
+ out << "\t</pump>" << std::endl;
+}
+