L1L1 / cardpeek

Automatically exported from code.google.com/p/cardpeek
Other
448 stars 116 forks source link

cardpeek tachograph over Fedora 31 lua float integer issues #109

Open howl opened 4 years ago

howl commented 4 years ago

I'm having troubles with cardpeek tachograph as it uses integer values as floats.

For example this piece of code: local format = "ISO-8859-"..data[0] makes format be "ISO-8859-1.0" instead "ISO-8859-1"

I don't know about lua so I searched to see if there is a way to default to integer values but it seems that it should do automatically as 1.0 could be represented as 1.

The same issue remains for the time for example here: local sub_node = node:append({ classname='record', label='Change', id=string.format("%02u:%02u",time/60,time%60), val=data, size=2 })

time/60 is not integer and it does fail.

I have added math.floor() where applicable but I suppose there should be an easier way to do it I can't find.

I have diff over an xml generated with the windows version and there are a lot of numbers in the fedora output with .0 that doesn't appear over the windows output.

howl commented 4 years ago

I think the problem could be because of a lua 5.2 to 5.3 change https://stackoverflow.com/a/36031506

Fedora is using 5.3, chould cardpeek be changed to use lua 5.3? also in the output the value cold ATR is set with .0 instead of just the value.

howl commented 4 years ago

I have tried my best with lua as I have no knowledge about it and I did the following changes.

19c19
< -- @name Tachograph 
---
> -- @name Tachograph LUA 5.3 
108c108
<     return activityStructureLength 
---
>     return math.tointeger(activityStructureLength) 
283a284
>     local part = math.tointeger(data[0])
285,286c286,287
<     if iconv and data[0]>0 then
<         local format = "ISO-8859-"..data[0]
---
>     if iconv and part>0 then
>         local format = "ISO-8859-"..part
295c296
<     if data[0]==1 then
---
>     if part==1 then
297c298
<     elseif data[0]==0 then
---
>     elseif part==0 then
308c309
<     node:set_attribute("alt",data:tonumber())
---
>     node:set_attribute("alt",math.tointeger(data:tonumber()))
330c331
<                                     id=string.format("%02u:%02u",time/60,time%60),
---
>                                     id=string.format("%02u:%02u",time//60,time%60),
415c416
<         subnode = node:append({classname='record',label='CardActivityDailyRecord', size=rec_len, id=counter})
---
>         subnode = node:append({classname='record',label='CardActivityDailyRecord', size=math.tointeger(rec_len), id=counter})
419c420
<                         alt=string.format("%d (address:%s)",rec_len,ptr)})
---
>                         alt=string.format("%d (address:%s)",rec_len,math.tointeger(ptr))})
423c424
<                         alt=subpart(data,ptr,ptr+1):tonumber()})
---
>                         alt=math.tointeger(subpart(data,ptr,ptr+1):tonumber())})
431c432
<                         alt=subpart(data,ptr+8,ptr+9):tonumber() })
---
>                         alt=math.tointeger(subpart(data,ptr+8,ptr+9):tonumber()) })
435c436
<                         alt=subpart(data,ptr+10,ptr+11):tonumber() .. " km"})
---
>                         alt=math.tointeger(subpart(data,ptr+10,ptr+11):tonumber()) .. " km"})
438c439
<                         size=#activity,
---
>                         size=math.tointeger(#activity),
455,458c456,459
<                     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))
---
>                     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))

If // operator is changed to use / and then the result with math.floor() I think it can be keep compatible with previous lua versions.

howl commented 4 years ago

I will try to do a pull request with 3 commits, one for the ATR, another one with the minimum needed changes to get tachograph.lua work over lua 5.3 and finally a third one making the output behave as the previous lua versions.

Still I don't know if it could be a way to make cardpeek work over lua 5.3 as expected over previous versions without the need to be using math.tointeger() an similars in the card script.

howl commented 4 years ago

Well, I tried to do my best, https://github.com/L1L1/cardpeek/pull/110.