make kestrel a tak server, so that it can send and receive pois as cots data
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
This commit is contained in:
54
test/helpers/fakeAtakClient.js
Normal file
54
test/helpers/fakeAtakClient.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Build a TAK Protocol stream frame: 0xBF, varint payload length, payload.
|
||||
* @param {string|Buffer} payload - UTF-8 payload (e.g. CoT XML)
|
||||
* @returns {Buffer} TAK stream frame buffer.
|
||||
*/
|
||||
export function buildTakFrame(payload) {
|
||||
const buf = Buffer.isBuffer(payload) ? payload : Buffer.from(payload, 'utf8')
|
||||
let n = buf.length
|
||||
const varint = []
|
||||
while (true) {
|
||||
const byte = n & 0x7F
|
||||
n >>>= 7
|
||||
if (n === 0) {
|
||||
varint.push(byte)
|
||||
break
|
||||
}
|
||||
varint.push(byte | 0x80)
|
||||
}
|
||||
return Buffer.concat([Buffer.from([0xBF]), Buffer.from(varint), buf])
|
||||
}
|
||||
|
||||
/**
|
||||
* Build CoT XML for a position update (event + point + optional contact).
|
||||
* @param {object} opts - Position options
|
||||
* @param {string} opts.uid - Entity UID
|
||||
* @param {number} opts.lat - Latitude
|
||||
* @param {number} opts.lon - Longitude
|
||||
* @param {string} [opts.callsign] - Optional callsign
|
||||
* @param {string} [opts.type] - Optional event type (default a-f-G)
|
||||
* @returns {string} CoT XML string.
|
||||
*/
|
||||
export function buildPositionCotXml({ uid, lat, lon, callsign, type = 'a-f-G' }) {
|
||||
const contact = callsign ? `<detail><contact callsign="${escapeXml(callsign)}"/></detail>` : ''
|
||||
return `<event uid="${escapeXml(uid)}" type="${escapeXml(type)}"><point lat="${lat}" lon="${lon}"/>${contact}</event>`
|
||||
}
|
||||
|
||||
/**
|
||||
* Build CoT XML for auth (username/password).
|
||||
* @param {object} opts - Auth options
|
||||
* @param {string} opts.username - Username
|
||||
* @param {string} opts.password - Password
|
||||
* @returns {string} CoT XML string.
|
||||
*/
|
||||
export function buildAuthCotXml({ username, password }) {
|
||||
return `<event><detail><auth username="${escapeXml(username)}" password="${escapeXml(password)}"/></detail></event>`
|
||||
}
|
||||
|
||||
function escapeXml(s) {
|
||||
return String(s)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
}
|
||||
Reference in New Issue
Block a user