]> git.basschouten.com Git - openhab-addons.git/blob
b5586b5d7c8ee80d7558dd9e47fadd1e75b297cf
[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.paradoxalarm.internal.communication.messages;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.paradoxalarm.internal.exceptions.ParadoxException;
17 import org.openhab.binding.paradoxalarm.internal.util.ParadoxUtil;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link EpromRequestPayload} Object representing payload of IP packet which retrieves data from Paradox EPROM
23  *
24  * @author Konstantin Polihronov - Initial contribution
25  */
26 @NonNullByDefault
27 public class EpromRequestPayload extends MemoryRequestPayload implements IPayload {
28
29     private final Logger logger = LoggerFactory.getLogger(EpromRequestPayload.class);
30
31     public EpromRequestPayload(int address, byte bytesToRead) throws ParadoxException {
32         super(address, bytesToRead);
33     }
34
35     @Override
36     protected byte calculateControlByte() {
37         int address = getAddress();
38         logTraceHexFormatted("Address: {}", address);
39
40         byte controlByte = 0x00;
41         byte[] shortToByteArray = ParadoxUtil.intToByteArray(address);
42         if (shortToByteArray.length > 2) {
43             byte bit16 = ParadoxUtil.getBit(address, 16);
44             controlByte |= bit16 << 0;
45             byte bit17 = ParadoxUtil.getBit(address, 17);
46             controlByte |= bit17 << 1;
47         }
48         logger.trace("ControlByte value: {}", controlByte);
49         return controlByte;
50     }
51 }