]> git.basschouten.com Git - openhab-addons.git/blob
5cb60cf016d6bce49cacd81b5b93543525b721a7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.plugwise.internal.protocol;
14
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.DEVICE_ROLE_CALL_RESPONSE;
16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
21
22 /**
23  * <p>
24  * The Circle+ sends this message as response to a {@link RoleCallRequestMessage}. It contains the MAC address for the
25  * the node identified by the node ID in the request message. When no node is known with given ID, the MAC
26  * address will be empty.
27  * </p>
28  * <p>
29  * The MAC address can belong to a relay device (Circle, Stealth) as well as a sleeping end device (SED: Scan, Sense,
30  * Switch). An {@link InformationRequestMessage} can be used to determine the actual device type (when it is online).
31  * </p>
32  * <p>
33  * The Circle+ MAC address can not be retrieved from the node list. The Circle+ MAC address can be retrieved with a
34  * {@link NetworkStatusRequestMessage}.
35  * </p>
36  *
37  * @author Wouter Born, Karel Goderis - Initial contribution
38  */
39 public class RoleCallResponseMessage extends Message {
40
41     private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{16})(\\w{2})");
42     private static final String EMPTY_MAC_ADDRESS = "FFFFFFFFFFFFFFFF";
43
44     private int nodeID;
45     private MACAddress nodeMAC;
46
47     public RoleCallResponseMessage(int sequenceNumber, String payload) {
48         super(DEVICE_ROLE_CALL_RESPONSE, sequenceNumber, payload);
49     }
50
51     public int getNodeID() {
52         return nodeID;
53     }
54
55     public MACAddress getNodeMAC() {
56         return nodeMAC;
57     }
58
59     @Override
60     protected void parsePayload() {
61         Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
62         if (matcher.matches()) {
63             macAddress = new MACAddress(matcher.group(1));
64             nodeMAC = matcher.group(2).equals(EMPTY_MAC_ADDRESS) ? null : new MACAddress(matcher.group(2));
65             nodeID = (Integer.parseInt(matcher.group(3), 16));
66         } else {
67             throw new PlugwisePayloadMismatchException(DEVICE_ROLE_CALL_RESPONSE, PAYLOAD_PATTERN, payload);
68         }
69     }
70 }