Esempio n. 1
0
File: spi.c Progetto: seL4/util_libs
int
spi_xfer(spi_bus_t* spi_bus, const void* txdata, size_t txcnt,
         void* rxdata, size_t rxcnt, spi_callback_fn cb, void* token)
{
    spi_bus->txbuf = (uint8_t*)txdata;
    spi_bus->rxbuf = (uint8_t*)rxdata;
    spi_bus->rxsize = rxcnt;
    spi_bus->txsize = txcnt;
    spi_bus->txtotal = txcnt;
    spi_bus->rxtotal = rxcnt;
    spi_bus->rxcnt = 0;
    spi_bus->txcnt = 0;
    spi_bus->bytes = 0;

    DSPI("Starting transfer: TX: from 0x%x, %d bytes. RX to 0x%x, %d bytes\n",
         (uint32_t)txdata, txcnt, (uint32_t)rxdata, rxcnt);
    spi_debug(XFER_SPI_FUNC_NAME "line: %d\n", __func__, __LINE__);

    //Moving chip select to calling component so that it can use GPIO

    if (cb == NULL) {
        spi_debug( XFER_SPI_FUNC_NAME "calling with out callback\n");
        while (transfer_data(spi_bus));
    } else {
        uint32_t v;
        spi_bus->cb = cb;
        spi_bus->token = token;
        v = SPI_IE_TX | SPI_IE_RX;
        spi_bus->regs->dma_ctl = v;
        spi_debug( XFER_SPI_FUNC_NAME "line: %d calling with callback\n", __func__, __LINE__);
        transfer_data(spi_bus);
    }
    spi_debug_xfer( XFER_SPI_FUNC_NAME "line: %d\n", __func__, __LINE__);
    return spi_bus->rxcnt;
}
Esempio n. 2
0
File: rpc.c Progetto: CCI/cci
static void
progress_server(void)
{
	int ret;
	cci_event_t *event;

	ret = cci_get_event(endpoint, &event);
	if (ret == CCI_SUCCESS) {
		assert(event);
		switch (event->type) {
		case CCI_EVENT_RECV:
			if (event->recv.len != 3) {
				msg = (void*)event->recv.ptr;
				transfer_data(*msg);
			} else {
				done = 1;
			}
			break;
		case CCI_EVENT_SEND:
			if (event->send.status != CCI_SUCCESS) {
				int cnt = (int)((uintptr_t)event->send.status);

				transfer_data(cnt);
			}
			break;
		default:
			fprintf(stderr, "ignoring event type %d\n",
				event->type);
		}
		cci_return_event(event);
	}
	return;
}
Esempio n. 3
0
static int
io_loop (FILE *client, FILE *server, FILE *protocol)
{
  fd_set active_fd_set, read_fd_set;
  int ret;
  int err;

  FD_ZERO (&active_fd_set);
  FD_SET (fileno (client), &active_fd_set);
  FD_SET (fileno (server), &active_fd_set);

  err = 0;

  while (1)
    {
      read_fd_set = active_fd_set;

      /* FIXME: eof?  */

      ret = select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL);
      if (ret < 0)
	{
	  err = errno;
	  break;
	}

      if (FD_ISSET (fileno (client), &read_fd_set))
	{
	  if (feof (client))
	    break;

	  /* Forward data from client to server.  */
	  err = transfer_data (client, server, protocol);
	}
      else if (FD_ISSET (fileno (server), &read_fd_set))
	{
	  if (feof (server))
	    break;

	  /* Forward data from server to client.  */
	  err = transfer_data (server, client, protocol);
	}

      if (err)
	break;
    }

  return err;
}
Esempio n. 4
0
int Steriss::exec () {
  try {
    std::list<std::string> valid_stems;
    valid_stems.push_back(".tiff");
    valid_stems.push_back(".tif");
    valid_stems.push_back(".bmp");
    valid_stems.push_back(".pgm");
    IO input_images( valid_stems );
    JobSplitter jobs( input_images );

    while( jobs.hasNext() ) {
      // read images
      _current_data = jobs.nextJob();
      sINFO(">> Running job %i of %i", %jobs.currentJob() %jobs.jobCt());

      // do the processing
      preprocess_data ();
      transfer_data ();
      process_data ();

      // write images
      input_images.writeImages( _current_data, jobs.currentStartIndex(), jobs.currentEndIndex() );

      // make sure to release the memory for the next turn
      _current_data.reset();
    }

    sINFO("All done. Now it's up to you - I'll have a break...");
    return EXIT_SUCCESS;
  } catch(std::exception& e) {
    return EXIT_FAILURE;
  }
}
Esempio n. 5
0
void display_string_8x16(unsigned char page,char column,char *text)
{
uint16_t i=0,j,k,n;
//Set_PINCS(0);
	
while(text[i]>0x00)
{
if((text[i]>=0x20)&&(text[i]<=0x7e))
{
j=text[i]-0x20;
for(n=0;n<2;n++)
{
lcd_address(page+n,column);
for(k=0;k<8;k++)
{
transfer_data(ascii_table_8x16[j][k+8*n]);/*??5x7 ?ASCII ??LCD ?,y ????,x ????,?????*/
}
}
i++;
column+=8;
}
else
i++;
}

//Set_PINCS(1);
}
Esempio n. 6
0
void stack_copy(struct stack_t *from, struct stack_t *to)
{
	to->data = (int*)malloc(from->size * sizeof(int));
	transfer_data(from->data, from->size, to->data);
	to->size = from->size;
	to->top = from->top;
}
Esempio n. 7
0
int main()
{
	struct netif *netif, server_netif;
	struct ip_addr ipaddr, netmask, gw;

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };

	netif = &server_netif;

	init_platform();

	/* initliaze IP addresses to be used */
	IP4_ADDR(&ipaddr,  192, 168,   1, 10);
	IP4_ADDR(&netmask, 255, 255, 255,  0);
	IP4_ADDR(&gw,      192, 168,   1,  1);

	print_app_header();


	print_ip_settings(&ipaddr, &netmask, &gw);

	lwip_init();

  	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(netif);
	
	/* Create a new DHCP client for this interface.
	 * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
	 * the predefined regular intervals after starting the client.
	 */
	/* dhcp_start(netif); */

	/* now enable interrupts */
	platform_enable_interrupts();

	/* specify that the network if is up */
	netif_set_up(netif);

	/* start the application (web server, rxtest, txtest, etc..) */
	start_application();

	/* receive and process packets */
	while (1) {
		xemacif_input(netif);
		transfer_data();
	}
  
	/* never reached */
	cleanup_platform();

	return 0;
}
Esempio n. 8
0
int main (void)
{
	clunet_init();  
	clunet_set_on_data_received(data_received);	
	time_init();
	sei();
	//eeprom_write_dword((void*)0, 0);
	record_num = eeprom_read_dword((void*)0); // Читаем кол-во записей
	mode_current = eeprom_read_byte((void*)4); // Режим 
	mode_temp = eeprom_read_byte((void*)5); // Временный режим

	disk_initialize(0);	

	unset_bit(DDRA, 3); set_bit(PORTA, 3);	 // Определение сигнала в линии	
	//unset_bit(DDRA, 4);	unset_bit(PORTA, 4); // Открывалка двери, напрямую
	set_bit(DDRA, 4);	unset_bit(PORTA, 4); // Открывалка двери, через реле
	set_bit(DDRA, 5); HANGUP; // Реле снимания трубки
	set_bit(DDRA, 6); MODE_NORMAL; // Реле выбора режима
	unset_bit(DDRG, 0); set_bit(PORTG, 0); // Определение, лежит ли трубка	
	set_bit(DDRD, 6); set_bit(DDRD, 7); // Светодиоды
	unset_bit(DDRA, 7); set_bit(PORTA, 7); // Счётчик оборотов диска

	unset_bit(DDRF, 0); // ADC+
	unset_bit(PORTF, 0);
	unset_bit(DDRF, 1); // ADC-
	unset_bit(PORTF, 1);

	beep(500, 200);
	beep(1500, 200);
	beep(3000, 200);
	_delay_ms(1000);
	if (play_wav_pgm(STARTED_WAV) == 0)
	{
		LED_GREEN_ON;
		while (sound_read() >= 0) ;
		LED_GREEN_OFF;
		sound_stop();
	} else {
		LED_RED_ON;
		beep(3000, 200);
		beep(1500, 200);
		beep(500, 200);
		LED_RED_OFF;
	}
	
	send_current_mode(CLUNET_BROADCAST_ADDRESS);

	while(1)
	{
		if (is_LINE_POWER()) incoming_ring();
		if (OFFHOOK) control_mode();
		transfer_data(); // Передаём данные на досуге.
	}
}
Esempio n. 9
0
/*全屏清屏*/
void LCD_ClearScreen(void)
{
uint8_t i,j;
//Set_PINCS(0);
for(i=0;i<8;i++)
{
lcd_address(i,0);
for(j=0;j<132;j++)
{
transfer_data(0x00);
}
}
//Set_PINCS(1);
}
Esempio n. 10
0
int
main(int argc, char **argv)
{
	BCPPARAMDATA params;

	DBPROCESS *dbsrc;
	DBPROCESS *dbtarget;

	setlocale(LC_ALL, "");

	memset(&params, '\0', sizeof(params));

	if (process_parameters(argc, argv, &params) == FALSE) {
		pusage();
		return 1;
	}

	if (login_to_databases(&params, &dbsrc, &dbtarget) == FALSE)
		return 1;

	if (params.cflag) {
		if (create_target_table(params.src.dbobject, params.owner, params.dest.dbobject, dbsrc, dbtarget) == FALSE) {
			printf("datacopy: could not create target table %s.%s . terminating\n", params.owner, params.dest.dbobject);
			dbclose(dbsrc);
			dbclose(dbtarget);
			return 1;
		}
	}

	if (check_table_structures(params.src.dbobject, params.dest.dbobject, dbsrc, dbtarget) == FALSE) {
		printf("datacopy: table structures do not match. terminating\n");
		dbclose(dbsrc);
		dbclose(dbtarget);
		return 1;
	}

	if (transfer_data(params, dbsrc, dbtarget) == FALSE) {
		printf("datacopy: table copy failed.\n");
		printf("           the data may have been partially copied into the target database \n");
		dbclose(dbsrc);
		dbclose(dbtarget);
		return 1;
	}


	dbclose(dbsrc);
	dbclose(dbtarget);

	return 0;
}
Esempio n. 11
0
//returns: 0 if it worked out OK and -1 if something went wrong
int stack_resize(struct stack_t *s)	
{	
	int *new_data = (int*)malloc(sizeof(int) * s->size);

	transfer_data(s->data, s->size, new_data);

	free(s->data);
	s->data = new_data;

	if(s->data == NULL)
		return -1;

	return 0;
}
Esempio n. 12
0
//==================display a piture of 128*64 dots================
void full_display()
{
int i,j;
//Set_PINCS(0);
for(i=0;i<8;i++)
{

lcd_address(i,0);
for(j=0;j<128;j++)
{
transfer_data(0xff);
}
}
//Set_PINCS(1);
}
Esempio n. 13
0
File: spi.c Progetto: seL4/util_libs
void
spi_handle_irq(spi_bus_t* spi_bus)
{
#ifdef DEBUG_IRQ
    int int_type = get_spi_interrupt_type(spi_bus);
    if (int_type == RDY_BIT_SET) {
        ZF_LOGE("Interrupt RDY_BIT\n");
    } else {
        ZF_LOGE("Interrupt FIFO ERROR\n");
        print_fifo_error(spi_bus->regs->fifo_status);
    }
#endif
    transfer_data(spi_bus);
    setbits(spi_bus->regs->xfer_status, SPI_XFER_STS_RDY);
}
Esempio n. 14
0
/*显示8x16 点阵图像、ASCII, 或8x16 点阵的自造字符、其他图标*/
void display_graphic_8x16(uint8_t page,uint8_t column,uint8_t *dp)
{
uint8_t i,j;
//Set_PINCS(0);
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<8;i++)
{
transfer_data(*dp); /*写数据到LCD,每写完一个8 位的数据后列地址自动加1*/
dp++;
}
}
//Set_PINCS(1);
}
Esempio n. 15
0
int send_files(unsigned char **files_path, int files_count, const char *ip) {
    char block_type;
    int sock, file, c;
    int trans_cond = EXIT_SUCCESS;
    /** Opening socket descriptor */
    if ((sock = open_socket(ip)) == EXIT_FAILURE) {
        return EXIT_FAILURE;
    }
    for (c = 0; c < files_count; c++) {
        /** Opening file descriptor */
        if ((file = open_file((const char *) files_path[c], O_RDONLY)) == EXIT_FAILURE) {
            return EXIT_FAILURE;
        }
        /** Sending block, file name and file size **/
        block_type = BLOCK_FILE_START;
        write_total(sock, &block_type, 1);
        const char *file_name = fname((const char *) files_path[c]);
        write_total(sock, file_name, strlen(file_name));
        write_total(sock, &"\n", 1);
        off_t file_size = fsize((const char *) files_path[c]);
        /** Checking for file size unavailable **/
        if (file_size == -1) {
            return EXIT_FAILURE;
        }
        write_total(sock, &file_size, 8);
        setup_bar(file_name, file_size);
        trans_cond = transfer_data(file, sock, 0, file_size);
        /** Closing streams **/
        close(file);
        /** Checking for transfer condition **/
        if (trans_cond == EXIT_FAILURE) {
            /** Nothing to do **/
            break;
        }
        printf("\n");
    }
    /** Checking for transaction success **/
    if (trans_cond == EXIT_SUCCESS) {
        /** Sending end-block **/
        block_type = BLOCK_FILE_END;
        write_total(sock, &block_type, 1);
    }
    shutdown(sock, SHUT_RDWR);
    return trans_cond;
}
Esempio n. 16
0
int load_file(const char *directory, const char *ip) {
    char block_type;
    int sock, file;
    int trans_cond = EXIT_SUCCESS;
    /** Opening socket descriptor */
    if ((sock = open_socket(ip)) == EXIT_FAILURE) {
        return EXIT_FAILURE;
    }
    /** Reading block until all files will not be received **/
    while (read_total(sock, &block_type, 1) == 1
           && block_type == BLOCK_FILE_START) {
        /** Reading file name **/
        const char *file_name = (const char *) read_data(sock, '\n', 0);
        /** Concatinating into file path **/
        char *file_path = fpath(file_name, directory);
        /** Reading file size **/
        off_t file_size = *((unsigned long *) read_data(sock, 0, 8));
        /** Opening file descriptor */
        if ((file = open_file(file_path, O_CREAT | O_WRONLY)) == EXIT_FAILURE) {
            return EXIT_FAILURE;
        }
        setup_bar(file_name, file_size);
        trans_cond = transfer_data(sock, file, 0, file_size);
        /** Closing streams **/
        close(file);
        /** Checking for transfer condition **/
        if (trans_cond == EXIT_FAILURE) {
            /** Nothing to do now **/
            break;
        }
        printf("\n");
    }
    /** Checking for transaction success **/
    if (trans_cond == EXIT_SUCCESS) {
        block_type = BLOCK_FILE_END;
        write_total(sock, &block_type, 1);
    }
    shutdown(sock, SHUT_RDWR);
    return trans_cond;
}
Esempio n. 17
0
File: linux.c Progetto: weizn11/C
int main(int argc,char *argv[])
{
    int RemotePort,TargetPort;
    SOCKET soc1,soc2;

    if(argc!=6 || strcmp(argv[1],"-remote")!=0)
    {
        printf("Usage:./XXX -remote RemoteIP RemotePort TargetIP TargetPort\n");
        return -1;
    }

    RemotePort=atoi(argv[3]);
    TargetPort=atoi(argv[5]);
    printf("Connect to %s:%d\n",argv[2],RemotePort);
    if((soc1=create_socket(argv[2],RemotePort))==INVALID_SOCKET)
    {
        printf("Can't connect to %s:%d\n",argv[2],RemotePort);
        return -1;
    }
    printf("Connect to %s:%d successfully!\n",argv[2],RemotePort);

    printf("Connect to %s:%d\n",argv[4],TargetPort);
    if((soc2=create_socket(argv[4],TargetPort))==INVALID_SOCKET)
    {
        printf("Can't connect to %s:%d\n",argv[4],TargetPort);
        return -1;
    }
    printf("Connect to %s:%d successfully!\n",argv[4],TargetPort);

    if(transfer_data(soc1,soc2)==-1)
    {
        printf("Remote host disconnect\n");
    }
    else
    {
        printf("Target host disconnect\n");
    }

    return 0;
}
Esempio n. 18
0
void run_server(const char* IP_ADDR, int PORT_NUMBER, int MAX_BACKLOG) {
	int socket_d = socket(AF_INET, SOCK_STREAM, 0);
    if (socket_d == -1) {
        check_errno("socket");
    }
    struct sockaddr_in local_addr;
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(PORT_NUMBER);
    local_addr.sin_addr.s_addr = inet_addr(IP_ADDR);
    if (!bind(socket_d, (const struct sockaddr*) &local_addr, sizeof(struct sockaddr_in))) {
        check_errno("bind");
    }

    while (!listen(socket_d, MAX_BACKLOG)) {
        struct sockaddr_in remote_addr;
        socklen_t addr_len = sizeof(struct sockaddr_in);
        int rs = accept(socket_d, (struct sockaddr*) &remote_addr, &addr_len);
        if (rs == -1) {
            check_errno("accept");
        }
        if (fork() == 0) {
            close(socket_d);
            fprintf(stderr, "Connected: %s:%d\n", inet_ntoa(remote_addr.sin_addr),
                     (int) ntohs(remote_addr.sin_port));
            transfer_data(rs);

            finalaze_socket(rs);

            fprintf(stderr, "Closed: %s:%d\n", inet_ntoa(remote_addr.sin_addr),
                     (int) ntohs(remote_addr.sin_port));
            exit(0);
        }
        close(rs);
    }
    close(socket_d);
    check_errno("listen");
}
Esempio n. 19
0
int main()
{
	// disable caches -- still fast enough for copies, no worries about coherency
	Xil_DCacheDisable();
	struct ip_addr ipaddr, netmask, gw;

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] =
	{ 0x00, 0x0a, 0x35, 0x00, 0x05, 0x12 };

	echo_netif = &server_netif;
