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"
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"
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"
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
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
);
130 static void cliServo(char *cmdline
);
131 static void cliServoMix(char *cmdline
);
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
);
140 static void cliVersion(char *cmdline
);
141 static void cliRxRange(char *cmdline
);
144 static void cliGpsPassthrough(char *cmdline
);
147 static void cliHelp(char *cmdline
);
148 static void cliMap(char *cmdline
);
151 static void cliLed(char *cmdline
);
152 static void cliColor(char *cmdline
);
155 #ifndef USE_QUAD_MIXER_ONLY
156 static void cliMixer(char *cmdline
);
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
);
169 static void cliVtx(char *cmdline
);
173 static void cliSdInfo(char *cmdline
);
177 static void cliBeeper(char *cmdline
);
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
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",
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
}
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
}
232 #ifndef SKIP_CLI_COMMAND_HELP
233 const char *description
;
236 void (*func
)(char *cmdline
);
239 #ifndef SKIP_CLI_COMMAND_HELP
240 #define CLI_COMMAND_DEF(name, description, args, method) \
248 #define CLI_COMMAND_DEF(name, description, args, method) \
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
),
260 CLI_COMMAND_DEF("color", "configure colors", NULL
, cliColor
),
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",
268 "\t<+|->[name]", cliFeature
),
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
),
277 CLI_COMMAND_DEF("get", "get variable value",
280 CLI_COMMAND_DEF("gpspassthrough", "passthrough gps to serial", NULL
, cliGpsPassthrough
),
282 CLI_COMMAND_DEF("help", NULL
, NULL
, cliHelp
),
284 CLI_COMMAND_DEF("led", "configure leds", NULL
, cliLed
),
286 CLI_COMMAND_DEF("map", "configure rc channel order",
288 #ifndef USE_QUAD_MIXER_ONLY
289 CLI_COMMAND_DEF("mixer", "configure mixer",
291 "\t<name>", cliMixer
),
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
),
311 CLI_COMMAND_DEF("servo", "configure servos", NULL
, cliServo
),
313 CLI_COMMAND_DEF("set", "change setting",
314 "[<name>=<value>]", cliSet
),
316 CLI_COMMAND_DEF("smix", "servo mixer",
317 "<rule> <servo> <source> <rate> <speed> <min> <max> <box>\r\n"
320 "\treverse <servo> <source> r|n", cliServoMix
),
323 CLI_COMMAND_DEF("sd_info", "sdcard info", NULL
, cliSdInfo
),
325 CLI_COMMAND_DEF("status", "show status", NULL
, cliStatus
),
326 #ifndef SKIP_TASK_STATISTICS
327 CLI_COMMAND_DEF("tasks", "show task stats", NULL
, cliTasks
),
329 CLI_COMMAND_DEF("version", "show version", NULL
, cliVersion
),
331 CLI_COMMAND_DEF("beeper", "turn on/off beeper", "list\r\n"
332 "\t<+|->[name]", cliBeeper
),
335 CLI_COMMAND_DEF("vtx", "vtx channels on switch", NULL
, cliVtx
),
338 #define CMD_COUNT (sizeof(cmdTable) / sizeof(clicmd_t))
340 static const char * const lookupTableOffOn
[] = {
344 static const char * const lookupTableUnit
[] = {
348 static const char * const lookupTableAlignment
[] = {
361 static const char * const lookupTableGPSProvider
[] = {
365 static const char * const lookupTableGPSSBASMode
[] = {
366 "AUTO", "EGNOS", "WAAS", "MSAS", "GAGAN"
370 static const char * const lookupTableCurrentSensor
[] = {
371 "NONE", "ADC", "VIRTUAL"
374 static const char * const lookupTableGimbalMode
[] = {
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
[] = {
399 static const char * const lookupTableGyroLpf
[] = {
410 static const char * const lookupTableAccHardware
[] = {
423 static const char * const lookupTableBaroHardware
[] = {
431 static const char * const lookupTableMagHardware
[] = {
439 static const char * const lookupTableDebug
[DEBUG_COUNT
] = {
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
;
472 TABLE_BLACKBOX_DEVICE
,
474 TABLE_CURRENT_SENSOR
,
476 TABLE_PID_CONTROLLER
,
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 *) },
492 { lookupTableGPSProvider
, sizeof(lookupTableGPSProvider
) / sizeof(char *) },
493 { lookupTableGPSSBASMode
, sizeof(lookupTableGPSSBASMode
) / sizeof(char *) },
496 { lookupTableBlackboxDevice
, sizeof(lookupTableBlackboxDevice
) / sizeof(char *) },
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
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
),
525 MASTER_VALUE
= (0 << VALUE_SECTION_OFFSET
),
526 PROFILE_VALUE
= (1 << VALUE_SECTION_OFFSET
),
527 PROFILE_RATE_VALUE
= (2 << VALUE_SECTION_OFFSET
),
529 MODE_DIRECT
= (0 << VALUE_MODE_OFFSET
),
530 MODE_LOOKUP
= (1 << VALUE_MODE_OFFSET
)
533 #define VALUE_TYPE_MASK (0x0F)
534 #define VALUE_SECTION_MASK (0x30)
535 #define VALUE_MODE_MASK (0xC0)
537 typedef struct cliMinMaxConfig_s
{
542 typedef struct cliLookupTableConfig_s
{
543 const lookupTableIndex_e tableIndex
;
544 } cliLookupTableConfig_t
;
547 cliLookupTableConfig_t lookup
;
548 cliMinMaxConfig_t minmax
;
554 const uint8_t type
; // see cliValueFlag_e
556 const cliValueConfig_t config
;
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
} },
588 { "enable_buzzer_p6", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.use_buzzer_p6
, .config
.lookup
= { TABLE_OFF_ON
} },
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 } },
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 } },
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 } },
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
} },
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
} },
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
} },
720 { "gimbal_mode", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.gimbalConfig
.mode
, .config
.lookup
= { TABLE_GIMBAL_MODE
} },
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 } },
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
} },
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 } },
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 } },
787 { "ledstrip_visual_beeper", VAR_UINT8
| MASTER_VALUE
| MODE_LOOKUP
, &masterConfig
.ledstrip_visual_beeper
, .config
.lookup
= { TABLE_OFF_ON
} },
791 #define VALUE_COUNT (sizeof(valueTable) / sizeof(clivalue_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)
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
)
826 for (int argIndex
= 0; argIndex
< 2; argIndex
++) {
827 ptr
= strchr(ptr
, ' ');
830 val
= CHANNEL_VALUE_TO_STEP(val
);
831 if (val
>= MIN_MODE_RANGE_STEP
&& val
<= MAX_MODE_RANGE_STEP
) {
833 range
->startStep
= val
;
835 range
->endStep
= val
;
837 (*validArgumentCount
)++;
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
)
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));
863 channel
= atoi(ptr
++);
864 if ((channel
< MAX_SUPPORTED_RC_CHANNEL_COUNT
)) {
866 rxFailsafeChannelConfiguration_t
*channelFailsafeConfiguration
= &masterConfig
.rxConfig
.failsafe_channel_configurations
[channel
];
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
, ' ');
875 char *p
= strchr(rxFailsafeModeCharacters
, *(++ptr
));
877 uint8_t requestedMode
= p
- rxFailsafeModeCharacters
;
878 mode
= rxFailsafeModesTable
[type
][requestedMode
];
880 mode
= RX_FAILSAFE_MODE_INVALID
;
882 if (mode
== RX_FAILSAFE_MODE_INVALID
) {
887 requireValue
= mode
== RX_FAILSAFE_MODE_SET
;
889 ptr
= strchr(ptr
, ' ');
896 value
= CHANNEL_VALUE_TO_RXFAIL_STEP(value
);
897 if (value
> MAX_RXFAIL_RANGE_STEP
) {
898 cliPrint("Value out of range\r\n");
902 channelFailsafeConfiguration
->step
= value
;
903 } else if (requireValue
) {
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.
919 cliPrintf("rxfail %u %c %d\r\n",
922 RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfiguration
->step
)
925 cliPrintf("rxfail %u %c\r\n",
931 cliShowArgumentRangeError("channel", 0, MAX_SUPPORTED_RC_CHANNEL_COUNT
- 1);
936 static void cliAux(char *cmdline
)
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",
948 mac
->auxChannelIndex
,
949 MODE_STEP_TO_CHANNEL_VALUE(mac
->range
.startStep
),
950 MODE_STEP_TO_CHANNEL_VALUE(mac
->range
.endStep
)
956 if (i
< MAX_MODE_ACTIVATION_CONDITION_COUNT
) {
957 modeActivationCondition_t
*mac
= &masterConfig
.modeActivationConditions
[i
];
958 uint8_t validArgumentCount
= 0;
959 ptr
= strchr(ptr
, ' ');
962 if (val
>= 0 && val
< CHECKBOX_ITEM_COUNT
) {
964 validArgumentCount
++;
967 ptr
= strchr(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
));
981 cliShowArgumentRangeError("index", 0, MAX_MODE_ACTIVATION_CONDITION_COUNT
- 1);
986 static void cliSerial(char *cmdline
)
991 if (isEmpty(cmdline
)) {
992 for (i
= 0; i
< SERIAL_PORT_COUNT
; i
++) {
993 if (!serialIsPortAvailable(masterConfig
.serialConfig
.portConfigs
[i
].identifier
)) {
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
]
1008 serialPortConfig_t portConfig
;
1009 memset(&portConfig
, 0 , sizeof(portConfig
));
1011 serialPortConfig_t
*currentConfig
;
1013 uint8_t validArgumentCount
= 0;
1018 currentConfig
= serialFindPortConfiguration(val
);
1019 if (currentConfig
) {
1020 portConfig
.identifier
= val
;
1021 validArgumentCount
++;
1024 ptr
= strchr(ptr
, ' ');
1027 portConfig
.functionMask
= val
& 0xFFFF;
1028 validArgumentCount
++;
1031 for (i
= 0; i
< 4; i
++) {
1032 ptr
= strchr(ptr
, ' ');
1039 uint8_t baudRateIndex
= lookupBaudRateIndex(val
);
1040 if (baudRates
[baudRateIndex
] != (uint32_t) val
) {
1046 if (baudRateIndex
< BAUD_9600
|| baudRateIndex
> BAUD_115200
) {
1049 portConfig
.msp_baudrateIndex
= baudRateIndex
;
1052 if (baudRateIndex
< BAUD_9600
|| baudRateIndex
> BAUD_115200
) {
1055 portConfig
.gps_baudrateIndex
= baudRateIndex
;
1058 if (baudRateIndex
!= BAUD_AUTO
&& baudRateIndex
> BAUD_115200
) {
1061 portConfig
.telemetry_baudrateIndex
= baudRateIndex
;
1064 if (baudRateIndex
< BAUD_19200
|| baudRateIndex
> BAUD_250000
) {
1067 portConfig
.blackbox_baudrateIndex
= baudRateIndex
;
1071 validArgumentCount
++;
1074 if (validArgumentCount
< 6) {
1075 cliShowParseError();
1079 memcpy(currentConfig
, &portConfig
, sizeof(portConfig
));
1083 #ifndef SKIP_SERIAL_PASSTHROUGH
1084 static void cliSerialPassthrough(char *cmdline
)
1086 if (isEmpty(cmdline
)) {
1087 cliShowParseError();
1094 char* tok
= strtok(cmdline
, " ");
1097 while (tok
!= NULL
) {
1106 if (strstr(tok
, "rx") || strstr(tok
, "RX"))
1108 if (strstr(tok
, "tx") || strstr(tok
, "TX"))
1113 tok
= strtok(NULL
, " ");
1116 serialPort_t
*passThroughPort
;
1117 serialPortUsage_t
*passThroughPortUsage
= findSerialPortUsageByIdentifier(id
);
1118 if (!passThroughPortUsage
|| passThroughPortUsage
->serialPort
== NULL
) {
1120 printf("Port %d is not open, you must specify baud\r\n", id
);
1126 passThroughPort
= openSerialPort(id
, FUNCTION_PASSTHROUGH
, NULL
,
1128 SERIAL_NOT_INVERTED
);
1129 if (!passThroughPort
) {
1130 printf("Port %d could not be opened\r\n", id
);
1133 printf("Port %d opened, baud=%d\r\n", id
, baud
);
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
);
1153 static void cliAdjustmentRange(char *cmdline
)
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
1175 if (i
< MAX_ADJUSTMENT_RANGE_COUNT
) {
1176 adjustmentRange_t
*ar
= &masterConfig
.adjustmentRanges
[i
];
1177 uint8_t validArgumentCount
= 0;
1179 ptr
= strchr(ptr
, ' ');
1182 if (val
>= 0 && val
< MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
) {
1183 ar
->adjustmentIndex
= val
;
1184 validArgumentCount
++;
1187 ptr
= strchr(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
, ' ');
1201 if (val
>= 0 && val
< ADJUSTMENT_FUNCTION_COUNT
) {
1202 ar
->adjustmentFunction
= val
;
1203 validArgumentCount
++;
1206 ptr
= strchr(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();
1220 cliShowArgumentRangeError("index", 0, MAX_ADJUSTMENT_RANGE_COUNT
- 1);
1225 static void cliMotorMix(char *cmdline
)
1227 #ifdef USE_QUAD_MIXER_ONLY
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
)
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
));
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
, ' ');
1256 len
= strlen(++ptr
);
1257 for (i
= 0; ; i
++) {
1258 if (mixerNames
[i
] == NULL
) {
1259 cliPrint("Invalid name\r\n");
1262 if (strncasecmp(ptr
, mixerNames
[i
], len
) == 0) {
1263 mixerLoadMix(i
, masterConfig
.customMotorMixer
);
1264 cliPrintf("Loaded %s\r\n", mixerNames
[i
]);
1272 i
= atoi(ptr
); // get motor number
1273 if (i
< MAX_SUPPORTED_MOTORS
) {
1274 ptr
= strchr(ptr
, ' ');
1276 masterConfig
.customMotorMixer
[i
].throttle
= fastA2F(++ptr
);
1279 ptr
= strchr(ptr
, ' ');
1281 masterConfig
.customMotorMixer
[i
].roll
= fastA2F(++ptr
);
1284 ptr
= strchr(ptr
, ' ');
1286 masterConfig
.customMotorMixer
[i
].pitch
= fastA2F(++ptr
);
1289 ptr
= strchr(ptr
, ' ');
1291 masterConfig
.customMotorMixer
[i
].yaw
= fastA2F(++ptr
);
1295 cliShowParseError();
1300 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS
- 1);
1306 static void cliRxRange(char *cmdline
)
1308 int i
, validArgumentCount
= 0;
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
);
1321 if (i
>= 0 && i
< NON_AUX_CHANNEL_COUNT
) {
1322 int rangeMin
, rangeMax
;
1324 ptr
= strchr(ptr
, ' ');
1326 rangeMin
= atoi(++ptr
);
1327 validArgumentCount
++;
1330 ptr
= strchr(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();
1341 rxChannelRangeConfiguration_t
*channelRangeConfiguration
= &masterConfig
.rxConfig
.channelRanges
[i
];
1342 channelRangeConfiguration
->min
= rangeMin
;
1343 channelRangeConfiguration
->max
= rangeMax
;
1346 cliShowArgumentRangeError("channel", 0, NON_AUX_CHANNEL_COUNT
- 1);
1352 static void cliLed(char *cmdline
)
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
);
1366 if (i
< MAX_LED_STRIP_LENGTH
) {
1367 ptr
= strchr(cmdline
, ' ');
1368 if (!parseLedStripConfig(i
, ++ptr
)) {
1369 cliShowParseError();
1372 cliShowArgumentRangeError("index", 0, MAX_LED_STRIP_LENGTH
- 1);
1377 static void cliColor(char *cmdline
)
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
1394 if (i
< CONFIGURABLE_COLOR_COUNT
) {
1395 ptr
= strchr(cmdline
, ' ');
1396 if (!parseColor(i
, ++ptr
)) {
1397 cliShowParseError();
1400 cliShowArgumentRangeError("index", 0, CONFIGURABLE_COLOR_COUNT
- 1);
1407 static void cliServo(char *cmdline
)
1409 enum { SERVO_ARGUMENT_COUNT
= 8 };
1410 int16_t arguments
[SERVO_ARGUMENT_COUNT
];
1412 servoParam_t
*servo
;
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",
1430 servo
->forwardFromChannel
1434 int validArgumentCount
= 0;
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
1442 if (*ptr
== '-' || (*ptr
>= '0' && *ptr
<= '9')) {
1443 if (validArgumentCount
>= SERVO_ARGUMENT_COUNT
) {
1444 cliShowParseError();
1448 arguments
[validArgumentCount
++] = atoi(ptr
);
1452 } while (*ptr
>= '0' && *ptr
<= '9');
1453 } else if (*ptr
== ' ') {
1456 cliShowParseError();
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();
1471 servo
= &masterConfig
.servoConf
[i
];
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();
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];
1499 static void cliServoMix(char *cmdline
)
1504 int args
[8], check
= 0;
1505 len
= strlen(cmdline
);
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)
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
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
, ' ');
1537 len
= strlen(++ptr
);
1538 for (i
= 0; ; i
++) {
1539 if (mixerNames
[i
] == NULL
) {
1540 cliPrintf("Invalid name\r\n");
1543 if (strncasecmp(ptr
, mixerNames
[i
], len
) == 0) {
1544 servoMixerLoadMix(i
, masterConfig
.customServoMixer
);
1545 cliPrintf("Loaded %s\r\n", mixerNames
[i
]);
1551 } else if (strncasecmp(cmdline
, "reverse", 7) == 0) {
1552 enum {SERVO
= 0, INPUT
, REVERSE
, ARGS_COUNT
};
1553 int servoIndex
, inputSource
;
1554 ptr
= strchr(cmdline
, ' ');
1559 for (inputSource
= 0; inputSource
< INPUT_SOURCE_COUNT
; inputSource
++)
1560 cliPrintf("\ti%d", inputSource
);
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");
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();
1583 if (args
[SERVO
] >= 0 && args
[SERVO
] < MAX_SUPPORTED_SERVOS
1584 && args
[INPUT
] >= 0 && args
[INPUT
] < INPUT_SOURCE_COUNT
1585 && (*ptr
== 'r' || *ptr
== 'n')) {
1587 masterConfig
.servoConf
[args
[SERVO
]].reversedSources
|= 1 << args
[INPUT
];
1589 masterConfig
.servoConf
[args
[SERVO
]].reversedSources
&= ~(1 << args
[INPUT
]);
1591 cliShowParseError();
1593 cliServoMix("reverse");
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();
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
];
1625 cliShowParseError();
1633 static void cliWriteBytes(const uint8_t *buffer
, int count
)
1642 static void cliSdInfo(char *cmdline
) {
1645 cliPrint("SD card: ");
1647 if (!sdcard_isInserted()) {
1648 cliPrint("None inserted\r\n");
1652 if (!sdcard_isInitialized()) {
1653 cliPrint("Startup failed\r\n");
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
:
1676 case AFATFS_FILESYSTEM_STATE_INITIALIZATION
:
1677 cliPrint("Initializing");
1679 case AFATFS_FILESYSTEM_STATE_UNKNOWN
:
1680 case AFATFS_FILESYSTEM_STATE_FATAL
:
1683 switch (afatfs_getLastError()) {
1684 case AFATFS_ERROR_BAD_MBR
:
1685 cliPrint(" - no FAT MBR partitions");
1687 case AFATFS_ERROR_BAD_FILESYSTEM_HEADER
:
1688 cliPrint(" - bad FAT header");
1690 case AFATFS_ERROR_GENERIC
:
1691 case AFATFS_ERROR_NONE
:
1692 ; // Nothing more detailed to print
1705 static void cliFlashInfo(char *cmdline
)
1707 const flashGeometry_t
*layout
= flashfsGetGeometry();
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
)
1719 cliPrintf("Erasing...\r\n");
1720 flashfsEraseCompletely();
1722 while (!flashfsIsReady()) {
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
, ' ');
1737 cliShowParseError();
1739 flashfsSeekAbs(address
);
1740 flashfsWrite((uint8_t*)text
, strlen(text
), true);
1743 cliPrintf("Wrote %u bytes at %u.\r\n", strlen(text
), address
);
1747 static void cliFlashRead(char *cmdline
)
1749 uint32_t address
= atoi(cmdline
);
1755 char *nextArg
= strchr(cmdline
, ' ');
1758 cliShowParseError();
1760 length
= atoi(nextArg
);
1762 cliPrintf("Reading %u bytes at %u:\r\n", length
, address
);
1764 while (length
> 0) {
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
1789 static void cliVtx(char *cmdline
)
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
,
1803 MODE_STEP_TO_CHANNEL_VALUE(cac
->range
.startStep
),
1804 MODE_STEP_TO_CHANNEL_VALUE(cac
->range
.endStep
)
1810 if (i
< MAX_CHANNEL_ACTIVATION_CONDITION_COUNT
) {
1811 vtxChannelActivationCondition_t
*cac
= &masterConfig
.vtxChannelActivationConditions
[i
];
1812 uint8_t validArgumentCount
= 0;
1813 ptr
= strchr(ptr
, ' ');
1816 if (val
>= 0 && val
< MAX_AUX_CHANNEL_COUNT
) {
1817 cac
->auxChannelIndex
= val
;
1818 validArgumentCount
++;
1821 ptr
= strchr(ptr
, ' ');
1824 if (val
>= VTX_BAND_MIN
&& val
<= VTX_BAND_MAX
) {
1826 validArgumentCount
++;
1829 ptr
= strchr(ptr
, ' ');
1832 if (val
>= VTX_CHANNEL_MIN
&& val
<= VTX_CHANNEL_MAX
) {
1834 validArgumentCount
++;
1837 ptr
= processChannelRangeArgs(ptr
, &cac
->range
, &validArgumentCount
);
1839 if (validArgumentCount
!= 5) {
1840 memset(cac
, 0, sizeof(vtxChannelActivationCondition_t
));
1843 cliShowArgumentRangeError("index", 0, MAX_CHANNEL_ACTIVATION_CONDITION_COUNT
- 1);
1849 static void dumpValues(uint16_t valueSection
)
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
) {
1860 cliPrintf("set %s = ", valueTable
[i
].name
);
1861 cliPrintVar(value
, 0);
1867 DUMP_MASTER
= (1 << 0),
1868 DUMP_PROFILE
= (1 << 1),
1869 DUMP_RATES
= (1 << 2),
1870 DUMP_ALL
= (1 << 3),
1874 static const char* const sectionBreak
= "\r\n";
1876 #define printSectionBreak() cliPrintf((char *)sectionBreak)
1878 static void cliDump(char *cmdline
)
1884 #ifndef USE_QUAD_MIXER_ONLY
1885 float thr
, roll
, pitch
, yaw
;
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");
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
)
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
);
1926 cliPrintf("%s", ftoa(thr
, buf
));
1929 cliPrintf("%s", ftoa(roll
, buf
));
1932 cliPrintf("%s", ftoa(pitch
, buf
));
1935 cliPrintf("%s\r\n", ftoa(yaw
, buf
));
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)
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
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
)
1968 cliPrintf("feature -%s\r\n", featureNames
[i
]);
1970 for (i
= 0; ; i
++) { // reenable what we want.
1971 if (featureNames
[i
] == NULL
)
1973 if (mask
& (1 << i
))
1974 cliPrintf("feature %s\r\n", featureNames
[i
]);
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
));
1987 cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i
));
1992 cliPrint("\r\n\r\n# map\r\n");
1994 for (i
= 0; i
< 8; i
++)
1995 buf
[masterConfig
.rxConfig
.rcmap
[i
]] = rcChannelLetters
[i
];
1997 cliPrintf("map %s\r\n", buf
);
1999 cliPrint("\r\n\r\n# serial\r\n");
2003 cliPrint("\r\n\r\n# led\r\n");
2006 cliPrint("\r\n\r\n# color\r\n");
2010 cliPrint("\r\n# aux\r\n");
2014 cliPrint("\r\n# adjrange\r\n");
2016 cliAdjustmentRange("");
2018 cliPrintf("\r\n# rxrange\r\n");
2023 cliPrint("\r\n# servo\r\n");
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
);
2040 cliPrint("\r\n# vtx\r\n");
2045 printSectionBreak();
2046 dumpValues(MASTER_VALUE
);
2048 cliPrint("\r\n# rxfail\r\n");
2051 if (dumpMask
& DUMP_ALL
) {
2052 uint8_t activeProfile
= masterConfig
.current_profile_index
;
2053 uint8_t currentRateIndex
= currentProfile
->activeRateProfile
;
2054 uint8_t profileCount
;
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
);
2066 printSectionBreak();
2068 changeControlRateProfile(currentRateIndex
);
2071 cliPrint("\r\n# save configuration\r\nsave\r\n");
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
2092 changeProfile(profileIndex
);
2093 cliPrint("\r\n# profile\r\n");
2095 cliPrintf("############################# PROFILE VALUES ####################################\r\n");
2097 printSectionBreak();
2098 dumpValues(PROFILE_VALUE
);
2103 void cliDumpRateProfile(uint8_t rateProfileIndex
) {
2104 if (rateProfileIndex
>= MAX_RATEPROFILES
) // Faulty values
2107 changeControlRateProfile(rateProfileIndex
);
2108 cliPrint("\r\n# rateprofile\r\n");
2110 printSectionBreak();
2112 dumpValues(PROFILE_RATE_VALUE
);
2115 void cliEnter(serialPort_t
*serialPort
)
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");
2125 ENABLE_ARMING_FLAG(PREVENT_ARMING
);
2128 static void cliExit(char *cmdline
)
2132 cliPrint("\r\nLeaving CLI mode, unsaved changes lost.\r\n");
2133 bufWriterFlush(cliWriter
);
2138 // incase a motor was left running during motortest, clear it here
2139 mixerResetDisarmedMotors();
2145 static void cliFeature(char *cmdline
)
2151 len
= strlen(cmdline
);
2152 mask
= featureMask();
2155 cliPrint("Enabled: ");
2156 for (i
= 0; ; i
++) {
2157 if (featureNames
[i
] == NULL
)
2159 if (mask
& (1 << i
))
2160 cliPrintf("%s ", featureNames
[i
]);
2163 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2164 cliPrint("Available: ");
2165 for (i
= 0; ; i
++) {
2166 if (featureNames
[i
] == NULL
)
2168 cliPrintf("%s ", featureNames
[i
]);
2173 bool remove
= false;
2174 if (cmdline
[0] == '-') {
2177 cmdline
++; // skip over -
2181 for (i
= 0; ; i
++) {
2182 if (featureNames
[i
] == NULL
) {
2183 cliPrint("Invalid name\r\n");
2187 if (strncasecmp(cmdline
, featureNames
[i
], len
) == 0) {
2191 if (mask
& FEATURE_GPS
) {
2192 cliPrint("unavailable\r\n");
2197 if (mask
& FEATURE_SONAR
) {
2198 cliPrint("unavailable\r\n");
2204 cliPrint("Disabled");
2207 cliPrint("Enabled");
2209 cliPrintf(" %s\r\n", featureNames
[i
]);
2217 static void cliBeeper(char *cmdline
)
2220 uint32_t len
= strlen(cmdline
);;
2221 uint8_t beeperCount
= beeperTableEntryCount();
2222 uint32_t mask
= getBeeperOffMask();
2225 cliPrintf("Disabled:");
2226 for (int i
= 0; ; i
++) {
2227 if (i
== beeperCount
-2){
2232 if (mask
& (1 << i
))
2233 cliPrintf(" %s", beeperNameForTableIndex(i
));
2236 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2237 cliPrint("Available:");
2238 for (i
= 0; i
< beeperCount
; i
++)
2239 cliPrintf(" %s", beeperNameForTableIndex(i
));
2243 bool remove
= false;
2244 if (cmdline
[0] == '-') {
2245 remove
= true; // this is for beeper OFF condition
2250 for (i
= 0; ; i
++) {
2251 if (i
== beeperCount
) {
2252 cliPrint("Invalid name\r\n");
2255 if (strncasecmp(cmdline
, beeperNameForTableIndex(i
), len
) == 0) {
2256 if (remove
) { // beeper off
2257 if (i
== BEEPER_ALL
-1)
2258 beeperOffSetAll(beeperCount
-2);
2260 if (i
== BEEPER_PREFERENCE
-1)
2261 setBeeperOffMask(getPreferredBeeperOffMask());
2266 cliPrint("Disabled");
2269 if (i
== BEEPER_ALL
-1)
2270 beeperOffClearAll();
2272 if (i
== BEEPER_PREFERENCE
-1)
2273 setPreferredBeeperOffMask(getBeeperOffMask());
2276 beeperOffClear(mask
);
2278 cliPrint("Enabled");
2280 cliPrintf(" %s\r\n", beeperNameForTableIndex(i
));
2290 static void cliGpsPassthrough(char *cmdline
)
2294 gpsEnablePassthrough(cliPort
);
2298 static void cliHelp(char *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
);
2318 static void cliMap(char *cmdline
)
2324 len
= strlen(cmdline
);
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
]))
2333 cliShowParseError();
2336 parseRcChannels(cmdline
, &masterConfig
.rxConfig
);
2339 for (i
= 0; i
< 8; i
++)
2340 out
[masterConfig
.rxConfig
.rcmap
[i
]] = rcChannelLetters
[i
];
2342 cliPrintf("%s\r\n", out
);
2345 #ifndef USE_QUAD_MIXER_ONLY
2346 static void cliMixer(char *cmdline
)
2351 len
= strlen(cmdline
);
2354 cliPrintf("Mixer: %s\r\n", mixerNames
[masterConfig
.mixerMode
- 1]);
2356 } else if (strncasecmp(cmdline
, "list", len
) == 0) {
2357 cliPrint("Available mixers: ");
2358 for (i
= 0; ; i
++) {
2359 if (mixerNames
[i
] == NULL
)
2361 cliPrintf("%s ", mixerNames
[i
]);
2367 for (i
= 0; ; i
++) {
2368 if (mixerNames
[i
] == NULL
) {
2369 cliPrint("Invalid name\r\n");
2372 if (strncasecmp(cmdline
, mixerNames
[i
], len
) == 0) {
2373 masterConfig
.mixerMode
= i
+ 1;
2382 static void cliMotor(char *cmdline
)
2384 int motor_index
= 0;
2385 int motor_value
= 0;
2390 if (isEmpty(cmdline
)) {
2391 cliShowParseError();
2395 pch
= strtok_r(cmdline
, " ", &saveptr
);
2396 while (pch
!= NULL
) {
2399 motor_index
= atoi(pch
);
2402 motor_value
= atoi(pch
);
2406 pch
= strtok_r(NULL
, " ", &saveptr
);
2409 if (motor_index
< 0 || motor_index
>= MAX_SUPPORTED_MOTORS
) {
2410 cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS
- 1);
2415 if (motor_value
< PWM_RANGE_MIN
|| motor_value
> PWM_RANGE_MAX
) {
2416 cliShowArgumentRangeError("value", 1000, 2000);
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
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");
2449 } else { //index value was given
2451 if ((name
=beeperNameForTableIndex(i
)) == NULL
) {
2452 cliPrintf("No sound for index %d\r\n", i
);
2458 cliPrintf("Playing sound %d: %s\r\n", i
, name
);
2459 beeper(beeperModeForTableIndex(i
));
2463 static void cliProfile(char *cmdline
)
2467 if (isEmpty(cmdline
)) {
2468 cliPrintf("profile %d\r\n", getCurrentProfile());
2472 if (i
>= 0 && i
< MAX_PROFILE_COUNT
) {
2473 masterConfig
.current_profile_index
= i
;
2481 static void cliRateProfile(char *cmdline
) {
2484 if (isEmpty(cmdline
)) {
2485 cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile());
2489 if (i
>= 0 && i
< MAX_RATEPROFILES
) {
2490 changeControlRateProfile(i
);
2496 static void cliReboot(void) {
2497 cliPrint("\r\nRebooting");
2498 bufWriterFlush(cliWriter
);
2499 waitForSerialPortToFinishTransmitting(cliPort
);
2501 handleOneshotFeatureChangeOnRestart();
2505 static void cliSave(char *cmdline
)
2510 //copyCurrentProfileToProfileSlot(masterConfig.current_profile_index);
2515 static void cliDefaults(char *cmdline
)
2519 cliPrint("Resetting to defaults");
2524 static void cliPrint(const char *str
)
2527 bufWriterAppend(cliWriter
, *str
++);
2530 static void cliPutp(void *p
, char ch
)
2532 bufWriterAppend(p
, ch
);
2535 static void cliPrintf(const char *fmt
, ...)
2539 tfp_format(cliWriter
, cliPutp
, fmt
, va
);
2543 static void cliWrite(uint8_t ch
)
2545 bufWriterAppend(cliWriter
, ch
);
2548 static void cliPrintVar(const clivalue_t
*var
, uint32_t full
)
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
) {
2564 value
= *(uint8_t *)ptr
;
2568 value
= *(int8_t *)ptr
;
2572 value
= *(uint16_t *)ptr
;
2576 value
= *(int16_t *)ptr
;
2580 value
= *(uint32_t *)ptr
;
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
) {
2594 cliPrintf("%d", value
);
2596 cliPrintf(" %d %d", var
->config
.minmax
.min
, var
->config
.minmax
.max
);
2600 cliPrintf(lookupTables
[var
->config
.lookup
.tableIndex
].values
[value
]);
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
);
2611 case (MODE_LOOKUP
): {
2612 const lookupTableEntry_t
*tableEntry
= &lookupTables
[var
->config
.lookup
.tableIndex
];
2613 cliPrint("Allowed values:");
2615 for (i
= 0; i
< tableEntry
->valueCount
; i
++) {
2618 cliPrintf(" %s", tableEntry
->values
[i
]);
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
) {
2638 *(int8_t *)ptr
= value
.int_value
;
2643 *(int16_t *)ptr
= value
.int_value
;
2647 *(uint32_t *)ptr
= value
.int_value
;
2651 *(float *)ptr
= (float)value
.float_value
;
2656 static void cliSet(char *cmdline
)
2660 const clivalue_t
*val
;
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
2673 } else if ((eqptr
= strstr(cmdline
, "=")) != NULL
) {
2676 char *lastNonSpaceCharacter
= eqptr
;
2677 while (*(lastNonSpaceCharacter
- 1) == ' ') {
2678 lastNonSpaceCharacter
--;
2680 uint8_t variableNameLength
= lastNonSpaceCharacter
- cmdline
;
2682 // skip the '=' and any ' ' characters
2684 while (*(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
) {
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
;
2708 tmp
.int_value
= value
;
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;
2721 tmp
.int_value
= tableValueIndex
;
2730 cliSetVar(val
, tmp
);
2732 cliPrintf("%s set to ", valueTable
[i
].name
);
2733 cliPrintVar(val
, 0);
2735 cliPrint("Invalid value\r\n");
2736 cliPrintVarRange(val
);
2742 cliPrint("Invalid name\r\n");
2744 // no equals, check for matching variables.
2749 static void cliGet(char *cmdline
)
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);
2761 cliPrintVarRange(val
);
2769 if (matchedCommands
) {
2773 cliPrint("Invalid name\r\n");
2776 static void cliStatus(char *cmdline
)
2780 cliPrintf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery - %s), CPU:%d%%\r\n",
2784 getBatteryStateString(),
2785 constrain(averageSystemLoadPercent
, 0, 100)
2788 cliPrintf("CPU Clock=%dMHz", (SystemCoreClock
/ 1000000));
2793 uint32_t detectedSensorsMask
= sensorsMask();
2795 for (i
= 0; ; i
++) {
2797 if (sensorTypeNames
[i
] == NULL
)
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
);
2817 uint16_t i2cErrorCounter
= i2cGetErrorCounter();
2819 uint16_t i2cErrorCounter
= 0;
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
)
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
);
2848 taskFrequency
= subTaskFrequency
;
2849 cliPrintf("%d - (%s/%s) ", taskId
, taskInfo
.subTaskName
, taskInfo
.taskName
);
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);
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
);
2871 static void cliVersion(char *cmdline
)
2875 cliPrintf("# BetaFlight/%s %s %s / %s (%s)",
2884 void cliProcess(void)
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))
2906 if (pstart
) { /* Buffer matches one or more commands */
2907 for (; ; bufferIndex
++) {
2908 if (pstart
->name
[bufferIndex
] != pend
->name
[bufferIndex
])
2910 if (!pstart
->name
[bufferIndex
] && bufferIndex
< sizeof(cliBuffer
) - 2) {
2911 /* Unambiguous -- append a space */
2912 cliBuffer
[bufferIndex
++] = ' ';
2913 cliBuffer
[bufferIndex
] = '\0';
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
);
2927 i
= 0; /* Redraw prompt */
2929 for (; i
< bufferIndex
; i
++)
2930 cliWrite(cliBuffer
[i
]);
2931 } else if (!bufferIndex
&& c
== 4) { // CTRL-D
2934 } else if (c
== 12) { // NewPage / CTRL-L
2936 cliPrint("\033[2J\033[1;1H");
2938 } else if (bufferIndex
&& (c
== '\n' || c
== '\r')) {
2942 // Strip comment starting with # from line
2943 char *p
= cliBuffer
;
2946 bufferIndex
= (uint32_t)(p
- cliBuffer
);
2949 // Strip trailing whitespace
2950 while (bufferIndex
> 0 && cliBuffer
[bufferIndex
- 1] == ' ') {
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)
2964 if(cmd
< cmdTable
+ CMD_COUNT
)
2965 cmd
->func(cliBuffer
+ strlen(cmd
->name
) + 1);
2967 cliPrint("Unknown command, try 'help'");
2971 memset(cliBuffer
, 0, sizeof(cliBuffer
));
2973 // 'exit' will reset this flag, so we don't need to print prompt again
2978 } else if (c
== 127) {
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
;
2993 void cliInit(serialConfig_t
*serialConfig
)
2995 UNUSED(serialConfig
);