takproto 0.4.2

Rust library for TAK (Team Awareness Kit) Protocol - send CoT messages to TAK servers with mTLS support
Documentation
//! Test a-f-G-U-C (friendly ground unit) with proper detail fields
//!
//! This CoT type typically requires contact info to display properly

use takproto::helpers::{contact, track};
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!("Negotiating protocol...");
    client.negotiate_protocol(1, 60).await?;
    println!("✓ Protocol negotiated (protobuf mode)\n");

    // Test 1: a-f-G-U-C with minimal contact (just callsign)
    println!("Test 1: a-f-G-U-C with contact (callsign only)...");
    let unit1 = CotEventBuilder::new()
        .uid("ALPHA-1")
        .cot_type("a-f-G-U-C")
        .lat_lon(39.377445, -76.832160)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("ALPHA-1", None))
        .build()?;

    println!("Sending ALPHA-1...");
    client.send_cot_event(unit1).await?;
    println!("✓ Sent\n");

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

    // Test 2: a-f-G-U-C with contact + endpoint
    println!("Test 2: a-f-G-U-C with contact (callsign + endpoint)...");
    let unit2 = CotEventBuilder::new()
        .uid("BRAVO-1")
        .cot_type("a-f-G-U-C")
        .lat_lon(39.378000, -76.832000)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("BRAVO-1", Some("192.168.1.100:4242")))
        .build()?;

    println!("Sending BRAVO-1...");
    client.send_cot_event(unit2).await?;
    println!("✓ Sent\n");

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

    // Test 3: a-f-G-U-C with contact + track
    println!("Test 3: a-f-G-U-C with contact + track (moving unit)...");
    let unit3 = CotEventBuilder::new()
        .uid("CHARLIE-1")
        .cot_type("a-f-G-U-C")
        .lat_lon(39.379000, -76.831000)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("CHARLIE-1", Some("192.168.1.101:4242")))
        .with_track(track(15.5, 270.0)) // 15.5 m/s heading west
        .build()?;

    println!("Sending CHARLIE-1...");
    client.send_cot_event(unit3).await?;
    println!("✓ Sent\n");

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

    // Test 4: a-f-G-U-C with NO detail (minimal)
    println!("Test 4: a-f-G-U-C with NO detail fields...");
    let unit4 = CotEventBuilder::new()
        .uid("DELTA-1")
        .cot_type("a-f-G-U-C")
        .lat_lon(39.380000, -76.830000)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .build()?;

    println!("Sending DELTA-1 (no detail)...");
    println!("Detail: {:?}", unit4.detail);
    client.send_cot_event(unit4).await?;
    println!("✓ Sent\n");

    println!("================================");
    println!("✅ All 4 friendly units sent!");
    println!("================================");
    println!("\nCheck iTAK. You should see:");
    println!("  1. ALPHA-1 (with callsign)");
    println!("  2. BRAVO-1 (with callsign + endpoint)");
    println!("  3. CHARLIE-1 (with callsign + endpoint + track)");
    println!("  4. DELTA-1 (no detail - might not show!)");
    println!("\nIf units 1-3 show but 4 doesn't, then a-f-G-U-C");
    println!("requires contact information to display.");

    Ok(())
}