beaconDecoderResult = {
const uuid = "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0";
const namespace = "EDD1EBEAC04E5DEFA017";
const instance = beaconMinor.toString(16).toUpperCase().padStart(12, "0");
const url = "https://mystore.com/offer";
let fields = [];
let packetHex = [];
let totalBytes = 0;
let headerColor = "#2C3E50";
if (beaconType === "iBeacon") {
headerColor = "#2C3E50";
fields = [
{name: "AD Length", value: "0x1A (26)", bytes: 1, color: "#7F8C8D"},
{name: "AD Type", value: "0xFF (Manufacturer Specific)", bytes: 1, color: "#7F8C8D"},
{name: "Company ID", value: "0x004C (Apple)", bytes: 2, color: "#9B59B6"},
{name: "iBeacon Type", value: "0x0215", bytes: 2, color: "#9B59B6"},
{name: "Proximity UUID", value: uuid, bytes: 16, color: "#16A085"},
{name: "Major", value: `${beaconMajor} (0x${beaconMajor.toString(16).toUpperCase().padStart(4, "0")})`, bytes: 2, color: "#E67E22"},
{name: "Minor", value: `${beaconMinor} (0x${beaconMinor.toString(16).toUpperCase().padStart(4, "0")})`, bytes: 2, color: "#3498DB"},
{name: "TX Power", value: `${beaconTxPower} dBm`, bytes: 1, color: "#E74C3C"}
];
totalBytes = 27;
} else if (beaconType === "Eddystone-URL") {
headerColor = "#16A085";
fields = [
{name: "Frame Type", value: "0x10 (URL)", bytes: 1, color: "#7F8C8D"},
{name: "TX Power", value: `${beaconTxPower} dBm`, bytes: 1, color: "#E74C3C"},
{name: "URL Scheme", value: "0x03 (https://)", bytes: 1, color: "#9B59B6"},
{name: "Encoded URL", value: url.replace("https://", ""), bytes: url.replace("https://", "").length, color: "#16A085"},
{name: "Service UUID", value: "0xFEAA (Eddystone)", bytes: 2, color: "#E67E22"}
];
totalBytes = 5 + url.replace("https://", "").length;
} else {
headerColor = "#3498DB";
fields = [
{name: "Frame Type", value: "0x00 (UID)", bytes: 1, color: "#7F8C8D"},
{name: "TX Power", value: `${beaconTxPower} dBm`, bytes: 1, color: "#E74C3C"},
{name: "Namespace (10B)", value: namespace, bytes: 10, color: "#16A085"},
{name: "Instance (6B)", value: instance, bytes: 6, color: "#3498DB"},
{name: "Service UUID", value: "0xFEAA (Eddystone)", bytes: 2, color: "#E67E22"},
{name: "Reserved", value: "0x0000", bytes: 2, color: "#7F8C8D"}
];
totalBytes = 22;
}
const detRange = Math.pow(10, (beaconTxPower - (-70)) / (10 * 2.0));
return html`<div style="font-family: Arial, sans-serif; background: #f8f9fa; border-radius: 8px; padding: 16px;">
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
<div style="background: ${headerColor}; color: white; padding: 6px 14px; border-radius: 20px; font-size: 14px; font-weight: bold;">${beaconType}</div>
<span style="font-size: 13px; color: #7F8C8D;">Packet size: ${totalBytes} bytes | Detection range: ~${detRange.toFixed(1)}m</span>
</div>
<div style="font-size: 13px; font-weight: bold; color: #2C3E50; margin-bottom: 8px;">Advertisement Packet Fields:</div>
${fields.map(f => html`<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 4px; padding: 6px 10px; background: white; border-radius: 4px; border-left: 4px solid ${f.color};">
<div style="min-width: 130px; font-size: 12px; font-weight: bold; color: ${f.color};">${f.name}</div>
<div style="flex: 1; font-size: 12px; color: #2C3E50; font-family: monospace;">${f.value}</div>
<div style="min-width: 40px; text-align: right; font-size: 11px; color: #7F8C8D;">${f.bytes}B</div>
</div>`)}
<div style="margin-top: 12px; padding: 10px; background: #eaf2f8; border-radius: 4px;">
<div style="font-size: 12px; color: #2C3E50;">
${beaconType === "iBeacon"
? html`<strong>iBeacon addressing:</strong> UUID identifies your organization/app, Major groups beacons (e.g., store floor), Minor identifies individual beacons (e.g., specific shelf). This 3-level hierarchy enables location precision from building to aisle.`
: beaconType === "Eddystone-URL"
? html`<strong>Eddystone-URL:</strong> Broadcasts a URL directly in the advertisement, enabling "Physical Web" interactions without a dedicated app. The URL is compressed using scheme codes (https:// = 0x03) and domain suffixes (.com = 0x07).`
: html`<strong>Eddystone-UID:</strong> Uses a 10-byte namespace (typically derived from a domain hash) plus a 6-byte instance ID, providing a flat addressing scheme alternative to iBeacon's UUID/Major/Minor hierarchy.`}
</div>
</div>
</div>`;
}