添加uuv
This commit is contained in:
parent
fd631d48be
commit
78e1d6b38e
123
UUV.lua
Normal file
123
UUV.lua
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
local n1 = {"漏水", "温度", "CDB", "S-TT", "BD", "SJL", "电源", "预留"}
|
||||||
|
local n2 = {"S-TT", "BD", "CDB", "SJL", "FB", "预留", "预留", "预留"}
|
||||||
|
local bx = {"0.6kbps", "1.2kbps", "2.4kbps", "4.8kbps"}
|
||||||
|
local sttSpeed = {"2.4bps", "4.8kbps", "9.6kbps"}
|
||||||
|
local cdbSpeed = {"未知","未知","2.4kbps", "4.8kbps", "38.4kbps"}
|
||||||
|
|
||||||
|
-- Function to check the status of modules based on the bits of a byte
|
||||||
|
function checkModuleStatus(moduleNames,a)
|
||||||
|
-- Table to store the status of each module
|
||||||
|
local status = {}
|
||||||
|
|
||||||
|
-- Table with module names
|
||||||
|
|
||||||
|
|
||||||
|
-- Iterate through each bit of the byte
|
||||||
|
for i = 0, 7 do
|
||||||
|
-- Extract the bit value (0 or 1) at position i
|
||||||
|
local bitValue = (a >> i) & 1
|
||||||
|
-- Store the status (1 for abnormal, 0 for normal)
|
||||||
|
status[moduleNames[i + 1]] = bitValue
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Return the status table
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
|
||||||
|
function getBattInfo(str)
|
||||||
|
local a1,a3,a5,a6,a7,a8,a9,a10,a18,a19,a23,a24,a25,a26,a27,a28,a29,a30= string.unpack("<c2Hc1BBBBc8BI4BBBBBBBB",str)
|
||||||
|
local a31,a33,a34,a35,a36,a37,a38,a40,a48,a56,a57,a58,a62,a66,a70,a71,a73,a75,a76,a78,a80,a82,a84,a86,a88,a90,a92,a94,a96,a97= string.unpack("<HBBBBBHddBBfffBHHBHHHHHHHHHHBH",str:sub(31,-1))
|
||||||
|
|
||||||
|
local s1=""
|
||||||
|
local moduleStatus = checkModuleStatus(n1,a6)
|
||||||
|
for moduleName, _ in pairs(moduleStatus) do
|
||||||
|
s1 = s1..moduleName .. "\t"
|
||||||
|
end
|
||||||
|
s1=s1.."\r\n"
|
||||||
|
|
||||||
|
-- Print the corresponding statuses
|
||||||
|
for _, status in pairs(moduleStatus) do
|
||||||
|
s1 = s1..(status == 1 and "X" or "√") .. "\t"
|
||||||
|
end
|
||||||
|
|
||||||
|
local s2=""
|
||||||
|
local moduleStatus = checkModuleStatus(n2,a6)
|
||||||
|
for moduleName, _ in pairs(moduleStatus) do
|
||||||
|
s2 = s2..moduleName .. "\t"
|
||||||
|
end
|
||||||
|
s2=s2.."\r\n"
|
||||||
|
|
||||||
|
-- Print the corresponding statuses
|
||||||
|
for _, status in pairs(moduleStatus) do
|
||||||
|
s2 = s2..(status == 1 and "√" or "--") .. "\t"
|
||||||
|
end
|
||||||
|
|
||||||
|
local rst = "\r\n"..
|
||||||
|
"a1 "..a1.."\r\n"..
|
||||||
|
"a3 "..a3.."\r\n"..
|
||||||
|
"a5 "..a5.."\r\n"..
|
||||||
|
"a6 "..string.format("0x%02X",a6).."\r\n"..
|
||||||
|
s1.."\r\n"..
|
||||||
|
"a7 "..string.format("0x%02X",a7).."\r\n"..
|
||||||
|
s2.."\r\n"..
|
||||||
|
"a8 ".."S工作状态\t\t"..(a8== 0 and "未入网" or (a8== 1 and "已入网" or "错误:"..string.format("0x%02X",a8))).."\r\n"..
|
||||||
|
"a9 "..a9.."\r\n"..
|
||||||
|
"a10 "..a10.."\r\n"..
|
||||||
|
"a18 "..a18.."\r\n"..
|
||||||
|
"a19 ".."CDB频率\t\t"..a19.." kHz\r\n"..
|
||||||
|
"a23 ".."CDB速率\t\t"..(a23 < 0x05 and bx[a23] or "错误:"..string.format("0x%02X",a23)).."\r\n"..
|
||||||
|
"a24 ".."S天线模式\t\t"..(a24 == 0x01 and "一线通天线<----->榄杆天线" or (a24 == 0x02 and "二线通天线<----->FB天线" or "错误:"..string.format("0x%02X",a24))).."\r\n"..
|
||||||
|
"a25 ".."TT模式\t\t"..(a25 == 0x00 and "点波束" or (a28 == 0x01 and "海模式" or "错误:"..string.format("0x%02X",a25))).."\r\n"..
|
||||||
|
"a26 ".."TT速率\t\t"..(a26 < 0x04 and sttSpeed[a26] or "错误:"..string.format("0x%02X",a26)).."\r\n"..
|
||||||
|
"a27 ".."BD天线模式\t"..(a27 == 0x01 and "一线通天线<----->榄杆天线" or (a27 == 0x02 and "二线通天线<----->FB天线" or "错误:"..string.format("0x%02X",a27))).."\r\n"..
|
||||||
|
"a28 ".."卡模式\t\t"..(a28 == 0x01 and "民卡模式" or (a28 == 0x02 and "芯片模式" or "错误:"..string.format("0x%02X",a28))).."\r\n"..
|
||||||
|
"a29 "..a29.."\r\n"..
|
||||||
|
"a30 "..a30.."\r\n"..
|
||||||
|
"a31 ".."时间\t\t"..string.format("%d年%d月%d日 %d:%d:%d.%d",a31,a33,a34,a35,a36,a37,a38).."\r\n"..
|
||||||
|
"a40 ".."纬度\t\t"..a40.."\r\n"..
|
||||||
|
"a48 ".."经度\t\t"..a48.."\r\n"..
|
||||||
|
"a56 ".."定位\t\t"..(a56== 6 and "正在估算" or (a56 == 1 and "非差分定位" or "未定位")).."\r\n"..
|
||||||
|
"a57 ".."卫星数\t\t"..a57.."\r\n"..
|
||||||
|
"a58 ".."HDOP\t\t"..a58.."\r\n"..
|
||||||
|
"a62 ".."海拔\t\t"..a62.."\r\n"..
|
||||||
|
"a66 ".."航速\t\t"..a66.."\r\n"..
|
||||||
|
"a70 ".."调制方式\t\t"..(a70 == 1 and "FM" or "AM").."\r\n"..
|
||||||
|
"a71 ".."信道类型\t\t"..(a71 == 0xc1 and "X02" or (a71 == 0xc2 and "X03" or "错误:"..string.format("0x%02X",a71))).."\r\n"..
|
||||||
|
"a73 ".."站方式\t\t"..(a73 == 0x01 and "主站" or (a73 == 0x04 and "从站" or "错误:"..string.format("0x%02X",a73))).."\r\n"..
|
||||||
|
"a75 ".."波形速率\t\t"..(a75 < 0x04 and bx[a75] or "错误").."\r\n"..
|
||||||
|
"a76 "..a76.."\r\n"..
|
||||||
|
"a78 "..a78.."\r\n"..
|
||||||
|
"a80 "..a80.."\r\n"..
|
||||||
|
"a82 "..a82.."\r\n"..
|
||||||
|
"a84 "..a84.."\r\n"..
|
||||||
|
"a86 "..a86.."\r\n"..
|
||||||
|
"a88 "..a88.."\r\n"..
|
||||||
|
"a90 "..a90.."\r\n"..
|
||||||
|
"a92 "..a92.."\r\n"..
|
||||||
|
"a94 "..a94.."\r\n"..
|
||||||
|
"a96 "..a96.."\r\n"..
|
||||||
|
"a97 "..a97.."\r\n"
|
||||||
|
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(0x54)..string.char(0x58))
|
||||||
|
|
||||||
|
--每包都处理一遍
|
||||||
|
for i=1,#udata do
|
||||||
|
if #udata[i]>10 then
|
||||||
|
-- local rst = parseInfo(string.char(0x54)..string.char(0x58)..udata[i])
|
||||||
|
local rst = getBattInfo(string.char(0x54)..string.char(0x58)..udata[i])
|
||||||
|
print(rst)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--注册串口接收函数
|
||||||
|
apiSetCb("uart",getinfo)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user