public abstract class BLDevice extends Object implements Closeable
| Modifier | Constructor and Description |
|---|---|
protected |
BLDevice(short deviceType,
String deviceDesc,
String host,
Mac mac)
Constructs a
BLDevice, with a device type (constants),
hostname and MAC address |
| Modifier and Type | Method and Description |
|---|---|
boolean |
auth()
Compatibility with previous code
|
boolean |
auth(boolean reauth)
Authenticates with the broadlink device, before any other control
commands
|
static byte[] |
chgLen(byte[] data,
int newLen) |
void |
close()
Releases the resources of this
BLDevice |
static BLDevice |
createInstance(short deviceType,
String host,
Mac mac)
Creates a Broadlink device client
|
protected byte[] |
decryptFromDeviceMessage(byte[] encData) |
static BLDevice[] |
discoverDevices()
Discover Broadlink devices in the local network, with
default timeout |
static BLDevice[] |
discoverDevices(InetAddress sourceIpAddr,
int sourcePort,
int timeout)
Discover Broadlink devices in the network, binded with a specific IP
address
|
static BLDevice[] |
discoverDevices(int timeout)
Discover Broadlink devices in the local network
|
AES |
getAes() |
static String |
getDescOfType(short devType) |
String |
getDeviceDescription()
Returns a friendly description of this BLDevice
|
short |
getDeviceType()
Returns the device type of this Broadlink device
|
String |
getHost()
Returns this Broadlink device's hostname / IP address
|
Mac |
getMac()
Returns this Broadlink device's MAC address
|
byte[] |
getRawPayloadBytesPadded(byte[] data)
Get Payload without header and padded for decryption.
|
static byte[] |
removeNullsFromEnd(byte[] data,
int offset)
Misc: Pull bytes out from end of array until a non null is detected
|
static byte[] |
reverseBytes(byte[] data)
Misc: Reverse the byte array
|
DatagramPacket |
sendCmdPkt(CmdPayload cmdPayload)
Sends a command packet from localhost to Broadlink device, with buffer
size 1024 bytes, 10 seconds timeout
Before any commands to be sent to the device, auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV. |
DatagramPacket |
sendCmdPkt(InetAddress sourceIpAddr,
int sourcePort,
int timeout,
int bufSize,
CmdPayload cmdPayload)
Binds to a specific IP address and sends a command packet to Broadlink
device
Before any commands to be sent to the device, auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV. |
DatagramPacket |
sendCmdPkt(int timeout,
CmdPayload cmdPayload)
Sends a command packet from localhost to Broadlink device, with default
buffer size 1024 bytes
Before any commands to be sent to the device, auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV. |
DatagramPacket |
sendCmdPkt(int timeout,
int bufSize,
CmdPayload cmdPayload)
Sends a command packet from localhost to Broadlink device
Before any commands to be sent to the device, auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV. |
static DatagramPacket |
sendPkt(DatagramSocket sock,
Packet pkt,
InetAddress destIpAddr,
int destPort,
int timeout,
int bufSize)
Sends a compiled packet to a destination host and port, and receives a
datagram from the source port specified.
|
static DatagramPacket |
sendPkt(Packet pkt,
InetAddress sourceIpAddr,
int sourcePort,
InetAddress destIpAddr,
int destPort,
int timeout,
int bufSize)
Sends a compiled packet to a destination host and port, and receives a
datagram from the source port specified.
|
static byte[] |
subbytes(byte[] data,
int start,
int end)
Picks bytes from start-set to the end-set in a bytes array
|
static byte[] |
subbytesTillNull(byte[] data,
int offset)
Misc: Pull bytes out from an array until a NULL (0) is detected
|
protected static final org.slf4j.Logger log
public static final byte[] INITIAL_KEY
public static final byte[] INITIAL_IV
public static final int DEFAULT_BYTES_SIZE
public static final short DEV_SP1
public static final short DEV_SP2
public static final short DEV_SP2_HONEYWELL_ALT1
public static final short DEV_SP2_HONEYWELL_ALT2
public static final short DEV_SP2_HONEYWELL_ALT3
public static final short DEV_SP2_HONEYWELL_ALT4
public static final short DEV_SPMINI
public static final short DEV_SP3
public static final short DEV_SPMINI2
public static final short DEV_SPMINI_OEM_ALT1
public static final short DEV_SPMINI_OEM_ALT2
public static final short DEV_SPMINI_PLUS
public static final short DEV_RM_2
public static final short DEV_RM_MINI
public static final short DEV_RM_PRO_PHICOMM
public static final short DEV_RM_2_HOME_PLUS
public static final short DEV_RM_2_2HOME_PLUS_GDT
public static final short DEV_RM_2_PRO_PLUS
public static final short DEV_RM_2_PRO_PLUS_2
public static final short DEV_RM_2_PRO_PLUS_2_BL
public static final short DEV_RM_MINI_SHATE
public static final short DEV_A1
public static final short DEV_MP1
public static final short DEV_HYSEN
public static final short DEV_FLOUREON
public static final String DESC_UNKNOWN
public static final String DESC_RM_2
public static final String DESC_RM_MINI
public static final String DESC_RM_PRO_PHICOMM
public static final String DESC_RM_2_HOME_PLUS
public static final String DESC_RM_2_2HOME_PLUS_GDT
public static final String DESC_RM_2_PRO_PLUS
public static final String DESC_RM_2_PRO_PLUS_2
public static final String DESC_RM_2_PRO_PLUS_2_BL
public static final String DESC_RM_MINI_SHATE
public static final String DESC_A1
public static final String DESC_MP1
public static final String DESC_SP1
public static final String DESC_SP2
public static final String DESC_SP2_HONEYWELL_ALT1
public static final String DESC_SP2_HONEYWELL_ALT2
public static final String DESC_SP2_HONEYWELL_ALT3
public static final String DESC_SP2_HONEYWELL_ALT4
public static final String DESC_SPMINI
public static final String DESC_SP3
public static final String DESC_SPMINI2
public static final String DESC_SPMINI_OEM_ALT1
public static final String DESC_SPMINI_OEM_ALT2
public static final String DESC_SPMINI_PLUS
public static final String DESC_HYSEN
public static final String DESC_FLOUREON
public static final int DISCOVERY_DEST_PORT
public static final int DISCOVERY_RECEIVE_BUFFER_SIZE
public static final int DEFAULT_TIMEOUT
protected BLDevice(short deviceType,
String deviceDesc,
String host,
Mac mac)
throws IOException
BLDevice, with a device type (constants),
hostname and MAC addressdeviceType - Device type constants (BLDevice.DEV_*)deviceDesc - Friendly device descriptionhost - Hostname of target Broadlink devicemac - MAC address of target Broadlink deviceIOException - Problems on constructing a datagram socketpublic void close()
BLDeviceclose in interface Closeableclose in interface AutoCloseablepublic short getDeviceType()
shortpublic String getHost()
public Mac getMac()
Mac implementationpublic AES getAes()
public String getDeviceDescription()
public boolean auth()
throws IOException
IOException - If I/O goes wrongpublic boolean auth(boolean reauth)
throws IOException
reauth - Setting this to true forces to perform re-auth with the device. Defaults not to perform re-auth.IOException - If I/O goes wrongpublic DatagramPacket sendCmdPkt(CmdPayload cmdPayload) throws IOException
auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV.cmdPayload - Command data to be sentDatagramPacket containing the byte data and sender host
information.IOException - Problems when sending the packetpublic DatagramPacket sendCmdPkt(int timeout, CmdPayload cmdPayload) throws IOException
auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV.timeout - Socket read timeoutcmdPayload - Command data to be sentDatagramPacket containing the byte data and sender host
information.IOException - Problems when sending the packetpublic DatagramPacket sendCmdPkt(int timeout, int bufSize, CmdPayload cmdPayload) throws IOException
auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV.timeout - Socket read timeoutbufSize - Receive datagram buffer sizecmdPayload - Command data to be sentDatagramPacket containing the byte data and sender host
information.IOException - Problems when sending the packetpublic DatagramPacket sendCmdPkt(InetAddress sourceIpAddr, int sourcePort, int timeout, int bufSize, CmdPayload cmdPayload) throws IOException
auth must
be ran first in order to authenticate with the device and gain a device
ID, encryption key and IV.sourceIpAddr - Bind the socket to this IP addresssourcePort - Bind the socket to this porttimeout - Socket read timeoutbufSize - Receive datagram buffer sizecmdPayload - Command data to be sentDatagramPacket containing the byte data and sender host
information.IOException - Problems when sending the packetpublic static BLDevice createInstance(short deviceType, String host, Mac mac) throws IOException
deviceType - Device type constant (BLDevice.DEV_*)host - Target Broadlink device hostnamemac - Target Broadlink device MAC addressIOException - Problems when constucting a datagram socketpublic static BLDevice[] discoverDevices() throws IOException
default timeoutBLDevice in the networkIOException - Problems when discoveringpublic static BLDevice[] discoverDevices(int timeout) throws IOException
timeout - Socket read timeoutBLDevice in the networkIOException - Problems when discoveringpublic static BLDevice[] discoverDevices(InetAddress sourceIpAddr, int sourcePort, int timeout) throws IOException
sourceIpAddr - The IP address to be bindedsourcePort - The port to be bindedtimeout - Socket read timeoutBLDevice in the networkIOException - Problems when discoveringpublic static String getDescOfType(short devType)
public static byte[] reverseBytes(byte[] data)
data - Original datapublic static byte[] removeNullsFromEnd(byte[] data,
int offset)
data - Original dataoffset - Starting offsetpublic static byte[] subbytesTillNull(byte[] data,
int offset)
data - Original dataoffset - Starting offsetpublic byte[] getRawPayloadBytesPadded(byte[] data)
data - the encrypted data message from the device and includes the headerprotected byte[] decryptFromDeviceMessage(byte[] encData)
throws Exception
Exceptionpublic static byte[] subbytes(byte[] data,
int start,
int end)
data - The bytes array to be usedstart - The starting position to be pickedend - The ending position to be pickedend - start)public static DatagramPacket sendPkt(Packet pkt, InetAddress sourceIpAddr, int sourcePort, InetAddress destIpAddr, int destPort, int timeout, int bufSize) throws IOException
pkt - The compiled packet to be sentsourceIpAddr - Source IP address to be binded for receiving datagramssourcePort - Source Port to be bineded for receiving datagramsdestIpAddr - Destination IP addressdestPort - Destination Porttimeout - Socket timeout. 0 will disable the timeoutbufSize - Receiving datagram's buffer sizeIOException - Thrown if socket timed out, cannot bind source IP and source
port, no permission, etc.public static DatagramPacket sendPkt(DatagramSocket sock, Packet pkt, InetAddress destIpAddr, int destPort, int timeout, int bufSize) throws IOException
sock - Uses an external socketpkt - The compiled packet to be sentdestIpAddr - Destination IP addressdestPort - Destination Porttimeout - Socket timeout. 0 will disable the timeoutbufSize - Receiving datagram's buffer sizeIOException - Thrown if socket timed out, cannot bind source IP and source
port, no permission, etc.public static byte[] chgLen(byte[] data,
int newLen)
Copyright © 2018. All rights reserved.