Git Product home page Git Product logo

Comments (5)

sjlongland avatar sjlongland commented on May 27, 2024

Okay, so KISS over TCP… that's not something I've tried, although in truth it's definitely something that should be implemented.

I'll have to look at how to achieve this. I don't think using socket directly is the answer, the aim of aioax25 is to use non-blocking I/O where possible and asyncio has native support for doing this with TCP connections, so it'd make better sense to use that.

That said, it should still be possible to use the synchronous socket library directly as you are doing. On Unix-like platforms, there'll be a method there to get the file handle (much like there is on the serial version), and that is what you'll want to pass to the IOLoop's add_reader method, so that it can notify the loop that something is waiting to be read.

In your test script, I note you don't seem to create any sort of IOLoop instance or try to launch any coroutines. I think for something asyncio based, you need to have an IOLoop running or else it will just fall though, doing nothing, which is indeed what you are seeing. aioax25 is an asynchronous library, and thus requires an IOLoop to run to perform its tasks.

This is what I have in my code:

# main.py

def main(): # pragma: no cover
    # Okay, this is for pulling settings from a command line and config file… adapt for your needs
    ap = argparse.ArgumentParser(description='aioax25 example')
    ap.add_argument('config', help='Path to configuration file')

    args = ap.parse_args()

    config = yaml.load(open(args.config, 'r'))

    # Event loop
    loop = asyncio.get_event_loop()

    # Set up logging
    logging.config.dictConfig(config.pop('logging'))
    log = logging.getLogger('rfidterm')

    log.info('Starting up')

    # Set up TNC interface
    kiss_port = config['kiss'].pop('port', 0)
    kiss = SerialKISSDevice( # in your case, TCPKISSDevice would be used.
            loop=loop, log=log.getChild('kiss'),
            **config['kiss']
    )
    kiss.open() # This starts the "open" process, which will continue when the IOLoop is started.

    # Set up AX.25 interface
    ax25int = AX25Interface(
            kissport=kiss[kiss_port],
            loop=loop, log=log.getChild('ax25'),
            **config.get('ax25', {})
    )

    # Set up APRS message handler
    aprs = APRSInterface(
            ax25int,
            log=log.getChild('aprs'),
            **config['aprs']
    )

    # Set up digipeating handler (optional)
    digi_enable = config.get('digi', {}).pop('enable', False)
    digi = APRSDigipeater(log=log.getChild('digi'),
            **config.get('digi', {}))
    if digi_enable:
        digi.connect(aprs)

    # Set up signal handlers
    def _shutdown():
        log.info('Shut-down signal received')
        # Do whatever you have to here to clean everything up!
        kiss.close()
        log.info('Waiting 5 seconds for final shut-down')
        loop.call_later(5, loop.stop)

    for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):
        loop.add_signal_handler(sig, _shutdown)

    # Enter the event loop
    log.info('Entering event loop')
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        # Perform whatever shutdown steps needed here.
        pass

# in __main__.py
from .main import main

if __name__ == '__main__':
    main()

That loop.run_forever() is the key here… that starts an IOLoop instance to run continuously; if we get a KeyboardInterrupt exception; or we receive a suitable signal, we shut everything down (cleanly)… otherwise it just keeps on trucking.

from aioax25.

sjlongland avatar sjlongland commented on May 27, 2024

Ohh, and the above, would use a configuration file that looks like this:

aprs:
        mycall: VK4MSL-1
        #aprs_path: []

kiss: # here, you would put the parameters used by TCPKISSInterface… in this case, it's a serial interface to a port on a PocketBeagle which connects to a KPC3
        device: /dev/ttyS4
        baudrate: 9600

# Logging settings
# See https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
logging:
        version: 1
        formatters:
                detail:
                        format: '%(asctime)s %(name)s[%(filename)s:%(lineno)4d] %(levelname)s %(message)s'
        handlers:
                console:
                        formatter: detail
                        class: logging.StreamHandler
                        level: DEBUG
                        stream: ext://sys.stdout
        root:
                level: DEBUG
                handlers:
                        - console

from aioax25.

hemna avatar hemna commented on May 27, 2024

Any chance you can do a formal release so I can use aioax25 from pypi with the new tcpkiss support?

from aioax25.

sjlongland avatar sjlongland commented on May 27, 2024

I'll have to schedule some time to give it a shot at some point. The last few weeks have been a bit of a battle getting free time to work on these projects.

from aioax25.

sjlongland avatar sjlongland commented on May 27, 2024

Release 0.0.10 includes these changes.

from aioax25.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.