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; }
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; }
/*---------------------------------------------------------------------------*/ 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); } }