%% Write BLE LL Packet to PCAPNG File from PCAPNG File Writer
% Create a PCAPNG file writer object, specifying the name of the PCAPNG file.

pcapObj = pcapngWriter('FileName','sampleBLELL',  ...
    'FileComment','This is a sample file');

% Create a BLE PCAP file writer object, specifying the PCAPNG file writer and the presence of PHY header.

blePCAP = blePCAPWriter('PCAPWriter',pcapObj,'PhyHeaderPresent',true);

% Generate a BLE LL packet.

cfgLLAdv = bleLLAdvertisingChannelPDUConfig;
cfgLLAdv.PDUType = 'Advertising indication';
cfgLLAdv.AdvertisingData = '020106';
llDataPDU = bleLLAdvertisingChannelPDU(cfgLLAdv);
connAccessAddress = de2bi(hex2dec('E213BC42'),32)';
llpacket = [connAccessAddress;llDataPDU];

% Write the BLE LL packet to the PCAPNG file.

PhyHeaderBytes = [39 10 8 1 10 10 10 10 15 00];
timestamp = 18912345; % Number of microseconds
write(blePCAP,llpacket,timestamp,'PacketFormat','bits', ...
    'PhyHeader',PhyHeaderBytes,'PacketComment','This is the first packet');

% Copyright 2020 The MathWorks, Inc.