Beispiel #1
0
void main_loop(void)
{
  const char *s[] = {
    "001.jpg",
    "002.jpg", 0,
    "003.jpg",
    "004.jpg",
    "005.jpg",
    "006.jpg",
    "007.jpg",
    "008.jpg",
    "009.jpg",
    "010.jpg",
    "011.jpg",
    "012.jpg",
    0
  };
  char **p = (char**)s;
  unsigned short fseq = 1;

  while (*p) {
    unsigned short seq;
    unsigned short client_fseq;
    
    load_buff_pool(p_bp, *p);
    p_bp->f.fseq = fseq;

    /* send filename, send chunks, send EOF */

    do {
      push_fileinfo(p_bp);
    } while (CPAPP_IOF != wait_ack(10, &client_fseq));

    for (unsigned int i = 0; i <= p_bp->f.filesize / CPAPP_MAX_CHUNKSIZE; i++) {
      push_chunk(p_bp, i);
    }
    push_eof(p_bp);

    while (((seq = wait_ack(10, &client_fseq)) != CPAPP_EOF) || (client_fseq != fseq)) {
//      printf("ACK LOOP:  ack, cliseq, seq  = %04x, %04x, %04x\n", seq, client_fseq, fseq);
      switch (seq) {
        case CPAPP_TMO:
          push_eof(p_bp);
          break;
        case CPAPP_IGN:
          break;
        case CPAPP_EOF:
          break;
        case CPAPP_IOF:
          break;
        default:
          push_chunk(p_bp, seq);
          break;
      }
    }
    printf("Step to next file. (%d finished)\n", client_fseq);
    p++;
    fseq++;
  }
}
Beispiel #2
0
static int
i2c_write(struct i2c_au1550_data *adap, unsigned char *buf,
		     unsigned int len)
{
	int	i;
	u32	data;
	volatile psc_smb_t	*sp;

	if (len == 0)
		return 0;

	sp = (volatile psc_smb_t *)(adap->psc_base);

	i = 0;
	while (i < (len-1)) {
		data = buf[i];
		sp->psc_smbtxrx = data;
		au_sync();
		if (wait_ack(adap))
			return -EIO;
		i++;
	}

	
	data = buf[i];
	data |= PSC_SMBTXRX_STP;
	sp->psc_smbtxrx = data;
	au_sync();
	if (wait_master_done(adap))
		return -EIO;
	return 0;
}
Beispiel #3
0
static int
do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
{
	unsigned long stat;

	/* Reset the FIFOs, clear events. */
	stat = RD(adap, PSC_SMBSTAT);
	WR(adap, PSC_SMBEVNT, PSC_SMBEVNT_ALLCLR);

	if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
		WR(adap, PSC_SMBPCR, PSC_SMBPCR_DC);
		while ((RD(adap, PSC_SMBPCR) & PSC_SMBPCR_DC) != 0)
			cpu_relax();
		udelay(50);
	}

	/* Write out the i2c chip address and specify operation */
	addr <<= 1;
	if (rd)
		addr |= 1;

	/* zero-byte xfers stop immediately */
	if (q)
		addr |= PSC_SMBTXRX_STP;

	/* Put byte into fifo, start up master. */
	WR(adap, PSC_SMBTXRX, addr);
	WR(adap, PSC_SMBPCR, PSC_SMBPCR_MS);
	if (wait_ack(adap))
		return -EIO;
	return (q) ? wait_master_done(adap) : 0;
}
Beispiel #4
0
static int i2c_write(struct i2c_au1550_data *adap, unsigned char *buf,
		     unsigned int len)
{
	int i;
	unsigned long data;

	if (len == 0)
		return 0;

	i = 0;
	while (i < (len-1)) {
		data = buf[i];
		WR(adap, PSC_SMBTXRX, data);
		if (wait_ack(adap))
			return -EIO;
		i++;
	}

	/* The last byte has to indicate transfer done. */
	data = buf[i];
	data |= PSC_SMBTXRX_STP;
	WR(adap, PSC_SMBTXRX, data);
	if (wait_master_done(adap))
		return -EIO;
	return 0;
}
void send_data_packets() {
  int i;
  struct sockaddr_in* from;
  int retsize, chunk_size;
  int * upload_id_list = get_upload_list(&retsize);
  int * upload_chunk_id_list = get_upload_chunk_list(&chunk_size);
  int peer_id;
  unsigned seq_number;
  int canSend;
  int timeout;
  for(i = 0; i < retsize; i++) {
  	peer_id = upload_id_list[i];
  	canSend = 1;
    /* if timeout send timeout packet first */
    if ((seq_number = get_timeout_seq(peer_id)) == 0) {
    	/* if not timout, check window size */
    	if(get_queue_size(peer_id) < get_cwnd_size(peer_id)) {
				seq_number = get_tail_seq_number(peer_id);
				/* transmit */
				timeout = 0;
			}
    	else{
    		canSend = 0;
      }
    }
    else {
    	/* retransmit */
      printf("retransmit\n");
      window_timeout(peer_id);
    	seq_number -= 1; /* offset by 1 */
    	timeout = 1;
    }
    //printf("seq: %d, canSend: %d, queue: %d, cwnd: %d\n", seq_number, canSend, get_queue_size(peer_id), get_cwnd_size(peer_id));
   	/* send one packet one time to ensure fairness */
    if(canSend && seq_number < MAX_PACKET_PER_CHUNK) {
		  char data[MAX_PAYLOAD_SIZE];
		  struct packet* packet;
		  if(seq_number==MAX_PACKET_PER_CHUNK-1){
		    int last_packet_size = BT_CHUNK_SIZE-MAX_PAYLOAD_SIZE*(MAX_PACKET_PER_CHUNK-1);
		    read_file(master_data_file_name, data, last_packet_size, 
		      upload_chunk_id_list[i] * BT_CHUNK_SIZE + seq_number * MAX_PAYLOAD_SIZE);
		    packet = make_packet(DATA, NULL, data, last_packet_size, seq_number + 1, 0, NULL, NULL, NULL);
		  }else{
		    read_file(master_data_file_name, data, MAX_PAYLOAD_SIZE, 
		      upload_chunk_id_list[i] * BT_CHUNK_SIZE + seq_number * MAX_PAYLOAD_SIZE);
		    packet = make_packet(DATA, NULL, data, MAX_PAYLOAD_SIZE, seq_number + 1, 0, NULL, NULL, NULL);
		  }

		  /* Send DATA */
		  from = find_addr(peer_id);
		  send_packet(*packet, sock, (struct sockaddr*)from);
		  wait_ack(peer_id, seq_number + 1, timeout);
		  free(packet->header);
		  free(packet);
    }
  }
  free(upload_id_list);
  free(upload_chunk_id_list);
}
Beispiel #6
0
static int i2c_write(struct i2c_algo_sgi_data *adap, unsigned char *buf,
             unsigned int len)
{
    int i;

    /* We are already in write state */
    for (i = 0; i < len; i++) {
        write_data(buf[i]);
        if (wait_ack(adap))
            return -EIO;
    }
    return 0;
}
Beispiel #7
0
void control_sender(int* data_parity,int frame_no,int isFile,int dataSize){
	unsigned char* frame;
	int send_unsuccess;

	// Send All-1 Frame
	while(frame_number_current<frame_number_last){

		// CREATE frame from << data_parity
		frame=iframe_new_frame(isFile,0,frame_number_current%2,dataSize-frame_number_current*8 /*size*/,data_parity+frame_number_current);
		printf("Frane Data size : %d\n",dataSize-frame_number_current*8);

		while(send_unsuccess){
			// Send 1 frame + Start counter
			frame_sender(frame);
			printf("Sent Frame : %d\n",frame_number_current);
			startTimer(sender_timer);

			send_unsuccess=wait_ack(frame_number_current%2); // frame_number_current%2 == 0,1 << ACK 					

			// EXIT PROGRAM
		}
		frame_number_current++; // Next frame

	}

	// LAST FRAME;
	frame=iframe_new_frame(isFile,1,frame_number_current%2,dataSize-frame_number_current*8,data_parity+frame_number_current);// text lastframe put 1
	while(send_unsuccess){
		// Send 1 frame + Start counter
		frame_sender(frame);
		printf("Sent Frame : %d\n",frame_number_current);
		startTimer(sender_timer);

		send_unsuccess=wait_ack(frame_number_current%2); // frame_number_current%2 == 0,1 << ACK 					

		// EXIT PROGRAM
	}
}
Beispiel #8
0
void send_file(int conn_fd) {
    strip_newline(buf);
    /* Client sends file name to recieve */
    FILE* f = fopen(buf, "r");
    if(f == NULL) {
        send(conn_fd, OP_DIE, strlen(OP_DIE), NO_FLAGS);
        return;
    }
    wait_ack(conn_fd, cmd_buf, sizeof(cmd_buf));
    while(fgets(buf, sizeof(buf), f) != NULL) 
        send(conn_fd, buf, strlen(buf), NO_FLAGS);
    send(conn_fd, OP_EOF, strlen(OP_EOF), NO_FLAGS);
    fclose(f);
}
Beispiel #9
0
SANE_Status
sane_start (SANE_Handle h)
{
  struct device_s *dev = (struct device_s *) h;
  int status;
  size_t size;

  dev->read_offset = 0;
  dev->write_offset_r = 0;
  dev->write_offset_g = 1;
  dev->write_offset_b = 2;

  free (dev->buffer);
  dev->buffer = NULL;


  send_pkt (PKT_RESET, 0, dev);
  send_pkt (PKT_READ_STATUS, 0, dev);
  wait_ack (dev, &status);
  if (status)
    return SANE_STATUS_IO_ERROR;

  send_pkt (PKT_READCONF, 0, dev);

  if ((size = wait_ack (dev, NULL)))
    {
      sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
    }
  send_pkt (PKT_SETCONF, 100, dev);
  send_conf (dev);
  wait_ack (dev, NULL);

  send_pkt (PKT_START_SCAN, 0, dev);
  wait_ack (dev, NULL);
  if ((size = wait_ack (dev, NULL)))
    {
      sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
    }
  if ((size = wait_ack (dev, NULL)))
    {
      sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
    }
  if ((size = wait_ack (dev, NULL)))
    {
      sanei_usb_read_bulk (dev->dn, (unsigned char *) dev->conf_data, &size);
    }

  dev->status = STATUS_SCANNING;
  /* Get the first data */
  return get_data (dev);
}
Beispiel #10
0
int stable_send(int fudp, const void *sndbuf, socklen_t len,  u_short ackno, int *pcancel)
{
    const char *psndbuf = (const char *)sndbuf;
    int result = send(fudp, psndbuf, len, 0);

    for (int i = 0; i < 5 && result == len && *pcancel == 0; i++) {
        if (wait_ack(fudp, ackno, pcancel))
            return 1;
        result = send(fudp, psndbuf, len, 0);
    }

    if (result != len)
        pcancel[0] = 1;
    return 0;
}
Beispiel #11
0
static bool ast_write_data(struct drm_device *dev, u8 data)
{
	struct ast_private *ast = dev->dev_private;

	if (wait_nack(ast)) {
		send_nack(ast);
		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9a, 0x00, data);
		send_ack(ast);
		if (wait_ack(ast)) {
			send_nack(ast);
			return true;
		}
	}
	send_nack(ast);
	return false;
}
Beispiel #12
0
int8_t SOFTI2C::send_byte(uint8_t byte)
{
	int8_t ret = 0;

	uint8_t ii = 8;
	sda_pin->mode(OUTPUT_PP);
	while( ii-- )
	{
		scl_pin->reset();
		sda_pin->write(byte & 0x80);delay_us(delay_times);
		byte += byte;//<<1
		scl_pin->set();delay_us(delay_times);
		scl_pin->reset();delay_us(delay_times);
	}
	ret = wait_ack();
  return ret;
}
Beispiel #13
0
static int
at_command (grub_uint8_t data)
{
  unsigned i;
  for (i = 0; i < GRUB_AT_TRIES; i++)
    {
      grub_uint8_t ack;
      keyboard_controller_wait_until_ready ();
      grub_outb (data, KEYBOARD_REG_STATUS);
      ack = wait_ack ();
      if (ack == GRUB_AT_NACK)
	continue;
      if (ack == GRUB_AT_ACK)
	break;
      return 0;
    }
  return (i != GRUB_AT_TRIES);
}
Beispiel #14
0
static int do_address(struct i2c_algo_sgi_data *adap, unsigned int addr,
              int rd)
{
    if (rd)
        set_control(SGI_I2C_NOT_IDLE);
    /* Check if bus is idle, eventually force it to do so */
    if (get_control() & SGI_I2C_NOT_IDLE)
        if (force_idle(adap))
                    return -EIO;
    /* Write out the i2c chip address and specify operation */
    set_control(SGI_I2C_HOLD_BUS | SGI_I2C_WRITE | SGI_I2C_NOT_IDLE);
    if (rd)
        addr |= 1;
    write_data(addr);
    if (wait_ack(adap))
        return -EIO;
    return 0;
}
Beispiel #15
0
static bool ast_read_data(struct drm_device *dev, u8 *data)
{
	struct ast_private *ast = dev->dev_private;
	u8 tmp;

	*data = 0;

	if (wait_ack(ast) == false)
		return false;
	tmp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd3, 0xff);
	*data = tmp;
	if (wait_nack(ast) == false) {
		send_nack(ast);
		return false;
	}
	send_nack(ast);
	return true;
}
static int
do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
{
	volatile psc_smb_t	*sp;
	u32			stat;

	sp = (volatile psc_smb_t *)(adap->psc_base);

	/* Reset the FIFOs, clear events.
	*/
	stat = sp->psc_smbstat;
	sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR;
	au_sync();

	if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
		sp->psc_smbpcr = PSC_SMBPCR_DC;
		au_sync();
		do {
			stat = sp->psc_smbpcr;
			au_sync();
		} while ((stat & PSC_SMBPCR_DC) != 0);
		udelay(50);
	}

	/* Write out the i2c chip address and specify operation
	*/
	addr <<= 1;
	if (rd)
		addr |= 1;

	/* zero-byte xfers stop immediately */
	if (q)
		addr |= PSC_SMBTXRX_STP;

	/* Put byte into fifo, start up master.
	*/
	sp->psc_smbtxrx = addr;
	au_sync();
	sp->psc_smbpcr = PSC_SMBPCR_MS;
	au_sync();
	if (wait_ack(adap))
		return -EIO;
	return (q) ? wait_master_done(adap) : 0;
}
Beispiel #17
0
static int
do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
{
	volatile psc_smb_t	*sp;
	u32			stat;

	sp = (volatile psc_smb_t *)(adap->psc_base);

	
	stat = sp->psc_smbstat;
	sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR;
	au_sync();

	if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
		sp->psc_smbpcr = PSC_SMBPCR_DC;
		au_sync();
		do {
			stat = sp->psc_smbpcr;
			au_sync();
		} while ((stat & PSC_SMBPCR_DC) != 0);
		udelay(50);
	}

	
	addr <<= 1;
	if (rd)
		addr |= 1;

	
	if (q)
		addr |= PSC_SMBTXRX_STP;

	
	sp->psc_smbtxrx = addr;
	au_sync();
	sp->psc_smbpcr = PSC_SMBPCR_MS;
	au_sync();
	if (wait_ack(adap))
		return -EIO;
	return (q) ? wait_master_done(adap) : 0;
}
Beispiel #18
0
static bool ast_write_cmd(struct drm_device *dev, u8 data)
{
	struct ast_private *ast = dev->dev_private;
	int retry = 0;
	if (wait_nack(ast)) {
		send_nack(ast);
		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x9a, 0x00, data);
		send_ack(ast);
		set_cmd_trigger(ast);
		do {
			if (wait_ack(ast)) {
				clear_cmd_trigger(ast);
				send_nack(ast);
				return true;
			}
		} while (retry++ < 100);
	}
	clear_cmd_trigger(ast);
	send_nack(ast);
	return false;
}
Beispiel #19
0
static int
write_mode (int mode)
{
  unsigned i;
  for (i = 0; i < GRUB_AT_TRIES; i++)
    {
      grub_uint8_t ack;
      keyboard_controller_wait_until_ready ();
      grub_outb (0xf0, KEYBOARD_REG_DATA);
      keyboard_controller_wait_until_ready ();
      grub_outb (mode, KEYBOARD_REG_DATA);
      keyboard_controller_wait_until_ready ();
      ack = wait_ack ();
      if (ack == GRUB_AT_NACK)
	continue;
      if (ack == GRUB_AT_ACK)
	break;
      return 0;
    }

  return (i != GRUB_AT_TRIES);
}
Beispiel #20
0
int8_t SOFTI2C::write_byte(uint8_t slave_address,uint8_t reg_address,uint8_t* data,uint16_t num_to_write)
{
	int8_t ret = 0;
		start();

    if (send_7bits_address(slave_address) == -1)
        ret = -1;
		
    if (send_byte(reg_address) == -1)
        ret = -2;

		while(num_to_write--)
		{
			send_byte(*data++);
			if (wait_ack() == -1)
					ret = -3;
		}
		
		stop();

    delay_us(10);      
    return ret;
}
Beispiel #21
0
void text_sender(unsigned char* send_data){
	int* data_parity;
	int send_unsuccess;
	char s_frame=sframe_new(0,1,0);

	send_unsuccess=1;
	//----------SSSSSSSS----------
	// Create S_FRAME;
	while(send_unsuccess){
		// Send 1 frame + Start counter
		frame_sender(s_frame);
		printf("Sent S-Frame\n");
		startTimer(sender_timer);
		send_unsuccess=wait_ack(0); // frame_number_current%2 == 0,1 << ACK 					
	}


	//----------IIIIIIII----------
	send_unsuccess=1;
	dataSize=strlen(send_data);
	printf("SIZE : %d\n",dataSize);
	data8bit=Cut8Char(send_data,dataSize);

	// Add 2D-Parity (send_data,dataSize)
	// Use new pointer from parity to Send >> data_parity
	data_parity=parityGenerator(send_data,dataSize);

	frame_number_current=0;
	frame_number_last=dataSize/8;
	printf("Frame Number : %d\n",frame_number_last);
	if(dataSize%8!=0)
		frame_number_last++;

	control_sender(data_parity,frame_number_last,0,dataSize);

}
Beispiel #22
0
static SANE_Status
get_data (struct device_s *dev)
{
  int color;
  size_t size;
  int packet_size;
  unsigned char *buffer = (unsigned char *) dev->packet_data;
  if (dev->status == STATUS_IDLE)
    return SANE_STATUS_IO_ERROR;
  /* first wait a standard data pkt */
  do
    {
      size = 32;
      sanei_usb_read_bulk (dev->dn, buffer, &size);
      if (size)
	{
	  if (ntohl (dev->packet_data[0]) == MAGIC_NUMBER)
	    {
	      if (ntohl (dev->packet_data[1]) == PKT_DATA)
		break;
	      if (ntohl (dev->packet_data[1]) == PKT_END_DATA)
		{
		  dev->status = STATUS_IDLE;
		  DBG(100,"End of scan encountered on device %s\n",dev->devname);
		  send_pkt (PKT_GO_IDLE, 0, dev);
		  wait_ack (dev, NULL);
		  wait_ack (dev, NULL);
		  send_pkt (PKT_UNKNOW_1, 0, dev);
		  wait_ack (dev, NULL);
		  send_pkt (PKT_RESET, 0, dev);
		  sleep (2);	/* Time for the scanning head to go back home */
		  return SANE_STATUS_EOF;
		}
	    }
	}
    }
  while (1);
  packet_size = ntohl (dev->packet_data[5]);
  if (!dev->buffer)
    {
      dev->bufs = packet_size - 24 /* size of header */ ;
      if (dev->optionw[COLOR_OFFSET] == RGB)
	dev->bufs *= 3;
      dev->buffer = malloc (dev->bufs);
      if (!dev->buffer)
	return SANE_STATUS_NO_MEM;
      dev->write_offset_r = 0;
      dev->write_offset_g = 1;
      dev->write_offset_b = 2;

    }
  /* Get the "data header" */
  do
    {
      size = 24;
      sanei_usb_read_bulk (dev->dn, buffer, &size);
    }
  while (!size);
  color = ntohl (dev->packet_data[0]);
  packet_size -= size;
  dev->width = ntohl (dev->packet_data[5]);
  DBG(100,"Got data size %d on device %s. Scan width: %d\n",packet_size, dev->devname, dev->width);
  /* Now, read the data */
  do
    {
      int j;
      int i;
      int ret;
      do
	{
	  size = packet_size > 512 ? 512 : packet_size;
	  ret = sanei_usb_read_bulk (dev->dn, buffer, &size);
	}
      while (!size || ret != SANE_STATUS_GOOD);
      packet_size -= size;
      switch (color)
	{
	case RED_LAYER:
	  DBG(101,"Got red layer data on device %s\n",dev->devname);
	  i = dev->write_offset_r + 3 * size;
	  if (i > dev->bufs)
	    i = dev->bufs;
	  for (j = 0; dev->write_offset_r < i; dev->write_offset_r += 3)
	    dev->buffer[dev->write_offset_r] = buffer[j++];
	  break;
	case GREEN_LAYER:
	  DBG(101,"Got green layer data on device %s\n",dev->devname);
	  i = dev->write_offset_g + 3 * size;
	  if (i > dev->bufs)
	    i = dev->bufs;
	  for (j = 0; dev->write_offset_g < i; dev->write_offset_g += 3)
	    dev->buffer[dev->write_offset_g] = buffer[j++];
	  break;
	case BLUE_LAYER:
          DBG(101,"Got blue layer data on device %s\n",dev->devname);
	  i = dev->write_offset_b + 3 * size;
	  if (i > dev->bufs)
	    i = dev->bufs;
	  for (j = 0; dev->write_offset_b < i; dev->write_offset_b += 3)
	    dev->buffer[dev->write_offset_b] = buffer[j++];
	  break;
	case GRAY_LAYER:
	  DBG(101,"Got gray layer data on device %s\n",dev->devname);
	  if (dev->write_offset_r + (int)size >= dev->bufs)
	    size = dev->bufs - dev->write_offset_r;
	  memcpy (dev->buffer + dev->write_offset_r, buffer, size);
	  dev->write_offset_r += size;
	  break;
	}
    }
  while (packet_size > 0);
  return SANE_STATUS_GOOD;
}