Tweaks

At the time I made the thread “TWEAKS”, it was old format of forum which did not allow posting of scripts. As a result I had to copy scripts to Microsoft Word files (.docx) and uploaded to Dropbox, and gave links to these files.

Later, I came to know .docx format gives problem if opened by any software other than Microsoft Word. I prepared these files in plain text and wanted to change links of dropbox from .docx files to .txt files, but by that time forum formate was changed to new “Discourse”, which did not allow editing of old posts.

Since the new forum format allows posting of code, I am posting below codes from all the .docx files here:

.

There are 4 Scripts below.
Their names describe the installation they will work with.
Select the one which applies to your installation, and copy paste that script to newly created blank file optimize-gain.py

(1) Optimize Gain Script for: Piaware SD Card-Image

#!/usr/bin/python2
import time, socket, subprocess, fileinput, os

measure_duration = 62  #duration of each pass, seconds
ntests = 5  #number of tests
gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6".split()
#gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()

gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}] #msgs, positions, aircraft

   for line in fileinput.input('/boot/piaware-config.txt', inplace=1):
      if line.startswith('rtlsdr-gain'):
         print 'rtlsdr-gain '+g
      else:
         print line,

   os.system("sudo systemctl restart dump1090-fa")
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',30003))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
      results[g][2][hex] = 1

print "\n===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())

.

(2) Optimize Gain Script for: dump1090-fa on Raspbian

#!/usr/bin/python2
import time, socket, subprocess, fileinput, os

measure_duration = 62  #duration of one pass, seconds
ntests = 5   #number of tests
gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6".split()
#gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()

gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}] #msgs, positions, aircraft

   for line in fileinput.input('/etc/default/dump1090-fa', inplace=1):
      if line.startswith('RECEIVER_OPTIONS'):
         print 'RECEIVER_OPTIONS="--device-index 0  --ppm 0 --gain  ' + g + ' --net-bo-port 30005 --net-sbs-port 30003"'
      else:
         print line,
   os.system("sudo systemctl restart dump1090-fa")
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',30003))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
      results[g][2][hex] = 1

print "\n===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())


.

(3) Optimize Gain Script for: dump1090-mutability on Raspbian

#!/usr/bin/python2
import time, socket, subprocess, fileinput, os

measure_duration = 62  #duration of each pass, seconds
ntests = 5   #number of tests
gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()
#gains = "22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests 
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}] #msgs, positions, aircraft

   for line in fileinput.input('/etc/default/dump1090-mutability', inplace=1):
      if line.startswith('GAIN'):
         print 'GAIN='+g
      else:
         print line,
   os.system("sudo systemctl restart dump1090-mutability")
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',30003))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
      results[g][2][hex] = 1

print "\n===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())


.

(4) Optimize Gain Script for: dump1090 (Malcolm-Robb) on Raspbian

#!/usr/bin/python2
import time, socket, subprocess

measure_duration = 15 #seconds
ntests = 10  #Number of tests
mutability = False    #set to True if you use dump1090-mutability
#gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6".split()
gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()
#gains = "22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests 
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}] #msgs, positions, aircraft
   if mutability:
       p = subprocess.Popen(('/usr/bin/dump1090-mutability --net --gain '+g+' --oversample --fix --phase-enhance --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   else:
       p = subprocess.Popen(('/usr/bin/dump1090 --net --gain '+g+' --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',30003))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   p.terminate()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
      results[g][2][hex] = 1

print "\n===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())

3 Likes