2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.plugwise.internal.protocol;
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.PING_RESPONSE;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
23 * Contains network diagnostic information. This message is the response of a {@link PingRequestMessage}.
25 * @author Wouter Born - Initial contribution
27 public class PingResponseMessage extends Message {
29 private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{2})(\\w{2})(\\w{4})");
33 private int pingMillis;
35 public PingResponseMessage(int sequenceNumber, String payload) {
36 super(PING_RESPONSE, sequenceNumber, payload);
39 public int getInRSSI() {
43 public int getOutRSSI() {
47 public int getPingMillis() {
52 protected void parsePayload() {
53 Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
54 if (matcher.matches()) {
55 macAddress = new MACAddress(matcher.group(1));
56 inRSSI = (Integer.parseInt(matcher.group(2), 16));
57 outRSSI = (Integer.parseInt(matcher.group(3), 16));
58 pingMillis = (Integer.parseInt(matcher.group(4), 16));
60 throw new PlugwisePayloadMismatchException(PING_RESPONSE, PAYLOAD_PATTERN, payload);