Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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);
00055 len = 500;
00056 priority = 1;
00057 sprintf(buff,"MESSAGE n.%d from node %d dest %d",i++, wmpGetNodeId(),dest);
00058 wmpPushData(port,buff,len,dest,priority);
00059 usleep(1500000);
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
00097 wmpRun();
00098 return 0;
00099 }