registerEventCallback
Description
registerEventCallback(
registers the function callback bluetoothNodeObj,eventName,callback)callback for the specified event
eventName from the Bluetooth® basic rate/enhanced data rate (BR/EDR) node,
bluetoothNodeObj.
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,"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
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:
TransmissionStartedReceptionEndedAppPacketGeneratedAppPacketReceivedChangingState
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)
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 triggered, 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 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
The object function defines these events.
TransmissionStartedThe baseband triggers this event, notifying the node of the start of packet transmission. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU | Row vector of decimal octets | PDU bits to be transmitted from the baseband in the current transmission |
Length | Double scalar | Number of octets sent from the baseband to the physical layer (PHY) |
Duration | Double scalar | Over the air transmission time in seconds, including PHY overhead |
TransmitPower | Double scalar | Power of the current transmission, in dBm |
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 |
LogicalTransport | Valid values are
| Bluetooth BR/EDR logical transport at which the packet transmission starts |
Role | Valid values are | Role of the Bluetooth BR/EDR node at which the packet transmission starts |
PHYMode | Valid values are | PHY transmission mode |
ReceptionEndedThe baseband triggers this event, notifying the node of the end of packet reception. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU | Row vector of decimal octets | PDU bits received from the baseband in the current transmission |
Length | Double scalar | Number of octets sent from the PHY to the baseband |
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 | Nonnegative integer, where If the PHY
does not transmit payload to the baseband, the value of this field is
| Decoding status of the signal received at the baseband |
SINR | Double scalar | Signal-to-interference plus noise ratio, in dB, of the current reception |
TransmitterNodeID | Double scalar | Identifier of the node that transmitted the signal of interest (SOI) in the current reception |
LogicalTransport | Valid values are | Bluetooth BR/EDR logical transport at which the packet transmission starts |
Role | Valid values are | Role of the Bluetooth BR/EDR node at which the packet transmission starts |
PHYMode | Valid values are | PHY transmission mode |
RSSI | Double scalar | Strength of the received SOI, in dBm. |
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 | Row vector of decimal octets | Application packet, in bytes |
PacketLength | Double scalar | Number of bytes in the application packet |
DestinationNodeID | Double scalar | Identifier of the destination node |
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 | Row vector of decimal octets | Application packet, in bytes |
PacketLength | Double scalar | Number of bytes in the application packet |
SourceNodeID | Double scalar | Identifier of the source node |
Note
The node does not notify the occurrence of this event when it receives packets generated using full-buffer traffic.
ChangingStateThe baseband triggers this event to notify the node of a change in its state. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PreviousState | Valid values are | State from which the baseband transitioned |
NextState | Valid values are | State to which the baseband transitioned |
PreviousStateDuration | Double scalar | Duration, in seconds, that the baseband remains in its previous state before transitioning. |
CenterFrequency | Double scalar | Frequency of operation of a device or link, in Hz |
Bandwidth | Double scalar | Bandwidth of operation of a device or a link, in Hz |
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
bluetoothNode|bluetoothConnectionConfig|wirelessNetworkSimulator(Wireless Network 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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)