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.connection;
15 import java.util.concurrent.TimeUnit;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lcn.internal.common.LcnAddr;
19 import org.openhab.binding.lcn.internal.common.PckGenerator;
22 * This state is active when the connection to the LCN bus has been established successfully and data can be sent and
25 * @author Fabian Wolter - Initial Contribution
28 public class ConnectionStateConnected extends AbstractConnectionState {
29 private static final int PING_INTERVAL_SEC = 60;
30 private int pingCounter;
32 public ConnectionStateConnected(ConnectionStateMachine context) {
37 public void startWorking() {
38 // send periodic keep-alives to keep the connection open
39 addTimer(getScheduler().scheduleWithFixedDelay(
40 () -> connection.queueDirectlyPlainText(PckGenerator.ping(++pingCounter)), PING_INTERVAL_SEC,
41 PING_INTERVAL_SEC, TimeUnit.SECONDS));
43 // run ModInfo.update() for every LCN module
44 addTimer(getScheduler().scheduleWithFixedDelay(connection::updateModInfos, 0, 1, TimeUnit.SECONDS));
46 connection.sendOfflineQueue();
50 public void queue(LcnAddr addr, boolean wantsAck, byte[] data) {
51 connection.queueDirectly(addr, wantsAck, data);
55 public void onPckMessageReceived(String data) {
56 parseLcnBusDiconnectMessage(data);