svd-xbee icon indicating copy to clipboard operation
svd-xbee copied to clipboard

Stream abstraction

Open joshperry opened this issue 11 years ago • 3 comments

I wonder if you've done or plan to do any work on abstracting the communication between your library and the XBee coordinator. I would like to talk to XBee devices over ethernet and directly using a libusb wrapper in addition to using the serialport module.

Just wanted to check with you guys before I started to put down some code. Perhaps a constructor that accepts a stream that will communicate with the XBee and pulling the serialport specific code out and moving it to another class.

joshperry avatar Jul 10 '13 22:07 joshperry

Have not worked on anything like this, but it sounds interesting!

jankolkmeier avatar Jul 12 '13 07:07 jankolkmeier

Node >= 0.10 now has readable, writable, and duplex stream base classes as well as a transform class that can be used for easy protocol dissection. My idea would be to refactor the library to use the new streams for the physical link to the XBee as well as making the Node object inherit from DuplexStream to ease sending and receiving data.

This would enable code something like this:

xbee.on('newNodeDiscovered', function(node) {
    var rxproto = new MyProtocolReadTransform();
    var txproto = new MyProtocolWriteTransform();
    rxproto.on('message', function(msg) {
        // Process the message from the hardware
        if(msg === 'ping')
            txproto.write('pong');
    });

    // Pipe the data from the tx protocol transformer into the node
    // and incoming data from the node into the rx protocol transformer
    txproto.pipe(node).pipe(rxproto);
});

joshperry avatar Aug 13 '13 22:08 joshperry

I would love that. I just got back from vacation and have some catching up to do on the other issues. Same goes for the new streaming classes... On Aug 14, 2013 12:59 AM, "joshperry" [email protected] wrote:

Node >= 0.10 now has readable, writable, and duplex stream base classes as well as a transform class that can be used for easy protocol dissection. My idea would be to refactor the library to use the new streams for the physical link to the XBee as well as making the Node object inherit from DuplexStream to ease sending and receiving data.

This would enable code something like this:

xbee.on('newNodeDiscovered', function(node) { var rxproto = new MyProtocolReadTransform(); var txproto = new MyProtocolWriteTransform(); rxproto.on('message', function(msg) { // Process the message from the hardware if(msg === 'ping') txproto.write('pong'); });

// Pipe the data from the tx protocol transformer into the node
// and incoming data from the node into the rx protocol transformer
txproto.pipe(node).pipe(rxproto);

});

— Reply to this email directly or view it on GitHubhttps://github.com/jouz/svd-xbee/issues/10#issuecomment-22604031 .

jankolkmeier avatar Aug 14 '13 06:08 jankolkmeier