"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Warp10 = void 0;
const logger_1 = require("./logger");
const UNITS = {
h: 'cm', x: 'cm', y: 'cm', z: 'cm', baro: 'cm', tof: 'cm',
templ: 'celcius', temph: 'celcius',
pitch: 'deg', roll: 'deg', yaw: 'deg',
agx: '0.001g', agy: '0.001g', agz: '0.001g',
vgx: 'cm/s', vgy: 'cm/s', vgz: 'cm/s',
bat: 'percent', time: 'second'
};
/** Forwards OSD telemetry data to a Warp 10 time-series database. */
class Warp10 {
/** @param params - Warp 10 endpoint URL and write token. */
constructor(params) {
this.url = params.url;
this.token = params.writeToken;
}
/** Push a telemetry frame as Warp 10 GTS input. Skips `mpry` and `mid` fields. */
pushData(osdData) {
const timestamp = Date.now() * 1000;
const lines = Object.keys(osdData)
.filter(k => k && k !== 'mpry' && k !== 'mid')
.map(k => `${timestamp}// ryze.tello.${k}{unit=${encodeURIComponent(UNITS[k])}} ${osdData[k]}`)
.join('\n');
logger_1.Logger.info('[Warp10]', 'pushData', lines);
fetch(this.url + '/update', {
method: 'POST',
headers: {
'X-Warp10-Token': this.token,
'Transfer-Encoding': 'chunked'
},
body: lines
});
}
}
exports.Warp10 = Warp10;
//# sourceMappingURL=warp10.js.map