• 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

59.09
/spinnman/messages/scp/impl/read_memory.py
1
# Copyright (c) 2014 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
from spinn_utilities.overrides import overrides
1✔
16
from spinn_utilities.typing.coords import XYP
1✔
17
from spinnman.messages.scp import SCPRequestHeader
1✔
18
from spinnman.messages.scp.abstract_messages import (
1✔
19
    AbstractSCPRequest, AbstractSCPResponse)
20
from spinnman.messages.scp.enums import SCPCommand, SCPResult
1✔
21
from spinnman.messages.sdp import SDPFlag, SDPHeader
1✔
22
from spinnman.exceptions import SpinnmanUnexpectedResponseCodeException
1✔
23
from spinnman.constants import address_length_dtype
1✔
24

25

26
class Response(AbstractSCPResponse):
1✔
27
    """
28
    An SCP response to a request to read a region of memory on a chip.
29
    """
30
    __slots__ = (
1✔
31
        "_data",
32
        "_length",
33
        "_offset",
34
        "__op",
35
        "__cmd")
36

37
    def __init__(self, operation: str, command: str) -> None:
1✔
38
        super().__init__()
×
39
        self._data = b''
×
40
        self._length = 0
×
41
        self._offset = 0
×
42
        self.__op = operation
×
43
        self.__cmd = command
×
44

45
    @overrides(AbstractSCPResponse.read_data_bytestring)
1✔
46
    def read_data_bytestring(self, data: bytes, offset: int):
1✔
47
        assert self._scp_response_header is not None
×
48
        if self._scp_response_header.result != SCPResult.RC_OK:
×
49
            raise SpinnmanUnexpectedResponseCodeException(
×
50
                self.__op, self.__cmd, self._scp_response_header.result)
51
        self._data = data
×
52
        self._offset = offset
×
53
        self._length = len(data) - offset
×
54

55
    @property
1✔
56
    def data(self) -> bytes:
1✔
57
        """
58
        The data read.
59

60
        .. note::
61
            The data starts at offset.
62

63
        :rtype: bytearray
64
        """
65
        return self._data
×
66

67
    @property
1✔
68
    def offset(self) -> int:
1✔
69
        """
70
        The offset where the valid data starts.
71

72
        :rtype: int
73
        """
74
        return self._offset
×
75

76
    @property
1✔
77
    def length(self) -> int:
1✔
78
        """
79
        The length of the valid data.
80

81
        :rtype: int
82
        """
83
        return self._length
×
84

85

86
class ReadMemory(AbstractSCPRequest[Response]):
1✔
87
    """
88
    An SCP request to read a region of memory on a chip.
89
    """
90
    __slots__ = ()
1✔
91

92
    def __init__(self, coordinates: XYP, base_address: int, size: int):
1✔
93
        """
94
        :param tuple coordinates:
95
            The X,Y,P coordinates of the chip to read from;
96
            X and Y between 0 and 255, P between 0 and 17
97
        :param int base_address:
98
            The positive base address to start the read from
99
        :param int size: The number of bytes to read, between 1 and 256
100
        :raise SpinnmanInvalidParameterException:
101
            * If the chip coordinates are out of range
102
            * If the base address is not a positive number
103
            * If the size is out of range
104
        """
105
        x, y, cpu = coordinates
1✔
106
        super().__init__(
1✔
107
            SDPHeader(
108
                flags=SDPFlag.REPLY_EXPECTED, destination_port=0,
109
                destination_cpu=cpu, destination_chip_x=x,
110
                destination_chip_y=y),
111
            SCPRequestHeader(command=SCPCommand.CMD_READ),
112
            argument_1=base_address, argument_2=size,
113
            argument_3=address_length_dtype[
114
                (base_address % 4, size % 4)].value)
115

116
    @overrides(AbstractSCPRequest.get_scp_response)
1✔
117
    def get_scp_response(self) -> Response:
1✔
118
        return Response("read memory", "CMD_READ")
×
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