Ejemplo n.º 1
0
 Bottle& putBottleCompat(const char *key, const Bottle& val) {
     if (val.get(1).asString()=="=") {
         Bottle b;
         b.add(val.get(0));
         b.append(val.tail().tail());
         return putBottle(key,b);
     }
     return putBottle(key,val);
 }
Ejemplo n.º 2
0
bool NameServer::apply(const Bottle& cmd, Bottle& result,
                       const Contact& remote) {
    Bottle rcmd;
    rcmd.addString("ignored_legacy");
    rcmd.append(cmd);
    ConstString in = rcmd.toString().c_str();
    ConstString out = apply(in,remote).c_str();
    result.fromString(out.c_str());
    return true;
}
Ejemplo n.º 3
0
bool DeviceResponder::respond(const Bottle& command, Bottle& reply) {
    switch (command.get(0).asVocab()) {
    case VOCAB4('h','e','l','p'):
        if (examples.size()>=1) {
            reply.add(Value::makeVocab("many"));
            if (command.get(1).toString()=="more") {
                reply.append(details);
            } else {
                reply.append(examples);
            }
            return true;
        } else {
            reply.add("no documentation available");
            return false;
        }
        break;
    default:
        reply.add("command not recognized");
        return false;
    }
    return false;
}
Ejemplo n.º 4
0
	bool respond(const Bottle &command, Bottle &reply)
	{
		reply.clear();

		if (command.get(0).asString() == "checkGraspSucceeded")
		{
			if (graspSucceeded)		reply.append("true");
			else					reply.append("false");

			//graspSucceeded = false;
		}
		else if (command.get(0).asString() == "grasp")
		{
			Bottle answer;

			if(command.size() == 4)
			{
				if(command.get(1).asString() != "safe")
				{
					reply.addInt(-2);
					reply.addString("Error: wrong keyword");
					return false;
				}

				graspSucceeded = false;
				activeHand = command.get(3).asString().c_str();
				answer = grasp->Grasp(primitives,command.get(2).asString().c_str(),activeHand, true);
				if (answer.get(0).asInt() == 0)		isGrasping.signal();

			}
			else if (command.size() == 3)
			{
				activeHand = command.get(2).asString().c_str();
				answer = grasp->Grasp(primitives,command.get(1).asString().c_str(),activeHand, false);
			}
			else
			{
				reply.addInt(-2);
				reply.addString("Error: wrong syntax");
				return false;
			}
			
			// check if grasp returned an error
			cout << answer.toString() << endl;
			reply.append(answer);
		}

		else if (command.get(0).asString() == "release")
		{
			if(command.size() != 2)
			{
				reply.addInt(-2);
				reply.addString("Error: wrong syntax");
				return false;
			}

			activeHand = command.get(1).asString().c_str();
			Bottle answer = grasp->Release(primitives,activeHand);
			reply.append(answer);
		}

		else if (command.get(0).asString() == "tighten")
		{	
			if(command.size() == 1)
				reply = grasp->Tighten(activeHand);
			
			else if(command.size() == 2)
			{
				activeHand = command.get(1).asString().c_str();
				Bottle answer = grasp->Tighten(activeHand);
				reply.append(answer);
			}
			else
			{
				reply.addInt(-2);
				reply.addString("Error: wrong syntax");
				return false;
			}				
		}

		else if (command.get(0).asString() == "offset")
		{
			if (command.size() == 2 && command.get(1).asString() == "get")
				reply = grasp->getOffset();

			else if (command.size() == 3 && command.get(1).asString() == "set")
			{			
				Bottle * list = command.get(2).asList();
				if(list->size() != 9)
				{
					reply.addInt(-2);
					reply.addString("Error: wrong argument number");
					return false;
				}
				grasp->setOffset(*list);
				reply.addInt(0);
			}
			else
			{
				reply.addInt(-2);
				reply.addString("Error: wrong syntax");
				return false;
			}
		}

		else if (command.get(0).asString() == "speed")
		{
			if (command.size() == 2 && command.get(1).asString() == "get")
				reply = grasp->getGraspSpeeds();

			else if (command.size() == 3 && command.get(1).asString() == "set")
			{			
				Bottle * list = command.get(2).asList();
				if(list->size() != 9)
				{
					reply.addInt(-2);
					reply.addString("Error: wrong argument number");
					return false;
				}
				grasp->setGraspSpeeds(*list);
				reply.addInt(0);
			}
			else
			{
				reply.addInt(-2);
				reply.addString("Error: wrong syntax");
				return false;
			}
				
		}
		else if (command.get(0).asString() == "quit")
		{
			reply.append("quit");
			return true;
		}
		else
		{
			reply.addInt(-2);
			return false;
		}

		return true;
	}
Ejemplo n.º 5
0
    bool respond(const Bottle &command, Bottle &reply)
    {
        int ack=Vocab::encode("ack");
        int nack=Vocab::encode("nack");

        if (command.size()>0)
        {
            switch (command.get(0).asVocab())
            {
                //-----------------
                case VOCAB4('c','l','e','a'):
                {
                    mutex.wait();
                    solver.clearItems();
                    solution=0.0;
                    mutex.post();

                    reply.addVocab(ack);
                    return true;
                }
                
                //-----------------
                case VOCAB4('s','e','l','e'):
                {
                    if (command.size()>=3)
                    {
                        string arm=command.get(1).asString().c_str();
                        string eye=command.get(2).asString().c_str();

                        if ((arm=="left") || (arm=="right"))
                            this->arm=arm;

                        if ((eye=="left") || (eye=="right"))
                            this->eye=eye;

                        if (this->arm=="left")
                            drvArmL.view(iarm);
                        else
                            drvArmR.view(iarm);

                        reply.addVocab(ack);
                    }
                    else
                        reply.addVocab(nack);

                    return true;
                }

                //-----------------
                case VOCAB3('n','u','m'):
                {
                    reply.addVocab(ack);

                    mutex.wait();
                    reply.addInt((int)solver.getNumItems());
                    mutex.post();

                    return true;
                }

                //-----------------
                case VOCAB4('f','i','n','d'):
                {
                    double error;

                    mutex.wait();
                    bool ok=solver.solve(solution,error);
                    mutex.post();

                    if (ok)
                    {
                        reply.addVocab(ack);
                        for (size_t i=0; i<solution.length(); i++)
                            reply.addDouble(solution[i]);
                    }
                    else
                        reply.addVocab(nack);

                    return true;
                }

                //-----------------
                case VOCAB4('s','h','o','w'):
                {
                    if (command.size()>=4)
                    {
                        solution[0]=command.get(1).asDouble();
                        solution[1]=command.get(2).asDouble();
                        solution[2]=command.get(3).asDouble();

                        reply.addVocab(ack);
                    }
                    else
                        reply.addVocab(nack);

                    return true;
                }

                //-----------------
                case VOCAB3('t','i','p'):
                {
                    if (tip.size()>=2)
                    {
                        reply.addVocab(ack);
                        reply.append(tip);
                    }
                    else
                        reply.addVocab(nack);

                    return true;
                }

                //-----------------
                case VOCAB4('e','n','a','b'):
                {
                    enabled=true;
                    reply.addVocab(ack);
                    return true;
                }

                //-----------------
                case VOCAB4('d','i','s','a'):
                {
                    enabled=false;
                    reply.addVocab(ack);
                    return true;
                }

                //-----------------
                default:
                    return RFModule::respond(command,reply);
            }
        }

        reply.addVocab(nack);
        return true;
    }
