UNPKG

tello-custom-ip

Version:

Tello drone client with custom IP address support, forked from @0x77/tellots

123 lines 3.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseCommandResponse = exports.parseTof = exports.parseAcceleration = exports.parseBarometer = exports.parseAttitude = exports.parseWifi = exports.parseTime = exports.parseSpeed = exports.parseTemperature = exports.parseHeight = exports.parseBattery = void 0; /** * Parse battery level string to structured response */ var parseBattery = function (batteryStr) { var value = parseInt(batteryStr, 10); return { value: value }; }; exports.parseBattery = parseBattery; /** * Parse height string to structured response */ var parseHeight = function (heightStr) { var value = parseInt(heightStr.replace('dm', ''), 10); return { value: value, unit: 'dm' }; }; exports.parseHeight = parseHeight; /** * Parse temperature string to structured response */ var parseTemperature = function (tempStr) { var match = tempStr.match(/(\d+)~(\d+)C/); if (match && match.length >= 3) { return { min: parseInt(match[1], 10), max: parseInt(match[2], 10), unit: '°C' }; } return { min: 0, max: 0, unit: '°C' }; }; exports.parseTemperature = parseTemperature; /** * Parse speed string to structured response */ var parseSpeed = function (speedStr) { var value = parseFloat(speedStr); return { value: value, unit: 'cm/s' }; }; exports.parseSpeed = parseSpeed; /** * Parse time string to structured response */ var parseTime = function (timeStr) { var value = parseInt(timeStr.replace('s', ''), 10); return { value: value, unit: 's' }; }; exports.parseTime = parseTime; /** * Parse wifi signal strength to structured response */ var parseWifi = function (wifiStr) { var value = parseInt(wifiStr, 10); return { value: value, unit: '%' }; }; exports.parseWifi = parseWifi; /** * Parse attitude string to structured response */ var parseAttitude = function (attitudeStr) { var parts = attitudeStr.split(';'); var result = { pitch: 0, roll: 0, yaw: 0, unit: '°' }; parts.forEach(function (part) { if (part.includes('pitch:')) { result.pitch = parseInt(part.replace('pitch:', ''), 10); } else if (part.includes('roll:')) { result.roll = parseInt(part.replace('roll:', ''), 10); } else if (part.includes('yaw:')) { result.yaw = parseInt(part.replace('yaw:', ''), 10); } }); return result; }; exports.parseAttitude = parseAttitude; /** * Parse barometer string to structured response */ var parseBarometer = function (baroStr) { var value = parseFloat(baroStr); return { value: value, unit: 'm' }; }; exports.parseBarometer = parseBarometer; /** * Parse acceleration string to structured response */ var parseAcceleration = function (accelStr) { var parts = accelStr.split(';'); var result = { x: 0, y: 0, z: 0, unit: 'mG' }; parts.forEach(function (part) { if (part.includes('agx:')) { result.x = parseFloat(part.replace('agx:', '')); } else if (part.includes('agy:')) { result.y = parseFloat(part.replace('agy:', '')); } else if (part.includes('agz:')) { result.z = parseFloat(part.replace('agz:', '')); } }); return result; }; exports.parseAcceleration = parseAcceleration; /** * Parse ToF (Time of Flight) string to structured response */ var parseTof = function (tofStr) { var value = parseInt(tofStr.replace('mm', ''), 10); return { value: value, unit: 'mm' }; }; exports.parseTof = parseTof; /** * Parse boolean command response * Returns true for "ok", false for any other response */ var parseCommandResponse = function (response) { return response.trim().toLowerCase() === "ok"; }; exports.parseCommandResponse = parseCommandResponse; //# sourceMappingURL=parsers.js.map