lua测试
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import lupa
|
||||
from lupa import LuaRuntime
|
||||
import execjs
|
||||
|
||||
|
||||
class save:
|
||||
@@ -38,20 +39,39 @@ class save:
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sa=save()
|
||||
print(sa.hex2bit(bytes([0xab,0xcd])))
|
||||
|
||||
def lua_test():
|
||||
# 初始化lua运行环境
|
||||
lua = LuaRuntime(unpack_returned_tuples=True)
|
||||
# 初始化全局变量 json
|
||||
save_json=lua.eval("function(a) json=a end")
|
||||
with open("file/json.lua",encoding="utf-8") as f:
|
||||
save_json(lua.execute(f.read()))
|
||||
# 初始化全局变量 prints
|
||||
save_prints=lua.eval("function(a) prints=a end")
|
||||
with open("file/prints.lua",encoding="utf-8") as f:
|
||||
save_prints(lua.execute(f.read()))
|
||||
# 初始化全局变量 cfg_name
|
||||
lua.execute("cfg_name=\"file/checker_ye_cfg.json\"\n")
|
||||
lua.execute("check_data={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}\n")
|
||||
# 初始化全局变量 check_data
|
||||
lua.execute("check_data={0xB5,0x96,0xEC,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x21,0x00,0x12,0x01,0x00,0x00,0x00,0x00,0xB5,0x00,0xB1,0x00,0x6B,0x00,0x00,0x00,0xA5,0x02,0xA4,0x02,0x00,0x00,0xA4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}\n")
|
||||
# 执行判定脚本
|
||||
with open("file/judge.lua",encoding="utf-8") as f:
|
||||
lua.execute(f.read())
|
||||
# lua_func = lua.eval('function(a, b) return a+b end')
|
||||
# print(lua_func(1,2))
|
||||
a,b=lua.execute(f.read())
|
||||
print(a,b)
|
||||
|
||||
|
||||
def js_test():
|
||||
with open("file/judge.js",encoding="utf-8") as f:
|
||||
context1 = execjs.compile(f.read())
|
||||
json=open("file/checker_ye_cfg.json",encoding="utf-8").read()
|
||||
check_data=bytearray([0xB5,0x96,0xEC,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x21,0x00,0x12,0x01,0x00,0x00,0x00,0x00,0xB5,0x00,0xB1,0x00,0x6B,0x00,0x00,0x00,0xA5,0x02,0xA4,0x02,0x00,0x00,0xA4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
|
||||
a=context1.call("main",1,check_data)
|
||||
print(a)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sa=save()
|
||||
print(sa.hex2bit(bytes([0xab,0xcd])))
|
||||
# lua_test()
|
||||
js_test()
|
||||
|
12
python/file/judge.js
Normal file
12
python/file/judge.js
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
|
||||
function main(j,check_data)
|
||||
{
|
||||
//var obj =JSON.parse(json);
|
||||
//print(j)
|
||||
//print(check_data)
|
||||
}
|
||||
|
||||
|
@@ -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})
|
@@ -1,6 +1,13 @@
|
||||
|
||||
|
||||
|
||||
-- 2023.6.29
|
||||
-- 使用算数运算代替位运算
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module = {}
|
||||
|
||||
function module:print_t ( t )
|
||||
@@ -45,12 +52,13 @@ function byte_to_hex(byte,size)
|
||||
local str_ret=""
|
||||
if(size==2) then
|
||||
str_ret=string.char(
|
||||
string.byte( str_table,((byte>>12)&0xf)+1),
|
||||
string.byte( str_table,((byte>>8)&0xf)+1),
|
||||
string.byte( str_table,((byte>>4)&0xf)+1),
|
||||
string.byte(str_table,(byte&0xf)+1))
|
||||
-- 右移12位,//4096
|
||||
string.byte( str_table,(math.floor(byte/4096)%16)+1),
|
||||
string.byte( str_table,(math.floor(byte/256)%16)+1),
|
||||
string.byte( str_table,(math.floor(byte/16)%16)+1),
|
||||
string.byte(str_table,(byte%16)+1))
|
||||
else
|
||||
str_ret=string.char(string.byte(str_table,(byte%256)//16+1),string.byte(str_table,(byte%256)%16+1))
|
||||
str_ret=string.char(string.byte(str_table,math.floor((byte%256)/16)+1),string.byte(str_table,(byte%256)%16+1))
|
||||
end
|
||||
return str_ret
|
||||
end
|
||||
|
Reference in New Issue
Block a user