How to convert String to Bitset

Hi There,

i am just in the Process to cearte a notification rule. This rule should use a String as Command and determine from this string the type of notification, the receiver(s) of the notification and the text itsself. Type and receiver are simple Hex value and with Bitchecks i determine type and receiber example 0x01 -> Thats me, 0x02 -> my wife and 0x03 should be my wife and me. So the receiver is bitwise coded.

My Problem is now to create a BitSet from 0x03 to check the receivers. How is this possible in a rule.

Thanks
Thomas

Are you needing to test for these bit checks in your rule before you send the notification, or do you need to send the notification with these bits as part of the message?

If before, why? There are dozens of simpler and easier to code approaches than this.

In any case, dealing with binary data is, in my opinion, a major pain in Java and by extension the Rules DSL. But I need more information to help. Can you post something like an example rule with some comments to show what you are trying to accomplish?

If I understand this correctly, what I would do is something like:

switch(destinationStr) {
    case "0x01": // me
    case "0x02": // wife
    case "0x03": // both
}

If you don’t have to convert to binary, don’t.

Find below a parts of my unfinished rule. The idea ist to use the bit position to select the destination. Based on the code i am able to create any combination of receivers and do not have to check any combination. It is possible to work with bit masks, but i think a bitset is more elegant

// The bit masks
val MsgTarget001	= 0x01 // 0000 0001  Thomas
val MsgTarget002	= 0x02 // 0000 0010  Tina
val MsgTarget003	= 0x04 // 0000 0100  openHAB
val MsgTarget004	= 0x08 // 0000 1000  Twitter

// The bitset (Does not work) each bit position represents a receiver. If bitmasks are added you cpuld create any combination 
MessageTarget =  BitSet.valueOf(DatatypeConverter.parseHexBinary(Notification.get(1).substring(2)))

// This is the check which receiver shoud receive the message
if (MessageTarget.get(MsgTarget001)) { // Thomas
    // Send some Kind of Message
}
if (MessageTarget.get(MsgTarget002)) { // Tina
    // Send some Kind of Message
}
if (MessageTarget.get(MsgTarget003)) { // openHAB
    // Send some Kind of Message
}
if (MessageTarget.get(MsgTarget004)) { // Twitter
    // Send some Kind of Message
}

Hope this make some thin more clear. The intention is to create the mother of all notigfication rules.

Thomas