Rework Super Expo Rate Implementation // On the fly Rc Expo
[betaflight.git] / src / main / io / serial_cli.c
blob05aefaa7ac1e03de492efcd8aad3df0ffa0ade4f
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <stdarg.h>
22 #include <string.h>
23 #include <math.h>
24 #include <ctype.h>
26 #include "platform.h"
27 #include "scheduler.h"
28 #include "version.h"
29 #include "debug.h"
31 #include "build_config.h"
33 #include "common/axis.h"
34 #include "common/maths.h"
35 #include "common/color.h"
36 #include "common/typeconversion.h"
38 #include "drivers/system.h"
40 #include "drivers/sensor.h"
41 #include "drivers/accgyro.h"
42 #include "drivers/compass.h"
44 #include "drivers/serial.h"
45 #include "drivers/bus_i2c.h"
46 #include "drivers/gpio.h"
47 #include "drivers/timer.h"
48 #include "drivers/pwm_rx.h"
49 #include "drivers/sdcard.h"
50 #include "drivers/gyro_sync.h"
52 #include "drivers/buf_writer.h"
54 #include "io/escservo.h"
55 #include "io/gps.h"
56 #include "io/gimbal.h"
57 #include "io/rc_controls.h"
58 #include "io/serial.h"
59 #include "io/ledstrip.h"
60 #include "io/flashfs.h"
61 #include "io/beeper.h"
62 #include "io/asyncfatfs/asyncfatfs.h"
63 #include "io/vtx.h"
65 #include "rx/rx.h"
66 #include "rx/spektrum.h"
68 #include "sensors/battery.h"
69 #include "sensors/boardalignment.h"
70 #include "sensors/sensors.h"
71 #include "sensors/acceleration.h"
72 #include "sensors/gyro.h"
73 #include "sensors/compass.h"
74 #include "sensors/barometer.h"
76 #include "flight/pid.h"
77 #include "flight/imu.h"
78 #include "flight/mixer.h"
79 #include "flight/navigation.h"
80 #include "flight/failsafe.h"
82 #include "telemetry/telemetry.h"
83 #include "telemetry/frsky.h"
85 #include "config/runtime_config.h"
86 #include "config/config.h"
87 #include "config/config_profile.h"
88 #include "config/config_master.h"
90 #include "common/printf.h"
92 #include "serial_cli.h"
94 // FIXME remove this for targets that don't need a CLI. Perhaps use a no-op macro when USE_CLI is not enabled
95 // signal that we're in cli mode
96 uint8_t cliMode = 0;
98 #ifdef USE_CLI
100 extern uint16_t cycleTime; // FIXME dependency on mw.c
102 void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort);
104 static serialPort_t *cliPort;
105 static bufWriter_t *cliWriter;
106 static uint8_t cliWriteBuffer[sizeof(*cliWriter) + 16];
108 static void cliAux(char *cmdline);
109 static void cliRxFail(char *cmdline);
110 static void cliAdjustmentRange(char *cmdline);
111 static void cliMotorMix(char *cmdline);
112 static void cliDefaults(char *cmdline);
113 static void cliDump(char *cmdLine);
114 void cliDumpProfile(uint8_t profileIndex);
115 void cliDumpRateProfile(uint8_t rateProfileIndex) ;
116 static void cliExit(char *cmdline);
117 static void cliFeature(char *cmdline);
118 static void cliMotor(char *cmdline);
119 static void cliPlaySound(char *cmdline);
120 static void cliProfile(char *cmdline);
121 static void cliRateProfile(char *cmdline);
122 static void cliReboot(void);
123 static void cliSave(char *cmdline);
124 static void cliSerial(char *cmdline);
125 #ifndef SKIP_SERIAL_PASSTHROUGH
126 static void cliSerialPassthrough(char *cmdline);
127 #endif
129 #ifdef USE_SERVOS
130 static void cliServo(char *cmdline);
131 static void cliServoMix(char *cmdline);
132 #endif
134 static void cliSet(char *cmdline);
135 static void cliGet(char *cmdline);
136 static void cliStatus(char *cmdline);
137 #ifndef SKIP_TASK_STATISTICS
138 static void cliTasks(char *cmdline);
139 #endif
140 static void cliVersion(char *cmdline);
141 static void cliRxRange(char *cmdline);
143 #ifdef GPS
144 static void cliGpsPassthrough(char *cmdline);
145 #endif
147 static void cliHelp(char *cmdline);
148 static void cliMap(char *cmdline);
150 #ifdef LED_STRIP
151 static void cliLed(char *cmdline);
152 static void cliColor(char *cmdline);
153 #endif
155 #ifndef USE_QUAD_MIXER_ONLY
156 static void cliMixer(char *cmdline);
157 #endif
159 #ifdef USE_FLASHFS
160 static void cliFlashInfo(char *cmdline);
161 static void cliFlashErase(char *cmdline);
162 #ifdef USE_FLASH_TOOLS
163 static void cliFlashWrite(char *cmdline);
164 static void cliFlashRead(char *cmdline);
165 #endif
166 #endif
168 #ifdef VTX
169 static void cliVtx(char *cmdline);
170 #endif
172 #ifdef USE_SDCARD
173 static void cliSdInfo(char *cmdline);
174 #endif
176 #ifdef BEEPER
177 static void cliBeeper(char *cmdline);
178 #endif
180 // buffer
181 static char cliBuffer[48];
182 static uint32_t bufferIndex = 0;
184 #ifndef USE_QUAD_MIXER_ONLY
185 // sync this with mixerMode_e
186 static const char * const mixerNames[] = {
187 "TRI", "QUADP", "QUADX", "BI",
188 "GIMBAL", "Y6", "HEX6",
189 "FLYING_WING", "Y4", "HEX6X", "OCTOX8", "OCTOFLATP", "OCTOFLATX",
190 "AIRPLANE", "HELI_120_CCPM", "HELI_90_DEG", "VTAIL4",
191 "HEX6H", "PPM_TO_SERVO", "DUALCOPTER", "SINGLECOPTER",
192 "ATAIL4", "CUSTOM", "CUSTOMAIRPLANE", "CUSTOMTRI", "QUADX1234", NULL
194 #endif
196 // sync this with features_e
197 static const char * const featureNames[] = {
198 "RX_PPM", "VBAT", "INFLIGHT_ACC_CAL", "RX_SERIAL", "MOTOR_STOP",
199 "SERVO_TILT", "SOFTSERIAL", "GPS", "FAILSAFE",
200 "SONAR", "TELEMETRY", "CURRENT_METER", "3D", "RX_PARALLEL_PWM",
201 "RX_MSP", "RSSI_ADC", "LED_STRIP", "DISPLAY", "ONESHOT125",
202 "BLACKBOX", "CHANNEL_FORWARDING", "TRANSPONDER", "AIRMODE", "SUPEREXPO",
203 NULL
206 // sync this with rxFailsafeChannelMode_e
207 static const char rxFailsafeModeCharacters[] = "ahs";
209 static const rxFailsafeChannelMode_e rxFailsafeModesTable[RX_FAILSAFE_TYPE_COUNT][RX_FAILSAFE_MODE_COUNT] = {
210 { RX_FAILSAFE_MODE_AUTO, RX_FAILSAFE_MODE_HOLD, RX_FAILSAFE_MODE_INVALID },
211 { RX_FAILSAFE_MODE_INVALID, RX_FAILSAFE_MODE_HOLD, RX_FAILSAFE_MODE_SET }
214 #ifndef CJMCU
215 // sync this with sensors_e
216 static const char * const sensorTypeNames[] = {
217 "GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
220 #define SENSOR_NAMES_MASK (SENSOR_GYRO | SENSOR_ACC | SENSOR_BARO | SENSOR_MAG)
222 static const char * const sensorHardwareNames[4][11] = {
223 { "", "None", "MPU6050", "L3G4200D", "MPU3050", "L3GD20", "MPU6000", "MPU6500", "FAKE", NULL },
224 { "", "None", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "FAKE", NULL },
225 { "", "None", "BMP085", "MS5611", "BMP280", NULL },
226 { "", "None", "HMC5883", "AK8975", "AK8963", NULL }
228 #endif
230 typedef struct {
231 const char *name;
232 #ifndef SKIP_CLI_COMMAND_HELP
233 const char *description;
234 const char *args;
235 #endif
236 void (*func)(char *cmdline);
237 } clicmd_t;
239 #ifndef SKIP_CLI_COMMAND_HELP
240 #define CLI_COMMAND_DEF(name, description, args, method) \
242 name , \
243 description , \
244 args , \
245 method \
247 #else
248 #define CLI_COMMAND_DEF(name, description, args, method) \
250 name, \
251 method \
253 #endif
255 // should be sorted a..z for bsearch()
256 const clicmd_t cmdTable[] = {
257 CLI_COMMAND_DEF("adjrange", "configure adjustment ranges", NULL, cliAdjustmentRange),
258 CLI_COMMAND_DEF("aux", "configure modes", NULL, cliAux),
259 #ifdef LED_STRIP
260 CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
261 #endif
262 CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", NULL, cliDefaults),
263 CLI_COMMAND_DEF("dump", "dump configuration",
264 "[master|profile]", cliDump),
265 CLI_COMMAND_DEF("exit", NULL, NULL, cliExit),
266 CLI_COMMAND_DEF("feature", "configure features",
267 "list\r\n"
268 "\t<+|->[name]", cliFeature),
269 #ifdef USE_FLASHFS
270 CLI_COMMAND_DEF("flash_erase", "erase flash chip", NULL, cliFlashErase),
271 CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL, cliFlashInfo),
272 #ifdef USE_FLASH_TOOLS
273 CLI_COMMAND_DEF("flash_read", NULL, "<length> <address>", cliFlashRead),
274 CLI_COMMAND_DEF("flash_write", NULL, "<address> <message>", cliFlashWrite),
275 #endif
276 #endif
277 CLI_COMMAND_DEF("get", "get variable value",
278 "[name]", cliGet),
279 #ifdef GPS
280 CLI_COMMAND_DEF("gpspassthrough", "passthrough gps to serial", NULL, cliGpsPassthrough),
281 #endif
282 CLI_COMMAND_DEF("help", NULL, NULL, cliHelp),
283 #ifdef LED_STRIP
284 CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed),
285 #endif
286 CLI_COMMAND_DEF("map", "configure rc channel order",
287 "[<map>]", cliMap),
288 #ifndef USE_QUAD_MIXER_ONLY
289 CLI_COMMAND_DEF("mixer", "configure mixer",
290 "list\r\n"
291 "\t<name>", cliMixer),
292 #endif
293 CLI_COMMAND_DEF("mmix", "custom motor mixer", NULL, cliMotorMix),
294 CLI_COMMAND_DEF("motor", "get/set motor",
295 "<index> [<value>]", cliMotor),
296 CLI_COMMAND_DEF("play_sound", NULL,
297 "[<index>]\r\n", cliPlaySound),
298 CLI_COMMAND_DEF("profile", "change profile",
299 "[<index>]", cliProfile),
300 CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
301 CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange),
302 CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFail),
303 CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
304 CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
305 #ifndef SKIP_SERIAL_PASSTHROUGH
306 CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port",
307 "<id> [baud] [mode] : passthrough to serial",
308 cliSerialPassthrough),
309 #endif
310 #ifdef USE_SERVOS
311 CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
312 #endif
313 CLI_COMMAND_DEF("set", "change setting",
314 "[<name>=<value>]", cliSet),
315 #ifdef USE_SERVOS
316 CLI_COMMAND_DEF("smix", "servo mixer",
317 "<rule> <servo> <source> <rate> <speed> <min> <max> <box>\r\n"
318 "\treset\r\n"
319 "\tload <mixer>\r\n"
320 "\treverse <servo> <source> r|n", cliServoMix),
321 #endif
322 #ifdef USE_SDCARD
323 CLI_COMMAND_DEF("sd_info", "sdcard info", NULL, cliSdInfo),
324 #endif
325 CLI_COMMAND_DEF("status", "show status", NULL, cliStatus),
326 #ifndef SKIP_TASK_STATISTICS
327 CLI_COMMAND_DEF("tasks", "show task stats", NULL, cliTasks),
328 #endif
329 CLI_COMMAND_DEF("version", "show version", NULL, cliVersion),
330 #ifdef BEEPER
331 CLI_COMMAND_DEF("beeper", "turn on/off beeper", "list\r\n"
332 "\t<+|->[name]", cliBeeper),
333 #endif
334 #ifdef VTX
335 CLI_COMMAND_DEF("vtx", "vtx channels on switch", NULL, cliVtx),
336 #endif
338 #define CMD_COUNT (sizeof(cmdTable) / sizeof(clicmd_t))
340 static const char * const lookupTableOffOn[] = {
341 "OFF", "ON"
344 static const char * const lookupTableUnit[] = {
345 "IMPERIAL", "METRIC"
348 static const char * const lookupTableAlignment[] = {
349 "DEFAULT",
350 "CW0",
351 "CW90",
352 "CW180",
353 "CW270",
354 "CW0FLIP",
355 "CW90FLIP",
356 "CW180FLIP",
357 "CW270FLIP"
360 #ifdef GPS
361 static const char * const lookupTableGPSProvider[] = {
362 "NMEA", "UBLOX"
365 static const char * const lookupTableGPSSBASMode[] = {
366 "AUTO", "EGNOS", "WAAS", "MSAS", "GAGAN"
368 #endif
370 static const char * const lookupTableCurrentSensor[] = {
371 "NONE", "ADC", "VIRTUAL"
374 static const char * const lookupTableGimbalMode[] = {
375 "NORMAL", "MIXTILT"
378 static const char * const lookupTableBlackboxDevice[] = {
379 "SERIAL", "SPIFLASH", "SDCARD"
383 static const char * const lookupTablePidController[] = {
384 "UNUSED", "MWREWRITE", "LUX"
387 static const char * const lookupTableSerialRX[] = {
388 "SPEK1024",
389 "SPEK2048",
390 "SBUS",
391 "SUMD",
392 "SUMH",
393 "XB-B",
394 "XB-B-RJ01",
395 "IBUS",
396 "JETIEXBUS"
399 static const char * const lookupTableGyroLpf[] = {
400 "OFF",
401 "188HZ",
402 "98HZ",
403 "42HZ",
404 "20HZ",
405 "10HZ",
406 "5HZ",
407 "EXPERIMENTAL"
410 static const char * const lookupTableAccHardware[] = {
411 "AUTO",
412 "NONE",
413 "ADXL345",
414 "MPU6050",
415 "MMA8452",
416 "BMA280",
417 "LSM303DLHC",
418 "MPU6000",
419 "MPU6500",
420 "FAKE"
423 static const char * const lookupTableBaroHardware[] = {
424 "AUTO",
425 "NONE",
426 "BMP085",
427 "MS5611",
428 "BMP280"
431 static const char * const lookupTableMagHardware[] = {
432 "AUTO",
433 "NONE",
434 "HMC5883",
435 "AK8975",
436 "AK8963"
439 static const char * const lookupTableDebug[DEBUG_COUNT] = {
440 "NONE",
441 "CYCLETIME",
442 "BATTERY",
443 "GYRO",
444 "ACCELEROMETER",
445 "MIXER",
446 "AIRMODE",
447 "PIDLOOP",
450 static const char * const lookupTableSuperExpoYaw[] = {
451 "OFF", "ON", "ALWAYS"
454 static const char * const lookupTableFastPwm[] = {
455 "OFF", "ONESHOT125", "ONESHOT42", "MULTISHOT"
458 typedef struct lookupTableEntry_s {
459 const char * const *values;
460 const uint8_t valueCount;
461 } lookupTableEntry_t;
463 typedef enum {
464 TABLE_OFF_ON = 0,
465 TABLE_UNIT,
466 TABLE_ALIGNMENT,
467 #ifdef GPS
468 TABLE_GPS_PROVIDER,
469 TABLE_GPS_SBAS_MODE,
470 #endif
471 #ifdef BLACKBOX
472 TABLE_BLACKBOX_DEVICE,
473 #endif
474 TABLE_CURRENT_SENSOR,
475 TABLE_GIMBAL_MODE,
476 TABLE_PID_CONTROLLER,
477 TABLE_SERIAL_RX,
478 TABLE_GYRO_LPF,
479 TABLE_ACC_HARDWARE,
480 TABLE_BARO_HARDWARE,
481 TABLE_MAG_HARDWARE,
482 TABLE_DEBUG,
483 TABLE_SUPEREXPO_YAW,
484 TABLE_FAST_PWM,
485 } lookupTableIndex_e;
487 static const lookupTableEntry_t lookupTables[] = {
488 { lookupTableOffOn, sizeof(lookupTableOffOn) / sizeof(char *) },
489 { lookupTableUnit, sizeof(lookupTableUnit) / sizeof(char *) },
490 { lookupTableAlignment, sizeof(lookupTableAlignment) / sizeof(char *) },
491 #ifdef GPS
492 { lookupTableGPSProvider, sizeof(lookupTableGPSProvider) / sizeof(char *) },
493 { lookupTableGPSSBASMode, sizeof(lookupTableGPSSBASMode) / sizeof(char *) },
494 #endif
495 #ifdef BLACKBOX
496 { lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) },
497 #endif
498 { lookupTableCurrentSensor, sizeof(lookupTableCurrentSensor) / sizeof(char *) },
499 { lookupTableGimbalMode, sizeof(lookupTableGimbalMode) / sizeof(char *) },
500 { lookupTablePidController, sizeof(lookupTablePidController) / sizeof(char *) },
501 { lookupTableSerialRX, sizeof(lookupTableSerialRX) / sizeof(char *) },
502 { lookupTableGyroLpf, sizeof(lookupTableGyroLpf) / sizeof(char *) },
503 { lookupTableAccHardware, sizeof(lookupTableAccHardware) / sizeof(char *) },
504 { lookupTableBaroHardware, sizeof(lookupTableBaroHardware) / sizeof(char *) },
505 { lookupTableMagHardware, sizeof(lookupTableMagHardware) / sizeof(char *) },
506 { lookupTableDebug, sizeof(lookupTableDebug) / sizeof(char *) },
507 { lookupTableSuperExpoYaw, sizeof(lookupTableSuperExpoYaw) / sizeof(char *) },
508 { lookupTableFastPwm, sizeof(lookupTableFastPwm) / sizeof(char *) },
511 #define VALUE_TYPE_OFFSET 0
512 #define VALUE_SECTION_OFFSET 4
513 #define VALUE_MODE_OFFSET 6
515 typedef enum {
516 // value type
517 VAR_UINT8 = (0 << VALUE_TYPE_OFFSET),
518 VAR_INT8 = (1 << VALUE_TYPE_OFFSET),
519 VAR_UINT16 = (2 << VALUE_TYPE_OFFSET),
520 VAR_INT16 = (3 << VALUE_TYPE_OFFSET),
521 VAR_UINT32 = (4 << VALUE_TYPE_OFFSET),
522 VAR_FLOAT = (5 << VALUE_TYPE_OFFSET),
524 // value section
525 MASTER_VALUE = (0 << VALUE_SECTION_OFFSET),
526 PROFILE_VALUE = (1 << VALUE_SECTION_OFFSET),
527 PROFILE_RATE_VALUE = (2 << VALUE_SECTION_OFFSET),
528 // value mode
529 MODE_DIRECT = (0 << VALUE_MODE_OFFSET),
530 MODE_LOOKUP = (1 << VALUE_MODE_OFFSET)
531 } cliValueFlag_e;
533 #define VALUE_TYPE_MASK (0x0F)
534 #define VALUE_SECTION_MASK (0x30)
535 #define VALUE_MODE_MASK (0xC0)
537 typedef struct cliMinMaxConfig_s {
538 const int32_t min;
539 const int32_t max;
540 } cliMinMaxConfig_t;
542 typedef struct cliLookupTableConfig_s {
543 const lookupTableIndex_e tableIndex;
544 } cliLookupTableConfig_t;
546 typedef union {
547 cliLookupTableConfig_t lookup;
548 cliMinMaxConfig_t minmax;
550 } cliValueConfig_t;
552 typedef struct {
553 const char *name;
554 const uint8_t type; // see cliValueFlag_e
555 void *ptr;
556 const cliValueConfig_t config;
557 } clivalue_t;
559 const clivalue_t valueTable[] = {
560 // { "emf_avoidance", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.emf_avoidance, .config.lookup = { TABLE_OFF_ON } },
562 { "mid_rc", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.midrc, .config.minmax = { 1200, 1700 } },
563 { "min_check", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.mincheck, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
564 { "max_check", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.maxcheck, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
565 { "rssi_channel", VAR_INT8 | MASTER_VALUE, &masterConfig.rxConfig.rssi_channel, .config.minmax = { 0, MAX_SUPPORTED_RC_CHANNEL_COUNT } },
566 { "rssi_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.rssi_scale, .config.minmax = { RSSI_SCALE_MIN, RSSI_SCALE_MAX } },
567 { "rssi_ppm_invert", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.rssi_ppm_invert, .config.lookup = { TABLE_OFF_ON } },
568 { "input_filtering_mode", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.inputFilteringMode, .config.lookup = { TABLE_OFF_ON } },
569 { "rc_smoothing", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.rcSmoothing, .config.lookup = { TABLE_OFF_ON } },
570 { "roll_yaw_cam_mix_degrees", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.fpvCamAngleDegrees, .config.minmax = { 0, 50 } },
571 { "max_aux_channels", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.max_aux_channel, .config.minmax = { 0, 13 } },
572 { "debug_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.debug_mode, .config.lookup = { TABLE_DEBUG } },
574 { "min_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.minthrottle, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
575 { "max_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.maxthrottle, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
576 { "min_command", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.mincommand, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
577 { "anti_desync_power_step", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.escDesyncProtection, .config.minmax = { 0, 2000 } },
578 { "servo_center_pulse", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.servoCenterPulse, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
580 { "3d_deadband_low", VAR_UINT16 | MASTER_VALUE, &masterConfig.flight3DConfig.deadband3d_low, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, // FIXME upper limit should match code in the mixer, 1500 currently
581 { "3d_deadband_high", VAR_UINT16 | MASTER_VALUE, &masterConfig.flight3DConfig.deadband3d_high, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, // FIXME lower limit should match code in the mixer, 1500 currently,
582 { "3d_neutral", VAR_UINT16 | MASTER_VALUE, &masterConfig.flight3DConfig.neutral3d, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
583 { "3d_deadband_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.flight3DConfig.deadband3d_throttle, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } },
585 { "unsynced_fast_pwm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.use_unsyncedPwm, .config.lookup = { TABLE_OFF_ON } },
586 { "fast_pwm_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.fast_pwm_protocol, .config.lookup = { TABLE_FAST_PWM } },
587 #ifdef CC3D
588 { "enable_buzzer_p6", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.use_buzzer_p6, .config.lookup = { TABLE_OFF_ON } },
589 #endif
590 { "motor_pwm_rate", VAR_UINT16 | MASTER_VALUE, &masterConfig.motor_pwm_rate, .config.minmax = { 200, 32000 } },
591 { "servo_pwm_rate", VAR_UINT16 | MASTER_VALUE, &masterConfig.servo_pwm_rate, .config.minmax = { 50, 498 } },
593 { "disarm_kill_switch", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.disarm_kill_switch, .config.lookup = { TABLE_OFF_ON } },
594 { "gyro_cal_on_first_arm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gyro_cal_on_first_arm, .config.lookup = { TABLE_OFF_ON } },
595 { "auto_disarm_delay", VAR_UINT8 | MASTER_VALUE, &masterConfig.auto_disarm_delay, .config.minmax = { 0, 60 } },
596 { "small_angle", VAR_UINT8 | MASTER_VALUE, &masterConfig.small_angle, .config.minmax = { 0, 180 } },
598 { "fixedwing_althold_dir", VAR_INT8 | MASTER_VALUE, &masterConfig.airplaneConfig.fixedwing_althold_dir, .config.minmax = { -1, 1 } },
600 { "reboot_character", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.reboot_character, .config.minmax = { 48, 126 } },
602 #ifdef GPS
603 { "gps_provider", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.provider, .config.lookup = { TABLE_GPS_PROVIDER } },
604 { "gps_sbas_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.sbasMode, .config.lookup = { TABLE_GPS_SBAS_MODE } },
605 { "gps_auto_config", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.autoConfig, .config.lookup = { TABLE_OFF_ON } },
606 { "gps_auto_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.autoBaud, .config.lookup = { TABLE_OFF_ON } },
608 { "gps_pos_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDPOS], .config.minmax = { 0, 200 } },
609 { "gps_pos_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDPOS], .config.minmax = { 0, 200 } },
610 { "gps_pos_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDPOS], .config.minmax = { 0, 200 } },
611 { "gps_posr_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDPOSR], .config.minmax = { 0, 200 } },
612 { "gps_posr_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDPOSR], .config.minmax = { 0, 200 } },
613 { "gps_posr_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDPOSR], .config.minmax = { 0, 200 } },
614 { "gps_nav_p", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDNAVR], .config.minmax = { 0, 200 } },
615 { "gps_nav_i", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDNAVR], .config.minmax = { 0, 200 } },
616 { "gps_nav_d", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDNAVR], .config.minmax = { 0, 200 } },
617 { "gps_wp_radius", VAR_UINT16 | MASTER_VALUE, &masterConfig.gpsProfile.gps_wp_radius, .config.minmax = { 0, 2000 } },
618 { "nav_controls_heading", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsProfile.nav_controls_heading, .config.lookup = { TABLE_OFF_ON } },
619 { "nav_speed_min", VAR_UINT16 | MASTER_VALUE, &masterConfig.gpsProfile.nav_speed_min, .config.minmax = { 10, 2000 } },
620 { "nav_speed_max", VAR_UINT16 | MASTER_VALUE, &masterConfig.gpsProfile.nav_speed_max, .config.minmax = { 10, 2000 } },
621 { "nav_slew_rate", VAR_UINT8 | MASTER_VALUE, &masterConfig.gpsProfile.nav_slew_rate, .config.minmax = { 0, 100 } },
622 #endif
623 #ifdef GTUNE
624 { "gtune_loP_rll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_lolimP[FD_ROLL], .config.minmax = { 10, 200 } },
625 { "gtune_loP_ptch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_lolimP[FD_PITCH], .config.minmax = { 10, 200 } },
626 { "gtune_loP_yw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_lolimP[FD_YAW], .config.minmax = { 10, 200 } },
627 { "gtune_hiP_rll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_hilimP[FD_ROLL], .config.minmax = { 0, 200 } },
628 { "gtune_hiP_ptch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_hilimP[FD_PITCH], .config.minmax = { 0, 200 } },
629 { "gtune_hiP_yw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_hilimP[FD_YAW], .config.minmax = { 0, 200 } },
630 { "gtune_pwr", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_pwr, .config.minmax = { 0, 10 } },
631 { "gtune_settle_time", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_settle_time, .config.minmax = { 200, 1000 } },
632 { "gtune_average_cycles", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_average_cycles, .config.minmax = { 8, 128 } },
633 #endif
635 { "serialrx_provider", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.serialrx_provider, .config.lookup = { TABLE_SERIAL_RX } },
636 { "sbus_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.sbus_inversion, .config.lookup = { TABLE_OFF_ON } },
637 { "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX} },
638 { "spektrum_sat_bind_autoreset",VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind_autoreset, .config.minmax = { 0, 1} },
640 { "telemetry_switch", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.telemetry_switch, .config.lookup = { TABLE_OFF_ON } },
641 { "telemetry_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.telemetry_inversion, .config.lookup = { TABLE_OFF_ON } },
642 { "frsky_default_lattitude", VAR_FLOAT | MASTER_VALUE, &masterConfig.telemetryConfig.gpsNoFixLatitude, .config.minmax = { -90.0, 90.0 } },
643 { "frsky_default_longitude", VAR_FLOAT | MASTER_VALUE, &masterConfig.telemetryConfig.gpsNoFixLongitude, .config.minmax = { -180.0, 180.0 } },
644 { "frsky_coordinates_format", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.frsky_coordinate_format, .config.minmax = { 0, FRSKY_FORMAT_NMEA } },
645 { "frsky_unit", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.frsky_unit, .config.lookup = { TABLE_UNIT } },
646 { "frsky_vfas_precision", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.frsky_vfas_precision, .config.minmax = { FRSKY_VFAS_PRECISION_LOW, FRSKY_VFAS_PRECISION_HIGH } },
647 { "frsky_vfas_cell_voltage", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.frsky_vfas_cell_voltage, .config.lookup = { TABLE_OFF_ON } },
648 { "hott_alarm_sound_interval", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.hottAlarmSoundInterval, .config.minmax = { 0, 120 } },
650 { "battery_capacity", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.batteryCapacity, .config.minmax = { 0, 20000 } },
651 { "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, .config.minmax = { VBAT_SCALE_MIN, VBAT_SCALE_MAX } },
652 { "vbat_max_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmaxcellvoltage, .config.minmax = { 10, 50 } },
653 { "vbat_min_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmincellvoltage, .config.minmax = { 10, 50 } },
654 { "vbat_warning_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatwarningcellvoltage, .config.minmax = { 10, 50 } },
655 { "vbat_hysteresis", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbathysteresis, .config.minmax = { 0, 250 } },
656 { "vbat_pid_compensation", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.batteryConfig.vbatPidCompensation, .config.lookup = { TABLE_OFF_ON } },
657 { "current_meter_scale", VAR_INT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterScale, .config.minmax = { -10000, 10000 } },
658 { "current_meter_offset", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterOffset, .config.minmax = { 0, 3300 } },
659 { "multiwii_current_meter_output", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.batteryConfig.multiwiiCurrentMeterOutput, .config.lookup = { TABLE_OFF_ON } },
660 { "current_meter_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.batteryConfig.currentMeterType, .config.lookup = { TABLE_CURRENT_SENSOR } },
662 { "align_gyro", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.gyro_align, .config.lookup = { TABLE_ALIGNMENT } },
663 { "align_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.acc_align, .config.lookup = { TABLE_ALIGNMENT } },
664 { "align_mag", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.sensorAlignmentConfig.mag_align, .config.lookup = { TABLE_ALIGNMENT } },
666 { "align_board_roll", VAR_INT16 | MASTER_VALUE, &masterConfig.boardAlignment.rollDegrees, .config.minmax = { -180, 360 } },
667 { "align_board_pitch", VAR_INT16 | MASTER_VALUE, &masterConfig.boardAlignment.pitchDegrees, .config.minmax = { -180, 360 } },
668 { "align_board_yaw", VAR_INT16 | MASTER_VALUE, &masterConfig.boardAlignment.yawDegrees, .config.minmax = { -180, 360 } },
670 { "max_angle_inclination", VAR_UINT16 | MASTER_VALUE, &masterConfig.max_angle_inclination, .config.minmax = { 100, 900 } },
672 { "gyro_lpf", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gyro_lpf, .config.lookup = { TABLE_GYRO_LPF } },
673 { "gyro_sync_denom", VAR_UINT8 | MASTER_VALUE, &masterConfig.gyro_sync_denom, .config.minmax = { 1, 8 } },
674 { "gyro_lowpass", VAR_UINT8 | MASTER_VALUE, &masterConfig.gyro_soft_lpf_hz, .config.minmax = { 0, 255 } },
675 { "moron_threshold", VAR_UINT8 | MASTER_VALUE, &masterConfig.gyroConfig.gyroMovementCalibrationThreshold, .config.minmax = { 0, 128 } },
676 { "imu_dcm_kp", VAR_UINT16 | MASTER_VALUE, &masterConfig.dcm_kp, .config.minmax = { 0, 50000 } },
677 { "imu_dcm_ki", VAR_UINT16 | MASTER_VALUE, &masterConfig.dcm_ki, .config.minmax = { 0, 50000 } },
679 { "alt_hold_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.rcControlsConfig.alt_hold_deadband, .config.minmax = { 1, 250 } },
680 { "alt_hold_fast_change", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rcControlsConfig.alt_hold_fast_change, .config.lookup = { TABLE_OFF_ON } },
681 { "deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.rcControlsConfig.deadband, .config.minmax = { 0, 32 } },
682 { "yaw_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.rcControlsConfig.yaw_deadband, .config.minmax = { 0, 100 } },
684 { "throttle_correction_value", VAR_UINT8 | MASTER_VALUE, &masterConfig.throttle_correction_value, .config.minmax = { 0, 150 } },
685 { "throttle_correction_angle", VAR_UINT16 | MASTER_VALUE, &masterConfig.throttle_correction_angle, .config.minmax = { 1, 900 } },
687 { "yaw_control_direction", VAR_INT8 | MASTER_VALUE, &masterConfig.yaw_control_direction, .config.minmax = { -1, 1 } },
689 { "yaw_motor_direction", VAR_INT8 | MASTER_VALUE, &masterConfig.mixerConfig.yaw_motor_direction, .config.minmax = { -1, 1 } },
690 { "yaw_p_limit", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_p_limit, .config.minmax = { YAW_P_LIMIT_MIN, YAW_P_LIMIT_MAX } },
691 #ifdef USE_SERVOS
692 { "tri_unarmed_servo", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.mixerConfig.tri_unarmed_servo, .config.lookup = { TABLE_OFF_ON } },
693 { "servo_lowpass_freq", VAR_UINT16 | MASTER_VALUE, &masterConfig.mixerConfig.servo_lowpass_freq, .config.minmax = { 10, 400} },
694 { "servo_lowpass_enable", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.mixerConfig.servo_lowpass_enable, .config.lookup = { TABLE_OFF_ON } },
695 #endif
697 { "rc_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcRate8, .config.minmax = { 0, 250 } },
698 { "rc_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcExpo8, .config.minmax = { 0, 100 } },
699 { "rc_yaw_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rcYawExpo8, .config.minmax = { 0, 100 } },
700 { "thr_mid", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].thrMid8, .config.minmax = { 0, 100 } },
701 { "thr_expo", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].thrExpo8, .config.minmax = { 0, 100 } },
702 { "roll_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_ROLL], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } },
703 { "pitch_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_PITCH], .config.minmax = { 0, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX } },
704 { "yaw_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].rates[FD_YAW], .config.minmax = { 0, CONTROL_RATE_CONFIG_YAW_RATE_MAX } },
705 { "tpa_rate", VAR_UINT8 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].dynThrPID, .config.minmax = { 0, CONTROL_RATE_CONFIG_TPA_MAX} },
706 { "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, &masterConfig.profile[0].controlRateProfile[0].tpa_breakpoint, .config.minmax = { PWM_RANGE_MIN, PWM_RANGE_MAX} },
707 { "airmode_activate_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.airModeActivateThreshold, .config.minmax = {1000, 2000 } },
709 { "failsafe_delay", VAR_UINT8 | MASTER_VALUE, &masterConfig.failsafeConfig.failsafe_delay, .config.minmax = { 0, 200 } },
710 { "failsafe_off_delay", VAR_UINT8 | MASTER_VALUE, &masterConfig.failsafeConfig.failsafe_off_delay, .config.minmax = { 0, 200 } },
711 { "failsafe_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.failsafeConfig.failsafe_throttle, .config.minmax = { PWM_RANGE_MIN, PWM_RANGE_MAX } },
712 { "failsafe_kill_switch", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.failsafeConfig.failsafe_kill_switch, .config.lookup = { TABLE_OFF_ON } },
713 { "failsafe_throttle_low_delay",VAR_UINT16 | MASTER_VALUE, &masterConfig.failsafeConfig.failsafe_throttle_low_delay, .config.minmax = { 0, 300 } },
714 { "failsafe_procedure", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.failsafeConfig.failsafe_procedure, .config.lookup = { TABLE_OFF_ON } },
716 { "rx_min_usec", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.rx_min_usec, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX } },
717 { "rx_max_usec", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.rx_max_usec, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX } },
719 #ifdef USE_SERVOS
720 { "gimbal_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gimbalConfig.mode, .config.lookup = { TABLE_GIMBAL_MODE } },
721 #endif
723 { "acc_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.acc_hardware, .config.lookup = { TABLE_ACC_HARDWARE } },
724 { "acc_lpf_hz", VAR_FLOAT | MASTER_VALUE, &masterConfig.acc_lpf_hz, .config.minmax = { 0, 400 } },
725 { "accxy_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.accDeadband.xy, .config.minmax = { 0, 100 } },
726 { "accz_deadband", VAR_UINT8 | MASTER_VALUE, &masterConfig.accDeadband.z, .config.minmax = { 0, 100 } },
727 { "acc_unarmedcal", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.acc_unarmedcal, .config.lookup = { TABLE_OFF_ON } },
728 { "acc_trim_pitch", VAR_INT16 | MASTER_VALUE, &masterConfig.accelerometerTrims.values.pitch, .config.minmax = { -300, 300 } },
729 { "acc_trim_roll", VAR_INT16 | MASTER_VALUE, &masterConfig.accelerometerTrims.values.roll, .config.minmax = { -300, 300 } },
731 { "baro_tab_size", VAR_UINT8 | MASTER_VALUE, &masterConfig.barometerConfig.baro_sample_count, .config.minmax = { 0, BARO_SAMPLE_COUNT_MAX } },
732 { "baro_noise_lpf", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_noise_lpf, .config.minmax = { 0 , 1 } },
733 { "baro_cf_vel", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_cf_vel, .config.minmax = { 0 , 1 } },
734 { "baro_cf_alt", VAR_FLOAT | MASTER_VALUE, &masterConfig.barometerConfig.baro_cf_alt, .config.minmax = { 0 , 1 } },
735 { "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.baro_hardware, .config.lookup = { TABLE_BARO_HARDWARE } },
737 { "mag_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.mag_hardware, .config.lookup = { TABLE_MAG_HARDWARE } },
738 { "mag_declination", VAR_INT16 | MASTER_VALUE, &masterConfig.mag_declination, .config.minmax = { -18000, 18000 } },
739 { "dterm_lowpass", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dterm_lpf_hz, .config.minmax = {0, 500 } },
740 { "dynamic_pid", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.dynamic_pid, .config.lookup = { TABLE_OFF_ON } },
741 { "iterm_ignore_threshold", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.rollPitchItermIgnoreRate, .config.minmax = {50, 1000 } },
742 { "yaw_iterm_ignore_threshold", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yawItermIgnoreRate, .config.minmax = {25, 1000 } },
743 { "yaw_lowpass", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_lpf_hz, .config.minmax = {0, 500 } },
744 { "pid_process_denom", VAR_UINT8 | MASTER_VALUE, &masterConfig.pid_process_denom, .config.minmax = { 1, 8 } },
746 { "pid_controller", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.pidController, .config.lookup = { TABLE_PID_CONTROLLER } },
748 { "p_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PITCH], .config.minmax = { 0, 200 } },
749 { "i_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PITCH], .config.minmax = { 0, 200 } },
750 { "d_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PITCH], .config.minmax = { 0, 200 } },
751 { "p_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[ROLL], .config.minmax = { 0, 200 } },
752 { "i_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[ROLL], .config.minmax = { 0, 200 } },
753 { "d_roll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[ROLL], .config.minmax = { 0, 200 } },
754 { "p_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[YAW], .config.minmax = { 0, 200 } },
755 { "i_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[YAW], .config.minmax = { 0, 200 } },
756 { "d_yaw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[YAW], .config.minmax = { 0, 200 } },
758 { "p_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDALT], .config.minmax = { 0, 200 } },
759 { "i_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDALT], .config.minmax = { 0, 200 } },
760 { "d_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDALT], .config.minmax = { 0, 200 } },
762 { "p_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDLEVEL], .config.minmax = { 0, 200 } },
763 { "i_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDLEVEL], .config.minmax = { 0, 200 } },
764 { "d_level", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDLEVEL], .config.minmax = { 0, 200 } },
766 { "p_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDVEL], .config.minmax = { 0, 200 } },
767 { "i_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDVEL], .config.minmax = { 0, 200 } },
768 { "d_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDVEL], .config.minmax = { 0, 200 } },
770 #ifdef BLACKBOX
771 { "blackbox_rate_num", VAR_UINT8 | MASTER_VALUE, &masterConfig.blackbox_rate_num, .config.minmax = { 1, 32 } },
772 { "blackbox_rate_denom", VAR_UINT8 | MASTER_VALUE, &masterConfig.blackbox_rate_denom, .config.minmax = { 1, 32 } },
773 { "blackbox_device", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.blackbox_device, .config.lookup = { TABLE_BLACKBOX_DEVICE } },
774 #endif
776 #ifdef VTX
777 { "vtx_band", VAR_UINT8 | MASTER_VALUE, &masterConfig.vtx_band, .config.minmax = { 1, 5 } },
778 { "vtx_channel", VAR_UINT8 | MASTER_VALUE, &masterConfig.vtx_channel, .config.minmax = { 1, 8 } },
779 { "vtx_mode", VAR_UINT8 | MASTER_VALUE, &masterConfig.vtx_mode, .config.minmax = { 0, 2 } },
780 { "vtx_mhz", VAR_UINT16 | MASTER_VALUE, &masterConfig.vtx_mhz, .config.minmax = { 5600, 5950 } },
781 #endif
783 { "magzero_x", VAR_INT16 | MASTER_VALUE, &masterConfig.magZero.raw[X], .config.minmax = { -32768, 32767 } },
784 { "magzero_y", VAR_INT16 | MASTER_VALUE, &masterConfig.magZero.raw[Y], .config.minmax = { -32768, 32767 } },
785 { "magzero_z", VAR_INT16 | MASTER_VALUE, &masterConfig.magZero.raw[Z], .config.minmax = { -32768, 32767 } },
786 #ifdef LED_STRIP
787 { "ledstrip_visual_beeper", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.ledstrip_visual_beeper, .config.lookup = { TABLE_OFF_ON } },
788 #endif
791 #define VALUE_COUNT (sizeof(valueTable) / sizeof(clivalue_t))
794 typedef union {
795 int32_t int_value;
796 float float_value;
797 } int_float_value_t;
799 static void cliSetVar(const clivalue_t *var, const int_float_value_t value);
800 static void cliPrintVar(const clivalue_t *var, uint32_t full);
801 static void cliPrintVarRange(const clivalue_t *var);
802 static void cliPrint(const char *str);
803 static void cliPrintf(const char *fmt, ...);
804 static void cliWrite(uint8_t ch);
806 static void cliPrompt(void)
808 cliPrint("\r\n# ");
809 bufWriterFlush(cliWriter);
812 static void cliShowParseError(void)
814 cliPrint("Parse error\r\n");
817 static void cliShowArgumentRangeError(char *name, int min, int max)
819 cliPrintf("%s must be between %d and %d\r\n", name, min, max);
822 static char *processChannelRangeArgs(char *ptr, channelRange_t *range, uint8_t *validArgumentCount)
824 int val;
826 for (int argIndex = 0; argIndex < 2; argIndex++) {
827 ptr = strchr(ptr, ' ');
828 if (ptr) {
829 val = atoi(++ptr);
830 val = CHANNEL_VALUE_TO_STEP(val);
831 if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
832 if (argIndex == 0) {
833 range->startStep = val;
834 } else {
835 range->endStep = val;
837 (*validArgumentCount)++;
842 return ptr;
845 // Check if a string's length is zero
846 static bool isEmpty(const char *string)
848 return *string == '\0';
851 static void cliRxFail(char *cmdline)
853 uint8_t channel;
854 char buf[3];
856 if (isEmpty(cmdline)) {
857 // print out rxConfig failsafe settings
858 for (channel = 0; channel < MAX_SUPPORTED_RC_CHANNEL_COUNT; channel++) {
859 cliRxFail(itoa(channel, buf, 10));
861 } else {
862 char *ptr = cmdline;
863 channel = atoi(ptr++);
864 if ((channel < MAX_SUPPORTED_RC_CHANNEL_COUNT)) {
866 rxFailsafeChannelConfiguration_t *channelFailsafeConfiguration = &masterConfig.rxConfig.failsafe_channel_configurations[channel];
868 uint16_t value;
869 rxFailsafeChannelType_e type = (channel < NON_AUX_CHANNEL_COUNT) ? RX_FAILSAFE_TYPE_FLIGHT : RX_FAILSAFE_TYPE_AUX;
870 rxFailsafeChannelMode_e mode = channelFailsafeConfiguration->mode;
871 bool requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET;
873 ptr = strchr(ptr, ' ');
874 if (ptr) {
875 char *p = strchr(rxFailsafeModeCharacters, *(++ptr));
876 if (p) {
877 uint8_t requestedMode = p - rxFailsafeModeCharacters;
878 mode = rxFailsafeModesTable[type][requestedMode];
879 } else {
880 mode = RX_FAILSAFE_MODE_INVALID;
882 if (mode == RX_FAILSAFE_MODE_INVALID) {
883 cliShowParseError();
884 return;
887 requireValue = mode == RX_FAILSAFE_MODE_SET;
889 ptr = strchr(ptr, ' ');
890 if (ptr) {
891 if (!requireValue) {
892 cliShowParseError();
893 return;
895 value = atoi(++ptr);
896 value = CHANNEL_VALUE_TO_RXFAIL_STEP(value);
897 if (value > MAX_RXFAIL_RANGE_STEP) {
898 cliPrint("Value out of range\r\n");
899 return;
902 channelFailsafeConfiguration->step = value;
903 } else if (requireValue) {
904 cliShowParseError();
905 return;
907 channelFailsafeConfiguration->mode = mode;
911 char modeCharacter = rxFailsafeModeCharacters[channelFailsafeConfiguration->mode];
913 // triple use of cliPrintf below
914 // 1. acknowledge interpretation on command,
915 // 2. query current setting on single item,
916 // 3. recursive use for full list.
918 if (requireValue) {
919 cliPrintf("rxfail %u %c %d\r\n",
920 channel,
921 modeCharacter,
922 RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfiguration->step)
924 } else {
925 cliPrintf("rxfail %u %c\r\n",
926 channel,
927 modeCharacter
930 } else {
931 cliShowArgumentRangeError("channel", 0, MAX_SUPPORTED_RC_CHANNEL_COUNT - 1);
936 static void cliAux(char *cmdline)
938 int i, val = 0;
939 char *ptr;
941 if (isEmpty(cmdline)) {
942 // print out aux channel settings
943 for (i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) {
944 modeActivationCondition_t *mac = &masterConfig.modeActivationConditions[i];
945 cliPrintf("aux %u %u %u %u %u\r\n",
947 mac->modeId,
948 mac->auxChannelIndex,
949 MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep),
950 MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep)
953 } else {
954 ptr = cmdline;
955 i = atoi(ptr++);
956 if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
957 modeActivationCondition_t *mac = &masterConfig.modeActivationConditions[i];
958 uint8_t validArgumentCount = 0;
959 ptr = strchr(ptr, ' ');
960 if (ptr) {
961 val = atoi(++ptr);
962 if (val >= 0 && val < CHECKBOX_ITEM_COUNT) {
963 mac->modeId = val;
964 validArgumentCount++;
967 ptr = strchr(ptr, ' ');
968 if (ptr) {
969 val = atoi(++ptr);
970 if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
971 mac->auxChannelIndex = val;
972 validArgumentCount++;
975 ptr = processChannelRangeArgs(ptr, &mac->range, &validArgumentCount);
977 if (validArgumentCount != 4) {
978 memset(mac, 0, sizeof(modeActivationCondition_t));
980 } else {
981 cliShowArgumentRangeError("index", 0, MAX_MODE_ACTIVATION_CONDITION_COUNT - 1);
986 static void cliSerial(char *cmdline)
988 int i, val;
989 char *ptr;
991 if (isEmpty(cmdline)) {
992 for (i = 0; i < SERIAL_PORT_COUNT; i++) {
993 if (!serialIsPortAvailable(masterConfig.serialConfig.portConfigs[i].identifier)) {
994 continue;
996 cliPrintf("serial %d %d %ld %ld %ld %ld\r\n" ,
997 masterConfig.serialConfig.portConfigs[i].identifier,
998 masterConfig.serialConfig.portConfigs[i].functionMask,
999 baudRates[masterConfig.serialConfig.portConfigs[i].msp_baudrateIndex],
1000 baudRates[masterConfig.serialConfig.portConfigs[i].gps_baudrateIndex],
1001 baudRates[masterConfig.serialConfig.portConfigs[i].telemetry_baudrateIndex],
1002 baudRates[masterConfig.serialConfig.portConfigs[i].blackbox_baudrateIndex]
1005 return;
1008 serialPortConfig_t portConfig;
1009 memset(&portConfig, 0 , sizeof(portConfig));
1011 serialPortConfig_t *currentConfig;
1013 uint8_t validArgumentCount = 0;
1015 ptr = cmdline;
1017 val = atoi(ptr++);
1018 currentConfig = serialFindPortConfiguration(val);
1019 if (currentConfig) {
1020 portConfig.identifier = val;
1021 validArgumentCount++;
1024 ptr = strchr(ptr, ' ');
1025 if (ptr) {
1026 val = atoi(++ptr);
1027 portConfig.functionMask = val & 0xFFFF;
1028 validArgumentCount++;
1031 for (i = 0; i < 4; i ++) {
1032 ptr = strchr(ptr, ' ');
1033 if (!ptr) {
1034 break;
1037 val = atoi(++ptr);
1039 uint8_t baudRateIndex = lookupBaudRateIndex(val);
1040 if (baudRates[baudRateIndex] != (uint32_t) val) {
1041 break;
1044 switch(i) {
1045 case 0:
1046 if (baudRateIndex < BAUD_9600 || baudRateIndex > BAUD_115200) {
1047 continue;
1049 portConfig.msp_baudrateIndex = baudRateIndex;
1050 break;
1051 case 1:
1052 if (baudRateIndex < BAUD_9600 || baudRateIndex > BAUD_115200) {
1053 continue;
1055 portConfig.gps_baudrateIndex = baudRateIndex;
1056 break;
1057 case 2:
1058 if (baudRateIndex != BAUD_AUTO && baudRateIndex > BAUD_115200) {
1059 continue;
1061 portConfig.telemetry_baudrateIndex = baudRateIndex;
1062 break;
1063 case 3:
1064 if (baudRateIndex < BAUD_19200 || baudRateIndex > BAUD_250000) {
1065 continue;
1067 portConfig.blackbox_baudrateIndex = baudRateIndex;
1068 break;
1071 validArgumentCount++;
1074 if (validArgumentCount < 6) {
1075 cliShowParseError();
1076 return;
1079 memcpy(currentConfig, &portConfig, sizeof(portConfig));
1083 #ifndef SKIP_SERIAL_PASSTHROUGH
1084 static void cliSerialPassthrough(char *cmdline)
1086 if (isEmpty(cmdline)) {
1087 cliShowParseError();
1088 return;
1091 int id = -1;
1092 uint32_t baud = 0;
1093 unsigned mode = 0;
1094 char* tok = strtok(cmdline, " ");
1095 int index = 0;
1097 while (tok != NULL) {
1098 switch(index) {
1099 case 0:
1100 id = atoi(tok);
1101 break;
1102 case 1:
1103 baud = atoi(tok);
1104 break;
1105 case 2:
1106 if (strstr(tok, "rx") || strstr(tok, "RX"))
1107 mode |= MODE_RX;
1108 if (strstr(tok, "tx") || strstr(tok, "TX"))
1109 mode |= MODE_TX;
1110 break;
1112 index++;
1113 tok = strtok(NULL, " ");
1116 serialPort_t *passThroughPort;
1117 serialPortUsage_t *passThroughPortUsage = findSerialPortUsageByIdentifier(id);
1118 if (!passThroughPortUsage || passThroughPortUsage->serialPort == NULL) {
1119 if (!baud) {
1120 printf("Port %d is not open, you must specify baud\r\n", id);
1121 return;
1123 if (!mode)
1124 mode = MODE_RXTX;
1126 passThroughPort = openSerialPort(id, FUNCTION_PASSTHROUGH, NULL,
1127 baud, mode,
1128 SERIAL_NOT_INVERTED);
1129 if (!passThroughPort) {
1130 printf("Port %d could not be opened\r\n", id);
1131 return;
1133 printf("Port %d opened, baud=%d\r\n", id, baud);
1134 } else {
1135 passThroughPort = passThroughPortUsage->serialPort;
1136 // If the user supplied a mode, override the port's mode, otherwise
1137 // leave the mode unchanged. serialPassthrough() handles one-way ports.
1138 printf("Port %d already open\r\n", id);
1139 if (mode && passThroughPort->mode != mode) {
1140 printf("Adjusting mode from configured value %d to %d\r\n",
1141 passThroughPort->mode, mode);
1142 serialSetMode(passThroughPort, mode);
1146 printf("Relaying data to device on port %d, Reset your board to exit "
1147 "serial passthrough mode.\r\n");
1149 serialPassthrough(cliPort, passThroughPort, NULL, NULL);
1151 #endif
1153 static void cliAdjustmentRange(char *cmdline)
1155 int i, val = 0;
1156 char *ptr;
1158 if (isEmpty(cmdline)) {
1159 // print out adjustment ranges channel settings
1160 for (i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
1161 adjustmentRange_t *ar = &masterConfig.adjustmentRanges[i];
1162 cliPrintf("adjrange %u %u %u %u %u %u %u\r\n",
1164 ar->adjustmentIndex,
1165 ar->auxChannelIndex,
1166 MODE_STEP_TO_CHANNEL_VALUE(ar->range.startStep),
1167 MODE_STEP_TO_CHANNEL_VALUE(ar->range.endStep),
1168 ar->adjustmentFunction,
1169 ar->auxSwitchChannelIndex
1172 } else {
1173 ptr = cmdline;
1174 i = atoi(ptr++);
1175 if (i < MAX_ADJUSTMENT_RANGE_COUNT) {
1176 adjustmentRange_t *ar = &masterConfig.adjustmentRanges[i];
1177 uint8_t validArgumentCount = 0;
1179 ptr = strchr(ptr, ' ');
1180 if (ptr) {
1181 val = atoi(++ptr);
1182 if (val >= 0 && val < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT) {
1183 ar->adjustmentIndex = val;
1184 validArgumentCount++;
1187 ptr = strchr(ptr, ' ');
1188 if (ptr) {
1189 val = atoi(++ptr);
1190 if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
1191 ar->auxChannelIndex = val;
1192 validArgumentCount++;
1196 ptr = processChannelRangeArgs(ptr, &ar->range, &validArgumentCount);
1198 ptr = strchr(ptr, ' ');
1199 if (ptr) {
1200 val = atoi(++ptr);
1201 if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
1202 ar->adjustmentFunction = val;
1203 validArgumentCount++;
1206 ptr = strchr(ptr, ' ');
1207 if (ptr) {
1208 val = atoi(++ptr);
1209 if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
1210 ar->auxSwitchChannelIndex = val;
1211 validArgumentCount++;
1215 if (validArgumentCount != 6) {
1216 memset(ar, 0, sizeof(adjustmentRange_t));
1217 cliShowParseError();
1219 } else {
1220 cliShowArgumentRangeError("index", 0, MAX_ADJUSTMENT_RANGE_COUNT - 1);
1225 static void cliMotorMix(char *cmdline)
1227 #ifdef USE_QUAD_MIXER_ONLY
1228 UNUSED(cmdline);
1229 #else
1230 int i, check = 0;
1231 int num_motors = 0;
1232 uint8_t len;
1233 char buf[16];
1234 char *ptr;
1236 if (isEmpty(cmdline)) {
1237 cliPrint("Motor\tThr\tRoll\tPitch\tYaw\r\n");
1238 for (i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
1239 if (masterConfig.customMotorMixer[i].throttle == 0.0f)
1240 break;
1241 num_motors++;
1242 cliPrintf("#%d:\t", i);
1243 cliPrintf("%s\t", ftoa(masterConfig.customMotorMixer[i].throttle, buf));
1244 cliPrintf("%s\t", ftoa(masterConfig.customMotorMixer[i].roll, buf));
1245 cliPrintf("%s\t", ftoa(masterConfig.customMotorMixer[i].pitch, buf));
1246 cliPrintf("%s\r\n", ftoa(masterConfig.customMotorMixer[i].yaw, buf));
1248 return;
1249 } else if (strncasecmp(cmdline, "reset", 5) == 0) {
1250 // erase custom mixer
1251 for (i = 0; i < MAX_SUPPORTED_MOTORS; i++)
1252 masterConfig.customMotorMixer[i].throttle = 0.0f;
1253 } else if (strncasecmp(cmdline, "load", 4) == 0) {
1254 ptr = strchr(cmdline, ' ');
1255 if (ptr) {
1256 len = strlen(++ptr);
1257 for (i = 0; ; i++) {
1258 if (mixerNames[i] == NULL) {
1259 cliPrint("Invalid name\r\n");
1260 break;
1262 if (strncasecmp(ptr, mixerNames[i], len) == 0) {
1263 mixerLoadMix(i, masterConfig.customMotorMixer);
1264 cliPrintf("Loaded %s\r\n", mixerNames[i]);
1265 cliMotorMix("");
1266 break;
1270 } else {
1271 ptr = cmdline;
1272 i = atoi(ptr); // get motor number
1273 if (i < MAX_SUPPORTED_MOTORS) {
1274 ptr = strchr(ptr, ' ');
1275 if (ptr) {
1276 masterConfig.customMotorMixer[i].throttle = fastA2F(++ptr);
1277 check++;
1279 ptr = strchr(ptr, ' ');
1280 if (ptr) {
1281 masterConfig.customMotorMixer[i].roll = fastA2F(++ptr);
1282 check++;
1284 ptr = strchr(ptr, ' ');
1285 if (ptr) {
1286 masterConfig.customMotorMixer[i].pitch = fastA2F(++ptr);
1287 check++;
1289 ptr = strchr(ptr, ' ');
1290 if (ptr) {
1291 masterConfig.customMotorMixer[i].yaw = fastA2F(++ptr);
1292 check++;
1294 if (check != 4) {
1295 cliShowParseError();
1296 } else {
1297 cliMotorMix("");
1299 } else {
1300 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
1303 #endif
1306 static void cliRxRange(char *cmdline)
1308 int i, validArgumentCount = 0;
1309 char *ptr;
1311 if (isEmpty(cmdline)) {
1312 for (i = 0; i < NON_AUX_CHANNEL_COUNT; i++) {
1313 rxChannelRangeConfiguration_t *channelRangeConfiguration = &masterConfig.rxConfig.channelRanges[i];
1314 cliPrintf("rxrange %u %u %u\r\n", i, channelRangeConfiguration->min, channelRangeConfiguration->max);
1316 } else if (strcasecmp(cmdline, "reset") == 0) {
1317 resetAllRxChannelRangeConfigurations(masterConfig.rxConfig.channelRanges);
1318 } else {
1319 ptr = cmdline;
1320 i = atoi(ptr);
1321 if (i >= 0 && i < NON_AUX_CHANNEL_COUNT) {
1322 int rangeMin, rangeMax;
1324 ptr = strchr(ptr, ' ');
1325 if (ptr) {
1326 rangeMin = atoi(++ptr);
1327 validArgumentCount++;
1330 ptr = strchr(ptr, ' ');
1331 if (ptr) {
1332 rangeMax = atoi(++ptr);
1333 validArgumentCount++;
1336 if (validArgumentCount != 2) {
1337 cliShowParseError();
1338 } else if (rangeMin < PWM_PULSE_MIN || rangeMin > PWM_PULSE_MAX || rangeMax < PWM_PULSE_MIN || rangeMax > PWM_PULSE_MAX) {
1339 cliShowParseError();
1340 } else {
1341 rxChannelRangeConfiguration_t *channelRangeConfiguration = &masterConfig.rxConfig.channelRanges[i];
1342 channelRangeConfiguration->min = rangeMin;
1343 channelRangeConfiguration->max = rangeMax;
1345 } else {
1346 cliShowArgumentRangeError("channel", 0, NON_AUX_CHANNEL_COUNT - 1);
1351 #ifdef LED_STRIP
1352 static void cliLed(char *cmdline)
1354 int i;
1355 char *ptr;
1356 char ledConfigBuffer[20];
1358 if (isEmpty(cmdline)) {
1359 for (i = 0; i < MAX_LED_STRIP_LENGTH; i++) {
1360 generateLedConfig(i, ledConfigBuffer, sizeof(ledConfigBuffer));
1361 cliPrintf("led %u %s\r\n", i, ledConfigBuffer);
1363 } else {
1364 ptr = cmdline;
1365 i = atoi(ptr);
1366 if (i < MAX_LED_STRIP_LENGTH) {
1367 ptr = strchr(cmdline, ' ');
1368 if (!parseLedStripConfig(i, ++ptr)) {
1369 cliShowParseError();
1371 } else {
1372 cliShowArgumentRangeError("index", 0, MAX_LED_STRIP_LENGTH - 1);
1377 static void cliColor(char *cmdline)
1379 int i;
1380 char *ptr;
1382 if (isEmpty(cmdline)) {
1383 for (i = 0; i < CONFIGURABLE_COLOR_COUNT; i++) {
1384 cliPrintf("color %u %d,%u,%u\r\n",
1386 masterConfig.colors[i].h,
1387 masterConfig.colors[i].s,
1388 masterConfig.colors[i].v
1391 } else {
1392 ptr = cmdline;
1393 i = atoi(ptr);
1394 if (i < CONFIGURABLE_COLOR_COUNT) {
1395 ptr = strchr(cmdline, ' ');
1396 if (!parseColor(i, ++ptr)) {
1397 cliShowParseError();
1399 } else {
1400 cliShowArgumentRangeError("index", 0, CONFIGURABLE_COLOR_COUNT - 1);
1404 #endif
1406 #ifdef USE_SERVOS
1407 static void cliServo(char *cmdline)
1409 enum { SERVO_ARGUMENT_COUNT = 8 };
1410 int16_t arguments[SERVO_ARGUMENT_COUNT];
1412 servoParam_t *servo;
1414 int i;
1415 char *ptr;
1417 if (isEmpty(cmdline)) {
1418 // print out servo settings
1419 for (i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
1420 servo = &masterConfig.servoConf[i];
1422 cliPrintf("servo %u %d %d %d %d %d %d %d\r\n",
1424 servo->min,
1425 servo->max,
1426 servo->middle,
1427 servo->angleAtMin,
1428 servo->angleAtMax,
1429 servo->rate,
1430 servo->forwardFromChannel
1433 } else {
1434 int validArgumentCount = 0;
1436 ptr = cmdline;
1438 // Command line is integers (possibly negative) separated by spaces, no other characters allowed.
1440 // If command line doesn't fit the format, don't modify the config
1441 while (*ptr) {
1442 if (*ptr == '-' || (*ptr >= '0' && *ptr <= '9')) {
1443 if (validArgumentCount >= SERVO_ARGUMENT_COUNT) {
1444 cliShowParseError();
1445 return;
1448 arguments[validArgumentCount++] = atoi(ptr);
1450 do {
1451 ptr++;
1452 } while (*ptr >= '0' && *ptr <= '9');
1453 } else if (*ptr == ' ') {
1454 ptr++;
1455 } else {
1456 cliShowParseError();
1457 return;
1461 enum {INDEX = 0, MIN, MAX, MIDDLE, ANGLE_AT_MIN, ANGLE_AT_MAX, RATE, FORWARD};
1463 i = arguments[INDEX];
1465 // Check we got the right number of args and the servo index is correct (don't validate the other values)
1466 if (validArgumentCount != SERVO_ARGUMENT_COUNT || i < 0 || i >= MAX_SUPPORTED_SERVOS) {
1467 cliShowParseError();
1468 return;
1471 servo = &masterConfig.servoConf[i];
1473 if (
1474 arguments[MIN] < PWM_PULSE_MIN || arguments[MIN] > PWM_PULSE_MAX ||
1475 arguments[MAX] < PWM_PULSE_MIN || arguments[MAX] > PWM_PULSE_MAX ||
1476 arguments[MIDDLE] < arguments[MIN] || arguments[MIDDLE] > arguments[MAX] ||
1477 arguments[MIN] > arguments[MAX] || arguments[MAX] < arguments[MIN] ||
1478 arguments[RATE] < -100 || arguments[RATE] > 100 ||
1479 arguments[FORWARD] >= MAX_SUPPORTED_RC_CHANNEL_COUNT ||
1480 arguments[ANGLE_AT_MIN] < 0 || arguments[ANGLE_AT_MIN] > 180 ||
1481 arguments[ANGLE_AT_MAX] < 0 || arguments[ANGLE_AT_MAX] > 180
1483 cliShowParseError();
1484 return;
1487 servo->min = arguments[1];
1488 servo->max = arguments[2];
1489 servo->middle = arguments[3];
1490 servo->angleAtMin = arguments[4];
1491 servo->angleAtMax = arguments[5];
1492 servo->rate = arguments[6];
1493 servo->forwardFromChannel = arguments[7];
1496 #endif
1498 #ifdef USE_SERVOS
1499 static void cliServoMix(char *cmdline)
1501 int i;
1502 uint8_t len;
1503 char *ptr;
1504 int args[8], check = 0;
1505 len = strlen(cmdline);
1507 if (len == 0) {
1509 cliPrint("Rule\tServo\tSource\tRate\tSpeed\tMin\tMax\tBox\r\n");
1511 for (i = 0; i < MAX_SERVO_RULES; i++) {
1512 if (masterConfig.customServoMixer[i].rate == 0)
1513 break;
1515 cliPrintf("#%d:\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
1517 masterConfig.customServoMixer[i].targetChannel,
1518 masterConfig.customServoMixer[i].inputSource,
1519 masterConfig.customServoMixer[i].rate,
1520 masterConfig.customServoMixer[i].speed,
1521 masterConfig.customServoMixer[i].min,
1522 masterConfig.customServoMixer[i].max,
1523 masterConfig.customServoMixer[i].box
1526 cliPrintf("\r\n");
1527 return;
1528 } else if (strncasecmp(cmdline, "reset", 5) == 0) {
1529 // erase custom mixer
1530 memset(masterConfig.customServoMixer, 0, sizeof(masterConfig.customServoMixer));
1531 for (i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
1532 masterConfig.servoConf[i].reversedSources = 0;
1534 } else if (strncasecmp(cmdline, "load", 4) == 0) {
1535 ptr = strchr(cmdline, ' ');
1536 if (ptr) {
1537 len = strlen(++ptr);
1538 for (i = 0; ; i++) {
1539 if (mixerNames[i] == NULL) {
1540 cliPrintf("Invalid name\r\n");
1541 break;
1543 if (strncasecmp(ptr, mixerNames[i], len) == 0) {
1544 servoMixerLoadMix(i, masterConfig.customServoMixer);
1545 cliPrintf("Loaded %s\r\n", mixerNames[i]);
1546 cliServoMix("");
1547 break;
1551 } else if (strncasecmp(cmdline, "reverse", 7) == 0) {
1552 enum {SERVO = 0, INPUT, REVERSE, ARGS_COUNT};
1553 int servoIndex, inputSource;
1554 ptr = strchr(cmdline, ' ');
1556 len = strlen(ptr);
1557 if (len == 0) {
1558 cliPrintf("s");
1559 for (inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++)
1560 cliPrintf("\ti%d", inputSource);
1561 cliPrintf("\r\n");
1563 for (servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) {
1564 cliPrintf("%d", servoIndex);
1565 for (inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++)
1566 cliPrintf("\t%s ", (masterConfig.servoConf[servoIndex].reversedSources & (1 << inputSource)) ? "r" : "n");
1567 cliPrintf("\r\n");
1569 return;
1572 ptr = strtok(ptr, " ");
1573 while (ptr != NULL && check < ARGS_COUNT - 1) {
1574 args[check++] = atoi(ptr);
1575 ptr = strtok(NULL, " ");
1578 if (ptr == NULL || check != ARGS_COUNT - 1) {
1579 cliShowParseError();
1580 return;
1583 if (args[SERVO] >= 0 && args[SERVO] < MAX_SUPPORTED_SERVOS
1584 && args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT
1585 && (*ptr == 'r' || *ptr == 'n')) {
1586 if (*ptr == 'r')
1587 masterConfig.servoConf[args[SERVO]].reversedSources |= 1 << args[INPUT];
1588 else
1589 masterConfig.servoConf[args[SERVO]].reversedSources &= ~(1 << args[INPUT]);
1590 } else
1591 cliShowParseError();
1593 cliServoMix("reverse");
1594 } else {
1595 enum {RULE = 0, TARGET, INPUT, RATE, SPEED, MIN, MAX, BOX, ARGS_COUNT};
1596 ptr = strtok(cmdline, " ");
1597 while (ptr != NULL && check < ARGS_COUNT) {
1598 args[check++] = atoi(ptr);
1599 ptr = strtok(NULL, " ");
1602 if (ptr != NULL || check != ARGS_COUNT) {
1603 cliShowParseError();
1604 return;
1607 i = args[RULE];
1608 if (i >= 0 && i < MAX_SERVO_RULES &&
1609 args[TARGET] >= 0 && args[TARGET] < MAX_SUPPORTED_SERVOS &&
1610 args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT &&
1611 args[RATE] >= -100 && args[RATE] <= 100 &&
1612 args[SPEED] >= 0 && args[SPEED] <= MAX_SERVO_SPEED &&
1613 args[MIN] >= 0 && args[MIN] <= 100 &&
1614 args[MAX] >= 0 && args[MAX] <= 100 && args[MIN] < args[MAX] &&
1615 args[BOX] >= 0 && args[BOX] <= MAX_SERVO_BOXES) {
1616 masterConfig.customServoMixer[i].targetChannel = args[TARGET];
1617 masterConfig.customServoMixer[i].inputSource = args[INPUT];
1618 masterConfig.customServoMixer[i].rate = args[RATE];
1619 masterConfig.customServoMixer[i].speed = args[SPEED];
1620 masterConfig.customServoMixer[i].min = args[MIN];
1621 masterConfig.customServoMixer[i].max = args[MAX];
1622 masterConfig.customServoMixer[i].box = args[BOX];
1623 cliServoMix("");
1624 } else {
1625 cliShowParseError();
1629 #endif
1631 #ifdef USE_SDCARD
1633 static void cliWriteBytes(const uint8_t *buffer, int count)
1635 while (count > 0) {
1636 cliWrite(*buffer);
1637 buffer++;
1638 count--;
1642 static void cliSdInfo(char *cmdline) {
1643 UNUSED(cmdline);
1645 cliPrint("SD card: ");
1647 if (!sdcard_isInserted()) {
1648 cliPrint("None inserted\r\n");
1649 return;
1652 if (!sdcard_isInitialized()) {
1653 cliPrint("Startup failed\r\n");
1654 return;
1657 const sdcardMetadata_t *metadata = sdcard_getMetadata();
1659 cliPrintf("Manufacturer 0x%x, %ukB, %02d/%04d, v%d.%d, '",
1660 metadata->manufacturerID,
1661 metadata->numBlocks / 2, /* One block is half a kB */
1662 metadata->productionMonth,
1663 metadata->productionYear,
1664 metadata->productRevisionMajor,
1665 metadata->productRevisionMinor
1668 cliWriteBytes((uint8_t*)metadata->productName, sizeof(metadata->productName));
1670 cliPrint("'\r\n" "Filesystem: ");
1672 switch (afatfs_getFilesystemState()) {
1673 case AFATFS_FILESYSTEM_STATE_READY:
1674 cliPrint("Ready");
1675 break;
1676 case AFATFS_FILESYSTEM_STATE_INITIALIZATION:
1677 cliPrint("Initializing");
1678 break;
1679 case AFATFS_FILESYSTEM_STATE_UNKNOWN:
1680 case AFATFS_FILESYSTEM_STATE_FATAL:
1681 cliPrint("Fatal");
1683 switch (afatfs_getLastError()) {
1684 case AFATFS_ERROR_BAD_MBR:
1685 cliPrint(" - no FAT MBR partitions");
1686 break;
1687 case AFATFS_ERROR_BAD_FILESYSTEM_HEADER:
1688 cliPrint(" - bad FAT header");
1689 break;
1690 case AFATFS_ERROR_GENERIC:
1691 case AFATFS_ERROR_NONE:
1692 ; // Nothing more detailed to print
1693 break;
1696 cliPrint("\r\n");
1697 break;
1701 #endif
1703 #ifdef USE_FLASHFS
1705 static void cliFlashInfo(char *cmdline)
1707 const flashGeometry_t *layout = flashfsGetGeometry();
1709 UNUSED(cmdline);
1711 cliPrintf("Flash sectors=%u, sectorSize=%u, pagesPerSector=%u, pageSize=%u, totalSize=%u, usedSize=%u\r\n",
1712 layout->sectors, layout->sectorSize, layout->pagesPerSector, layout->pageSize, layout->totalSize, flashfsGetOffset());
1715 static void cliFlashErase(char *cmdline)
1717 UNUSED(cmdline);
1719 cliPrintf("Erasing...\r\n");
1720 flashfsEraseCompletely();
1722 while (!flashfsIsReady()) {
1723 delay(100);
1726 cliPrintf("Done.\r\n");
1729 #ifdef USE_FLASH_TOOLS
1731 static void cliFlashWrite(char *cmdline)
1733 uint32_t address = atoi(cmdline);
1734 char *text = strchr(cmdline, ' ');
1736 if (!text) {
1737 cliShowParseError();
1738 } else {
1739 flashfsSeekAbs(address);
1740 flashfsWrite((uint8_t*)text, strlen(text), true);
1741 flashfsFlushSync();
1743 cliPrintf("Wrote %u bytes at %u.\r\n", strlen(text), address);
1747 static void cliFlashRead(char *cmdline)
1749 uint32_t address = atoi(cmdline);
1750 uint32_t length;
1751 int i;
1753 uint8_t buffer[32];
1755 char *nextArg = strchr(cmdline, ' ');
1757 if (!nextArg) {
1758 cliShowParseError();
1759 } else {
1760 length = atoi(nextArg);
1762 cliPrintf("Reading %u bytes at %u:\r\n", length, address);
1764 while (length > 0) {
1765 int bytesRead;
1767 bytesRead = flashfsReadAbs(address, buffer, length < sizeof(buffer) ? length : sizeof(buffer));
1769 for (i = 0; i < bytesRead; i++) {
1770 cliWrite(buffer[i]);
1773 length -= bytesRead;
1774 address += bytesRead;
1776 if (bytesRead == 0) {
1777 //Assume we reached the end of the volume or something fatal happened
1778 break;
1781 cliPrintf("\r\n");
1785 #endif
1786 #endif
1788 #ifdef VTX
1789 static void cliVtx(char *cmdline)
1791 int i, val = 0;
1792 char *ptr;
1794 if (isEmpty(cmdline)) {
1795 // print out vtx channel settings
1796 for (i = 0; i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT; i++) {
1797 vtxChannelActivationCondition_t *cac = &masterConfig.vtxChannelActivationConditions[i];
1798 printf("vtx %u %u %u %u %u %u\r\n",
1800 cac->auxChannelIndex,
1801 cac->band,
1802 cac->channel,
1803 MODE_STEP_TO_CHANNEL_VALUE(cac->range.startStep),
1804 MODE_STEP_TO_CHANNEL_VALUE(cac->range.endStep)
1807 } else {
1808 ptr = cmdline;
1809 i = atoi(ptr++);
1810 if (i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT) {
1811 vtxChannelActivationCondition_t *cac = &masterConfig.vtxChannelActivationConditions[i];
1812 uint8_t validArgumentCount = 0;
1813 ptr = strchr(ptr, ' ');
1814 if (ptr) {
1815 val = atoi(++ptr);
1816 if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
1817 cac->auxChannelIndex = val;
1818 validArgumentCount++;
1821 ptr = strchr(ptr, ' ');
1822 if (ptr) {
1823 val = atoi(++ptr);
1824 if (val >= VTX_BAND_MIN && val <= VTX_BAND_MAX) {
1825 cac->band = val;
1826 validArgumentCount++;
1829 ptr = strchr(ptr, ' ');
1830 if (ptr) {
1831 val = atoi(++ptr);
1832 if (val >= VTX_CHANNEL_MIN && val <= VTX_CHANNEL_MAX) {
1833 cac->channel = val;
1834 validArgumentCount++;
1837 ptr = processChannelRangeArgs(ptr, &cac->range, &validArgumentCount);
1839 if (validArgumentCount != 5) {
1840 memset(cac, 0, sizeof(vtxChannelActivationCondition_t));
1842 } else {
1843 cliShowArgumentRangeError("index", 0, MAX_CHANNEL_ACTIVATION_CONDITION_COUNT - 1);
1847 #endif
1849 static void dumpValues(uint16_t valueSection)
1851 uint32_t i;
1852 const clivalue_t *value;
1853 for (i = 0; i < VALUE_COUNT; i++) {
1854 value = &valueTable[i];
1856 if ((value->type & VALUE_SECTION_MASK) != valueSection) {
1857 continue;
1860 cliPrintf("set %s = ", valueTable[i].name);
1861 cliPrintVar(value, 0);
1862 cliPrint("\r\n");
1866 typedef enum {
1867 DUMP_MASTER = (1 << 0),
1868 DUMP_PROFILE = (1 << 1),
1869 DUMP_RATES = (1 << 2),
1870 DUMP_ALL = (1 << 3),
1871 } dumpFlags_e;
1874 static const char* const sectionBreak = "\r\n";
1876 #define printSectionBreak() cliPrintf((char *)sectionBreak)
1878 static void cliDump(char *cmdline)
1880 unsigned int i;
1881 char buf[16];
1882 uint32_t mask;
1884 #ifndef USE_QUAD_MIXER_ONLY
1885 float thr, roll, pitch, yaw;
1886 #endif
1888 uint8_t dumpMask = DUMP_MASTER;
1889 if (strcasecmp(cmdline, "master") == 0) {
1890 dumpMask = DUMP_MASTER; // only
1892 if (strcasecmp(cmdline, "profile") == 0) {
1893 dumpMask = DUMP_PROFILE; // only
1895 if (strcasecmp(cmdline, "rates") == 0) {
1896 dumpMask = DUMP_RATES;
1899 if (strcasecmp(cmdline, "all") == 0) {
1900 dumpMask = DUMP_ALL; // All profiles and rates
1903 if ((dumpMask & DUMP_MASTER) || (dumpMask & DUMP_ALL)) {
1905 cliPrint("\r\n# version\r\n");
1906 cliVersion(NULL);
1908 cliPrint("\r\n# dump master\r\n");
1909 cliPrint("\r\n# mixer\r\n");
1911 #ifndef USE_QUAD_MIXER_ONLY
1912 cliPrintf("mixer %s\r\n", mixerNames[masterConfig.mixerMode - 1]);
1914 cliPrintf("mmix reset\r\n");
1916 for (i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
1917 if (masterConfig.customMotorMixer[i].throttle == 0.0f)
1918 break;
1919 thr = masterConfig.customMotorMixer[i].throttle;
1920 roll = masterConfig.customMotorMixer[i].roll;
1921 pitch = masterConfig.customMotorMixer[i].pitch;
1922 yaw = masterConfig.customMotorMixer[i].yaw;
1923 cliPrintf("mmix %d", i);
1924 if (thr < 0)
1925 cliWrite(' ');
1926 cliPrintf("%s", ftoa(thr, buf));
1927 if (roll < 0)
1928 cliWrite(' ');
1929 cliPrintf("%s", ftoa(roll, buf));
1930 if (pitch < 0)
1931 cliWrite(' ');
1932 cliPrintf("%s", ftoa(pitch, buf));
1933 if (yaw < 0)
1934 cliWrite(' ');
1935 cliPrintf("%s\r\n", ftoa(yaw, buf));
1938 #ifdef USE_SERVOS
1939 // print custom servo mixer if exists
1940 cliPrintf("smix reset\r\n");
1942 for (i = 0; i < MAX_SERVO_RULES; i++) {
1944 if (masterConfig.customServoMixer[i].rate == 0)
1945 break;
1947 cliPrintf("smix %d %d %d %d %d %d %d %d\r\n",
1949 masterConfig.customServoMixer[i].targetChannel,
1950 masterConfig.customServoMixer[i].inputSource,
1951 masterConfig.customServoMixer[i].rate,
1952 masterConfig.customServoMixer[i].speed,
1953 masterConfig.customServoMixer[i].min,
1954 masterConfig.customServoMixer[i].max,
1955 masterConfig.customServoMixer[i].box
1959 #endif
1960 #endif
1962 cliPrint("\r\n\r\n# feature\r\n");
1964 mask = featureMask();
1965 for (i = 0; ; i++) { // disable all feature first
1966 if (featureNames[i] == NULL)
1967 break;
1968 cliPrintf("feature -%s\r\n", featureNames[i]);
1970 for (i = 0; ; i++) { // reenable what we want.
1971 if (featureNames[i] == NULL)
1972 break;
1973 if (mask & (1 << i))
1974 cliPrintf("feature %s\r\n", featureNames[i]);
1978 #ifdef BEEPER
1979 cliPrint("\r\n\r\n# beeper\r\n");
1981 uint8_t beeperCount = beeperTableEntryCount();
1982 mask = getBeeperOffMask();
1983 for (int i = 0; i < (beeperCount-2); i++) {
1984 if (mask & (1 << i))
1985 cliPrintf("beeper -%s\r\n", beeperNameForTableIndex(i));
1986 else
1987 cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i));
1989 #endif
1992 cliPrint("\r\n\r\n# map\r\n");
1994 for (i = 0; i < 8; i++)
1995 buf[masterConfig.rxConfig.rcmap[i]] = rcChannelLetters[i];
1996 buf[i] = '\0';
1997 cliPrintf("map %s\r\n", buf);
1999 cliPrint("\r\n\r\n# serial\r\n");
2000 cliSerial("");
2002 #ifdef LED_STRIP
2003 cliPrint("\r\n\r\n# led\r\n");
2004 cliLed("");
2006 cliPrint("\r\n\r\n# color\r\n");
2007 cliColor("");
2008 #endif
2010 cliPrint("\r\n# aux\r\n");
2012 cliAux("");
2014 cliPrint("\r\n# adjrange\r\n");
2016 cliAdjustmentRange("");
2018 cliPrintf("\r\n# rxrange\r\n");
2020 cliRxRange("");
2022 #ifdef USE_SERVOS
2023 cliPrint("\r\n# servo\r\n");
2025 cliServo("");
2027 // print servo directions
2028 unsigned int channel;
2030 for (i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
2031 for (channel = 0; channel < INPUT_SOURCE_COUNT; channel++) {
2032 if (servoDirection(i, channel) < 0) {
2033 cliPrintf("smix reverse %d %d r\r\n", i , channel);
2037 #endif
2039 #ifdef VTX
2040 cliPrint("\r\n# vtx\r\n");
2042 cliVtx("");
2043 #endif
2045 printSectionBreak();
2046 dumpValues(MASTER_VALUE);
2048 cliPrint("\r\n# rxfail\r\n");
2049 cliRxFail("");
2051 if (dumpMask & DUMP_ALL) {
2052 uint8_t activeProfile = masterConfig.current_profile_index;
2053 uint8_t currentRateIndex = currentProfile->activeRateProfile;
2054 uint8_t profileCount;
2055 uint8_t rateCount;
2056 for (profileCount=0; profileCount<MAX_PROFILE_COUNT;profileCount++) {
2057 cliDumpProfile(profileCount);
2058 for (rateCount=0; rateCount<MAX_RATEPROFILES; rateCount++)
2059 cliDumpRateProfile(rateCount);
2062 cliPrint("\r\n# restore original profile / rateprofile selection\r\n");
2064 changeProfile(activeProfile);
2065 cliProfile("");
2066 printSectionBreak();
2068 changeControlRateProfile(currentRateIndex);
2069 cliRateProfile("");
2071 cliPrint("\r\n# save configuration\r\nsave\r\n");
2072 } else {
2073 cliDumpProfile(masterConfig.current_profile_index);
2074 cliDumpRateProfile(currentProfile->activeRateProfile);
2078 if (dumpMask & DUMP_PROFILE) {
2079 cliDumpProfile(masterConfig.current_profile_index);
2082 if (dumpMask & DUMP_RATES) {
2083 cliDumpRateProfile(currentProfile->activeRateProfile);
2088 void cliDumpProfile(uint8_t profileIndex) {
2089 if (profileIndex >= MAX_PROFILE_COUNT) // Faulty values
2090 return;
2092 changeProfile(profileIndex);
2093 cliPrint("\r\n# profile\r\n");
2094 cliProfile("");
2095 cliPrintf("############################# PROFILE VALUES ####################################\r\n");
2097 printSectionBreak();
2098 dumpValues(PROFILE_VALUE);
2100 cliRateProfile("");
2103 void cliDumpRateProfile(uint8_t rateProfileIndex) {
2104 if (rateProfileIndex >= MAX_RATEPROFILES) // Faulty values
2105 return;
2107 changeControlRateProfile(rateProfileIndex);
2108 cliPrint("\r\n# rateprofile\r\n");
2109 cliRateProfile("");
2110 printSectionBreak();
2112 dumpValues(PROFILE_RATE_VALUE);
2115 void cliEnter(serialPort_t *serialPort)
2117 cliMode = 1;
2118 cliPort = serialPort;
2119 setPrintfSerialPort(cliPort);
2120 cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer),
2121 (bufWrite_t)serialWriteBufShim, serialPort);
2123 cliPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n");
2124 cliPrompt();
2125 ENABLE_ARMING_FLAG(PREVENT_ARMING);
2128 static void cliExit(char *cmdline)
2130 UNUSED(cmdline);
2132 cliPrint("\r\nLeaving CLI mode, unsaved changes lost.\r\n");
2133 bufWriterFlush(cliWriter);
2135 *cliBuffer = '\0';
2136 bufferIndex = 0;
2137 cliMode = 0;
2138 // incase a motor was left running during motortest, clear it here
2139 mixerResetDisarmedMotors();
2140 cliReboot();
2142 cliWriter = NULL;
2145 static void cliFeature(char *cmdline)
2147 uint32_t i;
2148 uint32_t len;
2149 uint32_t mask;
2151 len = strlen(cmdline);
2152 mask = featureMask();
2154 if (len == 0) {
2155 cliPrint("Enabled: ");
2156 for (i = 0; ; i++) {
2157 if (featureNames[i] == NULL)
2158 break;
2159 if (mask & (1 << i))
2160 cliPrintf("%s ", featureNames[i]);
2162 cliPrint("\r\n");
2163 } else if (strncasecmp(cmdline, "list", len) == 0) {
2164 cliPrint("Available: ");
2165 for (i = 0; ; i++) {
2166 if (featureNames[i] == NULL)
2167 break;
2168 cliPrintf("%s ", featureNames[i]);
2170 cliPrint("\r\n");
2171 return;
2172 } else {
2173 bool remove = false;
2174 if (cmdline[0] == '-') {
2175 // remove feature
2176 remove = true;
2177 cmdline++; // skip over -
2178 len--;
2181 for (i = 0; ; i++) {
2182 if (featureNames[i] == NULL) {
2183 cliPrint("Invalid name\r\n");
2184 break;
2187 if (strncasecmp(cmdline, featureNames[i], len) == 0) {
2189 mask = 1 << i;
2190 #ifndef GPS
2191 if (mask & FEATURE_GPS) {
2192 cliPrint("unavailable\r\n");
2193 break;
2195 #endif
2196 #ifndef SONAR
2197 if (mask & FEATURE_SONAR) {
2198 cliPrint("unavailable\r\n");
2199 break;
2201 #endif
2202 if (remove) {
2203 featureClear(mask);
2204 cliPrint("Disabled");
2205 } else {
2206 featureSet(mask);
2207 cliPrint("Enabled");
2209 cliPrintf(" %s\r\n", featureNames[i]);
2210 break;
2216 #ifdef BEEPER
2217 static void cliBeeper(char *cmdline)
2219 uint32_t i;
2220 uint32_t len = strlen(cmdline);;
2221 uint8_t beeperCount = beeperTableEntryCount();
2222 uint32_t mask = getBeeperOffMask();
2224 if (len == 0) {
2225 cliPrintf("Disabled:");
2226 for (int i = 0; ; i++) {
2227 if (i == beeperCount-2){
2228 if (mask == 0)
2229 cliPrint(" none");
2230 break;
2232 if (mask & (1 << i))
2233 cliPrintf(" %s", beeperNameForTableIndex(i));
2235 cliPrint("\r\n");
2236 } else if (strncasecmp(cmdline, "list", len) == 0) {
2237 cliPrint("Available:");
2238 for (i = 0; i < beeperCount; i++)
2239 cliPrintf(" %s", beeperNameForTableIndex(i));
2240 cliPrint("\r\n");
2241 return;
2242 } else {
2243 bool remove = false;
2244 if (cmdline[0] == '-') {
2245 remove = true; // this is for beeper OFF condition
2246 cmdline++;
2247 len--;
2250 for (i = 0; ; i++) {
2251 if (i == beeperCount) {
2252 cliPrint("Invalid name\r\n");
2253 break;
2255 if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0) {
2256 if (remove) { // beeper off
2257 if (i == BEEPER_ALL-1)
2258 beeperOffSetAll(beeperCount-2);
2259 else
2260 if (i == BEEPER_PREFERENCE-1)
2261 setBeeperOffMask(getPreferredBeeperOffMask());
2262 else {
2263 mask = 1 << i;
2264 beeperOffSet(mask);
2266 cliPrint("Disabled");
2268 else { // beeper on
2269 if (i == BEEPER_ALL-1)
2270 beeperOffClearAll();
2271 else
2272 if (i == BEEPER_PREFERENCE-1)
2273 setPreferredBeeperOffMask(getBeeperOffMask());
2274 else {
2275 mask = 1 << i;
2276 beeperOffClear(mask);
2278 cliPrint("Enabled");
2280 cliPrintf(" %s\r\n", beeperNameForTableIndex(i));
2281 break;
2286 #endif
2289 #ifdef GPS
2290 static void cliGpsPassthrough(char *cmdline)
2292 UNUSED(cmdline);
2294 gpsEnablePassthrough(cliPort);
2296 #endif
2298 static void cliHelp(char *cmdline)
2300 uint32_t i = 0;
2302 UNUSED(cmdline);
2304 for (i = 0; i < CMD_COUNT; i++) {
2305 cliPrint(cmdTable[i].name);
2306 #ifndef SKIP_CLI_COMMAND_HELP
2307 if (cmdTable[i].description) {
2308 cliPrintf(" - %s", cmdTable[i].description);
2310 if (cmdTable[i].args) {
2311 cliPrintf("\r\n\t%s", cmdTable[i].args);
2313 #endif
2314 cliPrint("\r\n");
2318 static void cliMap(char *cmdline)
2320 uint32_t len;
2321 uint32_t i;
2322 char out[9];
2324 len = strlen(cmdline);
2326 if (len == 8) {
2327 // uppercase it
2328 for (i = 0; i < 8; i++)
2329 cmdline[i] = toupper((unsigned char)cmdline[i]);
2330 for (i = 0; i < 8; i++) {
2331 if (strchr(rcChannelLetters, cmdline[i]) && !strchr(cmdline + i + 1, cmdline[i]))
2332 continue;
2333 cliShowParseError();
2334 return;
2336 parseRcChannels(cmdline, &masterConfig.rxConfig);
2338 cliPrint("Map: ");
2339 for (i = 0; i < 8; i++)
2340 out[masterConfig.rxConfig.rcmap[i]] = rcChannelLetters[i];
2341 out[i] = '\0';
2342 cliPrintf("%s\r\n", out);
2345 #ifndef USE_QUAD_MIXER_ONLY
2346 static void cliMixer(char *cmdline)
2348 int i;
2349 int len;
2351 len = strlen(cmdline);
2353 if (len == 0) {
2354 cliPrintf("Mixer: %s\r\n", mixerNames[masterConfig.mixerMode - 1]);
2355 return;
2356 } else if (strncasecmp(cmdline, "list", len) == 0) {
2357 cliPrint("Available mixers: ");
2358 for (i = 0; ; i++) {
2359 if (mixerNames[i] == NULL)
2360 break;
2361 cliPrintf("%s ", mixerNames[i]);
2363 cliPrint("\r\n");
2364 return;
2367 for (i = 0; ; i++) {
2368 if (mixerNames[i] == NULL) {
2369 cliPrint("Invalid name\r\n");
2370 return;
2372 if (strncasecmp(cmdline, mixerNames[i], len) == 0) {
2373 masterConfig.mixerMode = i + 1;
2374 break;
2378 cliMixer("");
2380 #endif
2382 static void cliMotor(char *cmdline)
2384 int motor_index = 0;
2385 int motor_value = 0;
2386 int index = 0;
2387 char *pch = NULL;
2388 char *saveptr;
2390 if (isEmpty(cmdline)) {
2391 cliShowParseError();
2392 return;
2395 pch = strtok_r(cmdline, " ", &saveptr);
2396 while (pch != NULL) {
2397 switch (index) {
2398 case 0:
2399 motor_index = atoi(pch);
2400 break;
2401 case 1:
2402 motor_value = atoi(pch);
2403 break;
2405 index++;
2406 pch = strtok_r(NULL, " ", &saveptr);
2409 if (motor_index < 0 || motor_index >= MAX_SUPPORTED_MOTORS) {
2410 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
2411 return;
2414 if (index == 2) {
2415 if (motor_value < PWM_RANGE_MIN || motor_value > PWM_RANGE_MAX) {
2416 cliShowArgumentRangeError("value", 1000, 2000);
2417 return;
2418 } else {
2419 motor_disarmed[motor_index] = motor_value;
2423 cliPrintf("motor %d: %d\r\n", motor_index, motor_disarmed[motor_index]);
2426 static void cliPlaySound(char *cmdline)
2428 #if FLASH_SIZE <= 64
2429 UNUSED(cmdline);
2430 #else
2431 int i;
2432 const char *name;
2433 static int lastSoundIdx = -1;
2435 if (isEmpty(cmdline)) {
2436 i = lastSoundIdx + 1; //next sound index
2437 if ((name=beeperNameForTableIndex(i)) == NULL) {
2438 while (true) { //no name for index; try next one
2439 if (++i >= beeperTableEntryCount())
2440 i = 0; //if end then wrap around to first entry
2441 if ((name=beeperNameForTableIndex(i)) != NULL)
2442 break; //if name OK then play sound below
2443 if (i == lastSoundIdx + 1) { //prevent infinite loop
2444 cliPrintf("Error playing sound\r\n");
2445 return;
2449 } else { //index value was given
2450 i = atoi(cmdline);
2451 if ((name=beeperNameForTableIndex(i)) == NULL) {
2452 cliPrintf("No sound for index %d\r\n", i);
2453 return;
2456 lastSoundIdx = i;
2457 beeperSilence();
2458 cliPrintf("Playing sound %d: %s\r\n", i, name);
2459 beeper(beeperModeForTableIndex(i));
2460 #endif
2463 static void cliProfile(char *cmdline)
2465 int i;
2467 if (isEmpty(cmdline)) {
2468 cliPrintf("profile %d\r\n", getCurrentProfile());
2469 return;
2470 } else {
2471 i = atoi(cmdline);
2472 if (i >= 0 && i < MAX_PROFILE_COUNT) {
2473 masterConfig.current_profile_index = i;
2474 writeEEPROM();
2475 readEEPROM();
2476 cliProfile("");
2481 static void cliRateProfile(char *cmdline) {
2482 int i;
2484 if (isEmpty(cmdline)) {
2485 cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile());
2486 return;
2487 } else {
2488 i = atoi(cmdline);
2489 if (i >= 0 && i < MAX_RATEPROFILES) {
2490 changeControlRateProfile(i);
2491 cliRateProfile("");
2496 static void cliReboot(void) {
2497 cliPrint("\r\nRebooting");
2498 bufWriterFlush(cliWriter);
2499 waitForSerialPortToFinishTransmitting(cliPort);
2500 stopMotors();
2501 handleOneshotFeatureChangeOnRestart();
2502 systemReset();
2505 static void cliSave(char *cmdline)
2507 UNUSED(cmdline);
2509 cliPrint("Saving");
2510 //copyCurrentProfileToProfileSlot(masterConfig.current_profile_index);
2511 writeEEPROM();
2512 cliReboot();
2515 static void cliDefaults(char *cmdline)
2517 UNUSED(cmdline);
2519 cliPrint("Resetting to defaults");
2520 resetEEPROM();
2521 cliReboot();
2524 static void cliPrint(const char *str)
2526 while (*str)
2527 bufWriterAppend(cliWriter, *str++);
2530 static void cliPutp(void *p, char ch)
2532 bufWriterAppend(p, ch);
2535 static void cliPrintf(const char *fmt, ...)
2537 va_list va;
2538 va_start(va, fmt);
2539 tfp_format(cliWriter, cliPutp, fmt, va);
2540 va_end(va);
2543 static void cliWrite(uint8_t ch)
2545 bufWriterAppend(cliWriter, ch);
2548 static void cliPrintVar(const clivalue_t *var, uint32_t full)
2550 int32_t value = 0;
2551 char buf[8];
2553 void *ptr = var->ptr;
2554 if ((var->type & VALUE_SECTION_MASK) == PROFILE_VALUE) {
2555 ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * masterConfig.current_profile_index);
2558 if ((var->type & VALUE_SECTION_MASK) == PROFILE_RATE_VALUE) {
2559 ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * masterConfig.current_profile_index) + (sizeof(controlRateConfig_t) * getCurrentControlRateProfile());
2562 switch (var->type & VALUE_TYPE_MASK) {
2563 case VAR_UINT8:
2564 value = *(uint8_t *)ptr;
2565 break;
2567 case VAR_INT8:
2568 value = *(int8_t *)ptr;
2569 break;
2571 case VAR_UINT16:
2572 value = *(uint16_t *)ptr;
2573 break;
2575 case VAR_INT16:
2576 value = *(int16_t *)ptr;
2577 break;
2579 case VAR_UINT32:
2580 value = *(uint32_t *)ptr;
2581 break;
2583 case VAR_FLOAT:
2584 cliPrintf("%s", ftoa(*(float *)ptr, buf));
2585 if (full && (var->type & VALUE_MODE_MASK) == MODE_DIRECT) {
2586 cliPrintf(" %s", ftoa((float)var->config.minmax.min, buf));
2587 cliPrintf(" %s", ftoa((float)var->config.minmax.max, buf));
2589 return; // return from case for float only
2592 switch(var->type & VALUE_MODE_MASK) {
2593 case MODE_DIRECT:
2594 cliPrintf("%d", value);
2595 if (full) {
2596 cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max);
2598 break;
2599 case MODE_LOOKUP:
2600 cliPrintf(lookupTables[var->config.lookup.tableIndex].values[value]);
2601 break;
2604 static void cliPrintVarRange(const clivalue_t *var)
2606 switch (var->type & VALUE_MODE_MASK) {
2607 case (MODE_DIRECT): {
2608 cliPrintf("Allowed range: %d - %d\n", var->config.minmax.min, var->config.minmax.max);
2610 break;
2611 case (MODE_LOOKUP): {
2612 const lookupTableEntry_t *tableEntry = &lookupTables[var->config.lookup.tableIndex];
2613 cliPrint("Allowed values:");
2614 uint8_t i;
2615 for (i = 0; i < tableEntry->valueCount ; i++) {
2616 if (i > 0)
2617 cliPrint(",");
2618 cliPrintf(" %s", tableEntry->values[i]);
2620 cliPrint("\n");
2622 break;
2625 static void cliSetVar(const clivalue_t *var, const int_float_value_t value)
2627 void *ptr = var->ptr;
2628 if ((var->type & VALUE_SECTION_MASK) == PROFILE_VALUE) {
2629 ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * masterConfig.current_profile_index);
2631 if ((var->type & VALUE_SECTION_MASK) == PROFILE_RATE_VALUE) {
2632 ptr = ((uint8_t *)ptr) + (sizeof(profile_t) * masterConfig.current_profile_index) + (sizeof(controlRateConfig_t) * getCurrentControlRateProfile());
2635 switch (var->type & VALUE_TYPE_MASK) {
2636 case VAR_UINT8:
2637 case VAR_INT8:
2638 *(int8_t *)ptr = value.int_value;
2639 break;
2641 case VAR_UINT16:
2642 case VAR_INT16:
2643 *(int16_t *)ptr = value.int_value;
2644 break;
2646 case VAR_UINT32:
2647 *(uint32_t *)ptr = value.int_value;
2648 break;
2650 case VAR_FLOAT:
2651 *(float *)ptr = (float)value.float_value;
2652 break;
2656 static void cliSet(char *cmdline)
2658 uint32_t i;
2659 uint32_t len;
2660 const clivalue_t *val;
2661 char *eqptr = NULL;
2663 len = strlen(cmdline);
2665 if (len == 0 || (len == 1 && cmdline[0] == '*')) {
2666 cliPrint("Current settings: \r\n");
2667 for (i = 0; i < VALUE_COUNT; i++) {
2668 val = &valueTable[i];
2669 cliPrintf("%s = ", valueTable[i].name);
2670 cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
2671 cliPrint("\r\n");
2673 } else if ((eqptr = strstr(cmdline, "=")) != NULL) {
2674 // has equals
2676 char *lastNonSpaceCharacter = eqptr;
2677 while (*(lastNonSpaceCharacter - 1) == ' ') {
2678 lastNonSpaceCharacter--;
2680 uint8_t variableNameLength = lastNonSpaceCharacter - cmdline;
2682 // skip the '=' and any ' ' characters
2683 eqptr++;
2684 while (*(eqptr) == ' ') {
2685 eqptr++;
2688 for (i = 0; i < VALUE_COUNT; i++) {
2689 val = &valueTable[i];
2690 // ensure exact match when setting to prevent setting variables with shorter names
2691 if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
2693 bool changeValue = false;
2694 int_float_value_t tmp;
2695 switch (valueTable[i].type & VALUE_MODE_MASK) {
2696 case MODE_DIRECT: {
2697 int32_t value = 0;
2698 float valuef = 0;
2700 value = atoi(eqptr);
2701 valuef = fastA2F(eqptr);
2703 if (valuef >= valueTable[i].config.minmax.min && valuef <= valueTable[i].config.minmax.max) { // note: compare float value
2705 if ((valueTable[i].type & VALUE_TYPE_MASK) == VAR_FLOAT)
2706 tmp.float_value = valuef;
2707 else
2708 tmp.int_value = value;
2710 changeValue = true;
2713 break;
2714 case MODE_LOOKUP: {
2715 const lookupTableEntry_t *tableEntry = &lookupTables[valueTable[i].config.lookup.tableIndex];
2716 bool matched = false;
2717 for (uint8_t tableValueIndex = 0; tableValueIndex < tableEntry->valueCount && !matched; tableValueIndex++) {
2718 matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0;
2720 if (matched) {
2721 tmp.int_value = tableValueIndex;
2722 changeValue = true;
2726 break;
2729 if (changeValue) {
2730 cliSetVar(val, tmp);
2732 cliPrintf("%s set to ", valueTable[i].name);
2733 cliPrintVar(val, 0);
2734 } else {
2735 cliPrint("Invalid value\r\n");
2736 cliPrintVarRange(val);
2739 return;
2742 cliPrint("Invalid name\r\n");
2743 } else {
2744 // no equals, check for matching variables.
2745 cliGet(cmdline);
2749 static void cliGet(char *cmdline)
2751 uint32_t i;
2752 const clivalue_t *val;
2753 int matchedCommands = 0;
2755 for (i = 0; i < VALUE_COUNT; i++) {
2756 if (strstr(valueTable[i].name, cmdline)) {
2757 val = &valueTable[i];
2758 cliPrintf("%s = ", valueTable[i].name);
2759 cliPrintVar(val, 0);
2760 cliPrint("\n");
2761 cliPrintVarRange(val);
2762 cliPrint("\r\n");
2764 matchedCommands++;
2769 if (matchedCommands) {
2770 return;
2773 cliPrint("Invalid name\r\n");
2776 static void cliStatus(char *cmdline)
2778 UNUSED(cmdline);
2780 cliPrintf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery - %s), CPU:%d%%\r\n",
2781 millis() / 1000,
2782 vbat,
2783 batteryCellCount,
2784 getBatteryStateString(),
2785 constrain(averageSystemLoadPercent, 0, 100)
2788 cliPrintf("CPU Clock=%dMHz", (SystemCoreClock / 1000000));
2790 #ifndef CJMCU
2791 uint8_t i;
2792 uint32_t mask;
2793 uint32_t detectedSensorsMask = sensorsMask();
2795 for (i = 0; ; i++) {
2797 if (sensorTypeNames[i] == NULL)
2798 break;
2800 mask = (1 << i);
2801 if ((detectedSensorsMask & mask) && (mask & SENSOR_NAMES_MASK)) {
2802 const char *sensorHardware;
2803 uint8_t sensorHardwareIndex = detectedSensors[i];
2804 sensorHardware = sensorHardwareNames[i][sensorHardwareIndex];
2806 cliPrintf(", %s=%s", sensorTypeNames[i], sensorHardware);
2808 if (mask == SENSOR_ACC && acc.revisionCode) {
2809 cliPrintf(".%c", acc.revisionCode);
2813 #endif
2814 cliPrint("\r\n");
2816 #ifdef USE_I2C
2817 uint16_t i2cErrorCounter = i2cGetErrorCounter();
2818 #else
2819 uint16_t i2cErrorCounter = 0;
2820 #endif
2822 cliPrintf("Cycle Time: %d, I2C Errors: %d, config size: %d\r\n", cycleTime, i2cErrorCounter, sizeof(master_t));
2825 #ifndef SKIP_TASK_STATISTICS
2826 static void cliTasks(char *cmdline)
2828 UNUSED(cmdline);
2830 cfTaskId_e taskId;
2831 cfTaskInfo_t taskInfo;
2833 cliPrintf("Task list:\r\n");
2834 for (taskId = 0; taskId < TASK_COUNT; taskId++) {
2835 getTaskInfo(taskId, &taskInfo);
2836 if (taskInfo.isEnabled) {
2837 uint16_t taskFrequency;
2838 uint16_t subTaskFrequency;
2840 uint32_t taskTotalTime = taskInfo.totalExecutionTime / 1000;
2842 if (taskId == TASK_GYROPID) {
2843 subTaskFrequency = (uint16_t)(1.0f / ((float)cycleTime * 0.000001f));
2844 if (masterConfig.pid_process_denom > 1) {
2845 taskFrequency = subTaskFrequency / masterConfig.pid_process_denom;
2846 cliPrintf("%d - (%s) ", taskId, taskInfo.taskName);
2847 } else {
2848 taskFrequency = subTaskFrequency;
2849 cliPrintf("%d - (%s/%s) ", taskId, taskInfo.subTaskName, taskInfo.taskName);
2851 } else {
2852 taskFrequency = (uint16_t)(1.0f / ((float)taskInfo.latestDeltaTime * 0.000001f));
2853 cliPrintf("%d - (%s) ", taskId, taskInfo.taskName);
2856 cliPrintf("max: %dus, avg: %dus, rate: %dhz, total: ", taskInfo.maxExecutionTime, taskInfo.averageExecutionTime, taskFrequency);
2858 if (taskTotalTime >= 1000) {
2859 cliPrintf("%dsec", taskTotalTime / 1000);
2860 } else {
2861 cliPrintf("%dms", taskTotalTime);
2864 if (taskId == TASK_GYROPID && masterConfig.pid_process_denom > 1) cliPrintf("\r\n- - (%s) rate: %dhz", taskInfo.subTaskName, subTaskFrequency);
2865 cliPrintf("\r\n", taskTotalTime);
2869 #endif
2871 static void cliVersion(char *cmdline)
2873 UNUSED(cmdline);
2875 cliPrintf("# BetaFlight/%s %s %s / %s (%s)",
2876 targetName,
2877 FC_VERSION_STRING,
2878 buildDate,
2879 buildTime,
2880 shortGitRevision
2884 void cliProcess(void)
2886 if (!cliWriter) {
2887 return;
2890 // Be a little bit tricky. Flush the last inputs buffer, if any.
2891 bufWriterFlush(cliWriter);
2893 while (serialRxBytesWaiting(cliPort)) {
2894 uint8_t c = serialRead(cliPort);
2895 if (c == '\t' || c == '?') {
2896 // do tab completion
2897 const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
2898 uint32_t i = bufferIndex;
2899 for (cmd = cmdTable; cmd < cmdTable + CMD_COUNT; cmd++) {
2900 if (bufferIndex && (strncasecmp(cliBuffer, cmd->name, bufferIndex) != 0))
2901 continue;
2902 if (!pstart)
2903 pstart = cmd;
2904 pend = cmd;
2906 if (pstart) { /* Buffer matches one or more commands */
2907 for (; ; bufferIndex++) {
2908 if (pstart->name[bufferIndex] != pend->name[bufferIndex])
2909 break;
2910 if (!pstart->name[bufferIndex] && bufferIndex < sizeof(cliBuffer) - 2) {
2911 /* Unambiguous -- append a space */
2912 cliBuffer[bufferIndex++] = ' ';
2913 cliBuffer[bufferIndex] = '\0';
2914 break;
2916 cliBuffer[bufferIndex] = pstart->name[bufferIndex];
2919 if (!bufferIndex || pstart != pend) {
2920 /* Print list of ambiguous matches */
2921 cliPrint("\r\033[K");
2922 for (cmd = pstart; cmd <= pend; cmd++) {
2923 cliPrint(cmd->name);
2924 cliWrite('\t');
2926 cliPrompt();
2927 i = 0; /* Redraw prompt */
2929 for (; i < bufferIndex; i++)
2930 cliWrite(cliBuffer[i]);
2931 } else if (!bufferIndex && c == 4) { // CTRL-D
2932 cliExit(cliBuffer);
2933 return;
2934 } else if (c == 12) { // NewPage / CTRL-L
2935 // clear screen
2936 cliPrint("\033[2J\033[1;1H");
2937 cliPrompt();
2938 } else if (bufferIndex && (c == '\n' || c == '\r')) {
2939 // enter pressed
2940 cliPrint("\r\n");
2942 // Strip comment starting with # from line
2943 char *p = cliBuffer;
2944 p = strchr(p, '#');
2945 if (NULL != p) {
2946 bufferIndex = (uint32_t)(p - cliBuffer);
2949 // Strip trailing whitespace
2950 while (bufferIndex > 0 && cliBuffer[bufferIndex - 1] == ' ') {
2951 bufferIndex--;
2954 // Process non-empty lines
2955 if (bufferIndex > 0) {
2956 cliBuffer[bufferIndex] = 0; // null terminate
2958 const clicmd_t *cmd;
2959 for (cmd = cmdTable; cmd < cmdTable + CMD_COUNT; cmd++) {
2960 if(!strncasecmp(cliBuffer, cmd->name, strlen(cmd->name)) // command names match
2961 && !isalnum((unsigned)cliBuffer[strlen(cmd->name)])) // next characted in bufffer is not alphanumeric (command is correctly terminated)
2962 break;
2964 if(cmd < cmdTable + CMD_COUNT)
2965 cmd->func(cliBuffer + strlen(cmd->name) + 1);
2966 else
2967 cliPrint("Unknown command, try 'help'");
2968 bufferIndex = 0;
2971 memset(cliBuffer, 0, sizeof(cliBuffer));
2973 // 'exit' will reset this flag, so we don't need to print prompt again
2974 if (!cliMode)
2975 return;
2977 cliPrompt();
2978 } else if (c == 127) {
2979 // backspace
2980 if (bufferIndex) {
2981 cliBuffer[--bufferIndex] = 0;
2982 cliPrint("\010 \010");
2984 } else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) {
2985 if (!bufferIndex && c == ' ')
2986 continue; // Ignore leading spaces
2987 cliBuffer[bufferIndex++] = c;
2988 cliWrite(c);
2993 void cliInit(serialConfig_t *serialConfig)
2995 UNUSED(serialConfig);
2997 #endif