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.globalcache.internal.command;
15 import java.util.concurrent.LinkedBlockingQueue;
16 import java.util.regex.Matcher;
17 import java.util.regex.Pattern;
19 import org.openhab.binding.globalcache.internal.GlobalCacheBindingConstants.CommandType;
20 import org.openhab.core.thing.Thing;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * The {@link CommandSetserial} class implements the GlobalCache set_SERIAL command, which sets the serial
26 * port parameters (baud, flow control, and parity) on the device.
28 * @author Mark Hilbush - Initial contribution
30 public class CommandSetserial extends AbstractCommand {
32 private final Logger logger = LoggerFactory.getLogger(CommandSetserial.class);
36 private String parity;
38 public CommandSetserial(Thing thing, LinkedBlockingQueue<RequestMessage> requestQueue, String mod, String con,
39 String baud, String flowcontrol, String parity) {
40 super(thing, requestQueue, "set_SERIAL", CommandType.COMMAND);
42 deviceCommand = "set_SERIAL," + mod + ":" + con + "," + baud + "," + flowcontrol + "," + parity;
46 public void parseSuccessfulReply() {
47 if (deviceReply == null) {
51 // decode response of form SERIAL,1:1,<baudrate>,<flowcontrol>,<parity
52 Pattern p = Pattern.compile("SERIAL,\\d:\\d,\\S+,\\S+,\\S+");
53 Matcher m = p.matcher(deviceReply);
58 String fields[] = deviceReply.split(",");
59 if (fields.length != 5) {
63 setModule(fields[1].substring(0, 1));
64 setConnector(fields[1].substring(2));
70 public String getBaud() {
74 public String getFlowcontrol() {
78 public String getParity() {
83 public void logSuccess() {
84 logger.debug("Execute '{}' succeeded on thing {} at {}", commandName, thing.getUID().getId(), ipAddress);
88 public void logFailure() {
89 logger.error("Execute '{}' failed on thing {} at: ipAdress={}, errorCode={}, errorMessage={}", commandName,
90 thing.getUID().getId(), ipAddress, errorCode, errorMessage);