handle_frames.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/core/routing/basic/handle_frames.c
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 #include "wmp_config.h"
00038 #include "core/include/frames.h"
00039 #include "core/include/wmp_com.h"
00040 #include "core/interface/wmp_interface.h"
00041 
00042 //#define WORST_LQM
00043 
00044 int timer_initied=0;
00045 
00046 void decode_routing_info(wmpFrame *p){
00047         //wmp_print_lqm(lqm_get_ptr(),"before decode",wmpGetNumOfNodes());
00048         /*if is a TOKEN update local LQM and unset new_token*/
00049         int i,j;
00050         char *cp;
00051         if (p->hdr.type == TOKEN){
00052                 cp= wmp_get_frame_routing_pointer(p);
00053                 for (i=0;i<status.N_NODES;i++){
00054                         for (j=0;j<status.N_NODES;j++){
00055                                 if (i!=j) {
00056                                         if (j == wmpGetNodeId() && i == p->hdr.from && (*cp) == 0){
00057                                                 /* is for me */
00058                                                 lqm_set_val(i,j,12);//rssi_get_averaged_rssi(i);
00059                                         }else{
00060                                                 /* not try value */
00061                                                 lqm_set_val(i,j,*cp);
00062                                         }
00063                                 }else {
00064                                         nstat_set_byte(i,*cp);
00065                                 }
00066                                 cp++;
00067                         }
00068                 }
00069         }
00070         //wmp_print_lqm(lqm_get_ptr(),"after1",wmpGetNumOfNodes());
00071 
00072         /*  Actualize LocalLQM */
00073         for (i=0;i<status.N_NODES;i++){
00074                 if (i==status.id) continue;
00075                 lqm_set_val(status.id,i,rssi_get_averaged_rssi(i));
00076         }
00077         //wmp_print_lqm(lqm_get_ptr(),"after2",wmpGetNumOfNodes());
00078 #ifdef WORST_LQM
00079         for (j = 0; j < status.N_NODES; j++) {
00080                 if (lqm_get_val(status.id, j) > lqm_get_val(j, status.id) && lqm_get_val(j,status.id) > 0 ) {
00081                         lqm_set_val(status.id, j, lqm_get_val(j, status.id));
00082                 }
00083         }
00084 #endif
00085 
00086         lqm_calculate_distances();
00087         //wmp_print_lqm(lqm_get_ptr(),"after3",wmpGetNumOfNodes());
00088 }
00089 
00090 void encode_routing_info(wmpFrame * t){
00091         int i,j;
00092         /* Create frame, setting reached and lqm */
00093 
00094 #ifdef WORST_LQM
00095         for (i=0;i<status.N_NODES;i++){
00096                 if (i==status.id) continue;
00097                 lqm_set_val(status.id,i,rssi_get_averaged_rssi(i));
00098         }
00099 #endif
00100 
00101         char *cp=wmp_get_frame_routing_pointer(t);
00102         for (i=0;i<status.N_NODES;i++){
00103                 for (j=0;j<status.N_NODES;j++){
00104                         if (i!=j) {
00105                                 (*cp) = lqm_get_val(i,j);
00106                         }else {
00107                                 (*cp) = nstat_get_byte(i);
00108                         }
00109                         cp++;
00110                 }
00111         }
00112 }
00113 
00114 
00115 
00116 


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