Ejemplo n.º 6
0
Bottle PMPthread::getVTGSparam(Bottle cmdBot, string side)
{
	VirtualTrajectoryGenerator * VTGS;

	if (side == "right")	VTGS = VTGS_r;
	if (side == "left")		VTGS = VTGS_l;

	VTGSparam cmd;
	Bottle reply;

	if(!identifyCmd(cmdBot, cmd))
	{
		reply.addString("Unknown command\n");
	}
	else
	{
		switch(cmd)
		{
			// VTGS parameters
			case target:
				reply.append(Matrix2Bottle(VTGS->getTarget()));
				break;
	
			case weights:
				reply.append(Matrix2Bottle(VTGS->getWeights()));
				break;
	
			// tbg1 parameters
			case T_init1:
				reply.addDouble(VTGS->tbg1.getT_init());
				break;
	
			case T_dur1:
				reply.addDouble(VTGS->tbg1.getT_dur());
				break;
	
			case SlopeRamp1:
				reply.addDouble(VTGS->tbg1.getSlopeRamp());
				break;
	
			case alpha1:
				reply.addDouble(VTGS->tbg1.getAlpha());
				break;

			// tbg2 parameters
			case T_init2:
				reply.addDouble(VTGS->tbg2.getT_init());
				break;
	
			case T_dur2:
				reply.addDouble(VTGS->tbg2.getT_dur());
				break;

			case SlopeRamp2:
				reply.addDouble(VTGS->tbg2.getSlopeRamp());
				break;
	
			case alpha2:
				reply.addDouble(VTGS->tbg2.getAlpha());
				break;
		}
	}
	return reply;
}
Ejemplo n.º 7
0
Bottle PMPthread::getPMPparam(Bottle cmdBot)
{
	PMPparam cmd;
	Bottle reply;

	if(!identifyCmd(cmdBot, cmd))
	{
		reply.addString("Unknown command\n");
	}
	else
	{
		switch(cmd)
		{
			// PMP parameters
			case xr_target:			
				reply.append(Vector2Bottle(PMP->x_tgR));
				break;
	
			case xl_target:
				reply.append(Vector2Bottle(PMP->x_tgL));
				break;

			case q_rightArm:
				reply.append(Vector2Bottle(PMP->get_q_rightArm()));
				break;

			case q_leftArm:
				reply.append(Vector2Bottle(PMP->get_q_rightArm()));
				break;

			case qr_initial:
				reply.append(Vector2Bottle(PMP->q_0R));
				break;

			case ql_initial:
				reply.append(Vector2Bottle(PMP->q_0L));
				break;

			case Kr_virt:
				reply.append(Matrix2Bottle(PMP->get_K_right()));
				break;

			case Kl_virt:
				reply.append(Matrix2Bottle(PMP->get_K_left()));
				break;

			case A_rightArm:
				reply.append(Matrix2Bottle(PMP->get_A_rightArm()));
				break;

			case A_leftArm:
				reply.append(Matrix2Bottle(PMP->get_A_rightArm()));
				break;

			case Kr_int:
				reply.append(Matrix2Bottle(PMP->get_Kint_right()));
				break;

			case Kl_int:
				reply.append(Matrix2Bottle(PMP->get_Kint_left()));
				break;

			case K_virt_bimanual:
				reply.append(Matrix2Bottle(PMP->get_K_biman()));
				break;

			case A_bimanual:
				reply.append(Matrix2Bottle(PMP->get_A_biman()));
				break;

			case wrist:

				if(cmdBot.size() != 2)
				{
					reply.append("Error: parameter value size mismatch");
					break;
				}

				cout << cmdBot.toString() << endl;
				if (cmdBot.get(1).asString() == "right")
				{
					reply.addDouble(PMP->q_ref_right(7)*CTRL_RAD2DEG);
					break;
				}
				else if (cmdBot.get(1).asString() == "left")
				{
					reply.addDouble(PMP->q_ref_left(7)*CTRL_RAD2DEG);
					break;
				}
				else if (cmdBot.get(1).asString() == "bimanual")
				{
					reply.addDouble(PMP->q_ref_right(7)*CTRL_RAD2DEG);
					reply.addDouble(PMP->q_ref_left(7)*CTRL_RAD2DEG);
					break;
				}
				else
				{
					printf("Error: unknown chain parameter value\n");
					reply.append("error");
					break;
				}
	
			// tbg parameters
			case T_init:
				reply.addDouble(PMP->tbg.getT_init());
				break;
	
			case T_dur:
				reply.addDouble(PMP->tbg.getT_dur());
				break;
	
			case SlopeRamp:
				reply.addDouble(PMP->tbg.getSlopeRamp());
				break;
	
			case alpha:
				reply.addDouble(PMP->tbg.getAlpha());
				break;
			case pose:
				if(!updateCurrentAngles(true)) reply.append("Error in communication");
				else
				{
					reply.append( Vector2Bottle( PMP->get_EEPose("right") ) );
					reply.append( Vector2Bottle( PMP->get_EEPose("left") ) );
				}
				break;
		}
	}
	return reply;
}
Ejemplo n.º 8
0
bool skinManager::respond(const Bottle& command, Bottle& reply) {
	stringstream temp;
	reply.clear();

	SkinManagerCommand com;
    Bottle params;
    if(command.get(0).isInt()){
        // if first value is int then it is the id of the command
        com = (SkinManagerCommand)command.get(0).asInt();
        params = command.tail();
    }
	else if(!identifyCommand(command, com, params)){
		reply.addString("Unknown command. Input 'help' to get a list of the available commands.");
		return true;
	}

	switch( com ){
		case quit:
			reply.addString("quitting");
			return false;

		case help:
            reply.addVocab(Vocab::encode("many"));				// print every string added to the bottle on a new line
			reply.addString((string(getName().c_str()) + " commands are: ").c_str());
			for(unsigned int i=0; i< SkinManagerCommandSize; i++){
				reply.addString( ("- "+SkinManagerCommandList[i]+": "+SkinManagerCommandDesc[i]).c_str() );
			}
			return true;

		case calibrate:
			myThread->calibrate();
			break;

		case get_touch_thr:
			{
			Vector touchThreshold = myThread->getTouchThreshold();
			for(size_t i=0; i< touchThreshold.size(); i++) 
				reply.addDouble(touchThreshold[i]);
			return true;
			}

		case set_binarization:
			{
			if(params.size()<1){
				reply.addString("Binarization state missing! Specify either on or off.");
				return true;
			}
			string value = params.get(0).asString().c_str();
			if(value.compare("on")==0)
				myThread->setBinarization(true);
			else if(value.compare("off")==0)
				myThread->setBinarization(false);
			else{
				reply.addString("Value not recognized.");
				return true;
			}
			break;
			}

		case get_binarization:
			if(myThread->getBinarization())
				reply.addString("on");
			else
				reply.addString("off");
			return true;

		case set_smooth_filter:
			{
			if(params.size()<1){
				reply.addString("Smooth filter state missing! Specify either on or off.");
				return true;
			}
			string value = params.get(0).asString().c_str();
			if(value.compare("on")==0)
				myThread->setSmoothFilter(true);
			else if(value.compare("off")==0)
				myThread->setSmoothFilter(false);
			else{
				reply.addString("Value not recognized.");
				return true;
			}
			break;
			}

		case get_smooth_filter:
			if(myThread->getSmoothFilter())
				reply.addString("on");
			else
				reply.addString("off");
			return true;

		case set_smooth_factor:
			{
			if(params.size()<1 || (!params.get(0).isDouble() && !params.get(0).isInt())){
				reply.addString("New smooth factor value missing or not a number! Smooth factor not updated.");
				return true;
			}

			stringstream temp;
			if(myThread->setSmoothFactor((float)params.get(0).asDouble())){
				temp<< "New smooth factor set: "<< params.get(0).asDouble();				
			}
			else{
				temp<< "ERROR in setting new smooth factor: "<< params.get(0).asDouble();
			}
			reply.addString( temp.str().c_str());
			return true;
			}

		case get_smooth_factor:
			reply.addDouble(myThread->getSmoothFactor());
			return true;

        case set_threshold:
            {
			if(params.size()<1 || (!params.get(0).isInt())){
				reply.addString("New threshold value missing or not an integer! Threshold not updated.");
				return true;
			}

			stringstream temp;
			if(myThread->setAddThreshold(params.get(0).asInt())){				
				temp<< "New threshold set: "<< params.get(0).asInt();				
			}
			else{
				temp<< "ERROR in setting new threshold: "<< params.get(0).asInt();
			}
			reply.addString( temp.str().c_str());
			return true;
			}

        case get_threshold:
            reply.addInt(myThread->getAddThreshold());
            return true;

        case set_gain:
            {
			if(params.size()<1 || (!params.get(0).isDouble())){
				reply.addString("New gain value missing or not a double! Gain not updated.");
				return true;
			}

			stringstream temp;
			if(myThread->setCompensationGain(params.get(0).asDouble())){	
				temp<< "New gain set: "<< params.get(0).asDouble();				
			}
			else{
				temp<< "ERROR in setting new gain: "<< params.get(0).asDouble();
			}
			reply.addString( temp.str().c_str());
			return true;
			}

        case get_gain:
            reply.addDouble(myThread->getCompensationGain());
            return true;

        case set_cont_gain:
            {
			if(params.size()<1 || (!params.get(0).isDouble())){
				reply.addString("New gain value missing or not a double! Contact gain not updated.");
				return true;
			}

			stringstream temp;
			if(myThread->setContactCompensationGain(params.get(0).asDouble())){	
				temp<< "New contact gain set: "<< params.get(0).asDouble();				
			}
			else{
				temp<< "ERROR in setting new contact gain: "<< params.get(0).asDouble();
			}
			reply.addString( temp.str().c_str());
			return true;
			}

        case get_cont_gain:
            reply.addDouble(myThread->getContactCompensationGain());
            return true;

        case get_max_neigh_dist:
            reply.addDouble(myThread->getMaxNeighborDistance());
            return true;

        case set_max_neigh_dist:
            {
			if(params.size()<1 || (!params.get(0).isDouble())){
				reply.addString("New max neighbor distance value missing or not a double! Not updated.");
				return true;
			}

			stringstream temp;
			if(myThread->setMaxNeighborDistance(params.get(0).asDouble())){	
				temp<< "New max neighbor distance set: "<< params.get(0).asDouble();				
			}
			else{
				temp<< "ERROR in setting new max neighbor distance: "<< params.get(0).asDouble();
			}
			reply.addString( temp.str().c_str());
			return true;
			}

        case get_skin_parts:
            {
                vector<SkinPart> spl = myThread->getSkinParts();
                for(vector<SkinPart>::const_iterator it=spl.begin(); it!=spl.end(); it++){
                    reply.addInt(*it);
                    reply.addString(SkinPart_s[*it].c_str());
                }
                return true;
            }

        case enable_skin_part:
            if(!(params.size()>0 && params.get(0).isInt())){
                reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                return true;
            }
            if(myThread->enableSkinPart((SkinPart)params.get(0).asInt()))
                reply.addString("SkinPart enabled");
            else
                reply.addString("SkinPart not found");
            return true;

        case disable_skin_part:
            if(!(params.size()>0 && params.get(0).isInt())){
                reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                return true;
            }
            if(myThread->disableSkinPart((SkinPart)params.get(0).asInt()))
                reply.addString("SkinPart disabled");
            else
                reply.addString("SkinPart not found");
            return true;

        case is_skin_enabled:
            if(!(params.size()>0 && params.get(0).isInt())){
                reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                return true;
            }
            if(myThread->isSkinEnabled((SkinPart)params.get(0).asInt()))
                reply.addString("yes");
            else
                reply.addString("no");
            return true;

		case is_calibrating:
			if(myThread->isCalibrating())
				reply.addString("yes");
			else
				reply.addString("no");
			return true;

        case get_pose:
            {
                if(!(params.size()>0 && params.get(0).isInt())){
                    reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                    return true;
                }
                SkinPart sp = (SkinPart) params.get(0).asInt();
                if(params.size()>1 && params.get(1).isInt()){
                    unsigned int taxelId = params.get(1).asInt();
                    Vector res = myThread->getTaxelPose(sp, taxelId);
                    if(res.size()>0)
                        addToBottle(reply, res);
                    else
                        reply.addString("No poses for the specified skin part");
                }
                else{
                    vector<Vector> res = myThread->getTaxelPoses(sp);
                    addToBottle(reply, res);
                }
                return true;
            }

        case set_pose:
            {
                if(!(params.size()>6 && params.get(0).isInt() )){
                    reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                    return true;
                }
                SkinPart sp = (SkinPart) params.get(0).asInt();
                if(params.get(1).isInt()){
                    unsigned int taxelId = params.get(1).asInt();
                    Vector pose;
                    if(!bottleToVector(params.tail().tail(), pose)){
                        reply.addString("ERROR while reading the taxel pose");
                        return true;
                    }
                    if(myThread->setTaxelPose(sp, taxelId, pose))
                        reply.addInt(skin_manager_ok);
                    else{
                        reply.addInt(skin_manager_error);
                        reply.addString("ERROR: pose was not set");
                    }
                }
                else{
                    Vector poses;
                    if(!bottleToVector(params.tail(), poses)){
                        reply.addString("ERROR while reading the taxel poses");
                        return true;
                    }
                    if(myThread->setTaxelPoses(sp, poses))
                        reply.addInt(skin_manager_ok);
                    else{
                        reply.addInt(skin_manager_error);
                        reply.addString("ERROR: pose was not set");
                    }
                }
                return true;
            }
		case get_position:
            {
                if(!(params.size()>0 && params.get(0).isInt())){
                    reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                    return true;
                }
                SkinPart sp = (SkinPart) params.get(0).asInt();
                if(params.size()>1 && params.get(1).isInt()){
                    unsigned int taxelId = params.get(1).asInt();
                    Vector res = myThread->getTaxelPosition(sp, taxelId);
                    if(res.size()>0)
                        addToBottle(reply, res);
                    else
                        reply.addString("No position for the specified skin part");
                }
                else{
                    vector<Vector> res = myThread->getTaxelPositions(sp);
                    if(res.empty())
                        reply.addString("Specified skin part has not been found.");
                    else
                        addToBottle(reply, res);
                }
                return true;
            }
		case set_position:
			{
                if(!(params.size()>3 && params.get(0).isInt() )){
                    reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                    return true;
                }
                SkinPart sp = (SkinPart) params.get(0).asInt();
                if(params.get(1).isInt()){
                    unsigned int taxelId = params.get(1).asInt();
                    Vector pose;
                    if(!bottleToVector(params.tail().tail(), pose)){
                        reply.addString("ERROR while reading the taxel position");
                        return true;
                    }
                    if(myThread->setTaxelPosition(sp, taxelId, pose))
                        reply.addInt(skin_manager_ok);
                    else{
                        reply.addInt(skin_manager_error);
                        reply.addString("ERROR: position was not set");
                    }
                }
                else{
                    Vector poses;
                    if(!bottleToVector(params.tail(), poses)){
                        reply.addString("ERROR while reading the taxel positions");
                        return true;
                    }
                    if(myThread->setTaxelPositions(sp, poses))
                        reply.addInt(skin_manager_ok);
                    else{
                        reply.addInt(skin_manager_error);
                        reply.addString("ERROR: position was not set");
                    }
                }
                return true;
            }
		case get_confidence:
			{
				if(!(params.size()>0 && params.get(0).isInt())){
                    reply.addString(("ERROR: SkinPart is not specified. Params read are: "+string(params.toString().c_str())).c_str());
                    return true;
                }
                SkinPart sp = (SkinPart) params.get(0).asInt();
                if(params.size()>1 && params.get(1).isInt()){
                    unsigned int taxelId = params.get(1).asInt();
                    double res = myThread->getPoseConfidence(sp, taxelId);
					reply.addDouble(res);
                }
                else{
                    Vector res = myThread->getPoseConfidences(sp);
                    if(res.size()==0)
                        reply.addString("Specified skin part has not been found");
                    else
                        addToBottle(reply, res);
                }
                return true;

			}
        case get_info:
            reply.append(myThread->getInfo());
            return true;

		default:
			reply.addString("ERROR: This command is known but it is not managed in the code.");
			return true;
	}

	reply.addString( (SkinManagerCommandList[com]+" command received.").c_str());

	return true;	
}
Ejemplo n.º 9
0
bool RGBDSensorParser::respond(const Bottle& cmd, Bottle& response)
{
    bool ret = false;
    int interfaceType = cmd.get(0).asVocab();

    response.clear();
    switch(interfaceType)
    {
        case VOCAB_RGB_VISUAL_PARAMS:
        {
            // forwarding to the proper parser.
            ret = rgbParser.respond(cmd, response);
        }
        break;

        case VOCAB_DEPTH_VISUAL_PARAMS:
        {
            // forwarding to the proper parser.
            ret = depthParser.respond(cmd, response);
        }
        break;

        case VOCAB_RGBD_SENSOR:
        {
            switch (cmd.get(1).asVocab())
            {
                case VOCAB_GET:
                {
                    switch(cmd.get(2).asVocab())
                    {
                        case VOCAB_EXTRINSIC_PARAM:
                        {
                            yarp::sig::Matrix params;
                            ret = iRGBDSensor->getExtrinsicParam(params);
                            if(ret)
                            {
                                yarp::os::Bottle params_b;
                                response.addVocab(VOCAB_RGBD_SENSOR);
                                response.addVocab(VOCAB_EXTRINSIC_PARAM);
                                response.addVocab(VOCAB_IS);
                                ret &= Property::copyPortable(params, params_b);  // will it really work??
                                response.append(params_b);
                            }
                            else
                                response.addVocab(VOCAB_FAILED);
                        }
                        break;

                        case VOCAB_ERROR_MSG:
                        {
                            response.addVocab(VOCAB_RGBD_SENSOR);
                            response.addVocab(VOCAB_ERROR_MSG);
                            response.addVocab(VOCAB_IS);
                            response.addString(iRGBDSensor->getLastErrorMsg());
                            ret = true;
                        }
                        break;

                        case VOCAB_RGBD_PROTOCOL_VERSION:
                        {
                            response.addVocab(VOCAB_RGBD_SENSOR);
                            response.addVocab(VOCAB_RGBD_PROTOCOL_VERSION);
                            response.addVocab(VOCAB_IS);
                            response.addInt(RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR);
                            response.addInt(RGBD_INTERFACE_PROTOCOL_VERSION_MINOR);
                        }
                        break;

                        case VOCAB_STATUS:
                        {
                            response.addVocab(VOCAB_RGBD_SENSOR);
                            response.addVocab(VOCAB_STATUS);
                            response.addVocab(VOCAB_IS);
                            response.addInt(iRGBDSensor->getSensorStatus());
                        }
                        break;

                        default:
                        {
                            yError() << "RGBDSensor interface parser received an unknown GET command. Command is " << cmd.toString();
                            response.addVocab(VOCAB_FAILED);
                        }
                        break;
                    }
                }
                break;

                case VOCAB_SET:
                {
                    yError() << "RGBDSensor interface parser received an unknown SET command. Command is " << cmd.toString();
                    response.addVocab(VOCAB_FAILED);
                }
                break;
            }
        }
        break;

        default:
        {
            yError() << "RGBD sensor wrapper received a command for a wrong interface " << yarp::os::Vocab::decode(interfaceType);
            ret = false;
        }
        break;
    }
    return ret;
}
Ejemplo n.º 10
0
Contact NameClient::registerName(const String& name, const Contact& suggest) {
    String np = getNamePart(name);
    Bottle cmd;
    cmd.addString("register");
    if (np!="") {
        cmd.addString(np.c_str());
    } else {
        cmd.addString("...");
    }
    ConstString prefix = NetworkBase::getEnvironment("YARP_IP");
    NestedContact nc = suggest.getNested();
    ConstString typ = nc.getTypeNameStar();
    if (suggest.isValid()||prefix!=""||typ!="*") {
        if (suggest.getCarrier()!="") {
            cmd.addString(suggest.getCarrier().c_str());
        } else {
            cmd.addString("...");
        }
        if (suggest.getHost()!="") {
            cmd.addString(suggest.getHost().c_str());
        } else {
            if (prefix!="") {
                Bottle ips = NameConfig::getIpsAsBottle();
                for (int i=0; i<ips.size(); i++) {
                    String ip = ips.get(i).asString().c_str();
                    if (ip.find(prefix)==0) {
                        prefix = ip.c_str();
                        break;
                    }
                }
            }
            cmd.addString((prefix!="")?prefix:"...");
        }
        if (suggest.getPort()!=0) {
            cmd.addInt(suggest.getPort());
        } else {
            cmd.addString("...");
        }
        if (typ!="*") {
            cmd.addString(typ);
        }
    }
    Bottle reply;
    send(cmd,reply);

    Contact address = extractAddress(reply);
    if (address.isValid()) {
        String reg = address.getRegName();

        /*

          // this never really got used

        cmd.fromString("set /port offers tcp text text_ack udp mcast shmem name_ser");
        cmd.get(1) = Value(reg.c_str());
        send(cmd,reply);

        // accept the same set of carriers
        cmd.get(2) = Value("accepts");
        send(cmd,reply);
        */

        cmd.clear();
        cmd.addString("set");
        cmd.addString(reg.c_str());
        cmd.addString("ips");
        cmd.append(NameConfig::getIpsAsBottle());
        send(cmd,reply);

        cmd.clear();
        cmd.addString("set");
        cmd.addString(reg.c_str());
        cmd.addString("process");
        cmd.addInt(ACE_OS::getpid());
        send(cmd,reply);
    }
    return address;
}
Ejemplo n.º 11
0
    void fromConfig(const char *txt,Searchable& env, bool wipe=true) {
        StringInputStream sis;
        sis.add(txt);
        sis.add("\n");
        if (wipe) {
            clear();
        }
        String tag = "";
        Bottle accum;
        bool done = false;
        do {
            bool isTag = false;
            bool including = false;
            String buf;
            bool good = true;
            buf = sis.readLine('\n',&good);
            while (good && !BottleImpl::isComplete(buf.c_str())) {
                buf += sis.readLine('\n',&good);
            }
            if (!good) {
                done = true;
            }
            if (!done) {
                including = false;

                if (buf.find("//")!=String::npos) {
                    bool quoted = false;
                    int comment = 0;
                    for (unsigned int i=0; i<buf.length(); i++) {
                        char ch = buf[i];
                        if (ch=='\"') { quoted = !quoted; }
                        if (!quoted) {
                            if (ch=='/') {
                                comment++;
                                if (comment==2) {
                                    //buf = buf.substr(0,buf.strstr("//"));
                                    buf = buf.substr(0,i);
                                    break;
                                }
                            } else {
                                comment = 0;
                            }
                        } else {
                            comment = 0;
                        }
                    }
                }

                // expand any environment references
                buf = expand(buf.c_str(),env,owner).c_str();

                if (buf.length()>0 && buf[0]=='[') {
                    size_t stop = buf.find("]");
                    if (stop!=String::npos) {
                        buf = buf.substr(1,stop-1);
                        size_t space = buf.find(" ");
                        if (space!=String::npos) {
                            Bottle bot(buf.c_str());
                            if (bot.size()>1) {
                                if (bot.get(0).toString() == "include") {
                                    including = true;
                                    if (bot.size()>2) {
                                        if (tag!="") {
                                            if (accum.size()>=1) {
                                                putBottleCompat(tag.c_str(),
                                                                accum);
                                            }
                                            tag = "";
                                        }
                                        ConstString subName, fname;
                                        if (bot.size()==3) {
                                            // [include section "filename"]
                                            subName = bot.get(1).toString();
                                            fname = bot.get(2).toString();
                                        } else if (bot.size()==4) {
                                            // [include type section "filename"]
                                            ConstString key;
                                            key = bot.get(1).toString();
                                            subName = bot.get(2).toString();
                                            fname = bot.get(3).toString();
                                            Bottle *target =
                                                getBottle(key.c_str());
                                            if (target==NULL) {
                                                Bottle init;
                                                init.addString(key.c_str());
                                                init.addString(subName.c_str());
                                                putBottleCompat(key.c_str(),
                                                                init);
                                            } else {
                                                target->addString(subName.c_str());
                                            }
                                        } else {
                                            YARP_ERROR(Logger::get(),
                                                       String("bad include"));
                                            return;
                                        }


                                        Property p;
                                        if (getBottle(subName)!=NULL) {
                                            p.fromString(getBottle(subName)->tail().toString());
                                            //printf(">>> prior p %s\n",
                                            //     p.toString().c_str());
                                        }
                                        p.fromConfigFile(fname.c_str(),
                                                         env, false);
                                        accum.fromString(p.toString());
                                        tag = subName.c_str();
                                        //printf(">>> tag %s accum %s\n",
                                        //     tag.c_str(),
                                        //     accum.toString().c_str());
                                        if (tag!="") {
                                            if (accum.size()>=1) {
                                                Bottle b;
                                                b.addString(tag.c_str());
                                                //Bottle& subList = b.addList();
                                                //subList.copy(accum);
                                                b.append(accum);
                                                putBottleCompat(tag.c_str(),
                                                                b);
                                            }
                                            tag = "";
                                        }
                                    } else {
                                        tag = "";
                                        ConstString fname =
                                            bot.get(1).toString();
                                        //printf("Including %s\n", fname.c_str());
                                        fromConfigFile(fname.c_str(),
                                                       env, false);
                                    }
                                }
                            }
                            if (bot.size()==2 && !including) {
                                buf = bot.get(1).toString().c_str();
                                String key = bot.get(0).toString().c_str();
                                Bottle *target = getBottle(key.c_str());
                                if (target==NULL) {
                                    Bottle init;
                                    init.addString(key.c_str());
                                    init.addString(buf.c_str());
                                    putBottleCompat(key.c_str(),init);
                                } else {
                                    target->addString(buf.c_str());
                                }
                            }
                        }
                        if (!including) {
                            isTag = true;
                        }
                    }
                }
            }
            if (!isTag && !including) {
                Bottle bot;
                bot.fromString(buf.c_str());
                if (bot.size()>=1) {
                    if (tag=="") {
                        putBottleCompat(bot.get(0).toString().c_str(),bot);
                    } else {
                        if (bot.get(1).asString()=="=") {
                            Bottle& b = accum.addList();
                            for (int i=0; i<bot.size(); i++) {
                                if (i!=1) {
                                    b.add(bot.get(i));
                                }
                            }
                        } else {
                            accum.addList().copy(bot);
                        }
                    }
                }
            }
            if (isTag||done) {
                if (tag!="") {
                    if (accum.size()>=1) {
                        putBottleCompat(tag.c_str(),accum);
                    }
                    tag = "";
                }
                tag = buf;
                accum.clear();
                accum.addString(tag.c_str());
                if (tag!="") {
                    if (getBottle(tag.c_str())!=NULL) {
                        // merge data
                        accum.append(getBottle(tag.c_str())->tail());
                        //printf("MERGE %s, got %s\n", tag.c_str(),
                        //     accum.toString().c_str());
                    }
                }
            }
        } while (!done);
    }