enhanced_io.cc
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           WMPSNIFFER          --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: enhanced_io.cc
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2012, 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 static char buff[2500];
00037 #include "enhanced_io.h"
00038 #include "core/interface/Msg.h"
00039 #include <cstring>
00040 
00041 int read_next_token(char * msg, char* bc_msg, int *serial, int * pos, const char * txt) {
00042     int res = io_read_next_sim_data(buff);
00043     if (res > 0) {
00044         wmpFrame * r = (wmpFrame *) (buff + sizeof (simData_Hdr));
00045         if (r->hdr.type == TOKEN) {
00046 #ifdef  ENABLE_BC_SUPPORT
00047                 if (r->hdr.bc_len > 0) {
00048                 if (r->hdr.bc_type == BC_TYPE_PLUS) {
00049                     Simple_bc * sbc = (Simple_bc*) wmp_get_frame_tail_pointer(r, io_get_num_of_nodes());
00050                     if (strstr(&sbc->data, txt) || strcmp(txt,"")==0) {
00051                         *serial = r->hdr.serial;
00052                         *pos = io_get_filepos() - 1;
00053                         memcpy(bc_msg, &sbc->data, sbc->len);
00054                         return 1;
00055                     }
00056                 }
00057             }else
00058 #endif
00059             {
00060                 *serial = r->hdr.serial;
00061                 *pos = io_get_filepos() - 1;
00062                 sprintf(bc_msg,"%s","");
00063             }
00064             return 1;
00065         } else return 0;
00066     }
00067     return -1;
00068 }
00069 
00070 
00071 
00072 
00073 #include <sstream>
00074 int read_next_message2(char * tmp, char * bc_msg, int *serial, int * pos, const char * txt) {
00075     int res = io_read_next_sim_data(buff);
00076     if (res > 0) {
00077         int ret = 0;
00078         return ret;
00079     }
00080     return -1;
00081 }
00082 
00083 #include <cstdlib>
00084 int read_next_message(char * tmp, char * bc_msg, int *serial, int * pos,
00085         const char * txt) {
00086     int res = io_read_next_sim_data(buff);
00087     if (res > 0) {
00088         int ret = 0;
00089         wmpFrame * r = (wmpFrame *) (buff + sizeof (simData_Hdr));
00090         if (r->hdr.type == MESSAGE) {
00091             if (atoi(txt) == r->msg.msg_hash || strstr(wmp_get_message_data_pointer(r), txt) || strcmp(txt,"")==0 ) {
00092                 *serial = r->hdr.serial;
00093                 *pos = io_get_filepos() - 1;
00094                 memcpy(tmp, wmp_get_message_data_pointer(r), r->msg.len);
00095                 sprintf(bc_msg,"%s","");
00096                 ret = 1;
00097             }
00098 #ifdef  ENABLE_BC_SUPPORT
00099             if (r->hdr.bc_len > 0) {
00100                 if (r->hdr.bc_type == BC_TYPE_PLUS) {
00101                     Simple_bc * sbc = (Simple_bc*) wmp_get_frame_tail_pointer(r, io_get_num_of_nodes());
00102                     if (strstr(&sbc->data, txt)) {
00103                         *serial = r->hdr.serial;
00104                         *pos = io_get_filepos() - 1;
00105                         memcpy(bc_msg, &sbc->data, sbc->len);
00106                         ret = 1;
00107                     }
00108                 }
00109             }
00110 #endif
00111         }
00112         return ret;
00113     }
00114     return -1;
00115 }
00116 
00117 int read_next_bc(char * tmp, char * bc_msg, int *serial, int * pos, const char * txt) {
00118     int res = io_read_next_sim_data(buff);
00119     if (res > 0) {
00120                 tmp[0] = 0;
00121                 bc_msg[0] = 0;
00122                 int ret = 0;
00123                 wmpFrame * r = (wmpFrame *) (buff + sizeof(simData_Hdr));
00124                 *serial = r->hdr.serial;
00125                 *pos =  - 1;
00126                 int must_return=0;
00127                 if (strcmp(txt,"")==0){
00128                         must_return=1;
00129                 }
00130 #ifdef  ENABLE_BC_SUPPORT
00131                 if (r->hdr.bc_len > 0 && r->hdr.type != DROP_TOKEN) {
00132                         if (r->hdr.bc_type == BC_TYPE_PLUS) {
00133                                 Simple_bc * sbc = (Simple_bc*) wmp_get_frame_tail_pointer(r,
00134                                                 io_get_num_of_nodes());
00135                                 if (strstr(&sbc->data, txt) || must_return) {
00136                                         memcpy(bc_msg, &sbc->data, sbc->len);
00137                                         ret++;
00138                                 }
00139                         }
00140                 } else
00141 #endif
00142                 {
00143                         sprintf(bc_msg, "%s","");
00144                 }
00145         if (r->hdr.type == MESSAGE){
00146                 if (strstr(wmp_get_message_data_pointer(r), txt) || must_return) {
00147                         memcpy(tmp, wmp_get_message_data_pointer(r), r->msg.len);
00148                         ret++;
00149                 }
00150         }else{
00151                 sprintf(tmp,"%s","");
00152         }
00153         if (must_return || ret>0 ) return 1;
00154         else return 0;
00155     }
00156     return -1;
00157 }
00158 
00159 int read_next_drop(char * tmp, char * bc_msg, int *serial, int * pos, const char * txt) {
00160     int res = io_read_next_sim_data(buff);
00161     if (res > 0) {
00162         wmpFrame * r = (wmpFrame *) (buff + sizeof (simData_Hdr));
00163         if (r->hdr.type == DROP_TOKEN) {
00164             *serial = r->hdr.serial;
00165             *pos = io_get_filepos() - 1;
00166             return 1;
00167         } else return 0;
00168     }
00169     return -1;
00170 
00171 }
00172 
00173 int read_next_authorization(char * tmp, char * bc_msg, int *serial, int * pos, const char * txt) {
00174     int res = io_read_next_sim_data(buff);
00175     if (res > 0) {
00176         wmpFrame * r = (wmpFrame *) (buff + sizeof (simData_Hdr));
00177         if (r->hdr.type == AUTHORIZATION) {
00178 #ifdef  ENABLE_BC_SUPPORT
00179             if (r->hdr.bc_len > 0) {
00180                 if (r->hdr.bc_type == BC_TYPE_PLUS) {
00181                     Simple_bc * sbc = (Simple_bc*) wmp_get_frame_tail_pointer(r, io_get_num_of_nodes());
00182                     if (strstr(&sbc->data, txt) || strcmp(txt,"")==0) {
00183                         *serial = r->hdr.serial;
00184                         *pos = io_get_filepos() - 1;
00185                         memcpy(bc_msg, &sbc->data, sbc->len);
00186                         return 1;
00187                     }
00188                 }
00189 
00190             }else
00191 #endif
00192             {
00193 
00194                 *serial = r->hdr.serial;
00195                 *pos = io_get_filepos() - 1;
00196                 sprintf(bc_msg,"%s","");
00197             }
00198             return 1;
00199         } else return 0;
00200     }
00201     return -1;
00202 }
00203 
00204 
00205 
00206 static FILE * outf[32];
00207 static int nnodes;
00208 
00209 void logger_init(int type, int nnodes_){
00210         nnodes = nnodes_;
00211         for (int i=0; i< nnodes ; i++){
00212                 outf[i] = 0;
00213         }
00214         if (type == 0){
00215                 for (int i=0; i< nnodes ; i++){
00216                         outf[i] = stderr;
00217                 }
00218         }else{
00219                 for (int i=0; i< nnodes ; i++){
00220                         char filename[256];
00221                         sprintf(filename,"rt-wmp-node-%d.log",i);
00222                         outf[i] = fopen(filename,"w+");
00223                 }
00224         }
00225 }
00226 
00227 void logger_printData(int node_id, wmpFrame *q, unsigned long long ts) {
00228         int i, j;
00229         double evtime;
00230 
00231         evtime = (double)ts/1e6;
00232 
00233         fprintf(outf[node_id], "%5.5f\t%d\t%d\t%d\t%d\t%d\t%d",evtime,(int) q->hdr.serial, q->hdr.rssi,
00234                         q->hdr.retries, q->hdr.from, q->hdr.to, q->hdr.type);
00235 
00236         char * lqm = wmp_get_frame_routing_pointer(q,nnodes);
00237         for (i = 0; i < nnodes; i++) {
00238                 for (j = 0; j < nnodes; j++) {
00239                         if (i != j) {
00240                                 fprintf(outf[node_id], "\t%d",  *lqm);
00241                         } else {
00242                                 fprintf(outf[node_id], "\t%d", 0);
00243                         }
00244                         lqm ++;
00245                 }
00246         }
00247 #ifdef ENABLE_WMP_DEBUG
00248         for (i = 0; i < 32; i++) {
00249                 fprintf(outf[node_id], "\t%d", q->hdr.path[i]);
00250         }
00251         fprintf(outf[node_id], "\n");
00252 #endif
00253 }
00254 
00255 void logger_close(){
00256         for (int i=0; i< nnodes ; i++){
00257                 fclose(outf[i]);
00258         }
00259 }


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