Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions CoT.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

DATETIME_FMT = "%Y-%m-%dT%H:%M:%SZ"


class CursorOnTarget:

def atoms(__self, unit):
@staticmethod
def atoms(unit):
timer = dt.datetime
now = timer.utcnow()
zulu = now.strftime(DATETIME_FMT)
Expand All @@ -60,6 +62,7 @@ def atoms(__self, unit):
evt_attr = {
"version": "2.0",
"uid": cot_id,
"how": "m-g",
"time": zulu,
"start": zulu,
"stale": stale,
Expand All @@ -73,21 +76,24 @@ def atoms(__self, unit):
"ce": "10", #unit["ce"],
"le": "10" #unit["le"]1
}

cot = ET.Element('event', attrib=evt_attr)
ET.SubElement(cot, 'detail')
ET.SubElement(cot,'point', attrib=pt_attr)

cot_xml = '<?xml version="1.0" standalone="yes"?>' + ET.tostring(cot)
ET.SubElement(cot, 'point', attrib=pt_attr)

cot_xml = '<?xml version="1.0"?>' + ET.tostring(cot, encoding='unicode')

return cot_xml

def pushUDP(__self, ip_address, port, cot_xml):
@staticmethod
def pushUDP(ip_address, port, cot_xml):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sent = sock.sendto(cot_xml, (ip_address, port))
sent = sock.sendto(bytes(cot_xml, 'utf-8'), (ip_address, port))
return sent

def pushTCP(__self, ip_address, port, cot_xml):
@staticmethod
def pushTCP(ip_address, port, cot_xml):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn = sock.connect((ip_address, port))
return sock.send(cot_xml)
return sock.send(bytes(cot_xml, 'utf-8'))

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ type is MIL-STD-2525 function code in CoT format (single letters separated by hy

Sample output data:
```
<?xml version="1.0" standalone="yes"?>
<?xml version="1.0"?>
<event
version="2.0"
uid="J-01334"
type="a-h-G"
how="m-g"
time="2017-10-30T11:43:38.07Z"
start="2017-10-30T11:43:38.07Z"
stale="2017-10-30T11:55:38.07Z">
stale="2017-10-30T11:55:38.07Z"
type="a-h-G">
<detail></detail>
<point
lat="30.0090027"
Expand Down
21 changes: 10 additions & 11 deletions testCoT.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
}

for i in range(0, 10):
params["lat"] = params["lat"] + i/10000.0
params["lon"] = params["lon"] + i/10000.0
print "Params:\n" + str(params)
# params["lat"] = params["lat"] + i/10000.0
# params["lon"] = params["lon"] + i/10000.0
print("Params:\n" + str(params))
cot = CoT.CursorOnTarget()
cot_xml = cot.atoms(params)

print("\nXML message:")
print(cot_xml)

print "\nXML message:"
print cot_xml

print "\nPushing to ATAK..."
print("\nPushing to ATAK...")
if ATAK_PROTO == "TCP":
sent = cot.pushTCP(ATAK_IP, ATAK_PORT, cot_xml)
else
sent = cot.pushUDP(ATAK_IP, ATAK_PORT, cot_xml)
print str(sent) + " bytes sent to " + ATAK_IP + " on port " + str(ATAK_PORT)
sent = cot.pushTCP(ATAK_IP, ATAK_PORT, cot_xml)
else:
sent = cot.pushUDP(ATAK_IP, ATAK_PORT, cot_xml)
print(str(sent) + " bytes sent to " + ATAK_IP + " on port " + str(ATAK_PORT))
time.sleep(2)