Ejemplo n.º 1
0
buffer get_weather(char * cmd, int sockfd){
    int numbytes;
    char version[50];
    char cmd1[8];
    struct timeval timeout;
    buffer ret;

    memcpy (cmd1,cmd,6);
    cmd1[6]='\n';
    cmd1[7]='\0';

    do{
    	ret = write_read("VER\n",4,sockfd);
    }while (ret.error <= 0);
    //printf("appeared to have gotten the version. packet length %d\n",ret.len);
    memcpy (version,ret.data,ret.len);
    version[ret.len] = '\0';
    //printf("version is %s",version);
    //printf("sending cmd %s",cmd1);

    do{
	ret = write_read(cmd1,7,sockfd);
        //printf("code is %d\n",ret.error);
    }while(ret.error<=0);

    //printf("recieved %d bytes\n",ret.len);
    return ret;
}
Ejemplo n.º 2
0
static int fusecow_read(const char *path, char *buf, size_t size,
                     off64_t offset, struct fuse_file_info *fi)
{
    int res;

    long long int block_number = offset / block_size;
    if(offset + size > (block_number+1)*block_size) {
    size = (block_number+1)*block_size - offset; // read only one block
    }

    if(write_map_get(block_number)) {
    res=pread64(fd_write, buf, size, offset);
    } else if(read_map_get(block_number)) {
    res=pread64(fd_read, buf, size, offset);
    } else {
    res=pread64(fd, buf, size, offset);
    // Data was never read yet, write to copy-on-read file.
    if (res != write_read(buf, size, offset) && read_only)
        res = -errno;
    }

    if (res == -1)
        res = -errno;

    return res;
    
}
Ejemplo n.º 3
0
bool setProtocolISO_EIC_15693BM019(BM019_PROTOCOL_ISO_IEC_15693_BYTE_0 configuration)
{
    if(stateBM019 < BM019_STATE_ANSWERING) {
        DEBUG("SETTING Protocol failed, bm019 not answering\n");
        return false;
    }
    DEBUG("SETTING Protocol to iso/iec 15693: %#x\n",configuration);

    int len = BM019_CMD_PROTOCOL_START[0]+BM019_CMD_PROTOCOL_ISO_IEC_15693[0];

    uint8_t iso[BM019_CMD_PROTOCOL_START[0]+BM019_CMD_PROTOCOL_ISO_IEC_15693[0]];
    memcpy(iso,&BM019_CMD_PROTOCOL_START[1],BM019_CMD_PROTOCOL_START[0]);
    memcpy(&iso[BM019_CMD_PROTOCOL_START[0]],&BM019_CMD_PROTOCOL_ISO_IEC_15693[1],BM019_CMD_PROTOCOL_ISO_IEC_15693[0]);
    iso[len-1] = configuration;

    int recieved = write_read(iso,len,20);
    if(recieved  >= 2 && rxBuffer[0] == 0x00 && rxBuffer[1] == 0x00) {
        stateBM019 = stateBM019 > BM019_STATE_PROTOCOL ? stateBM019 : BM019_STATE_PROTOCOL;
        return true;
    } else {
        DEBUG("SETTING Protocol failed: %#x\n",rxBuffer[0]);
        stateBM019 = BM019_STATE_UNKNOWN;
        return false;
    }
}
Ejemplo n.º 4
0
bool idnBM019(BM019_IDN *idn)
{
    if(stateBM019 < BM019_STATE_ANSWERING) {
        DEBUG("IDN failed, bm019 not answering\n");
        return false;
    }
    int len = write_read(&BM019_CMD_IDN[1],BM019_CMD_IDN[0]);
    if(len == 17) {
        memcpy(idn->deviceID,(const void *)&rxBuffer[2],13);
        memcpy(idn->romCRC,(const void *)&rxBuffer[15],2);
        return true;
    }
    return false;

}
Ejemplo n.º 5
0
bool inventoryISO_IES_15693BM019(BM019_TAG *tag, int timeout)
{
    if(stateBM019 < BM019_STATE_PROTOCOL) {
        DEBUG("inventory failed, bm019 not in protocol\n");
        return false;
    }

    DEBUG("inventory..");

    int len = write_read(&BM019_CMD_ISO_IEC_15693_INVENTORY[1],BM019_CMD_ISO_IEC_15693_INVENTORY[0]);

    DEBUG("got answer len()=%d\n",len);
    for(int i = 0; i < len; i++) {
        DEBUG("%#04x ",rxBuffer[i]);
    }
    DEBUG("\n");

    if(rxBuffer[0] != EFrameRecvOK) {
        DEBUG("got error %#04x\n",rxBuffer[0]);
        return false;
    }

    int tlen = rxBuffer[1];
    if(tlen < 11) {
        DEBUG("to few bytes recieved \n");
        return false;
    }
    /* this does not work very good, maybe something misinterpreted from docs
    if(rxBuffer[tlen-1] & 0x01) {
        DEBUG("got collision \n");
        return false;
    }
    if(rxBuffer[tlen-1] & 0x02) {
        DEBUG("got bad crc \n");
        return false;
    }*/
    tag->crc[0] = rxBuffer[tlen-2];
    tag->crc[1] = rxBuffer[tlen-3];

    for(int i = 0; i < 9; i++) {
        tag->uid[i] = rxBuffer[11-i];
    }
    return true;

}
Ejemplo n.º 6
0
bool echoBM019(int timeout, bool log)
{
    if(log) {
        DEBUG("BM019: echo\n");
    }
    int len = write_read(&BM019_CMD_ECHO[1],BM019_CMD_ECHO[0], timeout);
    if(len>=1 && rxBuffer[0] == 0x55) {
        stateBM019 = stateBM019 > BM019_STATE_ANSWERING ? stateBM019 : BM019_STATE_ANSWERING;
        return true;
    } else {
        if(log) {
            DEBUG("recievedlen: %d \n",len);

            for(int i = 0; i < len; i++)
                DEBUG("rx[%d]: %#x\n",i,rxBuffer[i]);
        }
    }
    stateBM019 = BM019_STATE_UNKNOWN;
    return false;
}
Ejemplo n.º 7
0
bool setProtocolOFF()
{
    if(stateBM019 < BM019_STATE_ANSWERING) {
        DEBUG("SETTING Protocol failed, bm019 not answering\n");
        return false;
    }
    DEBUG("SETTING Protocol to OFF\n");

    int len = BM019_CMD_PROTOCOL_START[0]+BM019_CMD_PROTOCOL_OFF[0];
    uint8_t off[BM019_CMD_PROTOCOL_START[0]+BM019_CMD_PROTOCOL_OFF[0]];
    memcpy(off,&BM019_CMD_PROTOCOL_START[1],BM019_CMD_PROTOCOL_START[0]);
    memcpy(&off[BM019_CMD_PROTOCOL_START[0]],&BM019_CMD_PROTOCOL_OFF[1],BM019_CMD_PROTOCOL_OFF[0]);

    int recieved = write_read(off,len,20);
    if(recieved  >= 2 && rxBuffer[0] == 0x00 && rxBuffer[1] == 0x00) {
        stateBM019 = BM019_STATE_ANSWERING;
        return true;
    } else {
        DEBUG("SETTING Protocol failed: %#x\n",rxBuffer[0]);
        stateBM019 = BM019_STATE_UNKNOWN;
        return false;
    }
}
Ejemplo n.º 8
0
int readMultiBM019(uint8_t adr, int count, uint8_t *buf, int len, int timeout)
{
    if(stateBM019 < BM019_STATE_PROTOCOL) {
        DEBUG("multi read failed, bm019 not in protocol\n");
        return -1;
    }
    uint8_t cmd[BM019_CMD_READ_MULTI[0]];
    memcpy(cmd,&BM019_CMD_READ_MULTI[1],BM019_CMD_READ_MULTI[0]);
    cmd[BM019_CMD_READ_MULTI[0]-2] = adr & 0xFF;
    cmd[BM019_CMD_READ_MULTI[0]-1] = (count-1) & 0xFF;

    DEBUG("multi read at %#4X for %d..\n",adr, count & 0xFF);
    for(int i = 0; i < BM019_CMD_READ_MULTI[0]; i++) {
        DEBUG("%#04x ",cmd[i]);
    }
    int tx = write_read(cmd,BM019_CMD_READ_MULTI[0]);

    DEBUG("got answer len()=%d\n",tx);
    for(int i = 0; i < tx; i++) {
        DEBUG("%02x ",rxBuffer[i]);
    }
    DEBUG("\n");
    if(rxBuffer[0] != EFrameRecvOK) {
        DEBUG("got error %#04x\n",rxBuffer[0]);
        return -1;
    }

    DEBUG("flags: %#04x\n",rxBuffer[2]);
    int tlen = rxBuffer[1]-4;
    if(tlen <=0)
        return -1;
    DEBUG("read resultet in %d bytes, copying %d bytes\n",rxBuffer[1],(tlen < len ? tlen : len));
    tlen = (tlen < len ? tlen : len);
    memcpy(buf,(const void *)&rxBuffer[3],tlen);

    return tlen;
}
Ejemplo n.º 9
0
void map_reads(gzFile *output_files, gzFile multi_out_file, 
	       gzFile unmapped_out_file, gzFile reads_f, Mapper *mapper,
	       int reads_format, int output_type) {
  FastqRead fastq_read;
  MapRead map_read;
  long warn_count, n_fastq_rec, n_fastq_err;
  long n_map_uniq, n_map_multi, n_map_none;

  map_read.fwd_nucs = my_new(unsigned char, FASTQ_MAX_LINE);
  map_read.rev_nucs = my_new(unsigned char, FASTQ_MAX_LINE);

  n_map_uniq = n_map_multi = n_map_none = 0;
  warn_count = n_fastq_err = n_fastq_rec = 0;

  /* loop over all records in FASTQ file */
  while(TRUE) {
    long r = 0;

    /* read fastq record from file */
    if(reads_format == READS_FORMAT_FASTQ) {
      r = fastq_parse_read(&fastq_read, reads_f);
    }
    else if(reads_format == READS_FORMAT_QSEQ) {
      r = fastq_parse_qseq_read(&fastq_read, reads_f);
    } 
    else {
      my_err("%s:%d: unknown read format", __FILE__, __LINE__);
    }
    
    if(r == FASTQ_END) {
      /* we have reached the end of the file */
      break;
    }

    if(r == FASTQ_ERR) {
      /* this fastq record contains an error */
      if(warn_count < FASTQ_MAX_WARN) {
	warn_count += 1;
	my_warn("%s:%d: skipping invalid fastq record:\n", 
		__FILE__, __LINE__);
	fprintf(stderr, "  %s\n  %s\n  %s\n  %s\n", fastq_read.line1, 
		fastq_read.line2, fastq_read.line3, fastq_read.line4);
      }
      n_fastq_err += 1;
    }
    else if(fastq_read.read_len != mapper->seed_finder_fwd->read_len) {
      /* check that read length is correct */
	warn_count += 1;
	my_warn("%s:%d: specified read length is %u, but got %d, "
		"skipping read\n",  __FILE__, __LINE__, 
		mapper->seed_finder_fwd->read_len, fastq_read.read_len);
	n_fastq_err += 1;
    }
    else if(r == FASTQ_OK) {
      n_fastq_rec += 1;

      read_from_fastq_record(&map_read, &fastq_read);

      if((n_fastq_rec % 1000000) == 0) {
	fprintf(stderr, ".");
      }

      /* try to map this read to genome */
      mapper_map_one_read(mapper, &map_read);

      if(map_read.map_code == MAP_CODE_NONE) {
	/* read does not map to genome */
	n_map_none += 1;
	if(output_type == OUTPUT_TYPE_SINGLE) {
	  write_unmapped_read(output_files[0], &map_read);
	} else {
	  write_unmapped_read(unmapped_out_file, &map_read);
	}
      }
      else if(map_read.map_code == MAP_CODE_MULTI) {
	/* read maps to multiple genomic locations */
	n_map_multi += 1;

	if(output_type == OUTPUT_TYPE_SINGLE) {
	  write_read(output_files, mapper->chr_tab, &map_read, FALSE);
	} else {
	  write_read(&multi_out_file, mapper->chr_tab, &map_read, FALSE);
	}
      }
      else if(map_read.map_code == MAP_CODE_UNIQUE) {
	/* read maps to single genomic location */
	n_map_uniq += 1;
	
	if(output_type == OUTPUT_TYPE_SINGLE) {
	  write_read(output_files, mapper->chr_tab, &map_read, FALSE);
	} else {
	  write_read(output_files, mapper->chr_tab, &map_read, TRUE);
	}
      }
      else {
	my_err("%s:%d: unknown mapping code", __FILE__, __LINE__);
      }
    } else {
      my_err("%s:%d: unknown fastq status", __FILE__, __LINE__);
    }
  }

  fprintf(stderr, "\ndone\n");
  fprintf(stderr, "fastq errors: %ld\n", n_fastq_err);
  fprintf(stderr, "fastq records (without errors): %ld\n", n_fastq_rec);
  fprintf(stderr, "unmapped reads: %ld\n", n_map_none);
  fprintf(stderr, "uniquely mapping reads: %ld\n", n_map_uniq);
  fprintf(stderr, "multiply mapping reads: %ld\n", n_map_multi);

  my_free(map_read.fwd_nucs);
  my_free(map_read.rev_nucs);
}
Ejemplo n.º 10
0
/* main */
int main(int argc, char **argv)
{
	off_t seek_pt;
	int fd;
	int c;
	uint64_t i;
	uint64_t node = 0;
	long int random_tmp;

	/* initialize */
	seek_max = 0x7FFFFFFFFFFULL - IO_SIZE;
	seek_min = 0;

	/* option proc */
	if (argc < 3) {
		usage();
	}
	while ((c = getopt(argc, argv, "r:")) != EOF) {
		switch (c) {
		case 'r':
			node = (uint64_t)strtoull(optarg, &optarg, 16);
			seek_max = (node + 1) * IO_SIZE * IO_POINT - IO_SIZE;
			seek_min = node * IO_SIZE * IO_POINT;
			break;
		default:
			usage();
		}
	}

	srand((unsigned int)node + time(NULL));

	/* malloc buffer */
	buf = (uint64_t *)malloc(IO_SIZE);
	if (buf == NULL) {
		perror("malloc()");
		return TO_RETURN;
	}

	/* creat data set */
	for (i = 0; i < (IO_SIZE / sizeof(uint64_t)); i++) {
		buf[i] = i;
	}

	printf("node %"PRIu64" , start : %"PRIu64"  , end : %"PRIu64"\n", node, seek_min, seek_max);

	/* open file */
	fd = open(FILE_NAME, O_RDWR|O_CREAT, 0666);
	if (fd < 0) {
		perror("OPEN");
		free(buf);
		return TO_RETURN;
	}

	for (;;) {
		random_tmp = random() % IO_POINT;
		seek_pt = random_tmp * IO_SIZE + seek_min;
		if (seek_pt > seek_max) {
			continue;
		}
		if (write_read(seek_pt, fd) < 0) {
			if (close(fd) < 0) {
				perror("close");
			}
			free(buf);
			return TO_RETURN;
		}
	}
	free(buf);
	if (close(fd) < 0) {
		perror("close");
		return TO_RETURN;
	}
	return 0;
}