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.lcn.internal.subhandler;
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.lcn.internal.LcnBindingConstants;
22 import org.openhab.binding.lcn.internal.LcnModuleHandler;
23 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
24 import org.openhab.binding.lcn.internal.connection.ModInfo;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Handle Acks received from an LCN module.
31 * @author Fabian Wolter - Initial contribution
34 public class LcnModuleMetaAckSubHandler extends AbstractLcnModuleSubHandler {
35 private final Logger logger = LoggerFactory.getLogger(LcnModuleMetaAckSubHandler.class);
36 /** The pattern for the Ack PCK message */
37 public static final Pattern PATTERN_POS = Pattern.compile("-M(?<segId>\\d{3})(?<modId>\\d{3})!");
38 private static final Pattern PATTERN_NEG = Pattern.compile("-M(?<segId>\\d{3})(?<modId>\\d{3})(?<code>\\d+)");
40 public LcnModuleMetaAckSubHandler(LcnModuleHandler handler, ModInfo info) {
45 public void handleRefresh(LcnChannelGroup channelGroup, int number) {
50 public void handleStatusMessage(Matcher matcher) {
51 if (matcher.pattern() == PATTERN_POS) {
52 handler.onAckRceived();
53 } else if (matcher.pattern() == PATTERN_NEG) {
54 logger.warn("{}: NACK received: {}", handler.getStatusMessageAddress(),
55 codeToString(Integer.parseInt(matcher.group("code"))));
59 private String codeToString(int code) {
61 case LcnBindingConstants.CODE_ACK:
64 return "Unknown command";
66 return "Invalid parameter count";
68 return "Invalid parameter";
70 return "Command not allowed (e.g. output locked)";
72 return "Command not allowed by module's configuration";
74 return "Module not capable";
76 return "Periphery missing";
78 return "Programming mode necessary";
80 return "Mains fuse blown";
87 public Collection<Pattern> getPckStatusMessagePatterns() {
88 return Arrays.asList(PATTERN_POS, PATTERN_NEG);