bool embObjVirtualAnalogSensor::open(yarp::os::Searchable &config) { std::string str; if(config.findGroup("GENERAL").find("verbose").asBool()) { str=config.toString().c_str(); _verbose = true; } else str=" "; yTrace() << str; // Read stuff from config file if(!fromConfig(config)) { yError() << "embObjAnalogSensor missing some configuration parameter. Check logs and your config file."; return false; } // Tmp variables Bottle groupEth; ACE_TCHAR address[64]; ACE_UINT16 port; Bottle groupTransceiver = Bottle(config.findGroup("TRANSCEIVER")); if(groupTransceiver.isNull()) { yError() << "embObjVirtualAnalogSensor: Can't find TRANSCEIVER group in config files"; return false; } Bottle groupProtocol = Bottle(config.findGroup("PROTOCOL")); if(groupProtocol.isNull()) { yError() << "embObjVirtualAnalogSensor: Can't find PROTOCOL group in config files"; return false; } // Get both PC104 and EMS ip addresses and port from config file groupEth = Bottle(config.findGroup("ETH")); Bottle parameter1( groupEth.find("PC104IpAddress").asString() ); // .findGroup("IpAddress"); port = groupEth.find("CmdPort").asInt(); // .get(1).asInt(); snprintf(_fId.pc104IPaddr.string, sizeof(_fId.pc104IPaddr.string), "%s", parameter1.toString().c_str()); _fId.pc104IPaddr.port = port; Bottle parameter2( groupEth.find("IpAddress").asString() ); // .findGroup("IpAddress"); snprintf(_fId.boardIPaddr.string, sizeof(_fId.boardIPaddr.string), "%s", parameter2.toString().c_str()); _fId.boardIPaddr.port = port; sscanf(_fId.boardIPaddr.string,"\"%d.%d.%d.%d", &_fId.boardIPaddr.ip1, &_fId.boardIPaddr.ip2, &_fId.boardIPaddr.ip3, &_fId.boardIPaddr.ip4); sscanf(_fId.pc104IPaddr.string,"\"%d.%d.%d.%d", &_fId.pc104IPaddr.ip1, &_fId.pc104IPaddr.ip2, &_fId.pc104IPaddr.ip3, &_fId.pc104IPaddr.ip4); snprintf(_fId.boardIPaddr.string, sizeof(_fId.boardIPaddr.string), "%u.%u.%u.%u:%u", _fId.boardIPaddr.ip1, _fId.boardIPaddr.ip2, _fId.boardIPaddr.ip3, _fId.boardIPaddr.ip4, _fId.boardIPaddr.port); snprintf(_fId.pc104IPaddr.string, sizeof(_fId.pc104IPaddr.string), "%u.%u.%u.%u:%u", _fId.pc104IPaddr.ip1, _fId.pc104IPaddr.ip2, _fId.pc104IPaddr.ip3, _fId.pc104IPaddr.ip4, _fId.pc104IPaddr.port); // Debug info snprintf(_fId.name, sizeof(_fId.name), "embObjAnalogSensor: referred to EMS: %d at address %s\n", _fId.boardNumber, address); // Saving User Friendly Id Value val =config.findGroup("ETH").check("Ems",Value(1), "Board number"); if(val.isInt()) _fId.boardNumber =val.asInt(); else { yError () << "embObjAnalogSensor: EMS Board number identifier not found for IP" << _fId.pc104IPaddr.string; return false; } ethManager = TheEthManager::instance(); if(NULL == ethManager) { yError() << "Unable to instantiate ethManager"; return false; } // N.B.: use a dynamic_cast to extract correct interface when using this pointer _fId.interface = this; _fId.type = ethFeatType_AnalogVirtual; /* Once I'm ok, ask for resources, through the _fId struct I'll give the ip addr, port and * and boradNum to the ethManagerin order to create the ethResource requested. * I'll Get back the very same sturct filled with other data useful for future handling * like the EPvector and EPhash_function */ res = ethManager->requestResource(config, groupTransceiver, groupProtocol, _fId); if(NULL == res) { yError() << "EMS device not instantiated... unable to continue"; cleanup(); return false; } /*IMPORTANT: implement isEpManagedByBoard like every embObj obj when virtaulAnalogSensor will be exist in eo proto!!!!*/ // if(!isEpManagedByBoard()) // { // yError() << "EMS "<< _fId.boardNumber << "is not connected to virtual analog sensor"; // return false; // } // if(!res->verifyProtocol(groupProtocol, eoprot_endpoint_???)) // { // yError() << "embObjVirtualAnalogSensor and board "<< _fId.boardNumber << "dont not have the same eoprot_endpoint_??? protocol version: DO A FW UPGRADE"; // return false; // } yTrace() << "EmbObj Virtual Analog Sensor for board "<< _fId.boardNumber << "instantiated correctly"; opened = true; return true; }