Gain Adjustment

Happy to do so, but be warned, this will mess up your local collectd stats. Depending on the timing between when collectd samples and the gain levels switching you’ll likely see some strange results. However, the overall average won’t change much and you’ll keep feeding data to FA. The constant rebooting of dump1090 will also break MLAT for the duration of the test. It’s a fairly crude hack of BartJr’s code that rewrites the dump1090-mutability config file with a different gain and then restarts dump1090. Please don’t use this unless you are prepared to deal with all that. No warranty is implied or should be inferred, if it breaks you get to keep both pieces! :open_mouth:

PS - If someone knows a cleaner way of restarting dump1090 with a different gain, then please post it.


#!/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())


2 Likes