From d87c922f234c63c1055ab14558034b3afe0cf9a7 Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 17 Sep 2016 14:51:20 +0200 Subject: [PATCH 1/3] added pir6 protocol and test cases, issue #114 --- src/controller.coffee | 2 +- src/protocols/pir6.coffee | 38 ++++++++++++++++++++++++++++++++++++++ test/lib-controller.coffee | 16 ++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/protocols/pir6.coffee diff --git a/src/controller.coffee b/src/controller.coffee index 025bba8..62a658c 100644 --- a/src/controller.coffee +++ b/src/controller.coffee @@ -9,7 +9,7 @@ protocols = [ 'switch26', 'switch27', 'switch28', 'switch29', 'switch30' 'rolling1' 'dimmer1', 'dimmer2' - 'pir1', 'pir2', 'pir3', 'pir4', 'pir5' + 'pir1', 'pir2', 'pir3', 'pir4', 'pir5', 'pir6' 'contact1', 'contact2', 'contact3', 'contact4' 'generic', 'generic2' 'alarm1', 'alarm2' diff --git a/src/protocols/pir6.coffee b/src/protocols/pir6.coffee new file mode 100644 index 0000000..05fdcd7 --- /dev/null +++ b/src/protocols/pir6.coffee @@ -0,0 +1,38 @@ +module.exports = (helper) -> +# mapping for decoding + pulsesToBinaryMapping = { + '10': '1' #binary 1 + '01': '0' #binary 0 + '02': '' #footer + '03': '' #footer + } + # same for send + binaryToPulse = { + '0': '01' + '1': '10' + } + return protocolInfo = { + name: 'pir6' + type: 'pir' + values: + id: + type: "number" + presence: + type: "boolean" + brands: ["Zanbo (ZABC86-1)", "Unknown (OSW-1-3 and OTW-1-3)"] + pulseLengths: [288, 864, 8964] + pulseCounts: [50] + decodePulses: (pulses) -> + binary = helper.map(pulses, pulsesToBinaryMapping) + console.log "######", binary, helper.binaryToNumber(binary, 2, 24) + # Pulses like: '001100001110100011000011' + # Translate to the following sequence + # 0011 0000 1110 1000 1100 0011 + # xxII IIII IIII IIII IIII IIII + # I: 24 bit ID (unsigned, MSB) + # x: ignored + return result = { + id: helper.binaryToNumber(binary, 2, 24) + presence: true + } + } diff --git a/test/lib-controller.coffee b/test/lib-controller.coffee index 77698b3..a33e6c6 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -69,6 +69,18 @@ describe '#decodePulses()', -> { id: 54099, unit: 21290, presence: true } ] }, + { + protocol: 'pir6' + pulseLengths: [ 288, 864, 8964 ] + pulses: [ + '01011010010101011010100110010101101001010101101002' + '01011010010101011010100110010101101001011001010102' + ] + values: [ + { id: 6410630, presence: true } + { id: 6410640, presence: true } + ] + }, { protocol: 'weather1' pulseLengths: [456, 1990, 3940, 9236] @@ -899,13 +911,13 @@ describe '#decodePulses()', -> it "#{t.protocol} should decode the pulses", -> for pulses, i in t.pulses results = controller.decodePulses(t.pulseLengths, pulses) - assert(results.length >= 1, "pulse of #{t.protocol} should be detected.") + assert(results.length >= 1, "pulse #{pulses} of #{t.protocol} should be detected.") result = null for r in results if r.protocol is t.protocol result = r break - assert(result, "pulse of #{t.protocol} should be detected as #{t.protocol}.") + assert(result, "pulse #{pulses} of #{t.protocol} should be detected as #{t.protocol}.") assert.deepEqual(result.values, t.values[i]) ) From 5add83abac5f54988706a12b9486f5da1c38aac1 Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 17 Sep 2016 14:52:52 +0200 Subject: [PATCH 2/3] Removed debug output --- src/protocols/pir6.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/protocols/pir6.coffee b/src/protocols/pir6.coffee index 05fdcd7..6caeea9 100644 --- a/src/protocols/pir6.coffee +++ b/src/protocols/pir6.coffee @@ -24,7 +24,6 @@ module.exports = (helper) -> pulseCounts: [50] decodePulses: (pulses) -> binary = helper.map(pulses, pulsesToBinaryMapping) - console.log "######", binary, helper.binaryToNumber(binary, 2, 24) # Pulses like: '001100001110100011000011' # Translate to the following sequence # 0011 0000 1110 1000 1100 0011 From eee69d2b40a78442b483185fbb27165e0a6adc0a Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 17 Sep 2016 19:03:37 +0200 Subject: [PATCH 3/3] Added testcase Removed mapping for footer 03 --- src/protocols/pir6.coffee | 1 - test/lib-controller.coffee | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/protocols/pir6.coffee b/src/protocols/pir6.coffee index 6caeea9..34de7b0 100644 --- a/src/protocols/pir6.coffee +++ b/src/protocols/pir6.coffee @@ -4,7 +4,6 @@ module.exports = (helper) -> '10': '1' #binary 1 '01': '0' #binary 0 '02': '' #footer - '03': '' #footer } # same for send binaryToPulse = { diff --git a/test/lib-controller.coffee b/test/lib-controller.coffee index a33e6c6..cb83bd2 100644 --- a/test/lib-controller.coffee +++ b/test/lib-controller.coffee @@ -74,10 +74,12 @@ describe '#decodePulses()', -> pulseLengths: [ 288, 864, 8964 ] pulses: [ '01011010010101011010100110010101101001010101101002' + '01011010010101011010100110010101101001010110010102' '01011010010101011010100110010101101001011001010102' ] values: [ { id: 6410630, presence: true } + { id: 6410632, presence: true } { id: 6410640, presence: true } ] },