253 | | void StartMessaging(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) { |
| 250 | void GetEnvironment() { |
| 251 | |
| 252 | } |
| 253 | |
| 254 | void Policy_ValidateSettings() { |
| 255 | |
| 256 | } |
| 257 | |
| 258 | // Update operating settings |
| 259 | // This function will interact with the hardware "drivers" |
| 260 | void UpdateRadioSettings() { |
| 261 | |
| 262 | } |
| 263 | |
| 264 | void LoadCEConfiguration(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info){ |
257 | | |
258 | | // while(1) { |
259 | | // Send number of utilities |
260 | | sprintf(counter,"%d",ce_info->numUtilities); |
| 268 | int total_bytes; |
| 269 | |
| 270 | printf("Sending configuration to CE.\n"); |
| 271 | |
| 272 | // Send number of utilities |
| 273 | sprintf(counter,"%d",ce_info->numUtilities); |
| 274 | SendMessage(socketfd,counter); |
| 275 | |
| 276 | // utilities |
| 277 | for(i = 0; i < ce_info->numUtilities; i++) { |
| 278 | SendMessage(socketfd,uList[i]->name); |
| 279 | SendMessage(socketfd,uList[i]->units); |
| 280 | SendMessage(socketfd,uList[i]->goal); |
| 281 | sprintf(var,"%f",uList[i]->target); |
| 282 | SendMessage(socketfd,var); |
| 283 | } |
| 284 | |
| 285 | // parameters |
| 286 | sprintf(counter,"%i",ce_info->numParameters); |
| 287 | SendMessage(socketfd,counter); |
| 288 | for(i = 0; i < ce_info->numParameters; i++) { |
| 289 | SendMessage(socketfd,pList[i]->name); |
| 290 | SendMessage(socketfd,pList[i]->units); |
| 291 | sprintf(var,"%f",pList[i]->min); |
| 292 | SendMessage(socketfd,var); |
| 293 | sprintf(var,"%f",pList[i]->max); |
| 294 | SendMessage(socketfd,var); |
| 295 | sprintf(var,"%f",pList[i]->step); |
| 296 | SendMessage(socketfd,var); |
| 297 | |
| 298 | sprintf(counter,"%i",pList[i]->numAffects); |
262 | | |
263 | | // utilities |
264 | | for(i = 0; i < ce_info->numUtilities; i++) { |
265 | | //for(i = 0; i < 1; i++) { |
266 | | SendMessage(socketfd,uList[i]->name); |
267 | | SendMessage(socketfd,uList[i]->units); |
268 | | SendMessage(socketfd,uList[i]->goal); |
269 | | sprintf(var,"%f",uList[i]->target); |
270 | | SendMessage(socketfd,var); |
271 | | } |
272 | | |
273 | | // parameters |
274 | | sprintf(counter,"%i",ce_info->numParameters); |
| 300 | for(j = 0; j < pList[i]->numAffects; j++) { |
| 301 | SendMessage(socketfd,pList[i]->affection_list[j].u->name); |
| 302 | SendMessage(socketfd,pList[i]->affection_list[j].relation); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // observables |
| 307 | sprintf(counter,"%i",ce_info->numObservables); |
| 308 | SendMessage(socketfd,counter); |
| 309 | for(i = 0; i < ce_info->numObservables; i++) { |
| 310 | SendMessage(socketfd,oList[i]->name); |
| 311 | |
| 312 | sprintf(counter,"%i",oList[i]->numAffects); |
276 | | for(i = 0; i < ce_info->numParameters; i++) { |
277 | | SendMessage(socketfd,pList[i]->name); |
278 | | SendMessage(socketfd,pList[i]->units); |
279 | | sprintf(var,"%f",pList[i]->min); |
280 | | SendMessage(socketfd,var); |
281 | | sprintf(var,"%f",pList[i]->max); |
282 | | SendMessage(socketfd,var); |
283 | | sprintf(var,"%f",pList[i]->step); |
284 | | SendMessage(socketfd,var); |
285 | | |
286 | | sprintf(counter,"%i",pList[i]->numAffects); |
287 | | SendMessage(socketfd,counter); |
288 | | for(j = 0; j < pList[i]->numAffects; j++) { |
289 | | SendMessage(socketfd,pList[i]->affection_list[j].u->name); |
290 | | SendMessage(socketfd,pList[i]->affection_list[j].relation); |
291 | | } |
292 | | } |
293 | | |
294 | | // observables |
295 | | sprintf(counter,"%i",ce_info->numObservables); |
296 | | SendMessage(socketfd,counter); |
297 | | for(i = 0; i < ce_info->numObservables; i++) { |
298 | | SendMessage(socketfd,oList[i]->name); |
299 | | |
300 | | sprintf(counter,"%i",oList[i]->numAffects); |
301 | | SendMessage(socketfd,counter); |
302 | | for(j = 0; j < oList[i]->numAffects; j++) { |
303 | | SendMessage(socketfd,oList[i]->affection_list[j].u->name); |
304 | | SendMessage(socketfd,oList[i]->affection_list[j].relation); |
305 | | } |
306 | | } |
307 | | |
308 | | // Receive a message |
| 314 | for(j = 0; j < oList[i]->numAffects; j++) { |
| 315 | SendMessage(socketfd,oList[i]->affection_list[j].u->name); |
| 316 | SendMessage(socketfd,oList[i]->affection_list[j].relation); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | printf("Configuration sent, waiting for ACK...\n"); |
| 321 | // Receive ACK for utils |
312 | | |
313 | | |
314 | | //printf("n = %d\n", n); |
315 | | /*if (n < 0) { |
316 | | printf("ERROR reading from socket\n"); |
317 | | close(socketfd); |
318 | | return; |
319 | | } |
320 | | if (n == 0) { |
321 | | printf("Client has closed the connection.\n"); |
322 | | return; |
323 | | }*/ |
324 | | |
325 | | // } |
| 325 | printf("ACK received.\n"); |
| 326 | |
| 327 | } |
| 328 | |
| 329 | void UpdateCEConfiguration() { |
| 330 | |
| 331 | } |
| 332 | |
| 333 | void ResetCEConfiguration(){ |
| 334 | |
| 335 | } |
| 336 | |
| 337 | void LoadCEExperience(){ |
| 338 | |
| 339 | } |
| 340 | |
| 341 | void UpdateCEExperience() { |
| 342 | |
| 343 | } |
| 344 | |
| 345 | void ResetCEExperience() { |
| 346 | |
| 347 | } |
| 348 | |
| 349 | void RequestCEOptimization() { |
| 350 | |
| 351 | } |
| 352 | |
| 353 | void RunSimulator(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) { |
| 354 | |
| 355 | // Set fake past environment |
| 356 | LoadCEExperience(); |
| 357 | |
| 358 | // Set fake current environment |
| 359 | RequestCEOptimization(); |
| 360 | |
| 361 | // Act like we are updating the hardware tranmission settings |
| 362 | UpdateRadioSettings(); |
| 363 | |
| 364 | // Send back fake utility values |
| 365 | UpdateCEExperience(); |
| 366 | } |
| 367 | |
| 368 | void StartMessaging(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) { |
| 369 | |
| 370 | LoadCEConfiguration(socketfd,uList, pList, oList, ce_info); |
| 371 | |
| 372 | RunSimulator(socketfd,uList, pList, oList, ce_info); |