CoT Event Construction
Constructs a validated CoT event struct from individual field values. All field validation is applied — invalid inputs throw SQL errors.
| Parameter | Type | Required | Notes |
|---|---|---|---|
| uid | VARCHAR | Yes | Unique identifier for this event/sender |
| type | VARCHAR | Yes | CoT type string (dot-notation e.g. a-f-G-U-C) |
| lat | DOUBLE | Yes | Latitude ∈ [-90, 90] |
| lon | DOUBLE | Yes | Longitude ∈ [-180, 180] |
| hae | DOUBLE | No | Height above ellipsoid (m). NULL → 9999999.0 |
| ce | DOUBLE | No | Circular error (m). NULL → 9999999.0 |
| le | DOUBLE | No | Linear error (m). NULL → 9999999.0 |
| time | TIMESTAMPTZ | Yes | Event time (UTC) |
| start | TIMESTAMPTZ | Yes | Valid start time |
| stale | TIMESTAMPTZ | Yes | Expiry time. Must be > time. |
SELECT cot_event(
'UNIT-001', cot_type('a','f','G-U-C'),
34.0522, -118.2437, 71.0, 10.0, 10.0,
now(), now(), now() + INTERVAL '5 min'
);
Builds a MIL-STD-2525B–compatible CoT type string in dot-notation from its three component parts.
| Parameter | Type | Examples |
|---|---|---|
| affiliation | VARCHAR | a=atom, b=bits |
| battle_dimension | VARCHAR | f=friendly, h=hostile, n=neutral |
| function_id | VARCHAR | G-U-C=ground unit combat |
SELECT cot_type('a', 'f', 'G-U-C'); -- → 'a-f-G-U-C'
SELECT cot_type('a', 'h', 'G'); -- → 'a-h-G' (hostile ground)
SELECT cot_type('a', 'n', 'A'); -- → 'a-n-A' (neutral aircraft)
Constructs a Detail_Builder struct from variadic key-value pairs. Must receive an even number of arguments. Attach the result to a cot_event via struct_update(event, detail := cot_detail(...)).
SELECT cot_detail(
'callsign', 'ALPHA-1',
'battery', '87',
'group', 'Cyan'
);
Serialization
Serializes a CoT event struct to a UTF-8 XML string conforming to CoT base schema version 2.0. Includes XML declaration, all required attributes on <event>, and a <point> child element. If the event has a detail field, a <detail> block is appended.
SELECT cot_to_xml(cot_event(...));
Serializes a CoT event to a TAK-framed Protocol Buffers binary blob. The framing header consists of magic byte 0xbf followed by a varint-encoded payload length. Detail fields are encoded in the xdetail field as an XML fragment string.
Protobuf encoding is designed and specified but not yet implemented in the current MVP. Accepting tak_set_format('protobuf') is the currently implemented behavior.
Sets the active serialization format for the current session. Valid values: 'xml', 'protobuf'. Any other value raises an error.
SELECT tak_set_format('protobuf');
SELECT tak_set_format('xml'); -- revert
Configuration
__tak_configStores TAK Server connection settings. Protocol must be one of tcp, tcp+tls, udp. Port must be in [1, 65535].
SELECT tak_configure('tak.example.mil', 8089, 'tcp+tls');
__tak_configStores PEM-encoded certificate material for mTLS. Both client_cert and client_key must be non-NULL and non-empty when calling this function.
SELECT tak_configure_tls(
read_text('client.pem'),
read_text('client.key'),
read_text('ca.pem')
);
Returns all configuration entries as a two-column table. Certificate values are masked to the first 32 characters followed by ....
Removes all entries from __tak_config. Returns true on success.
Connection Management
Establishes a TCP or TCP+TLS connection using the active configuration. Performs mTLS handshake if certificate material is configured. Returns a status string on success; throws on failure.
Closes the active connection and releases all resources. Returns true if a connection was open, false if already disconnected.
Returns the current connection state. state is one of connected, disconnected, or error. last_error is NULL unless the last operation failed.
Transmission
Serializes the event to the configured format (XML or protobuf) and sends it over the active connection. Returns the number of bytes written to the socket. Throws if not connected.
SELECT tak_send(cot_event(...)); -- → 248 (bytes sent)
Sends a list of CoT events sequentially. Returns one result row per input event. A transmission error on one row sets its status to error and populates error_message, but does not stop processing of subsequent events.
| Output column | Type | Description |
|---|---|---|
| index | BIGINT | 0-based position in input list |
| uid | VARCHAR | UID from the CoT event struct |
| status | VARCHAR | ok or error |
| error_message | VARCHAR | NULL on success; error details on failure |
GIS / Spatial
Converts a DuckDB GEOMETRY value to a CoT event struct. For POINT: extracts X=lon, Y=lat. For LINESTRING/POLYGON: uses centroid and encodes original shape as WKT in a <shape> detail element.
Executes query, expects a result column named geom of type GEOMETRY, translates each row to a CoT event via cot_from_geometry, and sends them. Returns the same result shape as tak_send_batch.
Logging
Returns the most recent limit entries from the in-memory ring-buffer (capacity: 10,000). Entries are ordered oldest-first. Levels: INFO, WARN, ERROR.
SELECT * FROM tak_log(); -- last 100
SELECT * FROM tak_log(500); -- last 500
SELECT * FROM tak_log(10000); -- entire buffer