mirror of https://github.com/craigerl/aprsd.git
Compare commits
2 Commits
717db6083e
...
813bc7ea29
Author | SHA1 | Date |
---|---|---|
Hemna | 813bc7ea29 | |
Hemna | bef32059f4 |
|
@ -105,6 +105,11 @@ aprsd_opts = [
|
|||
"'multiline' will use multiple lines for each packet and is the traditional format."
|
||||
"both will log both compact and multiline.",
|
||||
),
|
||||
cfg.IntOpt(
|
||||
"default_packet_send_count",
|
||||
default=3,
|
||||
help="The number of times to send a non ack packet before giving up.",
|
||||
),
|
||||
cfg.IntOpt(
|
||||
"default_ack_send_count",
|
||||
default=3,
|
||||
|
|
|
@ -22,15 +22,22 @@ def log_multiline(packet, tx: Optional[bool] = False, header: Optional[bool] = T
|
|||
"""LOG a packet to the logfile."""
|
||||
if CONF.log_packet_format == "compact":
|
||||
return
|
||||
|
||||
# asdict(packet)
|
||||
logit = ["\n"]
|
||||
name = packet.__class__.__name__
|
||||
|
||||
if isinstance(packet, AckPacket):
|
||||
pkt_max_send_count = CONF.default_ack_send_count
|
||||
else:
|
||||
pkt_max_send_count = CONF.default_packet_send_count
|
||||
|
||||
if header:
|
||||
if tx:
|
||||
header_str = f"<{TX_COLOR}>TX</{TX_COLOR}>"
|
||||
logit.append(
|
||||
f"{header_str}________(<{PACKET_COLOR}>{name}</{PACKET_COLOR}> "
|
||||
f"TX:{packet.send_count + 1} of {packet.retry_count})",
|
||||
f"TX:{packet.send_count + 1} of {pkt_max_send_count}",
|
||||
)
|
||||
else:
|
||||
header_str = f"<{RX_COLOR}>RX</{RX_COLOR}>"
|
||||
|
@ -78,6 +85,10 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
|||
|
||||
logit = []
|
||||
name = packet.__class__.__name__
|
||||
if isinstance(packet, AckPacket):
|
||||
pkt_max_send_count = CONF.default_ack_send_count
|
||||
else:
|
||||
pkt_max_send_count = CONF.default_packet_send_count
|
||||
|
||||
if header:
|
||||
if tx:
|
||||
|
@ -87,7 +98,7 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
|
|||
f"<red>TX {arrow}</red> "
|
||||
f"<cyan>{name}</cyan>"
|
||||
f":{packet.msgNo}"
|
||||
f" ({packet.send_count + 1} of {packet.retry_count})",
|
||||
f" ({packet.send_count + 1} of {pkt_max_send_count})",
|
||||
)
|
||||
else:
|
||||
via_color = "fg #828282"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from oslo_config import cfg
|
||||
|
@ -9,6 +10,7 @@ from aprsd.utils import objectstore
|
|||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
class PacketTrack(objectstore.ObjectStoreMixin):
|
||||
|
@ -100,7 +102,7 @@ class PacketTrack(objectstore.ObjectStoreMixin):
|
|||
|
||||
@wrapt.synchronized(lock)
|
||||
def get(self, key):
|
||||
return self.data.get(key, None)
|
||||
return self.data.get(key)
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def remove(self, key):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
@ -6,6 +7,7 @@ from rush import quota, throttle
|
|||
from rush.contrib import decorator
|
||||
from rush.limiters import periodic
|
||||
from rush.stores import dictionary
|
||||
import wrapt
|
||||
|
||||
from aprsd import client
|
||||
from aprsd import conf # noqa
|
||||
|
@ -37,15 +39,19 @@ ack_t = throttle.Throttle(
|
|||
|
||||
msg_throttle_decorator = decorator.ThrottleDecorator(throttle=msg_t)
|
||||
ack_throttle_decorator = decorator.ThrottleDecorator(throttle=ack_t)
|
||||
s_lock = threading.Lock()
|
||||
|
||||
|
||||
@wrapt.synchronized(s_lock)
|
||||
@msg_throttle_decorator.sleep_and_retry
|
||||
def send(packet: core.Packet, direct=False, aprs_client=None):
|
||||
"""Send a packet either in a thread or directly to the client."""
|
||||
# prepare the packet for sending.
|
||||
# This constructs the packet.raw
|
||||
collector.PacketCollector().tx(packet)
|
||||
packet.prepare()
|
||||
# Have to call the collector to track the packet
|
||||
# After prepare, as prepare assigns the msgNo
|
||||
collector.PacketCollector().tx(packet)
|
||||
if isinstance(packet, core.AckPacket):
|
||||
_send_ack(packet, direct=direct, aprs_client=aprs_client)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue