FIX: 'lua calc of iso15692 crc' - works better now

This commit is contained in:
iceman1001 2018-11-30 01:19:57 +01:00
parent bd7ac487cd
commit ccb0cd23f5

View file

@ -280,10 +280,19 @@ static int l_CmdConsole(lua_State *L) {
} }
static int l_iso15693_crc(lua_State *L) { static int l_iso15693_crc(lua_State *L) {
size_t size; uint32_t tmp;
const char *v = luaL_checklstring(L, 1, &size); unsigned char buf[USB_CMD_DATA_SIZE] = {0x00};
// iceman, should be size / 2 ?!? size_t size = 0;
lua_pushunsigned(L, crc( CRC_15693, (uint8_t *) v, size)); const char *data = luaL_checklstring(L, 1, &size);
for (int i = 0; i < size; i += 2) {
sscanf(&data[i], "%02x", &tmp);
buf[i / 2] = tmp & 0xFF;
}
size /= 2;
compute_crc(CRC_15693, buf, size, &buf[size], &buf[size+1]);
lua_pushlstring(L, (const char *)&buf, size+2);
return 1; return 1;
} }