예제 #1
0
int main(int argc, char**argv)
#endif
{
#if defined WIN32
#ifndef _DEBUG
    CreateMutexA(0, FALSE, "Local\\Domoticz");
    if(GetLastError() == ERROR_ALREADY_EXISTS) {
        MessageBox(HWND_DESKTOP,"Another instance of Domoticz is already running!","Domoticz",MB_OK);
        return 1;
    }
#endif //_DEBUG
    bool bStartWebBrowser = true;
    RedirectIOToConsole();
#endif //WIN32

    szStartupFolder = "";
    szWWWFolder = "";
    szWebRoot = "";

    CCmdLine cmdLine;

    // parse argc,argv
#if defined WIN32
    cmdLine.SplitLine(__argc, __argv);
#else
    cmdLine.SplitLine(argc, argv);
    //ignore pipe errors
    signal(SIGPIPE, SIG_IGN);
#endif

    if (cmdLine.HasSwitch("-log"))
    {
        if (cmdLine.GetArgumentCount("-log") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify an output log file");
            return 1;
        }
        logfile = cmdLine.GetSafeArgument("-log", 0, "domoticz.log");
        _log.SetOutputFile(logfile.c_str());
    }
    if (cmdLine.HasSwitch("-loglevel"))
    {
        if (cmdLine.GetArgumentCount("-loglevel") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify logfile output level (0=All, 1=Status+Error, 2=Error)");
            return 1;
        }
        int Level = atoi(cmdLine.GetSafeArgument("-loglevel", 0, "").c_str());
        _log.SetVerboseLevel((_eLogFileVerboseLevel)Level);
    }
    if (cmdLine.HasSwitch("-notimestamps"))
    {
        _log.EnableLogTimestamps(false);
    }

    if (cmdLine.HasSwitch("-approot"))
    {
        if (cmdLine.GetArgumentCount("-approot") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a APP root path");
            return 1;
        }
        std::string szroot = cmdLine.GetSafeArgument("-approot", 0, "");
        if (szroot.size() != 0)
            szStartupFolder = szroot;
    }

    if (szStartupFolder == "")
    {
#if !defined WIN32
        char szStartupPath[255];
        getExecutablePathName((char*)&szStartupPath,255);
        szStartupFolder=szStartupPath;
        if (szStartupFolder.find_last_of('/')!=std::string::npos)
            szStartupFolder=szStartupFolder.substr(0,szStartupFolder.find_last_of('/')+1);
#else
#ifndef _DEBUG
        char szStartupPath[255];
        char * p;
        GetModuleFileName(NULL, szStartupPath, sizeof(szStartupPath));
        p = szStartupPath + strlen(szStartupPath);

        while (p >= szStartupPath && *p != '\\')
            p--;

        if (++p >= szStartupPath)
            *p = 0;
        szStartupFolder=szStartupPath;
        size_t start_pos = szStartupFolder.find("\\Release\\");
        if(start_pos != std::string::npos) {
            szStartupFolder.replace(start_pos, 9, "\\domoticz\\");
            _log.Log(LOG_STATUS,"%s",szStartupFolder.c_str());
        }
#endif
#endif
    }
    GetAppVersion();
    _log.Log(LOG_STATUS, "Domoticz V%s (c)2012-%d GizMoCuz", szAppVersion.c_str(), ActYear);
    _log.Log(LOG_STATUS, "Build Hash: %s, Date: %s", szAppHash.c_str(), szAppDate.c_str());

#if !defined WIN32
    //Check if we are running on a RaspberryPi
    std::string sLine = "";
    std::ifstream infile;

    infile.open("/proc/cpuinfo");
    if (infile.is_open())
    {
        while (!infile.eof())
        {
            getline(infile, sLine);
            if (
                (sLine.find("BCM2708")!=std::string::npos)||
                (sLine.find("BCM2709")!=std::string::npos)
            )
            {
                //Core temperature of BCM2835 SoC
                _log.Log(LOG_STATUS,"System: Raspberry Pi");
                szInternalTemperatureCommand="/opt/vc/bin/vcgencmd measure_temp";
                bHasInternalTemperature=true;
                break;
            }
        }
        infile.close();
    }
    if (!bHasInternalTemperature)
    {
        if (file_exist("/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input"))
        {
            _log.Log(LOG_STATUS,"System: Cubieboard/Cubietruck");
            szInternalTemperatureCommand="cat /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input | awk '{ printf (\"temp=%0.2f\\n\",$1/1000); }'";
            bHasInternalTemperature = true;
        }
        else if (file_exist("/sys/devices/virtual/thermal/thermal_zone0/temp"))
        {
            //_log.Log(LOG_STATUS,"System: ODroid");
            szInternalTemperatureCommand="cat /sys/devices/virtual/thermal/thermal_zone0/temp | awk '{ printf (\"temp=%0.2f\\n\",$1/1000); }'";
            bHasInternalTemperature = true;
        }
    }
    if (file_exist("/sys/class/power_supply/ac/voltage_now"))
    {
        szInternalVoltageCommand = "cat /sys/class/power_supply/ac/voltage_now | awk '{ printf (\"volt=%0.2f\\n\",$1/1000000); }'";
        bHasInternalVoltage = true;
    }
    if (file_exist("/sys/class/power_supply/ac/current_now"))
    {
        szInternalCurrentCommand = "cat /sys/class/power_supply/ac/current_now | awk '{ printf (\"curr=%0.2f\\n\",$1/1000000); }'";
        bHasInternalCurrent = true;
    }
    _log.Log(LOG_STATUS,"Startup Path: %s", szStartupFolder.c_str());
#endif

    szWWWFolder = szStartupFolder + "www";

    if ((cmdLine.HasSwitch("-h")) || (cmdLine.HasSwitch("--help")) || (cmdLine.HasSwitch("/?")))
    {
        _log.Log(LOG_NORM, szHelp);
        return 0;
    }

    szUserDataFolder=szStartupFolder;
    if (cmdLine.HasSwitch("-userdata"))
    {
        if (cmdLine.GetArgumentCount("-userdata") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a path for user data to be stored");
            return 1;
        }
        std::string szroot = cmdLine.GetSafeArgument("-userdata", 0, "");
        if (szroot.size() != 0)
            szUserDataFolder = szroot;
    }

    if (cmdLine.HasSwitch("-startupdelay"))
    {
        if (cmdLine.GetArgumentCount("-startupdelay") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a startupdelay");
            return 1;
        }
        int DelaySeconds = atoi(cmdLine.GetSafeArgument("-startupdelay", 0, "").c_str());
        _log.Log(LOG_STATUS, "Startup delay... waiting %d seconds...", DelaySeconds);
        sleep_seconds(DelaySeconds);
    }

    if (cmdLine.HasSwitch("-wwwbind"))
    {
        if (cmdLine.GetArgumentCount("-wwwbind") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify an address");
            return 1;
        }
        std::string wwwbind = cmdLine.GetSafeArgument("-wwwbind", 0, "0.0.0.0");
        m_mainworker.SetWebserverAddress(wwwbind);
    }

    if (cmdLine.HasSwitch("-www"))
    {
        if (cmdLine.GetArgumentCount("-www") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a port");
            return 1;
        }
        std::string wwwport = cmdLine.GetSafeArgument("-www", 0, "8080");
        if (wwwport == "0")
            wwwport.clear();//HTTP server disabled
        m_mainworker.SetWebserverPort(wwwport);
    }
#ifdef NS_ENABLE_SSL
    if (cmdLine.HasSwitch("-sslwww"))
    {
        if (cmdLine.GetArgumentCount("-sslwww") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a port");
            return 1;
        }
        std::string wwwport = cmdLine.GetSafeArgument("-sslwww", 0, "443");
        if (wwwport == "0")
            wwwport.clear();//HTTPS server disabled
        m_mainworker.SetSecureWebserverPort(wwwport);
    }
    if (cmdLine.HasSwitch("-sslcert"))
    {
        if (cmdLine.GetArgumentCount("-sslcert") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify the file path");
            return 1;
        }
        std::string ca_cert = cmdLine.GetSafeArgument("-sslcert", 0, "./server_cert.pem");
        m_mainworker.SetSecureWebserverCert(ca_cert);
    }
    if (cmdLine.HasSwitch("-sslpass"))
    {
        if (cmdLine.GetArgumentCount("-sslpass") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a passphrase for your certificate file");
            return 1;
        }
        std::string ca_passphrase = cmdLine.GetSafeArgument("-sslpass", 0, "");
        m_mainworker.SetSecureWebserverPass(ca_passphrase);
    }
#endif
    if (cmdLine.HasSwitch("-nowwwpwd"))
    {
        m_mainworker.m_bIgnoreUsernamePassword = true;
    }
    if (cmdLine.HasSwitch("-nocache"))
    {
        g_bDontCacheWWW = true;
    }
    std::string dbasefile = szUserDataFolder + "domoticz.db";
#ifdef WIN32
#ifndef _DEBUG
    if (!IsUserAnAdmin())
    {
        char szPath[MAX_PATH];
        HRESULT hr = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath);
        if (SUCCEEDED(hr))
        {
            std::string sPath = szPath;
            sPath += "\\Domoticz";

            DWORD dwAttr = GetFileAttributes(sPath.c_str());
            BOOL bDirExists = (dwAttr != 0xffffffff && (dwAttr & FILE_ATTRIBUTE_DIRECTORY));
            if (!bDirExists)
            {
                BOOL bRet = CreateDirectory(sPath.c_str(), NULL);
                if (bRet == FALSE) {
                    MessageBox(0, "Error creating Domoticz directory in program data folder (%ProgramData%)!!", "Error:", MB_OK);
                }
            }
            sPath += "\\domoticz.db";
            dbasefile = sPath;
        }
    }
#endif
#endif

    if (cmdLine.HasSwitch("-dbase"))
    {
        if (cmdLine.GetArgumentCount("-dbase") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a Database Name");
            return 1;
        }
        dbasefile = cmdLine.GetSafeArgument("-dbase", 0, "domoticz.db");
    }
    m_sql.SetDatabaseName(dbasefile);

    if (cmdLine.HasSwitch("-wwwroot"))
    {
        if (cmdLine.GetArgumentCount("-wwwroot") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a WWW root path");
            return 1;
        }
        std::string szroot = cmdLine.GetSafeArgument("-wwwroot", 0, "");
        if (szroot.size() != 0)
            szWWWFolder = szroot;
    }

    if (cmdLine.HasSwitch("-webroot"))
    {
        if (cmdLine.GetArgumentCount("-webroot") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a web root path");
            return 1;
        }
        std::string szroot = cmdLine.GetSafeArgument("-webroot", 0, "");
        if (szroot.size() != 0)
            szWebRoot = szroot;
    }

    if (cmdLine.HasSwitch("-verbose"))
    {
        if (cmdLine.GetArgumentCount("-verbose") != 1)
        {
            _log.Log(LOG_ERROR, "Please specify a verbose level");
            return 1;
        }
        int Level = atoi(cmdLine.GetSafeArgument("-verbose", 0, "").c_str());
        m_mainworker.SetVerboseLevel((eVerboseLevel)Level);
    }
