// Get the name of the current "race" // (actually the current "race session", like quali.1, quali2, ... 1st race, ...). char * ReGetCurrentRaceName(void) { char path[64]; int curRaceIdx; void *params = ReInfo->params; void *results = ReInfo->results; curRaceIdx = (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, 1); snprintf(path, sizeof(path), "%s/%d", RM_SECT_RACES, curRaceIdx); return GfParmGetStrNC(params, path, RM_ATTR_NAME, 0); }
// Get the previous "race" (actually the previous "race session"). char * ReGetPrevRaceName(bool bLoop) { char path[64]; int curRaceIdx; void *params = ReInfo->params; void *results = ReInfo->results; curRaceIdx = (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, 1) - 1; if (bLoop && curRaceIdx <= 0) curRaceIdx = (int)GfParmGetEltNb(params, RM_SECT_RACES); snprintf(path, sizeof(path), "%s/%d", RM_SECT_RACES, curRaceIdx); return GfParmGetStrNC(params, path, RM_ATTR_NAME, 0); }
/* returns: 0, when failed to parse; 1, when successfully parsed */ int ReParseStartingOrder(const char *StartingOrder, tReGridPart **pGridList, int nCars, int &nGridList) { char path[128]; char *tempstr; int curRaceIdx; int i, nGL; void *params = ReInfo->params; void *results = ReInfo->results; tReGridPart *GridList; //input sanity check if ((StartingOrder == NULL) || (nCars<1)){nGridList = 0; return 0;} //find the number of parts, that is the number of '[' characters nGL = 0; i = 0; while (StartingOrder[i] != '\0') { if (StartingOrder[i] == '['){nGL++;} i++; } curRaceIdx = (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_RACE, NULL, 1); // check whether it is a name of an earlier session if (nGL == 0) { for ( i = 1; i < curRaceIdx; i++ ) { snprintf(path, sizeof(path), "%s/%d", RM_SECT_RACES, i); tempstr = GfParmGetStrNC(params, path, RM_ATTR_NAME, 0); if (strcmp(tempstr, StartingOrder) == 0 ) { GridList = new tReGridPart[1]; if (GridList == NULL){return 0;} GridList[0].racename = tempstr; GridList[0].startpos = 1; GridList[0].endpos = nCars; GridList[0].diffpos = 1; nGridList = 1; *pGridList = GridList; return 1; } } //badly formatted GridList nGridList = 0; *pGridList = NULL; return 0; } // now try to parse it char *tempstr2 = new char[strlen(StartingOrder)]; int stri; int GLi = 0; GridList = new tReGridPart[nGL]; for (i = 0; i < nGL; i++) { //search for session name stri = 0; while (StartingOrder[GLi] != '[') { tempstr2[stri] = StartingOrder[GLi]; stri++; GLi++; } tempstr2[stri] = '\0'; GLi++; GridList[i].racename = NULL; for ( int j = 1; j < curRaceIdx; j++ ) { snprintf(path, sizeof(path), "%s/%d", RM_SECT_RACES, j); tempstr = GfParmGetStrNC(params, path, RM_ATTR_NAME, 0); if (strcmp(tempstr, tempstr2) == 0 ) { GridList[i].racename = tempstr; break; } } if (GridList[i].racename == NULL) { // failed to find session nGridList = 0; delete[] GridList; delete[] tempstr2; *pGridList = NULL; return 0; } //find indexes stri = 0; while (StartingOrder[GLi] != ']') { tempstr2[stri] = StartingOrder[GLi]; stri++; GLi++; } tempstr2[stri] = '\0'; GLi++; GridList[i].startpos = GridList[i].endpos = -1; sscanf(tempstr2, "%d:%d", &(GridList[i].startpos), &(GridList[i].endpos)); if (GridList[i].startpos <= 0) { nGridList = 0; delete[] GridList; delete[] tempstr2; *pGridList = NULL; return 0; } else if (GridList[i].endpos <= 0) { GridList[i].endpos = GridList[i].startpos; } if (GridList[i].endpos < GridList[i].startpos) {GridList[i].diffpos = -1;} else {GridList[i].diffpos = 1;} } delete[] tempstr2; nGridList = nGL; *pGridList = GridList; return 1; }
//////////////////////////////////////////////////////////// // General entry point (new scheme) //////////////////////////////////////////////////////////// // Module entry point (new fixed name scheme), step #1. // Extended for use with schismatic robots extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* welcomeOut) { PLogUSR = GfLogger::instance("USR"); LogUSR.debug("\n#Interface Version: %d.%d\n", welcomeIn->itfVerMajor,welcomeIn->itfVerMinor); // Save module name and loadDir, and determine module XML file pathname. setRobotName(welcomeIn->name); // Filehandle for robot's xml-file void *robot_settings = getFileHandle(); GfOut("Robot XML-Path: %s\n\n", xml_path); // Let's look what we have to provide here if (robot_settings) { char section_buf[BUFSIZE]; const char *section = section_buf; snprintf(section_buf, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, 0); // Try to get first driver from index 0 const char *driver_name = GfParmGetStrNC(robot_settings, section, ROB_ATTR_NAME, undefined); // Check whether index 0 is used as start index if (strncmp(driver_name, undefined, strlen(undefined)) != 0) { // Teams xml file uses index 0, 1, ..., N - 1 indexOffset = 0; } else { // Teams xml file uses index 1, 2, ..., N indexOffset = 1; } // Loop over all possible drivers, clear all buffers, // save defined driver names and desc. for (int i = 0; i < MAXNBBOTS; ++i) { // Clear buffers memset(&DriverNames[i * DRIVERLEN], 0, DRIVERLEN); memset(&DriverDescs[i * DRIVERLEN], 0, DRIVERLEN); memset(&CarNames[i * DRIVERLEN], 0, DRIVERLEN); snprintf(section_buf, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, i + indexOffset); const char *driver_name = GfParmGetStr(robot_settings, section, ROB_ATTR_NAME, undefined); if (strncmp(driver_name, undefined, strlen(undefined)) != 0) { // This driver is defined in robot's xml-file strncpy(&DriverNames[i * DRIVERLEN], driver_name, DRIVERLEN - 1); const char *driver_desc = GfParmGetStr(robot_settings, section, ROB_ATTR_DESC, defaultBotDesc[i]); strncpy(&DriverDescs[i * DRIVERLEN], driver_desc, DRIVERLEN - 1); const char *car_name = GfParmGetStr(robot_settings, section, ROB_ATTR_CAR, "nocar"); strncpy(&CarNames[i * DRIVERLEN], car_name, DRIVERLEN - 1); NBBOTS = i + 1; } } } else { // For schismatic robots NBBOTS is unknown! // Handle error here NBBOTS = 0; // But this is not considered a real failure of moduleWelcome ! } GfOut("NBBOTS: %d (of %d)\n", NBBOTS, MAXNBBOTS); if (strncmp(robot_name, "usr_trb1", strlen("usr_trb1")) == 0) SetupUSR_trb1(); else if (strncmp(robot_name,"usr_sc", strlen("usr_sc")) == 0) SetupUSR_sc(); else if (strncmp(robot_name,"usr_ls1", strlen("usr_ls1")) == 0) SetupUSR_ls1(); else if (strncmp(robot_name,"usr_ls2", strlen("usr_ls2")) == 0) SetupUSR_ls2(); else if (strncmp(robot_name,"usr_36GP", strlen("usr_36GP")) == 0) SetupUSR_36GP(); else if (strncmp(robot_name,"usr_rs", strlen("usr_rs")) == 0) SetupUSR_rs(); else if (strncmp(robot_name,"usr_lp1", strlen("usr_lp1")) == 0) SetupUSR_lp1(); else if (strncmp(robot_name,"usr_mpa1", strlen("usr_mpa1")) == 0) SetupUSR_mpa1(); // Set max nb of interfaces to return. welcomeOut->maxNbItf = NBBOTS; return 0; }