添加电池测试功能
This commit is contained in:
parent
bf5b2f9691
commit
aec5e8b9e7
57
电池测试.lua
Normal file
57
电池测试.lua
Normal file
@ -0,0 +1,57 @@
|
||||
function getBattInfo(str)
|
||||
local a1,a2,a3,a4,a5,a6,a7,a8,a9,b1,b2,b3,b4,b5,b6,b7,b8= string.unpack(">hhhhhhhhhhhhhhhhh",str)
|
||||
local rst = ""
|
||||
.."实际电压 "..(a1/100).."V\r\n"
|
||||
.."电芯数量 "..a2.."\r\n"
|
||||
.."电量 "..a3.."%\r\n"
|
||||
.."容量 "..(a4/100).."AH\r\n"
|
||||
.."输出电流 "..(a5/100).."A\r\n"
|
||||
.."充电电流 "..(a6/100).."A\r\n"
|
||||
.."温度1 "..a7.."℃\r\n"
|
||||
.."温度2 "..a8.."℃\r\n"
|
||||
.."温度3 "..a9.."℃\r\n"
|
||||
.."电芯1电压 "..(b1/1000).."V\r\n"
|
||||
.."电芯2电压 "..(b2/1000).."V\r\n"
|
||||
.."电芯3电压 "..(b3/1000).."V\r\n"
|
||||
.."电芯4电压 "..(b4/1000).."V\r\n"
|
||||
.."电芯5电压 "..(b5/1000).."V\r\n"
|
||||
.."电芯6电压 "..(b6/1000).."V\r\n"
|
||||
.."电芯7电压 "..(b7/1000).."V\r\n"
|
||||
.."电芯8电压 "..(b8/1000).."V\r\n"
|
||||
|
||||
apiAddPoint((a1/100),8)
|
||||
apiAddPoint(a3,9)
|
||||
return rst
|
||||
end
|
||||
|
||||
|
||||
function getinfo(data)
|
||||
local info = "\r\n长度:["..string.len(data).."]字节\r\n原始数据:\r\n"..data:toHex()
|
||||
print(info)
|
||||
|
||||
--按换行符切开,防止粘包
|
||||
local udata = data:split(string.char(0x01)..string.char(0x03)..string.char(0x3a))
|
||||
|
||||
--每包都处理一遍
|
||||
for i=1,#udata do
|
||||
if #udata[i]>10 then
|
||||
local rst = "\r\n------电池信息------\r\n"..getBattInfo(udata[i]).."\r\n"
|
||||
print(rst)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--注册串口接收函数
|
||||
apiSetCb("uart",getinfo)
|
||||
|
||||
|
||||
--发送数据中间间隔时间(单位ms)
|
||||
local sendDelay = 1000*60
|
||||
local cmd="01030000001D85C3"
|
||||
|
||||
sys.taskInit(function ()
|
||||
while true do
|
||||
log.info("发送指令",apiSendUartData(cmd:fromHex()),cmd)
|
||||
sys.wait(sendDelay)
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue
Block a user