⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node_init.m

📁 用于网络控制系统仿真
💻 M
字号:
function node_init(args)% Wireless Ad-hoc Routing Using AODV.%% This example shows an implementation of Ad-hoc On-Demand Distance% Vector (AODV) routing in TrueTime. A scenario involving seven % nodes is used, all initialized by this initialization script.%% Node 1 sends data periodically to node 7 with period 0.5.% The initial route that is established is 1 -> 3 -> 5 -> 7.% At time t=3, node 5 breaks the route by moving away. The route % is repaired by node 6, creating the route 1 -> 2 -> 5 -> 6 -> 7.nodeID = args;% Initialize TrueTime kernelttInitKernel(2, 2, 'prioFP'); % nbrOfInputs, nbrOfOutputs, fixed priorityttCreateMailbox('AODVSendBox', 20); % Data messages to AODV layerttCreateMailbox('AODVRcvBox', 20);  % Data messages from AODV layer% AODV task to send application messages% initiates route discovery if necessarydataAODVsnd.nodeID = nodeID;dataAODVsnd.RREQID = 0;   dataAODVsnd.buffer = {};  % message bufferdataAODVsnd.buflen = zeros(1,7); dataAODVsnd.emptyBuffer = 0;dataAODVsnd.bufInd = 0;prio = 5;ttCreateTask('AODVSendTask', 1, prio, 'AODVsendcode', dataAODVsnd);% Task to process incoming messages% higher prio than AODVSend to allow faster routes to be% obtained while sending buffered datadataAODVrcv.nodeID = nodeID;dataAODVrcv.cache = {};    % cache for processed RREQsdataAODVrcv.cnt = 0;dataAODVrcv.RERRlist = {}; % list of RERRs to propagateprio = 1;ttCreateTask('AODVRcvTask', 1, prio, 'AODVrcvcode', dataAODVrcv);% Periodic task to send HELLO messages and% discover/handle lost connectionsdatahello.nodeID = nodeID;datahello.lastRREQ = -100;datahello.nbors = {};datahello.cnt = 0;datahello.RERRlist = {}; % list of RERRs to sendoffset = 0.1*rand(1); % to avoid collisions between HELLO msgsprio = 3;HELLO_INTERVAL = 1;ttCreatePeriodicTask('HelloTask', offset, HELLO_INTERVAL, prio, 'hellocode', datahello);% Timer handlerttCreateInterruptHandler('timer_handler', 2, 'timercode');% Task to handle expiry of routing table entriesdata_exp.nodeID = nodeID;data_exp.expTimer = 0; % flag to indicate timer setprio = 4;ttCreateTask('TimerTask', 1, prio, 'expcode', data_exp);% Application tasks% -----------------% Node 1 periodically sends data to Node 7% Jobs of RcvTask in node 7 created from AODV layer% Node 5 starts moving at time 3  to break the route% Node 6 starts moving at time 10 to re-establish the routeprio = 10;period = 0.5;if (nodeID==1)  datasend.nodeID = nodeID;  ttCreatePeriodicTask('SendTask', 0, period, prio, 'APPLsendcode', datasend);endif (nodeID==5)  ttCreatePeriodicTask('MoveTask', 0, period, prio, 'APPLmovecode5');endif (nodeID==6)  ttCreatePeriodicTask('MoveTask', 0, period, prio, 'APPLmovecode6');endif (nodeID==7)  datarcv.nodeID = nodeID;  ttCreateTask('RcvTask', 1, 10, 'APPLrcvcode', datarcv);end  % Initialize networkdata_nwhdl.nodeID = nodeID;ttCreateInterruptHandler('nw_handler', 2, 'nwrcvcode', data_nwhdl);ttInitNetwork(nodeID, 'nw_handler'); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -