Main Content

registerEventCallback

Register callback for event from WLAN node

Since R2026a

    Description

    registerEventCallback(wlanNodeObj,eventName,callback) registers the function callback, callback, for the specified event eventName from the WLAN node wlanNodeObj.

    example

    Examples

    collapse all

    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

    collapse all

    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)
    The WLAN node passes the event structure eventStruct with the notification data as a mandatory argument to the callback function. The structure contains these fields.

    Field ValueDescription

    EventName

    String scalar

    Name of the event.

    NodeName

    String scalar

    Name of the node.

    NodeID

    Double scalar

    Node identifier.

    Timestamp

    Double scalar

    Time at which the event is notified, in seconds.

    TechnologyType

    Double scalar

    Valid values are:

    • 0 — Invalid

    • 1 — WLAN

    • 2 — 5G

    • 3 — Bluetooth LE

    • 4 — Bluetooth basic rate/enhanced data rate ( BR/EDR)

    Type of technology.

    EventData

    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

    collapse all

    Version History

    Introduced in R2026a

    See Also

    Objects