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

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

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

14.29
/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/ReadIPAddress.java
1
/*
2
 * Copyright (c) 2022 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.messages.bmp;
17

18
import static java.lang.System.arraycopy;
19
import static java.net.InetAddress.getByAddress;
20
import static uk.ac.manchester.spinnaker.messages.bmp.BMPInfo.IP_ADDR;
21
import static uk.ac.manchester.spinnaker.messages.scp.SCPCommand.CMD_BMP_INFO;
22

23
import java.net.InetAddress;
24
import java.net.UnknownHostException;
25
import java.nio.ByteBuffer;
26

27
import uk.ac.manchester.spinnaker.machine.board.BMPBoard;
28
import uk.ac.manchester.spinnaker.messages.model.Addresses;
29
import uk.ac.manchester.spinnaker.messages.model.UnexpectedResponseCodeException;
30

31
/**
32
 * A request for the IP address data from a BMP. The response payload is the
33
 * {@linkplain Addresses pair of addresses} that the board is configured to
34
 * have.
35
 * <p>
36
 * Handled by {@code cmd_bmp_info()} in {@code bmp_cmd.c}.
37
 */
38
public final class ReadIPAddress extends BMPRequest<ReadIPAddress.Response> {
39
        /**
40
         * @param board
41
         *            which board to request the IP address data from
42
         */
43
        public ReadIPAddress(BMPBoard board) {
44
                super(board, CMD_BMP_INFO, IP_ADDR.value);
1✔
45
        }
1✔
46

47
        @Override
48
        public Response getSCPResponse(ByteBuffer buffer) throws Exception {
49
                return new Response(buffer);
×
50
        }
51

52
        private static final int CHUNK_LEN = 32;
53

54
        private static final int IP_OFFSET = 8;
55

56
        private static final int IP_LEN = 4;
57

58
        /**
59
         * Get a slice out of the result buffer and pick the IP address out of that.
60
         *
61
         * @param buffer
62
         *            The result buffer. Position will be updated.
63
         * @return The parsed IP address.
64
         * @throws UnknownHostException
65
         *             Unexpected; we are presenting the right number of bytes.
66
         */
67
        private static InetAddress getIP(ByteBuffer buffer)
68
                        throws UnknownHostException {
69
                /*
70
                 * NB: CHUNK_LEN != IP_LEN so we *must* copy like this or otherwise
71
                 * mess around with the buffer position. This is easiest.
72
                 */
73
                var chunk = new byte[CHUNK_LEN];
×
74
                buffer.get(chunk);
×
75
                var bytes = new byte[IP_LEN];
×
76
                arraycopy(chunk, IP_OFFSET, bytes, 0, IP_LEN);
×
77
                return getByAddress(bytes);
×
78
        }
79

80
        /** An SCP response to a request for IP address information. */
81
        protected final class Response
82
                        extends BMPRequest.PayloadedResponse<Addresses> {
83
                private Response(ByteBuffer buffer)
84
                                throws UnexpectedResponseCodeException {
×
85
                        super("Read IP Address Data", CMD_BMP_INFO, buffer);
×
86
                }
×
87

88
                /** @return The addresses of the SpiNNaker board. */
89
                @Override
90
                protected Addresses parse(ByteBuffer buffer) {
91
                        try {
92
                                // Tricky point: order of evaluation matters
93
                                return new Addresses(getIP(buffer), getIP(buffer));
×
94
                        } catch (UnknownHostException e) {
×
95
                                // Should be unreachable
96
                                return null;
×
97
                        }
98
                }
99
        }
100
}
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

© 2026 Coveralls, Inc