Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jul 2010 18:51:20 -0500
From:      Ryan Coleman <editor@d3photography.com>
To:        freebsd-questions@freebsd.org
Subject:   Radio Shark 2
Message-ID:  <A6ACACAE-B445-4CAF-8A61-9FB24536BBB7@d3photography.com>

next in thread | raw e-mail | index | archive | help
Does anyone have an experience getting the Radio Shark 2 set up? I'm =
hoping to use it for radio streaming in my apartment.=20

I've found shark2.c on the net and gcc is failing to compile it; I'm a =
PHP developer with a lot of admin time on FreeBSD (8-RELEASE, AMD64 =
build presently) but can't get my head around that piece.

root@server /usr/local/include]# gcc -g -o shark2 -lhid shark2.c
In file included from shark2.c:21:
/usr/include/hid.h:6:23: error: hidparser.h: No such file or directory
In file included from shark2.c:21:
/usr/include/hid.h:69: error: expected specifier-qualifier-list before =
'HIDData'
shark2.c: In function 'main':
shark2.c:98: warning: incompatible implicit declaration of built-in =
function 'exit'
shark2.c:102: warning: incompatible implicit declaration of built-in =
function 'exit'

[[Basically it's not finding hidparser.h - I get that - but it isn't =
checking paths to look for it or I just can't seem to set any new search =
paths -R]]

::::::: contents of shark2.c :::::::
/* This souce code written my Michael Rolig (email: =
michael_rolig@alumni.macalester.edu)
* This can be considered to be in the public domain
*/

/* Modified for Radio Shark2 2007-05-11
* This souce code written my Hisaaki Shibata (email: shibata@luky.org)
* This can be considered to be in the public domain
*/

#define DEBUG false             /* Set true for copious debugging output =
*/
#define SHARK_VENDID 0x077d     /* Griffin's Vendor ID */
#define SHARK_DEVID 0x627a      /* The radioSHARK's Device ID */

#define READ_EP 0x5             /* libhid read command? */
#define WRITE_EP 0x5            /* libhid write command? */
#define SEND_PACKET_LENGTH 7    /* size of an instruction packet: =
shark2=3D7 */

#include </usr/include/stdio.h>
#include </usr/include/string.h>
#include </usr/include/unistd.h>
#include </usr/include/hid.h>

void usage(int argc, const char** argv) {
       printf("%s <command> <arg>\n\tchange state of radioSHARK\n\n", =
argv[0]);
       printf("commands:\n"
               " -fm <freqeuncy>    : set FM frequency, e.g. '-fm =
91.5'\n"
               " -am <frequency>    : set AM frequency, e.g. '-am =
730'\n"
               " -blue <intensity>  : turn on blue LED (0-127) '-blue =
127'\n"
               " -red <0/1>         : turn on/off red LED '-red 1'\n");
}

