tello-custom-ip
Version:
Tello drone client with custom IP address support, forked from @0x77/tellots
47 lines • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.state = void 0;
var dgram_1 = __importDefault(require("dgram"));
var events_1 = require("events");
var constants_1 = require("../constants");
var client = dgram_1.default.createSocket('udp4'), _local = {
emitter: new events_1.EventEmitter()
};
var format = function (mapped) { return ({
pitch: mapped.pitch,
roll: mapped.roll,
yaw: mapped.yaw,
speed: { x: mapped.vgx, y: mapped.vgy, z: mapped.vgz },
temperature: { low: mapped.templ, high: mapped.temph },
tof: mapped.tof,
height: mapped.h,
battery: mapped.bat,
barometer: mapped.baro,
time: mapped.time,
acceleration: { x: mapped.agx, y: mapped.agy, z: mapped.agz }
}); };
var map = function (message) {
var mapped = message.toString()
.slice(0, -1)
.split(';')
.map(function (element) { return element.split(':'); })
// @ts-ignore
.reduce(function (acc, _a) {
var key = _a[0], value = _a[1];
acc[key] = Number(value);
return acc;
}, {});
return format(mapped);
};
client.on('message', function (message) { return _local.emitter.emit('message', map(message)); });
var bind = function () {
client.bind(constants_1.constants.ports.state);
return _local.emitter;
};
var close = function () { return client.close(); };
exports.state = { bind: bind, close: close };
exports.default = exports.state;
//# sourceMappingURL=state.js.map