question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AdvertisingPacketUtil:getAdvertisingPacketsBetween() Skip one advertising packet

See original GitHub issue

Hello,

According to the description, the method below “Returns an ArrayList of AdvertisingPackets that have been received in the specified time range.

public static <P extends AdvertisingPacket> ArrayList<P> getAdvertisingPacketsBetween(final ArrayList<P> advertisingPackets, long startTimestamp, long endTimestamp) {
          ...
    }

I am testing this method right now, Here is my input data :

long startTimestamp = 1533538629;
long endTimestamp = 1533538899;
         
ArrayList<AdvertisingPacket> advertisingPackets = new ArrayList<AdvertisingPacket>();
advertisingPackets.add(new AdvertisingPacket(1, 1533538511));
advertisingPackets.add(new AdvertisingPacket(2, 1533538629));
advertisingPackets.add(new AdvertisingPacket(3, 1533538686));
advertisingPackets.add(new AdvertisingPacket(4, 1533538737));
advertisingPackets.add(new AdvertisingPacket(5, 1533538772));
advertisingPackets.add(new AdvertisingPacket(6, 1533538805));
advertisingPackets.add(new AdvertisingPacket(7, 1533538849));
advertisingPackets.add(new AdvertisingPacket(8, 1533538865));
advertisingPackets.add(new AdvertisingPacket(9, 1533538884));
advertisingPackets.add(new AdvertisingPacket(10, 1533538899));
advertisingPackets.add(new AdvertisingPacket(11, 1533538912));
advertisingPackets.add(new AdvertisingPacket(12, 1533539012));

After calling getAdvertisingPacketsBetween method with the input above the result returned is [ 2, 3, 4, 5, 6, 7, 8, 9], Why we aren’t taking the index number 10 with the array ? I think it’s a bug, Every endTimestamp chosen > 6 ( which it’s the middle of the list), the last index is skipped.

To Solve the issue above, we should add 1 to the endIndex calculated when endTimestamp >= midstAdvertisingPacket.getTimestamp()

    // find the index of the last advertising packet with a timestamp
        // smaller than the specified endTimestamp
        int endIndex = advertisingPackets.size() - 1;
        if (endTimestamp < latestAdvertisingPacket.getTimestamp()) {
            // figure out if the end timestamp is before or after the midst advertising packet
            ListIterator<P> listIterator;
            if (endTimestamp < midstAdvertisingPacket.getTimestamp()) {
                // end timestamp is in the first half of advertising packets
                // start iterating from the beginning
                listIterator = advertisingPackets.listIterator(startIndex);
                while (listIterator.hasNext()) {
                    if (listIterator.next().getTimestamp() >= endTimestamp) {
                        endIndex = listIterator.previousIndex();
                        break;
                    }
                }
            } else {
                // end timestamp is in the second half of advertising packets
                // start iterating from the end
                listIterator = advertisingPackets.listIterator(advertisingPackets.size());
                while (listIterator.hasPrevious()) {
                    if (listIterator.previous().getTimestamp() < endTimestamp) {
                        endIndex = listIterator.nextIndex() + 1;  <------ HERE
                        break;
                    }
                }
            }
        }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hadiidboukcommented, Aug 8, 2018

Where is the line c) ? Also can you please add “java” after the code block, it’s more clear to read the code. Like so

``java <-- three ` not two

``
0reactions
marvinmirtschincommented, Oct 9, 2018

Fixed in #122

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Bluetooth Low Energy Works: Advertisements (Part 1)
A peripheral or broadcaster always starts with advertising before accepting a connection. In fact, the advertisement packets are the only ...
Read more >
KBA_BT_0201: Bluetooth advertising data basics
When a BLE device is advertising it will periodically transmit packets contains information such as: Preamble, Access Address, CRC, Bluetooth ...
Read more >
information about "SKIP" and "TIMEOUT" parameters of BLE 5 ...
Hi I am working on an application that uses extended periodic advertising feature of BLE 5. In this sample (periodic sync): ...
Read more >
what is the max length for serviceData in Advertisement ...
There are only 31 bytes in the Advertisement packet and a 128-bit UUID takes up 16 of them! So, if the service UUID...
Read more >
BLE Advertising Primer | Argenox
BLE Advertising is a critical part of the Bluetooth Low Energy protocl and ... is using advertisements, where a BLE peripheral device broadcasts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found