import numpy as np
import matplotlib.pyplot as plt

def decode_ota_bitmap(hex_data, width=72, height=14):
    # Step 1: Convert hex to binary string
    binary_data = ''.join(f"{int(h, 16):04b}" for h in hex_data)

    # Step 2: Ensure the binary data fits the expected size
    expected_bits = width * height
    binary_data = binary_data[:expected_bits]

    # Step 3: Convert binary data to a numpy array for visualization
    bitmap = np.array([int(bit) for bit in binary_data]).reshape(height, width)

    # Step 4: Display the bitmap
    plt.figure(figsize=(6, 2))
    plt.imshow(bitmap, cmap='gray', interpolation='nearest')
    plt.axis('off')
    plt.title("Decoded OTA Bitmap")
    plt.show()

# Example Usage
hex_payload = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFF9FFFFF3FFC71FFFFFFDFFFEFBFFDED0F3273DFFCC18FF8EDB7BDE1DFFB6FB7FB71B7BAEFDFFB6DB7FB7B8F12718FFCF30FF8E3BFFFFFFFFFFFFFFFFF1FFFFFFFFFFFFFFFFFFFFFFFFC0FFFFC0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00"
decode_ota_bitmap(hex_payload)

