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 CommandGetserial} class implements the GlobalCache get_SERIAL command, which retrieves the serial
26 * port parameters (baud, flow control, and parity) from the device.
28 * @author Mark Hilbush - Initial contribution
30 public class CommandGetserial extends AbstractCommand {
32 private final Logger logger = LoggerFactory.getLogger(CommandGetserial.class);
36 private String parity;
38 public CommandGetserial(Thing thing, LinkedBlockingQueue<RequestMessage> requestQueue, String mod, String con) {
39 super(thing, requestQueue, "get_SERIAL", CommandType.COMMAND);
41 deviceCommand = "get_SERIAL," + mod + ":" + con;
45 public void parseSuccessfulReply() {
46 if (deviceReply == null) {
50 // decode response of form SERIAL,1:1,<baudrate>,<flowcontrol>,<parity
51 Pattern p = Pattern.compile("SERIAL,\\d:\\d,\\S+,\\S+,\\S+");
52 Matcher m = p.matcher(deviceReply);
57 String[] fields = deviceReply.split(",");
58 if (fields.length != 5) {
62 setModule(fields[1].substring(0, 1));
63 setConnector(fields[1].substring(2));
69 public String getBaud() {
73 public String getFlowcontrol() {
77 public String getParity() {
82 public void logSuccess() {
83 logger.debug("Execute '{}' succeeded on thing {} at {}", commandName, thing.getUID().getId(), ipAddress);
87 public void logFailure() {
88 logger.error("Execute '{}' failed on thing {} at {}: errorCode={}, errorMessage={}", commandName,
89 thing.getUID().getId(), ipAddress, errorCode, errorMessage);