AdvertisingPacketUtil:getAdvertisingPacketsBetween() Skip one advertising packet
See original GitHub issueHello,
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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
Fixed in #122