rfcontroljs
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -6,3 +6,3 @@ var doesProtocolMatch, helper, protocols, sortIndices, | ||
protocols = ['weather1', 'weather2', 'weather3', 'weather4', 'switch1', 'switch2', 'switch3', 'switch4', "switch5", 'pir1', 'contact1', 'generic']; | ||
protocols = ['weather1', 'weather2', 'weather3', 'weather4', 'weather5', 'switch1', 'switch2', 'switch3', 'switch4', 'switch5', 'switch6', 'dimmer1', 'pir1', 'contact1', 'generic']; | ||
@@ -31,3 +31,3 @@ protocols = protocols.map((function(_this) { | ||
while (i < pulseLengths.length) { | ||
maxDelta = pulseLengths[i] * 0.25; | ||
maxDelta = pulseLengths[i] * 0.4; | ||
if (Math.abs(pulseLengths[i] - protocol.pulseLengths[i]) > maxDelta) { | ||
@@ -163,7 +163,9 @@ return false; | ||
if (this.debug) { | ||
console.log("Error trying to parse message with protocol " + p.name + ": " + err.stack); | ||
if (err instanceof helper.ParsingError) { | ||
console.log("Warning trying to parse message with protocol " + p.name + ": " + err.message); | ||
console.log("" + (err.stack.split("\n")[2])); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
if (!(err instanceof helper.ParsingError)) { | ||
throw err; | ||
} | ||
} | ||
@@ -170,0 +172,0 @@ } |
@@ -52,3 +52,23 @@ var ParsingError, | ||
}, | ||
binaryToNumber: function(data, b, e) { | ||
binaryToSignedNumberMSBLSB: function(data, b, e) { | ||
var signedPos; | ||
signedPos = b; | ||
b++; | ||
if ((parseInt(data[signedPos], 10)) === 1) { | ||
return this._binaryToSignedNumberMSBLSB(data, b, e); | ||
} else { | ||
return this.binaryToNumberMSBLSB(data, b, e); | ||
} | ||
}, | ||
binaryToSignedNumberLSBMSB: function(data, b, e) { | ||
var signedPos; | ||
signedPos = e; | ||
e--; | ||
if ((parseInt(data[signedPos], 10)) === 1) { | ||
return this._binaryToSignedNumberLSBMSB(data, b, e); | ||
} else { | ||
return this.binaryToNumberLSBMSB(data, b, e); | ||
} | ||
}, | ||
binaryToNumberMSBLSB: function(data, b, e) { | ||
var i, number; | ||
@@ -64,4 +84,15 @@ number = 0; | ||
}, | ||
binaryToNumberRevert: function(data, b, e) { | ||
_binaryToSignedNumberMSBLSB: function(data, b, e) { | ||
var i, number; | ||
number = ~0; | ||
i = b; | ||
while (i <= e) { | ||
number <<= 1; | ||
number |= parseInt(data[i], 10); | ||
i++; | ||
} | ||
return number; | ||
}, | ||
binaryToNumberLSBMSB: function(data, b, e) { | ||
var i, number; | ||
number = 0; | ||
@@ -76,3 +107,14 @@ i = e; | ||
}, | ||
numberToBinary: function(number, length) { | ||
_binaryToSignedNumberLSBMSB: function(data, b, e) { | ||
var i, number; | ||
number = ~0; | ||
i = e; | ||
while (i >= b) { | ||
number <<= 1; | ||
number |= parseInt(data[i], 10); | ||
i--; | ||
} | ||
return number; | ||
}, | ||
numberToBinaryMSBLSB: function(number, length) { | ||
var binary, i; | ||
@@ -88,2 +130,13 @@ binary = ''; | ||
}, | ||
numberToBinaryLSBMSB: function(number, length) { | ||
var binary, i; | ||
binary = ''; | ||
i = 0; | ||
while (i < length) { | ||
binary = binary + (number & 1); | ||
number >>= 1; | ||
i++; | ||
} | ||
return binary; | ||
}, | ||
binaryToBoolean: function(data, i) { | ||
@@ -93,1 +146,7 @@ return data[i] === '1'; | ||
}; | ||
module.exports.binaryToNumber = module.exports.binaryToNumberMSBLSB; | ||
module.exports.numberToBinary = module.exports.numberToBinaryMSBLSB; | ||
module.exports.binaryToSignedNumber = module.exports.binaryToSignedNumberMSBLSB; |
@@ -35,14 +35,14 @@ module.exports = function(helper) { | ||
id: helper.binaryToNumber(binary, 5, 9), | ||
state: helper.binaryToBoolean(binary, 11) | ||
state: !helper.binaryToBoolean(binary, 11) | ||
}; | ||
}, | ||
encodeMessage: function(message) { | ||
var fixed, id, state, unit; | ||
var fixed, id, invertedState, unit; | ||
unit = helper.map(helper.numberToBinary(message.unit, 5), binaryToPulse); | ||
id = helper.map(helper.numberToBinary(message.id, 5), binaryToPulse); | ||
fixed = binaryToPulse['0']; | ||
state = (message.state ? binaryToPulse['1'] : binaryToPulse['0']); | ||
return "" + unit + id + fixed + state + "02"; | ||
invertedState = (message.state ? binaryToPulse['0'] : binaryToPulse['1']); | ||
return "" + unit + id + fixed + invertedState + "02"; | ||
} | ||
}; | ||
}; |
module.exports = function(helper) { | ||
var protocolInfo, pulsesToBinaryMapping; | ||
pulsesToBinaryMapping = { | ||
'0000000012': '', | ||
'14': '0', | ||
'13': '1', | ||
'15': '' | ||
'1111111104': '', | ||
'02': '0', | ||
'03': '1', | ||
'05': '' | ||
}; | ||
@@ -9,0 +9,0 @@ return protocolInfo = { |
{ | ||
"name": "rfcontroljs", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Protocol support for different 433mhz switches and weather stations for the RFControl Arduino library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -97,2 +97,21 @@ rfcontroljs | ||
Details | ||
-------- | ||
RFControl is more sensitive than needed for most protocols. | ||
So we get sometimes, depending of the accuracy of the sender/remote, different bucket counts. | ||
This is by design, to catch up further protocols that maybe need a higher sensitivity. The specific | ||
protocol has not to deal with this issue, because `rfcontroljs` auto merges similar buckets before | ||
calling the `decodePulses` function of each protocol. | ||
The algorithm is the following: | ||
1. Record the (maybe to many) buckets and compressed pulses with [RFControl](https://github.com/pimatic/RFControl) (arduino / c++) | ||
2. Sort the buckets in `rfcontroljs` [`prepareCompressedPulses`](https://github.com/pimatic/rfcontroljs/blob/f39db799ae1fc86cda74c33a01c27da40eb3c9e8/src/controller.coffee#L68) | ||
3. Try to find a matching protocol in rfcontroljs [`decodePulses`](https://github.com/pimatic/rfcontroljs/blob/f39db799ae1fc86cda74c33a01c27da40eb3c9e8/src/controller.coffee#L118) | ||
4. If we have more than 3 buckets and two of the buckets are similar (`b1*2 < b2`) we merge them to just one bucket by averaging and adapting the pulses in rfcontroljs [`fixPulses`](https://github.com/pimatic/rfcontroljs/blob/f39db799ae1fc86cda74c33a01c27da40eb3c9e8/src/controller.coffee#L89) | ||
5. Go to step 3 | ||
Adding a new Protocol | ||
@@ -120,4 +139,6 @@ -------------------- | ||
controller = require './index.js' | ||
result = controller.prepareCompressedPulses('511 2006 627 7728 0 0 0 0 0101020202020102020101010201010102020102020201020201010101020102010101020101020102020303') | ||
result = controller.prepareCompressedPulses('255 2904 1388 771 11346 0 0 0 0100020002020000020002020000020002000202000200020002000200000202000200020000020002000200020002020002000002000200000002000200020002020002000200020034') | ||
console.log result | ||
result2 = controller.fixPulses(result.pulseLengths, result.pulses) | ||
console.log result2 | ||
``` | ||
@@ -128,4 +149,7 @@ sample output: | ||
coffee convert.coffee | ||
{ pulseLengths: [ 511, 627, 2006, 7728 ], | ||
pulses: '0202010101010201010202020102020201010201010102010102020202010201020202010202010201010303' } | ||
{ pulseLengths: [ 255, 771, 1388, 2904, 11346 ], | ||
pulses: '0300020002020000020002020000020002000202000200020002000200000202000200020000020002000200020002020002000002000200000002000200020002020002000200020014' } | ||
{ pulseLengths: [ 255, 1079, 2904, 11346 ], | ||
pulses: '0200010001010000010001010000010001000101000100010001000100000101000100010000010001000100010001010001000001000100000001000100010001010001000100010013' } | ||
``` | ||
The second line should be used for protocol developing. |
Sorry, the diff of this file is not supported yet
91730
24
1116
153