From adf9630fe72060966fc682de185f5ecc22124bdd Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Mon, 5 Jun 2017 11:32:19 +0200 Subject: [PATCH 1/3] (bluefox) fix error if no devices are connected to cube (bluefox) emit hello info --- maxcube-commandparser.js | 5 +++++ maxcube.js | 1 + 2 files changed, 6 insertions(+) diff --git a/maxcube-commandparser.js b/maxcube-commandparser.js index 08c4cb9..e3d0a18 100644 --- a/maxcube-commandparser.js +++ b/maxcube-commandparser.js @@ -62,6 +62,11 @@ function parseCommandHello (payload) { function parseCommandMetadata (payload) { var payloadArr = payload.split(","); + if (payloadArr.length < 3) { + console.error('Invalid Metadata received'); + return { rooms: {}, devices: {} }; + } + var decodedPayload = new Buffer(payloadArr[2], 'base64'); var room_count = decodedPayload[2]; var currentIndex = 3; diff --git a/maxcube.js b/maxcube.js index a4f64d3..a8e015b 100644 --- a/maxcube.js +++ b/maxcube.js @@ -49,6 +49,7 @@ function MaxCube(ip, port) { case 'H': { self.commStatus.duty_cycle = parsedCommand.duty_cycle; self.commStatus.free_memory_slots = parsedCommand.free_memory_slots; + self.emit('hello', parsedCommand); break; } case 'M': { From 1d6b09265dbb9811d8d43acecdcdbc63c34e341c Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Mon, 5 Jun 2017 23:24:45 +0200 Subject: [PATCH 2/3] (bluefox) add shutter contact parser --- maxcube-commandparser.js | 48 +++++++++++++++++++++++++++++++++++++++- maxcube-lowlevel.js | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/maxcube-commandparser.js b/maxcube-commandparser.js index e3d0a18..8e39463 100644 --- a/maxcube-commandparser.js +++ b/maxcube-commandparser.js @@ -210,9 +210,20 @@ function decodeDevice (payload) { var deviceStatus = {}; var deviceType = undefined; switch (payload[0]) { - case 8: deviceType = EQ3MAX_DEV_TYPE_PUSH_BUTTON; break; + case 6: + if (payload[1] === 9) { + deviceType = EQ3MAX_DEV_TYPE_PUSH_BUTTON; + deviceStatus = decodeDeviceButton (payload); + } else { + deviceType = EQ3MAX_DEV_TYPE_SHUTTER_CONTACT; + deviceStatus = decodeDeviceContact (payload); + } + + break; + case 8: deviceType = EQ3MAX_DEV_TYPE_PUSH_BUTTON; deviceStatus = decodeDeviceButton (payload); break; case 11: deviceType = EQ3MAX_DEV_TYPE_THERMOSTAT; deviceStatus = decodeDeviceThermostat (payload); break; case 12: deviceType = EQ3MAX_DEV_TYPE_WALLTHERMOSTAT; deviceStatus = decodeDeviceThermostat (payload); break; + case 13: deviceType = EQ3MAX_DEV_TYPE_THERMOSTAT_PLUS; deviceStatus = decodeDeviceThermostat (payload); break; // ??? if 13 is correct default: deviceType = EQ3MAX_DEV_TYPE_UNKNOWN; break; } @@ -221,6 +232,41 @@ function decodeDevice (payload) { return deviceStatus; } +function decodeDeviceContact (payload) { + var deviceStatus = { + rf_address: payload.slice(1, 4).toString('hex'), + opened: (payload[5] & 0x2) && !(payload[5] & 0x1), + initialized: !!(payload[5] & (1 << 1)), + fromCmd: !!(payload[5] & (1 << 2)), + error: !!(payload[5] & (1 << 3)), + valid: !!(payload[5] & (1 << 4)), + dst_active: !!(payload[6] & (1 << 3)), + gateway_known: !!(payload[6] & (1 << 4)), + link_error: !!(payload[6] & (1 << 6)), + battery_low: !!(payload[6] & (1 << 7)), + opened: !!(payload[6] & (1 << 1)) + }; + return deviceStatus; +} + +function decodeDeviceButton (payload) { + console.log(payload.join(', ')); + var deviceStatus = { + rf_address: payload.slice(1, 4).toString('hex'), + opened: (payload[5] & 0x2) && !(payload[5] & 0x1), + initialized: !!(payload[5] & (1 << 1)), + fromCmd: !!(payload[5] & (1 << 2)), + error: !!(payload[5] & (1 << 3)), + valid: !!(payload[5] & (1 << 4)), + dst_active: !!(payload[6] & (1 << 3)), + gateway_known: !!(payload[6] & (1 << 4)), + link_error: !!(payload[6] & (1 << 6)), + battery_low: !!(payload[6] & (1 << 7)), + eco_mode: !!(payload[6] & (1 << 1)) + }; + return deviceStatus; +} + function decodeDeviceThermostat (payload) { /* source: http://www.domoticaforum.eu/viewtopic.php?f=66&t=6654 diff --git a/maxcube-lowlevel.js b/maxcube-lowlevel.js index 09af07f..eff8001 100644 --- a/maxcube-lowlevel.js +++ b/maxcube-lowlevel.js @@ -48,7 +48,7 @@ function initSocket () { this.socket.on('error', function(err) { console.error(err); - self.emit('error'); + self.emit('error', err); }); } From dd3f02a9f75caf4787e79ecefc738f1a5fa02dba Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Mon, 5 Jun 2017 23:26:20 +0200 Subject: [PATCH 3/3] (bluefox) remove debug --- maxcube-commandparser.js | 1 - 1 file changed, 1 deletion(-) diff --git a/maxcube-commandparser.js b/maxcube-commandparser.js index 8e39463..bf6ac58 100644 --- a/maxcube-commandparser.js +++ b/maxcube-commandparser.js @@ -250,7 +250,6 @@ function decodeDeviceContact (payload) { } function decodeDeviceButton (payload) { - console.log(payload.join(', ')); var deviceStatus = { rf_address: payload.slice(1, 4).toString('hex'), opened: (payload[5] & 0x2) && !(payload[5] & 0x1),