From ccb0cd23f56f0b19a73da6817bacc4c22a806ddb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Nov 2018 01:19:57 +0100 Subject: [PATCH] FIX: 'lua calc of iso15692 crc' - works better now --- client/scripting.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/client/scripting.c b/client/scripting.c index f0fa9b2f4..762a9c470 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -280,10 +280,19 @@ static int l_CmdConsole(lua_State *L) { } static int l_iso15693_crc(lua_State *L) { - size_t size; - const char *v = luaL_checklstring(L, 1, &size); - // iceman, should be size / 2 ?!? - lua_pushunsigned(L, crc( CRC_15693, (uint8_t *) v, size)); + uint32_t tmp; + unsigned char buf[USB_CMD_DATA_SIZE] = {0x00}; + size_t size = 0; + 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; }