From 646b37b2b34a57a050984e4dd953070c1714b2d3 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 20 Sep 2022 10:01:32 +0200 Subject: [PATCH] sniffer / spectrum-scanner: reformat using black --- sniffer/tools/sniffer.py | 82 ++++++++++++++++------------- spectrum-scanner/tools/plot_rssi.py | 56 +++++++++++++------- 2 files changed, 84 insertions(+), 54 deletions(-) diff --git a/sniffer/tools/sniffer.py b/sniffer/tools/sniffer.py index 9d29a51691..07ea50e013 100755 --- a/sniffer/tools/sniffer.py +++ b/sniffer/tools/sniffer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" (C) 2012, Mariano Alvira (C) 2014, Oliver Hahm (C) 2015, Hauke Petersen @@ -30,7 +30,7 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' +""" from __future__ import print_function import argparse @@ -42,13 +42,13 @@ from struct import pack from serial import Serial # PCAP setup -MAGIC = 0xa1b2c3d4 +MAGIC = 0xA1B2C3D4 MAJOR = 2 MINOR = 4 ZONE = 0 SIG = 0 -SNAPLEN = 0xffff -NETWORK = 230 # 802.15.4 no FCS +SNAPLEN = 0xFFFF +NETWORK = 230 # 802.15.4 no FCS DEFAULT_BAUDRATE = 115200 @@ -56,45 +56,44 @@ DEFAULT_BAUDRATE = 115200 def configure_interface(port, channel): line = "" iface = 0 - port.write('ifconfig\n'.encode()) + port.write("ifconfig\n".encode()) while True: line = port.readline() - if line == b'': - print("Application has no network interface defined", - file=sys.stderr) + if line == b"": + print("Application has no network interface defined", file=sys.stderr) sys.exit(2) - match = re.search(r'^Iface +(\d+)', line.decode(errors="ignore")) + match = re.search(r"^Iface +(\d+)", line.decode(errors="ignore")) if match is not None: iface = int(match.group(1)) break # set channel, raw mode, and promiscuous mode - print('ifconfig %d set chan %d' % (iface, channel), file=sys.stderr) - print('ifconfig %d raw' % iface, file=sys.stderr) - print('ifconfig %d promisc' % iface, file=sys.stderr) - port.write(('ifconfig %d set chan %d\n' % (iface, channel)).encode()) - port.write(('ifconfig %d raw\n' % iface).encode()) - port.write(('ifconfig %d promisc\n' % iface).encode()) + print("ifconfig %d set chan %d" % (iface, channel), file=sys.stderr) + print("ifconfig %d raw" % iface, file=sys.stderr) + print("ifconfig %d promisc" % iface, file=sys.stderr) + port.write(("ifconfig %d set chan %d\n" % (iface, channel)).encode()) + port.write(("ifconfig %d raw\n" % iface).encode()) + port.write(("ifconfig %d promisc\n" % iface).encode()) def generate_pcap(port, out): # count incoming packets count = 0 # output overall PCAP header - out.write(pack('? *rftest-rx --- len (\w+).*", - line.decode(errors="ignore")) + pkt_header = re.match( + r">? *rftest-rx --- len (\w+).*", line.decode(errors="ignore") + ) if pkt_header: now = time() sec = int(now) usec = int((now - sec) * 1000000) length = int(pkt_header.group(1), 16) - out.write(pack('