jankolkmeier / svd-xbee

Node talks to xbee radios through serialport
40 stars 14 forks source link

Stream abstraction #10

Open joshperry opened 11 years ago

joshperry commented 11 years ago

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.

jankolkmeier commented 11 years ago

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

joshperry commented 11 years ago

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);
});
jankolkmeier commented 11 years ago

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" notifications@github.com 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 .