registerEventCallback
Description
registerEventCallback(
registers the function callback, wlanNodeObj,eventName,callback)callback, for the specified event
eventName from the WLAN node wlanNodeObj.
Examples
Set the seed for the random number generator to ensure repeatability of results. The seed value controls the pattern of random number generation. For high-fidelity simulation results, change the seed value and average the results over multiple simulations.
rng(1,"combRecursive")Create a wireless network simulator object. Specify the simulation time in seconds.
networkSimulator = wirelessNetworkSimulator.init; simulationTime = 0.5;
Create and configure a WLAN access point (AP).
apConfig = wlanDeviceConfig(Mode="AP",DisableRTS=true); accessPoint = wlanNode(Name="AP",DeviceConfig=apConfig);
Create and configure a WLAN station (STA).
staConfig = wlanDeviceConfig(Mode="STA"); station = wlanNode(Name="STA",DeviceConfig=staConfig);
Associate the STA with the AP.
associateStations(accessPoint,station)
Create an On-Off application traffic pattern generator object, specifying the On and Off state durations in seconds and the packet generation rate in Kbps. Add it as the application traffic source from the AP to the STA.
trafficSource = networkTrafficOnOff(OnTime=inf,OffTime=0,DataRate=1); addTrafficSource(accessPoint,trafficSource,DestinationNode=station)
Add the AP and STA to the wireless network simulator.
nodes = [accessPoint station]; addNodes(networkSimulator,nodes)
Register callbacks for the TransmissionStarted, ReceptionEnded, AppPacketGenerated, and AppPacketReceived events from the AP and the STA.
registerEventCallback(nodes,["TransmissionStarted","ReceptionEnded","AppPacketGenerated","AppPacketReceived"], ... @(eventStruct) disp(eventStruct))
Run the simulation for the specified time.
run(networkSimulator,simulationTime)
EventName: "AppPacketGenerated"
NodeName: "AP"
NodeID: 1
Timestamp: 0
TechnologyType: 1
EventData: [1×1 struct]
EventName: "TransmissionStarted"
NodeName: "AP"
NodeID: 1
Timestamp: 1.0600e-04
TechnologyType: 1
EventData: [1×1 struct]
EventName: "AppPacketReceived"
NodeName: "STA"
NodeID: 2
Timestamp: 0.0019
TechnologyType: 1
EventData: [1×1 struct]
EventName: "ReceptionEnded"
NodeName: "STA"
NodeID: 2
Timestamp: 0.0019
TechnologyType: 1
EventData: [1×1 struct]
EventName: "TransmissionStarted"
NodeName: "STA"
NodeID: 2
Timestamp: 0.0019
TechnologyType: 1
EventData: [1×1 struct]
EventName: "ReceptionEnded"
NodeName: "AP"
NodeID: 1
Timestamp: 0.0019
TechnologyType: 1
EventData: [1×1 struct]
Retrieve the statistics corresponding to the AP and STA.
statsAP = statistics(accessPoint)
statsAP = struct with fields:
Name: "AP"
ID: 1
App: [1×1 struct]
MAC: [1×1 struct]
PHY: [1×1 struct]
Mesh: [1×1 struct]
statsSTA = statistics(station)
statsSTA = struct with fields:
Name: "STA"
ID: 2
App: [1×1 struct]
MAC: [1×1 struct]
PHY: [1×1 struct]
Mesh: [1×1 struct]
Input Arguments
WLAN node object, specified as a wlanNode object or a vector of
wlanNode objects.
Name of the event, specified as a string scalar, character vector, vector of strings, or cell array of character vectors. Each element of this input argument must be one of these values:
"TransmissionStarted""ReceptionEnded""AppPacketGenerated""AppPacketReceived"
For more information about these events, see Events and Corresponding Event Notification Data Substructure.
Data Types: string | char | cell
Callback function to run when the WLAN node notifies the occurrence of the event, specified as a scalar function handle. The callback function must use this syntax.
@(eventStruct) callback(eventStruct)
eventStruct with the notification
data as a mandatory argument to the callback function. The structure contains these
fields.
| Field | Value | Description |
|---|---|---|
| String scalar | Name of the event. |
| String scalar | Name of the node. |
| Double scalar | Node identifier. |
| Double scalar | Time at which the event is notified, in seconds. |
| Double scalar Valid values are:
| Type of technology. |
| Structure | Event notification data. For more information about this structure, see Events and Corresponding Event Notification Data Substructure. |
Note
Register a callback function for an event from wlanNode only once. If you
register the same callback function multiple times for the same event, the callback
function executes repeatedly each time the node notifies the event.
More About
The object function defines these events.
TransmissionStartedThe medium access control (MAC) layer triggers this event, notifying the node of the start of packet transmission at the physical layer (PHY). In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU |
| List of MAC protocol data units (MPDUs) in current transmission. |
Length |
| Number of octets sent from the MAC to the PHY. |
Duration | Double scalar | Over the air transmission time in seconds, including PHY overhead. |
TransmitPower | Double scalar | Power of the current transmission, in dBm. This value does not include transmit gain and radio frequency (RF) impairments. |
TransmitCenterFrequency | Double scalar | Center frequency of the current transmission, in Hz. |
TransmitBandwidth | Double scalar | Bandwidth of the current transmission, in Hz. |
CenterFrequency | Double scalar | Frequency of operation of the PHY, in Hz. |
Bandwidth | Double scalar | Bandwidth of operation of the PHY, in Hz. |
ReceptionEndedThe MAC layer triggers this event, notifying the node of the end of packet reception at the PHY. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU |
This field is applicable only when the value of the
| List of MPDUs in current reception. |
Length |
This field is applicable only when the value of the
| Number of octets sent from the PHY to the MAC. |
Duration | Double scalar | Duration of the current reception, in seconds. |
ReceiveCenterFrequency | Double scalar | Center frequency of the current reception, in Hz. |
ReceiveBandwidth | Double scalar | Bandwidth of the current reception, in Hz. |
CenterFrequency | Double scalar | Frequency of operation of the PHY, in Hz. |
Bandwidth | Double scalar | Bandwidth of operation of the PHY, in Hz |
PHYDecodeStatus | Nonnegative integer, where | Decoding status of the current reception at the PHY. |
PDUDecodeStatus |
These are the valid values of this field.
This field is applicable only when the value of
the | Decoding status of the MPDUs in the current reception. |
IsIntendedReception | Logical scalar The default value is
If the value of the
| This flag indicates whether the node notifying the end of the
reception event is the intended recipient. The value is set to
|
AppPacketGeneratedThe application layer (APP) triggers this event, notifying the node of the packet generation. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
Packet | Column vector of decimal octets | Application packet in bytes. If you enable MAC frame
abstraction, the value of this field is an empty array
|
PacketLength | Double scalar | Number of bytes in the application packet. |
DestinationNodeID | Double scalar | Identifier of the destination node. In the case of a
broadcast packet, the value is an empty array
|
AccessCategory | Integer in the range [0, 3], where
| Access category of the application packet |
Note
If you generate packets using full-buffer traffic, the node does not notify the occurrence of this event.
AppPacketReceivedThe APP triggers this event, notifying the node of the packet reception. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
Packet | Column vector of decimal octets | Application packet in bytes. If you enable MAC frame
abstraction, the value of this field is an empty array
|
PacketLength | Double scalar | Number of bytes in the application packet. |
SourceNodeID | Double scalar | Identifier of the source node. |
AccessCategory | Integer in the range [0, 3], where
| Access category of the application packet. |
Note
The node does not notify the occurrence of this event when it receives packets generated using full-buffer traffic.
Version History
Introduced in R2026a
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)