コード例 #1
0
def test_send_message_oneshot_replyack():
    """
    Test that send_message in one-shot mode refuses to send reply-ack.
    """
    ax25int = DummyAX25Interface()
    aprsint = APRSInterface(ax25int, 'VK4MSL-10')
    try:
        aprsint.send_message(
                'VK4MDL-7', 'Hi', oneshot=True,
                replyack='This should be a message, but the code only tests '
                         'that this value is None, which it won\'t be here.'
        )
    except ValueError as e:
        eq_(str(e), 'Cannot send reply-ack in one-shot mode')
コード例 #2
0
def test_send_message_confirmable():
    """
    Test that send_message in confirmable mode generates a message handler.
    """
    ax25int = DummyAX25Interface()
    aprsint = APRSInterface(ax25int, 'VK4MSL-10')
    res = aprsint.send_message(
            'VK4MDL-7', 'Hi', oneshot=False
    )

    # We got back a handler class
    assert isinstance(res, APRSMessageHandler)

    # That message handler should be registered with the interface
    eq_(len(aprsint._pending_msg), 1)
    assert res.msgid in aprsint._pending_msg
    assert_is(aprsint._pending_msg[res.msgid], res)

    # The APRS message handler will have tried sending the message
    eq_(len(ax25int.transmitted), 1)
    frame = ax25int.transmitted.pop(0)

    # Frame is a APRS message frame
    assert isinstance(frame, APRSMessageFrame)

    # Message handler is in 'SEND' state
    eq_(res.state, APRSMessageHandler.HandlerState.SEND)
コード例 #3
0
def test_send_message_oneshot():
    """
    Test that send_message in one-shot mode generates a message frame.
    """
    ax25int = DummyAX25Interface()
    aprsint = APRSInterface(ax25int, 'VK4MSL-10')
    res = aprsint.send_message(
            'VK4MDL-7', 'Hi', oneshot=True
    )

    # We don't get a return value
    assert_is(res, None)

    # No message handler should be registered with the interface
    eq_(len(aprsint._pending_msg), 0)

    # The frame is passed to the AX.25 interface
    eq_(len(ax25int.transmitted), 1)
    frame = ax25int.transmitted.pop(0)

    # Frame is a APRS message frame
    assert isinstance(frame, APRSMessageFrame)

    # There is no pending messages
    eq_(len(aprsint._pending_msg), 0)
コード例 #4
0
ファイル: test_aprs.py プロジェクト: tarpn/aioax25
def test_send_message_replyack_notreplyack():
    """
    Test that send_message in confirmable mode generates a message handler.
    """
    ax25int = DummyAX25Interface()
    aprsint = APRSInterface(ax25int, 'VK4MSL-10')
    replymsg = APRSMessageFrame(destination='APRS',
                                source='VK4MDL-7',
                                addressee='VK4MSL-7',
                                message='Hello',
                                msgid='123',
                                replyack=False)
    try:
        aprsint.send_message('VK4MDL-7',
                             'Hi',
                             oneshot=False,
                             replyack=replymsg)
    except ValueError as e:
        eq_(str(e), 'replyack is not a reply-ack message')
コード例 #5
0
def test_send_message_replyack():
    """
    Test that send_message with a replyack message sets replyack.
    """
    ax25int = DummyAX25Interface()
    aprsint = APRSInterface(ax25int, 'VK4MSL-10')
    replymsg = APRSMessageFrame(
            destination='APRS',
            source='VK4MDL-7',
            addressee='VK4MSL-7',
            message='Hello',
            msgid='123',
            replyack=True
    )
    res = aprsint.send_message(
            'VK4MDL-7', 'Hi', oneshot=False, replyack=replymsg
    )

    # We got back a handler class
    assert isinstance(res, APRSMessageHandler)

    # That message handler should be registered with the interface
    eq_(len(aprsint._pending_msg), 1)
    assert res.msgid in aprsint._pending_msg
    assert_is(aprsint._pending_msg[res.msgid], res)

    # The APRS message handler will have tried sending the message
    eq_(len(ax25int.transmitted), 1)
    frame = ax25int.transmitted.pop(0)

    # Frame is a APRS message frame
    assert isinstance(frame, APRSMessageFrame)

    # Frame has reply-ACK set
    eq_(frame.replyack, '123')

    # Message handler is in 'SEND' state
    eq_(res.state, APRSMessageHandler.HandlerState.SEND)
コード例 #6
0
ファイル: kiss.py プロジェクト: craigerl/aprsd
class Aioax25Client:
    def __init__(self, config):
        self.config = config
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        self.loop = asyncio.get_event_loop()
        self.setup()

    def setup(self):
        # we can be TCP kiss or Serial kiss
        if "serial" in self.config["kiss"] and self.config["kiss"][
                "serial"].get(
                    "enabled",
                    False,
                ):
            LOG.debug(
                "Setting up Serial KISS connection to {}".format(
                    self.config["kiss"]["serial"]["device"], ), )
            self.kissdev = kiss.SerialKISSDevice(
                device=self.config["kiss"]["serial"]["device"],
                baudrate=self.config["kiss"]["serial"].get("baudrate", 9600),
                loop=self.loop,
            )
        elif "tcp" in self.config["kiss"] and self.config["kiss"]["tcp"].get(
                "enabled",
                False,
        ):
            LOG.debug(
                "Setting up KISSTCP Connection to {}:{}".format(
                    self.config["kiss"]["tcp"]["host"],
                    self.config["kiss"]["tcp"]["port"],
                ), )
            self.kissdev = kiss.TCPKISSDevice(
                self.config["kiss"]["tcp"]["host"],
                self.config["kiss"]["tcp"]["port"],
                loop=self.loop,
                log=LOG,
            )

        self.kissdev.open()
        self.kissport0 = self.kissdev[0]

        LOG.debug("Creating AX25Interface")
        self.ax25int = interface.AX25Interface(kissport=self.kissport0,
                                               loop=self.loop)

        LOG.debug("Creating APRSInterface")
        self.aprsint = APRSInterface(
            ax25int=self.ax25int,
            mycall=self.config["kiss"]["callsign"],
            log=LOG,
        )

    def stop(self):
        LOG.debug(self.kissdev)
        self.kissdev._close()
        self.loop.stop()

    def set_filter(self, filter):
        # This does nothing right now.
        pass

    def consumer(self, callback, blocking=True, immortal=False, raw=False):
        callsign = self.config["kiss"]["callsign"]
        call = callsign.split("-")
        if len(call) > 1:
            callsign = call[0]
            ssid = int(call[1])
        else:
            ssid = 0
        self.aprsint.bind(callback=callback,
                          callsign=callsign,
                          ssid=ssid,
                          regex=False)
        self.loop.run_forever()

    def send(self, msg):
        """Send an APRS Message object."""
        payload = f"{msg._filter_for_send()}"
        self.aprsint.send_message(
            addressee=msg.tocall,
            message=payload,
            path=["WIDE1-1", "WIDE2-1"],
            oneshot=True,
        )