17#include <yarp/os/Time.h>
18#include <yarp/os/Log.h>
19#include <yarp/os/LogStream.h>
22#include <yarp/dev/PolyDriver.h>
23#include <ace/config.h>
24#include <ace/Log_Msg.h>
30#include <yarp/os/LogStream.h>
31#include "EoAnalogSensors.h"
34#include "EoProtocol.h"
35#include "EoProtocolMN.h"
36#include "EoProtocolAS.h"
38#include <yarp/os/NetType.h>
39#include <yarp/conf/environment.h>
42#pragma warning(once:4355)
48using namespace yarp::os;
54 yWarning() << std::string(txt) <<
" not yet implemented for embObjMais\n";
60bool embObjMais::extractGroup(Bottle &input, Bottle &
out,
const std::string &key1,
const std::string &txt,
int size)
63 Bottle &
tmp=input.findGroup(key1.c_str(), txt.c_str());
66 yError (
"%s not found\n", key1.c_str());
72 yError(
"%s incorrect number of entries\n", key1.c_str());
82bool embObjMais::fromConfig(yarp::os::Searchable &_config)
84#if defined(EMBOBJMAIS_USESERVICEPARSER)
87 if(
false == parser->
parseService(_config, serviceConfig))
101 Bottle config = _config.findGroup(
"GENERAL");
102 if (!extractGroup(config, xtmp,
"Period",
"transmitting period of the sensors", 1))
104 yError() <<
"embObjMais Using default value = 0 (disabled)";
110 _period = xtmp.get(1).asInt32();
111 yDebug() <<
"embObjMais::fromConfig() detects embObjMais Using value of" << _period;
132 status = MAS_status::MAS_OK;
137 analogdata.resize(0);
140 std::string tmp = yarp::conf::environment::get_string(
"ETH_VERBOSEWHENOK");
143 verbosewhenok = (bool)(yarp::conf::numeric::from_string(tmp, 0U));
147 verbosewhenok =
false;
157 analogdata.resize(0);
181 if(NULL == ethManager)
183 yFatal() <<
"embObjMais::open() fails to instantiate ethManager";
188 if(
false == ethManager->
verifyEthBoardInfo(config, ipv4addr, boardIPstring, boardName))
190 yError() <<
"embObjMais::open(): object TheEthManager fails in parsing ETH propertiex from xml file";
213 if(!fromConfig(config))
215 yError() <<
"embObjMais missing some configuration parameter. Check logs and your config file.";
232 yError() <<
"embObjMais::open() fails because could not instantiate the ethResource for BOARD w/ IP = " << boardIPstring <<
" ... unable to continue";
236 printServiceConfig();
245#if defined(TEST_MAIS_PLUS_MC)
249 const eOmn_serv_parameter_t* mcservparam = NULL;
279#if defined(EMBOBJMAIS_USESERVICEPARSER)
280 const eOmn_serv_parameter_t* servparam = &serviceConfig.
ethservice;
282 const eOmn_serv_parameter_t* servparam = NULL;
289 SystemClock::delaySystem(1);
306 if(
false == sendConfig2Mais())
313 if(
false == initRegulars())
340bool embObjMais::sendConfig2Mais(
void)
344 eOprotID32_t id32 = eo_prot_ID32dummy;
349 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_mais, 0, eoprot_tag_as_mais_config_datarate);
366 eOenum08_t maismode = eoas_maismode_txdatacontinuously;
367 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_mais, 0, eoprot_tag_as_mais_config_mode);
388bool embObjMais::initRegulars()
392 vector<eOprotID32_t> id32v(0);
393 eOprotID32_t id32 = eo_prot_ID32dummy;
397 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_mais, 0, eoprot_tag_as_mais_status_the15values);;
401 id32v.push_back(id32);
407 yError() <<
"embObjMais::initRegulars() fails to add its variables to regulars: cannot proceed any further";
416 for (
size_t r = 0; r<id32v.size(); r++)
418 uint32_t item = id32v.at(r);
419 eoprot_ID2information(item, nvinfo,
sizeof(nvinfo));
420 yDebug() <<
"\t it added regular rop for" << nvinfo;
429void embObjMais::resetCounters()
437void embObjMais::getCounters(
unsigned int &
sat,
unsigned int &err,
unsigned int &to)
449if (sens_index >= 1)
return yarp::dev::MAS_UNKNOWN;
450 return yarp::dev::MAS_OK;
454 if (sens_index >= 1)
return false;
460 if (sens_index >= 1)
return false;
461 timestamp = this->timeStamp;
462 out.resize(analogdata.size());
468 if (sens_index >= 1)
return 0;
469 return analogdata.size();
482 this->timeStamp = timestamp;
495 EOarray *array = (EOarray*)rxdata;
496 uint8_t size = eo_array_Size(array);
497 uint8_t itemsize = eo_array_ItemSize(array);
498 if((0 == size) || (1 != itemsize))
503 std::lock_guard<std::mutex> lck(mtx);
505 for (
size_t k = 0; k<analogdata.size(); k++)
507 uint8_t* tmp = (uint8_t*) eo_array_At(array, k);
512 analogdata[k] = (double)val;
531void embObjMais::printServiceConfig(
void)
540 parser->
convert(serviceConfig.
ethservice.configuration.data.as.mais.canloc, loc,
sizeof(loc));
541 parser->
convert(serviceConfig.
ethservice.configuration.data.as.mais.version.firmware, fir,
sizeof(fir));
542 parser->
convert(serviceConfig.
ethservice.configuration.data.as.mais.version.protocol, pro,
sizeof(pro));
544 yInfo() <<
"The embObjMais device using BOARD" << boardname <<
"w/ IP" << ipv4 <<
"has the following service config:";
546 yInfo() <<
"- MAIS named" << serviceConfig.
nameOfMais <<
"@" << loc <<
"with required protocol version =" << pro <<
"and required firmware version =" << fir;
550void embObjMais::cleanup(
void)
552 if(ethManager == NULL)
return;
bool convert(std::string const &fromstring, eOmc_actuator_t &toactuatortype, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigMais_t &maisconfig)
virtual bool setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries=10, const double waitbeforecheck=0.001, const double timeout=0.050)=0
virtual bool serviceVerifyActivate(eOmn_serv_category_t category, const eOmn_serv_parameter_t *param, double timeout=0.500)=0
virtual const Properties & getProperties()=0
virtual bool verifyEPprotocol(eOprot_endpoint_t ep)=0
virtual bool serviceSetRegulars(eOmn_serv_category_t category, vector< eOprotID32_t > &id32vector, double timeout=0.500)=0
virtual bool serviceStart(eOmn_serv_category_t category, double timeout=0.500)=0
int releaseResource2(eth::AbstractEthResource *ethresource, IethResource *interface)
bool verifyEthBoardInfo(yarp::os::Searchable &cfgtotal, eOipv4addr_t &boardipv4, string boardipv4string, string boardname)
static bool killYourself()
static TheEthManager * instance()
eth::AbstractEthResource * requestResource2(IethResource *interface, yarp::os::Searchable &cfgtotal)
virtual bool initialised()
virtual bool getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
virtual bool getEncoderArrayName(size_t sens_index, std::string &name) const override
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
virtual size_t getNrOfEncoderArrays() const override
bool open(yarp::os::Searchable &config)
virtual yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const override
virtual eth::iethresType_t type()
virtual size_t getEncoderArraySize(size_t sens_index) const override
bool NOT_YET_IMPLEMENTED(const char *txt)
double sat(const double val, const double min, const double max)
Copyright (C) 2008 RobotCub Consortium.
eOmn_serv_parameter_t ethservice