Piaware 3 and Pro Stick Gain

Use the method below. This code was originally written by BartJr and improved by lignumaqua

Please see following thread for details:
Gain Adjustment…

(1) Give following command to create a blank file “optimize-gain.py”
Note: it is not necessary to name the file optimize-gain.py. You can use any name of your choice, but it must have .py at the end


sudo nano optimize-gain.py

(2) Copy-paste the script code below in the blank file created above, save the file (ctrl+o), and exit (ctrl+x)

(3) Make the file executable:


sudo chmod +x optimize-gain.py

(3) Run the script:


sudo ./optimize-gain.py

(4) The results are displayed in the SSH terminal progressively as these are conducted.
The totals of the test are displayed in the terminal at the end of test.
You can copy everything from terminal and paste into a text file & save the text file.

This is the code to be copy-pasted in the blank file “optimize-gain.py”



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

measure_duration = 62 #seconds
ntests = 10
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 /etc/init.d/dump1090-mutability restart")
   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('
'):
      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 "
===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())


1 Like