Now tried to put same script and same story again. This is the script:
Code: Select all
local a=3;local b=43.5;local c=addChannel("CAN",1,0,0,300,"Hz")initCAN(0,500000)setTickRate(1000)local d=true;function onTick()if d then d=false;for e=1,10 do rxCAN(0,5)end;readCANmap()end;if d then local f=getUptime()local g=0;repeat collectgarbage()g=g+1 until getUptime()>f+1000;setChannel(c,g)end end;local h={}local i="0123456789ABCDEF"function readCANmap()local j=1;while j<=string.len(i)do local k=0;while k~=44 and k~=59 and k~=64 do println(k)j=j+1;k=string.byte(i,j)end end end;function readCAN(l,m)for e,n in ipairs(l)do local o=n[3]local p=n[4]if p==nil then p=o;o=1 end;if m%o==0 then local q=n[5]if q==nil then q=0;for r,s in ipairs(p)do q=q+s[1]end;q=q/8;n[5]=q end;local t=readCANdata(n[1],n[2],q)if t~=nil then local u=1;for e,s in ipairs(p)do local v=setChannelData(s,t,u)u=u+v end end end end end;function setChannelData(s,t,u)if s[2]==nil and s[9]==nil then return s[1]end;if s[9]==nil then if s[5]==nil then s[5]=""end;if s[6]==nil then s[6]=1 end;if s[7]==nil then s[7]=0 end;if s[8]==nil then s[8]=false end;local w=0;if s[6]<0.001 then w=4 elseif s[6]<0.01 then w=3 elseif s[6]<0.1 then w=2 elseif s[6]<1 then w=1 end;s[9]=addChannel(s[2],1000,w,s[3],s[4],s[5])s[2]=nil;s[3]=nil;s[4]=nil;s[5]=nil end;setChannel(s[9],getBitsNumber(t,u,s[1],s[8])*s[6]+s[7])return s[1]end;local x={0x1,0x3,0x7,0xF,0x1F,0x3F,0x7F,0xFF,0x1FF,0x3FF,0x7FF,0xFFF,0x1FFF,0x3FFF,0x7FFF,0xFFFF,0x1FFFF,0x3FFFF,0x7FFFF,0xFFFFF,0x1FFFFF,0x3FFFFF,0x7FFFFF,0xFFFFFF}local y,z,A=bit.band,bit.bxor,bit.bnot;local B,C=bit.lshift,bit.rshift;function getBitsNumber(D,E,F,G)local H=(8-(E+F-1)%8)%8;local I=1+(E-1-(E-1)%8)/8;local J=D[I]if F+H>8 then J=D[I+1]+B(J,8)if F+H>16 then J=D[I+2]+B(J,8)end end;J=C(J,H)J=y(J,x[F])if G then J=unsign16Bits(J)end;return J end;function unsign16Bits(K)if K>0x7FFF then local L=C(K,8)local M=y(K,0xFF)local N=0-B(y(-A(0x1000+L),0x00FF),8)N=N-y(-z(0x1000+M,0x0000),0x00FF)-1;return N end;return K end;function readCANdata(O,P,q)local Q={2,0x21,255,255,255,255,255,255}local R={48,8,0,255,255,255,255,255}local S=100;local T=P>255;if T then Q[1]=5;Q[2]=0x23;Q[3]=C(P,16)Q[4]=y(C(P,8),x[8])Q[5]=y(P,x[8])Q[6]=q else Q[3]=P end;res=txCAN(0,O,0,Q,S)if res~=1 then return nil end;local t={}local U,V,W=rxCAN(0,S)if U==nil then return nil end;local X=W[1]==0x10;local e=1;local Y=3;if X then Y=Y+1 end;if not T then Y=Y+1 end;while Y<9 do t[e]=W[Y]e=e+1;Y=Y+1 end;if not X then return t end;res=txCAN(0,O,0,R,S)if res~=1 then return nil end;local Z=(W[2]+1)/7;for _=1,Z do local U,V,W=rxCAN(0,S)if U==nil then return nil end;local Y=2;while Y<9 and e<q+1 do t[e]=W[Y]e=e+1;Y=Y+1 end end;return t end