#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
	ProgramSi5324();
	ProgramSfpPhy();
#endif

	init_platform();

	/* initliaze IP addresses to be used */
	/* 129.241.110.214 */
	ipaddr.addr=0;
	netmask.addr=0;
	gw.addr=0;
	/*IP4_ADDR(&ipaddr,  129, 241,  110, 240);
	IP4_ADDR(&netmask, 255, 255, 254,  0);
	IP4_ADDR(&gw,      129, 241,  110,  1);*/



	print_app_header();
	print_ip_settings(&ipaddr, &netmask, &gw);

	lwip_init();

  	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(echo_netif, &ipaddr, &netmask,
						&gw, mac_ethernet_address,
						PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(echo_netif);

	/* Create a new DHCP client for this interface.
	 * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
	 * the predefined regular intervals after starting the client.
	 */
	/* dhcp_start(echo_netif); */
	dhcp_start(echo_netif);

	/* now enable interrupts */
	platform_enable_interrupts();

	/* specify that the network if is up */
	netif_set_up(echo_netif);

	/* start the application (web server, rxtest, txtest, etc..) */
	start_application();

	/* receive and process packets */
	int msg = 0;

	while (!finished) {
		xemacif_input(echo_netif);
		transfer_data();
		if(!msg && echo_netif->ip_addr.addr)
		{
			msg=1;
			xil_printf("Acquired DHCP address!\n");
			print_ip("",&(echo_netif->ip_addr));
		}

	}
  
	xil_printf("Cheetah finished, exiting..\n");
	cleanup_platform();

	return 0;
}
Esempio n. 20
0
int main()
{
	struct ip_addr ipaddr, netmask, gw;

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] =
	{ 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };

	echo_netif = &server_netif;
#if defined (__arm__) && !defined (ARMR5)
#if XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1 || XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1
	ProgramSi5324();
	ProgramSfpPhy();
#endif
#endif

	init_platform();

#if LWIP_DHCP==1
    ipaddr.addr = 0;
	gw.addr = 0;
	netmask.addr = 0;
#else
	/* initliaze IP addresses to be used */
	IP4_ADDR(&ipaddr,  192, 168,   1, 10);
	IP4_ADDR(&netmask, 255, 255, 255,  0);
	IP4_ADDR(&gw,      192, 168,   1,  1);
#endif	
	print_app_header();

	lwip_init();

  	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(echo_netif, &ipaddr, &netmask,
						&gw, mac_ethernet_address,
						PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(echo_netif);

	/* now enable interrupts */
	platform_enable_interrupts();

	/* specify that the network if is up */
	netif_set_up(echo_netif);

#if (LWIP_DHCP==1)
	/* Create a new DHCP client for this interface.
	 * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
	 * the predefined regular intervals after starting the client.
	 */
	dhcp_start(echo_netif);
	dhcp_timoutcntr = 24;

	while(((echo_netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0))
		xemacif_input(echo_netif);

	if (dhcp_timoutcntr <= 0) {
		if ((echo_netif->ip_addr.addr) == 0) {
			xil_printf("DHCP Timeout\r\n");
			xil_printf("Configuring default IP of 192.168.1.10\r\n");
			IP4_ADDR(&(echo_netif->ip_addr),  192, 168,   1, 10);
			IP4_ADDR(&(echo_netif->netmask), 255, 255, 255,  0);
			IP4_ADDR(&(echo_netif->gw),      192, 168,   1,  1);
		}
	}

	ipaddr.addr = echo_netif->ip_addr.addr;
	gw.addr = echo_netif->gw.addr;
	netmask.addr = echo_netif->netmask.addr;
#endif

	print_ip_settings(&ipaddr, &netmask, &gw);

	/* start the application (web server, rxtest, txtest, etc..) */
	start_application();

	/* receive and process packets */
	while (1) {
		if (TcpFastTmrFlag) {
			tcp_fasttmr();
			TcpFastTmrFlag = 0;
		}
		if (TcpSlowTmrFlag) {
			tcp_slowtmr();
			TcpSlowTmrFlag = 0;
		}
		xemacif_input(echo_netif);
		transfer_data();
	}
  
	/* never reached */
	cleanup_platform();

	return 0;
}
Esempio n. 21
0
void loop() {
  
    

  if(bt_connected) {
    // Read Fanatec Packet
    transfer_data(&wheel_out, &wheel_in, sizeof(wheel_out.raw));
    #ifdef IS_USB
      // Fetching HID packet
      uint16_t hid_size;
      hid_size = Joystick.recv(&hid_pck, 0);
      if(hid_size > 0) hid_output(1, hid_size, hid_pck);
    #endif


    if(wheel_in.header == 0xa5){
      bt_setWheel(wheel_in.id);
      // Left stick
      bt_X(255-(wheel_in.axisX+127));
      bt_Y(wheel_in.axisY+127);
  
      // All buttons
      bt_button(1, wheel_in.buttons[0]&0x80);
      bt_button(2, wheel_in.buttons[0]&0x40);
      bt_button(3, wheel_in.buttons[0]&0x20);
      bt_button(4, wheel_in.buttons[0]&0x10);
      bt_button(5, wheel_in.buttons[1]&0x80);
      bt_button(6, wheel_in.buttons[1]&0x40);
      bt_button(7, wheel_in.buttons[1]&0x20);
      bt_button(8, wheel_in.buttons[1]&0x10);
      bt_button(9, wheel_in.buttons[1]&0x04);
      bt_button(10, wheel_in.buttons[1]&0x02);
      bt_button(11, wheel_in.buttons[2]&0x08);
      bt_button(12, wheel_in.buttons[2]&0x04);
      bt_button(13, wheel_in.buttons[2]&0x02);
      bt_button(14, wheel_in.buttons[2]&0x20);
      // paddles shitfer 
      bt_button(15, wheel_in.buttons[1]&0x08);
      bt_button(16, wheel_in.buttons[1]&0x01);
      
      if(wheel_in.id == UNIHUB){
        // Uni Hub buttons
        // BUT_5 array (optional 3 buttons)
        bt_button(19, wheel_in.btnHub[0]&0x08);
        bt_button(20, wheel_in.btnHub[0]&0x10);
        bt_button(21, wheel_in.btnHub[0]&0x20);
        // Playstation buttons
        bt_button(22, wheel_in.btnPS[0]&0x01);
        bt_button(23, wheel_in.btnPS[0]&0x02);
        bt_button(24, wheel_in.btnPS[0]&0x04);
        bt_button(25, wheel_in.btnPS[0]&0x08);
        bt_button(26, wheel_in.btnPS[0]&0x10);
        bt_button(27, wheel_in.btnPS[0]&0x20);
        bt_button(28, wheel_in.btnPS[0]&0x40);
        bt_button(29, wheel_in.btnPS[0]&0x80);

        bt_button(30, wheel_in.btnPS[1]&0x01);
        bt_button(31, wheel_in.btnPS[1]&0x02);
        bt_button(32, wheel_in.btnPS[1]&0x04);
        bt_button(33, wheel_in.btnPS[1]&0x08);
        bt_button(34, wheel_in.btnPS[1]&0x10);
        bt_button(35, wheel_in.btnPS[1]&0x20);
        bt_button(36, wheel_in.btnPS[1]&0x40);
        bt_button(37, wheel_in.btnPS[1]&0x80);
      }
      
      if( rotary_debounce > 0 && rotary_debounce <= 50){
       rotary_debounce++;
      } else if (rotary_debounce > 50){
        rotary_debounce = 0;
      }
      

      if (rotary_debounce == 0) 
      {    
        //rotary_debounce = 0;
        rotary_value = wheel_in.encoder;
        
        bt_button(17, rotary_value==-1);
        bt_button(18, rotary_value==1);
        if (rotary_value != 0){
          #ifdef HAS_DEBUG
            Serial.println(String("DBNCE START!!!!!!!!!ROTARY : ") + rotary_value);
          #endif
          rotary_debounce++;
        }
      }

      int16_t hat;
      switch (wheel_in.buttons[0]&0x0f){
        case 0: hat=0xFF;break;
        case 1: hat=0;break;
        case 2: hat=6;break;
        case 4: hat=2;break;
        case 8: hat=4;break;
        default: hat=0xFF;
      }
      bt_hat(hat);
      
      //Serial.println(String("button: ") + hid_data[3]);

      
    }
  
    // 8 Extra Buttons
    for (int i = 0; i < 8; ++i)
    {
      bt_button(38+i, !digitalRead(2+i));
    }

    // Send HID report (all inputs)
    #ifdef IS_USB
      Joystick.send_now();
      //rotary_debounce = 0;
    #else
    uint32_t timout;
    timout = micros() - timing;
      if(timout > max_delay || (in_changed && timout > 10000))
      {
        //hid_data[3] = (hid_data[3]+1)&0xff;
        iwrap_send_data(main_link_id, sizeof(hid_data), hid_data, iwrap_mode);
        timing = micros();
        bt_delay = 0;
        #ifdef HAS_DEBUG
          if (rotary_debounce!=0)Serial.println(String("RESET!!!!!!!!!ROTARY : ") + rotary_value);
          if (in_changed)Serial.println("input sent");
        #endif
        in_changed = false;
        //rotary_debounce = 0;
      }
      bt_delay++;

      #endif
  }

  #ifndef IS_USB
  // Read WT12 incoming data
  uint16_t result;

  while((result = WT12.read()) < 256 && !got_hid) iwrap_parse(result & 0xFF, iwrap_mode);
  if(got_hid) got_hid = false;
  #endif
  //timing = micros() - timing;
  //if(timing > 550)  Serial.println(String("timing: ") + timing);
  // some delay
  idle();
}
Esempio n. 22
0
int main()
{

	struct ip_addr ipaddr, netmask, gw;
	unsigned FPGA_port_number;
	char *FPGA_ip_address;
	char *FPGA_netmask;
	char *FPGA_gateway;
	unsigned integer_ip;

	unsigned int  FPGA_ip_address_a1,FPGA_ip_address_a2,FPGA_ip_address_a3,FPGA_ip_address_a4;
	unsigned int  FPGA_netmask_a1,FPGA_netmask_a2,FPGA_netmask_a3,FPGA_netmask_a4;
	unsigned int  FPGA_gateway_a1,FPGA_gateway_a2,FPGA_gateway_a3,FPGA_gateway_a4;

	//EXAMPLE: set FPGA IP and port number
	FPGA_ip_address=FPGA_IP;
	FPGA_netmask=FPGA_NM;
	FPGA_gateway=FPGA_GW;
	FPGA_port_number=FPGA_PORT;

	//extract FPGA IP address from string
	if (ip_to_int (FPGA_ip_address,&FPGA_ip_address_a1,&FPGA_ip_address_a2,&FPGA_ip_address_a3,&FPGA_ip_address_a4) == INVALID) {
		printf ("'%s' is not a valid IP address for FPGA server.\n", FPGA_ip_address);
		return 1;
	}

	//extract FPGA netmask address from string
	if (ip_to_int (FPGA_netmask,&FPGA_netmask_a1,&FPGA_netmask_a2,&FPGA_netmask_a3,&FPGA_netmask_a4) == INVALID) {
		printf ("'%s' is not a valid netmask address for FPGA server.\n", FPGA_netmask);
		return 1;
	}

	//extract FPGA gateway address from string
	if (ip_to_int (FPGA_gateway,&FPGA_gateway_a1,&FPGA_gateway_a2,&FPGA_gateway_a3,&FPGA_gateway_a4) == INVALID) {
		printf ("'%s' is not a valid gateway address for FPGA server.\n", FPGA_gateway);
		return 1;
	}

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] =
	{ 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };

	echo_netif = &server_netif;

	init_platform();
	Xil_DCacheDisable();

	/* initliaze IP addresses to be used */
	IP4_ADDR(&ipaddr,  FPGA_ip_address_a4, FPGA_ip_address_a3,   FPGA_ip_address_a2, FPGA_ip_address_a1);
	IP4_ADDR(&netmask, FPGA_netmask_a4, FPGA_netmask_a3, FPGA_netmask_a2,  FPGA_netmask_a1);
	IP4_ADDR(&gw,      FPGA_gateway_a4, FPGA_gateway_a3,   FPGA_gateway_a2,  FPGA_gateway_a1);
	print_app_header();
	print_ip_settings(&ipaddr, &netmask, &gw);
	lwip_init();



  	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(echo_netif, &ipaddr, &netmask,&gw, mac_ethernet_address,PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(echo_netif);

	/* specify that the network if is up */
	netif_set_up(echo_netif);

	/* now enable interrupts */
	platform_enable_interrupts();


	/* start the application (web server, rxtest, txtest, etc..) */
	start_application();

	/* receive and process packets */
	while (1) {
		xemacif_input(echo_netif);
		transfer_data();
	}
  
	/* never reached */
	cleanup_platform();

	return 0;
}
Esempio n. 23
0
/******************************************************************************
 * non-static function definitions
 ******************************************************************************/
int main(int argc, char **argv)
{
	int retval;
	struct handles handles = {
			.sock = -1,
			.sock2 = -1,
			.server_sock = -1,
			.file = NULL,
			.file2 = NULL,
	};
	struct scope_parameter param;

	if(0 != handle_options(argc,argv, &g_options))
	{
		usage(argv[0]);
		return 1;
	}

	signal_init();

	if (scope_init(&param, &g_options)) {
		retval = 2;
		goto cleanup;
	}

	if (g_options.mode == client || g_options.mode == server) {
		if (connection_init(&g_options, &handles)) {
			retval = 3;
			goto cleanup_scope;
		}
	} else if (g_options.mode == file) {
		if (file_open(&g_options, &handles)) {
			retval = 4;
			goto cleanup_scope;
		}
	}

	retval = 0;
	while (!transfer_interrupted()) {
		if (g_options.mode == client || g_options.mode == server) {
			if (connection_start(&g_options, &handles) < 0) {
				fprintf(stderr, "%s: problem opening connection.\n", __func__);
				continue;
			}
		}

		retval = transfer_data(&param, &g_options, &handles);
		if (retval && !transfer_interrupted())
			fprintf(stderr, "%s: problem transferring data.\n", __func__);

		if (g_options.mode == client || g_options.mode == server)
			connection_stop(&handles);

		if (g_options.mode == file)
			break;
	}

	connection_cleanup(&handles);
	file_close(&handles);

cleanup_scope:
	scope_cleanup(&param, &g_options);
cleanup:
	signal_exit();

	return retval;
}
Esempio n. 24
0
int main()
{
	struct netif *netif, server_netif;
	struct ip_addr ipaddr, netmask, gw;

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };

	netif = &server_netif;

	if (init_platform() < 0) {
		xil_printf("ERROR initializing platform.\r\n");
		return -1;
	}

	xil_printf("\r\n\r\n");
	xil_printf("-----lwIP RAW Mode Demo Application ------\r\n");
	/* initliaze IP addresses to be used */
#if (LWIP_DHCP==0)
	IP4_ADDR(&ipaddr,  192, 168,   1, 10);
	IP4_ADDR(&netmask, 255, 255, 255,  0);
	IP4_ADDR(&gw,      192, 168,   1,  1);
    print_ip_settings(&ipaddr, &netmask, &gw);
#endif
	lwip_init();

#if (LWIP_DHCP==1)
	ipaddr.addr = 0;
	gw.addr = 0;
	netmask.addr = 0;
#endif

	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\r\n");
		return -1;
	}
	netif_set_default(netif);

	/* specify that the network if is up */
	netif_set_up(netif);

	/* now enable interrupts */
	platform_enable_interrupts();

#if (LWIP_DHCP==1)
	/* Create a new DHCP client for this interface.
	 * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
	 * the predefined regular intervals after starting the client.
	 */
	dhcp_start(netif);
	dhcp_timoutcntr = 24;
	TxPerfConnMonCntr = 0;
	while(((netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0)) {
		xemacif_input(netif);
		if (TcpFastTmrFlag) {
			tcp_fasttmr();
			TcpFastTmrFlag = 0;
		}
		if (TcpSlowTmrFlag) {
			tcp_slowtmr();
			TcpSlowTmrFlag = 0;
		}
	}
	if (dhcp_timoutcntr <= 0) {
		if ((netif->ip_addr.addr) == 0) {
			xil_printf("DHCP Timeout\r\n");
			xil_printf("Configuring default IP of 192.168.1.10\r\n");
			IP4_ADDR(&(netif->ip_addr),  192, 168,   1, 10);
			IP4_ADDR(&(netif->netmask), 255, 255, 255,  0);
			IP4_ADDR(&(netif->gw),      192, 168,   1,  1);
		}
	}
	/* receive and process packets */
	print_ip_settings(&(netif->ip_addr), &(netif->netmask), &(netif->gw));
#endif

	/* start the application (web server, rxtest, txtest, etc..) */
	start_applications();
	print_headers();

	while (1) {
		if (TcpFastTmrFlag) {
			tcp_fasttmr();
			TcpFastTmrFlag = 0;
		}
		if (TcpSlowTmrFlag) {
			tcp_slowtmr();
			TcpSlowTmrFlag = 0;
		}
		xemacif_input(netif);
		transfer_data();
	}

    /* never reached */
    cleanup_platform();

	return 0;
}
Esempio n. 25
0
int main (int argc, char *argv[]) {
	// no initial declarations in for loop blah blah blah
	int i;

	// for debug purposes
	setbuf(stdout, NULL);

	/* Arguments n stuff */
	int localport = PG_DEF_PORT;
	int remoteport = PG_DEF_PORT;
	char* remotehost = DEFAULT_HOST;
	parse_options(argc, argv, &localport, &remoteport, &remotehost);

	printf("%s - listening on TCP port %d and will connect to %s:%d\n",
		argv[0], localport, remotehost, remoteport);

	/* Make a few things regarding clients */
	ClientList clients;
	bzero((void*) &clients, sizeof(clients));

	SOCKET initsock = make_initial_socket(localport);

	fd_set sockset;
	int highest_fd = initsock; // for now

	/* Make a few things regarding the db server */
	ADDRINFO* serverinfo = find_remote_server(remotehost, remoteport);

	while(1) {
		FD_ZERO(&sockset);

		FD_SET(initsock, &sockset);
		for(i = 0; i < clients.count; ++i) {
			FD_SET(clients.list[i].clientsock, &sockset);
			FD_SET(clients.list[i].serversock, &sockset);
		}

		if(select(highest_fd+1, &sockset, NULL, NULL, NULL) < 0) {
			perror("Error at select");
			exit(-1);
		}

		// if it's our initial socket, add connection
		if(FD_ISSET(initsock, &sockset)) {
			if(add_client(initsock, serverinfo, &clients, &highest_fd) == 0) {
				perror("Problem while connecting client to server");
				continue;
			}
		}

		// otherwise find what's talking
		else {
			for(i = 0; i < clients.count; ++i) {
				if(FD_ISSET(clients.list[i].clientsock, &sockset)) {
					if(transfer_data(clients.list[i].clientsock, clients.list[i].serversock) == 0) {
						remove_client(&clients, i);
					}
				}
				else if(FD_ISSET(clients.list[i].serversock, &sockset)) {
					if(transfer_data(clients.list[i].serversock, clients.list[i].clientsock) == 0) {
						remove_client(&clients, i);
					}
				}
			}
		}
	}

	close(initsock);
	free(serverinfo);

	return 0;
}