Commit ea94b0f9 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Renamed Aprs to AprsKiss.

parent e0a03510
......@@ -22,7 +22,7 @@ from __future__ import print_function
import logging
from .aprs import Aprs # noqa: F401
from .aprs_kiss import AprsKiss # noqa: F401
from .igate import IGate # noqa: F401
__author__ = 'Jeffrey Phillips Freeman (WI2ARD)'
......
......@@ -21,7 +21,7 @@ __copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors'
__credits__ = []
class Aprs(object):
class AprsKiss(object):
"""APRS interface."""
......@@ -53,9 +53,9 @@ class Aprs(object):
if 1 < i < 11:
if raw_frame[raw_slice + 1] & 0x03 is 0x03 and raw_frame[raw_slice + 2] in [0xf0, 0xcf]:
frame['text'] = ''.join(map(chr, raw_frame[raw_slice + 3:]))
frame['destination'] = Aprs.__identity_as_string(Aprs.__extract_callsign(raw_frame))
frame['source'] = Aprs.__identity_as_string(Aprs.__extract_callsign(raw_frame[7:]))
frame['path'] = Aprs.__extract_path(int(i), raw_frame)
frame['destination'] = AprsKiss.__identity_as_string(AprsKiss.__extract_callsign(raw_frame))
frame['source'] = AprsKiss.__identity_as_string(AprsKiss.__extract_callsign(raw_frame[7:]))
frame['path'] = AprsKiss.__extract_path(int(i), raw_frame)
return frame
logging.debug('frame=%s', frame)
......@@ -74,7 +74,7 @@ class Aprs(object):
full_path = []
for i in range(2, start):
path = Aprs.__identity_as_string(Aprs.__extract_callsign(raw_frame[i * 7:]))
path = AprsKiss.__identity_as_string(AprsKiss.__extract_callsign(raw_frame[i * 7:]))
if path:
if raw_frame[i * 7 + 6] & 0x80:
full_path.append(''.join([path, '*']))
......@@ -122,12 +122,13 @@ class Aprs(object):
:return: KISS-encoded APRS frame.
:rtype: list
"""
enc_frame = Aprs.__encode_callsign(Aprs.__parse_identity_string(frame['destination'])) + \
Aprs.__encode_callsign(Aprs.__parse_identity_string(frame['source']))
enc_frame = AprsKiss.__encode_callsign(AprsKiss.__parse_identity_string(frame['destination'])) + \
AprsKiss.__encode_callsign(AprsKiss.__parse_identity_string(frame['source']))
for p in frame['path']:
enc_frame += Aprs.__encode_callsign(Aprs.__parse_identity_string(p))
enc_frame += AprsKiss.__encode_callsign(AprsKiss.__parse_identity_string(p))
return enc_frame[:-1] + [enc_frame[-1] | 0x01] + [apex.kiss.constants.SLOT_TIME] + [0xf0] + [ord(c) for c in frame['text']]
return enc_frame[:-1] + [enc_frame[-1] | 0x01] + [apex.kiss.constants.SLOT_TIME] + [0xf0]\
+ [ord(c) for c in frame['text']]
@staticmethod
def __encode_callsign(callsign):
......@@ -191,7 +192,7 @@ class Aprs(object):
:type frame: dict
"""
with self.lock:
encoded_frame = Aprs.__encode_frame(frame)
encoded_frame = AprsKiss.__encode_frame(frame)
self.data_stream.write(encoded_frame, *args, **kwargs)
def read(self, *args, **kwargs):
......@@ -200,6 +201,6 @@ class Aprs(object):
with self.lock:
frame = self.data_stream.read(*args, **kwargs)
if frame is not None and len(frame):
return Aprs.__decode_frame(frame)
return AprsKiss.__decode_frame(frame)
else:
return None
......@@ -131,11 +131,11 @@ def configure(configfile, verbose=False):
if config.has_option(section, 'com_port') and config.has_option(section, 'baud'):
com_port = config.get(section, 'com_port')
baud = config.get(section, 'baud')
kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.Aprs(apex.kiss.KissSerial(com_port=com_port, baud=baud)))
kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.AprsKiss(apex.kiss.KissSerial(com_port=com_port, baud=baud)))
elif config.has_option(section, 'tcp_host') and config.has_option(section, 'tcp_port'):
tcp_host = config.get(section, 'tcp_host')
tcp_port = config.get(section, 'tcp_port')
kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.Aprs(apex.kiss.KissTcp(host=tcp_host, tcp_port=tcp_port)))
kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.AprsKiss(apex.kiss.KissTcp(host=tcp_host, tcp_port=tcp_port)))
else:
echo_colorized_error("""Invalid configuration, must have both com_port and baud set or tcp_host and
tcp_port set in TNC sections of configuration file""")
......
......@@ -81,7 +81,7 @@ class AprsTest(unittest.TestCase): # pylint: disable=R0904
"""
Tests encoding a callsign.
"""
encoded_callsign = apex.aprs.Aprs._Aprs__encode_callsign(DECODED_CALLSIGN)
encoded_callsign = apex.aprs.AprsKiss._AprsKiss__encode_callsign(DECODED_CALLSIGN)
self.assertEqual(ENCODED_CALLSIGN, encoded_callsign)
def test_encode_callsign_digipeated(self):
......@@ -89,70 +89,70 @@ class AprsTest(unittest.TestCase): # pylint: disable=R0904
Tests encoding a digipeated callsign with
`aprs.util.encode_callsign()`.
"""
encoded_callsign = apex.aprs.Aprs._Aprs__encode_callsign(DECODED_CALLSIGN_DIGIPEATED)
encoded_callsign = apex.aprs.AprsKiss._AprsKiss__encode_callsign(DECODED_CALLSIGN_DIGIPEATED)
self.assertEqual(ENCODED_CALLSIGN_DIGIPEATED, encoded_callsign)
def test_decode_callsign(self):
"""
Tests extracting the callsign from a KISS-encoded APRS frame.
"""
decoded_callsign = apex.aprs.Aprs._Aprs__extract_callsign(ENCODED_CALLSIGN)
decoded_callsign = apex.aprs.AprsKiss._AprsKiss__extract_callsign(ENCODED_CALLSIGN)
self.assertEqual(DECODED_CALLSIGN, decoded_callsign)
def test_decode_callsign_digipeated(self):
"""
Tests extracting the callsign from a KISS-encoded APRS frame.
"""
decoded_callsign = apex.aprs.Aprs._Aprs__extract_callsign(ENCODED_CALLSIGN_DIGIPEATED)
decoded_callsign = apex.aprs.AprsKiss._AprsKiss__extract_callsign(ENCODED_CALLSIGN_DIGIPEATED)
self.assertEqual(DECODED_CALLSIGN, decoded_callsign)
def test_encode_frame(self):
"""
Tests KISS-encoding an APRS.
"""
encoded_frame = apex.aprs.Aprs._Aprs__encode_frame(DECODED_FRAME)
encoded_frame = apex.aprs.AprsKiss._AprsKiss__encode_frame(DECODED_FRAME)
self.assertEqual(ENCODED_FRAME, encoded_frame)
def test_encode_frame_recorded(self):
"""
Tests encoding a KISS-encoded APRS.
"""
encoded_frame = apex.aprs.Aprs._Aprs__encode_frame(DECODED_FRAME_RECORDED)
encoded_frame = apex.aprs.AprsKiss._AprsKiss__encode_frame(DECODED_FRAME_RECORDED)
self.assertEqual(ENCODED_FRAME_RECORDED, encoded_frame)
def test_encode_frame_multipath(self):
"""
Tests encoding a KISS-encoded APRS.
"""
encoded_frame = apex.aprs.Aprs._Aprs__encode_frame(DECODED_FRAME_MULTIPATH)
encoded_frame = apex.aprs.AprsKiss._AprsKiss__encode_frame(DECODED_FRAME_MULTIPATH)
self.assertEqual(ENCODED_FRAME_MULTIPATH, encoded_frame)
def test_decode_frame(self):
"""
Tests KISS-encoding an APRS
"""
decoded_frame = apex.aprs.Aprs._Aprs__decode_frame(ENCODED_FRAME)
decoded_frame = apex.aprs.AprsKiss._AprsKiss__decode_frame(ENCODED_FRAME)
self.assertEqual(DECODED_FRAME, decoded_frame)
def test_decode_frame_recorded(self):
"""
Tests decoding a KISS-encoded APRS frame
"""
decoded_frame = apex.aprs.Aprs._Aprs__decode_frame(ENCODED_FRAME_RECORDED)
decoded_frame = apex.aprs.AprsKiss._AprsKiss__decode_frame(ENCODED_FRAME_RECORDED)
self.assertEqual(DECODED_FRAME_RECORDED, decoded_frame)
def test_decode_frame_multipath(self):
"""
Tests decoding a KISS-encoded APRS frame
"""
decoded_frame = apex.aprs.Aprs._Aprs__decode_frame(ENCODED_FRAME_MULTIPATH)
decoded_frame = apex.aprs.AprsKiss._AprsKiss__decode_frame(ENCODED_FRAME_MULTIPATH)
self.assertEqual(DECODED_FRAME_MULTIPATH, decoded_frame)
def test_extract_path(self):
"""
Tests extracting the APRS path from a KISS-encoded.
"""
extracted_path = apex.aprs.Aprs._Aprs__extract_path(3, ENCODED_FRAME)
extracted_path = apex.aprs.AprsKiss._AprsKiss__extract_path(3, ENCODED_FRAME)
self.assertEqual(DECODED_FRAME['path'][0], extracted_path[0])
def test_idwentity_as_string_with_ssid(self):
......@@ -164,7 +164,7 @@ class AprsTest(unittest.TestCase): # pylint: disable=R0904
'callsign': 'W2GMD',
'ssid': 1
}
full_callsign = apex.aprs.Aprs._Aprs__identity_as_string(callsign)
full_callsign = apex.aprs.AprsKiss._AprsKiss__identity_as_string(callsign)
self.assertEqual(full_callsign, 'W2GMD-1')
def test_identity_as_string_sans_ssid(self):
......@@ -176,7 +176,7 @@ class AprsTest(unittest.TestCase): # pylint: disable=R0904
'callsign': 'W2GMD',
'ssid': 0
}
full_callsign = apex.aprs.Aprs._Aprs__identity_as_string(callsign)
full_callsign = apex.aprs.AprsKiss._AprsKiss__identity_as_string(callsign)
self.assertEqual(full_callsign, 'W2GMD')
if six.PY2:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment