# Test Script for YSP Hex Printing

## Overview
This script demonstrates the YSP hex printing functionality with sample data.

## Sample YSP Data
```
0245302260007820000200703c278028c0...
```

## Test Commands

### 1. Start IEx session:
```bash
cd /home/prem/mercurypay/mercury_device_middlelayer
iex -S mix
```

### 2. Test hex printing with sample data:
```elixir
# Sample ISO8583 data (without YSP framing)
iso_data = "60007820000200703c278028c0"

# Test basic hex printing
YspMessageFraming.print_hex_with_header(iso_data)

# Test compact format
YspMessageFraming.print_hex_with_header(iso_data, format: :compact)

# Test detailed format
YspMessageFraming.print_hex_with_header(iso_data, format: :detailed)

# Test breakdown format  
YspMessageFraming.print_hex_with_header(iso_data, format: :breakdown)

# Test string output (no console printing)
hex_string = YspMessageFraming.format_hex_with_header(iso_data, format: :breakdown)
IO.puts(hex_string)
```

### 3. Test YSP framing:
```elixir
# Frame a message (adds length prefix and header)
iso_data = "60007820000200703c278028c0"
{:ok, framed} = YspMessageFraming.frame_message(iso_data, %{})

# Print the framed message
YspMessageFraming.print_hex_with_header(framed, format: :breakdown)

# Unframe it back
{:ok, unframed} = YspMessageFraming.unframe_message(framed)
IO.puts("Original: #{iso_data}")
IO.puts("Unframed: #{unframed}")
```

### 4. Test error handling:
```elixir
# Test with malformed data
malformed = "123"  # Too short
case YspMessageFraming.unframe_message(malformed) do
  {:error, reason} -> IO.puts("Expected error: #{reason}")
  other -> IO.puts("Unexpected result: #{inspect(other)}")
end
```

## Expected Output Format

### Breakdown format example:
```
YSP Framed Message (31 bytes):
├─ Length: 0x001B (27 bytes)
├─ Header: 0x3022 (YSP Fixed Header) 
└─ ISO Data: 60 00 78 20 00 02 00 70 3c 27 80 28 c0
```

### Compact format example:
```
YSP: 001B 3022 | 60007820000200703c278028c0
```

## Notes
- The hex printing should work even if some functions have warnings
- The framing functionality adds the required 0x3022 header
- Length calculation is automatic and uses big-endian encoding
- Error handling provides meaningful messages for malformed packets

## Verification
If the above commands work without throwing exceptions, the implementation is successful!