Exemplo n.º 1
0
// ----------------------------------------------------------------------------
// the callback used by G-WAN to generate the data pushed to clients
// ----------------------------------------------------------------------------
static int make_fn(char *argv[])
{
   // of course, instead of using pseudo-random data, one could agregate data
   // from a database back-end server, or from another application server, or 
   // use other client requests that bring new data (publishers) but we could
   // also calculate complex things here (scoring, simulations, etc.)
   //
   // the point is to do things once (here) for all the clients we feed 
   // instead of doing it repeatedly each time a client gets data
   //
   if(!s_data)
   {
      s_data = (float*)calloc(1, sizeof(float) * CELLS);
      if(!s_data)
         return 0;
   }

   static int once = 0;
   if(!once)
   {
      once = 1;
      sw_init(&rnd, (u32)getns()); // (period: 1 << 158)
   }
   
   int i = 0;
   while(i < CELLS)
      s_data[i++] = (sw_rand(&rnd) % 100000) / 100.;

   return 1;
}
Exemplo n.º 2
0
void mx_list_test_them( mx_list_t* ml )
{
    int i;
    socket_work sw;
    sw.max_socket = -1;
    sw.waiting_sockets = 0;
    // keep an  array of all our sockets  so that we can  close all of
    // them if we timeout
    sw.nb_sockets = g_list_length( ml->mxs );
    sw.socket_list = malloc( sizeof( int ) * sw.nb_sockets );
    
    FD_ZERO(&sw.readset);

    sw_init( &sw, ml );
    ml->mx_ok = sw_select( &sw );

    // close (eventual) remaining sockets
    for ( i = 0 ; i < sw.nb_sockets ; ++i ) {
        if ( sw.socket_list[ i ] > 0 ) {
            close( sw.socket_list[ i ] );
        }
    }
    
    free( sw.socket_list );
}
Exemplo n.º 3
0
int
skin_inf_ask (void)
{
  static int tick = 0;
  sw_struct sw;

  printf ("inferior ask\n");

  sw_init (&sw);
  sw_set_name (&sw, "MyEncoder");

  sw.type = SW_SEN_ENCODER;
  sw.op = SW_SEN_ENCODER_SET;
  sw.data.encoder.resolution = 0.001;
  sw.data.encoder.mount.x = 1;
  sw.data.encoder.mount.y = 2;
  sw.data.encoder.mount.z = -3;
  sw.data.encoder.mount.roll = -0.1;
  sw.data.encoder.mount.pitch = -0.2;
  sw.data.encoder.mount.yaw = 0.3;
  sup_tell (&sw);

  ulapi_wait (500000000);

  sw.op = SW_SEN_ENCODER_STAT;
  sw.time = ulapi_time ();
  sw.data.encoder.tick = tick++;

  sup_tell (&sw);

  ulapi_wait (500000000);

  return 0;
}
Exemplo n.º 4
0
int main(int argc, char**argv)
{
  int c;
  int dontDaemon = 0;
  char *sport = NULL;

  while ((c = getopt (argc, argv, "fvc:")) != -1)
    switch (c)
      {
      case 'f':
	fprintf(stderr, "softwedge not daemonizing...\n");
	dontDaemon = 1;
	break;
      case 'v':
	fprintf(stderr, "softwedge v %s: The serial softwedge X11 helper. ", SOFTWEDGE_VERSION);
	fprintf(stderr, "(c) 2007 Yann Ramin <*****@*****.**>\n(Exiting...)\n");
	exit(0);
      case 'c':
	sport = optarg;
	break;
      case '?':
	if (optopt == 'c')
	  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
	else if (isprint (optopt))
	  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
	else
	  fprintf (stderr,
		   "Unknown option character `\\x%x'.\n",
		   optopt);
	return 1;
      default:
	abort ();
      }

  if (sport == NULL)
    sport = DEFAULT_SERIAL;

  sw_init();

  sw_open_serial(sport);



  if (!dontDaemon) {
    if(fork()) {
      return 0;
    }
    
    close(0);
    close(1);
    close(2);
  }

  // Loop forever reading
  sw_read_loop();

  return 0;
}
Exemplo n.º 5
0
// Create bridge state
struct bs_t *bs_create(int tc) {
 struct bs_t *bs = malloc(sizeof(bstate_t));
 mutex_init(bs);
 sw_init(bs);
 bs->nid = 1;
 bs->bc = 0;
 bs->tc = tc;
 return bs;
}
Exemplo n.º 6
0
void resetApplInd(void)
{
#ifdef NO_PRINTF_S
    PUTCHAR('X');
#else
    PRINTF("Application reset\n");
#endif
    sw_init();
}
Exemplo n.º 7
0
static int init(void)
{
	extern int erodata, data_start, edata, bss_start, ebss;
	memcpy(&data_start, &erodata, (size_t)&edata - (size_t)&data_start);
	memset(&bss_start, 0, (size_t)&ebss - (size_t)&bss_start);

	led_init();
	sw_init();
	serial_init(SERIAL_DEFAULT_DEVICE);
/*    sci_init(SCIDEV1, 9600, 8, PARITY_NON, 1);*/
	Pool_init(&pool, pool_buf, sizeof pool_buf, sizeof pool_buf[0]);
}
Exemplo n.º 8
0
void clock_init(void)
{
	sw_init();
	chg_init();
	timer_init();

	time = 0;
	ticks = 0;
	digit_count = 0;
	refresh_running = 0;
	usb_enabled = 1;

	state = S_STANDBY;

	/* enable PC irqs */
	PCICR = _BV(PCIE0) | _BV(PCIE1) | _BV(PCIE2);
}
Exemplo n.º 9
0
void init_gpio_manager()
{
    int result = 0;

    if( gpio_initialized == XTRUE )
        return;

    result = sw_init();
    if( result < 0 )
        return -1;
    result = hw_init();
    if( result < 0 )
        return -1;

    gpio_initialized = XTRUE;

    return;
}
Exemplo n.º 10
0
/**
 * Initialize the templ theme
 * @param hue [0..360] hue value from HSV color space to define the theme's base color
 * @param font pointer to a font (NULL to use the default)
 * @return pointer to the initialized theme
 */
lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font)
{
    if(font == NULL) font = LV_FONT_DEFAULT;

    _hue = hue;
    _font = font;

    /*For backward compatibility initialize all theme elements with a default style */
    uint16_t i;
    lv_style_t **style_p = (lv_style_t**) &theme;
    for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t*); i++) {
        *style_p = &def;
        style_p++;
    }

    basic_init();
    cont_init();
    btn_init();
    label_init();
    img_init();
    line_init();
    led_init();
    bar_init();
    slider_init();
    sw_init();
    lmeter_init();
    gauge_init();
    chart_init();
    cb_init();
    btnm_init();
    kb_init();
    mbox_init();
    page_init();
    ta_init();
    list_init();
    ddlist_init();
    roller_init();
    tabview_init();
    win_init();

    return &theme;
}
Exemplo n.º 11
0
//----------------------------------------------------------------------------------------------------------------------------------
// FUNCTION: main()
//
// DESCRIPTION/ Where it all begins. Initialize the hardware and software. Drop into an infinite loop displaying the Nunchuk state information
// on the console.
//----------------------------------------------------------------------------------------------------------------------------------
int main()
{

	hw_init();
	sw_init();forever {
	// g_console_update will be set to 1 at a 1 Hz rate.
	while (!g_console_update) {}
	// Retrieve the Nunchuk data from the oct_nunchuk module and display it on the CodeWarrior console.
	 printf("%d %d %d %d %d %d %d\n",
	 oct_nunchuk_pos_x(),
	 oct_nunchuk_pos_y(),
	  oct_nunchuk_accel_x(), oct_nunchuk_accel_y(),
	 oct_nunchuk_accel_z(),
	 oct_nunchuk_button_c(),
	 oct_nunchuk_button_z()
	 );
	 // Clear g_console_update so we will get stuck in the while loop above until the next PIT0 interrupt.
	 g_console_update = 0;
	 }
}
Exemplo n.º 12
0
int main (int argc, char *argv[]){
  char buf[256];

#ifdef GRAPHICS
  gs_init(WIDTH, HEIGHT);
#endif
  
  sw_init();
  sw_start();
  RoadMap();
  sw_stop();

  sw_timeString(buf);
  
  printf("Time taken: %s\n",buf);

#ifdef GRAPHICS
  gs_exit();
#else
  printf("CRC is %x\n",crc);
#endif

  return 0;
}
Exemplo n.º 13
0
/*************************** SWITCH CLASS FUNCTIONS ****************************/
SWITCH :: SWITCH(uint8_t priority) :scheduler_task("SWITCH", 1024, priority)
{
    sw_init();
    setRunDuration(25);
}
Exemplo n.º 14
0
int main(void) {
	BOOL_T		err = CO_FALSE; /* error flag */
	UNSIGNED8   temp = 0;
	uword	time_lo = 0, time_hi = 0;

    /*--- hardware initialization e.g SIO, Chip-Selects, ...----------*/
    iniDevice();
	IO_vInit();
	USIC0_vInit();
	USIC1_vInit();
	USIC2_vInit();
#if HW_KPS == 1
	USIC3_vInit();
#endif
	//RTC init
    DAVE_vUnlockProtecReg();
	RTC_vInit();
    NOP();  /* one cycle delay */
    NOP();  /* one cycle delay */
    DAVE_vLockProtecReg();

	lNodeId = (~IO_uwReadPort(P2))&0xFF;
	if (lNodeId > 127) { lNodeId = 127; }
	temp = (~IO_uwReadPort(P10))&0x0F;
	switch(temp){
		case 0: bitRate = 10; break;
		case 1: bitRate = 20; break; 
		case 2: bitRate = 50; break; 
		case 3: bitRate = 125; break; 
		case 4: bitRate = 250; break; 
		case 5: bitRate = 500; break; 
		case 0x9:
		case 0xE:
		case 0xF:
			bitRate = 125;
			if (((~IO_uwReadPort(P2)) & 0xFF) == 0){ lNodeId = 127;	}
		break;
		default: bitRate = 500; break;
	}

    initCan(bitRate);
    init_Library();
    initTimer();
    Start_CAN();
    ENABLE_CPU_INTERRUPTS();
	RTC_vSetTime(0,0);

	sw_init();

	//PRINTF("loop\n");
    while (err == CO_FALSE) {
		FlushMbox();		         /* Do the CANopen job */
		myRTC_ulGetTime(&time_lo, &time_hi);

		//odczyt temperatury wewn.
		status_wewn[2] = ad7814_read(U2C0, SPI_CS3); 

		sw_loop();

		//sygnalizacja na diodach

		if (blink(time_lo, ch1_led_st)) {	//St1
			IO_vResetPin(IO_P0_0_LED_ST1);
		} else {
			IO_vSetPin(IO_P0_0_LED_ST1);
		}

		if (blink(time_lo, ch2_led_st)) {	//St2
			IO_vResetPin(IO_P4_1_LED_ST2);
		} else {
			IO_vSetPin(IO_P4_1_LED_ST2);
		}

		if (blink(time_lo, ch1_led_err)) {	//Err1
			IO_vResetPin(IO_P4_2_LED_ERR1);
		} else {
			IO_vSetPin(IO_P4_2_LED_ERR1);
		}

		if (blink(time_lo, ch2_led_err)) {	//Err2
			IO_vResetPin(IO_P4_0_LED_ERR2);
		} else {
			IO_vSetPin(IO_P4_0_LED_ERR2);
		}

//w funkcji err_code dopisac cykliczna informacje o kilku bledach (numer bledu jako bity w slowie "dev_led_st" a nie wartosc)
		if (err_code(time_lo, dev_led_st)) {	//err code - Yellow diode
			IO_vResetPin(IO_P2_8_LED_C);
		} else {
			IO_vSetPin(IO_P2_8_LED_C);
		}

		/* give a chance to finish the loop */
		err = endLoop();
    }
    PRINTF("\nSTOP\n");
    Stop_CAN();
    DISABLE_CPU_INTERRUPTS();
    releaseTimer();
    ResetIntMask();
    deinit_Library();
    return 0; 
}
Exemplo n.º 15
0
int main(void) {
    wdt_enable(WDTO_4S);
    wdt_reset();
    /* configure PPM output port */
    PPM_DDR |= (1<<PPM_BIT);
    PPM_PORT &= ~(1<<PPM_BIT);

    /* configure LED output port */
    LED_DDR |= (1<<LED_BIT);
    LED_PORT |= (1<<LED_BIT);

    /* configure VOL(tage) warning port */
    VOL_DDR &= ~(1<<VOL_BIT);
    VOL_PORT |= (1<<VOL_BIT); // enable pullup

#ifdef ENABLE_SERIAL
    serial_init();
#endif
#ifdef ENABLE_TWI
    twi_init();
#endif
#ifdef USE_NUNCHUK
    nunchuk_init();
    wdt_reset();
#endif

    /* configure switches */
    sw_init();

    /* configure ADC */
    adc_init();

#if defined(USE_TWI_ADC)
    twi_adc_init();
    wdt_reset();
#endif
#if defined(USE_MAG)
    mag_init();
    wdt_reset();
#endif
#if defined(USE_ACC)
    acc_init();
#endif
#if defined(USE_LCD)
    /* initialize LCD twice (due to timing issues?) */
    lcd_init();
    wdt_reset();
    _delay_ms(100);
    wdt_reset();
    lcd_init();
    wdt_reset();
    lcd_splash();
#endif

    /* configure watchfog timer to reset after 60ms */
    wdt_enable(WDTO_60MS);

    /* configure timer */

    /* enable CTC waveform generation (TOP == OCR1A) */
    TCCR1B |= (1<<WGM12);
    /* set compare value for the stop pulse to 300µs */
    OCR1B = STOP_US;
    /* set pulse width to max for now */
    OCR1A = ~0;
    /* set Timer 1 to clk/8, giving us ticks of 1 µs */
    TCCR1B |= (1<<CS11);

    /* Timer 2 generates overflows at 1kHz */
#if defined(TCCR2) /* e.g. ATMega8 */
#define TIMER2_COMP_IRQ TIMER2_COMP_vect
    TCCR2 = (1<<WGM21 | 1<<CS22);
    OCR2 = 0x7D;
    /* enable compare and overflow interrupts */
    TIMSK = (1<<OCIE2 | 1<<OCIE1B | 1<<OCIE1A);
#elif defined(TCCR2A) /* e.g. ATMega{8,16,32}8 */
#define TIMER2_COMP_IRQ TIMER2_COMPA_vect
    TCCR2A = (1<<WGM21);
    TCCR2B = (1<<CS22);
    OCR2A = 0x7D;
    /* enable compare and overflow interrupts */
    TIMSK1 = (1<<OCIE1B | 1<<OCIE1A);
    TIMSK2 = (1<<OCIE2A);
#else
#error "Unable to determine timer 2 configuration registers"
#endif

    /* initialize channel data */
    start_ppm_frame();
    set_ppm(1);
    start_ppm_pulse();

    /* enable interrupts */
    sei();

    serial_write_str("Welcome!\n");
    while (1) {
        /* reset watchdog */
        wdt_reset();

        /* keep sampling adc data */
        adc_query();

        /* query switches */
        sw_query();

        /* prepare Datenschlag data frames */
        ds_prepare();

#ifdef USE_TWI_ADC
        /* query TWI/I²C ADC */
        twi_adc_query();
#endif
#if defined(USE_MAG)
#ifdef MAG_CENTER_CALIBRATION_TRIGGER_INPUT
        if (get_input_scaled( (MAG_CENTER_CALIBRATION_TRIGGER_INPUT), 1, -1) == (MAG_CENTER_CALIBRATION_TRIGGER_VALUE)) {
            mag_set_calibration(millis + 10000L);
        }
#endif
        if (mag_is_calibrating()) {
            mag_calibrate(0);
        } else {
            mag_calibrate(1);
            mag_query();
            mag_dump();
        }
#endif
#if defined(USE_ACC)
        acc_query();
        acc_dump();
#endif

#ifdef USE_NUNCHUK
        nunchuk_query();
#endif

        check_voltage();

        /* switch LED */
        if (!low_voltage || (millis/250 % 2)) {
            LED_PORT |= (1<<LED_BIT);
        } else {
            LED_PORT &= ~(1<<LED_BIT);
        }

#ifdef USE_LCD
        static enum {
            LCD_MODE_STATUS,
#ifdef LCD_MENU
            LCD_MODE_MENU,
#endif
            LCD_MODE_CNT
        } lcd_mode;

        uint8_t lcd_mode_changed = 0;
#ifdef LCD_MODE_SWITCH_INPUT
        static int8_t old_sw_state = 0;
        int8_t sw_state = get_input_scaled(LCD_MODE_SWITCH_INPUT, -1, 1);
        if (old_sw_state != sw_state) {
            lcd_mode += LCD_MODE_CNT;
            lcd_mode += sw_state;
            lcd_mode %= LCD_MODE_CNT;
            old_sw_state = sw_state;
            lcd_mode_changed = 1;
        }
#endif
        switch (lcd_mode) {
        case LCD_MODE_STATUS:
            lcd_status_update(lcd_mode_changed);
            break;
#ifdef LCD_MENU
        case LCD_MODE_MENU:
            lcd_menu_update(lcd_mode_changed);
            break;
#endif
        default:
            break;
        }
#endif
    }
    return 0;
}
Exemplo n.º 16
0
int main(void) {
	/* configure PPM output port */
	PPM_DDR |= (1<<PPM_BIT);
	PPM_PORT &= ~(1<<PPM_BIT);

	/* configure LED output port */
	LED_DDR |= (1<<LED_BIT);
	LED_PORT |= (1<<LED_BIT);

	/* configure VOL(tage) warning port */
	VOL_DDR &= ~(1<<VOL_BIT);
	VOL_PORT |= (1<<VOL_BIT); // enable pullup

	serial_init();
	serial_write_str("Serial Active\n\r");
	/* configure switches */
	sw_init();
	serial_write_str("Switches Inited\n\r");
	/* configure PS2 pad */
	serial_write_str("Activating PS2 Pad...");
	psx_init(PSX_SPI,PSX_DAT,PSX_SPI,PSX_CLK,PSX_SPI,PSX_COM,PSX_ATT,PSX_ATN);
	serial_write_str("Done\n\r");
	/* configure ADC */
	adc_init();
/*
	// configure watchfog timer to reset after 60ms 
	wdt_enable(WDTO_60MS);

	// configure timer 

	// enable CTC waveform generation (TOP == OCR1A) 
	TCCR1B |= (1<<WGM12);
	// set compare value for the stop pulse to 300µs 
	OCR1B = STOP_US;
	// set pulse width to max for now 
	OCR1A = ~0;
	// set Timer 1 to clk/8, giving us ticks of 1 µs 
	TCCR1B |= (1<<CS11);

	// Timer 2 generates overflows at 1kHz 
#if defined(TCCR2) // e.g. ATMega8 
#define TIMER2_COMP_IRQ TIMER2_COMP_vect
	TCCR2 = (1<<WGM21 | 1<<CS22);
	OCR2 = 0x7D;
	// enable compare and overflow interrupts 
	TIMSK = (1<<OCIE2 | 1<<OCIE1B | 1<<OCIE1A);
#elif defined(TCCR2A) // e.g. ATMega{8,16,32}8 
#define TIMER2_COMP_IRQ TIMER2_COMPA_vect
	TCCR2A = (1<<WGM21);
	TCCR2B = (1<<CS22);
	OCR2A = 0x7D;
	// enable compare and overflow interrupts 
	TIMSK1 = (1<<OCIE1B | 1<<OCIE1A);
	TIMSK2 = (1<<OCIE2A);
#else
#error "Unable to determine timer 2 configuration registers"
#endif

	// initialize channel data 
	start_ppm_frame();
	set_ppm(1);
	start_ppm_pulse();

	// enable interrupts 
	sei();
*/
	serial_write_str("Welcome!\n");
	while (1) {
		/* reset watchdog */
//		wdt_reset();

		/* keep sampling adc data */
//		adc_query();

		/* query switches */
//		sw_query();

		/* query PS2 Pad */
		ps2_query();

		/* prepare Datenschlag data frames */
//		ds_prepare();

		//if (psx_stick(5)>=140) serial_write_str("Over  140\r");
		//if (psx_stick(5)<=100) serial_write_str("Under 100\r");
		serial_write_str("Triangle=");
		if (psx_button(PSB_TRIANGLE)) serial_write_str("1");
		else serial_write_str("0");
		
		serial_write_str(" Square=");
		if (psx_button(PSB_SQUARE)) serial_write_str("1");
		else serial_write_str("0");
		
		serial_write_str(" Cross=");
		if (psx_button(PSB_CROSS)) serial_write_str("1");
		else serial_write_str("0");

		serial_write_str(" Circle=");
		if (psx_button(PSB_CIRCLE)) serial_write_str("1");
		else serial_write_str("0");
		serial_write_str("\r");
		/* check voltage */
		//if ((~VOL_PIN) & 1<<VOL_BIT) {
		if ((VOL_PIN) & 1<<VOL_BIT) {
			// everything OK
			//LED_PORT |= (1<<LED_BIT);
			LED_PORT &= ~(1<<LED_BIT);
		} else {
			// voltage dropped, alert the user!
			if (millis/250 % 2) {
				LED_PORT |= (1<<LED_BIT);
			} else {
				LED_PORT &= ~(1<<LED_BIT);
			}

		}
	}
	return 0;
}
Exemplo n.º 17
0
int main(int argc, char* argv[])
{

	char* input = NULL;
	char* output = NULL;	

	if(argc == 6) {
		input = argv[1];
		output = argv[2];
		SPU_THREADS = atoi(argv[3]);
		PPEid = atoi(argv[4]);
		file = argv[5]; 	
	} else if (argc == 4) {
		PPEid = 0;
		file = NULL; 		 		
		input = argv[1];
		output = argv[2]; 	
		SPU_THREADS = atoi(argv[3]);
	} else if (argc == 5) {
		PPEid = 0;
		file = NULL; 		 		
		input = argv[1];
		output = argv[2]; 	
		SPU_THREADS = atoi(argv[3]);
		
	} else {
		printf("Wrong number of arguments %i\n", argc);
		return -1;
	}
	
	pthread_t* threads;	
	struct IMAGE_FORMAT result;
	unsigned char* energy;
	unsigned char* cmap;
	unsigned char* scale;
	int scale_size = 9;
	char timer_buffer[256];
	int y, x;
	size_t i;

	WIDTH = 576;
	HEIGTH = 708;
	
	threads = dsmcbe_simpleInitialize(PPEid, file, SPU_THREADS);


	unsigned int* speIDs = dsmcbe_create(SPEID + PPEid, 4);
	*speIDs = PPEid * SPU_THREADS;
	dsmcbe_release(speIDs);

	if (PPEid == 0)
	{
		//printf("Starting loading images!\n");	
		loadImageNormal();
		//loadImageSmall();
		//printf("Finished loading images!\n");
		
			
		//for(i = 0; i < ROUNDS; i++)
		//{
			//struct POINTS* points = create(RESULT + i, sizeof(struct POINTS) * SHOTS_SPU);
			//memset(points, 0, sizeof(struct POINTS) * SHOTS_SPU);
			//release(points);	
		//}
	
			
		energy = dsmcbe_create(ENERGY+PPEid, (sizeof(unsigned char) * (HEIGTH * WIDTH)));
		memset(energy, 0, sizeof(unsigned char) * (HEIGTH * WIDTH));
	
		cmap = (unsigned char*)malloc(sizeof(unsigned char)*(9*3));
		cmap[0] = 0; cmap[1] = 0; cmap[2] = 85;
		cmap[3] = 0; cmap[4] = 0; cmap[5] = 170;
		cmap[6] = 0; cmap[7] = 0; cmap[8] = 255;
		cmap[9] = 0; cmap[10] = 85; cmap[11] = 0;
		cmap[12] = 0; cmap[13] = 170; cmap[14] = 0;
		cmap[15] = 0; cmap[16] = 255; cmap[17] = 0;
		cmap[18] = 85; cmap[19] = 0; cmap[20] = 0;
		cmap[21] = 170; cmap[22] = 0; cmap[23] = 0;
		cmap[24] = 255; cmap[25] = 0; cmap[26] = 0;
	
		scale = (unsigned char*)malloc(sizeof(unsigned char)*9);
		scale[0] = 10; scale[1] = 20; scale[2] = 30;
		scale[3] = 40; scale[4] = 50; scale[5] = 60;
		scale[6] = 70; scale[7] = 80; scale[8] = 90;
		
		srand(1);
	
		//Start timer!
		sw_init();
		sw_start();
				
		printf("Timer started\n");
	
		printf("Start firering canon #1\n");
		canon(0, SHOTS, SHOTS_SPU, 85, 75, 1.0, 0.8, energy);
		printf("Stopped firering canon #1\n");
	
		printf("Start firering canon #2\n");
		canon(1, SHOTS, SHOTS_SPU, 10, 230, 1.0, 0.0, energy);
		printf("Stopped firering canon #2\n");
	
		printf("Start firering canon #3\n");
		canon(2, SHOTS, SHOTS_SPU, 550, 230, -1.0, 0.0, energy);
		printf("Stopped firering canon #3\n");
	
		printf("Start firering canon #4\n");
		canon(3, SHOTS, SHOTS_SPU, 475, 90, -1.0, 0.75, energy);
		printf("Stopped firering canon #4\n");
		
		printf("Start firering canon #5\n");
		canon(4, SHOTS, SHOTS_SPU, 280, 0, 0.0, 1.0, energy);
		printf("Stopped firering canon #5\n");
			
		// Stop timer!
		sw_stop();
		sw_timeString(timer_buffer);
		printf("Time used: %s\n", timer_buffer);
	
		readimage_rgb(input, malloc, &result);
		unsigned long size;

		//printf("Starting harvest\n");		
		for(i=1; i<MAX(dsmcbe_MachineCount(), 1); i++)
		{
			//printf("START - FINISHJOB %i\n", FINISHJOB+i);
			dsmcbe_release(dsmcbe_acquire(FINISHJOB+i, &size, ACQUIRE_MODE_READ));
			//printf("END - FINISHJOB %i\n", FINISHJOB+i);
			//printf("START - ENERGY %i\n", ENERGY+i);
			unsigned char* temp = dsmcbe_acquire(ENERGY+i,&size, ACQUIRE_MODE_READ);

			for(y=0; y<HEIGTH; y++)
			{
				for(x=0; x<WIDTH; x++)
				{
					energy[MAPOFFSET(x,y)] = temp[MAPOFFSET(x,y)];
				}
			}
			dsmcbe_release(temp);
			//printf("END - ENERGY %i\n", ENERGY+i);
		}
		
		//printf("Harvest done\n");

		// Save energy map to image
		for(y=0; y<HEIGTH; y++)
		{
			for(x=0; x<WIDTH; x++)
			{
				if(energy[MAPOFFSET(x,y)] > 0)
				{
					int offset = 3 * fpos(scale, scale_size, energy[MAPOFFSET(x,y)]);
					result.image[MAPOFFSET(x,y)].r = cmap[offset];
					result.image[MAPOFFSET(x,y)].g = cmap[offset+1];
					result.image[MAPOFFSET(x,y)].b = cmap[offset+2];
				}
			}			
		}
		
		//printf("Done\n");

		dsmcbe_release(energy);
		writeimage_rgb(output, &result);
	
		free(cmap);
		free(scale);
		free(result.image);
	}

	if (PPEid != 0)
	{	
		energy = dsmcbe_create(ENERGY+PPEid, sizeof(unsigned char) * (708 * 576));
		memset(energy, 0, sizeof(unsigned char) * (708 * 576));
		
		collectResults(0, SHOTS, SHOTS_SPU, energy);
		collectResults(1, SHOTS, SHOTS_SPU, energy);
		collectResults(2, SHOTS, SHOTS_SPU, energy);
		collectResults(3, SHOTS, SHOTS_SPU, energy);
		collectResults(4, SHOTS, SHOTS_SPU, energy);
		
		dsmcbe_release(energy);
		
		//printf("CREATING - FINISHJOB %i\n", FINISHJOB+PPEid);
		dsmcbe_release(dsmcbe_create(FINISHJOB+PPEid, sizeof(unsigned int)));
		//printf("CREATED\n");
		
		for(i = 0; i < SPU_THREADS; i++)
			pthread_join(threads[i], NULL);
	}
	
	printf("Going to sleep before we die\n");
	//sleep(10);
	return 0;
}
Exemplo n.º 18
0
int main(int argc,char *argv[]){
	if ( argc < 3 ){
		printf("input error:handle splitnum\n");
		return -1;
	}
	FILE *fp;
	wam_init(NULL);
	WAM *w;
	u_int id;
        char *name;
	w = wam_open(argv[1]);
	if(!w){
		printf("wamopen error\n");
		return -1;
	}
	int i,j;


	struct syminfo qq[1000];
	struct syminfo *q = qq;
/*
	q.id = id;
	q.TF_d = 1;
	q.TF = 1;
	q.weight = NaN;
	q.attr = WSH_OR;
*/
	char ** sw = malloc(100 * sizeof( char* ) );;
	int sw_len = sw_init(sw);
	char** filename = malloc(4000 * sizeof(char*) );
	int filenum = trave_dir("/home/ko/topics/",filename);
	char temp[100] , *p, *term[1000];
	ssize_t k = 0;
	int l;
	for(j=0;j<filenum;j++){
		k = 0;
		fp = fopen(filename[j],"r");
		printf("%s\n",filename[j]);
		term[k] = malloc( 100*sizeof(char) );
		while(fscanf(fp,"%s",term[k]) != EOF){ 
			k++;
			term[k] = malloc( 100*sizeof(char) );
		}
		free(term[k]);

		fclose(fp);
		char opfile[50];
		if ( strcmp(argv[2] , "all" ) == 0 ){
                        snprintf(opfile,50,"%s/split/%s",RESULTPATH,filename[j]+strlen(filename[j])-8);
                        fp = fopen(opfile,"w");
                        for(l=0;l<k;l++){
				ssize_t kk = 1;
                                query(q,w,&term[l],&kk,0,sw,sw_len);
				if(kk <= 0){
                                        continue;
                                }

                                ssize_t len = 0;
                                ssize_t num = 1000;

                                struct syminfo *result = wsh(q,kk,w,WAM_COL,WT_SMARTAW,&num,&len);
                                fprintf(fp,"query:%d\nnum:%d\nresult:%d\n",kk,num,len);
                                for(i=0;i<num;i++){
                                        fprintf(fp,"name:%s df_d:%d df:%d tf_d:%d tf:%d weight:%lf\n",wam_id2name(w, WAM_ROW, result[i].id),result[i].DF_d,result[i].DF,result[i].TF_d,result[i].TF,result[i].weight);
                                }
                        }
                        fclose(fp);
		}else{
			int SPLIT = atoi(argv[2]);
			snprintf(opfile,50,"%s/%d/%s",RESULTPATH,SPLIT,filename[j]+strlen(filename[j])-8);
			//printf("file:%s\n",opfile);
			fp = fopen(opfile,"w");
			for(l=0;l<SPLIT;l++){
				ssize_t kkk = k/SPLIT;
				ssize_t kk = kkk;
				if(l == SPLIT-1) kk = k - kkk*l;
				query(q,w,&term[kkk*l],&kk,0,sw,sw_len);
				ssize_t len = 0;
        			ssize_t num = 1000;
        			if(kk <= 0){
                			printf("qlen <= 0\n");
					fprintf(fp,"query:%d\nnum:%d\nresult:%d\n",kk,0,len);
					continue;
        			}
	
        			struct syminfo *result = wsh(q,kk,w,WAM_COL,WT_SMARTAW,&num,&len);
				if(len > 1000) printf("%s over 1000\n",filename[j]);
        			fprintf(fp,"query:%d\nnum:%d\nresult:%d\n",kk,num,len);
        			for(i=0;i<num;i++){
                			fprintf(fp,"name:%s df_d:%d df:%d tf_d:%d tf:%d weight:%lf\n",wam_id2name(w, WAM_ROW, result[i].id),result[i].DF_d,result[i].DF,result[i].TF_d,result[i].TF,result[i].weight);
				}	
			}
			fclose(fp);
		}
	
	}
	return 0;
}
Exemplo n.º 19
0
// ----------------------------------------------------------------------------
// imported functions:
//   get_reply(): get a pointer on the 'reply' dynamic buffer from the server
//     get_env(): get connection's 'environment' variables from the server
//    xbuf_cat(): like strcat(), but it works in the specified dynamic buffer 
//   gif_build(): build an in-memory GIF image from a bitmap and palette
// ----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
   // -------------------------------------------------------------------------
   // build the top of our HTML page
   // -------------------------------------------------------------------------
   static char top[]=
     "<!DOCTYPE HTML>"
     "<html lang=\"en\"><head><title>Captcha</title><meta http-equiv"
     "=\"Content-Type\" content=\"text/html; charset=utf-8\">"
     "<link href=\"/imgs/style.css\" rel=\"stylesheet\" type=\"text/css\">"
     "</head><body style=\"margin:0 16px;\"><br><h2>Captcha for Humans</h2>"
     "<p>Please enter the SUM of all the GREEN FIGURES (not letters) below "
     "(that's twice the same image, just with a different HTML background "
     "- the Data-URI-inlined GIF background is transparent):</p><br>\r\n";

   xbuf_t *reply = get_reply(argv);
   xbuf_ncat(reply, top, sizeof(top) - 1);
   
   // -------------------------------------------------------------------------
   // allocate memory for a raw bitmap
   // -------------------------------------------------------------------------
   const int w = BMP_WIDTH, h = BMP_HEIGHT, wXh = w * h;
   u8 *bmp = (u8*)calloc(CHAR_WIDTH * w, h); 
   if(!bmp) return 503; // service unavailable

   // -------------------------------------------------------------------------
   // render the captcha in our bitmap
   // -------------------------------------------------------------------------
   u32 seed = (u32)getns();
   prnd_t rnd; // pseudo-random generator (period: 1 << 158)
   sw_init(&rnd, seed); // EPOCH time in nano-seconds

   // structure needed by G-WAN's frame buffer routines like dr_text()
   bmp_t img ={ .bmp = bmp, .p = bmp, .bbp = 8, .pen = 1, .bgd = 0, 
                .rect = {0,0, w,h}, .flags = 0, .w = w, .h = h, 
                .x = 0, .y = 0 };
   u32 sum = captcha(&img, &rnd);

   // -------------------------------------------------------------------------
   // build the GIF image, gif_build(0:transparent color index, 0: no comment)
   // -------------------------------------------------------------------------
   u8 pal[] = { 255, 255, 255,  223, 255, 191,  132, 164, 100,  0, 0, 0 };
   const int nbcolors = (sizeof(pal) / sizeof(u8)) / 3; // RGB values

   u8 *gif = (u8*)malloc(CHAR_WIDTH * wXh);
   if(!gif) { free(bmp); return 503; } // service unavailable
   int gln = gif_build(gif, bmp, w, h, pal, nbcolors, 0, 0);

   // -------------------------------------------------------------------------
   // store the base64 encoded GIF in the 'reply' buffer
   // -------------------------------------------------------------------------
   if(gln > 0) // (gln == -1) if gif_build() failed
   {   
      // a real captcha test would only display the first of those two views:
      // (they are shown side-by-side to visualize the background trick)
      xbuf_cat(reply, "<table><tr>\r\n"
                      "<td style=\"background:#dfffbf;\">\r\n");
      u32 img_pos = reply->len;
      xbuf_xcat(reply,
                "<img src=\"data:image/gif;base64,%*B\" alt=\"A tree\" "
                "width=\"%d\" height=\"%d\" /></td>\r\n",
                gln, gif, w + w, h + h); // scale picture
      xbuf_xcat(reply, 
                "<td style=\"background:#84a464;\">%.*s</tr>\r\n</table>\n\r",
                reply->len - img_pos, reply->ptr + img_pos);
   }
   free(gif);
   free(bmp);

   // -------------------------------------------------------------------------
   // close our HTML page
   // -------------------------------------------------------------------------
   xbuf_xcat(reply, 
            "<br>The two sums are: <b>%u</b> and <b>%u</b>... "
            "for the same Captcha image!<br><br>"
            "By just changing the <b>HTML background color</b> (mouse cursor "
            "hovering, previous state or input or shared secret) used for "
            "the transparent GIF Captcha image we can make something simple "
            "for humans become difficult or even completely impossible "
            "for robots.<br><br>"
            "HTML and GIF are served with one single request: the picture"
            " is generated on-the-fly and embedded into the HTML code by "
            " using the base64 encoding (look at the HTML source code)."
            "<br></body></html>", 
            (sum & 0xffff0000) >> 16, 
            sum & 0x0000ffff);

   return 200; // return an HTTP code (200:'OK')
}