performs the transmission between users (ie : multihop) INPUT par general parameters structure mob structure of mobiles msg structure of messages t time index of the simulation OUTPUT mob mobiles structure msg messages structure $Id: transmit_user.m,v 1.4 2004/07/16 01:58:31 dalai Exp $
0001 % performs the transmission between users (ie : multihop) 0002 % 0003 % INPUT 0004 % par general parameters structure 0005 % mob structure of mobiles 0006 % msg structure of messages 0007 % t time index of the simulation 0008 % 0009 % OUTPUT 0010 % mob mobiles structure 0011 % msg messages structure 0012 % 0013 % 0014 % $Id: transmit_user.m,v 1.4 2004/07/16 01:58:31 dalai Exp $ 0015 0016 function [mob,msg_mcn] = transmit_user(par,mob,msg_mcn,t) 0017 0018 % simplified notations 0019 % usr = reshape(struct2array(rmfield(mob,{'msg_mcn' 'msg_std' 'vstate' 'buffer_mcn' 'buffer_std' 'buffer_self'}))',t+1,2,par.mob); 0020 % usr = reshape(struct2array(getfield(mob,'xy'))',t+1,2,par.mob); 0021 % usr_xy(1:par.mob) = usr(t+1,1,1:par.mob); 0022 usr = reshape([mob(:).xy],t+1,par.mob)'; 0023 usr_xy(1:par.mob) = usr(1:par.mob,t+1); 0024 0025 0026 % compute the distance between mobiles 0027 dist = abs([repmat(usr_xy',1,par.mob) - repmat(usr_xy,par.mob,1)]); 0028 % set the distance of a mobile to itself to +infinity 0029 dist(eye(par.mob)==1)=inf; 0030 0031 % find the mobiles close enough to transmitt 0032 [I,J] = find(dist<par.cov_mob); 0033 0034 % if there are mobiles which are in the transmission range of each other 0035 if length(I)~=0 0036 % for each mobiles 0037 for idx=1:length(I) 0038 % find the messages to be transmitted 0039 msg2trsmit = find(mob(J(idx)).msg_mcn(:)>=0); 0040 % for each messages to be transmitted 0041 for mdx = 1:length(msg2trsmit) 0042 % check it is not already in the original mobile's buffer 0043 if mob(I(idx)).msg_mcn(msg2trsmit(mdx)) == -1 0044 % transmitt the messages by putting the original mobile's message state to +1 (increase of "one hop"). 0045 mob(I(idx)).msg_mcn(msg2trsmit(mdx)) = mob(J(idx)).msg_mcn(msg2trsmit(mdx)) + 1; 0046 end 0047 end 0048 end 0049 end