takproto 0.4.2

Rust library for TAK (Team Awareness Kit) Protocol - send CoT messages to TAK servers with mTLS support
Documentation
//! Simple test using XML mode instead of protobuf
//!
//! Usage:
//! ```
//! cargo run --example simple_test_xml -- \
//!     <server:port> <server_name> <ca_cert> <client_cert> <client_key>
//! ```

use takproto::helpers::{contact, precision_location, status};
use takproto::{CotEventBuilder, TakClient, TlsConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args: Vec<String> = std::env::args().collect();
    if args.len() < 6 {
        eprintln!(
            "Usage: {} <server:port> <server_name> <ca_cert> <client_cert> <client_key>",
            args[0]
        );
        std::process::exit(1);
    }

    let server_addr = &args[1];
    let server_name = &args[2];
    let ca_cert = &args[3];
    let client_cert = &args[4];
    let client_key = &args[5];

    println!("Loading certificates...");
    let tls_config = TlsConfig::new_with_client_cert(ca_cert, client_cert, client_key)?;
    println!("✓ Certificates loaded\n");

    println!("Connecting to {}...", server_addr);
    let mut client = TakClient::connect_tls(server_addr, server_name, tls_config).await?;
    println!("✓ Connected\n");

    println!("⚠️  NOT negotiating protocol - staying in XML mode");
    println!("   (This tests if the issue is protobuf-specific)\n");

    // Test 1: Minimal event (no detail)
    println!("Test 1: Sending minimal event (no detail fields) [XML]...");
    let minimal = CotEventBuilder::new()
        .uid("TEST-MINIMAL-XML")
        .cot_type("a-f-G-U-C")
        .lat_lon(37.7749, -122.4194)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .build()?;

    println!("Sending as XML...");
    client.send_cot_event_xml(minimal).await?;
    println!("✓ Sent\n");

    tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

    // Test 2: Event with contact
    println!("Test 2: Sending event with contact [XML]...");
    let with_contact = CotEventBuilder::new()
        .uid("TEST-CONTACT-XML")
        .cot_type("a-f-G-U-C")
        .lat_lon(37.7750, -122.4195)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("TestUser", Some("192.168.1.100:4242")))
        .build()?;

    client.send_cot_event_xml(with_contact).await?;
    println!("✓ Sent\n");

    tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

    // Test 3: Event with status
    println!("Test 3: Sending event with status [XML]...");
    let with_status = CotEventBuilder::new()
        .uid("TEST-STATUS-XML")
        .cot_type("a-f-G-U-C")
        .lat_lon(37.7751, -122.4196)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_status(status(85))
        .build()?;

    client.send_cot_event_xml(with_status).await?;
    println!("✓ Sent\n");

    tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

    // Test 4: Event with precision_location
    println!("Test 4: Sending event with precision_location [XML]...");
    let with_prec = CotEventBuilder::new()
        .uid("TEST-PRECISION-XML")
        .cot_type("a-f-G-U-C")
        .lat_lon(37.7752, -122.4197)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_precision_location(precision_location("GPS", "GPS"))
        .build()?;

    client.send_cot_event_xml(with_prec).await?;
    println!("✓ Sent\n");

    tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

    // Test 5: Event with all fields
    println!("Test 5: Sending event with all fields [XML]...");
    let with_all = CotEventBuilder::new()
        .uid("TEST-ALL-XML")
        .cot_type("a-f-G-U-C")
        .lat_lon(37.7753, -122.4198)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("AllFields", Some("192.168.1.100:4242")))
        .with_status(status(90))
        .with_precision_location(precision_location("GPS", "BARO"))
        .build()?;

    client.send_cot_event_xml(with_all).await?;
    println!("✓ Sent\n");

    println!("=================================");
    println!("✅ All 5 XML events sent!");
    println!("=================================");
    println!("\nCheck iTAK. You should see 5 markers with '-XML' suffix:");
    println!("  1. TEST-MINIMAL-XML");
    println!("  2. TEST-CONTACT-XML");
    println!("  3. TEST-STATUS-XML");
    println!("  4. TEST-PRECISION-XML");
    println!("  5. TEST-ALL-XML");
    println!("\nIf XML events show but protobuf events don't,");
    println!("we have a protobuf serialization issue.");

    Ok(())
}