Skip to content

Commit

Permalink
python3 -m black -l 78 clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlongland committed May 4, 2024
1 parent 7ba517b commit 0b23433
Show file tree
Hide file tree
Showing 46 changed files with 3,829 additions and 3,078 deletions.
10 changes: 5 additions & 5 deletions aioax25/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

__author__ = 'Stuart Longland VK4MSL'
__email__ = '[email protected]'
__license__ = 'GPL-2.0-or-later'
__copyright__ = 'Copyright 2021, Stuart Longland (and contributors)'
__version__ = '0.0.12'
__author__ = "Stuart Longland VK4MSL"
__email__ = "[email protected]"
__license__ = "GPL-2.0-or-later"
__copyright__ = "Copyright 2021, Stuart Longland (and contributors)"
__version__ = "0.0.12"
251 changes: 144 additions & 107 deletions aioax25/aprs/aprs.py

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions aioax25/aprs/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ def compress(value, length):

# Figure out the bytes
for pos in range(length):
(div, rem) = divmod(
value,
BYTE_VALUE_RADIX ** (length - pos - 1)
)
(div, rem) = divmod(value, BYTE_VALUE_RADIX ** (length - pos - 1))
bvalue[pos] += int(div)
value = rem

# Encode them into ASCII
return ''.join([chr(b + BYTE_VALUE_OFFSET) for b in bvalue])
return "".join([chr(b + BYTE_VALUE_OFFSET) for b in bvalue])


def decompress(value):
length = len(value)
return sum([
(
(b - BYTE_VALUE_OFFSET)
* (BYTE_VALUE_RADIX ** (length - i - 1))
)
return sum(
[
((b - BYTE_VALUE_OFFSET) * (BYTE_VALUE_RADIX ** (length - i - 1)))
for (i, b) in enumerate(bytes(value, "us-ascii"))
])
]
)
52 changes: 27 additions & 25 deletions aioax25/aprs/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@

from enum import Enum


class APRSDataType(Enum):
"""
APRS message types, given as the first byte in the information field,
not including unused or reserved types. Page 17 of APRS 1.0.1 spec.
"""
MIC_E_BETA0 = 0x1c
MIC_E_OLD_BETA0 = 0x1d
POSITION = ord('!')
PEET_BROS_WX1 = ord('#')
RAW_GPRS_ULT2K = ord('$')
AGRELO_DFJR = ord('%')
RESERVED_MAP = ord('&')
MIC_E_OLD = ord("'")
ITEM = ord(')')
PEET_BROS_WX2 = ord('*')
TEST_DATA = ord(',')
POSITION_TS = ord('/')
MESSAGE = ord(':')
OBJECT = ord(';')
STATIONCAP = ord('<')
POSITION_MSGCAP = ord('=')
STATUS = ord('>')
QUERY = ord('?')
POSITION_TS_MSGCAP = ord('@')
TELEMETRY = ord('T')
MAIDENHEAD = ord('[')
WX = ord('_')
MIC_E = ord('`')
USER_DEFINED = ord('{')
THIRD_PARTY = ord('}')

MIC_E_BETA0 = 0x1C
MIC_E_OLD_BETA0 = 0x1D
POSITION = ord("!")
PEET_BROS_WX1 = ord("#")
RAW_GPRS_ULT2K = ord("$")
AGRELO_DFJR = ord("%")
RESERVED_MAP = ord("&")
MIC_E_OLD = ord("'")
ITEM = ord(")")
PEET_BROS_WX2 = ord("*")
TEST_DATA = ord(",")
POSITION_TS = ord("/")
MESSAGE = ord(":")
OBJECT = ord(";")
STATIONCAP = ord("<")
POSITION_MSGCAP = ord("=")
STATUS = ord(">")
QUERY = ord("?")
POSITION_TS_MSGCAP = ord("@")
TELEMETRY = ord("T")
MAIDENHEAD = ord("[")
WX = ord("_")
MIC_E = ord("`")
USER_DEFINED = ord("{")
THIRD_PARTY = ord("}")
29 changes: 21 additions & 8 deletions aioax25/aprs/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class APRSTimestamp(object):
"""
Base abstract class for APRS timestamps.
"""

