Skip to content

Commit

Permalink
enhance pcaptool to output processed bursts
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Apr 6, 2024
1 parent a444730 commit 964c460
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ __pycache__
/.coverage
/coverage.xml
/.pdm.toml
/.idea
/.tool-versions
2 changes: 1 addition & 1 deletion okdmr/dmrlib/tools/pcap_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def iter_pcap(

if len(ip_whitelist):
# if no whitelisted ips, do not filter
if ip_layer.src not in ip_whitelist:
if ip_layer and ip_layer.src not in ip_whitelist:
continue

if len(ports_whitelist):
Expand Down
4 changes: 3 additions & 1 deletion okdmr/dmrlib/transmission/transmission_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def process_packet(self, data: bytes, packet: IP) -> None:
data=data, packet=packet, silent=True
)
if burst:
self.process_burst(burst)
processed_burst: Burst = self.process_burst(burst)
if processed_burst:
print(processed_burst)
if self.debug_voice_bytes and burst.is_vocoder:
import logging

Expand Down
27 changes: 27 additions & 0 deletions okdmr/dmrlib/utils/log_color_formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging


class LogColorFormatter(logging.Formatter):
# \x1b == \033
grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = (
"%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
)

FORMATS = {
logging.DEBUG: red + format + reset,
logging.INFO: yellow + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset,
}

def format(self, record):
print(f"OH {record.levelno}")
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
2 changes: 1 addition & 1 deletion okdmr/tests/dmrlib/storage/test_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_repeater():
rpt.attr("custom_attr", 123_456)
assert rpt.attr("custom_attr") == 123_456
rpt.delete_attr("custom_attr")
assert rpt.attr("custom_attr") == None
assert rpt.attr("custom_attr") is None

rpt.nat_enabled = True
assert rpt.repeater_target_address() == ADDRESS_EMPTY
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ test = [
"pytest>=7.0.0",
"pytest-cov>=4.0.0",
"pytest-asyncio>=0.20.0",
"crc>=4.0.0"
"crc>=4.0.0",
"coverage>=7.4.0"
]

[project.scripts]
Expand Down

0 comments on commit 964c460

Please sign in to comment.