当前位置: 首页>>代码示例>>C++>>正文


C++ cfs_read函数代码示例

本文整理汇总了C++中cfs_read函数的典型用法代码示例。如果您正苦于以下问题:C++ cfs_read函数的具体用法?C++ cfs_read怎么用?C++ cfs_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cfs_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: read_byte

/*---------------------------------------------------------------------------*/
static uint8_t
read_byte(int fd)
{
#if DATA_AS_HEX
  uint8_t hex[2];

  cfs_read(fd, hex, 2);

  if(hex[0] >= 'A' && hex[0] <= 'F') {
    hex[0] = (hex[0] - 'A' + 0xa);
  } else if(hex[0] >= 'a' && hex[0] <= 'f') {
    hex[0] = (hex[0] - 'a' + 0xa);
  } else {
    hex[0] = (hex[0] - '0');
  }
  if(hex[1] >= 'A' && hex[1] <= 'F') {
    hex[1] = (hex[1] - 'A' + 0xa);
  } else if(hex[1] >= 'a' && hex[1] <= 'f') {
    hex[1] = (hex[1] - 'a' + 0xa);
  } else {
    hex[1] = (hex[1] - '0');
  }
  return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f);
#else /* DATA_AS_HEX */
  uint8_t c;
  cfs_read(fd, &c, 1);
  return c;
#endif /* DATA_AS_HEX */
}
开发者ID:AlexandreRio,项目名称:contiki,代码行数:30,代码来源:checkpoint-arch.c

示例2: storage_get_relation

db_result_t
storage_get_relation(relation_t *rel, char *name)
{
  int fd;
  int r;
  int i;
  struct attribute_record record;
  db_result_t result;

  fd = cfs_open(name, CFS_READ);
  if(fd < 0) {
    return DB_STORAGE_ERROR;
  }

  r = cfs_read(fd, rel->name, sizeof(rel->name));
  if(r != sizeof(rel->name)) {
    cfs_close(fd);
    PRINTF("DB: Failed to read name, got %d of %d bytes\n",
	   r, sizeof(rel->name));
    return DB_STORAGE_ERROR;
  }

  r = cfs_read(fd, rel->tuple_filename, sizeof(rel->tuple_filename));
  if(r != sizeof(rel->name)) {
    cfs_close(fd);
    PRINTF("DB: Failed to read tuple filename\n");
    return DB_STORAGE_ERROR;
  }

  rel->tuple_filename[sizeof(rel->tuple_filename) - 1] ^= ROW_XOR;

  /* Read attribute records. */
  result = DB_OK;
  for(i = 0;; i++) {
    r = cfs_read(fd, &record, sizeof(record));
    if(r == 0) {
      break;
    }
    if(r != sizeof(record)) {
      PRINTF("DB: Failed to read attribute record %d (r = %d)\n", i, r);
      result = DB_STORAGE_ERROR;
      break;
    }

    if(relation_attribute_add(rel, DB_MEMORY, record.name,
			      record.domain, record.element_size) == NULL) {
      PRINTF("DB: Failed to add the attribute %s\n", record.name);
      result = DB_STORAGE_ERROR;
      break;
    }
  }

  PRINTF("DB: Read %d attributes\n", i);

  cfs_close(fd);
  return result;
}
开发者ID:1uk3,项目名称:contiki,代码行数:57,代码来源:storage-cfs.c

示例3: read_cb

/** File read callback.
 * Responds to a SBP_MSG_FILEIO_READ_REQUEST message.
 *
 * Reads a certain length (up to 255 bytes) from a given offset. Returns the
 * data in a SBP_MSG_FILEIO_READ_RESPONSE message where the message length field
 * indicates how many bytes were succesfully read.
 */
static void read_cb(u16 sender_id, u8 len, u8 msg[], void* context)
{
  (void)context;

  if (sender_id != SBP_SENDER_ID) {
    log_error("Invalid sender!\n");
    return;
  }

  if ((len < 9) || (msg[len-1] != '\0')) {
    log_error("Invalid fileio read message!\n");
    return;
  }

  u32 offset = ((u32)msg[3] << 24) | ((u32)msg[2] << 16) | (msg[1] << 8) | msg[0];
  u8 readlen = MIN(msg[4], SBP_FRAMING_MAX_PAYLOAD_SIZE - len);
  u8 buf[256];
  memcpy(buf, msg, len);
  int f = cfs_open((char*)&msg[5], CFS_READ);
  cfs_seek(f, offset, CFS_SEEK_SET);
  len += cfs_read(f, buf + len, readlen);
  cfs_close(f);

  sbp_send_msg(SBP_MSG_FILEIO_READ_RESPONSE, len, buf);
}
开发者ID:imh,项目名称:piksi_firmware,代码行数:32,代码来源:sbp_fileio.c

示例4: apply_tcpipconfig

/*-----------------------------------------------------------------------------------*/
static void
apply_tcpipconfig(void)
{
  int file = cfs_open("contiki.cfg", CFS_READ);
  int size = cfs_read(file, uip_buf, 100);
  cfs_close(file);

  nullterminate(ipaddr);
  uiplib_ipaddrconv(ipaddr, (uip_ipaddr_t *)&uip_buf[0]);

  nullterminate(netmask);
  uiplib_ipaddrconv(netmask, (uip_ipaddr_t *)&uip_buf[4]);

  nullterminate(gateway);
  uiplib_ipaddrconv(gateway, (uip_ipaddr_t *)&uip_buf[8]);
  
#if WITH_DNS
  nullterminate(dnsserver);
  uiplib_ipaddrconv(dnsserver, (uip_ipaddr_t *)&uip_buf[12]);
#endif /* WITH_DNS */

  file = cfs_open("contiki.cfg", CFS_WRITE);
  cfs_write(file, uip_buf, size);
  cfs_close(file);
}
开发者ID:AWRyder,项目名称:contiki,代码行数:26,代码来源:dhcp-client.c

示例5: _read_r

ssize_t
_read_r(struct _reent *r, int fd, void *ptr, size_t len) {

  if (fd < 0) {
    /* invalid file descriptor */
    r->_errno = EBADF;
    return -1;
  }

  if (fd >= MAX_OPEN_DEVICES) {
    int ret;
    /* CFS file */
    fd -= MAX_OPEN_DEVICES; /* Remap to CFS FD number */
    /* this is not really reentrant */
    ret = cfs_read(fd, ptr, len);
    if (ret < 0) {
      r->_errno = EBADF;
    }
    return ret;
  }
  if (devoptab_list[fd] == NULL) {
    /* nothing mapped on that FD */
    r->_errno = EBADF;
    return -1;
  }
  if (devoptab_list[fd]->read_r == NULL) {
    /* Function not implemented */
    r->_errno = ENOSYS;
    return -1;
  }
  /* Call method from device operations table */
  return devoptab_list[fd]->read_r(r, fd, ptr, len);
}
开发者ID:punyal,项目名称:Contiki_3-IPsec,代码行数:33,代码来源:newlib-syscalls.c

示例6: send_udpdata

/*---------------------------------------------------------------------*/
static u16_t
send_udpdata(struct codeprop_udphdr *uh)
{
  u16_t len;

  uh->type = HTONS(TYPE_DATA);
  uh->addr = htons(s.addr);
  uh->id = htons(s.id);

  if(s.len - s.addr > UDPDATASIZE) {
    len = UDPDATASIZE;
  } else {
    len = s.len - s.addr;
  }

  cfs_seek(fd, s.addr, CFS_SEEK_SET);
  cfs_read(fd, &uh->data[0], len);
  /*  eeprom_read(EEPROMFS_ADDR_CODEPROP + s.addr,
      &uh->data[0], len);*/

  uh->len = htons(s.len);

  PRINTF(("codeprop: sending packet from address 0x%04x\n", s.addr));
  uip_udp_send(len + UDPHEADERSIZE);

  return len;
}
开发者ID:EDAyele,项目名称:ptunes,代码行数:28,代码来源:codeprop-tmp.c

示例7: read_next_from_buffer

char read_next_from_buffer()
{
  char ret = '\0';

  // need to load a new buffer
  if (b.nb_read_buf == b.buf_size && !b.eof)
  {
    int r = cfs_read(b.fd, b.ch_buf, INPUT_BUFFER_MAX_SIZE);
    if (r > 0)
    {
      b.buf_size = r;
      b.nb_read_buf = 0;
    }
    else
      b.eof = true;
  }

  if (!b.eof)
  {
    b.buf_pos = &b.ch_buf[b.nb_read_buf];
    b.nb_read_buf++;
    ret = *b.buf_pos;
  }

  return ret;
}
开发者ID:AlexandreRio,项目名称:kmf-parser,代码行数:26,代码来源:kmf-lexer.c

示例8: initscript

