• 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

60.71
/spinnman/connections/udp_packet_connections/eieio_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 .udp_connection import UDPConnection
1✔
18
from spinnman.connections.abstract_classes import Listenable
1✔
19
from spinnman.messages.eieio import (
1✔
20
    read_eieio_command_message, read_eieio_data_message)
21
from spinn_utilities.overrides import overrides
1✔
22
from spinnman.messages.eieio import AbstractEIEIOMessage
1✔
23

24
_ONE_SHORT = struct.Struct("<H")
1✔
25
_REPR_TEMPLATE = "EIEIOConnection(local_host={}, local_port={},"\
1✔
26
    "remote_host={}, remote_port={})"
27

28

29
class EIEIOConnection(UDPConnection, Listenable[AbstractEIEIOMessage]):
1✔
30
    """
31
    A UDP connection for sending and receiving raw EIEIO messages.
32
    """
33
    __slots__ = ()
1✔
34

35
    def receive_eieio_message(
1✔
36
            self, timeout: Optional[float] = None) -> AbstractEIEIOMessage:
37
        """
38
        Receives an EIEIO message from this connection.  Blocks until
39
        a message has been received, or a timeout occurs.
40

41
        :param int timeout:
42
            The time in seconds to wait for the message to arrive; if not
43
            specified, will wait forever, or until the connection is closed
44
        :return: an EIEIO message
45
        :rtype: AbstractEIEIOMessage
46
        :raise SpinnmanIOException:
47
            If there is an error receiving the message.
48
        :raise SpinnmanTimeoutException:
49
            If there is a timeout before a message is received.
50
        :raise SpinnmanInvalidPacketException:
51
            If the received packet is not a valid EIEIO message.
52
        :raise SpinnmanInvalidParameterException:
53
            If one of the fields of the EIEIO message is invalid.
54
        """
55
        data = self.receive(timeout)
×
56
        header = _ONE_SHORT.unpack_from(data)[0]
×
57
        if header & 0xC000 == 0x4000:
×
58
            return read_eieio_command_message(data, 0)
×
59
        return read_eieio_data_message(data, 0)
×
60

61
    def send_eieio_message(self, eieio_message: AbstractEIEIOMessage):
1✔
62
        """
63
        Sends an EIEIO message down this connection.
64

65
        :param AbstractEIEIOMessage eieio_message:
66
            The EIEIO message to be sent
67
        :raise SpinnmanIOException:
68
            If there is an error sending the message
69
        """
70
        self.send(eieio_message.bytestring)
×
71

72
    def send_eieio_message_to(
1✔
73
            self, eieio_message: AbstractEIEIOMessage,
74
            ip_address: str, port: int):
75
        self.send_to(eieio_message.bytestring, (ip_address, port))
×
76

77
    @overrides(Listenable.get_receive_method)
1✔
78
    def get_receive_method(self) -> Callable[  # type: ignore[override]
1✔
79
            [], AbstractEIEIOMessage]:
80
        return self.receive_eieio_message
×
81

82
    def __repr__(self) -> str:
1✔
83
        return _REPR_TEMPLATE.format(
×
84
            self.local_ip_address, self.local_port,
85
            self.remote_ip_address, 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