#if defined WIN32
    if (cmdLine.HasSwitch("-nobrowser"))
    {
        bStartWebBrowser = false;
    }
    //Init WinSock
    WSADATA data;
    WORD version;

    version = (MAKEWORD(2, 2));
    int ret = WSAStartup(version, &data);
    if (ret != 0)
    {
        ret = WSAGetLastError();

        if (ret == WSANOTINITIALISED)
        {
            _log.Log(LOG_ERROR, "Error: Winsock could not be initialized!");
        }
    }
    CoInitializeEx(0, COINIT_MULTITHREADED);
    CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
#endif
#ifndef WIN32
    if (cmdLine.HasSwitch("-daemon"))
    {
        g_bRunAsDaemon = true;
    }

    std::string daemonname = DAEMON_NAME;
    if (cmdLine.HasSwitch("-daemonname"))
    {
        daemonname = cmdLine.GetSafeArgument("-daemonname", 0, DAEMON_NAME);
    }

    std::string pidfile = PID_FILE;
    if (cmdLine.HasSwitch("-pidfile"))
    {
        pidfile = cmdLine.GetSafeArgument("-pidfile", 0, PID_FILE);
    }

    if ((g_bRunAsDaemon)||(g_bUseSyslog))
    {
        setlogmask(LOG_UPTO(LOG_INFO));
        openlog(daemonname.c_str(), LOG_CONS | LOG_PERROR, LOG_USER);

        syslog(LOG_INFO, "Domoticz is starting up....");
    }

    if (g_bRunAsDaemon)
    {
        /* Deamonize */
        daemonize(szStartupFolder.c_str(), pidfile.c_str());
    }
    if ((g_bRunAsDaemon) || (g_bUseSyslog))
    {
        syslog(LOG_INFO, "Domoticz running...");
    }
#endif

    if (!g_bRunAsDaemon)
    {
        signal(SIGINT, signal_handler);
        signal(SIGTERM, signal_handler);
    }

    if (!m_mainworker.Start())
    {
        return 1;
    }
    m_StartTime = time(NULL);

    /* now, lets get into an infinite loop of doing nothing. */
#if defined WIN32
#ifndef _DEBUG
    RedirectIOToConsole();	//hide console
#endif
    InitWindowsHelper(hInstance, hPrevInstance, nShowCmd, m_mainworker.GetWebserverAddress(), atoi(m_mainworker.GetWebserverPort().c_str()), bStartWebBrowser);
    MSG Msg;
    while (!g_bStopApplication)
    {
        if (PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if (GetMessage(&Msg, NULL, 0, 0) > 0)
            {
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
            }
        }
        else
            sleep_milliseconds(100);
    }
    TrayMessage(NIM_DELETE, NULL);
#else
    while ( !g_bStopApplication )
    {
        sleep_seconds(1);
    }
#endif
    _log.Log(LOG_STATUS, "Closing application!...");
    fflush(stdout);
    _log.Log(LOG_STATUS, "Stopping worker...");
    try
    {
        m_mainworker.Stop();
    }
    catch (...)
    {

    }
#ifndef WIN32
    if (g_bRunAsDaemon)
    {
        syslog(LOG_INFO, "Domoticz stopped...");
        daemonShutdown();

        // Delete PID file
        remove(pidfile.c_str());
    }
#else
    // Release WinSock
    WSACleanup();
    CoUninitialize();
