int main() {
	printf("\n");
	getchar();
	esperar(100);
	esperar(1*1000);
	printf("%f\n",M_PI);
	return 0;
}
Beispiel #2
0
int main(void)
{
    /* Ejercicio : Completar este programa ejemplo para habilitar/deshabilitar
     * un GPIO (blink de un led conectado al puerto B de un atmega328p)
     *
     * Paso 1 : Establecer el 5to bit del puerto B como salida
     * (el puerto se puede utilizar como entrada o salida).
     * Para esto se debe poner en '1' el 5to bit de la dirección 0x24, que
     * es el la dirección del registro de dirección de los datos del puerto B
     * DDRB (Data Direction Register). El 5to bit estable como entrada o salida
     * el pin del atmega328p que tiene conectado un led en una board arduino
     */

    /*
    *
    * Paso 2:
    * Luego, para habilitar/deshabilitar (poner en ALTO/BAJO HIGH/LOW)
    * esa salida específica del puerto B
    * se debe poner en '1' el 5to bit de la dirección 0x25, que es la
    * dirección del registro que controla el estado HIGH o LOW del
    * pin de salida. En '1' ese bit enciende el led en una board arduino
    *
    * Poniendo en 0 la dirección anterior pone en LOW el pin de salida (apaga
    * el led)
    */

    /* Escribir un bucle infinito que repita los pasos 1 y 2, con un delay
     * entre el HIGH y LOW, de modo que pueda apreciarse el blink.
     */

    volatile unsigned char * puerto_b = (unsigned char *) 0x25;

    while (1) {

        *puerto_b = *puerto_b | LED_ROJO;
        esperar();

        *puerto_b = *puerto_b & (~LED_ROJO);
        esperar();
    }

}
int main(void)
{
  int fibonacci_num = 0;
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1DIR |= 0x01;                        // Set P1.0 to output direction
  P1OUT = 0x00;                         // Turn Off led.
  for(;;){
    fibonacci_num++;
    piscar(fibonacci(fibonacci_num));
    esperar(5);
  }
}
Beispiel #4
0
void main()
{
      sensor *ptr_termo, *ptr_termo_fin;
      brdInit();

      ptr_termo = termo;
      ptr_termo_fin = &termo[BUFF_TAM-1];

      while(1)
		{
      	esperar(1000);
      	ptr_termo->muestra = Termistor();
         getTimeStamp(timeStamp);
         printf("Temperatura %.2f C\nTimeStamp:\n%s\n", ptr_termo->muestra, timeStamp);

         if (ptr_termo > ptr_termo_fin)
         	ptr_termo = termo;
         ptr_termo+=1;
      }
}
ResultadoDeMovimiento VisualBoard::doMovements(vector<Movimiento> movimientos)
{
    ResultadoDeMovimiento res=SIGUE_MOVIENDO;
    bool fichaComida;
    for(Movimiento mov:movimientos)
    {
        fichaComida=tablero.esMovimientoConSalto(mov.filaOrigen,mov.colOrigen,mov.filaDestino,mov.colDestino);
        if(res!=SIGUE_MOVIENDO&&res!=DOBLE_MOV_Y_SIGUE_JUGANDO) break;
        if(!tablero.esMovimientoValido(mov.filaOrigen,mov.colOrigen,mov.filaDestino,mov.colDestino))
        {
            break;
        }
        res=tablero.moverFicha(mov.filaOrigen,mov.colOrigen,mov.filaDestino,mov.colDestino);
        if(fichaComida!=mov.fichaComida)
        {
            break;
        }
        cout<<"Lammando repaint"<<endl;
        repaint();
        esperar(300);
    }
    return res;
}
Beispiel #6
0
int main(){
	printf("--INICIÓ PROCESO HIJO--\n");
	init();     //inicializa operaciones
	
	
	int i, j, n;

	int shmid1,shmid2;
	key_t llave1,llave2;
	float *shm1;
	float *shm2;
	llave1 = 5677;
	llave2 = 5678;

	pid_t pid;
	char *argv[2];
	argv[0] = "Nieto";
	argv[1] = NULL;

	/*Creación de bloque de memoria compartida*/
	if((shmid1 = shmget(llave1, sizeof(float)*100, IPC_CREAT | 0666)) < 0)
	{
		perror("Error al obtener memoria compartida: shmget\n");
		exit(0);
	}
	if((shmid2 = shmget(llave2, sizeof(float)*100, IPC_CREAT | 0666)) < 0)
	{
		perror("Error al obtener memoria compartida: shmget\n");
		exit(0);
	}
	if((shm1 = shmat(shmid1, NULL, 0)) == (float *) -1){
		perror("Error al enlazar la memoria compartida: shmat\n");
		exit(0);
	}
	if((shm2 = shmat(shmid2, NULL, 0)) == (float *) -1){
		perror("Error al enlazar la memoria compartida: shmat\n");
		exit(0);
	}

	/*Obtención de las matrices del proceso padre*/
	Matriz m1 = crear(10, 10);
	Matriz m2 = crear(10, 10);
	for(i=0; i<10; i++){
		for(j=0; j<10; j++){
			n= (i*10) + j;
			m1->filas[i][j] = *(shm1+n);
			m2->filas[i][j] = *(shm2+n);
		}
	}
	
	/*Valores de las matrices para el proceso nieto*/
	srand(time(NULL));
	for(i=0; i<100; i++){
		*(shm1+i) = rand() % 11;
	}
	for(i=0; i<100; i++){
		*(shm2+i) = rand() % 11;
	}
	
	/*Creación del proceso hijo del hijo*/
	if((pid= fork())==-1)
		printf("Error al crear el proceso hijo del proceso hijo\n");
	if(pid == 0){
		execv(argv[0], argv);
	}
	else{
		Matriz m = mult(m1, m2);
	
		printf("\nMatriz 1 recibida del padre:\n");
		printMatriz(m1);
		printf("\nMatriz 2 recibida del padre:\n");
		printMatriz(m2);
		printf("\nM1*M2:\n");
		printMatriz(m);
	
		esperar(0); //esperamos que termine suma 
	
		printf("Hijo: Enviando mult a padre...\n");
		/*Guardando el producto en el bloque de memoria compartida*/
		for(i=0; i<10; i++){
			for(j=0; j<10; j++){
				n= (i*10) + j;
				*(shm1+n) = m->filas[i][j];
			}
		}
		printf("--FINALIZÓ PROCESO HIJO--\n");
		liberar(1); //termina multiplicación
		exit(0);
	}
	
}
Beispiel #7
0
TEST(FuncionesC, FormatoCadena) {
    esperar("Hola mundo\n");
    dado(sprintf(salida, "Hola %s\n", "mundo"));
}
Beispiel #8
0
TEST(FuncionesC, SinFormato) {
    esperar("hola");
    dado(sprintf(salida, "hola"));
}
void JuegoCliente::ejecutar(){

	if(puedoJugar){

		this->lector = new LectorTerreno(this->esc, this->esc->imagenTierra, this->cliente->getId());
		agregarTexturas(esc);
		agregarAgua(esc);
		this->dibujablesBase = new list<Dibujable*>(this->vista->getListaDibujables()->size());
		copy(this->vista->getListaDibujables()->begin(),this->vista->getListaDibujables()->end(),this->dibujablesBase->begin());


		this->cliente->enviarQuieroJugar();

		Reproductor::getReproductor()->activar();
		Logger::getLogger()->guardarEstado();
		//list<Dibujable*> *lista = new list<Dibujable*>(this->dibujablesBase->size());
		//game loop
		//espero que el servidor me diga q arranque...
		this->menu->agregarMensaje(string("Esperando a los demas jugadores..."),30,0,255,0);
		this->menu->dibujar();
		while(this->cliente->arrancarJuego == false){
		
			if (this->menu->leerEvento() == nameMenu::SALIR) return;
			this->cliente->actualizar();
		};
	
		const int SKIP_TICKS = 1000 / FPS;
		int sleepTime =0;
		DWORD next_game_tick = GetTickCount();


		while(!this->cliente->partidaTerminada && this->estadoActual != SALIDA && (evento->type != SDL_QUIT)){
			try{
				if(this->cliente->getTiempoActualDeJuego() == tiempoTurno) while(SDL_PollEvent(evento)); //vacio la lista de eventos.
				this->leerEvento();
				this->cliente->actualizar();
		
				this->reloj->setTiempoActual(this->cliente->getTiempoActualDeJuego());
		
				this->crearLista(this->cliente->vistaSerializada);

				if(this->cliente->nuevoMensaje){
					this->cartelInfo->setInfo(this->cliente->mensajeInfo);
					this->cliente->nuevoMensaje = false;
				}

				for(int i=0; i< maxExplosionesPorTurno; i++){
					if(this->cliente->exp[i].radio >= 0){
						this->vista->destruir(cliente->exp[i].x, cliente->exp[i].y, cliente->exp[i].radio, this->lector);
						this->vista->motor->generarExplosion(cliente->exp[i].x, cliente->exp[i].y);
						this->cliente->exp[i].radio = -1;
					}
				}

				this->vista->motor->actualizar();
			

				if(simulando){
					switch(estadoActual){

						case JUGANDO:		jugar();	break;
						case PAUSADO:		esperar();	break;
					}
				}
		
				vista->Dibujar();

				next_game_tick += SKIP_TICKS;
				sleepTime = next_game_tick - GetTickCount();
				if( sleepTime >= 0 ) {
					Sleep( sleepTime );
				}
			}
			catch(exception &e){
			
				cout<<"catch en JuegoCliente::ejecutar: "<<e.what()<<endl;
			};
		}

		if(this->cliente->partidaTerminada) this->volverAjugarCliente();

	}
}
Beispiel #10
0
int main(){
	init(); //inicializa operaciones

	int i, j, n;

	int shmid1,shmid2;
	key_t llave1,llave2;
	float *shm1;
	float *shm2;
	llave1 = 5677;
	llave2 = 5678;

	pid_t pid;
	char *argv[2];
	argv[0] = "Hijo";
	argv[1] = NULL;

	/*Creación de bloque de memoria compartida*/
	if((shmid1 = shmget(llave1, sizeof(float)*100, IPC_CREAT | 0666)) < 0)
	{
		perror("Error al obtener memoria compartida: shmget\n");
		exit(0);
	}
	if((shmid2 = shmget(llave2, sizeof(float)*100, IPC_CREAT | 0666)) < 0)
	{
		perror("Error al obtener memoria compartida: shmget\n");
		exit(0);
	}
	if((shm1 = shmat(shmid1, NULL, 0)) == (float *) -1){
		perror("Error al enlazar la memoria compartida: shmat\n");
		exit(0);
	}
	if((shm2 = shmat(shmid2, NULL, 0)) == (float *) -1){
		perror("Error al enlazar la memoria compartida: shmat\n");
		exit(0);
	}
	printf("shmid1: %d\n", shmid1);
	printf("shmid2: %d\n", shmid2);
	
	reset(0); //ponemos en 0 el semáforo
	reset(1); //ponemos en 0 el semáforo
	bloquear(0); //suma
	bloquear(1); //mult
	
	
	/*Valores de las matrices para el proceso hijo*/
	srand(time(NULL));
	for(i=0; i<100; i++){
		*(shm1+i) = rand() % 11;
	}
	for(i=0; i<100; i++){
		*(shm2+i) = rand() % 11;
	}
	
	/*Creación del proceso hijo*/
	if((pid= fork())==-1)
		printf("Error al crear el proceso hijo\n");
	if(pid == 0){
		execv(argv[0], argv);
	}
	else{	
	
		esperar(1); //esperamos operaciones
		/*Obtención de los resultados de la suma y producto*/
		Matriz mult = crear(10, 10);
		Matriz sum = crear(10, 10);
		for(i=0; i<10; i++){
			for(j=0; j<10; j++){
				n= (i*10) + j;
				mult->filas[i][j] = *(shm1+n);
				sum->filas[i][j] = *(shm2 + n);
			}
		}
		printf("Calculando inversas...\n");
		/*Matrices Inversas*/
		Matriz invMult = inv(mult);
		Matriz invSum = inv(sum);
		printf("\nMatriz inversa de la MULTIPLICACIÓN realizada por el HIJO:\n");
		printMatriz(invMult);
		printf("\nMatriz inversa de la SUMA realizada por el NIETO:\n");
		printMatriz(invSum);
		printf("\n");

		guardaMatriz(invMult, "multiplicacion.txt");
		guardaMatriz(invSum, "suma.txt");

		printf("Terminado.\n");

		exit(0);
	}
}