Esempio n. 1
0
/**
 * Creates an array of string pointer where each non null entry is malloced and
 * needs to be freed
 *
 *
 * @param basedir*
 * @param JVMUserArgs* initialize JVMUserArgs with values from developer config file
 */
void JVMUserArgs_initializeDefaults(JVMUserArgs *userArgs, TCHAR* basedir) {
    TCHAR jvmArgID[MAX_OPTION_NAME + 1] = {0};
    TCHAR argvalue[LAUNCHER_MAXPATH + 1] ={0};
    JVMUserArg* keys = userArgs->args;

    int index = 0;
    int found = 0;
    do {
        _stprintf_s(jvmArgID, MAX_OPTION_NAME, _T("jvmuserarg.%d.name"), (index+1));
        found = getConfigValue(basedir, jvmArgID, argvalue, LAUNCHER_MAXPATH);
        if (found) {
            keys->name = wcsdup(argvalue);
            _stprintf_s(jvmArgID, MAX_OPTION_NAME, _T("jvmuserarg.%d.value"), (index+1));
            found = getConfigValue(basedir, jvmArgID, argvalue, LAUNCHER_MAXPATH);
            if (found) {
                //allow use to specify everything in name only
                keys->value = wcsdup(argvalue);
            }
            else {
                keys->value = wcsdup(_T(""));
            }
            index++;
            keys++;
            userArgs->initialElements++;
            userArgs->currentSize++;
        }
    } while (found && index < userArgs->maxSize);
}
Esempio n. 2
0
int bartlby_extension_startup(void * shm_addr, void * dataLoaderHandle, char * configfile) {
	_log(LH_MOD, B_LOG_INFO, "extlogger: %s", configfile);
	/*
	extlogger_type=
	extlogger_host=
	extlogger_user=
	extlogger_password=
	extlogger_db=
	*/
	cType  = getConfigValue("extlogger_type", configfile);
	cHost = getConfigValue("extlogger_host", configfile);
	cUser = getConfigValue("extlogger_user", configfile);
	cPassword = getConfigValue("extlogger_password", configfile);
	cDB = getConfigValue("extlogger_db", configfile);
	
	if(cType == NULL || cHost == NULL || cUser  == NULL || cPassword == NULL || cDB == NULL) {
		_log(LH_MOD, B_LOG_CRIT, "extlogger: configuration failed 'extlogger_type', 'extlogger_host', 'extlogger_user', 'extlogger_password', 'extlogger_db'");
	}
	
	
	
	gHdr=bartlby_SHM_GetHDR(shm_addr);
	gDataLoaderHandle=dataLoaderHandle;
	gCFG=configfile;
	_log(LH_MOD, B_LOG_INFO, "Extlogger initiated");
	
	return EXTENSION_OK;
}
Esempio n. 3
0
int UpdateServerGroup(struct servergroup * svc, char *config) {
	/*
		modify worker
	*/
	MYSQL *mysql;
	int rtc;
	
	char * sqlupd;
	


	char * mysql_host = getConfigValue("mysql_host", config);
	char * mysql_user = getConfigValue("mysql_user", config);
	char * mysql_pw = getConfigValue("mysql_pw", config);
	char * mysql_db = getConfigValue("mysql_db", config);

	mysql=mysql_init(NULL);
BARTLBY_SQL_PROTECTION_INIT;
		CHK_ERR(mysql,NULL);
	mysql_real_connect(mysql, mysql_host, mysql_user, mysql_pw, NULL, 0, NULL, 0);
		CHK_ERR(mysql,NULL);
	mysql_select_db(mysql, mysql_db);
      		CHK_ERR(mysql,NULL);
	
	
	
	CHECKED_ASPRINTF(&sqlupd, UPDATE_SERVERGROUP, 
                                  BARTLBY_SQL_PROTECTION(svc->servergroup_name),
                                  svc->servergroup_notify,
                                  svc->servergroup_active,
                                  BARTLBY_SQL_PROTECTION(svc->servergroup_members),
                                  svc->servergroup_dead,
                                  BARTLBY_SQL_PROTECTION(svc->enabled_triggers),
                                  svc->orch_id,
                                  svc->servergroup_id
                                  );
	
	
	
	mysql_query(mysql, sqlupd);
		CHK_ERR(mysql,NULL);
	
	
	free(sqlupd);
	rtc=1;
	BARTLBY_MYSQL_CLOSE(mysql);
		
	free(mysql_host);
	free(mysql_user);
	free(mysql_pw);
	free(mysql_db);
	
	return rtc;	
}
Esempio n. 4
0
string Triggerconf::getConfigValue (string path)
{
	if (! checkItemCount (path, 3)) return "";

	STRING_LIST items = tokenize (path);
	return getConfigValue (items [0], items [1], items [2]);
}
Esempio n. 5
0
long ZLIntegerRangeOption::value() const {
	if (!myIsSynchronized) {
		myValue = stringToInteger(getConfigValue(), myDefaultValue, myMinValue, myMaxValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Esempio n. 6
0
double ZLDoubleOption::value() const {
	if (!myIsSynchronized) {
		myValue = stringToDouble(getConfigValue(), myDefaultValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Esempio n. 7
0
const std::string &ZLStringOption::value() const {
	if (!myIsSynchronized) {
		myValue = getConfigValue(myDefaultValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Esempio n. 8
0
ZLColor ZLColorOption::value() const {
	if (!myIsSynchronized) {
		myIntValue = stringToInteger(getConfigValue(), myDefaultIntValue);
		myIsSynchronized = true;
	}
	return ZLColor(myIntValue);
}
void notifyWaitingStart(StartMatch* startMatch, OutputStream* pcOutputStream) {
    appendString(pcOutputStream, NOTIFY_TO_PC_RESET);
    appendString(getAlwaysOutputStreamLogger(), "CFG:");
    appendBinary16(getAlwaysOutputStreamLogger(), getConfigValue(startMatch->robotConfig), 4);
    println(getAlwaysOutputStreamLogger());
    appendString(getAlwaysOutputStreamLogger(), "Waiting start:");
}
Esempio n. 10
0
void
getConfigValueGroup(
        const char *name,
        char       *setting,
        const char *formStart,
        const char *formEnd )
{
    char    *p, *q, *r;
    char    target[BUFSIZ];

    sprintf( target, "name=\"%s\"", name );
    p = strstr( formStart, target );
    while ( p && (p < formEnd) ) {
        q = strchr( p, '>' );
        if ( q < formEnd ) {
            while ( p > formStart ) {
                p--;
                if ( *p == '<' ) {
                    r = strstr( p, "checked" );
                    if ( r && (r < q) )
                        getConfigValue( name, setting, p, q );

                    p = strstr( q + 1, target );
                    break;
                }
            }
        }
    }
}
Esempio n. 11
0
bool ZLBooleanOption::value() const {
	if (!myIsSynchronized) {
		myValue = stringToBoolean(getConfigValue(), myDefaultValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Esempio n. 12
0
void
getConfigValueChecked(
        const char *name,
        char       *setting,
        const char *formStart,
        const char *formEnd )
{
    char    *p, *q, *r, *s;
    char    target[BUFSIZ];

    sprintf( target, "name=\"%s\"", name );
    p = strstr( formStart, target );
    if ( p && (p < formEnd) ) {
        r = p;
        while ( p > formStart ) {
            p--;
            if ( !strncmp( p, "<input ", 7 ) ) {
                s = p;
                p += 7;
                q = strstr( p, "checked" );
                if ( q ) {
                    if ( q < r ) {
                        getConfigValue( name, setting, s, formEnd );
                    }
                    else {
                        s = r + strlen( target );
                        getConfigValueChecked( name, setting, s, formEnd );
                    }
                    break;
                }
            }
        }
    }
}
Esempio n. 13
0
bool DirectorCore::buildProcessMap(void) noexcept
{
  // search existing processes for those we should be managing (not 100% foolproof)
  process_state_t state;
  std::set<pid_t> pidlist;
  const pid_t thispid = posix::getpid();
  if(proclist(pidlist) == posix::success_response)
  {
    for(pid_t pid : pidlist)
    {
      posix::memset(reinterpret_cast<void*>(&state), 0, sizeof(state));
      if(procstat(pid, state) && // if get process state works AND
         (!state.parent_process_id || state.parent_process_id == thispid)) // process has unknown parent process OR director is the parent process
        for(const std::string& config : getConfigList()) // try each config
          if(getConfigValue(config, "/Process/Executable") == state.executable) // if the executable matches
          {
            m_process_map[config]->add(thispid, pid); // claim this as a managed process
            posix::memset(reinterpret_cast<void*>(&state), 0, sizeof(state)); // wipe process state for safety
            for(pid_t childpid : pidlist)
              if(procstat(childpid, state) && // if get process state works AND
                 state.parent_process_id == pid) // process is a child of this parent pid
                m_process_map[config]->add(pid, childpid); // claim this as a managed process
          }
    }
    return true;
  }
  return false;
}
Esempio n. 14
0
ZLBoolean3 ZLBoolean3Option::value() const {
	if (!myIsSynchronized) {
		myValue = (ZLBoolean3)stringToInteger(getConfigValue(), myDefaultValue);
		myIsSynchronized = true;
	}
	return myValue;
}
Esempio n. 15
0
QString ProgramOptions::getHomeQFDirectory() const
{
    QString cfg=getConfigValue("quickfit/homedir", "").toString();
    if (!cfg.isEmpty() && QDir(cfg).exists()) return cfg;

    QDir d=QDir::home();
    if (!QDir(d.absolutePath()+"/quickfit3").exists()) d.mkdir("quickfit3");
    return d.absolutePath()+"/quickfit3/";
}
Esempio n. 16
0
int DeleteServerGroup(long servergroup_id, char * config) {
	
	MYSQL *mysql;

	
	char * sqlupd;
	


	char * mysql_host = getConfigValue("mysql_host", config);
	char * mysql_user = getConfigValue("mysql_user", config);
	char * mysql_pw = getConfigValue("mysql_pw", config);
	char * mysql_db = getConfigValue("mysql_db", config);

	mysql=mysql_init(NULL);
BARTLBY_SQL_PROTECTION_INIT;
		CHK_ERR(mysql,NULL);
	mysql_real_connect(mysql, mysql_host, mysql_user, mysql_pw, NULL, 0, NULL, 0);
		CHK_ERR(mysql,NULL);
	mysql_select_db(mysql, mysql_db);
      		CHK_ERR(mysql,NULL);
	
	
	CHECKED_ASPRINTF(&sqlupd, DEL_SERVERGROUP, servergroup_id);
	
	//Log("dbg", sqlupd);
	
	mysql_query(mysql, sqlupd);
		CHK_ERR(mysql,NULL);
	
	
	free(sqlupd);
	
	BARTLBY_MYSQL_CLOSE(mysql);
		
	free(mysql_host);
	free(mysql_user);
	free(mysql_pw);
	free(mysql_db);
	
	return 1;		
	
	
}
Esempio n. 17
0
void loadMatchSide() {
	matchSide = getConfigValue() & CONFIG_COLOR_BLUE_MASK;
	if (matchSide != 0) {
		matchSide = SIDE_BLUE;
	}
	else {
		matchSide = SIDE_YELLOW;
	}
	writeStringCR(getMatchSideAsString());
}
Esempio n. 18
0
bool ProNovoConfig::getParameters()
{

	string sTemp;
	istringstream issStream;

	// Extract the elements inside <Peptide_Identification>
	getConfigValue("[Peptide_Identification]Search_Type", sSearchType);
	getConfigValue("[Peptide_Identification]Search_Name", sSearchName);

	getConfigValue("[Peptide_Identification]FASTA_Database", sFASTAFilename);
	getConfigValue("[Peptide_Identification]Fragmentation_Method", sFragmentationMethod);


	if(sSearchType == "Regular")
	{
		getConfigValue("[Peptide_Identification]Max_PTM_Count", sTemp);
		issStream.clear();
		issStream.str( sTemp );
		issStream >> iMaxPTMcount;
	}
Esempio n. 19
0
long ServerGroupChangeId(long from, long to, char * config) {
	MYSQL *mysql;
	
	
	char * sqlupd;
	


	char * mysql_host = getConfigValue("mysql_host", config);
	char * mysql_user = getConfigValue("mysql_user", config);
	char * mysql_pw = getConfigValue("mysql_pw", config);
	char * mysql_db = getConfigValue("mysql_db", config);

	mysql=mysql_init(NULL);
BARTLBY_SQL_PROTECTION_INIT;
		CHK_ERR(mysql,NULL);
	mysql_real_connect(mysql, mysql_host, mysql_user, mysql_pw, NULL, 0, NULL, 0);
		CHK_ERR(mysql,NULL);
	mysql_select_db(mysql, mysql_db);
      		CHK_ERR(mysql,NULL);
	
	
	CHECKED_ASPRINTF(&sqlupd, SERVERGROUP_CHANGE_ID, to, from);
	
	
	
	mysql_query(mysql, sqlupd);
		CHK_ERR(mysql,NULL);
			
	free(sqlupd);
		
	
	BARTLBY_MYSQL_CLOSE(mysql);
	free(mysql_host);
	free(mysql_user);
	free(mysql_pw);
	free(mysql_db);
	return to;	
}
Esempio n. 20
0
void setConfigValue(const std::string &configKey, const std::string &value)
{
	if (configKey == APPBUILD)
	{
		SetAppBuild(value);
		return;
	}
	else if (configKey == APPID)
	{
		SetAppBranch(value);
		return;
	}

	dbCreateTables();

	sqlite3x::sqlite3_connection db(CONFIG_DB());

	ERROR_OUTPUT(gcString("Setting key \"{0}\" to value \"{1}\"", configKey, value).c_str());

	if(getConfigValue(configKey).length() > 0)
	{
		try
		{
			sqlite3x::sqlite3_command cmd(db, "UPDATE config_string SET value=? WHERE key=?;");
			cmd.bind(1, value);
			cmd.bind(2, configKey);
			cmd.executenonquery();
		}
		catch(std::exception &e)
		{
			ERROR_OUTPUT(gcString("Failed to update key \"{0}\" with value \"{1}\": \"{2}\"!\n", configKey, value, e.what()).c_str());
		}
	}
	else
	{
		try
		{
			sqlite3x::sqlite3_command cmd(db, "INSERT INTO config_string VALUES(?,?);");
			cmd.bind(1, configKey);
			cmd.bind(2, value);
			cmd.executenonquery();
		}
		catch(std::exception &e)
		{
			ERROR_OUTPUT(gcString("Failed to insert key \"{0}\" with value \"{1}\": \"{2}\"!\n", configKey, value, e.what()).c_str());
		}
	}

	return;
}
Esempio n. 21
0
void bartlby_check_sirene(char * configfile, void * bartlby_address) {
	struct service svc;
	char * cfg_sirene_wait;
	int sirene_retry;
	int diff;
	
	
	
	cfg_sirene_wait=getConfigValue("sirene_interval", configfile);
	if(cfg_sirene_wait == NULL) {
		_log(LH_ACK, B_LOG_INFO,"'sirene_interval' not set defaulting to 600 seconds re-notify");
		sirene_retry=600;
	} else {
		sirene_retry=atoi(cfg_sirene_wait);
		free(cfg_sirene_wait);
	}
	
		
	diff=time(NULL)-last_sirene;
	
	if(diff <= sirene_retry) {
		
		sleep(2); //usually ok and be nice to CPU
		return;	
	}
	last_sirene=time(NULL);
	
	
	svc.srv=malloc(sizeof(struct server));
	if(svc.srv == NULL) {
		_log(LH_ACK, B_LOG_CRIT,"malloc failed in bartlby_check_sirene()");
		return;	
	}
	
	
	sprintf(svc.srv->client_ip, "0.0.0.0");
	sprintf(svc.srv->server_name, "CORE");
	
	sprintf(svc.service_name, "SIRENE");
	sprintf(svc.new_server_text, "Your system is in sirene mode all checks have been disabled please give the UI a bit attention");
	svc.current_state=STATE_SIRENE;
	//svc.client_port=0;
	svc.last_state=STATE_SIRENE;
	
	_log(LH_PERF, B_LOG_CRIT,"!!! System is in sirene Mode !!!!");
	bartlby_trigger(&svc,configfile, bartlby_address, 0, 0);
	
	
	
}
Esempio n. 22
0
//Constructs full path to the main jar file
//return false if not found
bool getMainJar(TCHAR* basedir, TCHAR* jar, int buffer_size) {
    TCHAR jarname[LAUNCHER_MAXPATH] = {0};
    TCHAR jar_relative[LAUNCHER_MAXPATH] = {0};
    TCHAR jar_full[LAUNCHER_MAXPATH] = {0};

    if (!getConfigValue(basedir, CONFIG_MAINJAR_KEY, jarname, LAUNCHER_MAXPATH)) {
        return false;
    }

    _tcscat_s(jar_relative, LAUNCHER_MAXPATH, MAINJAR_FOLDER);
    _tcscat_s(jar_relative, LAUNCHER_MAXPATH - _tcslen(jar_relative), jarname);

    bool ret = getFileInPackage(basedir, jar_relative, jar_full, LAUNCHER_MAXPATH);

    _tcscat_s(jar, LAUNCHER_MAXPATH - _tcslen(jar), jar_full);

    return ret;
}
Esempio n. 23
0
//Constructs full path to the main jar file
//return false if not found
int getMainJar(char* basedir, char* jar, int buffer_size) {
    char jarname[MAX_PATH] = {0};
    char jar_relative[MAX_PATH] = {0};
    char jar_full[MAX_PATH] = {0};

    if (!getConfigValue(basedir, CONFIG_MAINJAR_KEY, jarname, MAX_PATH)) {
        return FALSE;
    }

    strcat(jar_relative, MAINJAR_FOLDER);
    strcat(jar_relative, jarname);

    int ret = getFileInPackage(basedir, jar_relative, jar_full, MAX_PATH);

    strcat(jar, jar_full);

    return ret;
}
Esempio n. 24
0
int bartlby_extension_startup(void * shm_addr, void * dataLoaderHandle, char * configfile) {
	_log(LH_MOD, B_LOG_INFO, "distributive: %s", configfile);
	
	distr_command  = getConfigValue("distributive_command", configfile);
	
	
	if(distr_command == NULL) {
		_log(LH_MOD, B_LOG_CRIT, "distributive: configuration failed 'distributive_command'");
	}
	
	
	
	gHdr=bartlby_SHM_GetHDR(shm_addr);
	gDataLoaderHandle=dataLoaderHandle;
	gCFG=configfile;
	_log(LH_MOD, B_LOG_INFO, "distributive initiated");
	
	return EXTENSION_OK;
}
Esempio n. 25
0
/*
 * Get use options from either defaults or from user preferences in registry
 */
int addUserOptions(TCHAR* basedir, JavaVMOption* options, int cnt) {
    JVMUserArg args[MAX_OPTIONS]; //Make sure we don't go over
    JVMUserArgs jvmUserArgs;
    TCHAR appid[LAUNCHER_MAXPATH + 1] = {0};
    TCHAR argvalue[LAUNCHER_MAXPATH + 1] = {0};

    jvmUserArgs.args = args;
    jvmUserArgs.currentSize = 0;
    jvmUserArgs.initialElements = 0;
    jvmUserArgs.maxSize = MAX_OPTIONS - cnt;
    memset(&args, 0, sizeof (JVMUserArg)*(MAX_OPTIONS - cnt));

    //Add property to command line for preferences id
    if (getConfigValue(basedir, CONFIG_APP_ID_KEY, appid, LAUNCHER_MAXPATH)) {
        _stprintf_s(argvalue, LAUNCHER_MAXPATH, _T("-D%s=%s"), CONFIG_APP_ID_KEY, appid);

        char* result = convertToDupedChar(argvalue);
        if (result != NULL) {
            //optionString is malloced
            options[cnt].optionString = result;
            cnt++;
        }

        JVMUserArgs_initializeDefaults(&jvmUserArgs, basedir);
        //Copy all user args to options
        int i;
        for (i = 0; i < jvmUserArgs.currentSize; i++) {
            getJvmUserArg(appid, &args[i]);

            //optionString needs to be malloced - JVMUserArg_toString returns malloced string
            char* jvmOption = JVMUserArg_toString(basedir, args[i], TRUE);
            if (jvmOption != NULL) {
                options[cnt].optionString = jvmOption;
                cnt++;
            }
        }
    } else {
        printf("WARNING: %s not defined:", CONFIG_APP_ID_KEY);
    }
    return cnt;
}
Esempio n. 26
0
//Constructs full path to the main jar file
//return false if not found
int getMainJar(char* basedir, char* jar, int buffer_size) {
    char jarname[MAX_PATH] = {0};
    char jar_relative[MAX_PATH] = {0};
    char jar_full[MAX_PATH] = {0};

    if (!getConfigValue(basedir, CONFIG_MAINJAR_KEY, jarname, MAX_PATH)) {
        return FALSE;
    }

    strcat(jar_relative, MAINJAR_FOLDER);
    //strcat(jar_relative, jarname);
    if(boinc_resolve_filename(jarname, (jar_relative+strlen(MAINJAR_FOLDER)), MAX_PATH-strlen(MAINJAR_FOLDER))) {
        printf("Unable to resolve file (%s) via boinc_resolve_filename!\n", jarname);
        return FALSE;
    }

    int ret = getFileInPackage(basedir, jar_relative, jar_full, MAX_PATH);

    strcat(jar, jar_full);

    return ret;
}
Esempio n. 27
0
int bartlby_extension_startup(void * shm_addr, void * dataLoaderHandle, char * configfile) {
	int x;
	struct service * svcmap;
	unsigned char new_hash_bin[SHA_DIGEST_LENGTH];
	char new_hash_str[40];
	
	
	_log("statehistory: %s", configfile);
	
	cfg_statehistory_dir = getConfigValue("statehistory_logdir", configfile);
	
	
	gHdr=bartlby_SHM_GetHDR(shm_addr);
	gDataLoaderHandle=dataLoaderHandle;
	gCFG=configfile;
	svcmap=bartlby_SHM_ServiceMap(shm_addr);
	
	
	if(cfg_statehistory_dir == NULL) {
		_log("statehistory you have to set 'statehistory_logdir'");
	}
	
	_log("statehistory: servicescount->%ld", gHdr->svccount);
	
	state_hash_map = malloc(sizeof(struct service_hash_map)*(gHdr->svccount+1));
	
	//initial hashing
	for(x=0; x<gHdr->svccount; x++) {
				state_hash_map[x].service_id=svcmap[x].service_id;
				SHA1(svcmap[x].new_server_text, strlen(svcmap[x].new_server_text), new_hash_bin);
				convertSHA1BinaryToCharStr(new_hash_bin, new_hash_str);				
				sprintf(state_hash_map[x].sha1_hash, "%s", new_hash_str);
				state_hash_map[x].last_write = time(NULL);
	}
	
	
	return EXTENSION_OK;
}
Esempio n. 28
0
const std::string &ZLOption::getConfigValue() const {
	return getConfigValue(EMPTY_STRING);
}
int main(void) {
    setBoardName("TITAN ELECTRONICAL MAIN BOARD 32bits V-JJ_7");

    i2cMasterInitialize();
    
    //setRobotMustStop(false);
    // Open the serial Link for debug
    openSerialLink(&debugSerialStreamLink,
            &debugInputBuffer,
            &debugInputBufferArray,
            MAIN_BOARD_DEBUG_INPUT_BUFFER_LENGTH,
            &debugOutputBuffer,
            &debugOutputBufferArray,
            MAIN_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH,
            &debugOutputStream,
            SERIAL_PORT_DEBUG,
            DEFAULT_SERIAL_SPEED);

    // Open the serial Link for the PC
    openSerialLink(&pcSerialStreamLink,
            &pcInputBuffer,
            &pcInputBufferArray,
            MAIN_BOARD_PC_INPUT_BUFFER_LENGTH,
            &pcOutputBuffer,
            &pcOutputBufferArray,
            MAIN_BOARD_PC_OUTPUT_BUFFER_LENGTH,
            &pcOutputStream,
            SERIAL_PORT_PC,
            DEFAULT_SERIAL_SPEED);

    // LCD (LCD03 via Serial interface)
    initLCDOutputStream(&lcdOutputStream);

    initTimerList(&timerListArray, MAIN_BOARD_TIMER_LENGTH);

    // Init the logs
    initLog(DEBUG);
    addLogHandler(&debugSerialLogHandler, "UART", &debugOutputStream, DEBUG);
    addLogHandler(&lcdLogHandler, "LCD", &lcdOutputStream, ERROR);

    appendString(getAlwaysOutputStreamLogger(), getBoardName());
    println(getAlwaysOutputStreamLogger());

    initDevicesDescriptor();
    initDriversDescriptor();

    i2cMasterInitialize();
    // Initialize EEPROM and RTC
    initClockPCF8563(&globalClock);
    init24C512Eeprom(&eeprom_);






    initRobotConfigPic32(&robotConfig);



    initStartMatchDetector32(&startMatchDetector);


    // Initializes the opponent robot
    // initOpponentRobot();

    /*
    // Creates a composite to notify both PC and Debug
    initCompositeOutputStream(&compositePcAndDebugOutputStream);
    addOutputStream(&compositePcAndDebugOutputStream, &debugOutputStream);
    addOutputStream(&compositePcAndDebugOutputStream, &pcOutputStream);

    // Creates a composite to redirect to driverRequest and Debug
    initCompositeOutputStream(&compositeDriverAndDebugOutputStream);
    addOutputStream(&compositeDriverAndDebugOutputStream, &debugOutputStream);
    addOutputStream(&compositeDriverAndDebugOutputStream, getDriverRequestOutputStream());
    */

    appendString(&debugOutputStream, "DEBUG\n");
    
    // Start interruptions
    //startTimerList();  //////RALENTI FORTEMENT LE PIC!!! PLANTE I2C !!!!!!!!

    // Configure data dispatcher
    //addLocalDriverDataDispatcher();

    // Stream for motorBoard
    /*
    addI2CDriverDataDispatcher(&motorI2cDispatcher,
            "MOTOR_BOARD_DISPATCHER",
            &motorBoardInputBuffer,
            &motorBoardInputBufferArray,
            MAIN_BOARD_LINK_TO_MOTOR_BOARD_BUFFER_LENGTH,
            &motorBoardOutputStream,
            &motorBoardInputStream,
            MOTOR_BOARD_I2C_ADDRESS);
    */
    /*
    // Stream for Mechanical Board 2
    addI2CDriverDataDispatcher(&mechanical2I2cDispatcher,
            "MECHANICAL_BOARD_2_DISPATCHER",
            &mechanical2BoardInputBuffer,
            &mechanical2BoardInputBufferArray,
            MAIN_BOARD_LINK_TO_MECA_BOARD_2_BUFFER_LENGTH,
            &mechanical2BoardOutputStream,
            &mechanical2BoardInputStream,
            MECHANICAL_BOARD_2_I2C_ADDRESS);
    */

 /*   // Stream for Air Conditioning
    addI2CDriverDataDispatcher(&airConditioningI2cDispatcher,
            "AIR_CONDITIONING_DISPATCHER",
            &airConditioningBoardInputBuffer,
            &airConditioningBoardInputBufferArray,
            MAIN_BOARD_LINK_TO_AIR_CONDITIONING_BOARD_BUFFER_LENGTH,
            &airConditioningBoardOutputStream,
            &airConditioningBoardInputStream,
            AIR_CONDITIONING_BOARD_I2C_ADDRESS);
*/
    // I2C Debug
    initI2CDebugBuffers(&i2cMasterDebugInputBuffer,
                        &i2cMasterDebugInputBufferArray,
                        MAIN_BOARD_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH,
                        &i2cMasterDebugOutputBuffer,
                        &i2cMasterDebugOutputBufferArray,
                        MAIN_BOARD_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH);


    appendStringConfig(&lcdOutputStream);

    //pingDriverDataDispatcherList(getDebugOutputStreamLogger());

    // Inform PC waiting
    showWaitingStart(&debugOutputStream);



    // wait other board initialization
    delaymSec(1500);

    // 2012 VALUE
    unsigned int configValue = getConfigValue();
    unsigned int homologationIndex = configValue & CONFIG_STRATEGY_MASK;
    unsigned int color = configValue & CONFIG_COLOR_BLUE_MASK;

    appendString(getAlwaysOutputStreamLogger(), "Homologation:");
    appendCRLF(getAlwaysOutputStreamLogger());
    appendDec(getAlwaysOutputStreamLogger(), homologationIndex);
    
    appendString(getAlwaysOutputStreamLogger(), "Config:");
    appendHex4(getAlwaysOutputStreamLogger(), configValue);
    appendCRLF(getAlwaysOutputStreamLogger());
    useBalise = configValue & CONFIG_USE_BALISE_MASK;
    useInfrared = configValue & CONFIG_USE_SONAR_MASK;

    if (color != 0) {
        appendString(getAlwaysOutputStreamLogger(), "COLOR:VIOLET\n");
    }
    else {
        appendString(getAlwaysOutputStreamLogger(), "COLOR:RED\n");
    }    

    // TODO 2012 SV motionDriverMaintainPosition();

    // wait for start
 //   setInitialPosition(color);

    // notify game strategy
 //   sendStrategyConfiguration(configValue);

    loopUntilStart(&waitForInstruction);

    // Enable the sonar Status only after start
    //setSonarStatus(configValue & CONFIG_USE_SONAR_MASK);

    // mark that match begins
    markStartMatch();

    // write begin of match
    showStarted(&pcOutputStream);

    if (homologationIndex == 0) {
        // MATCH

        while (1) {
            waitForInstruction();
            //CLOCK Read


            if (isEnd()) {
                break;
            }
        }
    } else {
        setReadyForNextMotion(true);

        while (1) {
            
            portableStartI2C(i2cBus);
            WaitI2C(i2cBus);
            portableMasterWriteI2C(FREE_ADDRESS_2);//0x54
            WaitI2C(i2cBus);
            portableMasterWriteI2C('H');
            WaitI2C(i2cBus);
            portableMasterWriteI2C('E');
            WaitI2C(i2cBus);
            portableMasterWriteI2C('L');
            WaitI2C(i2cBus);
            portableMasterWriteI2C('L');
            WaitI2C(i2cBus);
            portableMasterWriteI2C('O');

            portableStopI2C(i2cBus);
            WaitI2C(i2cBus);
            int data1,data2,data3;
            while(1){
                waitForInstruction();
                //globalClock.readClock(&globalClock);
                //printClock(&debugOutputStream,&globalClock);
                //appendCR(&debugOutputStream);

                int data = 0;
                portableMasterWaitSendI2C(i2cBus);

                portableStartI2C(i2cBus);
                IdleI2C1();
                portableMasterWriteI2C(FREE_ADDRESS_2 + 1);//0x54
                WaitI2C(i2cBus);
                
                data = portableMasterReadI2C(i2cBus);
                portableAckI2C(i2cBus);
                IdleI2C1();

                data1 = portableMasterReadI2C(i2cBus);
                portableAckI2C(i2cBus);
                IdleI2C1();

                data2= portableMasterReadI2C(i2cBus);
                portableAckI2C(i2cBus);
                IdleI2C1();


                data3 = portableMasterReadI2C(i2cBus);
                portableNackI2C(i2cBus);
                IdleI2C1();
                append(&lcdOutputStream,data);
                append(&lcdOutputStream,data1);
                append(&lcdOutputStream,data2);
                append(&lcdOutputStream,data3);

                portableStopI2C(i2cBus);
                IdleI2C1();
                
                delaymSec(500);
            }

















            homologation(homologationIndex, color);

            // We stop if we are in homologation mode
            if (isRobotMustStop()) {
                motionDriverStop();
                break;
            }

            // ultimate tentative to restart the robot if it is blocked
            forceRobotNextStepIfNecessary();
        }
    }

    showEnd(&lcdOutputStream);

    while (1) {
        // Avoid reboot even at end
    }
}
Esempio n. 30
0
int main(int argc,char *argv[])
{
	const int BUF_SIZE=1024;
	const int CMDLEN=50;
	int sockfd;//atoi(argv[1]);
	struct FTS fts;
	char command[BUF_SIZE];
	int index;
	struct COMMAND cmd;
	char user[CMDLEN];
	char arg[BUF_SIZE];
	const char* prompt="FTS> ";
	int numlogs,logfilesize;
	struct CONFIG_READER cfg;
	struct LOGGER lg;
	char ip[CMDLEN];
	llg=&lg;
	signal(SIGKILL,handle);
	createConfigReader(&cfg,"config.cfg");
	//printf("after config reader\n");
	getConfigValue("NLOGFILES",arg,&cfg);
	numlogs=atoi(arg);
	getConfigValue("LOGFILESIZE",arg,&cfg);
	logfilesize=atoi(arg);
	destroyConfigReader(&cfg);
	//printf("after destroy config reader\n");
	createLogger(&lg,"client_log","./client_logs",numlogs,logfilesize);
	//printf("after create logger\n");
	strncpy(arg,argv[1],BUF_SIZE);
	//printf("arg: %s\n",arg);
	strncpy(user,strtok(arg,"@"),BUF_SIZE);
	//printf("user: %s\n",user);
	strncpy(ip,strtok(NULL,"@"),BUF_SIZE);
	//printf("before connections\n");
	fts.sockfd=sockfd=connectToServer(ip);
	fts.mode=FTS_MODE_ASCII;
	//printf("sock: %d\n",sockfd);
	//printf("user: %s\n",user);
	write(sockfd,user,strlen(user));
	read(sockfd,&index,sizeof(index));
	//printf("%d\n",index);
	if(index==-1)
	{
		puts("user not found");
		exit(0);
	}
	puts("connected successfully");
	while(1)
	{
		printf("%s",prompt);
		fflush(stdout);
		fgets(command,BUF_SIZE,stdin);
		while(command[0]=='\0' || command[0]==' ' || command[0]=='\n')
			fgets(command,BUF_SIZE,stdin);
		if(command[strlen(command)-1]=='\n')
			command[strlen(command)-1]='\0';
		//printf("cmd: %s\n",command);
		writeToLogFile(command,&lg);
		fillCommandObject(command,&cmd);
		index=getCommandIndex(&cmd,(struct CMD_MAP *)&cmd_map);
		if(index < 0)
		{
			puts("Command not found");
			continue;
		}
		cmd_map[index].handler(&cmd,&fts);
		destroyCommandObject (&cmd);
	}
	return (0);
}