aura.c
Go to the documentation of this file.
00001 /*
00002  * aura.c
00003  *
00004  *  Created on: Sep 22, 2010
00005  *      Author: danilo
00006  */
00007 
00008 #include "config/compiler.h"
00009 #include "core/include/aura.h"
00010 #include "core/include/frames.h"
00011 #include "core/include/global.h"
00012 #include "core/include/dijkstra.h"
00013 #include "core/include/lqm.h"
00014 
00015 static int aura_vec[32];
00016 static char buff[2500];
00017 static int len;
00018 static Message bm;
00019 
00020 void aura_store_msg(Message * m){
00021         char * dp = (char *) m;
00022         dp += sizeof(Message);
00023 
00024         //XXX: WARNING with tree routing, it should be changed the data_pointer
00025         //dp += sizeof(Message) + status.N_NODES;
00026         bm = *m;
00027         len = m->len;
00028         memcpy(buff, dp,len);
00029 }
00030 
00031 void aura_restore_msg(Message * m){
00032         char * dp = (char *) m;
00033         dp += sizeof(Message);
00034 
00035         //XXX: WARNING with tree routing, it should be changed the data_pointer
00036         //dp += sizeof(Message) + status.N_NODES;
00037         m->part_id = bm.part_id;
00038         m->len = bm.len;
00039         m->msg_hash = bm.msg_hash;
00040         m->port = bm.port;
00041         m->priority = bm.priority;
00042         m->age = bm.age;
00043         memcpy(dp, buff, len);
00044         m->len = len;
00045 }
00046 
00047 void aura_add(aura_t val, int id){
00048         aura_vec[id] += val;
00049 }
00050 
00051 void aura_clear(void){
00052         int i;
00053         for (i = 0; i < 32 ; i++){
00054                 aura_vec[i] = 0;
00055         }
00056 }
00057 
00058 int aura_get(int id){
00059         return aura_vec[id];
00060 }
00061 
00062 void aura_discard_unnecessary(int dest){
00063         char path[32], necessary[32];
00064         int i,j;
00065 
00066         memset(necessary,0,sizeof(necessary));
00067         necessary[status.id] = 1;
00068         //fprintf(stderr,"### dest: %d\n",dest);
00069         for (i = 0; i< status.N_NODES ;i++){
00070                 if (mBitsIsSet(dest,i)){
00071                         int len = getPath(lqm_get_ptr(),status.id,i,path);
00072                         //fprintf(stderr,"### path from: %d to %d: ",status.id,i);
00073                         for (j = 0; j < len+1; j++){
00074                                 //fprintf(stderr,"%d ",path[j]);
00075                                 int node = path[j];
00076                                 necessary[node] = 1;
00077                         }
00078                         //fprintf(stderr,"\n");
00079                 }
00080         }
00081         for (i = 0; i< status.N_NODES ;i++){
00082                 if (necessary[i] == 0){
00083                         aura_vec[i] = aura_full;
00084                         //fprintf(stderr,"### discard: %d\n",i);
00085                 }
00086         }
00087 }
00088 
00089 
00090 int aura_get_next(wmpFrame * p, aura_t * type){
00091         char nb[32];
00092         int n_nb = getNeighbors(lqm_get_ptr(),status.id,nb);
00093         int i, best_val = 1000, best_id = -1;
00094         for (i = 0; i< n_nb ;i++){
00095                 int elem = aura_vec[(int)nb[i]];
00096                 if (elem < best_val){
00097                         best_val = elem;
00098                         best_id = nb[i];
00099                 }
00100         }
00101         if (best_val == 0){
00102                 *type = aura_msg;
00103                 return best_id;
00104         } else if (best_val == 1){
00105                 *type = aura_msg;
00106                 return best_id;
00107         } else if (best_val == 2){
00108                 *type = aura_auth;
00109                 return best_id;
00110         }else{
00111                 //WMP_ERROR(stderr,"Value:%d serial:%u\n",best_val,(int) p->hdr.serial);
00112                 return -1;
00113         }
00114 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54