Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2008-06-19
年龄: 38
帖子: 2
声望力: 0 ![]() |
![]()
该代码是有关于泛洪的:ft:
function x=animation_data small=5; medium=20; large=50; anim_def={... {'Init_Application', 0, [0 0 0 ], small}, ... {'Packet_Sent', 1, [0 1 0 ], small}, ... {'Packet_Received', 1, [0 1 0 ], small}, ... {'Collided_Packet_Received', 0, [1 0 0 ], small}, ... {'Clock_Tick', 0, [0 0 0 ], small}, ... {'Channel_Request', 0, [0 0 0 ], small}, ... {'Channel_Idle_Check', 1, [1 0 0 ], small}, ... {'Packet_Receive_Start', 0, [0 1 0 ], small}, ... {'Packet_Receive_End', 0, [0 0 0 ], small}, ... {'Packet_Transmit_Start', 1, [1 0 0 ], medium}, ... {'Packet_Transmit_End', 0, [0 1 0 ], small}}; for i=1:length(anim_def) a=anim_def{i}; x(i)=struct('event', a{1}, 'animated', a{2}, 'color', a{3}, 'size', a{4}); end function application(S) persistent app_data global ID t [t, event, ID, data]=animation_data(); [topology, mote_IDs]=prowler('GetTopologyInfo'); ix=find(mote_IDs==ID); if ~strcmp(event, 'Init_Application') try memory=app_data{ix}; catch memory=[]; end, end switch event case 'Init_Application' signal_strength=1; memory=struct('send',1, 'signal_strength', signal_strength); if ID==1 Set_Clock(1000) end PrintMessage('i') case 'Packet_Sent' PrintMessage('s') case 'Packet_Received' if memory.send p=sim_params('get_app', 'P'); if isempty(p); p=.5; end if rand<p Send_Packet(radiostream(data.data, memory.signal_strength)); end memory.send=0; PrintMessage('r') end case 'Collided_Packet_Received' case 'Clock_Tick' Send_Packet(radiostream('Message for 00111 from Golomb', memory.signal_strength)); case 'GuiInfoRequest' disp(sprintf('Memory Dump of mote ID# %d:\n',ID)); disp(memory) case 'Application_Stopped' case 'Application_Finished' otherwise error(['Bad event name for application: ' event]) end app_data{ix}=memory; function b=Send_Packet(data); global ID t radio=prowler('GetRadioName'); b=feval(radio, 'Send_Packet', ID, data, t); function b=Set_Clock(alarm_time); global ID prowler('InsertEvents2Q', make_event(alarm_time, 'Clock_Tick', ID)); function PrintMessage(msg) global ID prowler('TextMessage', ID, msg) function LED(msg) global ID prowler('LED', ID, msg) function varargout=info title1='Application FLOOD1D'; str1={ 'This application illustrates the simple flooding algorithm.'; ... '';... 'The sender mote transmits a message. Each mote receiving the';... 'message retransmits it with probability p.' ;... 'The value of p can be set in the ''Application Parameters''';... 'window. The default value is p=0.5';... '';... 'If p is too low, the flood dies out before every mote could';... 'receive the message. If p it too high, the message is';... 'retransmitted several times after every mote have received it,' ;... 'thus causing an unnecessarily high settling time.';... '';... 'The optimal value of p highly depends on topology.';... '';... 'You can change the topology by editing the file FLOOD1D_TOPOLOGY.';... '';... 'See also FLOOD2D.';... ''}; if nargout==0 helpwin({ title1, str1}, 'Application Info') else varargout={ title1, str1}; end function param=params; param(1).name='P'; param(1).default=0.5; function [topology,mote_IDs]=topology(varargin); Nx=10; Ny=1; ix=1;t=[]; distx=1; disty=5; X=1:distx ![]() Y=1:disty ![]() for i=X for j=Y t=[t; i,j]; end end topology=t; mote_IDs=1:Nx*Ny; |
![]() |
![]() |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
[原创]曲线拟合 | shiqiang | MATLAB论坛 | 147 | 2019-07-18 10:45 |
[求助]mcc编译问题,新手恳求赐教 | chujun0303 | MATLAB论坛 | 0 | 2008-07-23 11:50 |
求助:adc及采样保持电路的FFT测试SNR与频谱 | fuyibin | MATLAB论坛 | 0 | 2008-05-30 23:00 |
[求助]求助高手!!用MATLAB制作动画 | shingo | MATLAB论坛 | 1 | 2008-05-11 08:33 |
【求助】追击问题,试模拟追击路线 | libety | MATLAB论坛 | 5 | 2008-02-21 21:36 |