]> git.basschouten.com Git - openhab-addons.git/blob
1a51a9e743b360d4e1fd5abfa7ea0972190b1eb0
[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.max.internal.message;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * The {@link SMessage} contains information about Command execution results
21  *
22  * @author Bernd Michael Helm (bernd.helm at helmundwalter.de) - Initial contribution
23  * @author Marcel Verpaalen - OH2 version + parsing of the message
24  */
25 @NonNullByDefault
26 public final class SMessage extends Message {
27     private final Logger logger = LoggerFactory.getLogger(SMessage.class);
28
29     private int dutyCycle;
30     private int freeMemorySlots;
31     private boolean commandDiscarded = false;
32
33     public SMessage(String raw) {
34         super(raw);
35
36         String[] tokens = this.getPayload().split(Message.DELIMETER);
37
38         if (tokens.length == 3) {
39             try {
40                 dutyCycle = Integer.parseInt(tokens[0], 16);
41                 commandDiscarded = tokens[1].contentEquals("1");
42                 freeMemorySlots = Integer.parseInt(tokens[2], 16);
43             } catch (Exception e) {
44                 logger.debug("Exception occurred during parsing of S message: {}", e.getMessage(), e);
45             }
46         } else {
47             logger.debug("Unexpected # of tolkens ({}) received in S message: {}", tokens.length, this.getPayload());
48         }
49     }
50
51     public int getDutyCycle() {
52         return dutyCycle;
53     }
54
55     public int getFreeMemorySlots() {
56         return freeMemorySlots;
57     }
58
59     public boolean isCommandDiscarded() {
60         return commandDiscarded;
61     }
62
63     @Override
64     public void debug(Logger logger) {
65         logger.trace("=== S Message === ");
66         logger.trace("\tRAW : {}", this.getPayload());
67         logger.trace("\tDutyCycle         : {}", this.dutyCycle);
68         logger.trace("\tCommand Discarded : {}", this.commandDiscarded);
69         logger.trace("\tFreeMemorySlots   : {}", this.freeMemorySlots);
70     }
71
72     @Override
73     public MessageType getType() {
74         return MessageType.S;
75     }
76 }