主要内容

registerEventCallback

Register callback for event from Bluetooth BR/EDR node

Since R2026a

    Description

    registerEventCallback(bluetoothNodeObj,eventName,callback) registers the function callback callback for the specified event eventName from the Bluetooth® basic rate/enhanced data rate (BR/EDR) node, bluetoothNodeObj.

    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,"twister")

    Create a wireless network simulator object. Specify the simulation time in seconds.

    networkSimulator = wirelessNetworkSimulator.init();
    simulationTime = 0.01;

    Create a Bluetooth BR/EDR Central node and a Peripheral node, specifying their positions in 3-D Cartesian coordinates.

    centralNode = bluetoothNode("central",Position=[1 0 1]);
    peripheralNode = bluetoothNode("peripheral",Position=[2 0 0]);

    Create a default Bluetooth BR/EDR configuration object to share a connection between the Central and Peripheral nodes.

    cfgConnection = bluetoothConnectionConfig;

    Configure the connection between the Bluetooth BR/EDR Central and Peripheral nodes.

    configureConnection(cfgConnection,centralNode,peripheralNode)
    ans = 
      bluetoothConnectionConfig with properties:
    
        CentralToPeripheralACLPacketType: "DH1"
        PeripheralToCentralACLPacketType: "DH1"
                           SCOPacketType: "None"
                     HoppingSequenceType: "Connection adaptive"
                            UsedChannels: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 … ] (1×79 double)
                            PollInterval: 40
                           InstantOffset: 240
                        TransmitterPower: 20
                      SupervisionTimeout: 32000
                          CentralAddress: "6AC1F4B80001"
                        PrimaryLTAddress: 1
    
    

    Create an On-Off application traffic pattern generator object, specifying the On and Off state durations in seconds, the packet length in bytes, and the packet generation rate in Kbps. Add the application traffic source from the Central node to the Peripheral node.

    c2pTraffic = networkTrafficOnOff(DataRate=256,PacketSize=20,OnTime=inf,OffTime=0);
    addTrafficSource(centralNode,c2pTraffic,DestinationNode=peripheralNode)

    Create an On-Off application traffic pattern generator object, specifying the On and Off state durations in seconds, the packet length in bytes, and the packet generation rate in Kbps. Add the application traffic source from the Peripheral node to the Central node.

    p2cTraffic = networkTrafficOnOff(DataRate=256,PacketSize=20,OnTime=inf,OffTime=0);
    addTrafficSource(peripheralNode,p2cTraffic,DestinationNode=centralNode)

    Add the Central node and Peripheral node to the wireless network simulator.

    nodes = [centralNode peripheralNode];
    addNodes(networkSimulator,nodes)

    Register callbacks for the "TransmissionStarted" and "AppPacketReceived" events from the Central and Peripheral nodes.

    registerEventCallback(centralNode,"TransmissionStarted",@(eventStruct) disp(eventStruct))
    registerEventCallback(peripheralNode,"AppPacketReceived",@(eventStruct) disp(eventStruct))

    Run the simulation for the specified time.

    run(networkSimulator,simulationTime)
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 3.1000e-04
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0013
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0016
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0025
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0028
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0037
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0041
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0050
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0053
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0063
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0066
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0075
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0078
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0088
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "AppPacketReceived"
              NodeName: "Node2"
                NodeID: 2
             Timestamp: 0.0091
        TechnologyType: 4
             EventData: [1×1 struct]
    
             EventName: "TransmissionStarted"
              NodeName: "Node1"
                NodeID: 1
             Timestamp: 0.0100
        TechnologyType: 4
             EventData: [1×1 struct]
    

    Retrieve the APP, LL, and PHY statistics for the Central and Peripheral nodes.

    statsCentral = statistics(centralNode)
    statsCentral = struct with fields:
            Name: "Node1"
              ID: 1
             App: [1×1 struct]
        Baseband: [1×1 struct]
             PHY: [1×1 struct]
    
    
    statsPeripheral = statistics(peripheralNode)
    statsPeripheral = struct with fields:
            Name: "Node2"
              ID: 2
             App: [1×1 struct]
        Baseband: [1×1 struct]
             PHY: [1×1 struct]
    
    

    Input Arguments

    collapse all

    Bluetooth BR/EDR node object, specified as a bluetoothNode object or a vector of bluetoothNode objects.

    Name of the event, specified as a string scalar, character vector, vector of strings, or cell array of character vectors. Each element of the argument must be one of these values:

    • TransmissionStarted

    • ReceptionEnded

    • AppPacketGenerated

    • AppPacketReceived

    • ChangingState

    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 Bluetooth BR/EDR node notifies occurrence of an event, specified as a scalar function handle. The callback function must use this syntax.

    @(eventStruct) callback(eventStruct)
    The Bluetooth BR/EDR 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 triggered, 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 bluetoothNode 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

    References

    [1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed September 22, 2025. https://www.bluetooth.com/.

    [2] Bluetooth Core Specifications Working Group. "Bluetooth Core Specification" v6.1. https://www.bluetooth.com/specifications/specs/core-specification-6-1/.

    Version History

    Introduced in R2026a

    See Also

    Objects