Esempio n. 1
0
int vehicleSimStartup(void)
{
    FILE * propertyFile = NULL;
    char *property = NULL;
    pthread_attr_t attr;	// Thread attributed for the component threads spawned in this function
    char fileName[128] = {0};

    // Create vehiclePosLla object
    vehiclePosLla = pointLlaCreate();
    if(!vehiclePosLla)
    {
        //cError("vehicleSim: Could not create vehicleSimThread\n");
        vehicleSimShutdown();
        return VEHICLE_SIM_MALLOC_ERROR;
    }

    sprintf(fileName, "%svehicleSim.conf", CONFIG_DIRECTORY);
    propertyFile = fopen(fileName, "r");
    if(propertyFile)
    {
        vehicleSimProperties = propertiesCreate();
        vehicleSimProperties = propertiesLoad(vehicleSimProperties, propertyFile);
        fclose(propertyFile);
    }
    else
    {
        //cError("vehicleSim: Cannot find or open properties file\n");
        return VEHICLE_SIM_LOAD_CONFIGURATION_ERROR;
    }

    property = propertiesGetProperty(vehicleSimProperties, "INITIAL_LAT_DEGREES");
    if(property)
    {
        vehiclePosLla->latitudeRadians = atof( property );
        //cDebug(3, "vehicleSim: Property loaded INITIAL_LAT_DEGREES: %lf\n", vehiclePosLla->latitudeRadians);
        vehiclePosLla->latitudeRadians *= RAD_PER_DEG;
    }
    else
    {
        //cDebug(3, "vehicleSim: Property INITIAL_LAT_DEGREES not found, using default value: %lf\n", vehiclePosLla->latitudeRadians);
    }

    property = propertiesGetProperty(vehicleSimProperties, "INITIAL_LON_DEGREES");
    if(property)
    {
        vehiclePosLla->longitudeRadians = atof( property );
        //cDebug(3, "vehicleSim: Property loaded INITIAL_LON_DEGREES: %lf\n", vehiclePosLla->longitudeRadians);
        vehiclePosLla->longitudeRadians *= RAD_PER_DEG;
    }
    else
    {
        //cDebug(3, "vehicleSim: Property INITIAL_LON_DEGREES not found, using default value: %lf\n", vehiclePosLla->longitudeRadians);
    }

    property = propertiesGetProperty(vehicleSimProperties, "INITIAL_HEADING_DEGREES");
    if(property)
    {
        vehicleH = atof( property );
        //cDebug(3, "vehicleSim: Property loaded INITIAL_HEADING_DEGREES: %lf\n", vehicleH);
    }
    else
    {
        //cDebug(3, "vehicleSim: Property INITIAL_HEADING_DEGREES not found, using default value: %lf\n", vehicleH);
    }

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    vehicleSimRun = TRUE;

    if(pthread_create(&vehicleSimThreadId, &attr, vehicleSimThread, NULL) != 0)
    {
        //cError("vehicleSim: Could not create vehicleSimThread\n");
        vehicleSimShutdown();
        pthread_attr_destroy(&attr);
        return VEHICLE_SIM_THREAD_CREATE_ERROR;
    }
    pthread_attr_destroy(&attr);

    return 0;
}
Esempio n. 2
0
int main(int argCount, char **argString)
{
	char keyPressed = FALSE;
	int keyboardLock = FALSE;
	double keyboardLockTime = ojGetTimeSec() + KEYBOARD_LOCK_TIMEOUT_SEC;
	time_t timeStamp;

	//Get and Format Time String
	time(&timeStamp);
	strftime(timeString, DEFAULT_STRING_LENGTH-1, "%m-%d-%Y %X", localtime(&timeStamp));

	system(CLEAR);

	//cDebug(1, "main: Starting Up %s Node Software\n", simulatorGetName());
//	if(simulatorStartup())
//	{
//		printf("main: %s Node Startup failed\n", simulatorGetName());
//		//cDebug(1, "main: Exiting %s Node Software\n", simulatorGetName());
//#if defined(WIN32)
//		system("pause");
//#else
//		printf("Press ENTER to exit\n");
//		getch();
//#endif
//		return 0;
//	}

	vehicleSimStartup();
	pd = pdCreate();
	gpos = gposCreate();
	vss = vssCreate();
	wd = wdCreate();

	setupTerminal();

	mainRunning = TRUE;

	while(mainRunning)
	{
		keyPressed = getUserInput();

		if(keyPressed)
		{
			keyboardLockTime = ojGetTimeSec() + KEYBOARD_LOCK_TIMEOUT_SEC;
		}
		else if(ojGetTimeSec() > keyboardLockTime)
		{
				keyboardLock = TRUE;
		}

		//if(verbose)
		//{
		//	choice = getc(stdin);
		//}
		//else // Not in verbose mode
		//{
		//	choice = getch(); // Get the key that the user has selected
		//	updateScreen(keyboardLock, choice);
		//}

		ojSleepMsec(100);
	}

	cleanupConsole();

	//cDebug(1, "main: Shutting Down %s Node Software\n", simulatorGetName());
	wdDestroy(wd);
	pdDestroy(pd);
	gposDestroy(gpos);
	vssDestroy(vss);
	vehicleSimShutdown();

	if(logFile != NULL)
	{
		fclose(logFile);
	}

	return 0;
}