user_script/UUV.lua

125 lines
4.5 KiB
Lua
Raw Normal View History

local s6Info = {"漏水", "温度", "CDB", "S-TT", "BD", "SJL", "电源", "预留"}
local s7Info = {"S-TT", "BD", "CDB", "SJL", "FB", "预留2", "预留1", "预留0"}
local a23Info = {nil,"2.4kbps", "4.8kbps", "38.4kbps"}
local a24Info = {"一线通天线<----->榄杆天线","二线通天线<----->FB天线"}
local a25Info = {"点波束","海模式"}
local a26Info = {"2.4bps", "4.8kbps", "9.6kbps"}
local a27Info = {"一线通天线<----->榄杆天线","二线通天线<----->FB天线"}
local a28Info = {"北三","芯片","北二"}
local a70Info = {"AM-老SJL专用保留","FM"}
local a71Info = {[0xc1]="X02模式",[0xc2]="X03模式"}
local a73Info = {[0x01]="主站",[0x04]="从站"}
local a75Info = {"0.6kbps", "1.2kbps", "2.4kbps", "4.8kbps"}
local function safeGet(array, index)
return array[index] ~= nil and array[index] or "错误:"..string.format("0x%02X",index)
end
function printHead(t)
local tmp=""
for i = 1, #t do
tmp = tmp..t[i].."\t"
end
return tmp
2024-07-03 09:49:09 +00:00
end
function parseInfo(str)
2024-07-03 09:49:09 +00:00
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="-----------------------------------------------------------------------\r\n"
s1=s1..printHead(s6Info).."\r\n"
2024-07-03 09:49:09 +00:00
-- Print the corresponding statuses
for i = 7,0,-1 do
local bitValue = (a6 >> i) & 1
s1 = s1..(bitValue == 1 and "X" or "") .. "\t"
2024-07-03 09:49:09 +00:00
end
s1=s1.."\r\n-----------------------------------------------------------------------"
2024-07-03 09:49:09 +00:00
local s2="-----------------------------------------------------------------------\r\n"
s2=s2..printHead(s7Info).."\r\n"
2024-07-03 09:49:09 +00:00
-- Print the corresponding statuses
for i = 7,0,-1 do
local bitValue = (a7 >> i) & 1
s2 = s2..(bitValue == 1 and "" or "--") .. "\t"
2024-07-03 09:49:09 +00:00
end
s2=s2.."\r\n-----------------------------------------------------------------------"
2024-07-03 09:49:09 +00:00
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"..
2024-07-03 09:53:13 +00:00
"a9 ".."S信号强度\t\t"..(a9== 0 and "无信号" or a9.."(4最强)").."\r\n"..
2024-07-03 09:49:09 +00:00
"a10 "..a10.."\r\n"..
"a18 "..a18.."\r\n"..
"a19 ".."CDB频率\t\t"..a19.." kHz\r\n"..
"a23 ".."CDB速率\t\t"..safeGet(a23Info,a23).."\r\n"..
"a24 ".."S天线模式\t\t"..safeGet(a24Info,a24).."\r\n"..
"a25 ".."STT模式\t\t"..safeGet(a25Info,a25+1).."\r\n"..
"a26 ".."STT速率\t\t"..safeGet(a26Info,a26+1).."\r\n"..
"a27 ".."BD天线模式\t"..safeGet(a27Info,a27).."\r\n"..
"a28 ".."卡模式\t\t"..safeGet(a28Info,a28+1).."\r\n"..
2024-07-03 09:49:09 +00:00
"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"..safeGet(a70Info,a70+1).."\r\n"..
"a71 ".."信道类型\t\t"..safeGet(a71Info,a71).."\r\n"..
"a73 ".."站方式\t\t"..safeGet(a73Info,a73).."\r\n"..
"a75 ".."波形速率\t\t"..safeGet(a75Info,a75+1).."\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"..
2024-07-03 09:49:09 +00:00
"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]>100 then
local rst = parseInfo(string.char(0x54)..string.char(0x58)..udata[i])
2024-07-03 09:49:09 +00:00
print(rst)
end
end
end
function getinfo1(data)
local data = data.data
getinfo(data)
end
2024-07-03 09:49:09 +00:00
--注册串口接收函数
apiSetCb("uart",getinfo)
apiSetCb("tcp-server",getinfo1)
2024-07-03 09:49:09 +00:00