2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluegiga.internal.eir;
15 import java.util.Arrays;
16 import java.util.HashMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
23 * This class processes the Extended Inquiry Response data used in the BLE advertisement frame
25 * @author Chris Jackson - Initial contribution
29 public class EirPacket {
30 private Map<EirDataType, Object> records = new HashMap<>();
32 public EirPacket(int @Nullable [] data) {
33 if (data == null || data.length == 0) {
37 for (int cnt = 0; cnt < data.length;) {
42 int[] rawRecord = Arrays.copyOfRange(data, cnt + 1, cnt + data[cnt] + 1);
43 EirRecord record = new EirRecord(rawRecord);
47 records.put(record.getType(), record.getRecord());
52 * Returns a map of all records decoded in the packet
54 * @return {@link Map} of {@link EirDataType} to {@link Object}
56 public Map<EirDataType, Object> getRecords() {
61 * Returns the specified record decoded in the packet or null if the record is not found
63 * @param recordType the requested {@link EirDataType}
64 * @return {@link Map} of to {@link Object}
66 public @Nullable Object getRecord(EirDataType recordType) {
67 return records.get(recordType);
71 public String toString() {
72 final StringBuilder builder = new StringBuilder();
73 builder.append("EirPacket [records=");
74 builder.append(records);
76 return builder.toString();