File: 0002-tachograph.lua-Avoid-errors-over-Lua-5.3.patch

package info (click to toggle)
cardpeek 0.8.4-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,624 kB
  • sloc: ansic: 11,114; sh: 4,266; makefile: 83; xml: 58; objc: 38
file content (67 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Origin: https://github.com/L1L1/cardpeek/pull/110
From: =?UTF-8?q?David=20Santamar=C3=ADa=20Rogado?= <howl.nsp@gmail.com>
Date: Sat, 8 Feb 2020 21:54:22 +0100
Subject: [PATCH 2/3] 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 Santamara Rogado <howl.nsp@gmail.com>
---
 dot_cardpeek_dir/scripts/tachograph.lua | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/dot_cardpeek_dir/scripts/tachograph.lua b/dot_cardpeek_dir/scripts/tachograph.lua
index 17d52bc..77663d4 100644
--- a/dot_cardpeek_dir/scripts/tachograph.lua
+++ b/dot_cardpeek_dir/scripts/tachograph.lua
@@ -281,9 +281,10 @@ end
 
 function Tacho_TEXT_8859(data,node)
     global('iconv')
+    local part = math.tointeger(data[0])
     
-    if iconv and data[0]>0 then
-        local format = "ISO-8859-"..data[0]
+    if iconv and part>0 then
+        local format = "ISO-8859-"..part
         local conversion = iconv.open(format,"UTF-8")
         local converted = conversion:iconv(data:sub(1):format("%C"))
         if converted then
@@ -292,9 +293,9 @@ function Tacho_TEXT_8859(data,node)
         end
     end
     
-    if data[0]==1 then
+    if part==1 then
         node:set_attribute("alt",data:sub(1):format("%P"))
-    elseif data[0]==0 then
+    elseif part==0 then
         node:set_attribute("alt","(empty)")
     end
 end 
@@ -327,7 +328,7 @@ function Tacho_ActivityChangeInfo(data,node)
     local time = bit.AND(data:tonumber(),0x07FF)
     local sub_node = node:append({  classname='record',
                                     label='Change', 
-                                    id=string.format("%02u:%02u",time/60,time%60),
+                                    id=string.format("%02u:%02u",math.floor(time/60),time%60),
                                     val=data,
                                     size=2 })
     local activity = bit.SHR(bit.AND(data[0],0x18),3)
@@ -452,10 +453,10 @@ function Tacho_ACTIVITY_RECORDS(data,node)
             subnode:set_attribute("alt",string.format("%s: %d km\n  %dh%02d break, %dh%02d availability, %dh%02d work, %dh%02d drive",
                     rec_date,
                     subpart(data,ptr+10,ptr+11):tonumber(),
-                    cat_total[1]/60,  cat_total[1]%60,
-                    cat_total[2]/60,  cat_total[2]%60,
-                    cat_total[3]/60,  cat_total[3]%60,
-                    cat_total[4]/60,  cat_total[4]%60))
+                    math.floor(cat_total[1]/60),  cat_total[1]%60,
+                    math.floor(cat_total[2]/60),  cat_total[2]%60,
+                    math.floor(cat_total[3]/60),  cat_total[3]%60,
+                    math.floor(cat_total[4]/60),  cat_total[4]%60))
         else
              subnode:set_attribute("alt","(no activity)")
         end