scheduleAction
Download Required: To use scheduleAction
,
first download the Communications Toolbox Wireless Network Simulation Library add-on.
Syntax
Description
scheduleAction(
schedules an action to perform during the wireless network simulation. The
networkSimulator
,callbackFcn
,userData
,startTime
)callbackFcn
argument specifies the action to be performed at the
specified time, startTime
, and userData
specifies
the input data to use for the specified action.
scheduleAction(___,
specifies to repeat the action at regular or irregular time intervals, in addition to all
input arguments from the previous syntax.periodicity
)
returns an identifier specifying the action scheduled.actionID
= scheduleAction(___)
Examples
Schedule Action to Perform During Network Simulation
Simulate Bluetooth BR Network
Create a wirelessNetworkSimulator
object by using the wirelessNetworkSimulator.init()
function. By default, the wirelessNetworkSimulator
object applies free-space path loss model for the channel effects.
networkSimulator = wirelessNetworkSimulator.init();
Create two Bluetooth BR nodes, one with the "central"
role and other with the "peripheral"
role. Specify the position of the Peripheral node in meters.
centralNode = bluetoothNode("central"); peripheralNode = bluetoothNode("peripheral",Position=[1 0 0]);
Create a default Bluetooth BR connection configuration object to configure and share a connection between Bluetooth BR Central and Peripheral nodes.
cfgConnection = bluetoothConnectionConfig;
Configure connection between the Central and the Peripheral nodes.
connection = configureConnection( ...
cfgConnection,centralNode,peripheralNode);
Create and configure a networkTrafficOnOff
object to generate an On-Off application traffic pattern.
traffic = networkTrafficOnOff( ... DataRate=200, ... PacketSize=27, ... GeneratePacket=true, ... OnTime=inf);
Add application traffic from the Central to the Peripheral node.
addTrafficSource(centralNode,traffic, ...
DestinationNode=peripheralNode);
Add the Central and Peripheral nodes to the wireless network simulator.
addNodes(networkSimulator,[centralNode peripheralNode]);
Schedule Action
Create a custom function displayInfo
to define the actions for the simulator to perform during simulation. You can define an one time action, periodic action, and action when simulator advances in time. The input data for the custom function is stored as a structure and passed using the scheduleAction
function.
A) Schedule One Time Action
For the one time action, the displayInfo
function displays the details of the nodes in the network.
Specify the ActionType
input argument value of displayInfo
function as "OneTime"
. Specify the names of the nodes in the network as input to displayInfo
function.
userdata = struct( ... ActionType="OneTime", ... Nodes=[centralNode peripheralNode]);
Configure the simulator by using the scheduleAction
function to display the node details when the simulation time is 0.001s.
startTime = 0.001; scheduleAction(networkSimulator,@displayInfo,userdata,startTime);
B) Schedule Periodic Action
For the periodic action, the displayInfo
function displays the physical layer statistics of the central node in the Bluetooth BR network.
Specify the ActionType
input argument value of displayInfo
function as "Periodic"
. Specify the central node and the simulator as inputs to displayInfo
function.
userdata = struct( ... ActionType="Periodic", ... CentralNode=centralNode, ... Simulator=networkSimulator);
Configure the simulator by using the scheduleAction
function to display the physical layer statistics of the central node at a time interval of 0.002s starting from the beginning of the simulation.
startTime = 0;
periodicity = 0.002;
scheduleAction( ...
networkSimulator,@displayInfo,userdata,startTime,periodicity);
C) Schedule Action When Simulator Advances in Time
When the simulator advances in time, the displayInfo
function displays the next event time of the simulator.
Specify the ActionType
input argument value of displayInfo
function as "TimeAdvance"
. Specify the simulator as input to the displayInfo
function.
userdata = struct( ... ActionType="TimeAdvance", ... Simulator=networkSimulator);
Set the periodicity value to 0. Configure the simulator by using the scheduleAction
function to display the time of the next event.
startTime = 0;
periodicity = 0;
scheduleAction( ...
networkSimulator,@displayInfo,userdata,startTime,periodicity);
Run Simulation
Specify the simulation time in seconds.
simulationTime = 0.003;
Run the simulation for the specified simulation time.
run(networkSimulator,simulationTime);
-------Periodic Action ------- Statistics of Node1 at time 0.000 seconds: ReceivedPackets: 0 DecodeFailures: 0 PacketCollisions: 0 CoChannelCollisions: 0 CollisionsWithBREDR: 0 CollisionsWithNonBREDR: 0 CollisionsWithBREDRAndNonBREDR: 0 TransmittedPackets: 1 TransmittedBits: 366 -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00037 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00063 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00075 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00100 seconds -------End------- -------One Time Action ------- Node details: Name: Node1 ID: 1 Role: central Name: Node2 ID: 2 Role: peripheral -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00108 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00125 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00162 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00187 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00200 seconds -------End------- -------Periodic Action ------- Statistics of Node1 at time 0.002 seconds: ReceivedPackets: 2 DecodeFailures: 0 PacketCollisions: 0 CoChannelCollisions: 0 CollisionsWithBREDR: 0 CollisionsWithNonBREDR: 0 CollisionsWithBREDRAndNonBREDR: 0 TransmittedPackets: 2 TransmittedBits: 732 -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00200 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00216 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00250 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00287 seconds -------End-------
function displayInfo(~,userdata) switch(userdata.ActionType) case "Periodic" fprintf("-------Periodic Action -------\n") fprintf("Statistics of %s at time %.3f seconds:\n", ... userdata.CentralNode.Name, ... userdata.Simulator.CurrentTime); stats = statistics(userdata.CentralNode); disp(stats.PHY) fprintf("-------End-------\n") case "OneTime" fprintf("-------One Time Action -------\n") fprintf("Node details:\n") for idx=1:numel(userdata.Nodes) fprintf("Name: %s ID: %d Role: %s\n", ... userdata.Nodes(idx).Name, ... userdata.Nodes(idx).ID, ... userdata.Nodes(idx).Role) end fprintf("-------End-------\n") case "TimeAdvance" fprintf("-------Action When Simulator Advances in Time-------\n") fprintf("Simulator next event time is at %.5f seconds\n", ... userdata.Simulator.CurrentTime) fprintf("-------End-------\n") end end
Input Arguments
networkSimulator
— Wireless network simulator
wirelessNetworkSimulator
object
Wireless network simulator, specified as a wirelessNetworkSimulator
object.
callbackFcn
— Callback function to run at specified time
function handle
Callback function to run at the specified time, specified as a function handle. The callback function is a custom function defining an action to be performed during the wireless network simulation. The syntax for the callback function must be:
callbackFcn(actionID,userData)
userData
— Input to callback function
[ ]
| structure | cell array | numeric value | character vector | string scalar
Input to the callback function, specified as a numeric value, character vector, or
string scalar. If the callback function does not require any input, specify the
userData
value as [ ]
. To pass multiple values
as input to the callback function, specify the input as a structure or a cell
array.
startTime
— Absolute simulation time to perform the action
nonnegative scalar
Absolute simulation time at which a scheduled action is to be performed, specified as a nonnegative scalar. Units are in seconds.
If you specify the simulation time as zero, the simulator performs the scheduled action at the start of simulation.
If you specify both
startTime
andperiodicity
, the simulator performs the scheduled action at the specified simulation time and repeats the action until the end of simulation. The time interval for repeating the action is specified by the periodic time inperiodicity
.
periodicity
— Periodic time
nonnegative scalar
Periodic time, specified as a nonnegative scalar. The periodic time is the time interval at which the scheduled action repeats. Units are in seconds.
For periodic actions, the periodicity value must be greater than zero.
If the periodic time value is 0, the scheduled action is performed whenever the simulator advances in time in response to an event. The events can occur at regular or irregular time intervals. In this case, the simulator ignores the value of
startTime
.
Output Arguments
actionID
— Unique identifier for action
integer
Unique identifier for action, returned as an integer. You can also use this value to
cancel a scheduled action by using the cancelAction
function.
Version History
Introduced in R2022bR2023a: Moved to Communications Toolbox Wireless Network Simulation Library from Bluetooth Toolbox
Previously, this wirelessNetworkSimulator
object function required Bluetooth® Toolbox.
See Also
Objects
Functions
Topics
- Create, Configure, and Simulate Bluetooth BR/EDR Piconet (Bluetooth Toolbox)
- Bluetooth BR/EDR Data and Voice Communication with WLAN Signal Interference (Bluetooth Toolbox)
- Simulate Multiple Bluetooth BR/EDR Piconets with ACL Traffic (Bluetooth Toolbox)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)