GEMakers / gea-plugin-dishwasher

Dishwasher plugin for the GEA SDK
GNU General Public License v2.0
13 stars 6 forks source link

"Uncaught RangeError: index out of range" after writing to userConfiguration #19

Open Hixie opened 8 years ago

Hixie commented 8 years ago

If I read userConfiguration I get back [0, 128, 32] right now (no delay, no zone, no dry options, normal wash temp, rinse aid enabled, autosense cycle, leak detect enabled).

If I write [0, 128, 32] back to userConfiguration, I get back:

Uncaught RangeError: index out of range

FROM
checkOffset (buffer.js:625:5)
Buffer.readUInt16BE (buffer.js:679:5)
readUInt16 (/home/ianh/node_modules/green-bean/node_modules/gea-sdk/node_modules/binary-stream/index.js:78:22)
Adapter.<anonymous> (/home/ianh/node_modules/green-bean/node_modules/gea-sdk/src/erd.js:105:38)
emitOne (events.js:82:20)
Adapter.emit (events.js:169:7)
onPacketReceived (/home/ianh/node_modules/green-bean/node_modules/gea-adapter-usb/index.js:103:26)
/home/ianh/node_modules/green-bean/node_modules/gea-adapter-usb/index.js:128:17

Here's the test program:

// This has only been tested with a GE GDF570SGFWW dishwasher

require('events').EventEmitter.prototype._maxListeners = 0;

const greenBean = require("green-bean");

var delayTime = 1000; // milliseconds between messages to dishwasher
var fields = [ 'userConfiguration', 'operatingMode', 'cycleState', 'cycleStatus', 'error' ];
var pendingDishwasherMessages = [];
var lastMessage = 0;

function flushPendingDishwasherMessages() {
  var callback = pendingDishwasherMessages.shift();
  callback();
  if (pendingDishwasherMessages.length > 0)
    setTimeout(flushPendingDishwasherMessages, delayTime);
}

function sendDishwasherMessage(callback) {
  if (pendingDishwasherMessages.length > 0) {
    pendingDishwasherMessages.push(callback);
    return;
  }
  var now = Date.now();
  var timeSinceLastMessage = now - lastMessage;
  if (timeSinceLastMessage > delayTime) {
    callback();
    lastMessage = now;
    return;
  }
  pendingDishwasherMessages.push(callback);
  setTimeout(flushPendingDishwasherMessages, delayTime - timeSinceLastMessage);
}

function subscribe(dishwasher, field) {
  sendDishwasherMessage(function () {
    dishwasher[field].subscribe(function (value) {
      console.log(field, value);
    });
  });
}

function doTest() {
  sendDishwasherMessage(function () {
    console.log('writing to userConfiguration...');
    dishwasher.userConfiguration.write([0, 128, 32]);
  });
}

var dishwasher;
console.log('connecting to green bean');
greenBean.connect("dishwasher", function(dw) {
  if (dishwasher == null) {
    dw.operatingMode.read(function (value) {
      if (value == 11)
        return;
      dishwasher = dw;
      console.log('connected...');
      for (var index = 0; index < fields.length; index += 1)
        subscribe(dishwasher, fields[index]);
      setTimeout(doTest, 2000);
    });
  }
});
Hixie commented 8 years ago

The problem isn't with the write as far as I can tell. If I send [1, 128, 32], then I see the 2-hour delay LED turn on, and if I run the program again, it does report that the value is now [1, 128, 32]. It's just crashing when reading data immediately after the write for some reason.