]> git.basschouten.com Git - openhab-addons.git/blob
52daffecaba48cef98bca9fc63bcdae845614d0e
[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.sinope.internal.core;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.nio.ByteBuffer;
18
19 import org.openhab.binding.sinope.internal.core.base.SinopeRequest;
20 import org.openhab.binding.sinope.internal.util.ByteUtil;
21
22 /**
23  * The Class SinopeApiLoginRequest.
24  *
25  * @author Pascal Larin - Initial contribution
26  */
27 public class SinopeApiLoginRequest extends SinopeRequest {
28
29     /** The api key. */
30     private byte[] apiKey;
31
32     /** The id. */
33     private byte[] id;
34
35     /**
36      * Instantiates a new sinope api login request.
37      *
38      * @param id the id
39      * @param apiKey the api key
40      */
41     public SinopeApiLoginRequest(byte[] id, byte[] apiKey) {
42         this.id = id;
43         this.apiKey = apiKey;
44     }
45
46     /**
47      * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getCommand()
48      */
49     @Override
50     protected byte[] getCommand() {
51         return new byte[] { 0x01, 0x10 };
52     }
53
54     /**
55      * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getFrameData()
56      */
57     @Override
58     protected byte[] getFrameData() {
59         byte[] b = new byte[id.length + apiKey.length];
60
61         ByteBuffer bb = ByteBuffer.wrap(b);
62
63         bb.put(ByteUtil.reverse(id));
64         bb.put(ByteUtil.reverse(apiKey));
65
66         // System.out.println(toString(bb.array()));
67         return bb.array();
68     }
69
70     /**
71      * Gets the id.
72      *
73      * @return the id
74      */
75     public byte[] getId() {
76         return id;
77     }
78
79     /**
80      * @see org.openhab.binding.sinope.internal.core.base.SinopeRequest#getReplyAnswer(java.io.InputStream)
81      */
82     @Override
83     public SinopeApiLoginAnswer getReplyAnswer(InputStream r) throws IOException {
84         return new SinopeApiLoginAnswer(r);
85     }
86 }