refactoring

This commit is contained in:
Andrey 2022-08-26 00:14:52 -04:00
parent 45d8716fcc
commit c17cc38470
2 changed files with 16 additions and 13 deletions

View File

@ -21,6 +21,22 @@ end \
#define PRINT_ARRAY "hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \"A\", \"B\", \"C\", \"D\", \"E\", \"F\" } \ #define PRINT_ARRAY "hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \"A\", \"B\", \"C\", \"D\", \"E\", \"F\" } \
\ \
function toHexString(num) \
if num == 0 then \
return '0' \
end \
\
local result = \"\" \
while num > 0 do \
local n = num % 16 \
result = hexstr[n + 1] ..result \
num = math.floor(num / 16) \
end \
return result \
end \
\
\
\
" "
// LSB (Least Significant Byte comes first) "Intel" // LSB (Least Significant Byte comes first) "Intel"

View File

@ -23,19 +23,6 @@ TEST(LuaVag, Checksum) {
TEST(LuaVag, packMotor1) { TEST(LuaVag, packMotor1) {
const char* realdata = PRINT_ARRAY ARRAY_EQUALS SET_TWO_BYTES R"( const char* realdata = PRINT_ARRAY ARRAY_EQUALS SET_TWO_BYTES R"(
function toHexString(num)
if num == 0 then
return '0'
end
local result = ""
while num > 0 do
local n = num % 16
result = hexstr[n + 1] ..result
num = math.floor(num / 16)
end
return result
end
function arrayToString(arr) function arrayToString(arr)
local str = "" local str = ""