mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-31 17:29:17 +02:00
log
This commit is contained in:
+12
-3
@@ -74,7 +74,10 @@ end
|
|||||||
---@param packet string
|
---@param packet string
|
||||||
local function parse_uecp(packet)
|
local function parse_uecp(packet)
|
||||||
local end_i = string.find(packet, "\xff", 1, true)
|
local end_i = string.find(packet, "\xff", 1, true)
|
||||||
if not end_i then return end
|
if not end_i then
|
||||||
|
print("could not find 0xff")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local unstuffed = undo_byte_stuff(string.sub(packet, 2, end_i - 1))
|
local unstuffed = undo_byte_stuff(string.sub(packet, 2, end_i - 1))
|
||||||
|
|
||||||
@@ -87,14 +90,20 @@ local function parse_uecp(packet)
|
|||||||
|
|
||||||
local data = string.sub(unstuffed, 5, 4 + mfl)
|
local data = string.sub(unstuffed, 5, 4 + mfl)
|
||||||
|
|
||||||
if mfl ~= #data then return end
|
if mfl ~= #data then
|
||||||
|
print("data len not right")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local crc_calculated = dp.crc16(string.sub(unstuffed, 1, 4 + mfl))
|
local crc_calculated = dp.crc16(string.sub(unstuffed, 1, 4 + mfl))
|
||||||
local crc_hi = string.byte(unstuffed, 4 + mfl + 1)
|
local crc_hi = string.byte(unstuffed, 4 + mfl + 1)
|
||||||
local crc_lo = string.byte(unstuffed, 4 + mfl + 2)
|
local crc_lo = string.byte(unstuffed, 4 + mfl + 2)
|
||||||
local crc_stored = (crc_hi << 8) | crc_lo
|
local crc_stored = (crc_hi << 8) | crc_lo
|
||||||
|
|
||||||
if crc_calculated ~= crc_stored then return end
|
if crc_calculated ~= crc_stored then
|
||||||
|
print("bad crc")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local mec = string.byte(data, 1)
|
local mec = string.byte(data, 1)
|
||||||
local handler = mec_handlers[mec]
|
local handler = mec_handlers[mec]
|
||||||
|
|||||||
Reference in New Issue
Block a user