예제 #1
0
IceApp::sensorinfo_t 
IceApp::connectToSensor(const std::string &sensor_name) const
{
  Ice::PropertiesPtr props = this->communicator()->getProperties();
  Ice::LoggerPtr log = this->communicator()->getLogger();

  try
    {
      log->print(string("Connecting to ") + sensor_name + " sensor");
      const string prop_name = sensor_name + ".proxy";
      string sensor_str_proxy = props->getProperty(prop_name);
      sensors::SensorGroupPrx sensor_prx;
      if(sensor_str_proxy.empty())
	log->warning(prop_name 
		     + string(" property is not set. No ")
		     + sensor_name + ".");
      else
	{
	  Ice::ObjectPrx objprx = 
	    this->communicator()->stringToProxy(sensor_str_proxy);
	  sensor_prx = sensors::SensorGroupPrx::checkedCast(objprx);
	  if(!sensor_prx)
	    log->warning(string("Can not connect to ")
			 + sensor_name 
			 + string(" sensor. No ")
			 + sensor_name + ".");
	  else
	    {
	      string msg = "Connected to sensor group ";
	      log->print(msg + sensor_name);
	      sensors::SensorDescriptionSeq descr = 
		sensor_prx->getSensorDescription();
	      for(sensors::SensorDescriptionSeq::const_iterator d = descr.begin();
		  d != descr.end(); ++d)
		{
		  ostringstream os;
		  os << "  Vendor id: " << d->vendorid << endl;
		  os << "  Description: " << d->description << endl;
		  os << "  Id: " << d->id << endl;
		  os << "  Min value: " << d->minvalue << endl;
		  os << "  Max value: " << d->maxvalue << endl;
		  os << "  Recommended refresh rate, Hz: " << d->refreshrate;
		  log->print(os.str());
		}
	      return make_pair(sensor_prx, descr);
	    }
	}
    }
  catch(const Ice::Exception& ex)
    {
      ostringstream os;
      os << "Can not connect to " << sensor_name << " sensor. No "
	 << sensor_name + ".\n";
      ex.ice_print(os);
      log->warning(os.str());
    }

  return make_pair(sensors::SensorGroupPrx(), 
		   sensors::SensorDescriptionSeq());
}
예제 #2
0
IceApp::actuatorinfo_t 
IceApp::connectToActuator(const std::string &actuator_name) const
{
  Ice::PropertiesPtr props = this->communicator()->getProperties();
  Ice::LoggerPtr log = this->communicator()->getLogger();

  try
    {
      log->print(string("Connecting to ") + actuator_name + " actuators");
      const string prop_name = actuator_name + ".proxy";
      string actuator_str_proxy = props->getProperty(prop_name);
      actuators::ActuatorGroupPrx actuator_prx;
      if(actuator_str_proxy.empty())
	log->warning(prop_name 
		     + string(" property is not set. No ")
		     + actuator_name + ".");
      else
	{
	  Ice::ObjectPrx objprx = 
	    this->communicator()->stringToProxy(actuator_str_proxy);
	  actuator_prx = 
	    actuators::ActuatorGroupPrx::checkedCast(objprx);
	  if(!actuator_prx)
	    log->warning(string("Can not connect to ")
			 + actuator_name 
			 + string(" actuator. No ")
			 + actuator_name + ".");
	  else
	    {
	      string msg = "Connected to actuator group ";
	      log->print(msg + actuator_name);
	      actuators::ActuatorDescriptionSeq descr = 
		actuator_prx->getActuatorDescription();
	      for(actuators::ActuatorDescriptionSeq::const_iterator d = descr.begin();
		  d != descr.end(); ++d)
		{
		  ostringstream os;
		  os << "  Vendor id: " << d->vendorid << endl;
		  os << "  Description: " << d->description << endl;
		  os << "  Id: " << d->id << endl;
		  log->print(os.str());
		}
	      return make_pair(actuator_prx, descr);
	    }
	}
    }
  catch(const Ice::Exception &ex)
    {
      std::ostringstream os;
      os << "Can not connect to actuator " + actuator_name + ".\n";
      ex.ice_print(os);
      log->warning(os.str());
    }

  return make_pair(actuators::ActuatorGroupPrx(), 
		   actuators::ActuatorDescriptionSeq());
}