cannot get scan working in C

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

cannot get scan working in C

Post by gherlein » Sat Jul 04, 2015 6:37 pm

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;
}

Post Reply