#!/usr/bin/env elixir Mix.install([]) defmodule HeaderConfigFixTest do def test_fixed_config do IO.puts("šŸ”§ Testing Fixed Header Configuration") # Updated configuration (HEX instead of BCD) header_config = %{ enabled: true, type: :base1, encoding: :hex, # Fixed from :bcd to :hex pattern: "6000782000", length: 5, source_address_offset: 2, source_address_length: 2, dest_address_offset: 4, dest_address_length: 2 } # Your actual packet data packet_hex = "60007820000400703C078000C282051648549806007367400000000000000000050000000220912500917310500510000078200313233343536373131323334353637383930313233343500817B226F72696744617465223A223230323530393137222C226F7269674D7469223A2230323030222C226F7269675472616365223A22303030303232222C226F72696754696D65223A22303931323530227D3738340028950500800400009F1E0832333733303030319F100706011203A0A80200063030303030311234567812345678" case Base.decode16(packet_hex) do {:ok, packet_data} -> IO.puts("āœ… Packet decoded: #{byte_size(packet_data)} bytes") # Test header extraction with correct HEX encoding case Base.decode16(header_config.pattern) do {:ok, expected_header_binary} -> IO.puts("āœ… Pattern converts from HEX: #{Base.encode16(expected_header_binary)}") # Check if packet starts with expected header header_size = header_config.length <> = packet_data if actual_header == expected_header_binary do IO.puts("āœ… Header matches! Extracted #{byte_size(actual_header)} bytes") IO.puts(" Header (hex): #{Base.encode16(actual_header)}") IO.puts(" Remaining ISO data: #{byte_size(remaining)} bytes") IO.puts(" First 10 bytes of ISO: #{Base.encode16(binary_part(remaining, 0, 10))}") else IO.puts("āŒ Header mismatch!") IO.puts(" Expected: #{Base.encode16(expected_header_binary)}") IO.puts(" Got: #{Base.encode16(actual_header)}") end :error -> IO.puts("āŒ Invalid hex pattern") end :error -> IO.puts("āŒ Failed to decode packet") end IO.puts("\nšŸ“‹ Configuration Summary:") IO.puts(" Port: 8583") IO.puts(" Encoding: #{header_config.encoding} (was :bcd, now :hex)") IO.puts(" Pattern: #{header_config.pattern}") IO.puts(" Length: #{header_config.length} bytes") IO.puts(" Type: #{header_config.type}") end end HeaderConfigFixTest.test_fixed_config()