Skip to content

Commit 0f3e074

Browse files
committed
tachograph.lua: Avoid errors over Lua 5.3
This changes the bare-minimum to let tachograph.lua work over Lua 5.3. Just the ISO-8859- part converted to integer to avoid conversion be nil and the hours calculation floored. Signed-off-by: David Santamaría Rogado <[email protected]>
1 parent db81cea commit 0f3e074

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

dot_cardpeek_dir/scripts/tachograph.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ end
281281

282282
function Tacho_TEXT_8859(data,node)
283283
global('iconv')
284+
local part = math.tointeger(data[0])
284285

285-
if iconv and data[0]>0 then
286-
local format = "ISO-8859-"..data[0]
286+
if iconv and part>0 then
287+
local format = "ISO-8859-"..part
287288
local conversion = iconv.open(format,"UTF-8")
288289
local converted = conversion:iconv(data:sub(1):format("%C"))
289290
if converted then
@@ -292,9 +293,9 @@ function Tacho_TEXT_8859(data,node)
292293
end
293294
end
294295

295-
if data[0]==1 then
296+
if part==1 then
296297
node:set_attribute("alt",data:sub(1):format("%P"))
297-
elseif data[0]==0 then
298+
elseif part==0 then
298299
node:set_attribute("alt","(empty)")
299300
end
300301
end
@@ -327,7 +328,7 @@ function Tacho_ActivityChangeInfo(data,node)
327328
local time = bit.AND(data:tonumber(),0x07FF)
328329
local sub_node = node:append({ classname='record',
329330
label='Change',
330-
id=string.format("%02u:%02u",time/60,time%60),
331+
id=string.format("%02u:%02u",math.floor(time/60),time%60),
331332
val=data,
332333
size=2 })
333334
local activity = bit.SHR(bit.AND(data[0],0x18),3)
@@ -452,10 +453,10 @@ function Tacho_ACTIVITY_RECORDS(data,node)
452453
subnode:set_attribute("alt",string.format("%s: %d km\n %dh%02d break, %dh%02d availability, %dh%02d work, %dh%02d drive",
453454
rec_date,
454455
subpart(data,ptr+10,ptr+11):tonumber(),
455-
cat_total[1]/60, cat_total[1]%60,
456-
cat_total[2]/60, cat_total[2]%60,
457-
cat_total[3]/60, cat_total[3]%60,
458-
cat_total[4]/60, cat_total[4]%60))
456+
math.floor(cat_total[1]/60), cat_total[1]%60,
457+
math.floor(cat_total[2]/60), cat_total[2]%60,
458+
math.floor(cat_total[3]/60), cat_total[3]%60,
459+
math.floor(cat_total[4]/60), cat_total[4]%60))
459460
else
460461
subnode:set_attribute("alt","(no activity)")
461462
end

0 commit comments

Comments
 (0)