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 
00041 //#define WORST_LQM
00042 
00043 int timer_initied=0;
00044 
00045 extern void print_matrix(char* txt, char **lqm);
00046 extern void print_vector(char*txt, char *t);
00047 extern void tree_get_next_tree(char * cp);
00048 extern void tree_create_lqm_from_tree(char ** lqm, char * tree);
00049 extern void tree_create_tree_from_lqm(char * tree, char ** lqm);
00050 extern int tree_which_best(char * t1, char * t2);
00051 
00052 void decode_routing_info_pap(wmpFrame *p){
00053         int i, all_reached;
00054    char * cp;
00055         p->tkn.new_token=0;
00056 
00057         cp = wmp_get_frame_routing_pointer_status(p);
00058         for (i=0;i<status.N_NODES;i++){
00059                 nstat_set_byte(i,cp[i]);
00060         }
00061 
00062         all_reached = 1;
00063         for (i = 0; i < status.N_NODES; i++) {
00064                 if (i != status.id){
00065                         all_reached = all_reached && nstat_isReached(i);
00066                 }
00067         }
00068 
00069         if (all_reached){
00070                 cp = wmp_get_frame_routing_pointer_new_tree(p);
00071                 tree_get_next_tree(cp);
00072                 tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00073         } else{
00074                 cp = wmp_get_frame_routing_pointer(p);
00075                 tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00076         }
00077 
00078         lqm_calculate_distances();
00079 }
00080 
00081 
00082 
00083 void encode_routing_info_pap(wmpFrame * p) {
00084         int i;
00085    char * cp_s;
00086    char * cp;
00087    char * cp_nt;
00088         //fprintf(stderr, "encode_pap\n");
00089 
00090         /* Create frame, setting reached and lqm */
00091         cp = wmp_get_frame_routing_pointer(p);
00092 
00093 
00094         print_matrix("before", lqm_get_ptr());
00095         tree_create_tree_from_lqm(cp, lqm_get_ptr());
00096         print_matrix("after", lqm_get_ptr());
00097         print_vector("done",cp);
00098         cp_s = wmp_get_frame_routing_pointer_status(p);
00099         for (i = 0; i < status.N_NODES; i++) {
00100                 cp_s[i] = nstat_get_byte(i);
00101         }
00102 
00103         cp_nt = wmp_get_frame_routing_pointer_new_tree(p);
00104 
00105         //fprintf(stderr, "Last RECVD: %d \n", status.lastRecvdType);
00106         if (p->tkn.new_token && status.lastRecvdType != TOKEN) {
00107                 //fprintf(stderr,"&&&&&&& a que hago esto %d\n",p->hdr.serial);
00108 
00109                 memcpy(cp_nt,cp,status.N_NODES);
00110         }
00111 
00112         tree_get_next_tree(cp_nt);
00113 
00114         if (p->tkn.new_token) {
00115                 //fprintf(stderr,"&&&&&&& o esto %d\n",p->hdr.serial);
00116                 if (tree_which_best(cp,cp_nt)==2){
00117                         memcpy(cp, cp_nt, status.N_NODES);
00118                 }
00119         }
00120         print_vector("done2",cp);
00121 }
00122 
00123 void encode_routing_info_atp_mtp(wmpFrame * p){
00124         //fprintf(stderr,"*********** encode_atp type:%d serial:%d\n",p->hdr.type,p->hdr.serial);
00125         char * cp = wmp_get_frame_routing_pointer(p);
00126         tree_create_tree_from_lqm(cp,lqm_get_ptr());
00127 }
00128 
00129 void decode_routing_info_atp_mtp(wmpFrame * p){
00130         //fprintf(stderr,"decode atp type: %d serial:%d \n",p->hdr.type,p->hdr.serial);
00131         char * cp = wmp_get_frame_routing_pointer(p);
00132         tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00133 }
00134 
00135 void decode_routing_info(wmpFrame * p){
00136         //fprintf(stderr,"Type: %d, serial:%d \n",p->hdr.type,p->hdr.serial);
00137         if (p->hdr.type == TOKEN){
00138                 decode_routing_info_pap(p);
00139         } else if (p->hdr.type != DROP_TOKEN){
00140                 decode_routing_info_atp_mtp(p);
00141         }
00142 }
00143 
00144 void encode_routing_info(wmpFrame * p){
00145         //fprintf(stderr,"encode type: %d\n",p->hdr.type);
00146         if (p->hdr.type == TOKEN){
00147                 encode_routing_info_pap(p);
00148         } else if (p->hdr.type != DROP_TOKEN){
00149                 encode_routing_info_atp_mtp(p);
00150         }
00151 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10