Updating Global Cache Binding for bi-directional serial interface

Hi! I have noticed that the github repository has received updates implementing bi-directional support for serial devices.

I’d like to know when this update can be expected to be able to install over paper-ui. I’d love to have this functionality for the feedback communication with my AV equipment.

Thanks!

Hi @Oleksandr_Danylchenk The functionality is in the latest snapshot, so if you are on snapshot releases, it should be available now. If not on snapshot builds, it will be in the OH 2.1 release (the timing of which I’m not certain).

If you install it, let me know if you run into any issues. It’s been tested by myself and one other person so far.

One other thing…

If any of your AV devices use a binary protocol (i.e. use non-printable characters), I can give you a code snippet that URL decodes the received string, then converts it into a byte array. It’s not much code, but it took me a while to get it right for my own rules.

@mhilbush

Hi Mark. I’m not on snapshot releases, unfortunately.

I’m running standard openhabian on the raspberry pi. Didn’t do any tweaks to it so far.

I’m not able to find a step-by-step guide how to switch to the snapshot releases. Or how to install a single snapshot add on.

If you have spare time, could you please point me to the right direction?

Thanks!

The feedback I’m looking for is the rs232 protocol for marantz receivers. It looks like:

@VOL:0-18

So it’s not a binary, thankfully.

Here are a couple links that explain how to change versions, or how to install a newer binding than the one that came with the distro. I’ve not done this myself (I’ve been on snapshot builds from the beginning), so I can’t provide much guidance other than these links.

http://docs.openhab.org/installation/linux.html#changing-versions

1 Like

openHABian also offers the option to switch over to the latest stable build as described in the first link. Check out sudo openhabian-config

1 Like

@mhilbush, @ThomDietrich

Thanks for great suggestions.

Switched to the snapshot releases using these steps:

Will be doing more testing and give feedback soon.

Mark, would you mind posting your code snippet? I have some devices that need to decode URL into regular text. Thanks!

Sure. Here you go.

import java.util.concurrent.locks.ReentrantLock
import java.net.URLDecoder

var ReentrantLock lock  = new ReentrantLock()

rule "GlobalCache Receive"
when
    Item TestRule_Switch received command ON
then
    lock.lock
    try {
        var String encodedString
        var String decodedString
        var byte[] decodedBytes

        logInfo("gc-receive", "")

        // Example 1
        logInfo("gc-receive", "Example 1: encoded string containing all printable characters (easy)")
        encodedString = "%3CThis%20is%20a%20%26simple%26%20example!%3E"
        logInfo("gc-receive", "Encoded string is '" + encodedString + "'")

        decodedString = URLDecoder::decode(encodedString, "ISO-8859-1")
        logInfo("gc-receive", "Decoded string is '" + decodedString + "'")
        if (decodedString.contains("simple")) {
            logInfo("gc-receive", "Yep. This is a simple example")
        }

        logInfo("gc-receive", "")

        // Example 2
        logInfo("gc-receive", "Example 2: encoded string containing unprintable characters (more complex)")
        encodedString = "%F0%02ABCDE%03"
        logInfo("gc-receive", "Encoded string is '" + encodedString + "'")

        decodedBytes = (URLDecoder::decode(encodedString, "ISO-8859-1")).getBytes("ISO-8859-1")
        var int decodedLength = decodedBytes.length

        var int b
        val int SOH = 0xF0
        val int STX = 0x02
        val int ETX = 0x03

        var int sohByte = decodedBytes.get(0).bitwiseAnd(0xff)
        var int stxByte = decodedBytes.get(1).bitwiseAnd(0xff)
        var int etxByte = decodedBytes.get(decodedLength - 1).bitwiseAnd(0xff)

        if(sohByte == SOH) {
            logInfo("gc-receive", "Found valid start of header")
            if (stxByte == STX && etxByte == ETX) {
                logInfo("gc-receive", "Found valid start and end of text")
                var int counter = 0
                while (decodedLength > 0) {
                    b = decodedBytes.get(counter).bitwiseAnd(0xff)
                    logInfo("gc-receive", "byte[" + counter + "]=" + Integer::toHexString(b))
                    counter = counter + 1
                    decodedLength = decodedLength - 1
                }
            } else {
                logInfo("gc-receive", "Didn't find valid start and end of text")
            }
        } else {
            logInfo("gc-receive", "Didn't find valid start of header")
        }
    } finally  {
        lock.unlock
    }
end

Which should produce output like this in the log

2018-01-18 15:31:33.126 [INFO ] [se.smarthome.model.script.gc-receive] -
2018-01-18 15:31:33.127 [INFO ] [se.smarthome.model.script.gc-receive] - Example 1: encoded string containing all printable characters (easy)
2018-01-18 15:31:33.127 [INFO ] [se.smarthome.model.script.gc-receive] - Encoded string is '%3CThis%20is%20a%20%26simple%26%20example!%3E'
2018-01-18 15:31:33.129 [INFO ] [se.smarthome.model.script.gc-receive] - Decoded string is '<This is a &simple& example!>'
2018-01-18 15:31:33.130 [INFO ] [se.smarthome.model.script.gc-receive] - This is a simple example
2018-01-18 15:31:33.130 [INFO ] [se.smarthome.model.script.gc-receive] -
2018-01-18 15:31:33.131 [INFO ] [se.smarthome.model.script.gc-receive] - Example 2: encoded string containg unprintable characters (more complex)
2018-01-18 15:31:33.131 [INFO ] [se.smarthome.model.script.gc-receive] - Encoded string is '%F0%02ABCDE%03'
2018-01-18 15:31:33.133 [INFO ] [se.smarthome.model.script.gc-receive] - Found valid start of header
2018-01-18 15:31:33.134 [INFO ] [se.smarthome.model.script.gc-receive] - Found valid start and end of text
2018-01-18 15:31:33.136 [INFO ] [se.smarthome.model.script.gc-receive] - byte[0]=f0
2018-01-18 15:31:33.138 [INFO ] [se.smarthome.model.script.gc-receive] - byte[1]=2
2018-01-18 15:31:33.139 [INFO ] [se.smarthome.model.script.gc-receive] - byte[2]=41
2018-01-18 15:31:33.141 [INFO ] [se.smarthome.model.script.gc-receive] - byte[3]=42
2018-01-18 15:31:33.143 [INFO ] [se.smarthome.model.script.gc-receive] - byte[4]=43
2018-01-18 15:31:33.145 [INFO ] [se.smarthome.model.script.gc-receive] - byte[5]=44
2018-01-18 15:31:33.146 [INFO ] [se.smarthome.model.script.gc-receive] - byte[6]=45
2018-01-18 15:31:33.148 [INFO ] [se.smarthome.model.script.gc-receive] - byte[7]=3