]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth.am43] null annotations (#13972)
authorlsiepel <leosiepel@gmail.com>
Tue, 27 Dec 2022 15:27:19 +0000 (16:27 +0100)
committerGitHub <noreply@github.com>
Tue, 27 Dec 2022 15:27:19 +0000 (16:27 +0100)
* null annotations forbidden package
* improve createChecksum
* spotless + typo

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43Configuration.java
bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/command/AM43Command.java
bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/data/ControlAction.java
bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/data/Direction.java
bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/data/OperationMode.java

index d0fbc157e74babee79c363540718ce02c168d1bf..a6b1efc566403ec6dcadb2aab28bf65bcdb2cb1e 100644 (file)
  */
 package org.openhab.binding.bluetooth.am43.internal;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * Configuration class for AM43 Binding.
  *
  * @author Connor Petty - Initial contribution
  */
+@NonNullByDefault
 public class AM43Configuration {
 
-    public String address;
+    public String address = "";
     public int refreshInterval;
     public boolean invertPosition;
     public int commandTimeout;
index 3d67a41988c378b90309b5b598f46fcd529abe4d..2c20f1fe479aff10540100895b9b191d75c98922 100644 (file)
@@ -18,7 +18,6 @@ import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.commons.lang3.ArrayUtils;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 
@@ -121,19 +120,27 @@ public abstract class AM43Command {
     }
 
     public byte[] getRequest() {
-        byte[] value = ArrayUtils.EMPTY_BYTE_ARRAY;
-        value = ArrayUtils.add(value, HEADER_PREFIX);
-        value = ArrayUtils.add(value, header);
-        value = ArrayUtils.add(value, (byte) data.length);
-        value = ArrayUtils.addAll(value, data);
-        value = ArrayUtils.add(value, createChecksum(value));
-        return ArrayUtils.addAll(REQUEST_PREFIX, value);
+        byte[] value = new byte[4 + data.length + REQUEST_PREFIX.length];
+        System.arraycopy(REQUEST_PREFIX, 0, value, 0, REQUEST_PREFIX.length);
+        value[REQUEST_PREFIX.length] = HEADER_PREFIX;
+        value[REQUEST_PREFIX.length + 1] = header;
+        value[REQUEST_PREFIX.length + 2] = (byte) data.length;
+        System.arraycopy(data, 0, value, REQUEST_PREFIX.length + 3, data.length);
+        value[value.length - 1] = createChecksum(value, REQUEST_PREFIX.length, 3 + data.length);
+        return value;
     }
 
-    protected byte createChecksum(byte[] data) {
-        // this is a basic checksum
-        byte crc = data[0];
-        for (int i = 1; i < data.length; i++) {
+    /**
+     * A basic method to calculate the checksum
+     * 
+     * @param data source for the checksum calculation
+     * @param startIndex the zero-based start index to include in the calculation
+     * @param length the length of the range to include in the calculation
+     * @return the CRC-checksum result in {@link byte}
+     */
+    protected byte createChecksum(byte[] data, int startIndex, int length) {
+        byte crc = data[startIndex];
+        for (int i = startIndex + 1; i < startIndex + length; i++) {
             crc ^= data[i];
         }
         return crc;
index 453d5acddd868ef8f9e72bce1a810cc318ea5602..a05c7aa2ab629e8669c7cdbd0bc974de7f85a735 100644 (file)
  */
 package org.openhab.binding.bluetooth.am43.internal.data;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * The {@link ControlAction} list possible controls actions that can be sent through
  * {@link org.openhab.binding.bluetooth.am43.internal.command.ControlCommand}
  *
  * @author Connor Petty - Initial contribution
  */
+@NonNullByDefault
 public enum ControlAction {
     CLOSE(0xee),
     OPEN(0xdd),
index 0e8bf45a260877870677bc3a21d69179e6df5a22..c2314632c735205414d7ae26d1d2efe69d57ef83 100644 (file)
  */
 package org.openhab.binding.bluetooth.am43.internal.data;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * This is an enum representing possible motor direction settings
  *
  * @author Connor Petty - Initial contribution
  */
+@NonNullByDefault
 public enum Direction {
     Forward(0x1),
     Reverse(0x0);
index 7fbee5c3ab5918747fe89d82b8bdf9c1b11b03ae..63b03e62c6b7c63221ad78654d126c0edab9889a 100644 (file)
  */
 package org.openhab.binding.bluetooth.am43.internal.data;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * This is an enum representing possible motor modes settings
  *
  * @author Connor Petty - Initial contribution
  */
+@NonNullByDefault
 public enum OperationMode {
     Inching(0x1),
     Continuous(0x0);