#endif
    return 0;
}
예제 #2
0
int main(int argc, char *argv[]){
	Fgwas_params p;

    CCmdLine cmdline;
    if (cmdline.SplitLine(argc, argv) < 1){
        printopts();
        exit(1);
    }
    //get the input file
    if (cmdline.HasSwitch("-i")) p.infile = cmdline.GetArgument("-i", 0).c_str();
    else{
    	cerr << "ERROR: missing input file (-i)\n";
        printopts();
        exit(1);
    }
    //get the output file
    if (cmdline.HasSwitch("-o")) p.outstem = cmdline.GetArgument("-o", 0);
    if (cmdline.HasSwitch("-pcond")) printcond = true;
    if (cmdline.HasSwitch("-v")) {
     	p.V.clear();
     	vector<string> strs;
     	string s = cmdline.GetArgument("-v", 0);
     	boost::split(strs, s ,boost::is_any_of(","));
     	for (int i  = 0; i < strs.size(); i++) {
     		p.V.push_back( atof(strs[i].c_str()) );
     	}
     }
    //LD file
    if (cmdline.HasSwitch("-ld")) {
    	p.overlap = true;
    	p.ldfile = cmdline.GetArgument("-ld", 0);
    	if (cmdline.HasSwitch("-nhap")) p.Nhap = atoi(cmdline.GetArgument("-nhap", 0).c_str());
    	else{
    		cerr << "ERROR: inputing LD matrix, -nhap flag\n";
    	   	printopts();
    	   	exit(1);
    	}
    }
    else if (cmdline.HasSwitch("-cor")){
    	//cerr << "WARNING: including correlation, did you mean to include an LD file?\n";
    	//printopts();
    	//exit(1);
    }
    if (cmdline.HasSwitch("-rev")) p.rev = true;
    if (cmdline.HasSwitch("-numbered")) p.numberedseg = true;
    //set K
    if (cmdline.HasSwitch("-k")) p.K = atoi(cmdline.GetArgument("-k", 0).c_str());
    if (cmdline.HasSwitch("-bed")) {
    	p.bedseg = true;
    	p.segment_bedfile = cmdline.GetArgument("-bed", 0);
    }

    if (cmdline.HasSwitch("-noprint")) p.print = false;

    //names of the phenotypes, expecting header like NAME1_Z NAME1_V NAME2_Z NAME2_V
    if (cmdline.HasSwitch("-phenos")){
     	p.pairwise = true;
     	p.pheno1 = cmdline.GetArgument("-phenos", 0);
     	p.pheno2 = cmdline.GetArgument("-phenos", 1);
     }
    else{
    	cerr << "ERROR: missing phenotypes (-pheno)\n";
        printopts();
        exit(1);
    }
    /*
    if (cmdline.HasSwitch("-w")){
    	vector<string> strs;
    	string s = cmdline.GetArgument("-w", 0);
    	boost::split(strs, s ,boost::is_any_of("+"));
    	for (int i  = 0; i < strs.size(); i++) {
    		p.wannot.push_back( strs[i] );
    	}
    }
    if (cmdline.HasSwitch("-dists")){
     	vector<string> strs;
     	string s = cmdline.GetArgument("-dists", 0);
     	boost::split(strs, s ,boost::is_any_of("+"));
     	for (int i  = 0; i < strs.size(); i++) {
     		vector<string> strs2;
     		boost::split(strs2, strs[i], boost::is_any_of(":"));
     		p.dannot.push_back( strs2[0] );
     		p.distmodels.push_back(strs2[1]);
     	}
     }
    if (cmdline.HasSwitch("-drop")){
    	p.dropchr = true;
    	string s = cmdline.GetArgument("-drop", 0);
    	p.chrtodrop = s;
    }


    if (cmdline.HasSwitch("-dens")) {
    	p.segannot.push_back(cmdline.GetArgument("-dens", 0));
    	p.loquant = atof(cmdline.GetArgument("-dens", 1).c_str());
    	p.hiquant = atof(cmdline.GetArgument("-dens", 2).c_str());
    }
    */
    if (cmdline.HasSwitch("-fine")) p.finemap = true;
    if (cmdline.HasSwitch("-mcmc")) p.MCMC = true;
    if (cmdline.HasSwitch("-seed")){
    	p.seed = atoi(cmdline.GetArgument("-seed", 0).c_str());
    }
    else p.seed = unsigned( time(NULL));
    if (cmdline.HasSwitch("-nburn")){
     	p.burnin = atoi(cmdline.GetArgument("-nburn", 0).c_str());
    }
    if (cmdline.HasSwitch("-nsamp")){
      	p.nsamp = atoi(cmdline.GetArgument("-nsamp", 0).c_str());
     }
    if (cmdline.HasSwitch("-jumpsd")){
      	p.MCMC_gauss_SD = atof(cmdline.GetArgument("-jumpsd", 0).c_str());
     }
    if (cmdline.HasSwitch("-cor")){
        	p.cor = atof(cmdline.GetArgument("-cor", 0).c_str());
        	//p.overlap = true;
       }
    if (cmdline.HasSwitch("-prior")){
    	if (cmdline.GetArgumentCount("-prior") != 5) {
    		cerr << "ERROR: -prior needs 5 entries, "<< cmdline.GetArgumentCount("-prior") << " given\n";
    		exit(1);
    	}

       	p.alpha_prior[0] = atof(cmdline.GetArgument("-prior", 0).c_str());
       	p.alpha_prior[1] = atof(cmdline.GetArgument("-prior", 1).c_str());
       	p.alpha_prior[2] = atof(cmdline.GetArgument("-prior", 2).c_str());
       	p.alpha_prior[3] = atof(cmdline.GetArgument("-prior", 3).c_str());
       	p.alpha_prior[4] = atof(cmdline.GetArgument("-prior", 4).c_str());
      }


      //random number generator
    const gsl_rng_type * T;
    gsl_rng * r;
    gsl_rng_env_setup();
    T = gsl_rng_ranlxs2;
    r = gsl_rng_alloc(T);
    int seed = (int) time(0);
    gsl_rng_set(r, p.seed);


    SNPs_PW s(&p);
    if (printcond) s.get_all_condZ();
    s.GSL_optim();
    vector<double> ml;
    for (int i = 0; i < 5; i++)ml.push_back(s.pi[i]);

    vector<pair<pair<int, int>, pair<double, double> > > cis = s.get_cis();
	string outML = p.outstem+".MLE";
	ofstream outr(outML.c_str());
	int sti = 0;
	if (p.finemap) sti = 1;
	for (int i = sti; i < 5; i++){
		outr << "pi_"<< i <<" "<< cis.at(i-sti).second.first << " "<< ml[i]<< " "<< cis.at(i-sti).second.second << "\n";
	}
	outr.close();
    if (p.MCMC) s.MCMC(r);
	if (p.print) s.print(p.outstem+".bfs.gz", p.outstem+".segbfs.gz");
	//if (p.finemap) return 0;


	return 0;
}
예제 #3
0
int main(int argc, char**argv)
#endif
{
#if defined WIN32
	CreateMutexA(0, FALSE, "Local\\Domoticz"); 
    if(GetLastError() == ERROR_ALREADY_EXISTS) { 
		MessageBox(HWND_DESKTOP,"Another instance of Domoticz is already running!","Domoticz",MB_OK);
        return -1; 
	}
	bool bStartWebBrowser=true;
	RedirectIOToConsole();
#endif

	szStartupFolder="";
	szWWWFolder="";
#if !defined WIN32
	char szStartupPath[255];
	getExecutablePathName((char*)&szStartupPath,255);
	szStartupFolder=szStartupPath;
	if (szStartupFolder.find_last_of('/')!=std::string::npos)
		szStartupFolder=szStartupFolder.substr(0,szStartupFolder.find_last_of('/')+1);
#else
	#ifndef _DEBUG
		char szStartupPath[255];
		char * p;
		GetModuleFileName(NULL, szStartupPath, sizeof(szStartupPath));
		p = szStartupPath + strlen(szStartupPath);

		while(p >= szStartupPath && *p != '\\')
			p--;

		if(++p >= szStartupPath)
			*p = 0;
		szStartupFolder=szStartupPath;
		size_t start_pos = szStartupFolder.find("\\Release\\");
		if(start_pos != std::string::npos) {
			szStartupFolder.replace(start_pos, 9, "\\domoticz\\");
			_log.Log(LOG_NORM,"%s",szStartupFolder.c_str());
		}
	#endif
#endif
	GetAppVersion();
	_log.Log(LOG_NORM,"Domoticz V%s (c)2012-2014 GizMoCuz",szAppVersion.c_str());

#if !defined WIN32
	//Check if we are running on a RaspberryPi
	std::string sLine = "";
	std::ifstream infile;

	infile.open("/proc/cpuinfo");
	if (infile.is_open())
	{
		while (!infile.eof())
		{
			getline(infile, sLine);
			if (sLine.find("BCM2708")!=std::string::npos)
			{
				_log.Log(LOG_NORM,"System: Raspberry Pi");
				bIsRaspberryPi=true;
				break;
			}
		}
		infile.close();
	}
	_log.Log(LOG_NORM,"Startup Path: %s", szStartupFolder.c_str());
#endif

	szWWWFolder=szStartupFolder+"www";

	CCmdLine cmdLine;

	// parse argc,argv 
#if defined WIN32
	cmdLine.SplitLine(__argc, __argv);
#else
	cmdLine.SplitLine(argc, argv);
#endif

	if ((cmdLine.HasSwitch("-h"))||(cmdLine.HasSwitch("--help"))||(cmdLine.HasSwitch("/?")))
	{
		_log.Log(LOG_NORM,szHelp);
		return 0;
	}

	if (cmdLine.HasSwitch("-startupdelay"))
	{
		if (cmdLine.GetArgumentCount("-startupdelay")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify a startupdelay");
			return 0;
		}
		int DelaySeconds=atoi(cmdLine.GetSafeArgument("-startupdelay",0,"").c_str());
		_log.Log(LOG_NORM,"Startup delay... waiting %d seconds...",DelaySeconds);
		sleep_seconds(DelaySeconds);
	}

	if (cmdLine.HasSwitch("-www"))
	{
		if (cmdLine.GetArgumentCount("-www")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify a port");
			return 0;
		}
		std::string wwwport=cmdLine.GetSafeArgument("-www",0,"8080");
		_mainworker.SetWebserverPort(wwwport);
	}
	if (cmdLine.HasSwitch("-nowwwpwd"))
	{
		_mainworker.m_bIgnoreUsernamePassword=true;
	}

	std::string dbasefile=szStartupFolder + "domoticz.db";
#ifdef WIN32
	if (!IsUserAnAdmin())
	{
		char szPath[MAX_PATH];
		HRESULT hr = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath);
		if (SUCCEEDED(hr))
		{
			std::string sPath=szPath;
			sPath+="\\Domoticz";

			DWORD dwAttr = GetFileAttributes(sPath.c_str());
			BOOL bDirExists=(dwAttr != 0xffffffff && (dwAttr & FILE_ATTRIBUTE_DIRECTORY));
			if (!bDirExists)
			{
				BOOL bRet=CreateDirectory(sPath.c_str(),NULL);
				if (bRet==FALSE) {
					MessageBox(0,"Error creating Domoticz directory in program data folder (%ProgramData%)!!","Error:",MB_OK);
				}
			}
			sPath+="\\domoticz.db";
			dbasefile=sPath;
		}
	}
