From 31bc78b8459ddc27ab7bacf6dd17171aee2ca10e Mon Sep 17 00:00:00 2001 From: Lewis Date: Sun, 12 Jul 2020 15:56:39 +0100 Subject: [PATCH 1/6] add "how" to the event how is a required field --- CoT.py | 1 + 1 file changed, 1 insertion(+) diff --git a/CoT.py b/CoT.py index cfe9dd3..4ab8bd2 100644 --- a/CoT.py +++ b/CoT.py @@ -60,6 +60,7 @@ def atoms(__self, unit): evt_attr = { "version": "2.0", "uid": cot_id, + "how": "m-g", "time": zulu, "start": zulu, "stale": stale, From 2567a5490e19a2cf50d7c88e7d3ea0fcbe92c668 Mon Sep 17 00:00:00 2001 From: Lewis Date: Sun, 12 Jul 2020 16:04:24 +0100 Subject: [PATCH 2/6] Update for Python 3 Actions taken based on PEP8 warnings. Fixed the xml converting to string and back to bytes for sending. --- CoT.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/CoT.py b/CoT.py index 4ab8bd2..e36ae73 100644 --- a/CoT.py +++ b/CoT.py @@ -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) @@ -74,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 = '' + ET.tostring(cot) + ET.SubElement(cot, 'point', attrib=pt_attr) + + cot_xml = '' + 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')) From 8e15038835ac7cace516cf25139b197872173d5c Mon Sep 17 00:00:00 2001 From: Lewis Date: Sun, 12 Jul 2020 16:14:51 +0100 Subject: [PATCH 3/6] Update to Python 3 Chances made in accordance to PEP8 and remved the converting of the Lat and Long due to it causing drift --- testCoT.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/testCoT.py b/testCoT.py index 3348dec..e82c33d 100644 --- a/testCoT.py +++ b/testCoT.py @@ -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) From 1e607021bdb661efba8b02fc5b3a81b1bdca2b98 Mon Sep 17 00:00:00 2001 From: Lewis Date: Sun, 12 Jul 2020 16:23:12 +0100 Subject: [PATCH 4/6] add how to example Added how and moved type to after stale. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46c437c..77d512c 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ Sample output data: + stale="2017-10-30T11:55:38.07Z" + type="a-h-G"> Date: Sun, 12 Jul 2020 16:24:23 +0100 Subject: [PATCH 5/6] Fix Spacing --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77d512c..6a47021 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ Sample output data: + type="a-h-G"> Date: Sun, 12 Jul 2020 16:25:19 +0100 Subject: [PATCH 6/6] Remove standalone Not needed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a47021..123860b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ type is MIL-STD-2525 function code in CoT format (single letters separated by hy Sample output data: ``` - +