Changeset 175
- Timestamp:
- 03/21/09 17:06:47 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/shell/cr_shell.cpp
r169 r175 43 43 { 44 44 for(size_t i = 0; i < ce_info->numUtilities ; i++) { 45 LOG("Shell:: Utility: %s\n\tUnits: %s\n\tGoal: %s\n\tTarget: % s\n", \46 uList[i]->name , uList[i]->units, uList[i]->goal, \47 uList[i]-> target);45 LOG("Shell:: Utility: %s\n\tUnits: %s\n\tGoal: %s\n\tTarget: %f\n", \ 46 uList[i]->name.c_str(), uList[i]->units.c_str(), \ 47 uList[i]->goal.c_str(), uList[i]->target); 48 48 } 49 49 50 50 for(size_t i = 0; i < ce_info->numParameters; i++) { 51 51 LOG("Shell:: Radio Operation Profile has been sucessfully sent.\n"); 52 LOG("Shell:: Parameter: %s\n\tUnits: %s\n\tMin: %s\n\t", \ 53 pList[i]->name, pList[i]->units, pList[i]->min); 54 LOG("\tMax: %s\n\tStep: %s\n", pList[i]->max, pList[i]->step); 52 LOG("Shell:: Parameter: %s\n\tUnits: %s\n\tMin: %f\n\t", \ 53 pList[i]->name.c_str(), pList[i]->units.c_str(), \ 54 pList[i]->min); 55 LOG("\tMax: %f\n\tStep: %f\n", pList[i]->max, pList[i]->step); 55 56 56 57 for(size_t j = 0; j < pList[i]->numAffects; j++) { 57 LOG("\t\tAffect %s -> %s\n", pList[i]->affection_list[j].u->name , \58 pList[i]->affection_list[j].relation );58 LOG("\t\tAffect %s -> %s\n", pList[i]->affection_list[j].u->name.c_str(), \ 59 pList[i]->affection_list[j].relation.c_str()); 59 60 } 60 61 } 61 62 62 63 for(size_t i = 0; i < ce_info->numObservables; i++) { 63 LOG("Observable: %s\n", oList[i]->name );64 LOG("Observable: %s\n", oList[i]->name.c_str()); 64 65 65 66 for(size_t j = 0; j < oList[i]->numAffects; j++) { 66 LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name , \67 oList[i]->affection_list[j].relation );67 LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name.c_str(), \ 68 oList[i]->affection_list[j].relation.c_str()); 68 69 } 69 70 } … … 71 72 72 73 74 // TODO should this function really be called parse 'ce' config? Seems like it 75 // affects the entire radio? 76 // TODO Why are we always returning 1? Is this just a success variable? It's not 77 // even being used when we call it... 78 // TODO this function needs some serious comments 73 79 int32_t 74 80 parse_ce_config(TiXmlDocument* doc, Utility* u[], Parameter* p[], \ … … 116 122 u[item_count]->goal = uGoal; 117 123 118 if(pChild->QueryFloatAttribute("target", &u[i ]->target) != TIXML_SUCCESS)119 u[i ]->target = -1;124 if(pChild->QueryFloatAttribute("target", &u[item_count]->target) != TIXML_SUCCESS) 125 u[item_count]->target = -1; 120 126 121 127 item_count++; … … 143 149 const char *oUtilName = pSecondChild->Attribute("utility"); 144 150 if(oUtilName) { 145 for(attribute_count = 0; u[attribute_count] != NULL; attribute_count++ ) {151 for(attribute_count = 0; u[attribute_count] != NULL; attribute_count++ ) { 146 152 if(u[attribute_count]->name == oUtilName) { 147 o[i ]->affection_list[affect_count].u = u[attribute_count];153 o[item_count]->affection_list[affect_count].u = u[attribute_count]; 148 154 149 155 const char *oRelate = pSecondChild->Attribute("relationship"); … … 158 164 } 159 165 160 if(!match_found) 166 if(!match_found) { 161 167 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 162 o[i]->name, oUtilName); 168 o[item_count]->name.c_str(), oUtilName); 169 } 163 170 else 164 171 match_found = false; … … 189 196 p[item_count]->units = pUnits; 190 197 191 if(pChild->QueryFloatAttribute("min", &p[i ]->min) != TIXML_SUCCESS)198 if(pChild->QueryFloatAttribute("min", &p[item_count]->min) != TIXML_SUCCESS) 192 199 p[item_count]->min = -1; 193 200 194 if(pChild->QueryFloatAttribute("max", &p[i ]->max) != TIXML_SUCCESS)201 if(pChild->QueryFloatAttribute("max", &p[item_count]->max) != TIXML_SUCCESS) 195 202 p[item_count]->max = -1; 196 203 197 if(pChild->QueryFloatAttribute("step", &p[i ]->step) != TIXML_SUCCESS)204 if(pChild->QueryFloatAttribute("step", &p[item_count]->step) != TIXML_SUCCESS) 198 205 p[item_count]->step = -1; 199 206 … … 223 230 if(!match_found) { 224 231 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 225 p[item_count]->name , pUtilName);232 p[item_count]->name.c_str(), pUtilName); 226 233 } 227 234 … … 237 244 238 245 return 1; 239 }240 241 242 int32_t243 ReceiveMessage(int32_t socket, char* buffer)244 {245 int32_t i,n;246 247 n = recv(socket,buffer,256,MSG_PEEK);248 249 for(i=0;i<256;i++){250 if(strcmp(&buffer[i],"\0") == 0) break;251 }252 n = recv(socket,buffer,i+1,0);253 if (n < 0)254 ERROR(1, "Error reading from socket!\n");255 // printf("ReadMessage:%s %d\n",buffer,n);256 257 return n;258 }259 260 261 int32_t262 SendMessage(int32_t socketfd, string message)263 {264 int32_t n;265 266 message.append("\0");267 // Write message back to client268 n = send(socketfd,message.c_str(),(message.size()+1),0);269 if (n<0)270 ERROR(1, "Error sending to client\n");271 if(n == 0)272 printf("Client closed the socket.\n");273 274 //printf("SendMessage:%s %d\n",message.c_str(),n);275 return n;276 246 } 277 247 … … 292 262 // send utility 293 263 for(i = 0; i < ce_info->numUtilities; i++) { 294 SendMessage(socketfd, uList[i]->name);295 SendMessage(socketfd, uList[i]->units);296 SendMessage(socketfd, uList[i]->goal);297 sprintf(var,"%f", uList[i]->target);264 SendMessage(socketfd, uList[i]->name.c_str()); 265 SendMessage(socketfd, uList[i]->units.c_str()); 266 SendMessage(socketfd, uList[i]->goal.c_str()); 267 sprintf(var,"%f", uList[i]->target); 298 268 SendMessage(socketfd,var); 299 269 } … … 303 273 SendMessage(socketfd,counter); 304 274 for(i = 0; i < ce_info->numParameters; i++) { 305 SendMessage(socketfd,pList[i]->name );306 SendMessage(socketfd,pList[i]->units );275 SendMessage(socketfd,pList[i]->name.c_str()); 276 SendMessage(socketfd,pList[i]->units.c_str()); 307 277 sprintf(var,"%f",pList[i]->min); 308 278 SendMessage(socketfd,var); … … 315 285 SendMessage(socketfd,counter); 316 286 for(j = 0; j < pList[i]->numAffects; j++) { 317 SendMessage(socketfd,pList[i]->affection_list[j].u->name );318 SendMessage(socketfd,pList[i]->affection_list[j].relation );287 SendMessage(socketfd,pList[i]->affection_list[j].u->name.c_str()); 288 SendMessage(socketfd,pList[i]->affection_list[j].relation.c_str()); 319 289 } 320 290 } … … 324 294 SendMessage(socketfd,counter); 325 295 for(i = 0; i < ce_info->numObservables; i++) { 326 SendMessage(socketfd,oList[i]->name );296 SendMessage(socketfd,oList[i]->name.c_str()); 327 297 328 298 sprintf(counter,"%i",oList[i]->numAffects); 329 299 SendMessage(socketfd,counter); 330 300 for(j = 0; j < oList[i]->numAffects; j++) { 331 SendMessage(socketfd,oList[i]->affection_list[j].u->name );332 SendMessage(socketfd,oList[i]->affection_list[j].relation );301 SendMessage(socketfd,oList[i]->affection_list[j].u->name.c_str()); 302 SendMessage(socketfd,oList[i]->affection_list[j].relation.c_str()); 333 303 } 334 304 } … … 337 307 char buffer[256]; 338 308 string message; 339 n = ReceiveMessage(socketfd, buffer);309 ReadMessage(socketfd, buffer); 340 310 //printf("%s\n", buffer); 341 311 //cout << message << endl; … … 399 369 char var[50]; 400 370 int32_t i; 401 string control_msg;371 char* control_msg = "val"; 402 372 403 373 int32_t socketfd = ce_info->policy_socket; 404 374 405 375 // Control message that validation request is coming 406 control_msg = "val";407 376 SendMessage(socketfd,control_msg); 408 377 … … 413 382 SendMessage(socketfd,counter); 414 383 for(i = 0; i < ce_info->numParameters; i++) { 415 SendMessage(socketfd,pList[i]->name );416 SendMessage(socketfd,pList[i]->units );384 SendMessage(socketfd,pList[i]->name.c_str()); 385 SendMessage(socketfd,pList[i]->units.c_str()); 417 386 sprintf(var,"%f",pList[i]->min); 418 387 SendMessage(socketfd,var); … … 449 418 for (i = 0; i < ce_info->numParameters; i++){ 450 419 bzero(buffer,256); 451 Re ceiveMessage(sockfd,buffer);420 ReadMessage(sockfd,buffer); 452 421 var = atof(buffer); 453 422 pList[i]->value = var; … … 594 563 /* Receive message from client */ 595 564 bzero(buffer,256); 596 Re ceiveMessage(socketfd,buffer);565 ReadMessage(socketfd,buffer); 597 566 598 567 printf("Cognitive Radio:: Message Received - %s.\n\n", buffer);