Metadata-Version: 2.4
Name: kiss3
Version: 8.1.1
Summary: A pure-Python implementation of serial KISS and KISS-over-TCP protocols for communicating with TNC devices
Author-email: Masen Furer KF7HVM <kf7hvm@0x26.net>, Greg Albrecht W2GMD <oss@undef.net>
License: Copyright 2017 Greg Albrecht and Contributors
        
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
            http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
        
Project-URL: Homepage, https://github.com/python-aprs/kiss3
Keywords: Ham Radio,APRS,KISS
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Topic :: Communications :: Ham Radio
Classifier: Framework :: AsyncIO
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.11
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: attrs>20
Requires-Dist: ax253>=0.2.1
Requires-Dist: pyserial-asyncio>=0.6
Dynamic: license-file

kiss3 - Python KISS Module
**************************

.. image:: https://github.com/python-aprs/kiss3/actions/workflows/pytest.yml/badge.svg
    :target: https://github.com/python-aprs/kiss3/actions

kiss3 talks `KISS <https://en.wikipedia.org/wiki/KISS_(TNC)>`_ to TNCs
over serial ports and TCP (Dire Wolf, hardware TNCs, Bluetooth TNCs), with
plain blocking calls or asyncio. It frames and unframes AX.25 data and sends
TNC parameters. It needs Python 3.11 or newer.

Install it from PyPI::

    pip install kiss3

For APRS decoding on top of KISS, use `aprs3 <https://github.com/python-aprs/aprs3>`_.

Sending and receiving
=====================

``TCPKISS`` and ``SerialKISS`` block. ``start()`` connects and writes any
TNC parameters you pass, ``write()`` returns once the frame has gone out,
and ``read()`` waits for frames:

.. code-block:: python

    from ax253 import Frame

    import kiss

    tnc = kiss.TCPKISS("localhost", 8001, strip_df_start=True)  # Dire Wolf
    # or: kiss.SerialKISS("/dev/ttyUSB0", 9600, strip_df_start=True)
    tnc.start(TX_DELAY=40)
    try:
        tnc.write(Frame.from_str("N0CALL>APRS,WIDE1-1:>on the air"))
        for raw in tnc.read(min_frames=1):
            print(Frame.from_bytes(raw))
    finally:
        tnc.stop()

``strip_df_start=True`` removes the KISS command byte and drops frames that
aren't data. Without it, each frame still starts with the command byte
(``0x00`` for data on port 0) and ``Frame.from_bytes()`` fails with an error
like ``b'\x00VE3YC' does not match ...``.

With asyncio, ``create_tcp_connection`` and ``create_serial_connection``
return a ``KISSProtocol`` whose ``read()`` yields ``ax253.Frame`` objects:

.. code-block:: python

    import asyncio

    import kiss


    async def main():
        transport, protocol = await kiss.create_tcp_connection("localhost", 8001)
        async for frame in protocol.read():
            print(frame)


    asyncio.run(main())

Decoding a byte stream
======================

If you read the bytes yourself, the decoders turn them into frames as they
arrive:

>>> from ax253 import Frame
>>> import kiss
>>> stream = b"\xc0\x00" + bytes(Frame.from_str("N0CALL>APRS:>hi")) + b"\xc0"
>>> decoder = kiss.AX25KISSDecode()
>>> list(decoder.update(stream[:10]))
[]
>>> [str(frame) for frame in decoder.update(stream[10:])]
['N0CALL>APRS:>hi']

Detecting a lost connection
===========================

``read(min_frames=None)`` blocks until the connection closes, then returns
the frames that were left. Check ``connected`` to tell a closed connection
from a quiet one, and call ``stop()`` and ``start()`` to reconnect:

.. code-block:: python

    while True:
        tnc.read(callback=print, min_frames=None)
        if not tnc.connected:
            tnc.stop()
            tnc.start()

A TCP peer that disappears without closing the connection (network cable
pulled, host crashed) is only noticed when a write fails or the operating
system's TCP keepalive gives up.

Examples
========

The `examples <./examples>`_ directory has two scripts that work with any
KISS TNC, given ``--tcp host:port`` or ``--serial device``:

* ``kiss_monitor.py`` prints every frame the TNC hears.
* ``kiss_send.py`` sends frames given in TNC2 text, and can set TNC
  parameters like ``--set TX_DELAY=40``.

Versions
========

8.x is published by python-aprs as ``kiss3``. Earlier versions were released
by Greg Albrecht as ``kiss``.

Testing
=======

Run the tests with `uv <https://docs.astral.sh/uv/>`_::

    uv run pytest

Related projects
================

* `ax253 <https://github.com/python-aprs/ax253>`_, the AX.25 frames this
  package carries.
* `aprs3 <https://github.com/python-aprs/aprs3>`_, APRS encoding and decoding
  over KISS and APRS-IS.
* `Dire Wolf <https://github.com/wb2osz/direwolf>`_ by WB2OSZ, a sound card
  TNC with a KISS interface.

Source
======
GitHub: https://github.com/python-aprs/kiss3

Authors
=======
Greg Albrecht W2GMD oss@undef.net

http://ampledata.org/

Masen Furer KF7HVM kf7hvm@0x26.net

Copyright
=========
Copyright 2022 Masen Furer and Contributors

Copyright 2017 Greg Albrecht and Contributors

`Automatic Packet Reporting System (APRS) <http://www.aprs.org/>`_ is Copyright Bob Bruninga WB4APR wb4apr@amsat.org

License
=======
Apache License, Version 2.0. See LICENSE for details.
