@tak-ps/node-cot 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tak-ps/node-cot",
3
3
  "type": "module",
4
- "version": "2.5.0",
4
+ "version": "2.7.0",
5
5
  "description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
6
6
  "main": "index.js",
7
7
  "scripts": {
@@ -11,6 +11,7 @@
11
11
  "dependencies": {
12
12
  "@turf/point-on-feature": "^6.5.0",
13
13
  "ajv": "^8.11.2",
14
+ "color": "^4.2.3",
14
15
  "protobufjs": "^7.1.2",
15
16
  "uuid": "^9.0.0",
16
17
  "xml-js": "^1.6.11"
@@ -68,10 +68,10 @@ test('XML.from_geojson - Polygon', (t) => {
68
68
  ],
69
69
  labels_on: { _attributes: { value: 'false' } },
70
70
  tog: { _attributes: { enabled: '0' } },
71
- strokeColor: { _attributes: { value: '-256' } },
72
- strokeWeight: { _attributes: { value: '3.0' } },
71
+ strokeColor: { _attributes: { value: 16776960 } },
72
+ strokeWeight: { _attributes: { value: 3 } },
73
73
  strokeStyle: { _attributes: { value: 'solid' } },
74
- fillColor: { _attributes: { value: '-1761607936' } }
74
+ fillColor: { _attributes: { value: 16776960 } }
75
75
  });
76
76
 
77
77
  t.end();
@@ -116,10 +116,9 @@ test('XML.from_geojson - LineString', (t) => {
116
116
  ],
117
117
  labels_on: { _attributes: { value: 'false' } },
118
118
  tog: { _attributes: { enabled: '0' } },
119
- strokeColor: { _attributes: { value: '-256' } },
120
- strokeWeight: { _attributes: { value: '3.0' } },
121
- strokeStyle: { _attributes: { value: 'solid' } },
122
- fillColor: { _attributes: { value: '-1761607936' } }
119
+ strokeColor: { _attributes: { value: 16776960 } },
120
+ strokeWeight: { _attributes: { value: 3 } },
121
+ strokeStyle: { _attributes: { value: 'solid' } }
123
122
  });
124
123
 
125
124
  t.end();
@@ -0,0 +1,33 @@
1
+ import test from 'tape';
2
+ import { XML } from '../index.js';
3
+
4
+ test('XML.from_geojson - Polygon Style', (t) => {
5
+ const geo = XML.from_geojson({
6
+ type: 'Feature',
7
+ properties: {
8
+
9
+ },
10
+ geometry: {
11
+ type: 'Point',
12
+ coordinates: [1.1, 2.2]
13
+ }
14
+ });
15
+
16
+ t.equals(geo.raw.event._attributes.version, '2.0');
17
+ t.equals(geo.raw.event._attributes.type, 'a-f-G');
18
+ t.equals(geo.raw.event._attributes.how, 'm-g');
19
+ t.equals(geo.raw.event._attributes.uid.length, 36);
20
+ t.equals(geo.raw.event._attributes.time.length, 24);
21
+ t.equals(geo.raw.event._attributes.start.length, 24);
22
+ t.equals(geo.raw.event._attributes.stale.length, 24);
23
+
24
+ t.deepEquals(geo.raw.event.point, {
25
+ _attributes: { lat: 2.2, lon: 1.1, hae: 0, ce: 9999999, le: 9999999 }
26
+ });
27
+
28
+ t.deepEquals(geo.raw.event.detail, {
29
+ contact: { _attributes: { callsign: 'UNKNOWN' } }
30
+ });
31
+
32
+ t.end();
33
+ });
@@ -1,29 +0,0 @@
1
- const path = require('path')
2
- const {cot, proto} = require(path.join(__dirname, '../index.js'))
3
-
4
- const run = (message) => {
5
- if (!message) {
6
- console.error('Enter a TAK message')
7
- return
8
- }
9
-
10
- const bufferMessage = typeof message !== Buffer ? Buffer.from(message, 'hex') : message
11
-
12
- if (bufferMessage[0] === 191) { // TAK message format 0xbf
13
- console.log('TAK message received')
14
- const trimmedBuffer = bufferMessage.slice(3, bufferMessage.length) // remove tak message header from content
15
- if (bufferMessage[1] === 0) { // is COT XML
16
- console.error('Enter a TAK proto message')
17
- } else if (bufferMessage[1] === 1) { // is Protobuf
18
- console.log('TAK protobuf format')
19
- const protoMessage = proto.proto2js(trimmedBuffer)
20
- const cotMessage = proto.protojs2cotjs(protoMessage)
21
- console.log(cotMessage)
22
- console.log(cot.js2xml(cotMessage))
23
- }
24
- } else { // not TAK message format
25
- console.error('Enter a TAK proto message')
26
- }
27
- }
28
-
29
- run(process.argv[2])
package/scripts/parse.js DELETED
@@ -1,34 +0,0 @@
1
- const path = require('path')
2
- const {cot, proto} = require(path.join(__dirname, '../index.js'))
3
-
4
- // https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/blob/master/commoncommo/core/impl/protobuf/protocol.txt
5
-
6
- const run = (message) => {
7
- if (!message) {
8
- console.error('Enter a TAK message')
9
- return
10
- }
11
-
12
- const bufferMessage = typeof message !== Buffer ? Buffer.from(message, 'hex') : message
13
-
14
- if (bufferMessage[0] === 191) { // TAK message format 0xbf
15
- console.log('TAK message received')
16
- const trimmedBuffer = bufferMessage.slice(3, bufferMessage.length) // remove tak message header from content
17
- if (bufferMessage[1] === 0) { // is COT XML
18
- console.log('COT XML format')
19
- console.log(cot.xml2js(trimmedBuffer)) // try parsing raw XML
20
- } else if (bufferMessage[1] === 1) { // is Protobuf
21
- console.log('TAK protobuf format')
22
- console.log(proto.proto2js(trimmedBuffer))
23
- }
24
- } else { // not TAK message format
25
- try {
26
- console.log('COT XML received')
27
- console.log(cot.xml2js(message)) // try parsing raw XML
28
- } catch (e) {
29
- console.error('Failed to parse message', e)
30
- }
31
- }
32
- }
33
-
34
- run(process.argv[2])