• 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

44.9
/spinnman/messages/scp/impl/fixed_route_read.py
1
# Copyright (c) 2017 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 List
1✔
17
from spinn_utilities.overrides import overrides
1✔
18
from spinn_machine import FixedRouteEntry
1✔
19
from spinnman.exceptions import SpinnmanUnexpectedResponseCodeException
1✔
20
from spinnman.messages.scp import SCPRequestHeader
1✔
21
from spinnman.messages.scp.abstract_messages import (
1✔
22
    AbstractSCPRequest, AbstractSCPResponse)
23
from spinnman.messages.scp.enums import SCPCommand, SCPResult
1✔
24
from spinnman.messages.sdp import SDPHeader, SDPFlag
1✔
25

26
_ONE_WORD = struct.Struct("<I")
1✔
27

28

29
class _FixedRouteResponse(AbstractSCPResponse):
1✔
30
    """
31
    response for the fixed route read
32
    """
33
    __slots__ = [
1✔
34
        # the fixed route router entry
35
        "_route"]
36

37
    def __init__(self) -> None:
1✔
38
        super().__init__()
×
39
        self._route = 0
×
40

41
    @overrides(AbstractSCPResponse.read_data_bytestring)
1✔
42
    def read_data_bytestring(self, data: bytes, offset: int):
1✔
43
        result = self.scp_response_header.result
×
44
        if result != SCPResult.RC_OK:
×
45
            raise SpinnmanUnexpectedResponseCodeException(
×
46
                "Read Fixed Route entry", "CMD_RTR", result.name)
47

48
        self._route = _ONE_WORD.unpack_from(data, offset)[0]
×
49

50
    @property
1✔
51
    def route(self) -> FixedRouteEntry:
1✔
52
        processor_ids: List[int] = list()
×
53
        for processor_id in range(26):
×
54
            if self._route & (1 << (6 + processor_id)) != 0:
×
55
                processor_ids.append(processor_id)
×
56
        link_ids: List[int] = list()
×
57
        for link_id in range(6):
×
58
            if self._route & (1 << link_id) != 0:
×
59
                link_ids.append(link_id)
×
60
        return FixedRouteEntry(processor_ids, link_ids)
×
61

62

63
class FixedRouteRead(AbstractSCPRequest[_FixedRouteResponse]):
1✔
64
    """
65
    Gets a fixed route entry.
66
    """
67
    __slots__ = ()
1✔
68

69
    def __init__(self, x: int, y: int, app_id: int):
1✔
70
        """
71
        :param int x: The x-coordinate of the chip, between 0 and 255,
72
            this is not checked due to speed restrictions
73
        :param int y: The y-coordinate of the chip, between 0 and 255,
74
            this is not checked due to speed restrictions
75
        :param int app_id:
76
            The ID of the application with which to associate the routes.
77
            If not specified, defaults to 0.
78
        :raise SpinnmanInvalidParameterException:
79
            * If x is out of range
80
            * If y is out of range
81
        """
82
        super().__init__(
×
83
            SDPHeader(
84
                flags=SDPFlag.REPLY_EXPECTED, destination_port=0,
85
                destination_cpu=0, destination_chip_x=x,
86
                destination_chip_y=y),
87
            SCPRequestHeader(command=SCPCommand.CMD_RTR),
88
            argument_1=(app_id << 8) | 3, argument_2=1 << 31)
89

90
    @overrides(AbstractSCPRequest.get_scp_response)
1✔
91
    def get_scp_response(self) -> _FixedRouteResponse:
1✔
92
        return _FixedRouteResponse()
×
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