Click here to Skip to main content
14,218,418 members

C / C++ / MFC

 
AnswerRe: Write in registry Pin
Richard Deeming13-Mar-19 1:41
mveRichard Deeming13-Mar-19 1:41 
GeneralRe: Write in registry Pin
_Flaviu13-Mar-19 3:53
member_Flaviu13-Mar-19 3:53 
Questioninline question Pin
Rw23712-Mar-19 12:52
memberRw23712-Mar-19 12:52 
AnswerRe: inline question Pin
CPallini12-Mar-19 21:48
mveCPallini12-Mar-19 21:48 
QuestionC code for fourth degree polynomials Pin
Member 1417766810-Mar-19 19:45
memberMember 1417766810-Mar-19 19:45 
AnswerRe: C code for fourth degree polynomials Pin
Victor Nijegorodov10-Mar-19 22:27
memberVictor Nijegorodov10-Mar-19 22:27 
AnswerRe: C code for fourth degree polynomials Pin
leon de boer12-Mar-19 3:56
memberleon de boer12-Mar-19 3:56 
QuestionUnexpected sequence of cout / perror in console output Pin
Vaclav_10-Mar-19 7:23
memberVaclav_10-Mar-19 7:23 
Could somebody please explain to me why I do not see the "perror" in expected code sequence?
Thanks



int main() {
	// modified from scan.c
	// http://people.csail.mit.edu/albert/bluez-intro/c404.html
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	cout << "Basic bluetooth app BLUEZ_LINUX " << endl; // prints !!!Hello World!!!
	inquiry_info *ii = NULL;

	/*
	 *
	 *  The inquiry_info structure is defined as

	 typedef struct {
	 bdaddr_t    bdaddr;
	 uint8_t     pscan_rep_mode;
	 uint8_t     pscan_period_mode;
	 uint8_t     pscan_mode;
	 uint8_t     dev_class[3];
	 uint16_t    clock_offset;
	 } __attribute__ ((packed)) inquiry_info;
	 *
	 *
	 *
	 *
	 */
//HERE NEED TO INITIALIZE SOME OF THESE ??
	int max_rsp, num_rsp;
	int dev_id, sock, len, flags;
	int i;
	char addr[19] = { 0 };
	char name[248] = { 0 };

	// Get bluetooth device id
	dev_id = hci_get_route(NULL); // Passing NULL argument will retrieve the id of first avalaibe device

SHOULD PRINT PERROR HERE ??

	if (dev_id < 0) {
		//printf("Error: Bluetooth device not found");
		perror("Error: Bluetooth device not found"); // adds perror "no such device "
		// exit(1);
	}
#ifdef DEBUG
	cout << " dev_id = hci_get_route(NULL) " << endl; // prints !!!Hello World!!!
	cout << " dev_id  " << hex << +dev_id << endl; // prints !!!Hello World!!!
#endif

#ifdef BYPASS // replaced with abpve perror
	dev_id = hci_get_route(NULL); // what is valid dev_id ??

#endif

	sock = hci_open_dev(dev_id);

#ifdef DEBUG
	cout << " sock = hci_open_dev( dev_id ) " << endl; // prints !!!Hello World!!!
	cout << " sock  " << hex << +sock << endl; // prints !!!Hello World!!!
#endif

	if (dev_id < 0 || sock < 0) {
		perror("Error: Opening socket");
		//exit(1);
	}
#ifdef DEBUG
	cout << " HERE  @line " << dec << __LINE__ << endl; // prints !!!Hello World!!!
	cout << " TRACE file " << __FILE__ << endl;
	cout << " function " << __FUNCTION__ << endl;
#endif
// need desrtip[tion
	len = 8;
	max_rsp = 255;
	flags = IREQ_CACHE_FLUSH;

#ifdef DEBUG
	cout << " HERE  @line " << dec << __LINE__ << endl; // prints !!!Hello World!!!
	cout << " TRACE file " << __FILE__ << endl;
	cout << " function " << __FUNCTION__ << endl;
#endif

	ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
// not an error just checking but it exi6ts after second perror
#ifdef BYPASS
	if (ii)
		perror("Error: inquiry_info*");
	if (ii)
		perror("Error: inquiry_info*");
#endif

#ifdef DEBUG
	cout << " HERE  @line " << dec << __LINE__ << endl;
	cout << " TRACE file " << __FILE__ << endl;
	cout << " function " << __FUNCTION__ << endl;
#endif

// stops here
// NOTE hci_inquiry runs perror (?)
#ifdef DEBUG

cout << " max_rsp " << hex << +max_rsp << endl;
cout << " num_rsp " << hex << +num_rsp << endl;
cout << " len     " << hex << +len << endl;
cout << " flags  " << hex << +flags << endl;


//exit(42);
#endif

	num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
	if (num_rsp < 0)
		perror("Error: hci_inquiry");

#ifdef BYPASS
	if (num_rsp < 0)
		perror(NULL);
#endif



#ifdef DEBUG
	cout << " num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); "
			<< endl; // prints !!!Hello World!!!
	cout << " num_rsp  " << hex << +num_rsp << endl; // prints !!!Hello World!!!
#endif

	if (num_rsp < 0)
		perror("Error: hci_inquiry");



#ifdef DEBUG
	cout << " HERE  @line " << dec << __LINE__ << endl; // prints !!!Hello World!!!
	cout << " TRACE file " << __FILE__ << endl;
	cout << " function " << __FUNCTION__ << endl;
#endif







	for (i = 0; i < num_rsp; i++) {
		ba2str(&(ii + i)->bdaddr, addr);
		memset(name, 0, sizeof(name));
		if (hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name), name, 0)
				< 0)
			strcpy(name, "[unknown]");
		printf("%s  %s\n", addr, name);
	}

