예제 #1
0
파일: main.cpp 프로젝트: antoinealb/aseba
// Main
int main(int argc, char *argv[])
{
	Dashel::initPlugins();

	std::string httpPort = "3000";
	std::vector < std::string > dashelTargetList;
	bool verbose = false;
	int Kiterations = -1; // set to > 0 to limit run time e.g. for valgrind

	// process command line
	int argCounter = 1;
	while(argCounter < argc) {
		const char *arg = argv[argCounter++];

		if((strcmp(arg, "-v") == 0) || (strcmp(arg, "--verbose") == 0)) verbose = true;
		else if((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0)) dumpHelp(std::cout, argv[0]), exit(1);
		else if((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0)) dumpVersion (std::cout), exit(1);
		else if((strcmp(arg, "-p") == 0) || (strcmp(arg, "--port") == 0)) httpPort = argv[argCounter++];
		else if((strcmp(arg, "-K") == 0) || (strcmp(arg, "--Kiter") == 0)) Kiterations = atoi(argv[argCounter++]);
		else if(strncmp(arg, "-", 1) != 0) dashelTargetList.push_back(arg);
	}

	// initialize Dashel plugins
	Dashel::initPlugins();

	// create and run bridge, catch Dashel exceptions
	try {
		std::auto_ptr<Aseba::Http::HttpInterface> interface(new Aseba::Http::HttpInterface(httpPort));
		interface->setVerbose(verbose);

		int numTargets = (int) dashelTargetList.size();
		for(int i = 0; i < numTargets; i++) {
			interface->addTarget(dashelTargetList[i]);
		}

		while(Kiterations < 0 || Kiterations > 0) {
			interface->step();

			if(Kiterations > 0) {
				Kiterations--;
			}
		}
	} catch(Dashel::DashelException e) {
		std::cerr << "Unhandled Dashel exception: " << e.what() << std::endl;
		return 1;
	}

	return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: brettle/aseba
// Main
int main(int argc, char *argv[])
{
    Dashel::initPlugins();
    
    std::string http_port = "3000";
    std::string aesl_filename;
    std::string dashel_target;
    bool verbose = false;
    bool dump = false;
    int Kiterations = -1; // set to > 0 to limit run time e.g. for valgrind
        
    // process command line
    int argCounter = 1;
    while (argCounter < argc)
    {
        const char *arg = argv[argCounter++];
        
        if ((strcmp(arg, "-v") == 0) || (strcmp(arg, "--verbose") == 0))
            verbose = true;
        else if ((strcmp(arg, "-d") == 0) || (strcmp(arg, "--dump") == 0))
            dump = true;
        else if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
            dumpHelp(std::cout, argv[0]), exit(1);
        else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
            dumpVersion(std::cout), exit(1);
        else if ((strcmp(arg, "-p") == 0) || (strcmp(arg, "--port") == 0))
            http_port = argv[argCounter++];
        else if ((strcmp(arg, "-a") == 0) || (strcmp(arg, "--aesl") == 0))
            aesl_filename = argv[argCounter++];
        else if ((strcmp(arg, "-K") == 0) || (strcmp(arg, "--Kiter") == 0))
            Kiterations = atoi(argv[argCounter++]);
        else if (strncmp(arg, "-", 1) != 0)
            dashel_target = arg;
    }
    
    // initialize Dashel plugins
    Dashel::initPlugins();
    
    // create and run bridge, catch Dashel exceptions
    try
    {
        Aseba::HttpInterface* network(new Aseba::HttpInterface(dashel_target, http_port, 1000*Kiterations));
        
        for (int i = 0; i < 500; i++)
            network->step(10); // wait for description, variables, etc
        if (aesl_filename.size() > 0)
        {
            network->aeslLoadFile(aesl_filename);
        }
        else
        {
            const char* failsafe = "<!DOCTYPE aesl-source><network><keywords flag=\"true\"/><node nodeId=\"1\" name=\"thymio-II\"></node></network>\n";
            network->aeslLoadMemory(failsafe,strlen(failsafe));
        }
        
        network->run();
        delete network;
    }
    catch(Dashel::DashelException e)
    {
        std::cerr << "Unhandled Dashel exception: " << e.what() << std::endl;
        return 1;
    }
    catch (Aseba::InterruptException& e) {
        std::cerr << " attempting graceful network shutdown" << std::endl;
    }

    return 0;
}
예제 #3
0
파일: switch.cpp 프로젝트: brettle/aseba
int main(int argc, char *argv[])
{
	Dashel::initPlugins();
	unsigned port = ASEBA_DEFAULT_PORT;
	bool verbose = false;
	bool dump = false;
	bool forward = true;
	bool rawTime = false;
	std::vector<std::string> additionalTargets;
	
	int argCounter = 1;
	
	while (argCounter < argc)
	{
		const char *arg = argv[argCounter];
		
		if ((strcmp(arg, "-v") == 0) || (strcmp(arg, "--verbose") == 0))
		{
			verbose = true;
		}
		else if ((strcmp(arg, "-d") == 0) || (strcmp(arg, "--dump") == 0))
		{
			dump = true;
		}
		else if ((strcmp(arg, "-l") == 0) || (strcmp(arg, "--loop") == 0))
		{
			forward = false;
		}
		else if (strcmp(arg, "-p") == 0)
		{
			if (argCounter + 1 >= argc)
			{
				std::cerr << "port value needed" << std::endl;
				return 1;
			}
			arg = argv[++argCounter];
			port = atoi(arg);
		}
		else if (strcmp(arg, "--rawtime") == 0)
		{
			rawTime = true;
		}
		else if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
		{
			dumpHelp(std::cout, argv[0]);
			return 0;
		}
		else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
		{
			dumpVersion(std::cout);
			return 0;
		}
		else
		{
			additionalTargets.push_back(argv[argCounter]);
		}
		argCounter++;
	}
	
	try
	{
		Aseba::Switch aswitch(port, verbose, dump, forward, rawTime);
		for (size_t i = 0; i < additionalTargets.size(); i++)
		{
			const std::string& target(additionalTargets[i]);
			Dashel::Stream* stream = aswitch.connect(target);
			
			// see whether we have to remap the id of this stream
			Dashel::ParameterSet remapIdDecoder;
			remapIdDecoder.add("dummy:remapLocal=-1;remapTarget=1");
			remapIdDecoder.add(target.c_str());
			const int remappedLocalId(remapIdDecoder.get<int>("remapLocal"));
			const int remappedTargetId(remapIdDecoder.get<int>("remapTarget"));
			if (target.find("remapLocal=") != std::string::npos)
			{
				aswitch.remapId(stream, uint16(remappedLocalId), uint16(remappedTargetId));
				if (verbose)
					std::cout << "Remapping local " << remappedLocalId << " with remote " << remappedTargetId << std::endl;
			}
		}
		/*
		Uncomment this and comment aswitch.run() to flood all pears with dummy user messages
		while (1)
		{
			aswitch.step(10);
			aswitch.broadcastDummyUserMessage();
		}*/
		aswitch.run();
	}
	catch(Dashel::DashelException e)
	{
		std::cerr << e.what() << std::endl;
	}
	
	return 0;
}
예제 #4
0
int main(int argc, char *argv[])
{
	Dashel::initPlugins();
	bool respectTimings = true;
	int speedFactor = 1;
	std::vector<std::string> targets;
	const char* inputFile = 0;
	
	int argCounter = 1;
	
	while (argCounter < argc)
	{
		const char *arg = argv[argCounter];
		
		if (strcmp(arg, "--fastest") == 0)
		{
			respectTimings = false;
		}
		else if (strcmp(arg, "--fast") == 0)
		{
			speedFactor = 2;
		}
		else if (strcmp(arg, "--faster") == 0)
		{
			speedFactor = 4;
		}
		else if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
		{
			dumpHelp(std::cout, argv[0]);
			return 0;
		}
		else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
		{
			dumpVersion(std::cout);
			return 0;
		}
		else if (strcmp(arg, "-f") == 0)
		{
			argCounter++;
			if (argCounter >= argc)
			{
				dumpHelp(std::cout, argv[0]);
				return 1;
			}
			else
				inputFile = argv[argCounter];
		}
		else
		{
			targets.push_back(argv[argCounter]);
		}
		argCounter++;
	}
	
	if (targets.empty())
		targets.push_back(ASEBA_DEFAULT_TARGET);
	
	try
	{
		Aseba::Player player(inputFile, respectTimings, speedFactor);
		for (size_t i = 0; i < targets.size(); i++)
			player.connect(targets[i]);
		player.run();
	}
	catch(Dashel::DashelException e)
	{
		std::cerr << e.what() << std::endl;
	}
	
	return 0;
}