示例#1
0
文件: main.cpp 项目: smeyel/M2
void init(char *inifilename, int argc, char **argv)
{
	// Init config, allows overrides (including the ini file name)
	configManager.init(inifilename, argc, argv);

	// Init logger (singleton)
	Logger *logger = new StdoutLogger();
	//logger->SetLogLevel(Logger::LOGLEVEL_INFO);
	logger->SetLogLevel(Logger::LOGLEVEL_ERROR);
	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"CamClient","CamClient started\n");
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
	Logger::getInstance()->Log(Logger::LOGLEVEL_INFO,"CamClient","Current time: %d-%d-%d, %d:%d:%d\n",
		(now->tm_year + 1900),(now->tm_mon + 1),now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec );
	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"CamClient","Ini file: %s\n",inifilename);

	// Init time measurement
	timeMeasurement.init();
	CamClient::TimeMeasurementCodeDefs::setnames(&timeMeasurement);

	// Initialize camera
	if (configManager.usePs3eye)
	{
		videoInput = VideoInputFactory::CreateVideoInput(VIDEOINPUTTYPE_PS3EYE);
	}
	else
	{
		videoInput = VideoInputFactory::CreateVideoInput(VIDEOINPUTTYPE_GENERIC);
	}
	if (configManager.camID>=0)
	{
		videoInput->init(configManager.camID);
	}
	else
	{
		videoInput->init(configManager.camSourceFilename.data());
	}

	// Set auto gain, exposure and white balance
	videoInput->SetNormalizedGain(-1);
	videoInput->SetNormalizedExposure(-1);
	videoInput->SetNormalizedWhiteBalance(-1,-1,-1);

	if (configManager.showImage)
	{
		namedWindow(imageWindowName, CV_WINDOW_AUTOSIZE);
	}

	// Init matrices
	frameCaptured = new Mat(480,640,CV_8UC4);	// Warning: this assumes the resolution and 4 channel color depth

	// Initialize socket communication and server socket
	server.InitServer(configManager.serverPort);
}
示例#2
0
文件: main.cpp 项目: smeyel/LibTests
void main()
{
	// ============= Direct test of logger

	Logger *logger = new StdoutLogger();
	logger->SetLogLevel(Logger::LOGLEVEL_INFO);

	logger->Log(Logger::LOGLEVEL_INFO,"DirectTest","DirectTest message on info level.\n",1);
	logger->SetLogLevel(Logger::LOGLEVEL_VERBOSE);
	logger->Log(Logger::LOGLEVEL_INFO,"DirectTest","Not appearing DirectTest message on info level.\n",1);

	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"SingletonTest","Appearing singleton test...\n");


	int i=12;

	FileLogger loggerF("d:\\e3.txt");

	Logger::getInstance()->Log(Logger::LOGLEVEL_ERROR,"TAG","Szam:%d %d %s %d\n",1,2,"Hello",3);

	loggerF.close();


	// ============ Direct test of ConfigReader

	SimpleIniConfigReader *SIreader = new SimpleIniConfigReader("test.ini");
	ConfigReader *reader = SIreader;

	bool boolean1 = reader->getBoolValue("main","boolean1");
	bool boolean2 = reader->getBoolValue("main","boolean2");
	bool boolean3 = reader->getBoolValue("main","boolean3");
	const char *str = reader->getStringValue("main","string");
	int integer1 = ConfigReader::getInstance()->getIntValue("main","integer");

	std::cout << "Bools: " << boolean1 << ", " << boolean2 << ", " << boolean3 << std::endl;
	std::cout << "Integer: " << integer1 << std::endl;
	std::cout << "String: " << str << std::endl;

}
示例#3
0
int init(void) {
    iniFile = (char*) SendMessage(plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_GETINIFILE);
    if (! mlOrgConfig.LoadConfiguration(iniFile)) {
        logger.Error("ml_org::init()", "could not load configuration");
        return 1;
    }

    logger.SetLogLevel(mlOrgConfig.m_logLevel);
    logger.SetLogfile(mlOrgConfig.m_logfile);

    // Grab ahold of the window function pointer so we can do our own thang
    // when someone presses the "Organize Media Library" menu item
    mlWndproc = (WNDPROC) SetWindowLongPtr(plugin.hwndLibraryParent,
                                           GWLP_WNDPROC, (LONG) winproc);
    if (mlWndproc == 0) {
        int error = GetLastError();
        sprintf(tmp, "could not get window func ptr (%d)", error);
        logger.Error("ml_org::init()", tmp);
        return error;
    }

    logger.Info("ml_org::init()", "plugin initialized");
    return 0;
}
示例#4
0
文件: main.cpp 项目: smeyel/M2
/** Implementation of M2 scenario
*/
int main(int argc, char *argv[])
{
	if (argc>=2)
	{
		// INI file is given as command line parameter
		configfilename = argv[1];
	}
	// Setup config management
	configManager.init(configfilename);

	// Setup statistics output file
	Logger *logger = new FileLogger(configManager.logFileName.c_str());
	logger->SetLogLevel(Logger::LOGLEVEL_INFO);
	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"M2Host","M2Host started\n");

	cout << "Log is written to: " << configManager.logFileName << endl;

	// Write current time and date to log
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"M2Host","Current time: %d-%d-%d, %d:%d:%d\n",
		(now->tm_year + 1900),(now->tm_mon + 1),now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec );

	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"M2Host","Configuration: %s\n",configfilename);
	Logger::getInstance()->Log(Logger::LOGLEVEL_VERBOSE,"M2Host","Local measurement log: %s\nRemote measurement log: %s\n",
		configManager.localMLogFilename.c_str(), configManager.remoteMLogFilename.c_str());

	// Setup time management
	// Waiting a little to allow other processes to init...
	// Useful if started together with CamClient which needs to start its server.
	cout << "Waiting 3s..." << endl;
#ifdef WIN32
	Sleep(3000);
#else
#error TODO: Sleep not implemented for non-Win32.
#endif

	const bool useLocalCamera=true;

	CameraProxy *camProxy = NULL;
	CameraRemoteProxy *camRemoteProxy = NULL;
	CameraLocalProxy *camLocalProxy = NULL;
	if (useLocalCamera)
	{
		camProxy = camLocalProxy = new CameraLocalProxy(VIDEOINPUTTYPE_PS3EYE,0);
	}
	else
	{
		camProxy = camRemoteProxy = new CameraRemoteProxy();
	}

	// Prepare camera and detector objects
	//ChessboardDetector detector(Size(9,6),36.1);	// Chessboard cell size is 36x36mm, using CameraProxy default
	camProxy->camera->cameraID=0;
	camProxy->camera->isStationary=false;
	camProxy->camera->loadCalibrationData(configManager.camIntrinsicParamsFileName.data());

	if (camRemoteProxy)
	{
		cout << "Connecting..." << endl;
		camRemoteProxy->Connect(configManager.phoneIpAddress.c_str(),configManager.phonePort);
	}

	// --------------------------- Execute main task
	cout << "Main task started" << endl;

	// ---Currently, multiple possible measurements are supported.
	// - Original "capture 100 frames and report capture times" measurement
	//camRemoteProxy->PerformCaptureSpeedMeasurement_A(100,configManager.MLogFilename.c_str());
	// - Reading TimeSyncBeacon measurement
	M2_TimeSyncTest(camProxy,10);

	cout << "Main task finished" << endl;
	// --------------------------- Closing...
	if (camRemoteProxy)
	{
		cout << "Disconnecting..." << endl;
		camRemoteProxy->Disconnect();
	}

	delete camProxy;
	cout << "Done." << endl;
}
示例#5
0
int main(int argc,char**argv)
{
 int port=5566;
 string address="127.0.0.1";
  
 printf("This program is going to test:\n");
 printf("   * the dataType consistency\n");
 printf("   * Port used for the communication is %d.\n",port);
 printf("   * Addressed used for the communication is '%s'.\n",address.c_str());
 printf("   * Logger.\n");
 printf("\n");

 Logger l;

 printf("-> Constructing Publisher\n");
	 Publisher pub;
 //printf("-> Constructing Context\n");
	 //zmq::context_t context(2);

 // ActivateLog
 printf("-> Config Log\n");
	l.SetLogLevel(3);
 	l.SetAsync();
 	l.SetFileName("/tmp/log.txt");
 	l.Init();
 printf("-> Activate Logs\n");
 	pub.LogInit(&l);
 //Configure
 printf("-> Setting port\n");
 	pub.SetPort(port);
 //printf("-> Setting Context\n");
 	//pub.SetContext(&context);

 //pub.SetAsync();
 //Init Sockets
 printf("-> Init Publisher\n");
 	pub.Init();

 printf("-> Sleep\n");
 sleep(10);
 //Init Mex
 printf("-> Init Mex\n");
	 dataType mexSend, mexRecv;
	 char mex[]="Ciao\0da\0Andrea";
 printf("-> Append to Send\n");
	 mexSend.append((void*)mex,14);

 printf("-> Send Dummy\n");
	pub.SendMessage(mexSend);

 printf("-> Send\n");
	 pub.SendMessage(mexSend);

 printf("-> Sleep\n");
 sleep(10);
 string toprint=Utility::AsciiData(mexSend.data(),mexSend.size() );
 printf("%s",toprint.c_str());

 sleep(1);
 printf("-> Calling Destructors and exit\n");
// printf("---> Pub\n");
// pub.~Publisher();
// printf("---> Log\n");
// l.~Logger();
// printf("---> Mex\n");
// mexSend.~dataType();
// mexRecv.~dataType();
// printf("---> Context\n");
// context.~context_t();
 printf("---> Everything Else\n");
// printf("---> Log\n");
// l.~Logger();

 return 0;
}
示例#6
0
int main(int argc, char**argv)
{
/*
 *  this is the main loop of the controller.
 */
// define Handlers for sigint
define_handlers();

 int opt= 0;

 int verbose=1;
 string configFileName="";
 string logFileName="";

 static struct option long_options[] = {
   {"config",    required_argument, 0,  'c' },
   {"log",    required_argument, 0,  'l' },
   {"verbose",    required_argument, 0,  'v' },
   {0,           0,                 0,  0   }
 };
 
 int long_index =0;
 while ((opt = getopt_long(argc, argv,"c:l:v:", 
			   long_options, &long_index )) != -1) {
   switch (opt) {
   case 'c' : configFileName=string(optarg);
     break;
   case 'l' : logFileName=string(optarg);
     break;
   case 'v' : verbose=atoi(optarg);
     break;
   case '?':
     /* getopt_long already printed an error message. */
     print_usage(); 
     exit(EXIT_FAILURE);
   default: print_usage(); 
     exit(EXIT_FAILURE);
   }
 }

 if ( configFileName == "" ) 
   {
     print_usage(); 
     exit(EXIT_FAILURE);
   }
// -----------------
//string logFileName="/tmp/logRC.txt";
Logger l;

try
  {
    printf("[RunControllerDaemon]::Init Logfile => %s\n",logFileName.c_str());
    l.SetLogLevel(verbose);
    l.SetFileName(logFileName);
    l.Init();
  }
 catch (logfile_open_exception &l)
   {
     printf("Cannot Open Log File: %s\n",logFileName.c_str());
     exit(EXIT_FAILURE);
   }

//
//Daemon *d=new Daemon();
printf("RC\n");
DummyRunControlFSM *d=new DummyRunControlFSM();
printf("INIT\n");
//d->Init("data/configRC.xml");
printf("[RunControllerDaemon]::Init Configfile => %s\n",configFileName.c_str());
d->LogInit(&l);
d->Init(configFileName);
try{
	printf("LOOP\n");
	d->Loop();
   }
   catch (sigint_exception &e) { printf("%s\n",e.what());}

printf("CLEAR\n");
d->Clear();
return 0;
}
示例#7
0
int main(int argc,char**argv)
{
 int port=5566;
 string address="127.0.0.1";
  
 printf("This program is going to test:\n");
 printf("   * the dataType consistency\n");
 printf("   * the publisher and subscriber ability to handle it\n");
 printf("   * Port used for the communication is %d.\n",port);
 printf("   * Addressed used for the communication is '%s'.\n",address.c_str());
 printf("   * Logger.\n");
 printf("\n");

 Logger l;

 printf("-> Constructing Publisher\n");
	 Publisher pub;
 printf("-> Constructing Subscriber\n");
	 Subscriber sub;
 //printf("-> Constructing Context\n");
	 //zmq::context_t context(2);

 // ActivateLog
 printf("-> Config Log\n");
	l.SetLogLevel(3);
 	//l.SetAsync();
 	l.SetFileName("/tmp/log.txt");
 	l.Init();
 printf("-> Activate Logs\n");
 	sub.LogInit(&l);
 	pub.LogInit(&l);
 //Configure
 printf("-> Setting port\n");
 	pub.SetPort(port);
 printf("-> Setting port/address\n");
 	sub.SetAddress(address,port);
 //printf("-> Setting Context\n");
 	//pub.SetContext(&context);
 	//sub.SetContext(&context);

 //pub.SetAsync();
 //Init Sockets
 printf("-> Init Publisher\n");
 	pub.Init();
 printf("-> Init subscriber\n");
	sub.Init();

 //Init Mex
 printf("-> Init Mex\n");
	 dataType mexSend, mexRecv;
	 char mex[]="Ciao\0da\0Andrea";
 printf("-> Append to Send\n");
	 mexSend.append((void*)mex,14);

 printf("-> Send Dummy\n");
	int rc=1;
	rc=sub.RecvMessage(mexRecv);
	pub.SendMessage(mexSend);
 printf("-> Recv Dummy\n");
	//while (rc) { rc=sub.RecvMessage(mexRecv); printf("Cycle\n"); sleep(1);}
	rc=sub.RecvMessage(mexRecv);

 printf("-> Send\n");
	 pub.SendMessage(mexSend);
 printf("-> Recv\n");
 	rc=1;
	while (rc) { rc=sub.RecvMessage(mexRecv); printf("Cycle\n"); sleep(2);}


 printf("-> Verify content of size %d == %d\n",mexSend.size(),mexRecv.size());
 if (mexSend == mexRecv)printf(" ------ SUCCESS -------\n");
 else printf(" ------ FAIL -------\n");

 // for(int i=0;i<mexSend.size();i++)
 // {
 //        char c1='\0';
 //        if(i<mexSend.size())c1=((char*)mexSend.data())[i];
 //        char c2='\0';
 //        if(i<mexRecv.size())c2=((char*)mexRecv.data())[i];
 //        printf(" %02X %02X\n",c1,c2);	
 // }
 string toprint=Utility::AsciiData(mexSend.data(),mexRecv.data(),mexSend.size() );
 printf("%s",toprint.c_str());

 sleep(1);
 printf("-> Calling Destructors and exit\n");
}