#ifdef BYPASS

	free( ii );
	close( sock );

#endif

	return 0;
}


Basic bluetooth app BLUEZ_LINUX 
 dev_id = hci_get_route(NULL) 
 dev_id  ffffffff
 sock = hci_open_dev( dev_id ) 
 sock  ffffffff
 HERE  @line 84
 TRACE file ../src/BLUE.cpp
 function main
 HERE  @line 94
 TRACE file ../src/BLUE.cpp
 function main
 HERE  @line 109
 TRACE file ../src/BLUE.cpp
 function main
 max_rsp ff
 num_rsp 0
 len     8
 flags  1
 num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); 
 num_rsp  ffffffff
 HERE  @line 154
 TRACE file ../src/BLUE.cpp
 function main
Error: Bluetooth device not found: No such device
Error: Opening socket: No such device
Error: hci_inquiry: No such device
Error: hci_inquiry: No such device

AnswerRe: Unexpected sequence of cout / perror in console output Pin
Richard MacCutchan10-Mar-19 22:52
protectorRichard MacCutchan10-Mar-19 22:52 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
k505411-Mar-19 2:28
memberk505411-Mar-19 2:28 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
Richard MacCutchan11-Mar-19 3:56
protectorRichard MacCutchan11-Mar-19 3:56 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
k505411-Mar-19 5:41
memberk505411-Mar-19 5:41 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
Richard MacCutchan11-Mar-19 5:52
protectorRichard MacCutchan11-Mar-19 5:52 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
k505411-Mar-19 11:59
memberk505411-Mar-19 11:59 
GeneralRe: Unexpected sequence of cout / perror in console output Pin
leon de boer11-Mar-19 18:10
memberleon de boer11-Mar-19 18:10 
QuestionC Programming[Solved] Pin
Evolt_Pratom9-Mar-19 1:07
memberEvolt_Pratom9-Mar-19 1:07 
AnswerRe: C Programming Pin
Richard MacCutchan9-Mar-19 1:27
protectorRichard MacCutchan9-Mar-19 1:27 
GeneralRe: C Programming Pin
k50549-Mar-19 4:27
memberk50549-Mar-19 4:27 
GeneralRe: C Programming Pin
Richard MacCutchan9-Mar-19 5:16
protectorRichard MacCutchan9-Mar-19 5:16 
GeneralRe: C Programming Pin
Evolt_Pratom10-Mar-19 3:42
memberEvolt_Pratom10-Mar-19 3:42 
GeneralRe: C Programming Pin
Richard MacCutchan10-Mar-19 7:02
protectorRichard MacCutchan10-Mar-19 7:02 
Questiontemplate confusion Pin
Rw2377-Mar-19 13:00
memberRw2377-Mar-19 13:00 
AnswerRe: template confusion Pin
Rw2378-Mar-19 2:37
memberRw2378-Mar-19 2:37 
GeneralRe: template confusion Pin
Richard MacCutchan8-Mar-19 4:01
protectorRichard MacCutchan8-Mar-19 4:01 
GeneralRe: template confusion Pin
Victor Nijegorodov8-Mar-19 6:21
memberVictor Nijegorodov8-Mar-19 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.