takproto 0.4.2

Rust library for TAK (Team Awareness Kit) Protocol - send CoT messages to TAK servers with mTLS support
Documentation
use std::time::{SystemTime, UNIX_EPOCH};
use takproto::proto::{CotEvent, Detail};
use takproto::TakClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Parse command line arguments
    let args: Vec<String> = std::env::args().collect();
    let server_addr = if args.len() > 1 {
        args[1].as_str()
    } else {
        "127.0.0.1:8087"
    };

    println!("Connecting to TAK server at {}...", server_addr);

    // Connect to the TAK server
    let mut client = TakClient::connect(server_addr).await?;

    println!("Connected successfully!");

    // Get current time in milliseconds since Unix epoch
    let now_ms = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as u64;

    // Create a position report CoT event
    // Type "a-f-G-U-C" means: atom-friendly-Ground-Unit-Combat
    let event = CotEvent {
        r#type: "a-f-G-U-C".to_string(),        // Friendly ground unit
        uid: "RUST-TAK-CLIENT-001".to_string(), // Unique identifier
        send_time: now_ms,
        start_time: now_ms,
        stale_time: now_ms + 60_000, // Valid for 60 seconds
        how: "m-g".to_string(),      // Machine generated

        // Position (San Francisco coordinates as example)
        lat: 37.7749,
        lon: -122.4194,
        hae: 10.0, // Height above ellipsoid in meters
        ce: 9.9,   // Circular error (accuracy)
        le: 9.9,   // Linear error (altitude accuracy)

        // Optional detail information
        detail: Some(Detail {
            xml_detail: r#"<contact callsign="RustClient" endpoint="*:-1:stcp"/>"#.to_string(),
            ..Default::default()
        }),

        ..Default::default()
    };

    println!("Sending CoT event...");
    println!("  UID: {}", event.uid);
    println!("  Type: {}", event.r#type);
    println!("  Position: {}, {}", event.lat, event.lon);

    // Send the event
    client.send_cot_event(event).await?;

    println!("Event sent successfully!");

    // Close the connection
    client.close().await?;

    Ok(())
}