示例#1
0
文件: crc.c 项目: Aerovinci/Firmware
uint16_t crc16_signature(uint16_t initial, size_t length, const uint8_t *bytes)
{
	size_t i;

	for (i = 0u; i < length; i++) {
		initial = crc16_add(initial, bytes[i]);
	}

	return initial ^ CRC16_OUTPUT_XOR;
}
示例#2
0
static uint16_t
sendx_crc16(unsigned char b, uint16_t crcacc)
{
  gcr_encode(b);
  GCRLOG("(%02x)", b);
  crcacc = crc16_add(b, crcacc);
  while(gcr_get_encoded(&b)) {
    send(b);
    GCRLOG("C%02x ", b);
  }
  return crcacc;
}
示例#3
0
/*---------------------------------------------------------------------------*/
static void
handle_get_command(void)
{
  int fd = 0;
  fd = cfs_open("cp", CFS_READ);
  if(fd < 0) {
    printf("ERROR: No file access (get)\n");
  } else {
    PRINTF_COMMAND("GET:START\n");
    char data[8];
    int offset=0, size=0, read=8;
    unsigned short crc = 0;
    cfs_seek(fd, offset, CFS_SEEK_SET);

    while (read == 8) {
      int i;

      /*if(offset != cfs_seek(fd, offset, CFS_SEEK_SET)) {
        printf("bad seek, breaking\n");
        break;
      }*/
      read = cfs_read(fd, data, 8);
      size += read;

      printf("%04i: ", offset); /*REMOVE*/
      for (i=0; i < read; i++) {
        crc = crc16_add((uint8_t) data[i], crc);
        printf("%02x", (uint8_t) (0xff&data[i]));
      }
      printf("\n");

      offset += 8;
    }

    PRINTF_COMMAND("GET:DONE CRC=%u\n", crc);
    cfs_close(fd);
  }
}