From b3efbc7438a3a25167f9c39b4bd7c6f1708bd161 Mon Sep 17 00:00:00 2001 From: xAnavrins Date: Wed, 24 Jul 2019 00:45:00 -0400 Subject: [PATCH] Distance filter in Sniffer --- sys/apps/Sniff.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sys/apps/Sniff.lua b/sys/apps/Sniff.lua index 3a8257c..2bda4f0 100644 --- a/sys/apps/Sniff.lua +++ b/sys/apps/Sniff.lua @@ -73,13 +73,24 @@ local page = UI.Page { event = 'filter_add', }, filterAllCheck = UI.Checkbox { - x = 13, y = 4, + x = 14, y = 8, value = false, }, filterAddText = UI.Text { - x = 17, y = 4, + x = 18, y = 8, value = "Use ID filter", }, + rangeText = UI.Text { + x = 15, y = 2, + value = "Distance filter", + }, + rangeEntry = UI.TextEntry { + x = 15, y = 3, + width = 10, + limit = 8, + shadowText = 'Range', + transform = 'number', + }, }, modemTab = UI.Tab { tabTitle = 'Modem', @@ -268,8 +279,14 @@ function page.packetSlide:eventHandler(event) return true end +function page.packetGrid:getDisplayValues(row) + local row = Util.shallowCopy(row) + row.distance = Util.toBytes(Util.round(row.distance), 2) + return row +end + function page.packetGrid:addPacket(packet) - if not page.paused and (not filterConfig.filterAllCheck.value or filterConfig.filterGrid.values[packet.portid]) then + if not page.paused and (packet.distance <= (filterConfig.rangeEntry.value or math.huge)) and (not filterConfig.filterAllCheck.value or filterConfig.filterGrid.values[packet.portid]) then page.index = page.index + 1 local _, res = pcall(textutils.serialize, packet.message) packet.packetStr = res:gsub("\n%s*", "")