Crazyradio node driver help

Firmware/software/electronics
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Crazyradio node driver help

Post by adjavaherian »

I just put this together this weekend. https://github.com/adjavaherian/crazyradio-node-driver

It's basically a node-usb implementation of the crazy radio config specs here: https://wiki.bitcraze.io/doc:crazyradio ... ry_ard_arc

I wanted something a little faster and easier to manage than the chrome example, no cylon.js, no chrome, etc. So far so good, but I'm having issues with the START_SCAN_CHANNELS.

For some reason, my control transfer always times out and leaves the dongle in bad state (needs to be unplugged).

Any idea what's wrong with this code?

Code: Select all

device.controlTransfer(0x40, 0x21, low, high, new Buffer(high - low), cb);
https://github.com/adjavaherian/crazyra ... ex.js#L167

If you have some node savvy you can download the repo and run the tests pretty easily. The scan test is commented out tho.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyradio node driver help

Post by arnaud »

I have had firmware problem with the scann_channel commands and stopped using it for now. I would suggest to scann manually like we do in the python driver: https://github.com/bitcraze/crazyradio- ... #L244-L250
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Re: Crazyradio node driver help

Post by adjavaherian »

Will do. Thanks!
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Re: Crazyradio node driver help

Post by adjavaherian »

@arnaud, different question: I'm trying to setup bulk transfer out for endpoint 1, which I believe is correct. However, my test exits properly and then subsequent tests timeout. It looks like the endpoint is not released. Any idea? Here's the spec.

Code: Select all

describe.only('Packet tests', function() {

        var iface = null;
        //this.timeout(5000);


        beforeEach(function() {
            radio = new Crazyradio();
            radio.debugLevel(4);
            device = radio.find();
        });


        afterEach(function(done){
            radio.close(device, function(err, data){
                console.log('after', err);
                done();
            });
        });

        it('should send a packet', function(done){


            radio.open(device, function(){
                console.log('opening');

                iface = device.interface(0);
                iface.claim();

                var radioOut = iface.endpoint(1);
                var buff = new ArrayBuffer(32);

                console.log('radioOut', radioOut.direction, radioOut.transferType);

                radioOut.transfer(buff, function(error){
                    console.log('transfer callback', error);
                    iface.release(true, function(err){
                        console.log('releasing', err);
                        done();
                    });

                });



            });

        });
    });
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyradio node driver help

Post by arnaud »

Hi,

You should always read after writing, otherwise the radio might lock waiting for you to receive the ack status. I guess this is what is happening there.

/Arnaud
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Re: Crazyradio node driver help

Post by adjavaherian »

Its strange, I'm not sure if there's a bug in the usb library or I'm doing something wrong, but whenever I try to read from 0x81 it stalls out. In fact, the dongle seems to heat up too. Here's a thread I started with node-usb folks.

https://github.com/nonolith/node-usb/issues/111

Any ideas? Thanks.
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Re: Crazyradio node driver help

Post by adjavaherian »

@arnaud, I'm a little stuck here. The node-usb guys took a look at my code and they think its doing the right thing. I'm claiming interface 0, which has endpoint 0x01 and 0x81 and they are labeled out and in respectively. Then, I write an array to 0x01 and in the callback, I try reading from 0x81, but that times out. The dongle seems fine, because I can run the original ptx test in the crazyradio-driver/examples and I see the led light up and the acks are (). Any idea what might be going on? Thanks, amir

https://github.com/nonolith/node-usb/is ... -180852164
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyradio node driver help

Post by arnaud »

@adjavaherian I cloned your repos and it seems to work (I can run test.js). Though I do not know much about node. Could you guide me a bit on how to reproduce the problem so that I can investigate.
adjavaherian
Beginner
Posts: 26
Joined: Fri May 22, 2015 4:18 am

Re: Crazyradio node driver help

Post by adjavaherian »

Thanks @arnaud, I just updated the repo so if you pull it now, and run it, you should only see the one active test that's failing. It's not much different than the chrome client code, but instead of using the browser, I'm only using node and node-usb and mocha to run the tests. I'm pretty sure I'm doing the right thing in node-usb, but when I try to read the input buffer using usb.transfer() after the data out is written, it just kind of hangs there and test times out after 2s.

These should be roughly equivalent
https://github.com/bitcraze/crazyflie-c ... dio.js#L83
https://github.com/adjavaherian/crazyra ... st.js#L462

The main difference I can see is that node-usb doesn't have an in / out bit in its transfer API where as chrome.usb does. But, according to node-usb, you should just be able to read from the right endpoint, which I guess in our case should be interface[0].endpoint[0]?

https://github.com/nonolith/node-usb/issues/111

As per node as a beginner, you can think of it as simply Chrome's V8 without a Window / DOM and with many many modules like node-usb which can be as simple as a wrapper for libusb, etc.

Also, of note, if I write an array to the output endpoint, as opposed to an ArrayBuffer, the dongle temperature heats up significantly. Dunno why?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyradio node driver help

Post by arnaud »

adjavaherian wrote: Also, of note, if I write an array to the output endpoint, as opposed to an ArrayBuffer, the dongle temperature heats up significantly. Dunno why?
This is really strange! I tried to reproduce the heat part and it seems the be fixing the problem (at least 'it works for me' :). The only explanation I can find for more heat is if the PA is constantly ON and the radio is transmitting. Either you put the radio in continuous carrier mode by mistake, or you are hitting a bug I have never seen before (would be interesting).

Your test, as it is in the repos, does not send any packet: the red LED of the Crazyradio is not blinking. I changed the dataout packet (hopping to get some heat):

Code: Select all

diff --git a/test.js b/test.js
index c216dc4..2f5f7b4 100644
--- a/test.js
+++ b/test.js
@@ -464,7 +464,7 @@ describe('CrazyRadio tests', function(){
             console.log('opening', device);
             device.open();
 
-            var dataOut = new ArrayBuffer(15);
+            var dataOut = [255];
 
             var iface = device.interfaces[0];
                 iface.claim();
And now the Crazyradio red LED blinks, and the test is passing!

Is your Crazyradio working correctly with other clients?
Post Reply