lua测试
This commit is contained in:
@@ -30,7 +30,8 @@ PLAN_ID=15
|
||||
-- 2023.5.19
|
||||
-- 扫描uid,超出最大返回时间范围则显示芯片异常
|
||||
-- 添加起爆充能失败的判断,此时返回芯片异常
|
||||
|
||||
-- 2023.6.29
|
||||
-- 使用算数运算代替位运算
|
||||
|
||||
|
||||
|
||||
@@ -106,13 +107,29 @@ function only(t,n)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- 计算2的n次幂
|
||||
function exp2(n)
|
||||
local ret=1
|
||||
for i=1,n,1 do
|
||||
ret=ret*2
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- 8个字节描述执行结果0成功,1失败
|
||||
function find_ack(index,acks)
|
||||
if(index>len(acks)*8) or index<1 then
|
||||
print("index out of range.index=",index)
|
||||
return false
|
||||
end
|
||||
if ((acks[(index-1)//8+1] & (1<<((index-1)%8)))~=0) then
|
||||
local temp=acks[math.floor((index-1)/8)+1]
|
||||
local i=(index-1)%8
|
||||
if ((math.floor((temp % exp2(i+1))/exp2(i)))~=0) then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
@@ -126,7 +143,9 @@ function find_stat(index,stats)
|
||||
print("index out of range.index=",index)
|
||||
return false
|
||||
end
|
||||
if ((stats[(index-1)//8+1] & (1<<((index-1)%8)))~=0) then
|
||||
local temp=stats[math.floor((index-1)/8)+1]
|
||||
local i=(index-1)%8
|
||||
if ((math.floor((temp % exp2(i+1))/exp2(i)))~=0) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
@@ -197,8 +216,9 @@ function find_return(index)
|
||||
if(temp==nil) then return ret end
|
||||
-- print("find_return,temp=")
|
||||
-- prints:print_a(temp)
|
||||
for i=1,len//2,1 do
|
||||
ret[i]=temp[i*2-1]|(temp[i*2]<<8)
|
||||
local len_t=math.floor(len/2)
|
||||
for i=1,len_t,1 do
|
||||
ret[i]=temp[i*2-1]+(temp[i*2]*exp2(8))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
@@ -640,7 +660,7 @@ function check_env()
|
||||
local skip,l=calc_skip(len(json_table["TaskArray"]),json_table["TaskArray"])
|
||||
-- print("requier len=",skip+l)
|
||||
if(skip+l+16>len(check_data)) then
|
||||
print("check data too less.")
|
||||
print("check data too less.",skip+l+16)
|
||||
return "数据长度与方案不符",210
|
||||
end
|
||||
if(json_table["PlanID"]~=PLAN_ID) then
|
||||
@@ -693,4 +713,6 @@ end
|
||||
|
||||
-- 先返回错误描述,再返回错误码
|
||||
return main()
|
||||
|
||||
-- print("sssss",exp2(-1))
|
||||
-- show_acks({1,2,3,4,5,6,7,8})
|
||||
-- prints:print_a({1,2,3,4,5,6,7,8,9,0xf0,0xe,0xd})
|
Reference in New Issue
Block a user