Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

[AlarmDecoder] Added support for AlarmDecoder LRR Protocol #5019

Merged
merged 3 commits into from Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,7 +12,7 @@

/**
* The various message types that come from the ad2usb/ad2pi interface
*
*
* @author Bernd Pfrommer
* @since 1.6.0
*/
Expand All @@ -21,8 +21,9 @@ public enum ADMsgType {
RFX(1), // wireless message
EXP(2), // zone expander message
REL(3), // relay message
INVALID(4), // invalid message
NUMTYPES(5); // total number of types
LRR(4), // long range radio message
INVALID(5), // invalid message
NUMTYPES(6); // total number of types

private final int m_type;

Expand All @@ -31,15 +32,15 @@ public enum ADMsgType {
}

/**
*
*
* @return corresponding integer value
*/
public int getValue() {
return m_type;
}

/**
*
*
* @return true if it is a valid message type
*/
public boolean isValid() {
Expand All @@ -48,7 +49,7 @@ public boolean isValid() {

/**
* Determine the message type from a 3-letter string
*
*
* @param s the 3-letter string
* @return the message type (potentially INVALID)
*/
Expand All @@ -62,7 +63,7 @@ public static ADMsgType s_fromString(String s) {

/**
* Test if 3-letter string is a message type
*
*
* @param s string to test
* @return true if string is a valid message type
*/
Expand All @@ -72,7 +73,7 @@ public static boolean s_isValid(String s) {

/**
* Test if string contains a valid message type
*
*
* @param s string to test
* @return true if string contains a valid message type
*/
Expand All @@ -94,6 +95,7 @@ public static boolean s_containsValidMsgType(String s) {
s_strToType.put("RFX", RFX);
s_strToType.put("EXP", EXP);
s_strToType.put("REL", REL);
s_strToType.put("LRR", LRR);
s_strToType.put("INVALID", INVALID);
}
}
Expand Up @@ -57,7 +57,7 @@
* @author Bernd Pfrommer
* @since 1.6.0
*/
public class AlarmDecoderBinding extends AbstractActiveBinding<AlarmDecoderBindingProvider>implements ManagedService {
public class AlarmDecoderBinding extends AbstractActiveBinding<AlarmDecoderBindingProvider> implements ManagedService {

private static final Logger logger = LoggerFactory.getLogger(AlarmDecoderBinding.class);

Expand Down Expand Up @@ -415,6 +415,9 @@ public void run() {
case RFX:
parseRFMessage(msg);
break;
case LRR:
parseLRRMessage(msg);
break;
case INVALID:
default:
break;
Expand Down Expand Up @@ -548,6 +551,9 @@ private void setUnupdatedItemsToDefault() {
case REL:
updateItem(bc, OpenClosedType.CLOSED);
break;
case LRR:
updateItem(bc, new StringType(""));
break;
case INVALID:
default:
m_unupdatedItems.remove(itemName);
Expand Down Expand Up @@ -612,6 +618,19 @@ private void parseRFMessage(String msg) throws MessageParseException {
}
}

private void parseLRRMessage(String msg) throws MessageParseException {
String parts[] = splitMessage(msg);
if (parts.length != 3) {
throw new MessageParseException("need 3 comma separated fields in msg");
}

ArrayList<AlarmDecoderBindingConfig> bcl = getItems(ADMsgType.LRR, null, null);
for (AlarmDecoderBindingConfig c : bcl) {
updateItem(c, new StringType(String.join(",", parts)));
}

}

private String[] splitMessage(String msg) throws MessageParseException {
String parts[] = msg.split(":");
if (parts.length != 2) {
Expand Down Expand Up @@ -697,6 +716,7 @@ private static ADMsgType s_getMsgType(String s) {
s_startToMsgType.put("!SER", ADMsgType.INVALID);
s_startToMsgType.put("!RFX", ADMsgType.RFX);
s_startToMsgType.put("!EXP", ADMsgType.EXP);
s_startToMsgType.put("!LRR", ADMsgType.LRR);
}

/**
Expand Down
Expand Up @@ -136,7 +136,7 @@ public void processBindingConfiguration(String context, Item item, String bindin

/**
* Removes existing item configurations
*
*
* @param bcl array list of binding configs to be checked
* @param item item to be checked for
*/
Expand All @@ -151,7 +151,7 @@ private static void removeExisting(ArrayList<AlarmDecoderBindingConfig> bcl, Ite

/**
* Parses binding configuration string
*
*
* @param bindingConfig
* @return array with ["SEND", "TEXT"], or [type, address, feature + parameters]
* @throws BindingConfigParseException if invalid binding string is found
Expand Down Expand Up @@ -215,13 +215,14 @@ static private void s_parseParameters(String itemName, String[] params, int offs

/**
* Address validator
*
*
* @param type the known msg type of the configuration
* @param addr the address string of the configuration
* @return true if valid address for given type
*/
static private boolean s_isValidAddress(ADMsgType type, String addr) {
switch (type) {
case LRR:
case KPM:
return (addr.matches("[0-9]+") || addr.equalsIgnoreCase("any"));
case RFX:
Expand Down