Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hixie opened this issue Jul 8, 2016 · 1 comment

Comments

@Hixie
Copy link

Hixie commented Jul 8, 2016

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
Copy link
Author

Hixie commented Jul 8, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant