Skip to content

Commit

Permalink
[reassembler] mtmap: formatting / pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec42 committed Apr 29, 2024
1 parent 7551a4b commit 4a67ad3
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions iridiumtk/reassembler/mtpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .ida import ReassembleIDA
from ..config import config, outfile


class ReassembleIDAMap(ReassembleIDA):
"""Extract coordinates from access decision messages"""

Expand All @@ -29,29 +30,27 @@ def __init__(self):
if config.stats:
from util import curses_eol
global eol
eol=curses_eol()

eol = curses_eol()

def consume(self, q):
(data, time, ul, _, freq)=q
(data, time, ul, _, freq) = q
if len(data) < 2:
return

m_type = data[:2].hex()

if m_type !="0605" and m_type != "7605":
if m_type != "0605" and m_type != "7605":
return

if ul:
ul="UL"
ul = "UL"
else:
ul="DL"

ul = "DL"

if m_type == "7605":
if len(data) > 5 and data[2] == 0 and data[3]&0xf0 == 0x40:
type = 'sbd'
pos=xyz(data[3:], 4)
pos = xyz(data[3:], 4)
elif len(data) > 3 and data[3] == 0x50: # ack only
return
else: # no match
Expand All @@ -60,7 +59,7 @@ def consume(self, q):
off = (2+1+20+1+3+3+2+2+2)
if len(data) > off+2 and data[off] == 0x1b:
type = 'gsm'
pos=xyz(data[off+1:], 0)
pos = xyz(data[off+1:], 0)
#lac_o=2+1+20
#if data[lac_o] == 0x04:
# print("lac=",data[lac_o+1:lac_o+3].hex())
Expand All @@ -77,20 +76,19 @@ def consume(self, q):
self.last_output = time
self.mt_pos = [x for x in self.mt_pos if x['ts'] > time - self.exptime]

ofile=config.output
ofile = config.output
if ofile is None:
ofile="mt.json"
temp_file_path="%s.tmp"%(ofile)
ofile = "mt.json"
temp_file_path = "%s.tmp" % (ofile)
with open(temp_file_path, "w") as f:
print(json.dumps({"time": int(time), "interval": self.intvl, "mt_pos": self.mt_pos}, separators=(',', ':')), file=f)
os.rename(temp_file_path, ofile)
if config.stats:
sts=dt.epoch(int(time))
mts=len(self.mt_pos)
print("%s: %d MTs"%(sts,mts), end=eol, file=sys.stderr)

sts = dt.epoch(int(time))
mts = len(self.mt_pos)
print("%s: %d MTs" % (sts, mts), end=eol, file=sys.stderr)


modes=[
["live-mt-map", ReassembleIDAMap, ],
modes = [
["live-mt-map", ReassembleIDAMap, ],
]

0 comments on commit 4a67ad3

Please sign in to comment.