#include #include #include #include "node.h" #include "dstar.h" #define FALSE 0 #define TRUE 1 void main(void) { struct usb_bus *bus; struct usb_device *dev; struct dv_header *dv; usb_dev_handle *udev; int dev_found, ret; char string[256]; char buffer[8]; char radio_header[41]; char c; char SlowData[3]; int i,k,l,n; int HeaderLength; FILE *voice; usb_init(); usb_find_busses(); usb_find_devices(); udev = NULL; dev_found = FALSE; for (bus = usb_get_busses(); bus && !dev_found; bus = bus->next) { for (dev = bus->devices; dev && !dev_found; dev = dev->next) { if ((dev->descriptor.idVendor == 0x04D8) && (dev->descriptor.idProduct == 0x0004)) { dev_found = TRUE; udev = usb_open(dev); } } } if (!dev_found) { printf("No matching device found...\n"); } usb_set_configuration (udev, 1); /* PIC VERSION READ */ ret = 8; while (ret == 8) { ret = usb_control_msg(udev, 0xC0, GET_VERSION, 0, 0, buffer, 8, 100); for (i = 0 ; i < ret ; i++) { printf ("%c",buffer[i]); } } printf ("\n"); while (1) { k = 0; HeaderLength = 0; while (HeaderLength < 41) { ret = usb_control_msg(udev, 0xC0, GET_HEADER, 0, 0, buffer, 8, 100); if (ret < 0) { printf("Unable to send vendor request, ret = %d...\n", ret); } else { if (ret != 0) { HeaderLength += ret; for (i = 0 ; i < ret; i++) { radio_header[k] = buffer[i]; k++; } } } } dv = (struct dv_header *) radio_header; printf ("\n\n"); printf ("Flags : %2.2x %2.2x %2.2x\n",dv->flags[0],dv->flags[1],dv->flags[2]); printf ("RPT2 : %.8s\n",dv->RPT2Call); printf ("RPT1 : %.8s\n",dv->RPT1Call); printf ("YuCall : %.8s\n",dv->YourCall); printf ("MyCall : %.8s\n",dv->MyCall); printf ("MyCall2: %.4s\n",dv->MyCall2); printf ("CRC : %2.2x %2.2x\n",dv->CRC[0],dv->CRC[1]); printf ("\nDV STREAM \n"); k = 0; l = 0; while (ret <= 8) { ret = usb_control_msg(udev, 0xC0, GET_DATA, 0, 0, buffer, 8, 100); if (ret < 0) { printf("Unable to send vendor request, ret = %d...\n", ret); } else if (ret > 0) { for (i = 0 ; i < ret; i++) { printf ("%2.2x ",buffer[i] & 0xff); if (k == 11) SlowData[2] = (buffer[i] & 0xff) ^ 0xc9;; if (k == 10) SlowData[1] = (buffer[i] & 0xff) ^ 0xf2; if (k == 9) SlowData[0] = (buffer[i] & 0xff) ^ 0x0e; k++; if (k == 12) { c = SlowData[0]; SlowData[0] = 0x00; for (n = 0 ; n < 8 ; n++) { if (c & ( 0x01 << n)) SlowData[0] |= (0x80 >> n); } c = SlowData[1]; SlowData[1] = 0x00; for (n = 0 ; n < 8 ; n++) { if (c & ( 0x01 << n)) SlowData[1] |= (0x80 >> n); } c = SlowData[2]; SlowData[2] = 0x00; for (n = 0 ; n < 8 ; n++) { if (c & ( 0x01 << n)) SlowData[2] |= (0x80 >> n); } printf (" %2.2x %2.2x %2.2x %c %c %c \n",SlowData[0] & 0xff, SlowData[1] & 0xff, SlowData[2] & 0xff, SlowData[0], SlowData[1], SlowData[2]); k = 0; l++; } if (l == 21) { printf ("\n"); l = 0; } } } else if (ret == 0) { ret = usb_control_msg(udev, 0xC0, GET_AD_STATUS, 0, 0, buffer, 1, 100); if (!(buffer[0] & COS_OnOff)) break; /* check COS_OFF */ } } } /* end while (1) */ /* usb_close(udev); */ }