pass


class DHMBaseTimestamp(APRSTimestamp):
"""
Day/Hour/Minute timestamp (base class)
"""

TS_LENGTH = 7

def __init__(self, day, hour, minute):
Expand All @@ -26,44 +28,52 @@ def __init__(self, day, hour, minute):
self.minute = minute

def __str__(self):
return '%02d%02d%02d%s' % (
self.day, self.hour, self.minute,
self.TS_SUFFIX
return "%02d%02d%02d%s" % (
self.day,
self.hour,
self.minute,
self.TS_SUFFIX,
)


class DHMUTCTimestamp(DHMBaseTimestamp):
"""
Day/Hour/Minute timestamp in UTC.
"""

TS_SUFFIX = "z"


class DHMLocalTimestamp(DHMBaseTimestamp):
"""
Day/Hour/Minute timestamp in local time.
"""

TS_SUFFIX = "/"


class HMSTimestamp(time, APRSTimestamp):
"""
Hour/Minute/Second timestamp in UTC.
"""

TS_LENGTH = 7
TS_SUFFIX = "h"

def __str__(self):
return '%02d%02d%02d%s' % (
self.hour, self.minute, self.second,
self.TS_SUFFIX
return "%02d%02d%02d%s" % (
self.hour,
self.minute,
self.second,
self.TS_SUFFIX,
)


class MDHMTimestamp(APRSTimestamp):
"""
Month/Day/Hour/Minute timestamp in UTC.
"""

TS_LENGTH = 8

def __init__(self, month, day, hour, minute):
Expand All @@ -73,8 +83,11 @@ def __init__(self, month, day, hour, minute):
self.minute = minute

def __str__(self):
return '%02d%02d%02d%02d' % (
self.month, self.day, self.hour, self.minute
return "%02d%02d%02d%02d" % (
self.month,
self.day,
self.hour,
self.minute,
)


Expand Down
34 changes: 22 additions & 12 deletions aioax25/aprs/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def decode(cls, uiframe, log):
# Do not decode if not the APRS PID value
if uiframe.pid != cls.PID_NO_L3:
# Clearly not an APRS message
log.debug('Frame has wrong PID for APRS')
log.debug("Frame has wrong PID for APRS")
return uiframe

if len(uiframe.payload) == 0:
log.debug('Frame has no payload data')
log.debug("Frame has no payload data")
return uiframe

try:
Expand All @@ -38,21 +38,31 @@ def decode(cls, uiframe, log):
handler_class = cls.DATA_TYPE_HANDLERS[type_code]

# Decode the payload as text
payload = uiframe.payload.decode('US-ASCII')
payload = uiframe.payload.decode("US-ASCII")

return handler_class.decode(uiframe, payload, log)
except:
# Not decodable, leave as-is
log.debug('Failed to decode as APRS', exc_info=1)
log.debug("Failed to decode as APRS", exc_info=1)
return uiframe

def __init__(self, destination, source, payload, repeaters=None,
pf=False, cr=False, src_cr=None
def __init__(
self,
destination,
source,
payload,
repeaters=None,
pf=False,
cr=False,
src_cr=None,
):
super(APRSFrame, self).__init__(
destination=destination,
source=source,
pid=self.PID_NO_L3, # APRS spec
payload=payload,
repeaters=repeaters,
pf=pf, cr=cr, src_cr=src_cr)
destination=destination,
source=source,
pid=self.PID_NO_L3, # APRS spec
payload=payload,
repeaters=repeaters,
pf=pf,
cr=cr,
src_cr=src_cr,
)
Loading

0 comments on commit 0b23433

Please sign in to comment.