#endif

	if (cmdLine.HasSwitch("-dbase"))
	{
		if (cmdLine.GetArgumentCount("-dbase")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify a Database Name");
			return 0;
		}
		dbasefile=cmdLine.GetSafeArgument("-dbase",0,"domoticz.db");
	}
	_mainworker.m_sql.SetDatabaseName(dbasefile);

	if (cmdLine.HasSwitch("-wwwroot"))
	{
		if (cmdLine.GetArgumentCount("-wwwroot")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify a WWW root path");
			return 0;
		}
		std::string szroot=cmdLine.GetSafeArgument("-wwwroot",0,"");
		if (szroot.size()!=0)
			szWWWFolder=szroot;
	}

	if (cmdLine.HasSwitch("-verbose"))
	{
		if (cmdLine.GetArgumentCount("-verbose")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify a verbose level");
			return 0;
		}
		int Level=atoi(cmdLine.GetSafeArgument("-verbose",0,"").c_str());
		_mainworker.SetVerboseLevel((eVerboseLevel)Level);
	}
#if defined WIN32
	if (cmdLine.HasSwitch("-nobrowser"))
	{
		bStartWebBrowser=false;
	}
#endif
	if (cmdLine.HasSwitch("-log"))
	{
		if (cmdLine.GetArgumentCount("-log")!=1)
		{
			_log.Log(LOG_ERROR,"Please specify an output log file");
			return 0;
		}
		std::string logfile=cmdLine.GetSafeArgument("-log",0,"domoticz.log");
		_log.SetOutputFile(logfile.c_str());
	}

	if (!_mainworker.Start())
	{
		return 0;
	}

	signal(SIGINT, catch_intterm); 
	signal(SIGTERM,catch_intterm);
	
	/* now, lets get into an infinite loop of doing nothing. */

#if defined WIN32
#ifndef _DEBUG
	RedirectIOToConsole();	//hide console
#endif
	InitWindowsHelper(hInstance,hPrevInstance,nShowCmd,DQuitFunction,atoi(_mainworker.GetWebserverPort().c_str()),bStartWebBrowser);
	MSG Msg;
	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
#else
	for ( ;; )
		sleep_seconds(1);
#endif
	return 0;
}
예제 #4
0
/*! The main entrance to the program. */
int main(int argc, char * argv[])
{
	try
	{
		// Parse the command line arguments.
		CCmdLine cmdLine;
		if (cmdLine.SplitLine(argc, argv) < 1)
		{
			show_help();
			exit(-1);
		}

		string execId = cmdLine.GetArgument("-execid", 0);
		string celFile = cmdLine.GetSafeArgument("-cel", 0, "");
		string inFile = cmdLine.GetArgument("-in", 0);
		string outFile = cmdLine.GetArgument("-out", 0);
		string arrayType = cmdLine.GetArgument("-arrayType", 0);
		string algName = cmdLine.GetArgument("-algName", 0);
		string algVersion = cmdLine.GetArgument("-algVersion", 0);
		string programName = cmdLine.GetArgument("-programName", 0);
		string programVersion = cmdLine.GetArgument("-programVersion", 0);
		string programCompany = cmdLine.GetArgument("-programCompany", 0);

		vector<string> paramNames;
		int n = cmdLine.GetArgumentCount("-paramNames");
		for (int i=0; i<n; i++)
			paramNames.push_back(cmdLine.GetArgument("-paramNames", i));

		vector<string> paramValues;
		n = cmdLine.GetArgumentCount("-paramValues");
		for (int i=0; i<n; i++)
			paramValues.push_back(cmdLine.GetArgument("-paramValues", i));

		vector<string> sumNames;
		n = cmdLine.GetArgumentCount("-sumNames");
		for (int i=0; i<n; i++)
			sumNames.push_back(cmdLine.GetArgument("-sumNames", i));

		vector<string> sumValues;
		n = cmdLine.GetArgumentCount("-sumValues");
		for (int i=0; i<n; i++)
			sumValues.push_back(cmdLine.GetArgument("-sumValues", i));

		// Read the TSV input file
		list<string> names;
		list<float> quantifications;
		ReadData(inFile, names, quantifications);

		// Create the CHP file.
		CreateFileWithHeader(execId, celFile, outFile, names, algName, algVersion, arrayType,
			programName, programVersion, programCompany, paramNames, paramValues, sumNames, sumValues);
		UpdateQuantifications(outFile, quantifications);
	}
	catch (string s)
	{
		cout << s << endl;
		show_help();
	}
	catch (int e)
	{
		cout << "Invalid argument" << endl;
		show_help();
	}
	catch (...)
	{
		cout << "Unknown error" << endl;
		show_help();
	}
	return 0;
}
예제 #5
0
int main( int argc, char** argv )
{

#ifdef USE_CVCAM
	bool cvcam=true;
#else 
	bool cvcam=false;
#endif

	
	if (cmdLine.SplitLine(argc, argv) < 1)
	{
      // no switches were given on the command line, abort
      //ShowHelp();
      //exit(-1);
	}

	std::string infile="../../../stip_online/video/walk-complex.avi";
	std::string tmp;
	int cam=-1;
	try
	{
		if( cmdLine.HasSwitch("-h") || 
			cmdLine.HasSwitch("-help") ||
			cmdLine.HasSwitch("--help"))
		{
			ShowHelp();
			exit(0);
		}

		if( cmdLine.HasSwitch("-f") && cmdLine.HasSwitch("-cam") )
		{
			std::cout<<"You can't specify both file and camera as input!"<<std::endl;
			ShowHelp();
			exit(-1);
		}

	

		if( !(cmdLine.HasSwitch("-f") || cmdLine.HasSwitch("-cam") ))
		{
			std::cout<<"no input..."<<std::endl;
			ShowHelp();
			exit(-1);
		}

		//*** input/output options
		if(cmdLine.GetArgumentCount("-f")>0) 
			infile = cmdLine.GetArgument("-f", 0);
		if(cmdLine.GetArgumentCount("-o")>0) 
			outfile = cmdLine.GetArgument("-o", 0);
	
		if(cmdLine.HasSwitch("-cam"))
			if(cmdLine.GetArgumentCount("-cam")>0)
				cam =  atoi(cmdLine.GetArgument("-cam", 0).c_str());
			else
				cam = -1;

		if(cmdLine.GetArgumentCount("-res")>0) resid =  atoi(cmdLine.GetArgument( "-res", 0 ).c_str());
		if(resid<0 || resid>4) resid=1;

		if(cmdLine.GetArgumentCount("-vis")>0) show = cmdLine.GetArgument("-vis", 0)=="yes"?true:false;
		
		//*** descriptor options
		if(cmdLine.GetArgumentCount("-dscr")>0) mshb.descriptortype = cmdLine.GetArgument("-dscr", 0);
		if(cmdLine.GetArgumentCount("-szf")>0) mshb.patchsizefactor = atof(cmdLine.GetArgument("-szf", 0).c_str());

		//*** detection options
		if(cmdLine.GetArgumentCount("-nplev")>0) mshb.nxplev=atoi(cmdLine.GetArgument("-nplev", 0).c_str());
		if(cmdLine.GetArgumentCount("-plev0")>0) mshb.initpyrlevel=atoi(cmdLine.GetArgument("-plev0", 0).c_str());
		//if(cmdLine.GetArgumentCount("-sigma")>0) hb.sig2 =  atof(cmdLine.GetArgument( "-sigma", 0 ).c_str());
		//if(cmdLine.GetArgumentCount("-tau")>0) hb.tau2 =  atof(cmdLine.GetArgument( "-tau", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-kparam")>0) mshb.kparam =  atof(cmdLine.GetArgument( "-kparam", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-thresh")>0) mshb.SignificantPointThresh =  atof(cmdLine.GetArgument( "-thresh", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-border")>0) mshb.Border =  atoi(cmdLine.GetArgument( "-border", 0 ).c_str());

		//*** video capture options
		mshb.framemax = 100000000;
		if(cmdLine.GetArgumentCount("-framemax")>0) mshb.framemax =  atoi(cmdLine.GetArgument( "-framemax", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-ff")>0) frame_begin =  atoi(cmdLine.GetArgument( "-ff", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-lf")>0) frame_end =  atoi(cmdLine.GetArgument( "-lf", 0 ).c_str());
		
		
	}
	catch (...)
	{
		ShowHelp();
		exit(-1);
	}


	if(infile=="")  //prb:both can handle cam and file
	{
		if(!InitCVCAM(cam))
			return -2;
		// initialize source name string
        sourcename="CameraStream";
	} else {
		cvcam=false;
		if(!InitCapture(infile.c_str()))
			return -2;	
		// initialize source name string
        sourcename=infile;
		std::cout<<"Options summary: "<<std::endl;
		std::cout<<"  video input:     "<<sourcename<<std::endl;
		std::cout<<"  frame interval:  "<<frame_begin<<"-"<<frame_end<<std::endl;
		std::cout<<"  output file:     "<<outfile<<std::endl;
		std::cout<<"  #pyr.levels:     "<<mshb.nxplev<<std::endl;
		std::cout<<"  init.pyr.level:  "<<mshb.initpyrlevel<<std::endl;
		std::cout<<"  patch size fct.: "<<mshb.patchsizefactor<<std::endl;
		std::cout<<"  descriptor type: "<<mshb.descriptortype<<std::endl;
	}

		
        
	if(show)
	{
		//cvNamedWindow( win1,  CV_WINDOW_AUTOSIZE  );
		cvNamedWindow( win2, 0 );
	}


	//cvNamedWindow("Original");

	if(capture)
	{
    int fn=0;
    for(;;)
    {
        if (fn>=mshb.framemax) break;
        if (fn>=frame_end-frame_begin) break;

        fn++;
		frame = cvQueryFrame( capture );
			
        if( !frame )
            break;

		//CVUtil::DrawCircleFeature(frame,cvPoint(10,10),4.0);
		//CapProperties(capture);		
		//cvShowImage("Original",frame);

		dostuff(frame);
		if(show)
		{
			dovisstuff();
			//cvWaitKey();
			cvWaitKey(10);
			//if(cvWaitKey(10) >= 0 )
			//    break;
		}  
    }
	}
	std::cout<<"-> detected "<<TotalIPs<<" points"<<std::endl;

#ifdef USE_CVCAM
	if(cvcam)
	{
		cvWaitKey(0);
		cvcamExit();
	}
#endif
	
	if(capture)
		cvReleaseCapture( &capture );
	

	if(show)
	{
		cvDestroyWindow(win1);
	}

	if(gray) cvReleaseImage(&gray);
	if(vis)  cvReleaseImage(&vis);
	if(vis2)	cvReleaseImage(&vis2);
	if(vis3)	cvReleaseImage(&vis3);
	if(camimg) cvReleaseImage(&camimg);
    return 0;
}
예제 #6
0
/*! The main entrance to the program. */
int main(int argc, char * argv[])
{
	try
	{
		// Parse the command line arguments.
		CCmdLine cmdLine;
		if (cmdLine.SplitLine(argc, argv) < 1)
		{
			show_help();
			exit(-1);
		}

		string execId = cmdLine.GetArgument("-execid", 0);
		string celFile = cmdLine.GetSafeArgument("-cel", 0, "");
		string inFile = cmdLine.GetArgument("-in", 0);
		string outFile = cmdLine.GetArgument("-out", 0);
		string arrayType = cmdLine.GetArgument("-arrayType", 0);
		string algName = cmdLine.GetArgument("-algName", 0);
		string algVersion = cmdLine.GetArgument("-algVersion", 0);
		string programName = cmdLine.GetArgument("-programName", 0);
		string programVersion = cmdLine.GetArgument("-programVersion", 0);
		string programCompany = cmdLine.GetArgument("-programCompany", 0);

		vector<string> colNames;
		int n = cmdLine.GetArgumentCount("-colNames");
		for (int i=0; i<n; i++)
			colNames.push_back(cmdLine.GetArgument("-colNames", i));

		vector<string> colTypes;
		n = cmdLine.GetArgumentCount("-colTypes");
		for (int i=0; i<n; i++)
			colTypes.push_back(cmdLine.GetArgument("-colTypes", i));

		vector<string> paramNames;
		n = cmdLine.GetArgumentCount("-paramNames");
		for (int i=0; i<n; i++)
			paramNames.push_back(cmdLine.GetArgument("-paramNames", i));

		vector<string> paramValues;
		n = cmdLine.GetArgumentCount("-paramValues");
		for (int i=0; i<n; i++)
			paramValues.push_back(cmdLine.GetArgument("-paramValues", i));

		vector<string> sumNames;
		n = cmdLine.GetArgumentCount("-sumNames");
		for (int i=0; i<n; i++)
			sumNames.push_back(cmdLine.GetArgument("-sumNames", i));

		vector<string> sumValues;
		n = cmdLine.GetArgumentCount("-sumValues");
		for (int i=0; i<n; i++)
			sumValues.push_back(cmdLine.GetArgument("-sumValues", i));

		vector<string> extraNames;
		n = cmdLine.GetArgumentCount("-extraNames");
		for (int i=0; i<n; i++)
			extraNames.push_back(cmdLine.GetArgument("-extraNames", i));

		vector<string> extraValues;
		n = cmdLine.GetArgumentCount("-extraValues");
		for (int i=0; i<n; i++)
			extraValues.push_back(cmdLine.GetArgument("-extraValues", i));

		// Read the TSV input file
		int maxProbeSetNameLength = 0;

		// data collection is no longer used, so we have ReadData return the row count so that we can pass it into
		// CreateFileWithHeader call
		unsigned long rowCount = ReadData(inFile, maxProbeSetNameLength);

		// Create the CHP file.
		// Creates the header
		CreateFileWithHeader(execId, celFile, outFile, colNames, colTypes, rowCount, maxProbeSetNameLength,
			algName, algVersion, arrayType, programName, programVersion, programCompany, paramNames, paramValues,
			sumNames, sumValues, extraNames, extraValues);

		// add the body (data)
		AddFileBody(inFile,outFile, maxProbeSetNameLength, colTypes);
	}
	catch (string s)
	{
		cout << s << endl;
		show_help();
	}
	catch (int e)
	{
		cout << "Invalid argument" << endl;
		show_help();
	}
	catch (...)
	{
		cout << "Unknown error" << endl;
		show_help();
	}
	return 0;
}
예제 #7
0
int
P300ClassifierMain( int argc, char **argv, QApplication& app )
{
  ConfigDialog dialog;

  CCmdLine    cmdLine;
  QString     arg_TrainingDataFiles;
  QString     arg_TestingDataFiles;
  QString     arg_inicfg;
  QStringList arg_TrainingDataFilesList;
  QStringList arg_TestingDataFilesList;
  bool        barg_TrainingDataFiles;
  bool        barg_TestingDataFiles;
  bool        barg_inicfg;

  cmdLine.SplitLine(argc, argv);

  barg_TrainingDataFiles     =cmdLine.HasSwitch("-TrainingDataFiles");
  barg_TestingDataFiles      =cmdLine.HasSwitch("-TestingDataFiles");
  barg_inicfg                =cmdLine.HasSwitch("-inicfg");

  //int co = cmdLine.GetArgumentCount("-TrainingDataFiles");
  if (barg_TrainingDataFiles)
  {
    for (int i=0; i<cmdLine.GetArgumentCount("-TrainingDataFiles"); i++)
    {
        arg_TrainingDataFiles = arg_TrainingDataFiles.fromStdString(cmdLine.GetArgument("-TrainingDataFiles",i));
        arg_TrainingDataFilesList.insert(i, arg_TrainingDataFiles);
    }
  }
  else
  {
      arg_TrainingDataFiles = "";
  }


  if (barg_TestingDataFiles)
  {
   for (int i=0; i<cmdLine.GetArgumentCount("-TestingDataFiles"); i++)
   {
       arg_TestingDataFiles = arg_TestingDataFiles.fromStdString(cmdLine.GetArgument("-TestingDataFiles",i));
       arg_TestingDataFilesList.insert(i, arg_TestingDataFiles);
   }
  }
  else
  {
    arg_TestingDataFiles = "";
  }

  if (barg_inicfg)
  {
    arg_inicfg = arg_inicfg.fromStdString(cmdLine.GetArgument("-inicfg",0));
  }
  else
  {
    arg_inicfg = "";
  }

  QString classifierOutputFile = cmdLine.GetSafeArgument( "-ClassifierOutputFile", 0, "" ).c_str();
  dialog.SetFiles(arg_TrainingDataFilesList, arg_TestingDataFilesList, arg_inicfg, classifierOutputFile);

  return dialog.exec();
}