main.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./example/common/empty/main.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 <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <malloc.h>
00041 #include <math.h>
00042 #include <fcntl.h>
00043 
00044 void *fthread_tx (void * param){
00045         int dest, len, i=0, port = 0;
00046         signed char priority;
00047         char buff[1500];
00048         
00049         sleep(3);
00050 
00051         fprintf(stderr,"Initializing TX thread...\n");
00052         int idx = 0;
00053         while (1){
00054                 dest = 1 << (wmpGetNumOfNodes()-1); //Last node of the present
00055                 len = 300;
00056                 priority = 1;//rand()%5; 
00057                 sprintf(buff,"MESSAGE n.%d from node %d dest %d",i++, wmpGetNodeId(),dest);
00058                 wmpPushData(port,buff,len,dest,priority);
00059                 usleep(150000);
00060                 idx++;
00061         }
00062 }
00063 
00064 void *fthread_rx (void * param){
00065         char *p;
00066         char priority;
00067         unsigned int size, port = 0;
00068         unsigned char src;
00069         sleep(3);
00070 
00071         fprintf(stderr,"Initializing RX thread...\n");
00072 
00073         while (1){
00074 
00075                 int res = wmpPopDataTimeout(port,&p,&size,&src,&priority,1000);
00076                 if(res>=0){
00077                         fprintf(stderr,"Received message-> size: %d src:%d prio:%d text:%s \n",size,src, priority,p);
00078                 }
00079                 wmpPopDataDone(res);
00080         }
00081 
00082 }
00083 
00084 int main(int argc, char* argv[]){
00085         if (argc < 3) {
00086                 fprintf(stderr,"Use: %s id num_of_nodes\n",argv[0]);
00087                 return 0;
00088         }
00089         wmpSetup(atoi(argv[1]), atoi(argv[2]));
00090         
00091         pthread_t th1, th2;
00092         if (wmpGetNodeId()==1)  {
00093                 pthread_create(&th1,0,fthread_tx,0);
00094         }       
00095         pthread_create(&th2,0,fthread_rx,0);
00096 //      wmpForceTopology("chain",0);
00097         wmpRun();
00098         return 0;
00099 }


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