Changeset 95
- Timestamp:
- 02/09/09 16:51:58 (15 years ago)
- Location:
- vtcross/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/CR_engines/CBR/src/main_cognitive_engine.c
r89 r95 285 285 strcpy(buffer, "xml received"); 286 286 SendMessage(sockfd, buffer); 287 printf("xml reception done\n");287 //printf("xml reception done\n"); 288 288 289 289 return 1; … … 306 306 } 307 307 308 int GetRequest(int sockfd) 309 { 310 char buffer[256]; 311 312 bzero(buffer,256); 313 ReadMessage(sockfd,buffer); 314 315 return 1; 316 } 308 317 309 318 int GetExperience(int sockfd, int num_rows, int num_cols, … … 536 545 // get xml info from server 537 546 GetXMLFromServer(sockfd, uList, pList, oList, &ce_info); 538 print_current_config(uList, pList, oList, &ce_info); 539 547 printf("Received Radio Operation Profile from Server Successfully.\n\n"); 548 //print_current_config(uList, pList, oList, &ce_info); 549 550 540 551 // get experience size from server 541 552 int num_rows, num_cols; 542 553 GetExperienceSize(sockfd, &num_rows, &num_cols); 554 543 555 // get experience 544 556 int i, j; 545 /*float **past_exp;546 past_exp = (float **)malloc(sizeof(float)*num_rows);547 for (i = 0; i< 1; i++){548 past_exp[i] = (float*)malloc(sizeof(float)*num_cols);549 }*/550 557 float past_exp[num_rows][num_cols]; 551 558 GetExperience(sockfd, num_rows, num_cols, past_exp); 552 for (i = 0; i < num_rows; i++){ 553 printf("experience #%d:\n", i+1); 554 for (j = 0; j < num_cols; j++){ 555 printf(" %f", past_exp[i][j]); 556 } 557 printf("\n"); 558 } 559 559 printf("Received Previous Radio Experience from Server Successfully.\n\n"); 560 560 561 // calculate utility 561 562 562 563 563 // cbr operation … … 567 567 num_cols = num_cols + ce_info.numObservables; 568 568 num_cols = num_cols + 1; // overall utility 569 printf("number of rows: %d, number of columns: %d\n", 570 num_rows, num_cols); 571 RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows, 569 570 //while(1) { 571 572 // Wait until request is received from server to perform optimization 573 //printf("Waiting for Request for optimization from Server\n\n"); 574 //GetRequest(sockfd); 575 //printf("Received optimization request from server\n\n"); 576 RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows, 572 577 past_exp); 573 // print out results 574 //int i; 575 printf("search result: "); 576 for (i=0;i<ce_info.numUtilities; i++) 577 printf("%f, ",uList[i].value); 578 for (i=0;i<ce_info.numParameters; i++) 579 printf("%f, ",pList[i].value); 580 for (i=0;i<ce_info.numObservables; i++) 581 printf("%f, ",oList[i].value); 582 printf("\n"); 583 584 // send results back to server 585 SendCEResults(sockfd, uList, pList, oList, &ce_info); 586 587 588 return 0; 589 } 578 579 printf("Sending optimization results to server.\n\n"); 580 // send results back to server 581 SendCEResults(sockfd, uList, pList, oList, &ce_info); 582 //} 583 584 return 0; 585 } -
vtcross/trunk/CR_shell/Makefile
r66 r95 3 3 # 4 4 5 TESTS = cognitive_radio cognitive_engine5 TESTS = cognitive_radio 6 6 #CTESTS = client 7 7 all: $(TESTS) $(CTESTS) … … 15 15 16 16 OBJS = tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o 17 SOCKET_OBJS = ServerSocket.o Socket.o17 #SOCKET_OBJS = ServerSocket.o Socket.o 18 18 #OBJS = cbr.o sqlite3.o utility.o cognitive_radio_test.o ezxml.o 19 19 … … 23 23 # src/utility.h src/cognitive_radio_test.h 24 24 25 $(SOCKET_OBJS) : %.o : src/socket/%.cpp26 $(CC) $(CFLAGS) -c $< -o $@25 #$(SOCKET_OBJS) : %.o : src/socket/%.cpp 26 # $(CC) $(CFLAGS) -c $< -o $@ 27 27 28 28 $(OBJS) : %.o : src/%.cpp $(HEADERS) -
vtcross/trunk/CR_shell/src/main_cognitive_radio.cpp
r90 r95 59 59 for(i = 0; i < ce_info->numParameters; i++) { 60 60 cout << "Parameter: " << pList[i]->name << endl; 61 printf("Radio Operation Profile has been sucessfully sent.\n"); 61 62 cout << " Units: " << pList[i]->units << endl; 62 63 cout << " Min: " << pList[i]->min << endl; … … 115 116 } 116 117 ce_info->numUtilities = i; 117 cout << " Parsed " << ce_info->numUtilities << " utilities." << endl;118 cout << "Initialize:: Parsed " << ce_info->numUtilities << " utilities." << endl; 118 119 119 120 // Pull observable information from XML file. … … 157 158 } 158 159 ce_info->numObservables = i; 159 cout << " Parsed " << ce_info->numObservables << " observables." << endl;160 cout << "Initialize:: Parsed " << ce_info->numObservables << " observables." << endl; 160 161 161 162 … … 210 211 } 211 212 ce_info->numParameters = i; 212 cout << " Parsed " << ce_info->numParameters << " parameters." << endl;213 cout << "Initialize:: Parsed " << ce_info->numParameters << " parameters." << endl; 213 214 return 1; 214 215 } … … 269 270 //int total_bytes; 270 271 271 printf("Sending configuration to CE.\n");272 printf("Sending Radio Operating Profile to Cognitive Engine.\n\n"); 272 273 273 274 // utilities … … 319 320 } 320 321 321 printf("Configuration sent, waiting for ACK...\n");322 322 // Receive ACK for utils 323 323 char buffer[256]; 324 324 string message; 325 325 n = ReceiveMessage(socketfd, buffer); 326 printf("%s\n", buffer);326 //printf("%s\n", buffer); 327 327 //cout << message << endl; 328 printf("ACK received.\n");328 //printf("ACK received.\n"); 329 329 330 330 } … … 368 368 } 369 369 370 printf("experience sent\n");371 370 } 372 371 … … 389 388 float var; 390 389 391 /*// utility 392 for (i = 0; i < ce_info->numUtilities; i++){ 393 bzero(buffer,256); 394 ReceiveMessage(sockfd,buffer); 395 var = atof(buffer); 396 uList[i]->value = var; 397 printf("utility %s, value %f\n" 398 , uList[i]->name.c_str(), uList[i]->value); 399 }*/ 400 401 // paramter 390 // Send request optimization message followed by the current environment parameters. 391 /* 392 SendMessage(sockfd,"request"); 393 for (i = 0; i < ce_info->numObservables; i++){ 394 SendMessage(sockfd,..); 395 } 396 */ 397 398 // Receive optimized values from the Cognitive Engine 402 399 for (i = 0; i < ce_info->numParameters; i++){ 403 400 bzero(buffer,256); … … 405 402 var = atof(buffer); 406 403 pList[i]->value = var; 407 printf("parameter %s, value %f\n"408 , pList[i]->name.c_str(), pList[i]->value);409 404 } 410 405 411 /*// observable412 for (i = 0; i < ce_info->numObservables; i++){413 bzero(buffer,256);414 ReceiveMessage(sockfd,buffer);415 var = atof(buffer);416 oList[i]->value = var;417 printf("observable %s, value %f\n"418 , oList[i]->name.c_str(), oList[i]->value);419 }*/420 406 421 407 return 1; … … 476 462 477 463 // update ce with experience 464 printf("Sending Previous Experience to New Cognitive Engine.\n\n"); 478 465 UpdateCEExperience(socketfd, num_rows, num_cols, past_exp); 479 466 … … 484 471 // Start socket server 485 472 int sockfd, newsockfd, clilen; 473 int peer_len = sizeof(struct sockaddr); 486 474 struct sockaddr_in serv_addr, cli_addr; 475 struct sockaddr_in peer; 476 487 477 488 478 // Setup server socket connection … … 507 497 error("ERROR on accept"); 508 498 499 if(getpeername(newsockfd, (struct sockaddr *) &peer, (socklen_t*)&peer_len) == -1) { 500 perror("getpeername() failed"); 501 return -1; 502 } 503 504 printf("Received a connection from a Cognitive Engine with IP address: %s\n\n",inet_ntoa(peer.sin_addr)); 505 509 506 // Begin parsing the messages 510 507 StartMessaging(newsockfd, uList, pList, oList, ce_info); … … 541 538 } 542 539 543 cout << " Attemping to parse " << pFilename << "." << endl;540 cout << "\n\nInitialize:: Attemping to parse " << pFilename << "." << endl; 544 541 parse_ce_config( &doc , uList, pList, oList, &ce_info); 545 cout << " Configuration file parsing completed." << endl;542 cout << "Initialize:: Configuration file parsing completed.\n" << endl; 546 543 547 544 //print_current_config(uList, pList, oList, &ce_info);