• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.58
/spinnman/connections/udp_packet_connections/sdp_connection.py
1
# Copyright (c) 2015 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import struct
1✔
16
from typing import Callable, Optional
1✔
17
from spinn_utilities.overrides import overrides
1✔
18
from spinnman.messages.sdp import SDPMessage, SDPFlag
1✔
19
from .udp_connection import UDPConnection
1✔
20
from spinnman.connections.abstract_classes import Listenable
1✔
21
from spinnman.exceptions import SpinnmanUnsupportedOperationException
1✔
22

23
_TWO_SKIP = struct.Struct("<2x")
1✔
24

25

26
class SDPConnection(UDPConnection, Listenable[SDPMessage]):
1✔
27
    """
28
    A connection that talks SpiNNaker Datagram Protocol.
29
    """
30
    __slots__ = (
1✔
31
        "_chip_x",
32
        "_chip_y")
33

34
    def __init__(
1✔
35
            self, chip_x: int, chip_y: int,
36
            local_host: Optional[str] = None,
37
            local_port: Optional[int] = None,
38
            remote_host: Optional[str] = None,
39
            remote_port: Optional[int] = None):
40
        """
41
        :param int chip_x: The optional x-coordinate of the chip at the remote
42
            end of the connection. If not specified, it will not be possible
43
            to send SDP messages that require a response with this connection.
44
        :param int chip_y: The optional y-coordinate of the chip at the remote
45
            end of the connection. If not specified, it will not be possible
46
            to send SDP messages that require a response with this connection.
47
        :param str local_host: The optional IP address or host name of the
48
            local interface to listen on
49
        :param int local_port: The optional local port to listen on
50
        :param str remote_host: The optional remote host name or IP address to
51
            send messages to. If not specified, sending will not be possible
52
            using this connection
53
        :param int remote_port: The optional remote port number to send
54
            messages to. If not specified, sending will not be possible using
55
            this connection
56
        """
57
        # pylint: disable=too-many-arguments
58
        super().__init__(local_host, local_port, remote_host, remote_port)
1✔
59
        self._chip_x = chip_x
1✔
60
        self._chip_y = chip_y
1✔
61

62
    def receive_sdp_message(
1✔
63
            self, timeout: Optional[float] = None) -> SDPMessage:
64
        """
65
        Receives an SDP message from this connection.  Blocks until the
66
        message has been received, or a timeout occurs.
67

68
        :param int timeout:
69
            The time in seconds to wait for the message to arrive; if not
70
            specified, will wait forever, or until the connection is closed.
71
        :return: The received SDP message
72
        :rtype: SDPMessage
73
        :raise SpinnmanIOException:
74
            If there is an error receiving the message
75
        :raise SpinnmanTimeoutException:
76
            If there is a timeout before a message is received
77
        :raise SpinnmanInvalidPacketException:
78
            If the received packet is not a valid SDP message
79
        :raise SpinnmanInvalidParameterException:
80
            If one of the fields of the SDP message is invalid
81
        """
82
        data = self.receive(timeout)
×
83
        return SDPMessage.from_bytestring(data, 2)
×
84

85
    def send_sdp_message(self, sdp_message: SDPMessage):
1✔
86
        """
87
        Sends an SDP message down this connection.
88

89
        :param SDPMessage sdp_message: The SDP message to be sent
90
        :raise SpinnmanIOException:
91
            If there is an error sending the message.
92
        """
93
        if self._chip_x is None or self._chip_y is None:
×
94
            raise SpinnmanUnsupportedOperationException(
×
95
                "send on receive-only connection")
96
        # If a reply is expected, the connection should
97
        if sdp_message.sdp_header.flags == SDPFlag.REPLY_EXPECTED:
×
98
            sdp_message.sdp_header.update_for_send(self._chip_x, self._chip_y)
×
99
        else:
100
            sdp_message.sdp_header.update_for_send(0, 0)
×
101
        self.send(_TWO_SKIP.pack() + sdp_message.bytestring)
×
102

103
    @overrides(Listenable.get_receive_method)
1✔
104
    def get_receive_method(  # type: ignore[override]
1✔
105
            self) -> Callable[[], SDPMessage]:
106
        return self.receive_sdp_message
×
107

108
    def __repr__(self) -> str:
1✔
109
        return (
×
110
            f"SDPConnection(chip_x={self._chip_x}, chip_y={self._chip_y}, "
111
            f"local_host={self.local_ip_address}, local_port={self.local_port}"
112
            f", remote_host={self.remote_ip_address}, "
113
            f"remote_port={self.remote_port})")
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc