timlow84
asked on
Using Java X10 to get Status Request from CM11
I'm currently using Java X10 API (http://x10.homelinux.org/docs/) that utilized JavaComm (http://java.sun.com/products/javacomm/reference/api/index.html) to communicate with a CM11 device that's connected to my computer throught a serial port.
Here's the protocol that CM11 uses (http://www.x10pro.com/pro/pdf/cm11a_protocol.txt).
I've managed to send out X10 signals to a AM12 device connected to a standing fan to make it on/off. I'm now trying to send a Status Request command to the CM11 (0x8b), and apparently the CM11 sends data back to me through the serial port which i read off using the inputbuffer/outputbuffer.
I need to get bit range 31-16 as defined in the CM11 protocol so that i can monitor if a device is switched on/off from the byte that i picked off the inputbuffer.
Here's the protocol that CM11 uses (http://www.x10pro.com/pro/pdf/cm11a_protocol.txt).
I've managed to send out X10 signals to a AM12 device connected to a standing fan to make it on/off. I'm now trying to send a Status Request command to the CM11 (0x8b), and apparently the CM11 sends data back to me through the serial port which i read off using the inputbuffer/outputbuffer.
I need to get bit range 31-16 as defined in the CM11 protocol so that i can monitor if a device is switched on/off from the byte that i picked off the inputbuffer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Upon sending the status command, i would get 16 bytes back... and the status request is
-------------------------- ---------- ---------- ---------- ---------- ---------- ----------
# Bit range Description
# 111 to 96 Battery timer (set to 0xffff on reset) (Byte 0-1)
# 95 to 88 Current time (seconds) (Byte 2 )
# 87 to 80 Current time (minutes ranging from 0 to 119) (Byte 3)
# 79 to 72 Current time (hours/2, ranging from 0 to 11) (Byte 4)
# 71 to 63 Current year day (MSB bit 63) (Byte 5+)
# 62 to 56 Day mask (SMTWTFS) (Byte 6-)
# 55 to 52 Monitored house code (Byte 7 lo)
# 51 to 48 Firmware revision level 0 to 15 (Byte 7 hi)
# 47 to 32 Currently addressed monitored devices (Byte 8-9)
# 31 to 16 On / Off status of the monitored devices (Byte 10-11)
# 15 to 0 Dim status of the monitored devices (Byte 12-13)
-------------------------- ---------- ---------- ---------- ---------- ---------- ----------
Scenario: i'm reading data off the inputstream in a thread... if i detect nothing in the outputstream, i'll attempt to read incoming data... here's a sniplet of my code...
public class CM11ASerialController implements Runnable, Controller
{
private DataInputStream fromX10;
public static final byte TIME_POLL = ((byte) 0xA5);
public static final byte DATA_POLL = ((byte) 0x5A);
...
...
public void run()
{
byte nextByte = (byte) fromX10.readByte();
switch(nextByte)
{
// detect that a status request is sent, and handle the status request
// in a function handleStatusRequest();
case TIME_POLL : setInterfaceTime();
break;
case DATA_POLL : handleData();
break;
default : handleChecksum(nextByte);
}
if (running && (fromX10.available() == 0))
{
System.out.println("Sendin g data from SerialPort to Interface");
initiateNextCommand();
}
...
}
i want to be able to...
(1) detect that a status request, and then pass the byte to a function in which i'll handle the data
(2) inside the function where i'm able to get the On / Off status of the monitored devices throught [bit range 31 to 16] / [Byte 10-11]...
--------------------------
# Bit range Description
# 111 to 96 Battery timer (set to 0xffff on reset) (Byte 0-1)
# 95 to 88 Current time (seconds) (Byte 2 )
# 87 to 80 Current time (minutes ranging from 0 to 119) (Byte 3)
# 79 to 72 Current time (hours/2, ranging from 0 to 11) (Byte 4)
# 71 to 63 Current year day (MSB bit 63) (Byte 5+)
# 62 to 56 Day mask (SMTWTFS) (Byte 6-)
# 55 to 52 Monitored house code (Byte 7 lo)
# 51 to 48 Firmware revision level 0 to 15 (Byte 7 hi)
# 47 to 32 Currently addressed monitored devices (Byte 8-9)
# 31 to 16 On / Off status of the monitored devices (Byte 10-11)
# 15 to 0 Dim status of the monitored devices (Byte 12-13)
--------------------------
Scenario: i'm reading data off the inputstream in a thread... if i detect nothing in the outputstream, i'll attempt to read incoming data... here's a sniplet of my code...
public class CM11ASerialController implements Runnable, Controller
{
private DataInputStream fromX10;
public static final byte TIME_POLL = ((byte) 0xA5);
public static final byte DATA_POLL = ((byte) 0x5A);
...
...
public void run()
{
byte nextByte = (byte) fromX10.readByte();
switch(nextByte)
{
// detect that a status request is sent, and handle the status request
// in a function handleStatusRequest();
case TIME_POLL : setInterfaceTime();
break;
case DATA_POLL : handleData();
break;
default : handleChecksum(nextByte);
}
if (running && (fromX10.available() == 0))
{
System.out.println("Sendin
initiateNextCommand();
}
...
}
i want to be able to...
(1) detect that a status request, and then pass the byte to a function in which i'll handle the data
(2) inside the function where i'm able to get the On / Off status of the monitored devices throught [bit range 31 to 16] / [Byte 10-11]...
You have to do it like I said in my first comment, right shift the value you need as many positions as the number of the bits you want to get.
I meant from 24 to 31.