int main(int argc, const char** argv) {

       /* Declare variables used later */
       hid_return ret;
       HIDInterface* hid;
       HIDInterfaceMatcher matcher =3D { SHARK_VENDID, SHARK_DEVID, =
NULL, NULL, 0 };

       /* Build the instruction packet to send to the shark */
       unsigned char PACKET[SEND_PACKET_LENGTH] =3D { 0x00, 0x00, 0x00, =
0x00, 0x00, 0x00, 0x00 };
       unsigned short encodedFreq;
       float freq;
       unsigned int intensity;
       if (argc =3D=3D 3) {
               if (strcmp(argv[1], "-fm") =3D=3D 0) {
                       /* Tune to an FM frequency */
                       PACKET[0] =3D 0x81;
                       encodedFreq =3D 0;
                       freq =3D atof(argv[2]);
                       encodedFreq  =3D ((freq * 10 * 2) - 3 );
                       PACKET[1] =3D (encodedFreq >> 8) & 0xFF;
                       PACKET[2] =3D encodedFreq & 0xFF;
                       PACKET[3] =3D 0x33;
                       PACKET[4] =3D 0x04;
                       PACKET[5] =3D 0x00;
                       PACKET[6] =3D 0x28;
                       if (DEBUG) {
                               printf("band =3D fm\n");
                               printf("freq =3D %.1f\n", freq);
                               printf("encoded freq =3D 0x%x\n", =
(unsigned int)encodedFreq);
                       }
               } else if (strcmp(argv[1], "-am") =3D=3D 0) {
                       /* Tune to an AM frequency */
                       PACKET[0] =3D 0x81;
                       encodedFreq =3D 0;
                       freq =3D (float)atoi(argv[2]);
                       encodedFreq  =3D ((unsigned short)freq * 4 ) + =
16300;
                       PACKET[1] =3D (encodedFreq >> 8) & 0xFF;
                       PACKET[2] =3D encodedFreq & 0xFF;
                       PACKET[3] =3D 0xF3;
                       PACKET[4] =3D 0x36;
                       PACKET[5] =3D 0x00;
                       PACKET[6] =3D 0x24;
                       if (DEBUG) {
                               printf("band =3D am\n");
                               printf("freq =3D %d\n", (unsigned =
int)freq);
                               printf("encoded freq =3D 0x%x\n", =
(unsigned int)encodedFreq);
                       }
               } else if (strcmp(argv[1], "-blue") =3D=3D 0) {
                       /* Adjust the blue LED */
                       intensity =3D atoi(argv[2]);
                       PACKET[0] =3D 0x83;
                       PACKET[1] =3D (char)intensity;
               } else if (strcmp(argv[1], "-bblue") =3D=3D 0) {
                       /* Adjust the blue LED's pulsing rate */
                       intensity =3D atoi(argv[2]);
                       PACKET[0] =3D 0xA1;
                       PACKET[1] =3D (char)intensity;
               } else if (strcmp(argv[1], "-red") =3D=3D 0) {
                       /* Toggle the red LED */
                       intensity =3D atoi(argv[2]);
                       if (intensity) PACKET[0] =3D 0x84;
                       else PACKET[0] =3D 0x84;
                       PACKET[1] =3D (char)intensity;
               } else {
                       /* Bad command - display the program's usage =
instructions */
                       usage(argc, argv);
                       exit(1);
               }
       } else {
               usage(argc, argv);
               exit(1);
       }

       /* Turn libhid debugging on if requested.  See include/debug.h =
for possible values. */
       if (DEBUG) {
               hid_set_debug(HID_DEBUG_ALL);
               hid_set_debug_stream(stderr);
               hid_set_usb_debug(0);                   /* passed =
directly to libusb */
       }

       /* Initialize the hid library */
       ret =3D hid_init();
       if (ret !=3D HID_RET_SUCCESS) {
               fprintf(stderr, "hid_init failed with return code %d\n", =
ret);
               return 1;
       }

       /* Initialize the hid object */
       hid =3D hid_new_HIDInterface();
       if (hid =3D=3D 0) {
               fprintf(stderr, "hid_new_HIDInterface() failed, out of =
memory?\n");
               return 1;
       }

       /* Open the shark */
       ret =3D hid_force_open(hid, 2, &matcher, 3);
       if (ret !=3D HID_RET_SUCCESS) {
               fprintf(stderr, "hid_force_open failed with return code =
%d\n", ret);
               return 1;
       }

       /* Send the instruction packet constructed above to the Shark */
       ret =3D hid_interrupt_write(hid, WRITE_EP, (char*)PACKET, =
SEND_PACKET_LENGTH, 10000);
       if (ret !=3D HID_RET_SUCCESS) fprintf(stderr, =
"hid_interrupt_write failed with return code %d\n", ret);

       /* Close the shark */
       ret =3D hid_close(hid);
       if (ret !=3D HID_RET_SUCCESS) {
               fprintf(stderr, "hid_close failed with return code %d\n", =
ret);
               return 1;
       }

       /* Delete the hid object */
       hid_delete_HIDInterface(&hid);

       /* Clean up the hid library */
       ret =3D hid_cleanup();
       if (ret !=3D HID_RET_SUCCESS) {
               fprintf(stderr, "hid_cleanup failed with return code =
%d\n", ret);
               return 1;
       }

       return 0;
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A6ACACAE-B445-4CAF-8A61-9FB24536BBB7>