36 #include "btrCore_service.h"
40 static GThread* fileWriteThread = NULL;
41 static int writeSBC = 0;
42 unsigned int BT_loop = 0;
46 tBTRCoreHandle hBTRCore;
51 unsigned int ui32DevDelay;
55 #define NO_ADAPTER 1234
58 static int acceptConnection = 0;
59 static int connectedDeviceIndex=0;
65 char *message =
"SBC Write Thread Started";
66 char * myfifo =
"/tmp/myfifo";
72 fprintf(stderr,
"%d\t: %s - Thread starting: %s \n", __LINE__, __FUNCTION__, message);
73 fd = open(myfifo, O_WRONLY );
74 fprintf(stderr,
"%d\t: %s - BT data flowing...\n", __LINE__, __FUNCTION__);
78 }
while (writeSBC == 0);
82 unsigned char sigByte1 = 0;
83 unsigned char bitpool = 0;
91 unsigned char bit_blocks;
92 unsigned char bit_channel_mode;
94 unsigned char bit_sub_bands;
100 int sbcFrameState = 0;
110 while (k < BT_loop) {
112 read_return = read(pstAppData->iDataPath, buffy, pstAppData->iDataReadMTU);
116 while (first_time_thru) {
121 fprintf(stderr,
"%d\t: %s - first sbc frame detected\n", __LINE__, __FUNCTION__);
126 bit_blocks = (x & 0x30) >> 4;
127 bit_channel_mode = (x & 0x0C) >> 2;
129 bit_sub_bands = (x & 0x01);
130 sub_bands = (bit_sub_bands + 1) * 4;
131 blocks = (bit_blocks + 1) * 4;
137 fprintf(stderr,
"%d\t: %s - channel mode 0x%x\n", __LINE__, __FUNCTION__, bit_channel_mode);
138 fprintf(stderr,
"%d\t: %s - nrof_subbands 0x%x\n", __LINE__, __FUNCTION__, sub_bands);
139 fprintf(stderr,
"%d\t: %s - nrof_blocks 0x%x\n", __LINE__, __FUNCTION__, blocks);
140 fprintf(stderr,
"%d\t: %s - bitpool 0x%x\n", __LINE__, __FUNCTION__, bitpool );
142 switch (bit_channel_mode) {
145 tmp = blocks * bitpool;
148 tmp = blocks * bitpool * 2;
151 tmp = blocks * bitpool;
154 tmp = blocks * bitpool + sub_bands;
160 computed_len = sub_bands + ((tmp + 7) / 8);
161 frame_length = computed_len + 4;
164 fprintf(stderr,
"%d\t: %s - frame length is %d\n", __LINE__, __FUNCTION__, frame_length);
172 if (read_return > 0) {
173 if ( (k % 1000) == 0) {
174 fprintf(stderr,
"%d\t: %s - reading %d - %d - %d\n", __LINE__, __FUNCTION__, read_return,k,BT_loop);
181 for(z=0;z<read_return;z++) {
183 if ((sbcFrameState == 0) && (x == 0x9C)) {
187 if ((sbcFrameState == 1) && (x == sigByte1)) {
191 if ((sbcFrameState == 2) && (x == bitpool)) {
195 bytes2write=frame_length-2;
199 if (write(fd,&temp,1)) {
203 if (write(fd,&temp,1)) {
211 if (write(fd,&x,1)) {
214 if (bytes2write == 0)
241 BTRCore_GetDeviceMediaInfo ( pstAppData->hBTRCore, connectedDeviceIndex, enBTRCoreMobileAudioIn, &pstAppData->stBtrCoreDevMediaInfo);
243 pstAppData->iDataPath = 0;
244 pstAppData->iDataReadMTU = 0;
245 pstAppData->iDataWriteMTU = 0;
246 pstAppData->ui32DevDelay = 0;
249 connectedDeviceIndex,
250 enBTRCoreMobileAudioIn,
251 &pstAppData->iDataPath,
252 &pstAppData->iDataReadMTU,
253 &pstAppData->iDataWriteMTU,
254 &pstAppData->ui32DevDelay);
256 fprintf(stderr,
"%d\t: %s - Device Data Path = %d \n", __LINE__, __FUNCTION__, pstAppData->iDataPath);
257 fprintf(stderr,
"%d\t: %s - Device Data Read MTU = %d \n", __LINE__, __FUNCTION__, pstAppData->iDataReadMTU);
258 fprintf(stderr,
"%d\t: %s - Device Data Write MTU= %d \n", __LINE__, __FUNCTION__, pstAppData->iDataWriteMTU);
259 fprintf(stderr,
"%d\t: %s - Device Delay = %d \n", __LINE__, __FUNCTION__, pstAppData->ui32DevDelay);
261 if (pstAppData->stBtrCoreDevMediaInfo.eBtrCoreDevMType == eBTRCoreDevMediaTypeSBC) {
262 if (pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo) {
263 fprintf(stderr,
"%d\t: %s - Device Media Info SFreq = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui32DevMSFreq);
264 fprintf(stderr,
"%d\t: %s - Device Media Info AChan = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->eDevMAChan);
265 fprintf(stderr,
"%d\t: %s - Device Media Info SbcAllocMethod= %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcAllocMethod);
266 fprintf(stderr,
"%d\t: %s - Device Media Info SbcSubbands = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcSubbands);
267 fprintf(stderr,
"%d\t: %s - Device Media Info SbcBlockLength= %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcBlockLength);
268 fprintf(stderr,
"%d\t: %s - Device Media Info SbcMinBitpool = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcMinBitpool);
269 fprintf(stderr,
"%d\t: %s - Device Media Info SbcMaxBitpool = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcMaxBitpool);
270 fprintf(stderr,
"%d\t: %s - Device Media Info SbcFrameLen = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui16DevMSbcFrameLen);
271 fprintf(stderr,
"%d\t: %s - Device Media Info SbcBitrate = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(pstAppData->stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui16DevMSbcBitrate);
282 fprintf(stderr,
"\nEnter a choice...\n");
283 if (scanf(
"%d", &mychoice)) {
293 char sbcEncodedFile[1024];
294 fprintf(stderr,
"%d\t: %s - Enter SBC File location...\n", __LINE__, __FUNCTION__);
295 if (scanf(
"%s", sbcEncodedFile)) {
298 return strdup(sbcEncodedFile);
305 char leUuidString[64];
306 fprintf(stderr,
"%d\t: %s - Enter the UUID for Le device...\n", __LINE__, __FUNCTION__);
307 if (scanf(
"%s",leUuidString )) {
310 return strdup(leUuidString);
315 unsigned short flagBits
319 fprintf(stderr,
"%d", (flagBits >> i) & 1);
331 FILE* sbcFilePtr = fopen(fileLocation,
"rb");
333 void *encoded_buf = NULL;
334 int bytesToSend = mtuSize;
335 struct pollfd pollout = { fd, POLLOUT, 0 };
342 fprintf(stderr,
"%d\t: %s - fileLocation %s", __LINE__, __FUNCTION__, fileLocation);
344 fseek(sbcFilePtr, 0, SEEK_END);
345 bytesLeft = ftell(sbcFilePtr);
346 fseek(sbcFilePtr, 0, SEEK_SET);
348 fprintf(stderr,
"%d\t: %s - File size: %d bytes\n", __LINE__, __FUNCTION__, (
int)bytesLeft);
350 encoded_buf = malloc (mtuSize);
354 if (bytesLeft < mtuSize)
355 bytesToSend = bytesLeft;
357 timeout = poll (&pollout, 1, 1000);
362 fprintf (stderr,
"%d\t: %s - Bluetooth Write Error : %d\n", __LINE__, __FUNCTION__, errno);
366 if (fread (encoded_buf, 1, bytesToSend, sbcFilePtr)) {
368 if (write(fd, encoded_buf, bytesToSend)) {
370 bytesLeft -= bytesToSend;
382 cb_connection_intimation (
384 int* api32ConnInIntimResp,
387 fprintf(stderr,
"%d\t: %s - Choose 35 to verify pin-passcode or 36 to discard pin-passcode\n\n", __LINE__, __FUNCTION__);
389 if (apstConnCbInfo->ui32devPassKey) {
390 fprintf(stderr,
"%d\t: %s - Incoming Connection passkey = %6d\n", __LINE__, __FUNCTION__, apstConnCbInfo->ui32devPassKey);
395 }
while (acceptConnection == 0);
397 fprintf(stderr,
"%d\t: %s - you picked %d\n", __LINE__, __FUNCTION__, acceptConnection);
398 if (acceptConnection == 1) {
399 fprintf(stderr,
"%d\t: %s - Pin-Passcode accepted\n", __LINE__, __FUNCTION__);
400 acceptConnection = 0;
401 *api32ConnInIntimResp = 1;
404 fprintf(stderr,
"%d\t: %s - Pin-Passcode denied\n", __LINE__, __FUNCTION__);
405 acceptConnection = 0;
406 *api32ConnInIntimResp = 0;
409 return enBTRCoreSuccess;
414 cb_connection_authentication (
416 int* api32ConnInAuthResp,
419 fprintf(stderr,
"%d\t: %s - Choose 35 to accept the connection or 36 to deny the connection\n\n", __LINE__, __FUNCTION__);
423 }
while (acceptConnection == 0);
425 fprintf(stderr,
"%d\t: %s - you picked %d\n", __LINE__, __FUNCTION__, acceptConnection);
426 if (acceptConnection == 1) {
427 fprintf(stderr,
"%d\t: %s - connection accepted\n", __LINE__, __FUNCTION__);
428 acceptConnection = 0;
429 *api32ConnInAuthResp = 1;
432 fprintf(stderr,
"%d\t: %s - connection denied\n", __LINE__, __FUNCTION__);
433 acceptConnection = 0;
434 *api32ConnInAuthResp = 0;
437 return enBTRCoreSuccess;
442 cb_unsolicited_bluetooth_status (
447 fprintf(stderr,
"%d\t: %s - app level cb device status change: new state is %d\n", __LINE__, __FUNCTION__, p_StatusCB->eDeviceCurrState);
448 if ((p_StatusCB->eDevicePrevState == enBTRCoreDevStConnected) && (p_StatusCB->eDeviceCurrState == enBTRCoreDevStPlaying)) {
449 if (p_StatusCB->eDeviceType == enBTRCoreMobileAudioIn) {
450 fprintf(stderr,
"%d\t: %s - transition to playing, get the transport info...\n", __LINE__, __FUNCTION__);
455 return enBTRCoreSuccess;
462 fprintf( stderr,
"Bluetooth Test Menu\n\n");
463 fprintf( stderr,
"1. Get Current Adapter\n");
464 fprintf( stderr,
"2. Scan\n");
465 fprintf( stderr,
"3. Show found devices\n");
466 fprintf( stderr,
"4. Pair\n");
467 fprintf( stderr,
"5. UnPair/Forget a device\n");
468 fprintf( stderr,
"6. Show known devices\n");
469 fprintf( stderr,
"7. Connect to Headset/Speakers\n");
470 fprintf( stderr,
"8. Disconnect to Headset/Speakers\n");
471 fprintf( stderr,
"9. Connect as Headset/Speakerst\n");
472 fprintf( stderr,
"10. Disconnect as Headset/Speakerst\n");
473 fprintf( stderr,
"11. Show all Bluetooth Adapters\n");
474 fprintf( stderr,
"12. Enable Bluetooth Adapter\n");
475 fprintf( stderr,
"13. Disable Bluetooth Adapter\n");
476 fprintf( stderr,
"14. Set Discoverable Timeout\n");
477 fprintf( stderr,
"15. Set Discoverable \n");
478 fprintf( stderr,
"16. Set friendly name \n");
479 fprintf( stderr,
"17. Check for audio sink capability\n");
480 fprintf( stderr,
"18. Check for existance of a service\n");
481 fprintf( stderr,
"19. Find service details\n");
482 fprintf( stderr,
"20. Check if Device Paired\n");
483 fprintf( stderr,
"21. Get Connected Dev Data path\n");
484 fprintf( stderr,
"22. Release Connected Dev Data path\n");
485 fprintf( stderr,
"23. Send SBC data to BT Headset/Speakers\n");
486 fprintf( stderr,
"29. BT audio input test\n");
487 fprintf( stderr,
"30. install agent for accepting connections NoInputNoOutput\n");
488 fprintf( stderr,
"31. install agent for accepting connections DisplayYesNo\n");
489 fprintf( stderr,
"32. Uninstall agent - allows device-initiated pairing\n");
490 fprintf( stderr,
"33. Register connection-in intimation callback.\n");
491 fprintf( stderr,
"34. Register connection authentication callback to allow accepting or rejection of connections.\n");
492 fprintf( stderr,
"35. Accept a connection request\n");
493 fprintf( stderr,
"36. Deny a connection request\n");
494 fprintf( stderr,
"37. Check if Device is Connectable\n");
495 fprintf( stderr,
"38. Scan for LE Devices\n");
496 fprintf( stderr,
"39. Connect to LE Device\n");
497 fprintf( stderr,
"40. Disconnect to LE Device\n");
498 fprintf( stderr,
"41. Get Gatt Properties of connected LE device.\n");
499 fprintf( stderr,
"42. Perform Operation on connected LE device.\n");
500 fprintf( stderr,
"43. Connect to HID/Unknown\n");
501 fprintf( stderr,
"44. Disconnect to HID/Unknown\n");
503 fprintf( stderr,
"88. debug test\n");
504 fprintf( stderr,
"99. Exit\n");
512 tBTRCoreHandle lhBTRCore = NULL;
516 int default_adapter = NO_ADAPTER;
520 char default_path[128];
521 char* agent_path = NULL;
527 char *sbcEncodedFileName = NULL;
533 memset(&stAppData, 0,
sizeof(stAppData));
535 snprintf(default_path,
sizeof(default_path),
"/org/bluez/agent_%d", getpid());
538 agent_path = strdup(default_path);
544 lstBTRCoreAdapter.bFirstAvailable =
TRUE;
546 default_adapter = lstBTRCoreAdapter.adapter_number;
547 fprintf(stderr,
"%d\t: %s - GetAdapter Returns Adapter number %d\n", __LINE__, __FUNCTION__, default_adapter);
550 fprintf(stderr,
"%d\t: %s - No bluetooth adapter found!\n", __LINE__, __FUNCTION__);
554 stAppData.hBTRCore = lhBTRCore;
556 BTRCore_RegisterStatusCb(lhBTRCore, cb_unsolicited_bluetooth_status, &stAppData);
563 fileWriteThread = g_thread_new(
"DoSBCwrite", DoSBCwrite, (gpointer)&stAppData);
565 fprintf(stderr,
"Enter a choice...\n");
566 if(scanf(
"%d", &choice)) {
571 fprintf(stderr,
"%d\t: %s - Adapter is %s\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.pcAdapterPath);
574 if (default_adapter != NO_ADAPTER) {
575 fprintf(stderr,
"%d\t: %s - Looking for devices on BT adapter %s\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.pcAdapterPath);
576 fprintf(stderr,
"%d\t: %s - Performing device scan for 15 seconds . Please wait...\n", __LINE__, __FUNCTION__);
578 fprintf(stderr,
"%d\t: %s - scan complete\n", __LINE__, __FUNCTION__);
581 fprintf(stderr,
"%d\t: %s - Error, no default_adapter set\n", __LINE__, __FUNCTION__);
587 fprintf(stderr,
"%d\t: %s - Show Found Devices\n", __LINE__, __FUNCTION__);
588 lstBTRCoreAdapter.adapter_number = myadapter;
591 fprintf(stderr,
"%d\t: %s - Display Ad Service data for scanned devices\n", __LINE__, __FUNCTION__);
592 fprintf(stderr,
"%d\t: %s - *******************************************\n", __LINE__, __FUNCTION__);
593 fprintf(stderr,
"%d\t: %s - numberOfDevices : %d \n", __LINE__, __FUNCTION__, lstBTRCoreScannedDevList.numberOfDevices);
595 for(
int i = 0; i < lstBTRCoreScannedDevList.numberOfDevices; i++)
597 fprintf(stderr,
"%d\t: %s - ServiceData from Scanned Device : %d \n", __LINE__, __FUNCTION__, i);
599 for(
int count = 0; count < lstBTRCoreScannedDevList.devices[i].stDeviceProfile.numberOfService; count++)
601 fprintf(stderr,
"%d\t: %s - ServiceData for UUID : %s \n", __LINE__, __FUNCTION__, lstBTRCoreScannedDevList.devices[i].stAdServiceData[count].pcUUIDs);
602 if(0 != lstBTRCoreScannedDevList.devices[i].stAdServiceData[count].len)
604 for (
int j =0; j < lstBTRCoreScannedDevList.devices[i].stAdServiceData[count].len; j++){
605 fprintf(stderr,
"%d\t: %s - ServiceData[%d] = [%x]\n ", __LINE__, __FUNCTION__, j, lstBTRCoreScannedDevList.devices[i].stAdServiceData[count].pcData[j]);
616 fprintf(stderr,
"%d\t: %s - Pick a Device to Pair...\n", __LINE__, __FUNCTION__);
617 lstBTRCoreAdapter.adapter_number = myadapter;
619 devnum = getChoice();
621 fprintf(stderr,
"%d\t: %s - adapter_path %s\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.pcAdapterPath);
622 fprintf(stderr,
"%d\t: %s - agent_path %s\n", __LINE__, __FUNCTION__, agent_path);
624 fprintf(stderr,
"%d\t: %s - device pairing successful.\n", __LINE__, __FUNCTION__);
626 fprintf(stderr,
"%d\t: %s - device pairing FAILED.\n", __LINE__, __FUNCTION__);
632 fprintf(stderr,
"%d\t: %s - UnPair/Forget a device\n", __LINE__, __FUNCTION__);
633 fprintf(stderr,
"%d\t: %s - Pick a Device to Remove...\n", __LINE__, __FUNCTION__);
634 lstBTRCoreAdapter.adapter_number = myadapter;
636 devnum = getChoice();
643 fprintf(stderr,
"%d\t: %s - Show Known Devices...using BTRCore_GetListOfPairedDevices\n", __LINE__, __FUNCTION__);
644 lstBTRCoreAdapter.adapter_number = myadapter;
651 fprintf(stderr,
"%d\t: %s - Pick a Device to Connect...\n", __LINE__, __FUNCTION__);
652 lstBTRCoreAdapter.adapter_number = myadapter;
654 devnum = getChoice();
656 connectedDeviceIndex = devnum;
657 fprintf(stderr,
"%d\t: %s - device connect process completed.\n", __LINE__, __FUNCTION__);
663 fprintf(stderr,
"%d\t: %s - Pick a Device to Disconnect...\n", __LINE__, __FUNCTION__);
664 lstBTRCoreAdapter.adapter_number = myadapter;
666 devnum = getChoice();
668 fprintf(stderr,
"%d\t: %s - device disconnect process completed.\n", __LINE__, __FUNCTION__);
674 fprintf(stderr,
"%d\t: %s - Pick a Device to Connect...\n", __LINE__, __FUNCTION__);
675 lstBTRCoreAdapter.adapter_number = myadapter;
677 devnum = getChoice();
679 connectedDeviceIndex = devnum;
680 fprintf(stderr,
"%d\t: %s - device connect process completed.\n", __LINE__, __FUNCTION__);
686 fprintf(stderr,
"%d\t: %s - Pick a Device to Disonnect...\n", __LINE__, __FUNCTION__);
687 lstBTRCoreAdapter.adapter_number = myadapter;
689 devnum = getChoice();
691 fprintf(stderr,
"%d\t: %s - device disconnect process completed.\n", __LINE__, __FUNCTION__);
695 fprintf(stderr,
"%d\t: %s - Getting all available adapters\n", __LINE__, __FUNCTION__);
698 if ( GetAdapters.number_of_adapters > 1) {
699 fprintf(stderr,
"%d\t: %s - There are %d Bluetooth adapters\n", __LINE__, __FUNCTION__, GetAdapters.number_of_adapters);
700 fprintf(stderr,
"%d\t: %s - current adatper is %s\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.pcAdapterPath);
701 fprintf(stderr,
"%d\t: %s - Which adapter would you like to use (0 = default)?\n", __LINE__, __FUNCTION__);
702 myadapter = getChoice();
709 lstBTRCoreAdapter.adapter_number = myadapter;
710 fprintf(stderr,
"%d\t: %s - Enabling adapter %d\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.adapter_number);
714 lstBTRCoreAdapter.adapter_number = myadapter;
715 fprintf(stderr,
"%d\t: %s - Disabling adapter %d\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.adapter_number);
719 fprintf(stderr,
"%d\t: %s - Enter discoverable timeout in seconds. Zero seconds = FOREVER \n", __LINE__, __FUNCTION__);
720 lstBTRCoreAdapter.DiscoverableTimeout = getChoice();
721 fprintf(stderr,
"%d\t: %s - setting DiscoverableTimeout to %d\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.DiscoverableTimeout);
725 fprintf(stderr,
"%d\t: %s - Set discoverable. Zero = Not Discoverable, One = Discoverable \n", __LINE__, __FUNCTION__);
726 lstBTRCoreAdapter.discoverable = getChoice();
727 fprintf(stderr,
"%d\t: %s - setting discoverable to %d\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.discoverable);
732 char lcAdapterName[64] = {
'\0'};
733 fprintf(stderr,
"%d\t: %s - Set friendly name (up to 64 characters): \n", __LINE__, __FUNCTION__);
734 if (fgets(lcAdapterName, 63 , stdin)) {
736 fprintf(stderr,
"%d\t: %s - setting name to %s\n", __LINE__, __FUNCTION__, lcAdapterName);
743 fprintf(stderr,
"%d\t: %s - Check for Audio Sink capability\n", __LINE__, __FUNCTION__);
744 fprintf(stderr,
"%d\t: %s - Pick a Device to Check for Audio Sink...\n", __LINE__, __FUNCTION__);
745 lstBTRCoreAdapter.adapter_number = myadapter;
747 devnum = getChoice();
748 if (
BTRCore_FindService(lhBTRCore, devnum, BTR_CORE_A2SNK,NULL,&bfound) == enBTRCoreSuccess) {
750 fprintf(stderr,
"%d\t: %s - Service UUID BTRCore_A2SNK is found\n", __LINE__, __FUNCTION__);
753 fprintf(stderr,
"%d\t: %s - Service UUID BTRCore_A2SNK is NOT found\n", __LINE__, __FUNCTION__);
757 fprintf(stderr,
"%d\t: %s - Error on BTRCore_FindService\n", __LINE__, __FUNCTION__);
764 fprintf(stderr,
"%d\t: %s - Find a Service\n", __LINE__, __FUNCTION__);
765 fprintf(stderr,
"%d\t: %s - Pick a Device to Check for Services...\n", __LINE__, __FUNCTION__);
766 lstBTRCoreAdapter.adapter_number = myadapter;
768 devnum = getChoice();
769 fprintf(stderr,
"%d\t: %s - enter UUID of desired service... e.g. 0x110b for Audio Sink\n", __LINE__, __FUNCTION__);
770 if (fgets(myService,
sizeof(myService),stdin)) {
772 for (i=0;i<
sizeof(myService);i++)
774 if(myService[i] ==
'\n')
780 fprintf(stderr,
"%d\t: %s - Service UUID %s is found\n", __LINE__, __FUNCTION__, myService);
783 fprintf(stderr,
"%d\t: %s - Service UUID %s is NOT found\n", __LINE__, __FUNCTION__, myService);
787 fprintf(stderr,
"%d\t: %s - Error on BTRCore_FindService\n", __LINE__, __FUNCTION__);
794 fprintf(stderr,
"%d\t: %s - Find a Service and get details\n", __LINE__, __FUNCTION__);
795 fprintf(stderr,
"%d\t: %s - Pick a Device to Check for Services...\n", __LINE__, __FUNCTION__);
796 lstBTRCoreAdapter.adapter_number = myadapter;
798 devnum = getChoice();
799 fprintf(stderr,
"%d\t: %s - enter UUID of desired service... e.g. 0x110b for Audio Sink\n", __LINE__, __FUNCTION__);
800 if (fgets(myService,
sizeof(myService),stdin)) {
802 for (i=0;i<
sizeof(myService);i++)
804 if(myService[i] ==
'\n')
816 fprintf(stderr,
"%d\t: %s - Service UUID %s is found\n", __LINE__, __FUNCTION__, myService);
817 fprintf(stderr,
"%d\t: %s - Data is:\n %s \n", __LINE__, __FUNCTION__, myData);
820 fprintf(stderr,
"%d\t: %s - Service UUID %s is NOT found\n", __LINE__, __FUNCTION__, myService);
824 fprintf(stderr,
"%d\t: %s - Error on BTRCore_FindService\n", __LINE__, __FUNCTION__);
831 fprintf(stderr,
"%d\t: %s - Pick a Device to Find (see if it is already paired)...\n", __LINE__, __FUNCTION__);
832 lstBTRCoreAdapter.adapter_number = myadapter;
834 devnum = getChoice();
836 fprintf(stderr,
"%d\t: %s - device FOUND successful.\n", __LINE__, __FUNCTION__);
838 fprintf(stderr,
"%d\t: %s - device was NOT found.\n", __LINE__, __FUNCTION__);
844 fprintf(stderr,
"%d\t: %s - Pick a Device to Get Data tranport parameters...\n", __LINE__, __FUNCTION__);
845 lstBTRCoreAdapter.adapter_number = myadapter;
847 devnum = getChoice();
851 stAppData.iDataPath = 0;
852 stAppData.iDataReadMTU = 0;
853 stAppData.iDataWriteMTU = 0;
854 stAppData.ui32DevDelay = 0;
856 BTRCore_AcquireDeviceDataPath(lhBTRCore, devnum, enBTRCoreSpeakers, &stAppData.iDataPath, &stAppData.iDataReadMTU, &stAppData.iDataWriteMTU, &stAppData.ui32DevDelay);
858 fprintf(stderr,
"%d\t: %s - Device Data Path = %d \n", __LINE__, __FUNCTION__, stAppData.iDataPath);
859 fprintf(stderr,
"%d\t: %s - Device Data Read MTU = %d \n", __LINE__, __FUNCTION__, stAppData.iDataReadMTU);
860 fprintf(stderr,
"%d\t: %s - Device Data Write MTU= %d \n", __LINE__, __FUNCTION__, stAppData.iDataWriteMTU);
861 fprintf(stderr,
"%d\t: %s - Device Delay = %d \n", __LINE__, __FUNCTION__, stAppData.ui32DevDelay);
863 if (stAppData.stBtrCoreDevMediaInfo.eBtrCoreDevMType == eBTRCoreDevMediaTypeSBC) {
864 if (stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo) {
865 fprintf(stderr,
"%d\t: %s - Device Media Info SFreq = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui32DevMSFreq);
866 fprintf(stderr,
"%d\t: %s - Device Media Info AChan = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->eDevMAChan);
867 fprintf(stderr,
"%d\t: %s - Device Media Info SbcAllocMethod= %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcAllocMethod);
868 fprintf(stderr,
"%d\t: %s - Device Media Info SbcSubbands = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcSubbands);
869 fprintf(stderr,
"%d\t: %s - Device Media Info SbcBlockLength= %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcBlockLength);
870 fprintf(stderr,
"%d\t: %s - Device Media Info SbcMinBitpool = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcMinBitpool);
871 fprintf(stderr,
"%d\t: %s - Device Media Info SbcMaxBitpool = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui8DevMSbcMaxBitpool);
872 fprintf(stderr,
"%d\t: %s - Device Media Info SbcFrameLen = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui16DevMSbcFrameLen);
873 fprintf(stderr,
"%d\t: %s - Device Media Info SbcBitrate = %d\n", __LINE__, __FUNCTION__, ((
stBTRCoreDevMediaSbcInfo*)(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo))->ui16DevMSbcBitrate);
881 fprintf(stderr,
"%d\t: %s - Pick a Device to ReleaseData tranport...\n", __LINE__, __FUNCTION__);
882 lstBTRCoreAdapter.adapter_number = myadapter;
884 devnum = getChoice();
887 stAppData.iDataPath = 0;
888 stAppData.iDataReadMTU = 0;
889 stAppData.iDataWriteMTU = 0;
893 fprintf(stderr,
"%d\t: %s - Enter Encoded SBC file location to send to BT Headset/Speakers...\n", __LINE__, __FUNCTION__);
894 sbcEncodedFileName = getEncodedSBCFile();
895 if (sbcEncodedFileName) {
896 fprintf(stderr,
"%d\t: %s - We will send %s to BT FD %d \n", __LINE__, __FUNCTION__, sbcEncodedFileName, stAppData.iDataPath);
897 sendSBCFileOverBT(sbcEncodedFileName, stAppData.iDataPath, stAppData.iDataWriteMTU);
898 free(sbcEncodedFileName);
899 sbcEncodedFileName = NULL;
902 fprintf(stderr,
"%d\t: %s - Invalid file location\n", __LINE__, __FUNCTION__);
906 fprintf(stderr,
"%d\t: %s - rtp deplayload and play some music over BT\n", __LINE__, __FUNCTION__);
907 fprintf(stderr,
"%d\t: %s - about how many minutes to play?\n", __LINE__, __FUNCTION__);
908 choice = getChoice();
909 BT_loop = 6000 * choice;
912 if (system(
"gst-launch-1.0 filesrc location=/tmp/myfifo ! sbcparse ! sbcdec ! brcmpcmsink")) {
916 fprintf(stderr,
"%d\t: %s - install agent - NoInputNoOutput\n", __LINE__, __FUNCTION__);
920 fprintf(stderr,
"%d\t: %s - install agent - DisplayYesNo\n", __LINE__, __FUNCTION__);
924 fprintf(stderr,
"%d\t: %s - uninstall agent - DisplayYesNo\n", __LINE__, __FUNCTION__);
928 fprintf(stderr,
"%d\t: %s - register connection-in Intimation CB\n", __LINE__, __FUNCTION__);
929 BTRCore_RegisterConnectionIntimationCb(lhBTRCore, cb_connection_intimation, NULL);
932 fprintf(stderr,
"%d\t: %s - register authentication CB\n", __LINE__, __FUNCTION__);
933 BTRCore_RegisterConnectionAuthenticationCb(lhBTRCore, cb_connection_authentication, NULL);
936 fprintf(stderr,
"%d\t: %s - accept the connection\n", __LINE__, __FUNCTION__);
937 acceptConnection = 1;
940 fprintf(stderr,
"%d\t: %s - deny the connection\n", __LINE__, __FUNCTION__);
941 acceptConnection = 2;
944 fprintf(stderr,
"%d\t: %s - Pick a Device to Check if Connectable...\n", __LINE__, __FUNCTION__);
945 devnum = getChoice();
949 if (default_adapter != NO_ADAPTER) {
950 fprintf(stderr,
"%d\t: %s - Looking for LE devices on BT adapter %s\n", __LINE__, __FUNCTION__, lstBTRCoreAdapter.pcAdapterPath);
951 fprintf(stderr,
"%d\t: %s - Performing LE scan for 30 seconds . Please wait...\n", __LINE__, __FUNCTION__);
953 fprintf(stderr,
"%d\t: %s - scan complete\n", __LINE__, __FUNCTION__);
956 fprintf(stderr,
"%d\t: %s - Error, no default_adapter set\n", __LINE__, __FUNCTION__);
962 fprintf(stderr,
"%d\t: %s - Pick a LE Device to Connect...\n", __LINE__, __FUNCTION__);
963 lstBTRCoreAdapter.adapter_number = myadapter;
965 devnum = getChoice();
967 connectedDeviceIndex = devnum;
968 fprintf(stderr,
"%d\t: %s - LE device connect process completed.\n", __LINE__, __FUNCTION__);
975 fprintf(stderr,
"%d\t: %s - Pick a LE Device to Disconnect...\n", __LINE__, __FUNCTION__);
976 lstBTRCoreAdapter.adapter_number = myadapter;
978 devnum = getChoice();
980 fprintf(stderr,
"%d\t: %s - LE device disconnect process completed.\n", __LINE__, __FUNCTION__);
985 fprintf(stderr,
"%d\t: %s - Pick a connected LE Device to Show Gatt Properties.\n", __LINE__, __FUNCTION__);
986 lstBTRCoreAdapter.adapter_number = myadapter;
987 devnum = getChoice();
988 char *leUuidString = getLeUuidString();
992 fprintf(stderr,
"%d\t: %s - select the property you want to query for.\n", __LINE__, __FUNCTION__);
993 fprintf(stderr,
"[0 - Uuid | 1 - Primary | 2 - Device | 3 - Service | 4 - Value |"
994 " 5 - Notifying | 6 - Flags | 7 -Character]\n");
995 int propSelection = getChoice();
997 if (!propSelection) {
1001 if (lstBTRCoreUUIDList.numberOfUUID) {
1002 fprintf(stderr,
"\n\nObtained 'Flag' indices are based on the below mapping..\n"
1005 "2 - encrypt-read\n"
1006 "3 - encrypt-write\n"
1007 "4 - encrypt-authenticated-read\n"
1008 "5 - encrypt-authenticated-write\n"
1009 "6 - secure-read (Server only)\n"
1010 "7 - secure-write (Server only)\n"
1014 "11 - write-without-response\n"
1015 "12 - authenticated-signed-writes\n"
1016 "13 - reliable-write\n"
1017 "14 - writable-auxiliaries\n");
1018 fprintf(stderr,
"\n\t%-40s Flag\n",
"UUID List");
1019 for (; i<lstBTRCoreUUIDList.numberOfUUID; i++) {
1020 fprintf(stderr,
"\n\t%-40s ", lstBTRCoreUUIDList.uuidList[i].uuid);
1021 getBitsToString(lstBTRCoreUUIDList.uuidList[i].flags);
1024 fprintf (stderr,
"\n\n\tNo UUIDs Found...\n");
1027 if (propSelection == 1 || propSelection == 5) {
1028 unsigned char val = 0;
1030 fprintf(stderr,
"\n\tResult : %d\n", val);
1032 if (propSelection == 4 || propSelection == 2 ||
1033 propSelection == 3 || propSelection == 7 ){
1034 char val[BTRCORE_MAX_STR_LEN] =
"\0";
1036 fprintf(stderr,
"\n\tResult : %s\n", val);
1038 if (propSelection == 6) {
1039 char val[15][64];
int i=0;
1040 memset (val, 0,
sizeof(val));
1042 fprintf(stderr,
"\n\tResult :\n");
1043 for (; i < 15 && val[i][0]; i++) {
1044 fprintf(stderr,
"\t- %s\n", val[i]);
1048 leUuidString = NULL;
1054 fprintf(stderr,
"%d\t: %s - Pick a connected LE Device to Perform Operation.\n", __LINE__, __FUNCTION__);
1055 lstBTRCoreAdapter.adapter_number = myadapter;
1056 devnum = getChoice();
1057 char *leUuidString = getLeUuidString();
1058 char writeArg[BTRCORE_MAX_STR_LEN] =
"\0";
1060 fprintf(stderr,
"%d\t: %s - Pick a option to perform method operation LE.\n", __LINE__, __FUNCTION__);
1061 fprintf(stderr,
"\t[1 - ReadValue | 2 - WriteValue | 3 - StartNotify | 4 - StopNotify]\n");
1063 enBTRCoreLeOp aenBTRCoreLeOp = getChoice();
1065 if (aenBTRCoreLeOp == enBTRCoreLeOpGWriteValue) {
1066 fprintf(stderr,
"\tEnter the Value to Write : ");
1067 if (scanf(
"%s", writeArg)) {
1072 char val[BTRCORE_MAX_STR_LEN] =
"\0";
1075 leUuidString = NULL;
1076 if (aenBTRCoreLeOp == 1) {
1077 fprintf(stderr,
"%d\t: %s - Obtained Value [%s]\n", __LINE__, __FUNCTION__, val );
1085 fprintf(stderr,
"%d\t: %s - Pick a Device to Connect...\n", __LINE__, __FUNCTION__);
1086 lstBTRCoreAdapter.adapter_number = myadapter;
1088 devnum = getChoice();
1090 connectedDeviceIndex = devnum;
1091 fprintf(stderr,
"%d\t: %s - device connect process completed.\n", __LINE__, __FUNCTION__);
1097 fprintf(stderr,
"%d\t: %s - Pick a Device to Disconnect...\n", __LINE__, __FUNCTION__);
1098 lstBTRCoreAdapter.adapter_number = myadapter;
1100 devnum = getChoice();
1102 fprintf(stderr,
"%d\t: %s - device disconnect process completed.\n", __LINE__, __FUNCTION__);
1107 fprintf(stderr,
"%d\t: %s - Quitting program!\n", __LINE__, __FUNCTION__);
1112 fprintf(stderr,
"%d\t: %s - Available options are:\n", __LINE__, __FUNCTION__);
1119 if (stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo)
1120 free(stAppData.stBtrCoreDevMediaInfo.pstBtrCoreDevMCodecInfo);