static void
initscript(void)
{
  char line[40], *lineptr;
  /*  struct c64_fs_file f;*/
  int f;

  if((f = cfs_open("config.cfg", 0)) == -1) {
    return;
  }
  line[0] = ' ';
  while(line[0] != '.' &&
	line[0] != 0) {
    lineptr = line;
    do {
      if(cfs_read(f, lineptr, 1) != 1) {
	cfs_close(f);
	return;
      }
      ++lineptr;
    } while(*(lineptr - 1) != '\n' &&
	    *(lineptr - 1) != '\r');

    *lineptr = 0;

    if(line[0] != '.' &&
       line[0] != 0) {
      parse(line, initparsetab);
    }
    
  }
  cfs_close(f);
  return;
}
开发者ID:pulkomandy,项目名称:contiki-1.x,代码行数:34,代码来源:configedit.c

示例9: storage_read

db_result_t
storage_read(db_storage_id_t fd,
	     void *buffer, unsigned long offset, unsigned length)
{
  char *ptr;
  int r;

  /* Extend the file if necessary, so that previously unwritten bytes
     will be read in as zeroes. */
  if(cfs_seek(fd, offset + length, CFS_SEEK_SET) == (cfs_offset_t)-1) {
    return DB_STORAGE_ERROR;
  }

  if(cfs_seek(fd, offset, CFS_SEEK_SET) == (cfs_offset_t)-1) {
    return DB_STORAGE_ERROR;
  }

  ptr = buffer;
  while(length > 0) {
    r = cfs_read(fd, ptr, length);
    if(r <= 0) {
      return DB_STORAGE_ERROR;
    }
    ptr += r;
    length -= r;
  }

  return DB_OK;
}
开发者ID:1uk3,项目名称:contiki,代码行数:29,代码来源:storage-cfs.c

示例10: queuebuf_load_to_ram

/* If the queuebuf is in CFS, load it to tmpdata */
static struct queuebuf_data *
queuebuf_load_to_ram(struct queuebuf *b)
{
  int fileid, fd, ret;
  cfs_offset_t offset;
  if(b->location == IN_RAM) { /* the qbuf is loacted in RAM */
    return b->ram_ptr;
  } else { /* the qbuf is located in CFS */
    if(tmpdata_qbuf && tmpdata_qbuf->swap_id == b->swap_id) { /* the qbuf is already in tmpdata */
      return &tmpdata;
    } else { /* the qbuf needs to be loaded from CFS */
      tmpdata_qbuf = b;
      /* read the qbuf from CFS */
      fileid = b->swap_id / NQBUF_PER_FILE;
      offset = (b->swap_id % NQBUF_PER_FILE) * sizeof(struct queuebuf_data);
      fd = qbuf_files[fileid].fd;
      ret = cfs_seek(fd, offset, CFS_SEEK_SET);
      if(ret == -1) {
        PRINTF("queuebuf_load_to_ram: cfs seek error\n");
      }
      ret = cfs_read(fd, &tmpdata, sizeof(struct queuebuf_data));
      if(ret == -1) {
        PRINTF("queuebuf_load_to_ram: cfs read error\n");
      }
      return &tmpdata;
    }
  }
}
开发者ID:200018171,项目名称:contiki,代码行数:29,代码来源:queuebuf.c

示例11: write_chunk

/*---------------------------------------------------------------------------*/
static void
write_chunk(struct rudolph2_conn *c, int offset, int flag,
	    uint8_t *data, int datalen)
{
  int fd;
#if CONTIKI_TARGET_NETSIM
  {
    char buf[100];
    sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE);
    ether_set_text(buf);
  }
#endif /* CONTIKI_TARGET_NETSIM */

  if(flag == RUDOLPH2_FLAG_NEWFILE) {
    printf("+++ rudolph2 new file incoming at %lu\n", clock_time());
    leds_on(LEDS_RED);
    fd = cfs_open("codeprop.out", CFS_WRITE);
  } else {
    fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
  }
  
  if(datalen > 0) {
    int ret;
    cfs_seek(fd, offset, CFS_SEEK_SET);
    ret = cfs_write(fd, data, datalen);
    printf("+++ rudolph2 offset %d, length %d\n", offset, datalen);
  }

  cfs_close(fd);

  if(flag == RUDOLPH2_FLAG_LASTCHUNK) {
    int i;
    printf("+++ rudolph2 entire file received at %d, %d\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
    leds_off(LEDS_RED);
    leds_on(LEDS_YELLOW);

    fd = cfs_open("hej", CFS_READ);
    for(i = 0; i < FILESIZE; ++i) {
      unsigned char buf;
      int r = cfs_read(fd, &buf, 1);
      if (r != 1) {
	printf("%d.%d: error: read failed at %d\n",
	       rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	       i);
	break;
      }       
      else if(buf != (unsigned char)i) {
	printf("%d.%d: error: diff at %d, %d != %d\n",
	       rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	       i, (unsigned char)i, buf);
	break;
      }
    }
#if CONTIKI_TARGET_NETSIM
    ether_send_done();
#endif
    cfs_close(fd);
  }
}
开发者ID:Contiki-leoqin,项目名称:contiki,代码行数:61,代码来源:example-rudolph2.c

