• 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

78.95
/spinnman/connections/udp_packet_connections/scamp_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 Optional, Tuple
1✔
17
from spinn_utilities.overrides import overrides
1✔
18
from spinnman.constants import SCP_SCAMP_PORT
1✔
19
from spinnman.messages.scp.enums import SCPResult
1✔
20
from spinnman.connections.abstract_classes import AbstractSCPConnection
1✔
21
from spinnman.messages.scp.abstract_messages import AbstractSCPRequest
1✔
22
from .sdp_connection import SDPConnection
1✔
23

24
_TWO_SHORTS = struct.Struct("<2H")
1✔
25
_TWO_SKIP = struct.Struct("<2x")
1✔
26

27

28
class SCAMPConnection(SDPConnection, AbstractSCPConnection):
1✔
29
    """
30
    A UDP connection to SCAMP on the board.
31
    """
32
    __slots__ = ()
1✔
33

34
    def __init__(
1✔
35
            self, chip_x: int = 255, chip_y: int = 255,
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:
42
            The x-coordinate of the chip on the board with this remote_host
43
        :param int chip_y:
44
            The y-coordinate of the chip on the board with this remote_host
45
        :param str local_host: The optional IP address or host name of the
46
            local interface to listen on
47
        :param int local_port: The optional local port to listen on
48
        :param str remote_host: The optional remote host name or IP address to
49
            send messages to.  If not specified, sending will not be possible
50
            using this connection
51
        :param int remote_port: The optional remote port number to send
52
            messages to. If not specified, sending will not be possible using
53
            this connection
54
        """
55
        # pylint: disable=too-many-arguments
56
        if remote_port is None:
1!
57
            remote_port = SCP_SCAMP_PORT
1✔
58
        super().__init__(
1✔
59
            chip_x, chip_y, local_host, local_port, remote_host, remote_port)
60

61
    @property
1✔
62
    @overrides(AbstractSCPConnection.chip_x)
1✔
63
    def chip_x(self) -> int:
1✔
64
        return self._chip_x
1✔
65

66
    @property
1✔
67
    @overrides(AbstractSCPConnection.chip_y)
1✔
68
    def chip_y(self) -> int:
1✔
69
        return self._chip_y
1✔
70

71
    def update_chip_coordinates(self, x: int, y: int):
1✔
72
        self._chip_x = x
×
73
        self._chip_y = y
×
74

75
    @overrides(AbstractSCPConnection.get_scp_data,
1✔
76
               additional_arguments=['x', 'y'], extend_defaults=True)
77
    def get_scp_data(
1✔
78
            self, scp_request: AbstractSCPRequest,
79
            x: Optional[int] = None, y: Optional[int] = None) -> bytes:
80
        """
81
        :param int x: Optional: x-coordinate of where to send to
82
        :param int y: Optional: y-coordinate of where to send to
83
        """
84
        # pylint: disable=arguments-differ
85
        if x is None:
1!
86
            x = self.chip_x
1✔
87
        if y is None:
1!
88
            y = self.chip_y
1✔
89
        scp_request.sdp_header.update_for_send(x, y)
1✔
90
        return _TWO_SKIP.pack() + scp_request.bytestring
1✔
91

92
    @overrides(AbstractSCPConnection.receive_scp_response)
1✔
93
    def receive_scp_response(self, timeout: Optional[float] = 1.0) -> Tuple[
1✔
94
            SCPResult, int, bytes, int]:
95
        data = self.receive(timeout)
1✔
96
        result, sequence = _TWO_SHORTS.unpack_from(data, 10)
×
97
        return SCPResult(result), sequence, data, 2
×
98

99
    def receive_scp_response_with_address(
1✔
100
            self, timeout: float = 1.0) -> Tuple[
101
                SCPResult, int, bytes, int, str, int]:
102
        data, (addr, port) = self.receive_with_address(timeout)
×
103
        result, sequence = _TWO_SHORTS.unpack_from(data, 10)
×
104
        return SCPResult(result), sequence, data, 2, addr, port
×
105

106
    @overrides(AbstractSCPConnection.send_scp_request)
1✔
107
    def send_scp_request(self, scp_request: AbstractSCPRequest):
1✔
108
        self.send(self.get_scp_data(scp_request))
1✔
109

110
    def send_scp_request_to(
1✔
111
            self, scp_request: AbstractSCPRequest,
112
            x: int, y: int, ip_address: str):
113
        self.send_to(
×
114
            self.get_scp_data(scp_request, x, y),
115
            (str(ip_address), SCP_SCAMP_PORT))
116

117
    def __repr__(self) -> str:
1✔
118
        return (
×
119
            f"SCAMPConnection(chip_x={self._chip_x}, chip_y={self._chip_y}, "
120
            f"local_host={self.local_ip_address}, local_port={self.local_port}"
121
            f", remote_host={self.remote_ip_address}, "
122
            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