UNPKG

swarms

Version:

The ultimate node.js library for controlling Bitcraze Crazyflie 2.0 drones

256 lines 8.06 kB
"use strict"; /** * @file Constants used throughout the library */ Object.defineProperty(exports, "__esModule", { value: true }); // import * as ieee754 from 'ieee754'; const utils_1 = require("./utils"); /** * Crazyradio constants * These values were taken from (https://wiki.bitcraze.io/doc:crazyradio:usb:index) */ exports.CRAZYRADIO = { VID: 0x1915, PID: 0x7777 // Product ID of dongle }; var DATA_RATES; (function (DATA_RATES) { DATA_RATES[DATA_RATES["250K"] = 0] = "250K"; DATA_RATES[DATA_RATES["1M"] = 1] = "1M"; DATA_RATES[DATA_RATES["2M"] = 2] = "2M"; })(DATA_RATES = exports.DATA_RATES || (exports.DATA_RATES = {})); function GET_DATA_RATE(targetRate) { for (const rate of utils_1.properEnumKeys(DATA_RATES)) { if (DATA_RATES[rate] === targetRate) { return rate; } } return null; } exports.GET_DATA_RATE = GET_DATA_RATE; var RADIO_POWERS; (function (RADIO_POWERS) { RADIO_POWERS[RADIO_POWERS["-18dBm"] = 0] = "-18dBm"; RADIO_POWERS[RADIO_POWERS["-12dBm"] = 1] = "-12dBm"; RADIO_POWERS[RADIO_POWERS["-6dBm"] = 2] = "-6dBm"; RADIO_POWERS[RADIO_POWERS["0dBm"] = 3] = "0dBm"; })(RADIO_POWERS = exports.RADIO_POWERS || (exports.RADIO_POWERS = {})); function GET_RADIO_POWER(targetPower) { for (const power of utils_1.properEnumKeys(RADIO_POWERS)) { if (RADIO_POWERS[power] === targetPower) { return power; } } return null; } exports.GET_RADIO_POWER = GET_RADIO_POWER; exports.BM_REQUEST_TYPE = 0x40; exports.VENDOR_REQUESTS = { SET_RADIO_CHANNEL: 0x01, SET_RADIO_ADDRESS: 0x02, SET_DATA_RATE: 0x03, SET_RADIO_POWER: 0x04, SET_RADIO_ARD: 0x05, SET_RADIO_ARC: 0x06, ACK_ENABLE: 0x10, SET_CONT_CARRIER: 0x20, SCAN_CHANNELS: 0x21, LAUNCH_BOOTLOADER: 0xFF }; /** * Crazyflie Real-Time Protocol (CRTP) * These values were taken from (https://wiki.bitcraze.io/projects:crazyflie:crtp) */ exports.PORTS = { CONSOLE: 0, PARAMETERS: 2, COMMANDER: 3, LOGGING: 5, COMMANDER_GENERIC: 7, LINK_LAYER: 15 }; exports.MAX_PAYLOAD_SIZE = 31; exports.CHANNELS = { TOC: 0, // (https://wiki.bitcraze.io/doc:crazyflie:crtp:param#parameters) PARAM: { READ: 1, WRITE: 2, MISC: 3 // Miscellaneous commands }, // (https://wiki.bitcraze.io/doc:crazyflie:crtp:log#communication_protocol) LOG: { CTRL: 1, DATA: 2 // Used to send log data from the Crazyflie to the client } }; exports.COMMANDS = { // TOC commands for both logging and parameters (you just change the port) // (https://wiki.bitcraze.io/doc:crazyflie:crtp:log#table_of_content_access) TOC: { GET_ITEM: 0, GET_INFO: 1 // Get information about the TOC including length and checksum for caching }, // (https://wiki.bitcraze.io/doc:crazyflie:crtp:param#misc_commands) PARAM_MISC: { SET_BY_NAME: 0 }, // (https://wiki.bitcraze.io/doc:crazyflie:crtp:log#log_control) LOG_CTRL: { CREATE_BLOCK: 0, APPEND_BLOCK: 1, DELETE_BLOCK: 2, START_BLOCK: 3, STOP_BLOCK: 4, RESET_LOG: 5 }, // (https://wiki.bitcraze.io/doc:crazyflie:crtp:generic_setpoint) // (https://github.com/bitcraze/crazyflie-lib-python/blob/master/cflib/crazyflie/commander.py) COMMANDER_GENERIC: { STOP: 0, VELOCITY_WORLD: 1, Z_DISTANCE: 2, HOVER: 5 } }; /** * Parameter types * (https://wiki.bitcraze.io/doc:crazyflie:crtp:param#toc_access) */ var PARAM_TYPES; (function (PARAM_TYPES) { PARAM_TYPES[PARAM_TYPES["int8"] = 0] = "int8"; PARAM_TYPES[PARAM_TYPES["int16"] = 1] = "int16"; PARAM_TYPES[PARAM_TYPES["int32"] = 2] = "int32"; PARAM_TYPES[PARAM_TYPES["int64"] = 3] = "int64"; PARAM_TYPES[PARAM_TYPES["fp16"] = 5] = "fp16"; PARAM_TYPES[PARAM_TYPES["float"] = 6] = "float"; PARAM_TYPES[PARAM_TYPES["double"] = 7] = "double"; PARAM_TYPES[PARAM_TYPES["uInt8"] = 8] = "uInt8"; PARAM_TYPES[PARAM_TYPES["uInt16"] = 9] = "uInt16"; PARAM_TYPES[PARAM_TYPES["uInt32"] = 10] = "uInt32"; PARAM_TYPES[PARAM_TYPES["uInt64"] = 11] = "uInt64"; })(PARAM_TYPES = exports.PARAM_TYPES || (exports.PARAM_TYPES = {})); function GET_PARAM_TYPE(typeValue) { for (const type of utils_1.properEnumKeys(PARAM_TYPES)) { if (PARAM_TYPES[type] === typeValue) { return type; } } return null; } exports.GET_PARAM_TYPE = GET_PARAM_TYPE; /** * Logging types * (https://wiki.bitcraze.io/projects:crazyflie:firmware:log#firmware_usage) */ var LOGGING_TYPES; (function (LOGGING_TYPES) { LOGGING_TYPES[LOGGING_TYPES["uInt8"] = 1] = "uInt8"; LOGGING_TYPES[LOGGING_TYPES["uInt16"] = 2] = "uInt16"; LOGGING_TYPES[LOGGING_TYPES["uInt32"] = 3] = "uInt32"; LOGGING_TYPES[LOGGING_TYPES["int8"] = 4] = "int8"; LOGGING_TYPES[LOGGING_TYPES["int16"] = 5] = "int16"; LOGGING_TYPES[LOGGING_TYPES["int32"] = 6] = "int32"; LOGGING_TYPES[LOGGING_TYPES["float"] = 7] = "float"; LOGGING_TYPES[LOGGING_TYPES["fp16"] = 8] = "fp16"; })(LOGGING_TYPES = exports.LOGGING_TYPES || (exports.LOGGING_TYPES = {})); function GET_LOGGING_TYPE(typeValue) { for (const type of utils_1.properEnumKeys(LOGGING_TYPES)) { if (LOGGING_TYPES[type] === typeValue) { return type; } } return null; } exports.GET_LOGGING_TYPE = GET_LOGGING_TYPE; /** * Possible logging errors * (https://wiki.bitcraze.io/projects:crazyflie:firmware:comm_protocol#variable_format) */ exports.BLOCK_ERRORS = { 2: { name: 'ENOENT', message: 'Block or variable not found' }, 7: { name: 'E2BIG', message: 'Log block is too long' }, 8: { name: 'ENOEXEC', message: 'Unknown command received' }, 12: { name: 'ENOMEM', message: 'No memory to allocate Log Block or Log Item' } }; /** * Buffers used for things */ exports.BUFFERS = { NOTHING: Buffer.alloc(0), SOMETHING: Buffer.alloc(1) // Single byte when scanning for Crazyflies }; /** * Factory to return read and write functions for a buffer * We need to bind the `this` context to the functions otherwise it won't work * @TODO Implement i64/u64/fp16 functions and get rid of Partial<T> */ function BUFFER_TYPES(buffer) { return { double: { size: 8, read: buffer.readDoubleLE.bind(buffer), write: buffer.writeDoubleLE.bind(buffer) }, float: { size: 4, read: buffer.readFloatLE.bind(buffer), write: buffer.writeFloatLE.bind(buffer) }, // Also used for writing just a plain 'ol byte int8: { size: 1, read: buffer.readInt8.bind(buffer), write: buffer.writeInt8.bind(buffer) }, int16: { size: 2, read: buffer.readInt16LE.bind(buffer), write: buffer.writeInt16LE.bind(buffer) }, int32: { size: 4, read: buffer.readInt32LE.bind(buffer), write: buffer.writeInt32LE.bind(buffer) }, // int64: { // /** @todo Implement 64-bit unsigned integer read and write functions */ // }, uInt8: { size: 1, read: buffer.readUInt8.bind(buffer), write: buffer.writeUInt8.bind(buffer) }, uInt16: { size: 2, read: buffer.readUInt16LE.bind(buffer), write: buffer.writeUInt16LE.bind(buffer) }, uInt32: { size: 4, read: buffer.readUInt32LE.bind(buffer), write: buffer.writeUInt32LE.bind(buffer) } // uInt64: { // /** @todo Implement 64-bit unsigned integer read and write functions */ // }, // fp16: { // /** @todo Implement fp16 read and write functions */ // } }; } exports.BUFFER_TYPES = BUFFER_TYPES; //# sourceMappingURL=constants.js.map