Cannot get scan working in C

Firmware/software/electronics/mechanics
Post Reply
gherlein
Beginner
Posts: 11
Joined: Mon Jun 22, 2015 8:32 pm

Cannot get scan working in C

Post by gherlein »

I have C code to open the USB and set up the CrazyRadio. I think that's working OK. I don't really have a way to test that!

So, I was writing a function to scan the radio channels and see if I can find the CF2. I've tried a pile of stuff and finally have to ask for help. Should this function work if all the rest of my code is working to set up the radio?


int
scanChannels(void)
{
unsigned char b[1];
unsigned char a[3];
unsigned char c[64];
int r=0;

a[0]=0xF0;
a[1]=0x01;
a[2]=0x01;

r = libusb_control_transfer(dev_handle, 0x40, 0x21, 0, 125, (unsigned char*)&a, 3, 1000);
if(r<0)
{
printf("error writing scan command\n");
return 0;
}
printf("wrote %d bytes to command a scan...\n",r);

sleep(2); // in case the scan takes some time
memset(c,0xff,64);

r = libusb_control_transfer(dev_handle, 0xC0, 0x21, 0, 0, (unsigned char*)c, 63, 1000);
if(r==0)
{
printf("got no reply from channel scan\n");
return 0;
}
if(r<0)
{
printf("error reading scan results\n");
return 0;
}
printf("read %d bytes of scanned channel data...\n",r);

for(r=0;r<64;r++)
{
printf("Channel %d: %d\n",r,c[r]);
}


return 0;
}
gherlein

Posts: 5
Joined: Mon Jun 22, 2015 12:32 pm
gherlein
Beginner
Posts: 11
Joined: Mon Jun 22, 2015 8:32 pm

Re: Cannot get scan working in C

Post by gherlein »

I discivered that my CF2 was actually set to use the 250KB data rate for some reason. I reflashed the firmware and it resumed the default 2M and now I can scan for it fine.

I am getting back a value of 80 on the channel it's on. What does that value mean? Is it an RSSI?
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Cannot get scan working in C

Post by chad »

gherlein wrote:I am getting back a value of 80 on the channel it's on. What does that value mean? Is it an RSSI?
I don't know the answer to this for certain but, since you haven't gotten any responses...

IIRC my CF2 radio defaulted to radio channel 80 and 250K bandwidth. Is the value you're getting back the radio channel number itself (80)?
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Post Reply