mirror of https://github.com/craigerl/aprsd.git
Fixed issue with PacketList being empty
This commit is contained in:
parent
a656d93263
commit
7541f13174
|
@ -25,12 +25,15 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super().__new__(cls)
|
cls._instance = super().__new__(cls)
|
||||||
cls._instance.maxlen = CONF.packet_list_maxlen
|
cls._instance.maxlen = CONF.packet_list_maxlen
|
||||||
cls._instance.data = {
|
cls._instance._init_data()
|
||||||
"types": {},
|
|
||||||
"packets": OrderedDict(),
|
|
||||||
}
|
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
|
def _init_data(self):
|
||||||
|
self.data = {
|
||||||
|
"types": {},
|
||||||
|
"packets": OrderedDict(),
|
||||||
|
}
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def rx(self, packet: type[core.Packet]):
|
def rx(self, packet: type[core.Packet]):
|
||||||
"""Add a packet that was received."""
|
"""Add a packet that was received."""
|
||||||
|
@ -56,6 +59,8 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
self._add(packet)
|
self._add(packet)
|
||||||
|
|
||||||
def _add(self, packet):
|
def _add(self, packet):
|
||||||
|
if not self.data.get("packets"):
|
||||||
|
self._init_data()
|
||||||
if packet.key in self.data["packets"]:
|
if packet.key in self.data["packets"]:
|
||||||
self.data["packets"].move_to_end(packet.key)
|
self.data["packets"].move_to_end(packet.key)
|
||||||
elif len(self.data["packets"]) == self.maxlen:
|
elif len(self.data["packets"]) == self.maxlen:
|
||||||
|
@ -85,7 +90,13 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def stats(self, serializable=False) -> dict:
|
def stats(self, serializable=False) -> dict:
|
||||||
# limit the number of packets to return to 50
|
# limit the number of packets to return to 50
|
||||||
tmp = OrderedDict(reversed(list(self.data.get("packets", []).items())))
|
tmp = OrderedDict(
|
||||||
|
reversed(
|
||||||
|
list(
|
||||||
|
self.data.get("packets", OrderedDict()).items(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
pkts = []
|
pkts = []
|
||||||
count = 1
|
count = 1
|
||||||
for packet in tmp:
|
for packet in tmp:
|
||||||
|
@ -98,8 +109,8 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||||
"total_tracked": self._total_rx + self._total_rx,
|
"total_tracked": self._total_rx + self._total_rx,
|
||||||
"rx": self._total_rx,
|
"rx": self._total_rx,
|
||||||
"tx": self._total_tx,
|
"tx": self._total_tx,
|
||||||
"types": self.data["types"],
|
"types": self.data.get("types", []),
|
||||||
"packet_count": len(self.data["packets"]),
|
"packet_count": len(self.data.get("packets", [])),
|
||||||
"maxlen": self.maxlen,
|
"maxlen": self.maxlen,
|
||||||
"packets": pkts,
|
"packets": pkts,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue