diff --git a/UUV.lua b/UUV.lua new file mode 100644 index 0000000..4536fd0 --- /dev/null +++ b/UUV.lua @@ -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("榄杆天线" 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) + +