Skip to content

remove the use of JAXB (javax.xml.bind) which has been removed from J… #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 130 additions & 124 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,132 +27,138 @@
- Christian Fischer (computerlyrik)
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.mob41.blapi</groupId>
<artifactId>broadlink-java-api</artifactId>
<packaging>jar</packaging>
<groupId>com.github.mob41.blapi</groupId>
<artifactId>broadlink-java-api</artifactId>
<packaging>jar</packaging>

<name>broadlink-java-api</name>
<description>A clean, hacked Broadlink API for Java</description>
<url>http://github.com/mob41/broadlink-java-api</url>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>

<developers>
<developer>
<name>Anthony Law</name>
<email>anthonylaw0401@gmail.com</email>
<organization>Anthony Law</organization>
<organizationUrl>http://github.com/mob41</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/mob41/broadlink-java-api.git</connection>
<developerConnection>scm:git:ssh://github.com:mob41/broadlink-java-api.git</developerConnection>
<url>http://github.com/mob41/broadlink-java-api/tree/master</url>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<name>broadlink-java-api</name>
<description>A clean, hacked Broadlink API for Java</description>
<url>http://github.com/mob41/broadlink-java-api</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check />
</configuration>
</plugin>
</plugins>
</build>

<version>1.0.1</version>
<developers>
<developer>
<name>Anthony Law</name>
<email>anthonylaw0401@gmail.com</email>
<organization>Anthony Law</organization>
<organizationUrl>http://github.com/mob41</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/mob41/broadlink-java-api.git</connection>
<developerConnection>scm:git:ssh://github.com:mob41/broadlink-java-api.git</developerConnection>
<url>http://github.com/mob41/broadlink-java-api/tree/master</url>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
</plugin>
</plugins>
</build>

<version>1.0.1</version>
</project>
8 changes: 4 additions & 4 deletions src/main/java/com/github/mob41/blapi/A1Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import java.io.IOException;
import java.net.DatagramPacket;

import javax.xml.bind.DatatypeConverter;

import com.github.mob41.blapi.mac.Mac;
import com.github.mob41.blapi.pkt.CmdPayload;
import com.github.mob41.blapi.pkt.Payload;

import static com.github.mob41.blapi.ByteToHexString.*;

public class A1Device extends BLDevice {

public A1Device(String host, Mac mac) throws IOException {
Expand Down Expand Up @@ -68,13 +68,13 @@ public byte[] getData() {
});
byte[] data = packet.getData();

log.debug("A1 check sensors received encrypted bytes: " + DatatypeConverter.printHexBinary(data));
log.debug("A1 check sensors received encrypted bytes: " + toHexString(data));

int err = data[0x22] | (data[0x23] << 8);

if (err == 0) {
byte[] pl = decryptFromDeviceMessage(data);
log.debug("A1 check sensors received bytes (decrypted):" + DatatypeConverter.printHexBinary(pl));
log.debug("A1 check sensors received bytes (decrypted):" + toHexString(pl));

float temp = (float) ((pl[0x4] * 10 + pl[0x5]) / 10.0);
float hum = (float) ((pl[0x6] * 10 + pl[0x7]) / 10.0);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/github/mob41/blapi/BLDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import java.util.List;
import java.util.Random;

import javax.xml.bind.DatatypeConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -51,6 +49,8 @@
import com.github.mob41.blapi.pkt.auth.AuthCmdPayload;
import com.github.mob41.blapi.pkt.dis.DiscoveryPacket;

import static com.github.mob41.blapi.ByteToHexString.*;

/**
* This is the base class of all Broadlink devices (e.g. SP1, RMPro)
*
Expand Down Expand Up @@ -389,7 +389,7 @@ public boolean auth(boolean reauth) throws IOException {
log.debug("auth Sending CmdPacket with AuthCmdPayload: cmd=" + Integer.toHexString(sendPayload.getCommand())
+ " len=" + sendPayload.getPayload().getData().length);

log.debug("auth AuthPayload initial bytes to send: {}", DatatypeConverter.printHexBinary(sendPayload.getPayload().getData()));
log.debug("auth AuthPayload initial bytes to send: {}", toHexString(sendPayload.getPayload().getData()));

DatagramPacket recvPack = sendCmdPkt(10000, 2048, sendPayload);

Expand All @@ -401,7 +401,7 @@ public boolean auth(boolean reauth) throws IOException {
return false;
}

log.debug("auth recv encrypted data bytes (" + data.length +") after initial req: {}", DatatypeConverter.printHexBinary(data));
log.debug("auth recv encrypted data bytes (" + data.length +") after initial req: {}", toHexString(data));

byte[] payload = null;
try {
Expand All @@ -417,11 +417,11 @@ public boolean auth(boolean reauth) throws IOException {
return false;
}

log.debug("auth Packet received payload bytes: " + DatatypeConverter.printHexBinary(payload));
log.debug("auth Packet received payload bytes: " + toHexString(payload));

key = subbytes(payload, 0x04, 0x14);

log.debug("auth Packet received key bytes: " + DatatypeConverter.printHexBinary(key));
log.debug("auth Packet received key bytes: " + toHexString(key));

if (key.length % 16 != 0) {
log.error("auth Received key len is not a multiple of 16! Aborting");
Expand All @@ -434,7 +434,7 @@ public boolean auth(boolean reauth) throws IOException {

id = subbytes(payload, 0x00, 0x04);

log.debug("auth Packet received id bytes: " + DatatypeConverter.printHexBinary(id) + " with ID len=" + id.length);
log.debug("auth Packet received id bytes: " + toHexString(id) + " with ID len=" + id.length);

log.debug("auth End of authentication method");
alreadyAuthorized = true;
Expand Down Expand Up @@ -530,7 +530,7 @@ public DatagramPacket sendCmdPkt(int timeout, int bufSize, CmdPayload cmdPayload
public DatagramPacket sendCmdPkt(InetAddress sourceIpAddr, int sourcePort, int timeout, int bufSize,
CmdPayload cmdPayload) throws IOException {
CmdPacket cmdPkt = new CmdPacket(mac, pktCount++, id, aes, cmdPayload);
log.debug("sendCmdPkt - Send Command Packet bytes: {}", DatatypeConverter.printHexBinary(cmdPkt.getData()));
log.debug("sendCmdPkt - Send Command Packet bytes: {}", toHexString(cmdPkt.getData()));
return sendPkt(sock, cmdPkt, InetAddress.getByName(host), 80, timeout, bufSize);
}

Expand Down Expand Up @@ -1041,7 +1041,7 @@ public static DatagramPacket sendPkt(DatagramSocket sock, Packet pkt, InetAddres
}
}

log.debug("sendPkt - recv data bytes (" + recepack.getData().length +") after initial req: {}", DatatypeConverter.printHexBinary(recepack.getData()));
log.debug("sendPkt - recv data bytes (" + recepack.getData().length +") after initial req: {}", toHexString(recepack.getData()));
recepack.setData(removeNullsFromEnd(recepack.getData(), 0));
return recepack;
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/github/mob41/blapi/ByteToHexString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.mob41.blapi;

public final class ByteToHexString {
private static final char[] hexCode = "0123456789ABCDEF".toCharArray();

private ByteToHexString() {
}

/**
* Converts the given byte array to a hex string where each byte is represented by exactly two characters.
* For example, a byte
*
* @param data the array to convert
* @return the resulting hex string
*/
public static String toHexString(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]);
}
return r.toString();
}
}
Loading