示例12: storage_get_index

db_result_t
storage_get_index(index_t *index, relation_t *rel, attribute_t *attr)
{
  char filename[INDEX_NAME_LENGTH];
  int fd;
  int r;
  struct index_record record;
  db_result_t result;

  merge_strings(filename, rel->name, INDEX_NAME_SUFFIX);

  fd = cfs_open(filename, CFS_READ);
  if(fd < 0) {
    return DB_STORAGE_ERROR;
  }

  for(result = DB_STORAGE_ERROR;;) {
    r = cfs_read(fd, &record, sizeof(record));
    if(r < sizeof(record)) {
      break;
    }
    if(strcmp(attr->name, record.attribute_name) == 0) {
      PRINTF("DB: Found the index record for %s.%s: type %d, filename %s\n",
	rel->name, attr->name, record.type, record.file_name);
      index->type = record.type;
      memcpy(index->descriptor_file, record.file_name,
	     sizeof(index->descriptor_file));
      result = DB_OK;
    }
  }

  cfs_close(fd);

  return result;
}
开发者ID:1uk3,项目名称:contiki,代码行数:35,代码来源:storage-cfs.c

示例13: PROCESS_THREAD

PROCESS_THREAD(cfs_write_test, ev, data) {
    PROCESS_BEGIN();

    char str[20], str2[20];
    strcpy(str, "Vot bl'a nahuj!");

    int fd = cfs_open("a", CFS_WRITE);
    if (fd == -1) {
        cfs_close(fd);
        fd = cfs_open("a", CFS_WRITE);
        if (fd == -1) {
            alarma(5);
        }
    }
    cfs_write(fd, (void *)str, strlen(str));
    cfs_close(fd);

    fd = cfs_open("a", CFS_READ);
    cfs_read(fd, (void *)str2, strlen(str));
    cfs_close(fd);

    strcat(str2, " Da yopt!");

    fd = cfs_open("a", CFS_WRITE);
    cfs_write(fd, (void *)str2, strlen(str2));
    cfs_close(fd);

    ledd_on(PB5);
    PROCESS_END();
}
开发者ID:project-master-device,项目名称:project-master-device,代码行数:30,代码来源:eeprom_write_contiki_test.c

示例14: manage_acq_setup

void manage_acq_setup()
{
  for (u8 prn=0; prn<32; prn++) {
    acq_prn_param[prn].state = ACQ_PRN_UNTRIED;
    acq_prn_param[prn].score = 0;
  }

  int fd = cfs_open("almanac", CFS_READ);
  if (fd != -1) {
    cfs_read(fd, almanac, 32*sizeof(almanac_t));
    log_info("Loaded almanac from flash\n");
    cfs_close(fd);
  } else {
    log_info("No almanac file present in flash, create an empty one\n");
    cfs_coffee_reserve("almanac", 32*sizeof(almanac_t));
    cfs_coffee_configure_log("almanac", 256, sizeof(almanac_t));

    for (u8 prn=0; prn<32; prn++) {
      almanac[prn].valid = 0;
    }
  }

  sbp_register_cbk(
    MSG_ALMANAC,
    &almanac_callback,
    &almanac_callback_node
  );

  chThdCreateStatic(
      wa_manage_acq_thread,
      sizeof(wa_manage_acq_thread),
      MANAGE_ACQ_THREAD_PRIORITY,
      manage_acq_thread, NULL
  );
}
开发者ID:njoubert,项目名称:piksi_firmware,代码行数:35,代码来源:manage.c

示例15: urlconv_init

void
urlconv_init(void)
{
  int fd = cfs_open("wwwroot.cfg", CFS_READ);
  int rd = cfs_read(fd, wwwroot, sizeof(wwwroot));
  cfs_close(fd);
  if(rd != -1) wwwrootlen = rd;
}
开发者ID:13416795,项目名称:contiki,代码行数:8,代码来源:urlconv.c


注:本文中的cfs_read函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。