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!("Negotiating protocol...");
client.negotiate_protocol(1, 60).await?;
println!("✓ Protocol negotiated (protobuf mode)\n");
println!("Test 1: Sending minimal event (no detail fields)...");
let minimal = CotEventBuilder::new()
.uid("TEST-MINIMAL")
.cot_type("b-m-p-s-m") .lat_lon(39.377445, -76.832160) .hae(10.0)
.ce_le(9.9, 9.9)
.how("h-e")
.stale_minutes(5)
.build()?;
println!("Event: type={}, uid={}", minimal.r#type, minimal.uid);
println!("Detail: {:?}", minimal.detail);
client.send_cot_event(minimal).await?;
println!("✓ Sent\n");
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
println!("Test 2: Sending event with contact only...");
let with_contact = CotEventBuilder::new()
.uid("TEST-CONTACT")
.cot_type("b-m-p-s-m")
.lat_lon(39.378000, -76.832000)
.hae(10.0)
.ce_le(9.9, 9.9)
.how("h-e")
.stale_minutes(5)
.with_contact(contact("TestUser", Some("192.168.1.100:4242")))
.build()?;
println!(
"Event: type={}, uid={}",
with_contact.r#type, with_contact.uid
);
println!("Detail: {:?}", with_contact.detail);
client.send_cot_event(with_contact).await?;
println!("✓ Sent\n");
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
println!("Test 3: Sending event with status only...");
let with_status = CotEventBuilder::new()
.uid("TEST-STATUS")
.cot_type("b-m-p-s-m")
.lat_lon(39.379000, -76.831000)
.hae(10.0)
.ce_le(9.9, 9.9)
.how("h-e")
.stale_minutes(5)
.with_status(status(85))
.build()?;
println!(
"Event: type={}, uid={}",
with_status.r#type, with_status.uid
);
println!("Detail: {:?}", with_status.detail);
client.send_cot_event(with_status).await?;
println!("✓ Sent\n");
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
println!("Test 4: Sending event with precision_location...");
let with_prec = CotEventBuilder::new()
.uid("TEST-PRECISION")
.cot_type("b-m-p-s-m")
.lat_lon(39.380000, -76.830000)
.hae(10.0)
.ce_le(9.9, 9.9)
.how("h-e")
.stale_minutes(5)
.with_precision_location(precision_location("GPS", "GPS"))
.build()?;
println!("Event: type={}, uid={}", with_prec.r#type, with_prec.uid);
println!("Detail: {:?}", with_prec.detail);
client.send_cot_event(with_prec).await?;
println!("✓ Sent\n");
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
println!("Test 5: Sending event with multiple detail fields...");
let with_all = CotEventBuilder::new()
.uid("TEST-ALL")
.cot_type("b-m-p-s-m")
.lat_lon(39.381000, -76.829000)
.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()?;
println!("Event: type={}, uid={}", with_all.r#type, with_all.uid);
println!("Detail: {:?}", with_all.detail);
client.send_cot_event(with_all).await?;
println!("✓ Sent\n");
println!("=================================");
println!("✅ All 5 tests sent successfully!");
println!("=================================");
println!("\nCheck your TAK client. You should see 5 markers:");
println!(" 1. TEST-MINIMAL (no details)");
println!(" 2. TEST-CONTACT (with callsign)");
println!(" 3. TEST-STATUS (with battery)");
println!(" 4. TEST-PRECISION (with precision location)");
println!(" 5. TEST-ALL (with all three)");
println!("\nIf you don't see them, check the TAK server logs for errors.");
Ok(())
}