#!/usr/bin/env elixir Mix.install([]) defmodule HeaderConfigTest do def test_header_processing do IO.puts("šŸ” Testing Header Configuration Detection") # Test configuration matching your setup header_config = %{ enabled: true, type: :base1, encoding: :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 = "60007820000400703C078000C282051648549806007367400000000000000050000000220912500917310500510000078200313233343536373131323334353637383930313233343500817B226F72696744617465223A223230323530393137222C226F7269674D7469223A2230323030222C226F7269675472616365223A22303030303232222C226F72696754696D65223A22303931323530227D3738340028950500800400009F1E0832333733303030319F100706011203A0A80200063030303030311234567812345678" case Base.decode16(packet_hex) do {:ok, packet_data} -> IO.puts("āœ… Packet decoded successfully: #{byte_size(packet_data)} bytes") # Extract expected header expected_header = String.slice(packet_hex, 0, 10) # First 5 bytes = 10 hex chars IO.puts("šŸ“‹ Expected header (hex): #{expected_header}") # Check if header matches pattern if expected_header == "6000782000" do IO.puts("āœ… Header pattern matches configuration!") # Extract remaining data remaining_hex = String.slice(packet_hex, 10, String.length(packet_hex) - 10) remaining_size = String.length(remaining_hex) / 2 IO.puts("šŸ“„ Remaining ISO data: #{trunc(remaining_size)} bytes") IO.puts("šŸ“„ First 20 bytes of ISO data: #{String.slice(remaining_hex, 0, 40)}") else IO.puts("āŒ Header pattern does not match!") IO.puts(" Expected: 6000782000") IO.puts(" Got: #{expected_header}") end :error -> IO.puts("āŒ Failed to decode packet hex") end # Test configuration validation IO.puts("\nšŸ”§ Testing Configuration Validation...") required_fields = [:enabled, :type, :encoding, :pattern, :length] missing_fields = Enum.filter(required_fields, fn field -> not Map.has_key?(header_config, field) end) if Enum.empty?(missing_fields) do IO.puts("āœ… All required header config fields present") else IO.puts("āŒ Missing header config fields: #{inspect(missing_fields)}") end # Test pattern conversion case Base.decode16(header_config.pattern) do {:ok, pattern_binary} -> IO.puts("āœ… Pattern converts to binary successfully: #{byte_size(pattern_binary)} bytes") :error -> IO.puts("āŒ Invalid hex pattern in configuration") end end end HeaderConfigTest.test_header_processing()