From 20d2dd4e331fbbaf6aea12c8a51d733c1a1c5355 Mon Sep 17 00:00:00 2001 From: s-ol Date: Sun, 18 Feb 2024 20:42:30 +0100 Subject: dissectors/t937: dissect TEMP_STATUS messages --- dissectors/t937.lua | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/dissectors/t937.lua b/dissectors/t937.lua index 9d37ba6..cec6e9a 100755 --- a/dissectors/t937.lua +++ b/dissectors/t937.lua @@ -18,7 +18,11 @@ proto.fields.fun = ProtoField.uint8("t937.function", "Function", base.HEX, FUN_T proto.fields.len = ProtoField.uint8("t937.length", "Data Length", base.HEX) proto.fields.checksum = ProtoField.uint16("t937.checksum", "Message Checksum", base.HEX) -proto.fields.data = ProtoField.bytes("t937.data", "Data") +proto.fields.temp1 = ProtoField.uint16("t937.temp1", "Chamber Temp 1", base.UNIT_STRING, {"°C"}) +proto.fields.temp2 = ProtoField.uint16("t937.temp2", "Chamber Temp 2", base.UNIT_STRING, {"°C"}) +proto.fields.temp3 = ProtoField.uint16("t937.temp3", "Control Board Temp", base.UNIT_STRING, {"°C"}) + +proto.fields.data = ProtoField.bytes("t937.data", "Raw Data") local function try_dissect(bytes, pinfo, tree) -- minimum len is header + checksum @@ -28,34 +32,40 @@ local function try_dissect(bytes, pinfo, tree) if bytes:len() < 4 + raw_len + 2 then return end local buffer = bytes:subset(0, 4+raw_len+2):tvb("T-937 Frame") - local address = buffer(0, 2) - local fun = buffer(2, 1) - local len = buffer(3, 1) + local sub = tree:add(proto, buffer()) + + local i = 0 + sub:add_packet_field(proto.fields.addr, buffer(0, 2), ENC_BIG_ENDIAN) + local funf, fun, i = sub:add_packet_field(proto.fields.fun, buffer(2, 1), ENC_BIG_ENDIAN) + sub:add_packet_field(proto.fields.len, buffer(3, 1), ENC_BIG_ENDIAN) local data = buffer(4, raw_len) - local checksum = buffer(4+raw_len, 2) + sub:add_packet_field(proto.fields.data, data, ENC_BIG_ENDIAN) + local csf, cs = sub:add_packet_field(proto.fields.checksum, buffer(4+raw_len), ENC_BIG_ENDIAN) local sum = 0 for i=0,4+raw_len-1 do sum = sum + buffer(i, 1):uint() end - pinfo.cols.info:set("T937 " .. (FUN_TABLE[fun:uint()] or "")) - pinfo.cols.dst:clear_fence() - pinfo.cols.dst:set(address:bytes():tohex()) - - local sub = tree:add(proto, buffer()) - sub:add(proto.fields.addr, address) - sub:add(proto.fields.fun, fun) - sub:add(proto.fields.len, len) - sub:add(proto.fields.data, data) - - local cs = sub:add(proto.fields.checksum, checksum) - if sum ~= checksum:uint() then - cs:add_proto_expert_info(proto.experts.checksum, string.format( - "expected 0x%04x, got 0x%04x", checksum:uint(), sum + if sum ~= cs then + csf:add_proto_expert_info(proto.experts.checksum, string.format( + "expected 0x%04x, got 0x%04x", cs, sum )) end + local fun_name = FUN_TABLE[fun] + pinfo.cols.info:set("T937 " .. (fun_name or "")) + + if fun_name then + sub = sub:add(data, fun_name) + end + + if fun_name == "TEMP_STATUS" then + sub:add(proto.fields.temp1, data(0,2)) + sub:add(proto.fields.temp2, data(2,2)) + sub:add(proto.fields.temp3, data(4,2)) + end + return buffer:len() end @@ -106,9 +116,9 @@ function proto.dissector(_buf, pinfo, tree) while rest:len() > 0 do local ok, len = pcall(try_dissect, rest, pinfo, tree) if not ok then - print("GOT ERR", len, pinfo.number) state.error[pinfo.p2p_dir] = len state.last_number = pinfo.number + print(len) error(len) elseif not len then break -- cgit v1.2.3