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/>.
27 #include "scheduler.h"
30 #include "build_config.h"
32 #include "common/axis.h"
33 #include "common/maths.h"
34 #include "common/color.h"
35 #include "common/typeconversion.h"
37 #include "drivers/system.h"
39 #include "drivers/sensor.h"
40 #include "drivers/accgyro.h"
41 #include "drivers/compass.h"
43 #include "drivers/serial.h"
44 #include "drivers/bus_i2c.h"
45 #include "drivers/gpio.h"
46 #include "drivers/timer.h"
47 #include "drivers/pwm_rx.h"
48 #include "drivers/sdcard.h"
49 #include "drivers/gyro_sync.h"
51 #include "drivers/buf_writer.h"
53 #include "io/escservo.h"
55 #include "io/gimbal.h"
56 #include "io/rc_controls.h"
57 #include "io/serial.h"
58 #include "io/ledstrip.h"
59 #include "io/flashfs.h"
60 #include "io/beeper.h"
61 #include "io/asyncfatfs/asyncfatfs.h"
64 #include "rx/spektrum.h"
66 #include "sensors/battery.h"
67 #include "sensors/boardalignment.h"
68 #include "sensors/sensors.h"
69 #include "sensors/acceleration.h"
70 #include "sensors/gyro.h"
71 #include "sensors/compass.h"
72 #include "sensors/barometer.h"
74 #include "flight/pid.h"
75 #include "flight/imu.h"
76 #include "flight/mixer.h"
77 #include "flight/navigation.h"
78 #include "flight/failsafe.h"
80 #include "telemetry/telemetry.h"
81 #include "telemetry/frsky.h"
83 #include "config/runtime_config.h"
84 #include "config/config.h"
85 #include "config/config_profile.h"
86 #include "config/config_master.h"
88 #include "common/printf.h"
90 #include "serial_cli.h"
92 // FIXME remove this for targets that don't need a CLI. Perhaps use a no-op macro when USE_CLI is not enabled
93 // signal that we're in cli mode
98 extern uint16_t cycleTime
; // FIXME dependency on mw.c
100 void gpsEnablePassthrough(serialPort_t
*gpsPassthroughPort
);
102 static serialPort_t
*cliPort
;
103 static bufWriter_t
*cliWriter
;
104 static uint8_t cliWriteBuffer
[sizeof(*cliWriter
) + 16];
106 static void cliAux(char *cmdline
);
107 static void cliRxFail(char *cmdline
);
108 static void cliAdjustmentRange(char *cmdline
);
109 static void cliMotorMix(char *cmdline
);
110 static void cliDefaults(char *cmdline
);
111 static void cliDump(char *cmdLine
);
112 void cliDumpProfile(uint8_t profileIndex
);
113 void cliDumpRateProfile(uint8_t rateProfileIndex
) ;
114 static void cliExit(char *cmdline
);
115 static void cliFeature(char *cmdline
);
116 static void cliMotor(char *cmdline
);
117 static void cliPlaySound(char *cmdline
);
118 static void cliProfile(char *cmdline
);
119 static void cliRateProfile(char *cmdline
);
120 static void cliReboot(void);
121 static void cliSave(char *cmdline
);
122 static void cliSerial(char *cmdline
);
123 #ifndef SKIP_SERIAL_PASSTHROUGH
124 static void cliSerialPassthrough(char *cmdline
);
128 static void cliServo(char *cmdline
);
129 static void cliServoMix(char *cmdline
);
132 static void cliSet(char *cmdline
);
133 static void cliGet(char *cmdline
);
134 static void cliStatus(char *cmdline
);
135 #ifndef SKIP_TASK_STATISTICS
136 static void cliTasks(char *cmdline
);
138 static void cliVersion(char *cmdline
);
139 static void cliRxRange(char *cmdline
);
142 static void cliGpsPassthrough(char *cmdline
);
145 static void cliHelp(char *cmdline
);
146 static void cliMap(char *cmdline
);
149 static void cliLed(char *cmdline
);
150 static void cliColor(char *cmdline
);
153 #ifndef USE_QUAD_MIXER_ONLY
154 static void cliMixer(char *cmdline
);
158 static void cliFlashInfo(char *cmdline
);
159 static void cliFlashErase(char *cmdline
);
160 #ifdef USE_FLASH_TOOLS
161 static void cliFlashWrite(char *cmdline
);
162 static void cliFlashRead(char *cmdline
);
167 static void cliSdInfo(char *cmdline
);
171 static void cliBeeper(char *cmdline
);
175 static char cliBuffer
[48];
176 static uint32_t bufferIndex
= 0;
178 #ifndef USE_QUAD_MIXER_ONLY
179 // sync this with mixerMode_e
180 static const char * const mixerNames
[] = {
181 "TRI", "QUADP", "QUADX", "BI",
182 "GIMBAL", "Y6", "HEX6",
183 "FLYING_WING", "Y4", "HEX6X", "OCTOX8", "OCTOFLATP", "OCTOFLATX",
184 "AIRPLANE", "HELI_120_CCPM", "HELI_90_DEG", "VTAIL4",
185 "HEX6H", "PPM_TO_SERVO", "DUALCOPTER", "SINGLECOPTER",
186 "ATAIL4", "CUSTOM", "CUSTOMAIRPLANE", "CUSTOMTRI", "QUADX1234", NULL
190 // sync this with features_e
191 static const char * const featureNames
[] = {
192 "RX_PPM", "VBAT", "INFLIGHT_ACC_CAL", "RX_SERIAL", "MOTOR_STOP",
193 "SERVO_TILT", "SOFTSERIAL", "GPS", "FAILSAFE",
194 "SONAR", "TELEMETRY", "CURRENT_METER", "3D", "RX_PARALLEL_PWM",
195 "RX_MSP", "RSSI_ADC", "LED_STRIP", "DISPLAY", "ONESHOT125",
196 "BLACKBOX", "CHANNEL_FORWARDING", "TRANSPONDER", NULL
199 // sync this with rxFailsafeChannelMode_e
200 static const char rxFailsafeModeCharacters
[] = "ahs";
202 static const rxFailsafeChannelMode_e rxFailsafeModesTable
[RX_FAILSAFE_TYPE_COUNT
][RX_FAILSAFE_MODE_COUNT
] = {
203 { RX_FAILSAFE_MODE_AUTO
, RX_FAILSAFE_MODE_HOLD
, RX_FAILSAFE_MODE_INVALID
},
204 { RX_FAILSAFE_MODE_INVALID
, RX_FAILSAFE_MODE_HOLD
, RX_FAILSAFE_MODE_SET
}
208 // sync this with sensors_e
209 static const char * const sensorTypeNames
[] = {
210 "GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
213 #define SENSOR_NAMES_MASK (SENSOR_GYRO | SENSOR_ACC | SENSOR_BARO | SENSOR_MAG)
215 static const char * const sensorHardwareNames
[4][11] = {
216 { "", "None", "MPU6050", "L3G4200D", "MPU3050", "L3GD20", "MPU6000", "MPU6500", "FAKE", NULL
},
217 { "", "None", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "FAKE", NULL
},
218 { "", "None", "BMP085", "MS5611", "BMP280", NULL
},
219 { "", "None", "HMC5883", "AK8975", "AK8963", NULL
}
225 #ifndef SKIP_CLI_COMMAND_HELP
226 const char *description
;
229 void (*func
)(char *cmdline
);
232 #ifndef SKIP_CLI_COMMAND_HELP
233 #define CLI_COMMAND_DEF(name, description, args, method) \
241 #define CLI_COMMAND_DEF(name, description, args, method) \
248 // should be sorted a..z for bsearch()
249 const clicmd_t cmdTable
[] = {
250 CLI_COMMAND_DEF("adjrange", "configure adjustment ranges", NULL
, cliAdjustmentRange
),
251 CLI_COMMAND_DEF("aux", "configure modes", NULL
, cliAux
),
253 CLI_COMMAND_DEF("color", "configure colors", NULL
, cliColor
),
255 CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", NULL
, cliDefaults
),
256 CLI_COMMAND_DEF("dump", "dump configuration",
257 "[master|profile]", cliDump
),
258 CLI_COMMAND_DEF("exit", NULL
, NULL
, cliExit
),
259 CLI_COMMAND_DEF("feature", "configure features",
261 "\t<+|->[name]", cliFeature
),
263 CLI_COMMAND_DEF("flash_erase", "erase flash chip", NULL
, cliFlashErase
),
264 CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL
, cliFlashInfo
),
265 #ifdef USE_FLASH_TOOLS
266 CLI_COMMAND_DEF("flash_read", NULL
, "<length> <address>", cliFlashRead
),
267 CLI_COMMAND_DEF("flash_write", NULL
, "<address> <message>", cliFlashWrite
),
270 CLI_COMMAND_DEF("get", "get variable value",
273 CLI_COMMAND_DEF("gpspassthrough", "passthrough gps to serial", NULL
, cliGpsPassthrough
),
275 CLI_COMMAND_DEF("help", NULL
, NULL
, cliHelp
),
277 CLI_COMMAND_DEF("led", "configure leds", NULL
, cliLed
),
279 CLI_COMMAND_DEF("map", "configure rc channel order",
281 #ifndef USE_QUAD_MIXER_ONLY
282 CLI_COMMAND_DEF("mixer", "configure mixer",
284 "\t<name>", cliMixer
),
286 CLI_COMMAND_DEF("mmix", "custom motor mixer", NULL
, cliMotorMix
),
287 CLI_COMMAND_DEF("motor", "get/set motor",
288 "<index> [<value>]", cliMotor
),
289 CLI_COMMAND_DEF("play_sound", NULL
,
290 "[<index>]\r\n", cliPlaySound
),
291 CLI_COMMAND_DEF("profile", "change profile",
292 "[<index>]", cliProfile
),
293 CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile
),
294 CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL
, cliRxRange
),
295 CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL
, cliRxFail
),
296 CLI_COMMAND_DEF("save", "save and reboot", NULL
, cliSave
),
297 CLI_COMMAND_DEF("serial", "configure serial ports", NULL
, cliSerial
),
298 #ifndef SKIP_SERIAL_PASSTHROUGH
299 CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port",
300 "<id> [baud] [mode] : passthrough to serial",
301 cliSerialPassthrough
),
304 CLI_COMMAND_DEF("servo", "configure servos", NULL
, cliServo
),
306 CLI_COMMAND_DEF("set", "change setting",
307 "[<name>=<value>]", cliSet
),
309 CLI_COMMAND_DEF("smix", "servo mixer",
310 "<rule> <servo> <source> <rate> <speed> <min> <max> <box>\r\n"
313 "\treverse <servo> <source> r|n", cliServoMix
),
316 CLI_COMMAND_DEF("sd_info", "sdcard info", NULL
, cliSdInfo
),
318 CLI_COMMAND_DEF("status", "show status", NULL
, cliStatus
),
319 #ifndef SKIP_TASK_STATISTICS
320 CLI_COMMAND_DEF("tasks", "show task stats", NULL
, cliTasks
),
322 CLI_COMMAND_DEF("version", "show version", NULL
, cliVersion
),
324 CLI_COMMAND_DEF("beeper", "turn on/off beeper", "list\r\n"
325 "\t<+|->[name]", cliBeeper
),
328 #define CMD_COUNT (sizeof(cmdTable) / sizeof(clicmd_t))
330 static const char * const lookupTableOffOn
[] = {
334 static const char * const lookupTableUnit
[] = {
338 static const char * const lookupTableAlignment
[] = {
351 static const char * const lookupTableGPSProvider
[] = {
355 static const char * const lookupTableGPSSBASMode
[] = {
356 "AUTO", "EGNOS", "WAAS", "MSAS", "GAGAN"
360 static const char * const lookupTableCurrentSensor
[] = {
361 "NONE", "ADC", "VIRTUAL"
364 static const char * const lookupTableGimbalMode
[] = {
368 static const char * const lookupTableBlackboxDevice
[] = {
369 "SERIAL", "SPIFLASH", "SDCARD"
373 static const char * const lookupTablePidController
[] = {
374 "MW23", "MWREWRITE", "LUX"
377 static const char * const lookupTableSerialRX
[] = {
389 static const char * const lookupTableGyroLpf
[] = {
400 static const char * const lookupTableAccHardware
[] = {
413 static const char * const lookupTableBaroHardware
[] = {
421 static const char * const lookupTableMagHardware
[] = {
429 static const char * const lookupDeltaMethod
[] = {
430 "ERROR", "MEASUREMENT"
433 static const char * const lookupTableDebug
[] = {
443 typedef struct lookupTableEntry_s
{
444 const char * const *values
;
445 const uint8_t valueCount
;
446 } lookupTableEntry_t
;
457 TABLE_BLACKBOX_DEVICE
,
459 TABLE_CURRENT_SENSOR
,
461 TABLE_PID_CONTROLLER
,
469 } lookupTableIndex_e
;
471 static const lookupTableEntry_t lookupTables
[] = {
472 { lookupTableOffOn
, sizeof(lookupTableOffOn
) / sizeof(char *) },
473 { lookupTableUnit
, sizeof(lookupTableUnit
) / sizeof(char *) },
474 { lookupTableAlignment
, sizeof(lookupTableAlignment
) / sizeof(char *) },
476 { lookupTableGPSProvider
, sizeof(lookupTableGPSProvider
) / sizeof(char *) },
477 { lookupTableGPSSBASMode
, sizeof(lookupTableGPSSBASMode
) / sizeof(char *) },
480 { lookupTableBlackboxDevice
, sizeof(lookupTableBlackboxDevice
) / sizeof(char *) },
482 { lookupTableCurrentSensor
, sizeof(lookupTableCurrentSensor
) / sizeof(char *) },
483 { lookupTableGimbalMode
, sizeof(lookupTableGimbalMode
) / sizeof(char *) },
484 { lookupTablePidController
, sizeof(lookupTablePidController
) / sizeof(char *) },
485 { lookupTableSerialRX
, sizeof(lookupTableSerialRX
) / sizeof(char *) },
486 { lookupTableGyroLpf
, sizeof(lookupTableGyroLpf
) / sizeof(char *) },
487 { lookupTableAccHardware
, sizeof(lookupTableAccHardware
) / sizeof(char *) },
488 { lookupTableBaroHardware
, sizeof(lookupTableBaroHardware
) / sizeof(char *) },
489 { lookupTableMagHardware
, sizeof(lookupTableMagHardware
) / sizeof(char *) },
490 { lookupDeltaMethod
, sizeof(lookupDeltaMethod
) / sizeof(char *) },
491 { lookupTableDebug
, sizeof(lookupTableDebug
) / sizeof(char *) }
494 #define VALUE_TYPE_OFFSET 0
495 #define VALUE_SECTION_OFFSET 4
496 #define VALUE_MODE_OFFSET 6
500 VAR_UINT8
= (0 << VALUE_TYPE_OFFSET
),
501 VAR_INT8
= (1 << VALUE_TYPE_OFFSET
),
502 VAR_UINT16
= (2 << VALUE_TYPE_OFFSET
),
503 VAR_INT16
= (3 << VALUE_TYPE_OFFSET
),
504 VAR_UINT32
= (4 << VALUE_TYPE_OFFSET
),
505 VAR_FLOAT
= (5 << VALUE_TYPE_OFFSET
),
508 MASTER_VALUE
= (0 << VALUE_SECTION_OFFSET
),
509 PROFILE_VALUE
= (1 << VALUE_SECTION_OFFSET
),
510 PROFILE_RATE_VALUE
= (2 << VALUE_SECTION_OFFSET
),
512 MODE_DIRECT
= (0 << VALUE_MODE_OFFSET
),
513 MODE_LOOKUP
= (1 << VALUE_MODE_OFFSET
)
516 #define VALUE_TYPE_MASK (0x0F)
517 #define VALUE_SECTION_MASK (0x30)
518 #define VALUE_MODE_MASK (0xC0)
520 typedef struct cliMinMaxConfig_s
{
525 typedef struct cliLookupTableConfig_s
{
526 const lookupTableIndex_e tableIndex
;
527 } cliLookupTableConfig_t
;
530 cliLookupTableConfig_t lookup
;
531 cliMinMaxConfig_t minmax
;
537 const uint8_t type
; // see cliValueFlag_e
539 const cliValueConfig_t config
;
542 const clivalue_t valueTable
[] = {
543 // { "emf_avoidance", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.emf_avoidance, .config.lookup = { TABLE_OFF_ON } },
545 { "mid_rc", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.rxConfig
.midrc
, .config
.minmax
= { 1200, 1700 } },
546 { "min_check", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.rxConfig
.mincheck
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
547 { "max_check", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.rxConfig
.maxcheck
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
548 { "rssi_channel", VAR_INT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.rssi_channel
, .config
.minmax
= { 0, MAX_SUPPORTED_RC_CHANNEL_COUNT
} },
549 { "rssi_scale", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.rssi_scale
, .config
.minmax
= { RSSI_SCALE_MIN
, RSSI_SCALE_MAX
} },
550 { "rssi_ppm_invert", VAR_INT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.rxConfig
.rssi_ppm_invert
, .config
.lookup
= { TABLE_OFF_ON
} },
551 { "input_filtering_mode", VAR_INT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.inputFilteringMode
, .config
.lookup
= { TABLE_OFF_ON
} },
552 { "rc_smoothing", VAR_INT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.rxConfig
.rcSmoothing
, .config
.lookup
= { TABLE_OFF_ON
} },
553 { "roll_yaw_cam_mix_degrees", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.fpvCamAngleDegrees
, .config
.minmax
= { 0, 50 } },
554 { "max_aux_channels", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.max_aux_channel
, .config
.minmax
= { 0, 13 } },
555 { "debug_mode", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.debug_mode
, .config
.lookup
= { TABLE_DEBUG
} },
557 { "min_throttle", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.escAndServoConfig
.minthrottle
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
558 { "max_throttle", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.escAndServoConfig
.maxthrottle
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
559 { "min_command", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.escAndServoConfig
.mincommand
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
560 { "servo_center_pulse", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.escAndServoConfig
.servoCenterPulse
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
562 { "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
563 { "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,
564 { "3d_neutral", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.flight3DConfig
.neutral3d
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
565 { "3d_deadband_throttle", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.flight3DConfig
.deadband3d_throttle
, .config
.minmax
= { PWM_RANGE_ZERO
, PWM_RANGE_MAX
} },
567 { "use_oneshot42", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.use_oneshot42
, .config
.lookup
= { TABLE_OFF_ON
} },
568 { "use_multishot", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.use_multiShot
, .config
.lookup
= { TABLE_OFF_ON
} },
570 { "enable_buzzer_p6", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.use_buzzer_p6
, .config
.lookup
= { TABLE_OFF_ON
} },
572 { "motor_pwm_rate", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.motor_pwm_rate
, .config
.minmax
= { 300, 32000 } },
573 { "servo_pwm_rate", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.servo_pwm_rate
, .config
.minmax
= { 50, 498 } },
575 { "disarm_kill_switch", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.disarm_kill_switch
, .config
.lookup
= { TABLE_OFF_ON
} },
576 { "gyro_cal_on_first_arm", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gyro_cal_on_first_arm
, .config
.lookup
= { TABLE_OFF_ON
} },
577 { "auto_disarm_delay", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.auto_disarm_delay
, .config
.minmax
= { 0, 60 } },
578 { "small_angle", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.small_angle
, .config
.minmax
= { 0, 180 } },
580 { "fixedwing_althold_dir", VAR_INT8
| MASTER_VALUE
, &masterConfig
.airplaneConfig
.fixedwing_althold_dir
, .config
.minmax
= { -1, 1 } },
582 { "reboot_character", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.serialConfig
.reboot_character
, .config
.minmax
= { 48, 126 } },
585 { "gps_provider", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gpsConfig
.provider
, .config
.lookup
= { TABLE_GPS_PROVIDER
} },
586 { "gps_sbas_mode", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gpsConfig
.sbasMode
, .config
.lookup
= { TABLE_GPS_SBAS_MODE
} },
587 { "gps_auto_config", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gpsConfig
.autoConfig
, .config
.lookup
= { TABLE_OFF_ON
} },
588 { "gps_auto_baud", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gpsConfig
.autoBaud
, .config
.lookup
= { TABLE_OFF_ON
} },
590 { "gps_pos_p", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDPOS
], .config
.minmax
= { 0, 200 } },
591 { "gps_pos_i", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDPOS
], .config
.minmax
= { 0, 200 } },
592 { "gps_pos_d", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDPOS
], .config
.minmax
= { 0, 200 } },
593 { "gps_posr_p", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDPOSR
], .config
.minmax
= { 0, 200 } },
594 { "gps_posr_i", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDPOSR
], .config
.minmax
= { 0, 200 } },
595 { "gps_posr_d", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDPOSR
], .config
.minmax
= { 0, 200 } },
596 { "gps_nav_p", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDNAVR
], .config
.minmax
= { 0, 200 } },
597 { "gps_nav_i", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDNAVR
], .config
.minmax
= { 0, 200 } },
598 { "gps_nav_d", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDNAVR
], .config
.minmax
= { 0, 200 } },
599 { "gps_wp_radius", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.gpsProfile
.gps_wp_radius
, .config
.minmax
= { 0, 2000 } },
600 { "nav_controls_heading", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gpsProfile
.nav_controls_heading
, .config
.lookup
= { TABLE_OFF_ON
} },
601 { "nav_speed_min", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.gpsProfile
.nav_speed_min
, .config
.minmax
= { 10, 2000 } },
602 { "nav_speed_max", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.gpsProfile
.nav_speed_max
, .config
.minmax
= { 10, 2000 } },
603 { "nav_slew_rate", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.gpsProfile
.nav_slew_rate
, .config
.minmax
= { 0, 100 } },
606 { "gtune_loP_rll", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_lolimP
[FD_ROLL
], .config
.minmax
= { 10, 200 } },
607 { "gtune_loP_ptch", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_lolimP
[FD_PITCH
], .config
.minmax
= { 10, 200 } },
608 { "gtune_loP_yw", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_lolimP
[FD_YAW
], .config
.minmax
= { 10, 200 } },
609 { "gtune_hiP_rll", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_hilimP
[FD_ROLL
], .config
.minmax
= { 0, 200 } },
610 { "gtune_hiP_ptch", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_hilimP
[FD_PITCH
], .config
.minmax
= { 0, 200 } },
611 { "gtune_hiP_yw", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_hilimP
[FD_YAW
], .config
.minmax
= { 0, 200 } },
612 { "gtune_pwr", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_pwr
, .config
.minmax
= { 0, 10 } },
613 { "gtune_settle_time", VAR_UINT16
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_settle_time
, .config
.minmax
= { 200, 1000 } },
614 { "gtune_average_cycles", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.gtune_average_cycles
, .config
.minmax
= { 8, 128 } },
617 { "serialrx_provider", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.rxConfig
.serialrx_provider
, .config
.lookup
= { TABLE_SERIAL_RX
} },
618 { "sbus_inversion", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.rxConfig
.sbus_inversion
, .config
.lookup
= { TABLE_OFF_ON
} },
619 { "spektrum_sat_bind", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.spektrum_sat_bind
, .config
.minmax
= { SPEKTRUM_SAT_BIND_DISABLED
, SPEKTRUM_SAT_BIND_MAX
} },
620 { "spektrum_sat_bind_autoreset",VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.spektrum_sat_bind_autoreset
, .config
.minmax
= { 0, 1} },
622 { "telemetry_switch", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.telemetryConfig
.telemetry_switch
, .config
.lookup
= { TABLE_OFF_ON
} },
623 { "telemetry_inversion", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.telemetryConfig
.telemetry_inversion
, .config
.lookup
= { TABLE_OFF_ON
} },
624 { "frsky_default_lattitude", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.telemetryConfig
.gpsNoFixLatitude
, .config
.minmax
= { -90.0, 90.0 } },
625 { "frsky_default_longitude", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.telemetryConfig
.gpsNoFixLongitude
, .config
.minmax
= { -180.0, 180.0 } },
626 { "frsky_coordinates_format", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.telemetryConfig
.frsky_coordinate_format
, .config
.minmax
= { 0, FRSKY_FORMAT_NMEA
} },
627 { "frsky_unit", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.telemetryConfig
.frsky_unit
, .config
.lookup
= { TABLE_UNIT
} },
628 { "frsky_vfas_precision", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.telemetryConfig
.frsky_vfas_precision
, .config
.minmax
= { FRSKY_VFAS_PRECISION_LOW
, FRSKY_VFAS_PRECISION_HIGH
} },
629 { "frsky_vfas_cell_voltage", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.telemetryConfig
.frsky_vfas_cell_voltage
, .config
.lookup
= { TABLE_OFF_ON
} },
630 { "hott_alarm_sound_interval", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.telemetryConfig
.hottAlarmSoundInterval
, .config
.minmax
= { 0, 120 } },
632 { "battery_capacity", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.batteryConfig
.batteryCapacity
, .config
.minmax
= { 0, 20000 } },
633 { "vbat_scale", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.batteryConfig
.vbatscale
, .config
.minmax
= { VBAT_SCALE_MIN
, VBAT_SCALE_MAX
} },
634 { "vbat_max_cell_voltage", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.batteryConfig
.vbatmaxcellvoltage
, .config
.minmax
= { 10, 50 } },
635 { "vbat_min_cell_voltage", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.batteryConfig
.vbatmincellvoltage
, .config
.minmax
= { 10, 50 } },
636 { "vbat_warning_cell_voltage", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.batteryConfig
.vbatwarningcellvoltage
, .config
.minmax
= { 10, 50 } },
637 { "vbat_hysteresis", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.batteryConfig
.vbathysteresis
, .config
.minmax
= { 0, 250 } },
638 { "vbat_pid_compensation", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.batteryConfig
.vbatPidCompensation
, .config
.lookup
= { TABLE_OFF_ON
} },
639 { "current_meter_scale", VAR_INT16
| MASTER_VALUE
, &masterConfig
.batteryConfig
.currentMeterScale
, .config
.minmax
= { -10000, 10000 } },
640 { "current_meter_offset", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.batteryConfig
.currentMeterOffset
, .config
.minmax
= { 0, 3300 } },
641 { "multiwii_current_meter_output", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.batteryConfig
.multiwiiCurrentMeterOutput
, .config
.lookup
= { TABLE_OFF_ON
} },
642 { "current_meter_type", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.batteryConfig
.currentMeterType
, .config
.lookup
= { TABLE_CURRENT_SENSOR
} },
644 { "align_gyro", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.sensorAlignmentConfig
.gyro_align
, .config
.lookup
= { TABLE_ALIGNMENT
} },
645 { "align_acc", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.sensorAlignmentConfig
.acc_align
, .config
.lookup
= { TABLE_ALIGNMENT
} },
646 { "align_mag", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.sensorAlignmentConfig
.mag_align
, .config
.lookup
= { TABLE_ALIGNMENT
} },
648 { "align_board_roll", VAR_INT16
| MASTER_VALUE
, &masterConfig
.boardAlignment
.rollDegrees
, .config
.minmax
= { -180, 360 } },
649 { "align_board_pitch", VAR_INT16
| MASTER_VALUE
, &masterConfig
.boardAlignment
.pitchDegrees
, .config
.minmax
= { -180, 360 } },
650 { "align_board_yaw", VAR_INT16
| MASTER_VALUE
, &masterConfig
.boardAlignment
.yawDegrees
, .config
.minmax
= { -180, 360 } },
652 { "max_angle_inclination", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.max_angle_inclination
, .config
.minmax
= { 100, 900 } },
654 { "gyro_lpf", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gyro_lpf
, .config
.lookup
= { TABLE_GYRO_LPF
} },
655 { "gyro_sync_denom", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.gyro_sync_denom
, .config
.minmax
= { 1, 8 } },
656 { "gyro_lowpass_hz", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.gyro_soft_lpf_hz
, .config
.minmax
= { 0, 500 } },
657 { "moron_threshold", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.gyroConfig
.gyroMovementCalibrationThreshold
, .config
.minmax
= { 0, 128 } },
658 { "imu_dcm_kp", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.dcm_kp
, .config
.minmax
= { 0, 50000 } },
659 { "imu_dcm_ki", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.dcm_ki
, .config
.minmax
= { 0, 50000 } },
661 { "alt_hold_deadband", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rcControlsConfig
.alt_hold_deadband
, .config
.minmax
= { 1, 250 } },
662 { "alt_hold_fast_change", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.rcControlsConfig
.alt_hold_fast_change
, .config
.lookup
= { TABLE_OFF_ON
} },
663 { "deadband", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rcControlsConfig
.deadband
, .config
.minmax
= { 0, 32 } },
664 { "yaw_deadband", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rcControlsConfig
.yaw_deadband
, .config
.minmax
= { 0, 100 } },
666 { "throttle_correction_value", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.throttle_correction_value
, .config
.minmax
= { 0, 150 } },
667 { "throttle_correction_angle", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.throttle_correction_angle
, .config
.minmax
= { 1, 900 } },
669 { "yaw_control_direction", VAR_INT8
| MASTER_VALUE
, &masterConfig
.yaw_control_direction
, .config
.minmax
= { -1, 1 } },
671 { "yaw_motor_direction", VAR_INT8
| MASTER_VALUE
, &masterConfig
.mixerConfig
.yaw_motor_direction
, .config
.minmax
= { -1, 1 } },
672 { "yaw_jump_prevention_limit", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.mixerConfig
.yaw_jump_prevention_limit
, .config
.minmax
= { YAW_JUMP_PREVENTION_LIMIT_LOW
, YAW_JUMP_PREVENTION_LIMIT_HIGH
} },
673 { "yaw_p_limit", VAR_UINT16
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.yaw_p_limit
, .config
.minmax
= { YAW_P_LIMIT_MIN
, YAW_P_LIMIT_MAX
} },
675 { "tri_unarmed_servo", VAR_INT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.mixerConfig
.tri_unarmed_servo
, .config
.lookup
= { TABLE_OFF_ON
} },
676 { "servo_lowpass_freq", VAR_INT16
| MASTER_VALUE
, &masterConfig
.mixerConfig
.servo_lowpass_freq
, .config
.minmax
= { 10, 400} },
677 { "servo_lowpass_enable", VAR_INT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.mixerConfig
.servo_lowpass_enable
, .config
.lookup
= { TABLE_OFF_ON
} },
680 { "rc_rate", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].rcRate8
, .config
.minmax
= { 0, 250 } },
681 { "rc_expo", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].rcExpo8
, .config
.minmax
= { 0, 100 } },
682 { "rc_yaw_expo", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].rcYawExpo8
, .config
.minmax
= { 0, 100 } },
683 { "thr_mid", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].thrMid8
, .config
.minmax
= { 0, 100 } },
684 { "thr_expo", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].thrExpo8
, .config
.minmax
= { 0, 100 } },
685 { "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
} },
686 { "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
} },
687 { "yaw_rate", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].rates
[FD_YAW
], .config
.minmax
= { 0, CONTROL_RATE_CONFIG_YAW_RATE_MAX
} },
688 { "tpa_rate", VAR_UINT8
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].dynThrPID
, .config
.minmax
= { 0, CONTROL_RATE_CONFIG_TPA_MAX
} },
689 { "tpa_breakpoint", VAR_UINT16
| PROFILE_RATE_VALUE
, &masterConfig
.profile
[0].controlRateProfile
[0].tpa_breakpoint
, .config
.minmax
= { PWM_RANGE_MIN
, PWM_RANGE_MAX
} },
690 { "super_expo_factor", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.rxConfig
.superExpoFactor
, .config
.minmax
= {1, 100 } },
692 { "failsafe_delay", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.failsafeConfig
.failsafe_delay
, .config
.minmax
= { 0, 200 } },
693 { "failsafe_off_delay", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.failsafeConfig
.failsafe_off_delay
, .config
.minmax
= { 0, 200 } },
694 { "failsafe_throttle", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.failsafeConfig
.failsafe_throttle
, .config
.minmax
= { PWM_RANGE_MIN
, PWM_RANGE_MAX
} },
695 { "failsafe_kill_switch", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.failsafeConfig
.failsafe_kill_switch
, .config
.lookup
= { TABLE_OFF_ON
} },
696 { "failsafe_throttle_low_delay",VAR_UINT16
| MASTER_VALUE
, &masterConfig
.failsafeConfig
.failsafe_throttle_low_delay
, .config
.minmax
= { 0, 300 } },
697 { "failsafe_procedure", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.failsafeConfig
.failsafe_procedure
, .config
.lookup
= { TABLE_OFF_ON
} },
699 { "rx_min_usec", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.rxConfig
.rx_min_usec
, .config
.minmax
= { PWM_PULSE_MIN
, PWM_PULSE_MAX
} },
700 { "rx_max_usec", VAR_UINT16
| MASTER_VALUE
, &masterConfig
.rxConfig
.rx_max_usec
, .config
.minmax
= { PWM_PULSE_MIN
, PWM_PULSE_MAX
} },
703 { "gimbal_mode", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gimbalConfig
.mode
, .config
.lookup
= { TABLE_GIMBAL_MODE
} },
706 { "acc_hardware", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.acc_hardware
, .config
.lookup
= { TABLE_ACC_HARDWARE
} },
707 { "acc_lpf_hz", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.acc_lpf_hz
, .config
.minmax
= { 0, 400 } },
708 { "accxy_deadband", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.accDeadband
.xy
, .config
.minmax
= { 0, 100 } },
709 { "accz_deadband", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.accDeadband
.z
, .config
.minmax
= { 0, 100 } },
710 { "acc_unarmedcal", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.acc_unarmedcal
, .config
.lookup
= { TABLE_OFF_ON
} },
711 { "acc_trim_pitch", VAR_INT16
| MASTER_VALUE
, &masterConfig
.accelerometerTrims
.values
.pitch
, .config
.minmax
= { -300, 300 } },
712 { "acc_trim_roll", VAR_INT16
| MASTER_VALUE
, &masterConfig
.accelerometerTrims
.values
.roll
, .config
.minmax
= { -300, 300 } },
714 { "baro_tab_size", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.barometerConfig
.baro_sample_count
, .config
.minmax
= { 0, BARO_SAMPLE_COUNT_MAX
} },
715 { "baro_noise_lpf", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.barometerConfig
.baro_noise_lpf
, .config
.minmax
= { 0 , 1 } },
716 { "baro_cf_vel", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.barometerConfig
.baro_cf_vel
, .config
.minmax
= { 0 , 1 } },
717 { "baro_cf_alt", VAR_FLOAT
| MASTER_VALUE
, &masterConfig
.barometerConfig
.baro_cf_alt
, .config
.minmax
= { 0 , 1 } },
718 { "baro_hardware", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.baro_hardware
, .config
.lookup
= { TABLE_BARO_HARDWARE
} },
720 { "mag_hardware", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.mag_hardware
, .config
.lookup
= { TABLE_MAG_HARDWARE
} },
721 { "mag_declination", VAR_INT16
| MASTER_VALUE
, &masterConfig
.mag_declination
, .config
.minmax
= { -18000, 18000 } },
722 { "pid_delta_method", VAR_UINT8
| PROFILE_VALUE
| MODE_LOOKUP
, &masterConfig
.profile
[0].pidProfile
.deltaMethod
, .config
.lookup
= { TABLE_DELTA_METHOD
} },
723 { "dterm_lowpass_hz", VAR_FLOAT
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.dterm_lpf_hz
, .config
.minmax
= {0, 500 } },
724 { "dterm_average_count", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.dterm_average_count
, .config
.minmax
= {0, 12 } },
725 { "iterm_reset_degrees", VAR_UINT16
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.rollPitchItermResetRate
, .config
.minmax
= {50, 1000 } },
726 { "yaw_iterm_reset_degrees", VAR_UINT16
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.yawItermResetRate
, .config
.minmax
= {25, 1000 } },
727 { "yaw_lowpass_hz", VAR_FLOAT
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.yaw_lpf_hz
, .config
.minmax
= {0, 500 } },
728 { "pid_process_denom", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.pid_process_denom
, .config
.minmax
= { 1, 8 } },
730 { "pid_controller", VAR_UINT8
| PROFILE_VALUE
| MODE_LOOKUP
, &masterConfig
.profile
[0].pidProfile
.pidController
, .config
.lookup
= { TABLE_PID_CONTROLLER
} },
732 { "p_pitch", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PITCH
], .config
.minmax
= { 0, 200 } },
733 { "i_pitch", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PITCH
], .config
.minmax
= { 0, 200 } },
734 { "d_pitch", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PITCH
], .config
.minmax
= { 0, 200 } },
735 { "p_roll", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[ROLL
], .config
.minmax
= { 0, 200 } },
736 { "i_roll", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[ROLL
], .config
.minmax
= { 0, 200 } },
737 { "d_roll", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[ROLL
], .config
.minmax
= { 0, 200 } },
738 { "p_yaw", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[YAW
], .config
.minmax
= { 0, 200 } },
739 { "i_yaw", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[YAW
], .config
.minmax
= { 0, 200 } },
740 { "d_yaw", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[YAW
], .config
.minmax
= { 0, 200 } },
742 { "p_alt", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDALT
], .config
.minmax
= { 0, 200 } },
743 { "i_alt", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDALT
], .config
.minmax
= { 0, 200 } },
744 { "d_alt", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDALT
], .config
.minmax
= { 0, 200 } },
746 { "p_level", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDLEVEL
], .config
.minmax
= { 0, 200 } },
747 { "i_level", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDLEVEL
], .config
.minmax
= { 0, 200 } },
748 { "d_level", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDLEVEL
], .config
.minmax
= { 0, 200 } },
750 { "p_vel", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.P8
[PIDVEL
], .config
.minmax
= { 0, 200 } },
751 { "i_vel", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.I8
[PIDVEL
], .config
.minmax
= { 0, 200 } },
752 { "d_vel", VAR_UINT8
| PROFILE_VALUE
, &masterConfig
.profile
[0].pidProfile
.D8
[PIDVEL
], .config
.minmax
= { 0, 200 } },
755 { "blackbox_rate_num", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.blackbox_rate_num
, .config
.minmax
= { 1, 32 } },
756 { "blackbox_rate_denom", VAR_UINT8
| MASTER_VALUE
, &masterConfig
.blackbox_rate_denom
, .config
.minmax
= { 1, 32 } },
757 { "blackbox_device", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.blackbox_device
, .config
.lookup
= { TABLE_BLACKBOX_DEVICE
} },
760 { "magzero_x", VAR_INT16
| MASTER_VALUE
, &masterConfig
.magZero
.raw
[X
], .config
.minmax
= { -32768, 32767 } },
761 { "magzero_y", VAR_INT16
| MASTER_VALUE
, &masterConfig
.magZero
.raw
[Y
], .config
.minmax
= { -32768, 32767 } },
762 { "magzero_z", VAR_INT16
| MASTER_VALUE
, &masterConfig
.magZero
.raw
[Z
], .config
.minmax
= { -32768, 32767 } },
765 #define VALUE_COUNT (sizeof(valueTable) / sizeof(clivalue_t))
773 static void cliSetVar(const clivalue_t
*var
, const int_float_value_t value
);
774 static void cliPrintVar(const clivalue_t
*var
, uint32_t full
);
775 static void cliPrintVarRange(const clivalue_t
*var
);
776 static void cliPrint(const char *str
);
777 static void cliPrintf(const char *fmt
, ...);
778 static void cliWrite(uint8_t ch
);
780 static void cliPrompt(void)
783 bufWriterFlush(cliWriter
);
786 static void cliShowParseError(void)
788 cliPrint("Parse error\r\n");
791 static void cliShowArgumentRangeError(char *name
, int min
, int max
)
793 cliPrintf("%s must be between %d and %d\r\n", name
, min
, max
);
796 static char *processChannelRangeArgs(char *ptr
, channelRange_t
*range
, uint8_t *validArgumentCount
)
800 for (int argIndex
= 0; argIndex
< 2; argIndex
++) {
801 ptr
= strchr(ptr
, ' ');
804 val
= CHANNEL_VALUE_TO_STEP(val
);
805 if (val
>= MIN_MODE_RANGE_STEP
&& val
<= MAX_MODE_RANGE_STEP
) {
807 range
->startStep
= val
;
809 range
->endStep
= val
;
811 (*validArgumentCount
)++;
819 // Check if a string's length is zero
820 static bool isEmpty(const char *string
)
822 return *string
== '\0';
825 static void cliRxFail(char *cmdline
)
830 if (isEmpty(cmdline
)) {
831 // print out rxConfig failsafe settings
832 for (channel
= 0; channel
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; channel
++) {
833 cliRxFail(itoa(channel
, buf
, 10));
837 channel
= atoi(ptr
++);
838 if ((channel
< MAX_SUPPORTED_RC_CHANNEL_COUNT
)) {
840 rxFailsafeChannelConfiguration_t
*channelFailsafeConfiguration
= &masterConfig
.rxConfig
.failsafe_channel_configurations
[channel
];
843 rxFailsafeChannelType_e type
= (channel
< NON_AUX_CHANNEL_COUNT
) ? RX_FAILSAFE_TYPE_FLIGHT
: RX_FAILSAFE_TYPE_AUX
;
844 rxFailsafeChannelMode_e mode
= channelFailsafeConfiguration
->mode
;
845 bool requireValue
= channelFailsafeConfiguration
->mode
== RX_FAILSAFE_MODE_SET
;
847 ptr
= strchr(ptr
, ' ');
849 char *p
= strchr(rxFailsafeModeCharacters
, *(++ptr
));
851 uint8_t requestedMode
= p
- rxFailsafeModeCharacters
;
852 mode
= rxFailsafeModesTable
[type
][requestedMode
];
854 mode
= RX_FAILSAFE_MODE_INVALID
;
856 if (mode
== RX_FAILSAFE_MODE_INVALID
) {
861 requireValue
= mode
== RX_FAILSAFE_MODE_SET
;
863 ptr
= strchr(ptr
, ' ');
870 value
= CHANNEL_VALUE_TO_RXFAIL_STEP(value
);
871 if (value
> MAX_RXFAIL_RANGE_STEP
) {
872 cliPrint("Value out of range\r\n");
876 channelFailsafeConfiguration
->step
= value
;
877 } else if (requireValue
) {
881 channelFailsafeConfiguration
->mode
= mode
;
885 char modeCharacter
= rxFailsafeModeCharacters
[channelFailsafeConfiguration
->mode
];
887 // triple use of cliPrintf below
888 // 1. acknowledge interpretation on command,
889 // 2. query current setting on single item,
890 // 3. recursive use for full list.
893 cliPrintf("rxfail %u %c %d\r\n",
896 RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfiguration
->step
)
899 cliPrintf("rxfail %u %c\r\n",
905 cliShowArgumentRangeError("channel", 0, MAX_SUPPORTED_RC_CHANNEL_COUNT
- 1);
910 static void cliAux(char *cmdline
)
915 if (isEmpty(cmdline
)) {
916 // print out aux channel settings
917 for (i
= 0; i
< MAX_MODE_ACTIVATION_CONDITION_COUNT
; i
++) {
918 modeActivationCondition_t
*mac
= &masterConfig
.modeActivationConditions
[i
];
919 cliPrintf("aux %u %u %u %u %u\r\n",
922 mac
->auxChannelIndex
,
923 MODE_STEP_TO_CHANNEL_VALUE(mac
->range
.startStep
),
924 MODE_STEP_TO_CHANNEL_VALUE(mac
->range
.endStep
)
930 if (i
< MAX_MODE_ACTIVATION_CONDITION_COUNT
) {
931 modeActivationCondition_t
*mac
= &masterConfig
.modeActivationConditions
[i
];
932 uint8_t validArgumentCount
= 0;
933 ptr
= strchr(ptr
, ' ');
936 if (val
>= 0 && val
< CHECKBOX_ITEM_COUNT
) {
938 validArgumentCount
++;
941 ptr
= strchr(ptr
, ' ');
944 if (val
>= 0 && val
< MAX_AUX_CHANNEL_COUNT
) {
945 mac
->auxChannelIndex
= val
;
946 validArgumentCount
++;
949 ptr
= processChannelRangeArgs(ptr
, &mac
->range
, &validArgumentCount
);
951 if (validArgumentCount
!= 4) {
952 memset(mac
, 0, sizeof(modeActivationCondition_t
));
955 cliShowArgumentRangeError("index", 0, MAX_MODE_ACTIVATION_CONDITION_COUNT
- 1);
960 static void cliSerial(char *cmdline
)
965 if (isEmpty(cmdline
)) {
966 for (i
= 0; i
< SERIAL_PORT_COUNT
; i
++) {
967 if (!serialIsPortAvailable(masterConfig
.serialConfig
.portConfigs
[i
].identifier
)) {
970 cliPrintf("serial %d %d %ld %ld %ld %ld\r\n" ,
971 masterConfig
.serialConfig
.portConfigs
[i
].identifier
,
972 masterConfig
.serialConfig
.portConfigs
[i
].functionMask
,
973 baudRates
[masterConfig
.serialConfig
.portConfigs
[i
].msp_baudrateIndex
],
974 baudRates
[masterConfig
.serialConfig
.portConfigs
[i
].gps_baudrateIndex
],
975 baudRates
[masterConfig
.serialConfig
.portConfigs
[i
].telemetry_baudrateIndex
],
976 baudRates
[masterConfig
.serialConfig
.portConfigs
[i
].blackbox_baudrateIndex
]
982 serialPortConfig_t portConfig
;
983 memset(&portConfig
, 0 , sizeof(portConfig
));
985 serialPortConfig_t
*currentConfig
;
987 uint8_t validArgumentCount
= 0;
992 currentConfig
= serialFindPortConfiguration(val
);
994 portConfig
.identifier
= val
;
995 validArgumentCount
++;
998 ptr
= strchr(ptr
, ' ');
1001 portConfig
.functionMask
= val
& 0xFFFF;
1002 validArgumentCount
++;
1005 for (i
= 0; i
< 4; i
++) {
1006 ptr
= strchr(ptr
, ' ');
1013 uint8_t baudRateIndex
= lookupBaudRateIndex(val
);
1014 if (baudRates
[baudRateIndex
] != (uint32_t) val
) {
1020 if (baudRateIndex
< BAUD_9600
|| baudRateIndex
> BAUD_115200
) {
1023 portConfig
.msp_baudrateIndex
= baudRateIndex
;
1026 if (baudRateIndex
< BAUD_9600
|| baudRateIndex
> BAUD_115200
) {
1029 portConfig
.gps_baudrateIndex
= baudRateIndex
;
1032 if (baudRateIndex
!= BAUD_AUTO
&& baudRateIndex
> BAUD_115200
) {
1035 portConfig
.telemetry_baudrateIndex
= baudRateIndex
;
1038 if (baudRateIndex
< BAUD_19200
|| baudRateIndex
> BAUD_250000
) {
1041 portConfig
.blackbox_baudrateIndex
= baudRateIndex
;
1045 validArgumentCount
++;
1048 if (validArgumentCount
< 6) {
1049 cliShowParseError();
1053 memcpy(currentConfig
, &portConfig
, sizeof(portConfig
));
1057 #ifndef SKIP_SERIAL_PASSTHROUGH
1058 static void cliSerialPassthrough(char *cmdline
)
1060 if (isEmpty(cmdline
)) {
1061 cliShowParseError();
1068 char* tok
= strtok(cmdline
, " ");
1071 while (tok
!= NULL
) {
1080 if (strstr(tok
, "rx") || strstr(tok
, "RX"))
1082 if (strstr(tok
, "tx") || strstr(tok
, "TX"))
1087 tok
= strtok(NULL
, " ");
1090 serialPort_t
*passThroughPort
;
1091 serialPortUsage_t
*passThroughPortUsage
= findSerialPortUsageByIdentifier(id
);
1092 if (!passThroughPortUsage
|| passThroughPortUsage
->serialPort
== NULL
) {
1094 printf("Port %d is not open, you must specify baud\r\n", id
);
1100 passThroughPort
= openSerialPort(id
, FUNCTION_PASSTHROUGH
, NULL
,
1102 SERIAL_NOT_INVERTED
);
1103 if (!passThroughPort
) {
1104 printf("Port %d could not be opened\r\n", id
);
1107 printf("Port %d opened, baud=%d\r\n", id
, baud
);
1109 passThroughPort
= passThroughPortUsage
->serialPort
;
1110 // If the user supplied a mode, override the port's mode, otherwise
1111 // leave the mode unchanged. serialPassthrough() handles one-way ports.
1112 printf("Port %d already open\r\n", id
);
1113 if (mode
&& passThroughPort
->mode
!= mode
) {
1114 printf("Adjusting mode from configured value %d to %d\r\n",
1115 passThroughPort
->mode
, mode
);
1116 serialSetMode(passThroughPort
, mode
);
1120 printf("Relaying data to device on port %d, Reset your board to exit "
1121 "serial passthrough mode.\r\n");
1123 serialPassthrough(cliPort
, passThroughPort
, NULL
, NULL
);
1127 static void cliAdjustmentRange(char *cmdline
)
1132 if (isEmpty(cmdline
)) {
1133 // print out adjustment ranges channel settings
1134 for (i
= 0; i
< MAX_ADJUSTMENT_RANGE_COUNT
; i
++) {
1135 adjustmentRange_t
*ar
= &masterConfig
.adjustmentRanges
[i
];
1136 cliPrintf("adjrange %u %u %u %u %u %u %u\r\n",
1138 ar
->adjustmentIndex
,
1139 ar
->auxChannelIndex
,
1140 MODE_STEP_TO_CHANNEL_VALUE(ar
->range
.startStep
),
1141 MODE_STEP_TO_CHANNEL_VALUE(ar
->range
.endStep
),
1142 ar
->adjustmentFunction
,
1143 ar
->auxSwitchChannelIndex
1149 if (i
< MAX_ADJUSTMENT_RANGE_COUNT
) {
1150 adjustmentRange_t
*ar
= &masterConfig
.adjustmentRanges
[i
];
1151 uint8_t validArgumentCount
= 0;
1153 ptr
= strchr(ptr
, ' ');
1156 if (val
>= 0 && val
< MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
) {
1157 ar
->adjustmentIndex
= val
;
1158 validArgumentCount
++;
1161 ptr
= strchr(ptr
, ' ');
1164 if (val
>= 0 && val
< MAX_AUX_CHANNEL_COUNT
) {
1165 ar
->auxChannelIndex
= val
;
1166 validArgumentCount
++;
1170 ptr
= processChannelRangeArgs(ptr
, &ar
->range
, &validArgumentCount
);
1172 ptr
= strchr(ptr
, ' ');
1175 if (val
>= 0 && val
< ADJUSTMENT_FUNCTION_COUNT
) {
1176 ar
->adjustmentFunction
= val
;
1177 validArgumentCount
++;
1180 ptr
= strchr(ptr
, ' ');
1183 if (val
>= 0 && val
< MAX_AUX_CHANNEL_COUNT
) {
1184 ar
->auxSwitchChannelIndex
= val
;
1185 validArgumentCount
++;
1189 if (validArgumentCount
!= 6) {
1190 memset(ar
, 0, sizeof(adjustmentRange_t
));
1191 cliShowParseError();
1194 cliShowArgumentRangeError("index", 0, MAX_ADJUSTMENT_RANGE_COUNT
- 1);
1199 static void cliMotorMix(char *cmdline
)
1201 #ifdef USE_QUAD_MIXER_ONLY
1210 if (isEmpty(cmdline
)) {
1211 cliPrint("Motor\tThr\tRoll\tPitch\tYaw\r\n");
1212 for (i
= 0; i
< MAX_SUPPORTED_MOTORS
; i
++) {
1213 if (masterConfig
.customMotorMixer
[i
].throttle
== 0.0f
)
1216 cliPrintf("#%d:\t", i
);
1217 cliPrintf("%s\t", ftoa(masterConfig
.customMotorMixer
[i
].throttle
, buf
));
1218 cliPrintf("%s\t", ftoa(masterConfig
.customMotorMixer
[i
].roll
, buf
));
1219 cliPrintf("%s\t", ftoa(masterConfig
.customMotorMixer
[i
].pitch
, buf
));
1220 cliPrintf("%s\r\n", ftoa(masterConfig
.customMotorMixer
[i
].yaw
, buf
));
1223 } else if (strncasecmp(cmdline
, "reset", 5) == 0) {
1224 // erase custom mixer
1225 for (i
= 0; i
< MAX_SUPPORTED_MOTORS
; i
++)
1226 masterConfig
.customMotorMixer
[i
].throttle
= 0.0f
;
1227 } else if (strncasecmp(cmdline
, "load", 4) == 0) {
1228 ptr
= strchr(cmdline
, ' ');
1230 len
= strlen(++ptr
);
1231 for (i
= 0; ; i
++) {
1232 if (mixerNames
[i
] == NULL
) {
1233 cliPrint("Invalid name\r\n");
1236 if (strncasecmp(ptr
, mixerNames
[i
], len
) == 0) {
1237 mixerLoadMix(i
, masterConfig
.customMotorMixer
);
1238 cliPrintf("Loaded %s\r\n", mixerNames
[i
]);
1246 i
= atoi(ptr
); // get motor number
1247 if (i
< MAX_SUPPORTED_MOTORS
) {
1248 ptr
= strchr(ptr
, ' ');
1250 masterConfig
.customMotorMixer
[i
].throttle
= fastA2F(++ptr
);
1253 ptr
= strchr(ptr
, ' ');
1255 masterConfig
.customMotorMixer
[i
].roll
= fastA2F(++ptr
);
1258 ptr
= strchr(ptr
, ' ');
1260 masterConfig
.customMotorMixer
[i
].pitch
= fastA2F(++ptr
);
1263 ptr
= strchr(ptr
, ' ');
1265 masterConfig
.customMotorMixer
[i
].yaw
= fastA2F(++ptr
);
1269 cliShowParseError();
1274 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS
- 1);
1280 static void cliRxRange(char *cmdline
)
1282 int i
, validArgumentCount
= 0;
1285 if (isEmpty(cmdline
)) {
1286 for (i
= 0; i
< NON_AUX_CHANNEL_COUNT
; i
++) {
1287 rxChannelRangeConfiguration_t
*channelRangeConfiguration
= &masterConfig
.rxConfig
.channelRanges
[i
];
1288 cliPrintf("rxrange %u %u %u\r\n", i
, channelRangeConfiguration
->min
, channelRangeConfiguration
->max
);
1290 } else if (strcasecmp(cmdline
, "reset") == 0) {
1291 resetAllRxChannelRangeConfigurations(masterConfig
.rxConfig
.channelRanges
);
1295 if (i
>= 0 && i
< NON_AUX_CHANNEL_COUNT
) {
1296 int rangeMin
, rangeMax
;
1298 ptr
= strchr(ptr
, ' ');
1300 rangeMin
= atoi(++ptr
);
1301 validArgumentCount
++;
1304 ptr
= strchr(ptr
, ' ');
1306 rangeMax
= atoi(++ptr
);
1307 validArgumentCount
++;
1310 if (validArgumentCount
!= 2) {
1311 cliShowParseError();
1312 } else if (rangeMin
< PWM_PULSE_MIN
|| rangeMin
> PWM_PULSE_MAX
|| rangeMax
< PWM_PULSE_MIN
|| rangeMax
> PWM_PULSE_MAX
) {
1313 cliShowParseError();
1315 rxChannelRangeConfiguration_t
*channelRangeConfiguration
= &masterConfig
.rxConfig
.channelRanges
[i
];
1316 channelRangeConfiguration
->min
= rangeMin
;
1317 channelRangeConfiguration
->max
= rangeMax
;
1320 cliShowArgumentRangeError("channel", 0, NON_AUX_CHANNEL_COUNT
- 1);
1326 static void cliLed(char *cmdline
)
1330 char ledConfigBuffer
[20];
1332 if (isEmpty(cmdline
)) {
1333 for (i
= 0; i
< MAX_LED_STRIP_LENGTH
; i
++) {
1334 generateLedConfig(i
, ledConfigBuffer
, sizeof(ledConfigBuffer
));
1335 cliPrintf("led %u %s\r\n", i
, ledConfigBuffer
);
1340 if (i
< MAX_LED_STRIP_LENGTH
) {
1341 ptr
= strchr(cmdline
, ' ');
1342 if (!parseLedStripConfig(i
, ++ptr
)) {
1343 cliShowParseError();
1346 cliShowArgumentRangeError("index", 0, MAX_LED_STRIP_LENGTH
- 1);
1351 static void cliColor(char *cmdline
)
1356 if (isEmpty(cmdline
)) {
1357 for (i
= 0; i
< CONFIGURABLE_COLOR_COUNT
; i
++) {
1358 cliPrintf("color %u %d,%u,%u\r\n",
1360 masterConfig
.colors
[i
].h
,
1361 masterConfig
.colors
[i
].s
,
1362 masterConfig
.colors
[i
].v
1368 if (i
< CONFIGURABLE_COLOR_COUNT
) {
1369 ptr
= strchr(cmdline
, ' ');
1370 if (!parseColor(i
, ++ptr
)) {
1371 cliShowParseError();
1374 cliShowArgumentRangeError("index", 0, CONFIGURABLE_COLOR_COUNT
- 1);
1381 static void cliServo(char *cmdline
)
1383 enum { SERVO_ARGUMENT_COUNT
= 8 };
1384 int16_t arguments
[SERVO_ARGUMENT_COUNT
];
1386 servoParam_t
*servo
;
1391 if (isEmpty(cmdline
)) {
1392 // print out servo settings
1393 for (i
= 0; i
< MAX_SUPPORTED_SERVOS
; i
++) {
1394 servo
= &masterConfig
.servoConf
[i
];
1396 cliPrintf("servo %u %d %d %d %d %d %d %d\r\n",
1404 servo
->forwardFromChannel
1408 int validArgumentCount
= 0;
1412 // Command line is integers (possibly negative) separated by spaces, no other characters allowed.
1414 // If command line doesn't fit the format, don't modify the config
1416 if (*ptr
== '-' || (*ptr
>= '0' && *ptr
<= '9')) {
1417 if (validArgumentCount
>= SERVO_ARGUMENT_COUNT
) {
1418 cliShowParseError();
1422 arguments
[validArgumentCount
++] = atoi(ptr
);
1426 } while (*ptr
>= '0' && *ptr
<= '9');
1427 } else if (*ptr
== ' ') {
1430 cliShowParseError();
1435 enum {INDEX
= 0, MIN
, MAX
, MIDDLE
, ANGLE_AT_MIN
, ANGLE_AT_MAX
, RATE
, FORWARD
};
1437 i
= arguments
[INDEX
];
1439 // Check we got the right number of args and the servo index is correct (don't validate the other values)
1440 if (validArgumentCount
!= SERVO_ARGUMENT_COUNT
|| i
< 0 || i
>= MAX_SUPPORTED_SERVOS
) {
1441 cliShowParseError();
1445 servo
= &masterConfig
.servoConf
[i
];
1448 arguments
[MIN
] < PWM_PULSE_MIN
|| arguments
[MIN
] > PWM_PULSE_MAX
||
1449 arguments
[MAX
] < PWM_PULSE_MIN
|| arguments
[MAX
] > PWM_PULSE_MAX
||
1450 arguments
[MIDDLE
] < arguments
[MIN
] || arguments
[MIDDLE
] > arguments
[MAX
] ||
1451 arguments
[MIN
] > arguments
[MAX
] || arguments
[MAX
] < arguments
[MIN
] ||
1452 arguments
[RATE
] < -100 || arguments
[RATE
] > 100 ||
1453 arguments
[FORWARD
] >= MAX_SUPPORTED_RC_CHANNEL_COUNT
||
1454 arguments
[ANGLE_AT_MIN
] < 0 || arguments
[ANGLE_AT_MIN
] > 180 ||
1455 arguments
[ANGLE_AT_MAX
] < 0 || arguments
[ANGLE_AT_MAX
] > 180
1457 cliShowParseError();
1461 servo
->min
= arguments
[1];
1462 servo
->max
= arguments
[2];
1463 servo
->middle
= arguments
[3];
1464 servo
->angleAtMin
= arguments
[4];
1465 servo
->angleAtMax
= arguments
[5];
1466 servo
->rate
= arguments
[6];
1467 servo
->forwardFromChannel
= arguments
[7];
1473 static void cliServoMix(char *cmdline
)
1478 int args
[8], check
= 0;
1479 len
= strlen(cmdline
);
1483 cliPrint("Rule\tServo\tSource\tRate\tSpeed\tMin\tMax\tBox\r\n");
1485 for (i
= 0; i
< MAX_SERVO_RULES
; i
++) {
1486 if (masterConfig
.customServoMixer
[i
].rate
== 0)
1489 cliPrintf("#%d:\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
1491 masterConfig
.customServoMixer
[i
].targetChannel
,
1492 masterConfig
.customServoMixer
[i
].inputSource
,
1493 masterConfig
.customServoMixer
[i
].rate
,
1494 masterConfig
.customServoMixer
[i
].speed
,
1495 masterConfig
.customServoMixer
[i
].min
,
1496 masterConfig
.customServoMixer
[i
].max
,
1497 masterConfig
.customServoMixer
[i
].box
1502 } else if (strncasecmp(cmdline
, "reset", 5) == 0) {
1503 // erase custom mixer
1504 memset(masterConfig
.customServoMixer
, 0, sizeof(masterConfig
.customServoMixer
));
1505 for (i
= 0; i
< MAX_SUPPORTED_SERVOS
; i
++) {
1506 masterConfig
.servoConf
[i
].reversedSources
= 0;
1508 } else if (strncasecmp(cmdline
, "load", 4) == 0) {
1509 ptr
= strchr(cmdline
, ' ');
1511 len
= strlen(++ptr
);
1512 for (i
= 0; ; i
++) {
1513 if (mixerNames
[i
] == NULL
) {
1514 cliPrintf("Invalid name\r\n");
1517 if (strncasecmp(ptr
, mixerNames
[i
], len
) == 0) {
1518 servoMixerLoadMix(i
, masterConfig
.customServoMixer
);
1519 cliPrintf("Loaded %s\r\n", mixerNames
[i
]);
1525 } else if (strncasecmp(cmdline
, "reverse", 7) == 0) {
1526 enum {SERVO
= 0, INPUT
, REVERSE
, ARGS_COUNT
};
1527 int servoIndex
, inputSource
;
1528 ptr
= strchr(cmdline
, ' ');
1533 for (inputSource
= 0; inputSource
< INPUT_SOURCE_COUNT
; inputSource
++)
1534 cliPrintf("\ti%d", inputSource
);
1537 for (servoIndex
= 0; servoIndex
< MAX_SUPPORTED_SERVOS
; servoIndex
++) {
1538 cliPrintf("%d", servoIndex
);
1539 for (inputSource
= 0; inputSource
< INPUT_SOURCE_COUNT
; inputSource
++)
1540 cliPrintf("\t%s ", (masterConfig
.servoConf
[servoIndex
].reversedSources
& (1 << inputSource
)) ? "r" : "n");
1546 ptr
= strtok(ptr
, " ");
1547 while (ptr
!= NULL
&& check
< ARGS_COUNT
- 1) {
1548 args
[check
++] = atoi(ptr
);
1549 ptr
= strtok(NULL
, " ");
1552 if (ptr
== NULL
|| check
!= ARGS_COUNT
- 1) {
1553 cliShowParseError();
1557 if (args
[SERVO
] >= 0 && args
[SERVO
] < MAX_SUPPORTED_SERVOS
1558 && args
[INPUT
] >= 0 && args
[INPUT
] < INPUT_SOURCE_COUNT
1559 && (*ptr
== 'r' || *ptr
== 'n')) {
1561 masterConfig
.servoConf
[args
[SERVO
]].reversedSources
|= 1 << args
[INPUT
];
1563 masterConfig
.servoConf
[args
[SERVO
]].reversedSources
&= ~(1 << args
[INPUT
]);
1565 cliShowParseError();
1567 cliServoMix("reverse");
1569 enum {RULE
= 0, TARGET
, INPUT
, RATE
, SPEED
, MIN
, MAX
, BOX
, ARGS_COUNT
};
1570 ptr
= strtok(cmdline
, " ");
1571 while (ptr
!= NULL
&& check
< ARGS_COUNT
) {
1572 args
[check
++] = atoi(ptr
);
1573 ptr
= strtok(NULL
, " ");
1576 if (ptr
!= NULL
|| check
!= ARGS_COUNT
) {
1577 cliShowParseError();
1582 if (i
>= 0 && i
< MAX_SERVO_RULES
&&
1583 args
[TARGET
] >= 0 && args
[TARGET
] < MAX_SUPPORTED_SERVOS
&&
1584 args
[INPUT
] >= 0 && args
[INPUT
] < INPUT_SOURCE_COUNT
&&
1585 args
[RATE
] >= -100 && args
[RATE
] <= 100 &&
1586 args
[SPEED
] >= 0 && args
[SPEED
] <= MAX_SERVO_SPEED
&&
1587 args
[MIN
] >= 0 && args
[MIN
] <= 100 &&
1588 args
[MAX
] >= 0 && args
[MAX
] <= 100 && args
[MIN
] < args
[MAX
] &&
1589 args
[BOX
] >= 0 && args
[BOX
] <= MAX_SERVO_BOXES
) {
1590 masterConfig
.customServoMixer
[i
].targetChannel
= args
[TARGET
];
1591 masterConfig
.customServoMixer
[i
].inputSource
= args
[INPUT
];
1592 masterConfig
.customServoMixer
[i
].rate
= args
[RATE
];
1593 masterConfig
.customServoMixer
[i
].speed
= args
[SPEED
];
1594 masterConfig
.customServoMixer
[i
].min
= args
[MIN
];
1595 masterConfig
.customServoMixer
[i
].max
= args
[MAX
];
1596 masterConfig
.customServoMixer
[i
].box
= args
[BOX
];
1599 cliShowParseError();
1607 static void cliWriteBytes(const uint8_t *buffer
, int count
)
1616 static void cliSdInfo(char *cmdline
) {
1619 cliPrint("SD card: ");
1621 if (!sdcard_isInserted()) {
1622 cliPrint("None inserted\r\n");
1626 if (!sdcard_isInitialized()) {
1627 cliPrint("Startup failed\r\n");
1631 const sdcardMetadata_t
*metadata
= sdcard_getMetadata();
1633 cliPrintf("Manufacturer 0x%x, %ukB, %02d/%04d, v%d.%d, '",
1634 metadata
->manufacturerID
,
1635 metadata
->numBlocks
/ 2, /* One block is half a kB */
1636 metadata
->productionMonth
,
1637 metadata
->productionYear
,
1638 metadata
->productRevisionMajor
,
1639 metadata
->productRevisionMinor
1642 cliWriteBytes((uint8_t*)metadata
->productName
, sizeof(metadata
->productName
));
1644 cliPrint("'\r\n" "Filesystem: ");
1646 switch (afatfs_getFilesystemState()) {
1647 case AFATFS_FILESYSTEM_STATE_READY
:
1650 case AFATFS_FILESYSTEM_STATE_INITIALIZATION
:
1651 cliPrint("Initializing");
1653 case AFATFS_FILESYSTEM_STATE_UNKNOWN
:
1654 case AFATFS_FILESYSTEM_STATE_FATAL
:
1657 switch (afatfs_getLastError()) {
1658 case AFATFS_ERROR_BAD_MBR
:
1659 cliPrint(" - no FAT MBR partitions");
1661 case AFATFS_ERROR_BAD_FILESYSTEM_HEADER
:
1662 cliPrint(" - bad FAT header");
1664 case AFATFS_ERROR_GENERIC
:
1665 case AFATFS_ERROR_NONE
:
1666 ; // Nothing more detailed to print
1679 static void cliFlashInfo(char *cmdline
)
1681 const flashGeometry_t
*layout
= flashfsGetGeometry();
1685 cliPrintf("Flash sectors=%u, sectorSize=%u, pagesPerSector=%u, pageSize=%u, totalSize=%u, usedSize=%u\r\n",
1686 layout
->sectors
, layout
->sectorSize
, layout
->pagesPerSector
, layout
->pageSize
, layout
->totalSize
, flashfsGetOffset());
1689 static void cliFlashErase(char *cmdline
)
1693 cliPrintf("Erasing...\r\n");
1694 flashfsEraseCompletely();
1696 while (!flashfsIsReady()) {
1700 cliPrintf("Done.\r\n");
1703 #ifdef USE_FLASH_TOOLS
1705 static void cliFlashWrite(char *cmdline
)
1707 uint32_t address
= atoi(cmdline
);
1708 char *text
= strchr(cmdline
, ' ');
1711 cliShowParseError();
1713 flashfsSeekAbs(address
);
1714 flashfsWrite((uint8_t*)text
, strlen(text
), true);
1717 cliPrintf("Wrote %u bytes at %u.\r\n", strlen(text
), address
);
1721 static void cliFlashRead(char *cmdline
)
1723 uint32_t address
= atoi(cmdline
);
1729 char *nextArg
= strchr(cmdline
, ' ');
1732 cliShowParseError();
1734 length
= atoi(nextArg
);
1736 cliPrintf("Reading %u bytes at %u:\r\n", length
, address
);
1738 while (length
> 0) {
1741 bytesRead
= flashfsReadAbs(address
, buffer
, length
< sizeof(buffer
) ? length
: sizeof(buffer
));
1743 for (i
= 0; i
< bytesRead
; i
++) {
1744 cliWrite(buffer
[i
]);
1747 length
-= bytesRead
;
1748 address
+= bytesRead
;
1750 if (bytesRead
== 0) {
1751 //Assume we reached the end of the volume or something fatal happened
1762 static void dumpValues(uint16_t valueSection
)
1765 const clivalue_t
*value
;
1766 for (i
= 0; i
< VALUE_COUNT
; i
++) {
1767 value
= &valueTable
[i
];
1769 if ((value
->type
& VALUE_SECTION_MASK
) != valueSection
) {
1773 cliPrintf("set %s = ", valueTable
[i
].name
);
1774 cliPrintVar(value
, 0);
1780 DUMP_MASTER
= (1 << 0),
1781 DUMP_PROFILE
= (1 << 1),
1782 DUMP_RATES
= (1 << 2),
1783 DUMP_ALL
= (1 << 3),
1787 static const char* const sectionBreak
= "\r\n";
1789 #define printSectionBreak() cliPrintf((char *)sectionBreak)
1791 static void cliDump(char *cmdline
)
1797 #ifndef USE_QUAD_MIXER_ONLY
1798 float thr
, roll
, pitch
, yaw
;
1801 uint8_t dumpMask
= DUMP_MASTER
;
1802 if (strcasecmp(cmdline
, "master") == 0) {
1803 dumpMask
= DUMP_MASTER
; // only
1805 if (strcasecmp(cmdline
, "profile") == 0) {
1806 dumpMask
= DUMP_PROFILE
; // only
1808 if (strcasecmp(cmdline
, "rates") == 0) {
1809 dumpMask
= DUMP_RATES
;
1812 if (strcasecmp(cmdline
, "all") == 0) {
1813 dumpMask
= DUMP_ALL
; // All profiles and rates
1816 if ((dumpMask
& DUMP_MASTER
) || (dumpMask
& DUMP_ALL
)) {
1818 cliPrint("\r\n# version\r\n");
1821 cliPrint("\r\n# dump master\r\n");
1822 cliPrint("\r\n# mixer\r\n");
1824 #ifndef USE_QUAD_MIXER_ONLY
1825 cliPrintf("mixer %s\r\n", mixerNames
[masterConfig
.mixerMode
- 1]);
1827 cliPrintf("mmix reset\r\n");
1829 for (i
= 0; i
< MAX_SUPPORTED_MOTORS
; i
++) {
1830 if (masterConfig
.customMotorMixer
[i
].throttle
== 0.0f
)
1832 thr
= masterConfig
.customMotorMixer
[i
].throttle
;
1833 roll
= masterConfig
.customMotorMixer
[i
].roll
;
1834 pitch
= masterConfig
.customMotorMixer
[i
].pitch
;
1835 yaw
= masterConfig
.customMotorMixer
[i
].yaw
;
1836 cliPrintf("mmix %d", i
);
1839 cliPrintf("%s", ftoa(thr
, buf
));
1842 cliPrintf("%s", ftoa(roll
, buf
));
1845 cliPrintf("%s", ftoa(pitch
, buf
));
1848 cliPrintf("%s\r\n", ftoa(yaw
, buf
));
1852 // print custom servo mixer if exists
1853 cliPrintf("smix reset\r\n");
1855 for (i
= 0; i
< MAX_SERVO_RULES
; i
++) {
1857 if (masterConfig
.customServoMixer
[i
].rate
== 0)
1860 cliPrintf("smix %d %d %d %d %d %d %d %d\r\n",
1862 masterConfig
.customServoMixer
[i
].targetChannel
,
1863 masterConfig
.customServoMixer
[i
].inputSource
,
1864 masterConfig
.customServoMixer
[i
].rate
,
1865 masterConfig
.customServoMixer
[i
].speed
,
1866 masterConfig
.customServoMixer
[i
].min
,
1867 masterConfig
.customServoMixer
[i
].max
,
1868 masterConfig
.customServoMixer
[i
].box
1875 cliPrint("\r\n\r\n# feature\r\n");
1877 mask
= featureMask();
1878 for (i
= 0; ; i
++) { // disable all feature first
1879 if (featureNames
[i
] == NULL
)
1881 cliPrintf("feature -%s\r\n", featureNames
[i
]);
1883 for (i
= 0; ; i
++) { // reenable what we want.
1884 if (featureNames
[i
] == NULL
)
1886 if (mask
& (1 << i
))
1887 cliPrintf("feature %s\r\n", featureNames
[i
]);
1892 cliPrint("\r\n\r\n# beeper\r\n");
1894 uint8_t beeperCount
= beeperTableEntryCount();
1895 mask
= getBeeperOffMask();
1896 for (int i
= 0; i
< (beeperCount
-2); i
++) {
1897 if (mask
& (1 << i
))
1898 cliPrintf("beeper -%s\r\n", beeperNameForTableIndex(i
));
1900 cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i
));
1905 cliPrint("\r\n\r\n# map\r\n");
1907 for (i
= 0; i
< 8; i
++)
1908 buf
[masterConfig
.rxConfig
.rcmap
[i
]] = rcChannelLetters
[i
];
1910 cliPrintf("map %s\r\n", buf
);
1912 cliPrint("\r\n\r\n# serial\r\n");
1916 cliPrint("\r\n\r\n# led\r\n");
1919 cliPrint("\r\n\r\n# color\r\n");
1923 cliPrint("\r\n# aux\r\n");
1927 cliPrint("\r\n# adjrange\r\n");
1929 cliAdjustmentRange("");
1931 cliPrintf("\r\n# rxrange\r\n");
1936 cliPrint("\r\n# servo\r\n");
1940 // print servo directions
1941 unsigned int channel
;
1943 for (i
= 0; i
< MAX_SUPPORTED_SERVOS
; i
++) {
1944 for (channel
= 0; channel
< INPUT_SOURCE_COUNT
; channel
++) {
1945 if (servoDirection(i
, channel
) < 0) {
1946 cliPrintf("smix reverse %d %d r\r\n", i
, channel
);
1952 printSectionBreak();
1953 dumpValues(MASTER_VALUE
);
1955 cliPrint("\r\n# rxfail\r\n");
1958 if (dumpMask
& DUMP_ALL
) {
1959 uint8_t activeProfile
= masterConfig
.current_profile_index
;
1960 uint8_t currentRateIndex
= currentProfile
->activeRateProfile
;
1961 uint8_t profileCount
;
1963 for (profileCount
=0; profileCount
<MAX_PROFILE_COUNT
;profileCount
++) {
1964 cliDumpProfile(profileCount
);
1965 for (rateCount
=0; rateCount
<MAX_RATEPROFILES
; rateCount
++)
1966 cliDumpRateProfile(rateCount
);
1969 changeProfile(activeProfile
);
1970 changeControlRateProfile(currentRateIndex
);
1972 cliDumpProfile(masterConfig
.current_profile_index
);
1973 cliDumpRateProfile(currentProfile
->activeRateProfile
);
1977 if (dumpMask
& DUMP_PROFILE
) {
1978 cliDumpProfile(masterConfig
.current_profile_index
);
1981 if (dumpMask
& DUMP_RATES
) {
1982 cliDumpRateProfile(currentProfile
->activeRateProfile
);
1987 void cliDumpProfile(uint8_t profileIndex
) {
1988 if (profileIndex
>= MAX_PROFILE_COUNT
) // Faulty values
1991 changeProfile(profileIndex
);
1992 cliPrint("\r\n# profile\r\n");
1994 cliPrintf("############################# PROFILE VALUES ####################################\r\n");
1996 printSectionBreak();
1997 dumpValues(PROFILE_VALUE
);
2001 void cliDumpRateProfile(uint8_t rateProfileIndex
) {
2002 if (rateProfileIndex
>= MAX_RATEPROFILES
) // Faulty values
2005 changeControlRateProfile(rateProfileIndex
);
2006 cliPrint("\r\n# rateprofile\r\n");
2008 printSectionBreak();
2010 dumpValues(PROFILE_RATE_VALUE
);
2013 void cliEnter(serialPort_t
*serialPort
)
2016 cliPort
= serialPort
;
2017 setPrintfSerialPort(cliPort
);
2018 cliWriter
= bufWriterInit(cliWriteBuffer
, sizeof(cliWriteBuffer
),
2019 (bufWrite_t
)serialWriteBufShim
, serialPort
);
2021 cliPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n");
2023 ENABLE_ARMING_FLAG(PREVENT_ARMING
);
2026 static void cliExit(char *cmdline
)
2030 cliPrint("\r\nLeaving CLI mode, unsaved changes lost.\r\n");
2031 bufWriterFlush(cliWriter
);
2036 // incase a motor was left running during motortest, clear it here
2037 mixerResetDisarmedMotors();
2043 static void cliFeature(char *cmdline
)
2049 len
= strlen(cmdline
);
2050 mask
= featureMask();
2053 cliPrint("Enabled: ");
2054 for (i
= 0; ; i
++) {
2055 if (featureNames
[i
] == NULL
)
2057 if (mask
& (1 << i
))
2058 cliPrintf("%s ", featureNames
[i
]);
2061 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2062 cliPrint("Available: ");
2063 for (i
= 0; ; i
++) {
2064 if (featureNames
[i
] == NULL
)
2066 cliPrintf("%s ", featureNames
[i
]);
2071 bool remove
= false;
2072 if (cmdline
[0] == '-') {
2075 cmdline
++; // skip over -
2079 for (i
= 0; ; i
++) {
2080 if (featureNames
[i
] == NULL
) {
2081 cliPrint("Invalid name\r\n");
2085 if (strncasecmp(cmdline
, featureNames
[i
], len
) == 0) {
2089 if (mask
& FEATURE_GPS
) {
2090 cliPrint("unavailable\r\n");
2095 if (mask
& FEATURE_SONAR
) {
2096 cliPrint("unavailable\r\n");
2102 cliPrint("Disabled");
2105 cliPrint("Enabled");
2107 cliPrintf(" %s\r\n", featureNames
[i
]);
2115 static void cliBeeper(char *cmdline
)
2118 uint32_t len
= strlen(cmdline
);;
2119 uint8_t beeperCount
= beeperTableEntryCount();
2120 uint32_t mask
= getBeeperOffMask();
2123 cliPrintf("Disabled:");
2124 for (int i
= 0; ; i
++) {
2125 if (i
== beeperCount
-2){
2130 if (mask
& (1 << i
))
2131 cliPrintf(" %s", beeperNameForTableIndex(i
));
2134 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2135 cliPrint("Available:");
2136 for (i
= 0; i
< beeperCount
; i
++)
2137 cliPrintf(" %s", beeperNameForTableIndex(i
));
2141 bool remove
= false;
2142 if (cmdline
[0] == '-') {
2143 remove
= true; // this is for beeper OFF condition
2148 for (i
= 0; ; i
++) {
2149 if (i
== beeperCount
) {
2150 cliPrint("Invalid name\r\n");
2153 if (strncasecmp(cmdline
, beeperNameForTableIndex(i
), len
) == 0) {
2154 if (remove
) { // beeper off
2155 if (i
== BEEPER_ALL
-1)
2156 beeperOffSetAll(beeperCount
-2);
2158 if (i
== BEEPER_PREFERENCE
-1)
2159 setBeeperOffMask(getPreferedBeeperOffMask());
2164 cliPrint("Disabled");
2167 if (i
== BEEPER_ALL
-1)
2168 beeperOffClearAll();
2170 if (i
== BEEPER_PREFERENCE
-1)
2171 setPreferedBeeperOffMask(getBeeperOffMask());
2174 beeperOffClear(mask
);
2176 cliPrint("Enabled");
2178 cliPrintf(" %s\r\n", beeperNameForTableIndex(i
));
2188 static void cliGpsPassthrough(char *cmdline
)
2192 gpsEnablePassthrough(cliPort
);
2196 static void cliHelp(char *cmdline
)
2202 for (i
= 0; i
< CMD_COUNT
; i
++) {
2203 cliPrint(cmdTable
[i
].name
);
2204 #ifndef SKIP_CLI_COMMAND_HELP
2205 if (cmdTable
[i
].description
) {
2206 cliPrintf(" - %s", cmdTable
[i
].description
);
2208 if (cmdTable
[i
].args
) {
2209 cliPrintf("\r\n\t%s", cmdTable
[i
].args
);
2216 static void cliMap(char *cmdline
)
2222 len
= strlen(cmdline
);
2226 for (i
= 0; i
< 8; i
++)
2227 cmdline
[i
] = toupper((unsigned char)cmdline
[i
]);
2228 for (i
= 0; i
< 8; i
++) {
2229 if (strchr(rcChannelLetters
, cmdline
[i
]) && !strchr(cmdline
+ i
+ 1, cmdline
[i
]))
2231 cliShowParseError();
2234 parseRcChannels(cmdline
, &masterConfig
.rxConfig
);
2237 for (i
= 0; i
< 8; i
++)
2238 out
[masterConfig
.rxConfig
.rcmap
[i
]] = rcChannelLetters
[i
];
2240 cliPrintf("%s\r\n", out
);
2243 #ifndef USE_QUAD_MIXER_ONLY
2244 static void cliMixer(char *cmdline
)
2249 len
= strlen(cmdline
);
2252 cliPrintf("Mixer: %s\r\n", mixerNames
[masterConfig
.mixerMode
- 1]);
2254 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2255 cliPrint("Available mixers: ");
2256 for (i
= 0; ; i
++) {
2257 if (mixerNames
[i
] == NULL
)
2259 cliPrintf("%s ", mixerNames
[i
]);
2265 for (i
= 0; ; i
++) {
2266 if (mixerNames
[i
] == NULL
) {
2267 cliPrint("Invalid name\r\n");
2270 if (strncasecmp(cmdline
, mixerNames
[i
], len
) == 0) {
2271 masterConfig
.mixerMode
= i
+ 1;
2280 static void cliMotor(char *cmdline
)
2282 int motor_index
= 0;
2283 int motor_value
= 0;
2288 if (isEmpty(cmdline
)) {
2289 cliShowParseError();
2293 pch
= strtok_r(cmdline
, " ", &saveptr
);
2294 while (pch
!= NULL
) {
2297 motor_index
= atoi(pch
);
2300 motor_value
= atoi(pch
);
2304 pch
= strtok_r(NULL
, " ", &saveptr
);
2307 if (motor_index
< 0 || motor_index
>= MAX_SUPPORTED_MOTORS
) {
2308 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS
- 1);
2313 if (motor_value
< PWM_RANGE_MIN
|| motor_value
> PWM_RANGE_MAX
) {
2314 cliShowArgumentRangeError("value", 1000, 2000);
2317 motor_disarmed
[motor_index
] = motor_value
;
2321 cliPrintf("motor %d: %d\r\n", motor_index
, motor_disarmed
[motor_index
]);
2324 static void cliPlaySound(char *cmdline
)
2326 #if FLASH_SIZE <= 64
2331 static int lastSoundIdx
= -1;
2333 if (isEmpty(cmdline
)) {
2334 i
= lastSoundIdx
+ 1; //next sound index
2335 if ((name
=beeperNameForTableIndex(i
)) == NULL
) {
2336 while (true) { //no name for index; try next one
2337 if (++i
>= beeperTableEntryCount())
2338 i
= 0; //if end then wrap around to first entry
2339 if ((name
=beeperNameForTableIndex(i
)) != NULL
)
2340 break; //if name OK then play sound below
2341 if (i
== lastSoundIdx
+ 1) { //prevent infinite loop
2342 cliPrintf("Error playing sound\r\n");
2347 } else { //index value was given
2349 if ((name
=beeperNameForTableIndex(i
)) == NULL
) {
2350 cliPrintf("No sound for index %d\r\n", i
);
2356 cliPrintf("Playing sound %d: %s\r\n", i
, name
);
2357 beeper(beeperModeForTableIndex(i
));
2361 static void cliProfile(char *cmdline
)
2365 if (isEmpty(cmdline
)) {
2366 cliPrintf("profile %d\r\n", getCurrentProfile());
2370 if (i
>= 0 && i
< MAX_PROFILE_COUNT
) {
2371 masterConfig
.current_profile_index
= i
;
2379 static void cliRateProfile(char *cmdline
) {
2382 if (isEmpty(cmdline
)) {
2383 cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile());
2387 if (i
>= 0 && i
< MAX_RATEPROFILES
) {
2388 changeControlRateProfile(i
);
2394 static void cliReboot(void) {
2395 cliPrint("\r\nRebooting");
2396 bufWriterFlush(cliWriter
);
2397 waitForSerialPortToFinishTransmitting(cliPort
);
2399 handleOneshotFeatureChangeOnRestart();
2403 static void cliSave(char *cmdline
)
2408 //copyCurrentProfileToProfileSlot(masterConfig.current_profile_index);
2413 static void cliDefaults(char *cmdline
)
2417 cliPrint("Resetting to defaults");
2422 static void cliPrint(const char *str
)
2425 bufWriterAppend(cliWriter
, *str
++);
2428 static void cliPutp(void *p
, char ch
)
2430 bufWriterAppend(p
, ch
);
2433 static void cliPrintf(const char *fmt
, ...)
2437 tfp_format(cliWriter
, cliPutp
, fmt
, va
);
2441 static void cliWrite(uint8_t ch
)
2443 bufWriterAppend(cliWriter
, ch
);
2446 static void cliPrintVar(const clivalue_t
*var
, uint32_t full
)
2451 void *ptr
= var
->ptr
;
2452 if ((var
->type
& VALUE_SECTION_MASK
) == PROFILE_VALUE
) {
2453 ptr
= ((uint8_t *)ptr
) + (sizeof(profile_t
) * masterConfig
.current_profile_index
);
2456 if ((var
->type
& VALUE_SECTION_MASK
) == PROFILE_RATE_VALUE
) {
2457 ptr
= ((uint8_t *)ptr
) + (sizeof(profile_t
) * masterConfig
.current_profile_index
) + (sizeof(controlRateConfig_t
) * getCurrentControlRateProfile());
2460 switch (var
->type
& VALUE_TYPE_MASK
) {
2462 value
= *(uint8_t *)ptr
;
2466 value
= *(int8_t *)ptr
;
2470 value
= *(uint16_t *)ptr
;
2474 value
= *(int16_t *)ptr
;
2478 value
= *(uint32_t *)ptr
;
2482 cliPrintf("%s", ftoa(*(float *)ptr
, buf
));
2483 if (full
&& (var
->type
& VALUE_MODE_MASK
) == MODE_DIRECT
) {
2484 cliPrintf(" %s", ftoa((float)var
->config
.minmax
.min
, buf
));
2485 cliPrintf(" %s", ftoa((float)var
->config
.minmax
.max
, buf
));
2487 return; // return from case for float only
2490 switch(var
->type
& VALUE_MODE_MASK
) {
2492 cliPrintf("%d", value
);
2494 cliPrintf(" %d %d", var
->config
.minmax
.min
, var
->config
.minmax
.max
);
2498 cliPrintf(lookupTables
[var
->config
.lookup
.tableIndex
].values
[value
]);
2502 static void cliPrintVarRange(const clivalue_t
*var
)
2504 switch (var
->type
& VALUE_MODE_MASK
) {
2505 case (MODE_DIRECT
): {
2506 cliPrintf("Allowed range: %d - %d\n", var
->config
.minmax
.min
, var
->config
.minmax
.max
);
2509 case (MODE_LOOKUP
): {
2510 const lookupTableEntry_t
*tableEntry
= &lookupTables
[var
->config
.lookup
.tableIndex
];
2511 cliPrint("Allowed values:");
2513 for (i
= 0; i
< tableEntry
->valueCount
; i
++) {
2516 cliPrintf(" %s", tableEntry
->values
[i
]);
2523 static void cliSetVar(const clivalue_t
*var
, const int_float_value_t value
)
2525 void *ptr
= var
->ptr
;
2526 if ((var
->type
& VALUE_SECTION_MASK
) == PROFILE_VALUE
) {
2527 ptr
= ((uint8_t *)ptr
) + (sizeof(profile_t
) * masterConfig
.current_profile_index
);
2529 if ((var
->type
& VALUE_SECTION_MASK
) == PROFILE_RATE_VALUE
) {
2530 ptr
= ((uint8_t *)ptr
) + (sizeof(profile_t
) * masterConfig
.current_profile_index
) + (sizeof(controlRateConfig_t
) * getCurrentControlRateProfile());
2533 switch (var
->type
& VALUE_TYPE_MASK
) {
2536 *(int8_t *)ptr
= value
.int_value
;
2541 *(int16_t *)ptr
= value
.int_value
;
2545 *(uint32_t *)ptr
= value
.int_value
;
2549 *(float *)ptr
= (float)value
.float_value
;
2554 static void cliSet(char *cmdline
)
2558 const clivalue_t
*val
;
2561 len
= strlen(cmdline
);
2563 if (len
== 0 || (len
== 1 && cmdline
[0] == '*')) {
2564 cliPrint("Current settings: \r\n");
2565 for (i
= 0; i
< VALUE_COUNT
; i
++) {
2566 val
= &valueTable
[i
];
2567 cliPrintf("%s = ", valueTable
[i
].name
);
2568 cliPrintVar(val
, len
); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui
2571 } else if ((eqptr
= strstr(cmdline
, "=")) != NULL
) {
2574 char *lastNonSpaceCharacter
= eqptr
;
2575 while (*(lastNonSpaceCharacter
- 1) == ' ') {
2576 lastNonSpaceCharacter
--;
2578 uint8_t variableNameLength
= lastNonSpaceCharacter
- cmdline
;
2580 // skip the '=' and any ' ' characters
2582 while (*(eqptr
) == ' ') {
2586 for (i
= 0; i
< VALUE_COUNT
; i
++) {
2587 val
= &valueTable
[i
];
2588 // ensure exact match when setting to prevent setting variables with shorter names
2589 if (strncasecmp(cmdline
, valueTable
[i
].name
, strlen(valueTable
[i
].name
)) == 0 && variableNameLength
== strlen(valueTable
[i
].name
)) {
2591 bool changeValue
= false;
2592 int_float_value_t tmp
;
2593 switch (valueTable
[i
].type
& VALUE_MODE_MASK
) {
2598 value
= atoi(eqptr
);
2599 valuef
= fastA2F(eqptr
);
2601 if (valuef
>= valueTable
[i
].config
.minmax
.min
&& valuef
<= valueTable
[i
].config
.minmax
.max
) { // note: compare float value
2603 if ((valueTable
[i
].type
& VALUE_TYPE_MASK
) == VAR_FLOAT
)
2604 tmp
.float_value
= valuef
;
2606 tmp
.int_value
= value
;
2613 const lookupTableEntry_t
*tableEntry
= &lookupTables
[valueTable
[i
].config
.lookup
.tableIndex
];
2614 bool matched
= false;
2615 for (uint8_t tableValueIndex
= 0; tableValueIndex
< tableEntry
->valueCount
&& !matched
; tableValueIndex
++) {
2616 matched
= strcasecmp(tableEntry
->values
[tableValueIndex
], eqptr
) == 0;
2619 tmp
.int_value
= tableValueIndex
;
2628 cliSetVar(val
, tmp
);
2630 cliPrintf("%s set to ", valueTable
[i
].name
);
2631 cliPrintVar(val
, 0);
2633 cliPrint("Invalid value\r\n");
2634 cliPrintVarRange(val
);
2640 cliPrint("Invalid name\r\n");
2642 // no equals, check for matching variables.
2647 static void cliGet(char *cmdline
)
2650 const clivalue_t
*val
;
2651 int matchedCommands
= 0;
2653 for (i
= 0; i
< VALUE_COUNT
; i
++) {
2654 if (strstr(valueTable
[i
].name
, cmdline
)) {
2655 val
= &valueTable
[i
];
2656 cliPrintf("%s = ", valueTable
[i
].name
);
2657 cliPrintVar(val
, 0);
2659 cliPrintVarRange(val
);
2667 if (matchedCommands
) {
2671 cliPrint("Invalid name\r\n");
2674 static void cliStatus(char *cmdline
)
2678 cliPrintf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery - %s), CPU:%d%%\r\n",
2682 getBatteryStateString(),
2683 constrain(averageSystemLoadPercent
, 0, 100)
2686 cliPrintf("CPU Clock=%dMHz", (SystemCoreClock
/ 1000000));
2691 uint32_t detectedSensorsMask
= sensorsMask();
2693 for (i
= 0; ; i
++) {
2695 if (sensorTypeNames
[i
] == NULL
)
2699 if ((detectedSensorsMask
& mask
) && (mask
& SENSOR_NAMES_MASK
)) {
2700 const char *sensorHardware
;
2701 uint8_t sensorHardwareIndex
= detectedSensors
[i
];
2702 sensorHardware
= sensorHardwareNames
[i
][sensorHardwareIndex
];
2704 cliPrintf(", %s=%s", sensorTypeNames
[i
], sensorHardware
);
2706 if (mask
== SENSOR_ACC
&& acc
.revisionCode
) {
2707 cliPrintf(".%c", acc
.revisionCode
);
2715 uint16_t i2cErrorCounter
= i2cGetErrorCounter();
2717 uint16_t i2cErrorCounter
= 0;
2720 cliPrintf("Cycle Time: %d, I2C Errors: %d, config size: %d\r\n", cycleTime
, i2cErrorCounter
, sizeof(master_t
));
2723 #ifndef SKIP_TASK_STATISTICS
2724 static void cliTasks(char *cmdline
)
2729 cfTaskInfo_t taskInfo
;
2731 cliPrintf("Task list:\r\n");
2732 for (taskId
= 0; taskId
< TASK_COUNT
; taskId
++) {
2733 getTaskInfo(taskId
, &taskInfo
);
2734 if (taskInfo
.isEnabled
) {
2735 uint16_t taskFrequency
;
2736 uint16_t subTaskFrequency
;
2738 uint32_t taskTotalTime
= taskInfo
.totalExecutionTime
/ 1000;
2740 if (taskId
== TASK_GYROPID
) {
2741 subTaskFrequency
= (uint16_t)(1.0f
/ ((float)cycleTime
* 0.000001f
));
2742 if (masterConfig
.pid_process_denom
> 1) {
2743 taskFrequency
= subTaskFrequency
/ masterConfig
.pid_process_denom
;
2744 cliPrintf("%d - (%s) ", taskId
, taskInfo
.taskName
);
2746 taskFrequency
= subTaskFrequency
;
2747 cliPrintf("%d - (%s/%s) ", taskId
, taskInfo
.subTaskName
, taskInfo
.taskName
);
2750 taskFrequency
= (uint16_t)(1.0f
/ ((float)taskInfo
.latestDeltaTime
* 0.000001f
));
2751 cliPrintf("%d - (%s) ", taskId
, taskInfo
.taskName
);
2754 cliPrintf("max: %dus, avg: %dus, rate: %dhz, total: ", taskInfo
.maxExecutionTime
, taskInfo
.averageExecutionTime
, taskFrequency
);
2756 if (taskTotalTime
>= 1000) {
2757 cliPrintf("%dsec", taskTotalTime
/ 1000);
2759 cliPrintf("%dms", taskTotalTime
);
2762 if (taskId
== TASK_GYROPID
&& masterConfig
.pid_process_denom
> 1) cliPrintf("\r\n- - (%s) rate: %dhz", taskInfo
.subTaskName
, subTaskFrequency
);
2763 cliPrintf("\r\n", taskTotalTime
);
2769 static void cliVersion(char *cmdline
)
2773 cliPrintf("# BetaFlight/%s %s %s / %s (%s)",
2782 void cliProcess(void)
2788 // Be a little bit tricky. Flush the last inputs buffer, if any.
2789 bufWriterFlush(cliWriter
);
2791 while (serialRxBytesWaiting(cliPort
)) {
2792 uint8_t c
= serialRead(cliPort
);
2793 if (c
== '\t' || c
== '?') {
2794 // do tab completion
2795 const clicmd_t
*cmd
, *pstart
= NULL
, *pend
= NULL
;
2796 uint32_t i
= bufferIndex
;
2797 for (cmd
= cmdTable
; cmd
< cmdTable
+ CMD_COUNT
; cmd
++) {
2798 if (bufferIndex
&& (strncasecmp(cliBuffer
, cmd
->name
, bufferIndex
) != 0))
2804 if (pstart
) { /* Buffer matches one or more commands */
2805 for (; ; bufferIndex
++) {
2806 if (pstart
->name
[bufferIndex
] != pend
->name
[bufferIndex
])
2808 if (!pstart
->name
[bufferIndex
] && bufferIndex
< sizeof(cliBuffer
) - 2) {
2809 /* Unambiguous -- append a space */
2810 cliBuffer
[bufferIndex
++] = ' ';
2811 cliBuffer
[bufferIndex
] = '\0';
2814 cliBuffer
[bufferIndex
] = pstart
->name
[bufferIndex
];
2817 if (!bufferIndex
|| pstart
!= pend
) {
2818 /* Print list of ambiguous matches */
2819 cliPrint("\r\033[K");
2820 for (cmd
= pstart
; cmd
<= pend
; cmd
++) {
2821 cliPrint(cmd
->name
);
2825 i
= 0; /* Redraw prompt */
2827 for (; i
< bufferIndex
; i
++)
2828 cliWrite(cliBuffer
[i
]);
2829 } else if (!bufferIndex
&& c
== 4) { // CTRL-D
2832 } else if (c
== 12) { // NewPage / CTRL-L
2834 cliPrint("\033[2J\033[1;1H");
2836 } else if (bufferIndex
&& (c
== '\n' || c
== '\r')) {
2840 // Strip comment starting with # from line
2841 char *p
= cliBuffer
;
2844 bufferIndex
= (uint32_t)(p
- cliBuffer
);
2847 // Strip trailing whitespace
2848 while (bufferIndex
> 0 && cliBuffer
[bufferIndex
- 1] == ' ') {
2852 // Process non-empty lines
2853 if (bufferIndex
> 0) {
2854 cliBuffer
[bufferIndex
] = 0; // null terminate
2856 const clicmd_t
*cmd
;
2857 for (cmd
= cmdTable
; cmd
< cmdTable
+ CMD_COUNT
; cmd
++) {
2858 if(!strncasecmp(cliBuffer
, cmd
->name
, strlen(cmd
->name
)) // command names match
2859 && !isalnum((unsigned)cliBuffer
[strlen(cmd
->name
)])) // next characted in bufffer is not alphanumeric (command is correctly terminated)
2862 if(cmd
< cmdTable
+ CMD_COUNT
)
2863 cmd
->func(cliBuffer
+ strlen(cmd
->name
) + 1);
2865 cliPrint("Unknown command, try 'help'");
2869 memset(cliBuffer
, 0, sizeof(cliBuffer
));
2871 // 'exit' will reset this flag, so we don't need to print prompt again
2876 } else if (c
== 127) {
2879 cliBuffer
[--bufferIndex
] = 0;
2880 cliPrint("\010 \010");
2882 } else if (bufferIndex
< sizeof(cliBuffer
) && c
>= 32 && c
<= 126) {
2883 if (!bufferIndex
&& c
== ' ')
2884 continue; // Ignore leading spaces
2885 cliBuffer
[bufferIndex
++] = c
;
2891 void cliInit(serialConfig_t
*serialConfig
)
2893 UNUSED(serialConfig
);