]> git.basschouten.com Git - openhab-addons.git/blob
7ca1c062d8ebb6cb0c3edbff377f419fd2508932
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.knx.internal.client;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 import tuwien.auto.calimero.DetachEvent;
21 import tuwien.auto.calimero.process.ProcessEvent;
22 import tuwien.auto.calimero.process.ProcessListener;
23
24 /**
25  * This implementation of {@link ProcessListener} caches a received frames.
26  *
27  * It can be registered to {@link DummyKNXNetworkLink} to receive raw frame data.
28  *
29  * @author Holger Friedrich - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class DummyProcessListener implements ProcessListener {
34     private byte[] lastFrame = new byte[0];
35     public static final Logger LOGGER = LoggerFactory.getLogger(DummyProcessListener.class);
36
37     public DummyProcessListener() {
38     }
39
40     @Override
41     public void detached(@Nullable DetachEvent e) {
42         LOGGER.info("The KNX network link was detached from the process communicator");
43     }
44
45     @Override
46     public void groupWrite(@Nullable ProcessEvent e) {
47         if (e == null) {
48             lastFrame = new byte[0];
49             LOGGER.warn("invalid ProcessEvent");
50             return;
51         }
52         LOGGER.info("groupWrite({})", e.toString());
53         lastFrame = e.getASDU(); // clones
54     }
55
56     @Override
57     public void groupReadRequest(@Nullable ProcessEvent e) {
58         if (e == null) {
59             lastFrame = new byte[0];
60             LOGGER.warn("invalid ProcessEvent");
61             return;
62         }
63         LOGGER.warn("groupReadRequest({})", e.toString());
64         lastFrame = e.getASDU(); // clones
65     }
66
67     @Override
68     public void groupReadResponse(@Nullable ProcessEvent e) {
69         if (e == null) {
70             lastFrame = new byte[0];
71             LOGGER.warn("invalid ProcessEvent");
72             return;
73         }
74         LOGGER.warn("groupReadResponse({})", e.toString());
75         lastFrame = e.getASDU(); // clones
76     }
77
78     public byte[] getLastFrame() {
79         return lastFrame;
80     }
81 }