This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AWRL6432BOOST: Trying to get the detected points coordinate

Part Number: AWRL6432BOOST

HI Team, trying to help a customer. 

______________________________

written a python code and I read the data from the UART port and save it to a .bin file. Then using the code below I try to save the values and extract the detected points cooridinate:

import struct
import numpy as np
from enum import Enum

class MmwDemo_output_message_type(Enum):
    MMWDEMO_OUTPUT_MSG_DETECTED_POINTS = 1
    MMWDEMO_OUTPUT_MSG_RANGE_PROFILE = 2
    MMWDEMO_OUTPUT_MSG_NOISE_PROFILE = 3
    MMWDEMO_OUTPUT_MSG_AZIMUT_STATIC_HEAT_MAP = 4
    MMWDEMO_OUTPUT_MSG_RANGE_DOPPLER_HEAT_MAP = 5
    MMWDEMO_OUTPUT_MSG_STATS = 6
    MMWDEMO_OUTPUT_MSG_DETECTED_POINTS_SIDE_INFO = 7
    MMWDEMO_OUTPUT_MSG_AZIMUT_ELEVATION_STATIC_HEAT_MAP = 8
    MMWDEMO_OUTPUT_MSG_TEMPERATURE_STATS = 9
    MMWDEMO_OUTPUT_MSG_MAX = 10
    MMWDEMO_OUTPUT_EXT_MSG_START = 300
    MMWDEMO_OUTPUT_EXT_MSG_DETECTED_POINTS = 301
    MMWDEMO_OUTPUT_EXT_MSG_RANGE_PROFILE_MAJOR = 302
    MMWDEMO_OUTPUT_EXT_MSG_RANGE_PROFILE_MINOR = 303
    MMWDEMO_OUTPUT_EXT_MSG_RANGE_AZIMUT_HEAT_MAP_MAJOR = 304
    MMWDEMO_OUTPUT_EXT_MSG_RANGE_AZIMUT_HEAT_MAP_MINOR = 305
    MMWDEMO_OUTPUT_EXT_MSG_STATS = 306
    MMWDEMO_OUTPUT_EXT_MSG_PRESENCE_INFO = 307
    MMWDEMO_OUTPUT_EXT_MSG_TARGET_LIST = 308
    MMWDEMO_OUTPUT_EXT_MSG_TARGET_INDEX = 309
    MMWDEMO_OUTPUT_EXT_MSG_MICRO_DOPPLER_RAW_DATA = 310
    MMWDEMO_OUTPUT_EXT_MSG_MICRO_DOPPLER_FEATURES = 311
    MMWDEMO_OUTPUT_EXT_MSG_RADAR_CUBE_MAJOR = 312
    MMWDEMO_OUTPUT_EXT_MSG_RADAR_CUBE_MINOR = 313
    MMWDEMO_OUTPUT_EXT_MSG_POINT_CLOUD_INDICES = 314
    MMWDEMO_OUTPUT_EXT_MSG_MAX = 315

# Magic Word
magic_word = [0x0102, 0x0304, 0x0506, 0x0708]

# Open binary file
input_file = 'Output_files/tlvs.bin'  # Replace with your input file path
with open(input_file, 'rb') as file:
    data = file.read()

# Convert magic word to bytes
magic_word_bytes = struct.pack('<HHHH', *magic_word)

# Find all occurrences of the magic word
magic_word_indices = []
start_index = 0
while True:
    magic_word_index = data.find(magic_word_bytes, start_index)
    if magic_word_index == -1:
        break
    magic_word_indices.append(magic_word_index)
    start_index = magic_word_index + len(magic_word_bytes)

if not magic_word_indices:
    print("Magic word not found in the file.")
    exit()

already_gone = 0
# Process each magic word occurrence
for index, magic_word_index in enumerate(magic_word_indices):
    # Extract values after magic word
    data = data[magic_word_index + len(magic_word_bytes) - already_gone:]

    already_gone = magic_word_index + len(magic_word_bytes)

    # Define format for unpacking header values
    header_format_string = "<IIIIIIII"

    # Unpack header values
    if len(data) < struct.calcsize(header_format_string):
        print("Insufficient data to unpack TLV type and length.")
        continue
    else:
        header_values = struct.unpack(header_format_string, data[:struct.calcsize(header_format_string)])
        version, total_packet_length, platform, frame_number, time_cycles, num_detected_obj, num_tlvs, subframe_number = header_values

    # Print the extracted header values
    print("Version:", version)
    print("Total Packet Length:", total_packet_length)
    print("Platform:", platform)
    print("Frame Number:", frame_number)
    print("Time [in CPU Cycles]:", time_cycles)
    print("Num Detected Obj:", num_detected_obj)
    print("Num TLVs:", num_tlvs)
    print("Subframe Number:", subframe_number)

    # Extract TLVs
    tlv_data = data[struct.calcsize(header_format_string):]
    for tlv_index in range(num_tlvs):
        if len(tlv_data) < 8:
            print("Insufficient data to unpack TLV type and length.")
            break
        
        # Unpack TLV type and length
        tlv_format_string = "<II"
        tlv_type, tlv_length = struct.unpack(tlv_format_string, tlv_data[:struct.calcsize(tlv_format_string)])

        # Extract TLV value
        if len(tlv_data) < struct.calcsize(tlv_format_string) + tlv_length:
            print("Insufficient data to extract TLV value.")
            break
        tlv_value = tlv_data[struct.calcsize(tlv_format_string):struct.calcsize(tlv_format_string) + tlv_length]

        # Unpack TLV value as decimals (assuming little endian byte order)
        point_size = 4  # Size of each point in bytes
        num_values = tlv_length // point_size  # Assuming each point is 16 bytes
        remaining_bytes = tlv_length % point_size  # Calculate the remaining bytes
        point_format_string = f"<{num_values}f"

        # Adjust the tlv_value length by discarding remaining bytes if necessary
        tlv_value_length = tlv_length - remaining_bytes
        tlv_value = tlv_data[struct.calcsize(tlv_format_string):struct.calcsize(tlv_format_string) + tlv_value_length]

        # Check if the tlv_value length is divisible by the point size
        if tlv_value_length % point_size != 0:
            # Discard the remaining incomplete point at the end
            tlv_value = tlv_value[:-(remaining_bytes % point_size)]

        tlv_decimals = struct.unpack(point_format_string, tlv_value)

        # Save TLV value as NumPy file
        output_file = f"Output_files/{MmwDemo_output_message_type(tlv_type)}-{frame_number}-{tlv_index}.npy"
        output_file = output_file.replace("MmwDemo_output_message_type.", '')
        output_file = output_file.replace("MMWDEMO_OUTPUT_", '')
        np.save(output_file, tlv_decimals)

        # Print TLV information
        print("TLV Type:", MmwDemo_output_message_type(tlv_type))
        print("TLV Length:", tlv_length)
        print("TLV Values Saved to:", output_file)

        # Move to the next TLV
        tlv_data = tlv_data[struct.calcsize(tlv_format_string) + tlv_length:]

    print()  # Add a newline between magic words

Everything works fine and I can find headers and TLVs, however, according to the document the typdef=1 which is for detected points is supposed to be a multiplication of 16 as for every point there is 16 bytes of data (X,Y,Z and velocity). However, the tlv data is not necessarily a multiplication of 16. As a result, I have unpack it 4 bytes by 4 bytes, then considered the very first element as X of the first point, the second element Y of the first point and so on.

I plot these points then but what I get is different from what I get from the visualizer. Can you share the AWRL6432BOOST visualizer code or tell me what is going wrong in my code?

____________________________________________-

Thank you.

-Mark