Hello,
Started to develop my Velbus Binding. First some words to explain what I had before :
My existing code
- my java code using a Jvelbus library. it's using Rxtxcom.jar, rxtxparalell.dll and rxtxserial.dll to interface with Serial/USB port.
- code :
SerialBus bus = new SerialBus("COM1");
Worker worker = new Worker(bus);
Thread t = new Thread(worker);
t.start();
where Worker class implements Runnable, PacketSentListener, PacketReceivedListener
with public void packetReceivedEvent(PacketReceivedEvent event) which get read packet from the BUS on the serial port
with public void packetSentEvent(PacketSentEvent event) which implements message sent to the BUS
public void run() {
this.bus.addPacketReceivedListener(this);
this.bus.addPacketSentListener(this);
this.bus.open();
while (running) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
...
So with Worker class, implementing PacketReceivedListener, I get message/packets from Bus and I decrypt it to reflect it in my current gui.
For action on the Bus, I am using a bus.sendBlocking(Packet) or bus.send(Packet) methods.
The Bus is synchronized to share this object correctly between thread.
This java api si a low level api, so I have to work with Hexadecimal packet and interpret command/received message.
How to integrate my existing code with openhab... but smartly
- First I would like open the bus and start worker thread via the Activator.
- Second for I will create a Provider for SwitchItem with command velbus={">[ON:switchrelay:moduleaddress:channel] >[OFF:switchrelay:moduleaddress:channel]}
- Now for the binding itself, could you give me someadvices :
1 Where can I implement my asynchronous calls to the bus? in which method?
2 Where can I implement the update of ItemState? messages coming from the bus? in which method?
By the way I hope to open my code as rest WS. Do I have to think something special now in order to develop it?
Hoping with your advices to have fast a skeleton of code that I could test.
Thks for your time
Valery