added adaptive frequncy limit for OGN
This commit is contained in:
parent
2d20e0a632
commit
d35a019027
|
|
@ -78,6 +78,7 @@ class TrackDirectDataCollector():
|
||||||
connection = AprsISConnection(
|
connection = AprsISConnection(
|
||||||
self.callsign, self.passcode, self.sourceHostname, self.sourcePort)
|
self.callsign, self.passcode, self.sourceHostname, self.sourcePort)
|
||||||
connection.setFrequencyLimit(self.hardFrequencyLimit)
|
connection.setFrequencyLimit(self.hardFrequencyLimit)
|
||||||
|
connection.setSourceId(self.sourceId)
|
||||||
|
|
||||||
def onPacketRead(line):
|
def onPacketRead(line):
|
||||||
if (not reactor.running):
|
if (not reactor.running):
|
||||||
|
|
@ -246,7 +247,14 @@ class TrackDirectDataCollector():
|
||||||
Boolean
|
Boolean
|
||||||
"""
|
"""
|
||||||
if (packet.mapId in [1, 5, 7, 9] and packet.isMoving == 1):
|
if (packet.mapId in [1, 5, 7, 9] and packet.isMoving == 1):
|
||||||
if (packet.timestamp - int(self.frequencyLimit) < packet.markerPrevPacketTimestamp):
|
frequencyLimitToApply = int(self.frequencyLimit)
|
||||||
|
|
||||||
|
if (packet.ogn is not None and packet.ogn.ognTurnRate is not None):
|
||||||
|
turnRate = abs(float(packet.ogn.ognTurnRate))
|
||||||
|
if (turnRate > 0) :
|
||||||
|
frequencyLimitToApply = int(frequencyLimitToApply / (1+turnRate))
|
||||||
|
|
||||||
|
if ((packet.timestamp - frequencyLimitToApply) < packet.markerPrevPacketTimestamp):
|
||||||
# This station is sending faster than config limit
|
# This station is sending faster than config limit
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import collections
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class AprsISConnection(aprslib.IS):
|
class AprsISConnection(aprslib.IS):
|
||||||
|
|
@ -25,6 +26,7 @@ class AprsISConnection(aprslib.IS):
|
||||||
self.logger = logging.getLogger("aprslib.IS")
|
self.logger = logging.getLogger("aprslib.IS")
|
||||||
self.frequencyLimit = None
|
self.frequencyLimit = None
|
||||||
self.stationHashTimestamps = {}
|
self.stationHashTimestamps = {}
|
||||||
|
self.sourceId = 1
|
||||||
|
|
||||||
def setFrequencyLimit(self, frequencyLimit):
|
def setFrequencyLimit(self, frequencyLimit):
|
||||||
"""Set frequency limit
|
"""Set frequency limit
|
||||||
|
|
@ -42,6 +44,14 @@ class AprsISConnection(aprslib.IS):
|
||||||
"""
|
"""
|
||||||
return self.frequencyLimit
|
return self.frequencyLimit
|
||||||
|
|
||||||
|
def setSourceId(self, sourceId):
|
||||||
|
"""Set what source packet is from (APRS, CWOP ...)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sourceId (int): Id that corresponds to id in source-table
|
||||||
|
"""
|
||||||
|
self.sourceId = sourceId
|
||||||
|
|
||||||
def filteredConsumer(self, callback, blocking=True, raw=False):
|
def filteredConsumer(self, callback, blocking=True, raw=False):
|
||||||
"""The filtered consume method
|
"""The filtered consume method
|
||||||
|
|
||||||
|
|
@ -86,11 +96,22 @@ class AprsISConnection(aprslib.IS):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Try to find turn rate and reduce frequency limit if high turn rate
|
||||||
|
frequencyLimitToApply = int(self.frequencyLimit)
|
||||||
|
if (self.sourceId == 5) :
|
||||||
|
match = re.search("(\+|\-)(\d\.\d)rot ", line)
|
||||||
|
try:
|
||||||
|
turnRate = abs(float(match.group(2)))
|
||||||
|
if (turnRate > 0) :
|
||||||
|
frequencyLimitToApply = int(frequencyLimitToApply / (1+turnRate))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
latestTimestampOnMap = 0
|
latestTimestampOnMap = 0
|
||||||
if (name in self.stationHashTimestamps):
|
if (name in self.stationHashTimestamps):
|
||||||
latestTimestampOnMap = self.stationHashTimestamps[name]
|
latestTimestampOnMap = self.stationHashTimestamps[name]
|
||||||
|
|
||||||
if ((int(time.time()) - 1) - int(self.frequencyLimit) < latestTimestampOnMap):
|
if (((int(time.time()) - 1) - frequencyLimitToApply) < latestTimestampOnMap):
|
||||||
# This sender is sending faster than config limit
|
# This sender is sending faster than config limit
|
||||||
return True
|
return True
|
||||||
self.stationHashTimestamps[name] = int(time.time()) - 1
|
self.stationHashTimestamps[name] = int(time.time()) - 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue