org.universAAL.lddi.fs20.connect
Class FHZ1000PC

Package class diagram package FHZ1000PC
java.lang.Object
  extended by org.universAAL.lddi.fs20.connect.FHZ1000PC

public class FHZ1000PC
extends Object

This class encapsulates an interface towards the FHZ1000PC device. It works on both Windows and Linux, with different internal access methods but the external interface is the same. FHZ1000PC is part of the FS20-system which is a home automation system with devices like dimmers, switches, rain sensors and so on. The devices talk with each other via radio messages. The FHZ1000PC is a USB-based interface that allows a computer to send and receive these radio messages and thereby control and monitor the devices. Unfortunatly only a german control program without any external API accompany the device, so I had to write this interface to communicate with it. The FHZ1000PC hardware is originally built for serial communication, but an FTDI-chip (http://www.ftdichip.com) is used internally to convert the serial communication to USB. In Windows The FTDI-drivers are installed when the FHZ1000PC software is installed, and API software for those drivers are provided free by FTDI. Those API:s are C-based, so some interface class is needed to access it from Java. Such an interface is provided by https://jd2xx.dev.java.net. This interface is released with a Berkeley Software Distribution (BSD) License. This interface is implemented in two files which are needed to use this interface: - jd2xx.dll - jd2xx.jar The http://fhz4linux.info/tiki-index.php site provided me with information on the serial protocol that FHZ1000PC uses. I Linux we access the device directly via the serial interface. We only have to persuade Linux that it really is a serial device. This is described on: http://fhz4linux.info/tiki-index.php?page=Driver+installation

Author:
Stefan Strömberg

Nested Class Summary
static interface FHZ1000PC.FHZ1000Device
          An interface to the "raw" FHZ1000 device where you can read and write data to it.
 class FHZ1000PC.FHZ1000SerialDevice
          When running on Linux, we access the USB-device via generic serial drivers for FTDI-chips.
 class FHZ1000PC.JD2XXFHZ1000Device
          When running on Windows, we access the USB-device via FTDI-specific drivers to access the device.
 
Field Summary
static byte COMMAND_DELIVERY_STATE
           
static byte COMMAND_DIM_DOWN
           
static byte COMMAND_DIM_LOOP
           
static byte COMMAND_DIM_UP
           
static byte COMMAND_DIM1
           
static byte COMMAND_OFF
           
static byte COMMAND_ON
           
static byte COMMAND_TIMER_PROG
           
static byte COMMAND_TOGGLE
           
protected  FHZ1000PC.FHZ1000Device m_Device
           
protected  FS20EventListener m_EventListener
           
protected  String m_PortName
           
 
Constructor Summary
FHZ1000PC(String portName)
           
 
Method Summary
static String binFS20ByteToString(int value, int bits)
          Converts an integer address to the "base 4 + 1" format used by FS20 to denote the addresses for buttons and devices.
 void deviceEvent()
           
 void fs20Init()
          Send FS20Init command to the FHZ1000PC device.
protected  byte[] read()
          Reads a complete message from the FHZ1000PC device and returns the payload of the message including telegram type and checksum.
 void registerEventListener(FS20EventListener ev)
           
 void sendFS20Command(int houseCode, byte button, byte command)
          Send a command (for example COMMAND_DIM_DOWN) to a FS20 device (for example a dimmer) via the FHZ1000PC.
static int StringFS20ToInt(String value)
          Converts an address string in the "base 4 + 1" format used by FS20 to a binary byte format actually used on the protocol.
 void unregisterEventListener()
           
protected  int write(byte[] data, byte telegramType)
          Sends an string of bytes to the FHZ1000PC device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMAND_OFF

public static final byte COMMAND_OFF
See Also:
Constant Field Values

COMMAND_DIM1

public static final byte COMMAND_DIM1
See Also:
Constant Field Values

COMMAND_ON

public static final byte COMMAND_ON
See Also:
Constant Field Values

COMMAND_DIM_LOOP

public static final byte COMMAND_DIM_LOOP
See Also:
Constant Field Values

COMMAND_DIM_DOWN

public static final byte COMMAND_DIM_DOWN
See Also:
Constant Field Values

COMMAND_DIM_UP

public static final byte COMMAND_DIM_UP
See Also:
Constant Field Values

COMMAND_TOGGLE

public static final byte COMMAND_TOGGLE
See Also:
Constant Field Values

COMMAND_TIMER_PROG

public static final byte COMMAND_TIMER_PROG
See Also:
Constant Field Values

COMMAND_DELIVERY_STATE

public static final byte COMMAND_DELIVERY_STATE
See Also:
Constant Field Values

m_Device

protected FHZ1000PC.FHZ1000Device m_Device

m_EventListener

protected FS20EventListener m_EventListener

m_PortName

protected String m_PortName
Constructor Detail

FHZ1000PC

public FHZ1000PC(String portName)
          throws IOException
Throws:
IOException
Method Detail

fs20Init

public void fs20Init()
              throws IOException
Send FS20Init command to the FHZ1000PC device.

Throws:
IOException

sendFS20Command

public void sendFS20Command(int houseCode,
                            byte button,
                            byte command)
                     throws IOException
Send a command (for example COMMAND_DIM_DOWN) to a FS20 device (for example a dimmer) via the FHZ1000PC. The FS20 device is addressed via house code and button id.

Parameters:
houseCode - 16 bit House Code of the FS20 device in binary form, not the 1111 2222-form.
button - 8 bit button id
command - FS20 Command (for example COMMAND_DIM_DOWN)
Throws:
IOException

registerEventListener

public void registerEventListener(FS20EventListener ev)

unregisterEventListener

public void unregisterEventListener()
                             throws IOException
Throws:
IOException

deviceEvent

public void deviceEvent()

write

protected int write(byte[] data,
                    byte telegramType)
             throws IOException
Sends an string of bytes to the FHZ1000PC device. The method will add the required header information including checksum.

Parameters:
data - Array of bytes to send to device
telegramType - Type of message
Returns:
Number of bytes actually written to device
Throws:
IOException

read

protected byte[] read()
               throws IOException
Reads a complete message from the FHZ1000PC device and returns the payload of the message including telegram type and checksum. The actual message begins at index 2 in the array, index 0 is the telegram type and index 1 is the checksum. If no data was available before timeout an empty array is returned.

Returns:
bytes read including telegram type and checksum
Throws:
IOException

binFS20ByteToString

public static String binFS20ByteToString(int value,
                                         int bits)
Converts an integer address to the "base 4 + 1" format used by FS20 to denote the addresses for buttons and devices.

Parameters:
value - The binary value to convert
bits - Number of bits to convert, usually 8 or 16.
Returns:
the address in the "11224411"-format.

StringFS20ToInt

public static int StringFS20ToInt(String value)
Converts an address string in the "base 4 + 1" format used by FS20 to a binary byte format actually used on the protocol.

Parameters:
value - The address string to convert
Returns:
the corresponding binary value


Copyright © 2014 universAAL Consortium. All Rights Reserved.