Skip to content

Commit 2936574

Browse files
committed
cliConfig
1 parent e86e758 commit 2936574

File tree

2 files changed

+244
-0
lines changed

2 files changed

+244
-0
lines changed

src/main/cli/cli.c

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,6 +4514,246 @@ STATIC_UNIT_TESTED void cliGet(const char *cmdName, char *cmdline)
45144514
}
45154515
}
45164516

4517+
#ifdef USE_PEGASUS_UI
4518+
static const char * valueSectionMask[] = {
4519+
"GLOBAL", "PROFILE", "RATE", "HARDWARE"
4520+
};
4521+
4522+
static const char * valueTypeMask[] = {
4523+
"UINT8", "INT8", "UINT16", "INT16"
4524+
};
4525+
4526+
static const char * valueModeMask[] = {
4527+
"DIRECT", "LOOKUP", "ARRAY", "BITMASK", "STRING"
4528+
};
4529+
4530+
void cliPrintValueJson(const char *cmdName, int32_t i){
4531+
const clivalue_t *var = &valueTable[i];
4532+
cliPrintf("\"%s\":{\"scope\":\"%s\",\"type\":\"%s\",\"mode\":\"%s\",\"current\":\"",
4533+
var->name,
4534+
valueSectionMask[((var->type & VALUE_SECTION_MASK) >> VALUE_SECTION_OFFSET)],
4535+
valueTypeMask[((var->type & VALUE_TYPE_MASK) >> VALUE_TYPE_OFFSET)],
4536+
valueModeMask[((var->type & VALUE_MODE_MASK) >> VALUE_MODE_OFFSET)]);
4537+
cliPrintVar(cmdName, var, 0);
4538+
if ((var->type & VALUE_MODE_MASK) == MODE_STRING) {
4539+
cliPrintf("\",\"string min length\":\"%d\",\"string max length\":\"%d\"", var->config.string.minlength, var->config.string.maxlength);
4540+
// strings have no default
4541+
} else {
4542+
cliPrint("\",\"default\":\"");
4543+
const pgRegistry_t *pg = pgFind(var->pgn);
4544+
const int valueOffset = getValueOffset(var);
4545+
printValuePointer(cmdName, var, (uint8_t*)pg->address + valueOffset, false);
4546+
cliPrint("\"");
4547+
if ((var->type & VALUE_MODE_MASK) == MODE_LOOKUP)
4548+
{
4549+
const lookupTableEntry_t *tableEntry = &lookupTables[var->config.lookup.tableIndex];
4550+
cliPrintLine(",\"values\":[");
4551+
for (int32_t i = 0; i < tableEntry->valueCount ; i++) {
4552+
if (i > 0)
4553+
{
4554+
cliPrintLine(",");
4555+
}
4556+
cliPrintf("\"%s\"", tableEntry->values[i]);
4557+
}
4558+
cliPrint("]");
4559+
}
4560+
4561+
int min;
4562+
int max;
4563+
getMinMax(var, &min, &max);
4564+
4565+
if ((var->type & VALUE_MODE_MASK) == MODE_DIRECT) {
4566+
cliPrintf(",\"min\":\"%d\",\"max\":\"%d\"", min, max);
4567+
}
4568+
if ((var->type & VALUE_MODE_MASK) == MODE_ARRAY) {
4569+
cliPrintf(",\"min\":\"%d\",\"max\":\"%d\"", min, max);
4570+
}
4571+
}
4572+
cliPrint("}");
4573+
}
4574+
4575+
static void printFeatureJson(const featureConfig_t *configCopy)
4576+
{
4577+
const uint32_t mask = configCopy->enabledFeatures;
4578+
const uint32_t defaultMask = featureConfig()->enabledFeatures;
4579+
cliPrintLine(",");
4580+
cliPrintf("\"features\":{\"scope\":\"GLOBAL\",\"type\":\"UINT8\",\"mode\":\"ARRAY\",\"current\":\"%d\",\"values\":[", mask);
4581+
cliPrintLine("");
4582+
for (uint32_t i = 0; featureNames[i]; i++) { // disabled features first
4583+
if (strcmp(featureNames[i], emptyString) != 0) { //Skip unused
4584+
if (i > 0)
4585+
{
4586+
cliPrintLine(",");
4587+
}
4588+
if ((~defaultMask | mask) & (1 << i)) {
4589+
cliPrintf("\"-%s\"", featureNames[i]);
4590+
} else {
4591+
cliPrintf("\"%s\"", featureNames[i]);
4592+
}
4593+
}
4594+
}
4595+
cliPrintf("]}");
4596+
}
4597+
static void printSerialJson(const serialConfig_t *serialConfig)
4598+
{
4599+
cliPrintLine(",");
4600+
cliPrintLine("\"ports\":{\"scope\":\"GLOBAL\",\"type\":\"UINT16\",\"mode\":\"ARRAY\",\"values\":[");
4601+
for (uint32_t i = 0; i < SERIAL_PORT_COUNT; i++) {
4602+
if (!serialIsPortAvailable(serialConfig->portConfigs[i].identifier)) {
4603+
continue;
4604+
};
4605+
if (i > 0)
4606+
{
4607+
cliPrintLine(",");
4608+
}
4609+
cliPrintf("\"%d|%d|%ld|%ld|%ld|%ld\"",
4610+
serialConfig->portConfigs[i].identifier,
4611+
serialConfig->portConfigs[i].functionMask,
4612+
baudRates[serialConfig->portConfigs[i].msp_baudrateIndex],
4613+
baudRates[serialConfig->portConfigs[i].gps_baudrateIndex],
4614+
baudRates[serialConfig->portConfigs[i].telemetry_baudrateIndex],
4615+
baudRates[serialConfig->portConfigs[i].blackbox_baudrateIndex]);
4616+
}
4617+
cliPrintf("]}");
4618+
}
4619+
4620+
static void printAuxJson(const modeActivationCondition_t *modeActivationConditions)
4621+
{
4622+
cliPrintLine(",");
4623+
cliPrintLine("\"modes\":{\"scope\":\"GLOBAL\",\"type\":\"UINT16\",\"mode\":\"ARRAY\",\"values\":[");
4624+
for (uint32_t i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) {
4625+
if (i > 0)
4626+
{
4627+
cliPrintLine(",");
4628+
}
4629+
const modeActivationCondition_t *mac = &modeActivationConditions[i];
4630+
const box_t *box = findBoxByBoxId(mac->modeId);
4631+
if (box) {
4632+
cliPrintf("\"%u|%u|%u|%u|%u|%u\"",
4633+
i,
4634+
box->permanentId,
4635+
mac->auxChannelIndex,
4636+
MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep),
4637+
MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep),
4638+
mac->modeLogic
4639+
);
4640+
}
4641+
}
4642+
cliPrintf("]}");
4643+
}
4644+
4645+
static void printResourceJson()
4646+
{
4647+
cliPrintLine(",");
4648+
cliPrintLine("\"resources\":{\"scope\":\"GLOBAL\",\"type\":\"string\",\"mode\":\"ARRAY\",\"values\":[");
4649+
for (int i = 0; i < DEFIO_IO_USED_COUNT; i++) {
4650+
if (i > 0)
4651+
{
4652+
cliPrintLine(",");
4653+
}
4654+
const char* owner;
4655+
owner = ownerNames[ioRecs[i].owner];
4656+
4657+
cliPrintf("\"%c%02d|%s|", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner);
4658+
if (ioRecs[i].index > 0) {
4659+
cliPrintf("%d", ioRecs[i].index);
4660+
} else {
4661+
cliPrintf("0");
4662+
}
4663+
cliPrintf("\"");
4664+
//cliPrintLinefeed();
4665+
}
4666+
cliPrintf("]}");
4667+
}
4668+
4669+
#define PROFILE_JSON_STRING "\"%s_profile\":{\"scope\":\"GLOBAL\",\"type\":\"UINT8\",\"mode\":\"LOOKUP\",\"current\":\"%d\",\"values\":[{"
4670+
4671+
static void dumpProfileValueJson(const char *cmdName, uint16_t valueSection)
4672+
{
4673+
bool foundFirst = false;
4674+
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
4675+
const clivalue_t *value = &valueTable[i];
4676+
if ((value->type & VALUE_SECTION_MASK) == valueSection) {
4677+
if (foundFirst)
4678+
{
4679+
cliPrintLine(",");
4680+
}
4681+
cliPrintValueJson(cmdName, i);
4682+
foundFirst = true;
4683+
}
4684+
}
4685+
}
4686+
4687+
static void cliPidProfilesJson(const char *cmdName)
4688+
{
4689+
cliPrintLine(",");
4690+
cliPrintf(PROFILE_JSON_STRING, "pid", getCurrentPidProfileIndex());
4691+
const uint8_t saved = systemConfig_Copy.pidProfileIndex;
4692+
for (uint32_t i = 0; i < PID_PROFILE_COUNT; i++) {
4693+
changePidProfile(i);
4694+
if (i > 0)
4695+
{
4696+
cliPrintLine("},");
4697+
cliPrint("{");
4698+
}
4699+
dumpProfileValueJson(cmdName, PROFILE_VALUE);
4700+
}
4701+
changePidProfile(saved);
4702+
cliPrint("}]}");
4703+
}
4704+
4705+
static void cliRateProfilesJson(const char *cmdName)
4706+
{
4707+
cliPrintLine(",");
4708+
cliPrintf(PROFILE_JSON_STRING, "rate", getCurrentControlRateProfileIndex());
4709+
const uint8_t saved = systemConfig_Copy.activeRateProfile;
4710+
for (uint32_t i = 0; i < CONTROL_RATE_PROFILE_COUNT; i++) {
4711+
changeControlRateProfile(i);
4712+
if (i > 0)
4713+
{
4714+
cliPrintLine("},");
4715+
cliPrint("{");
4716+
}
4717+
dumpProfileValueJson(cmdName, PROFILE_RATE_VALUE);
4718+
}
4719+
changeControlRateProfile(saved);
4720+
cliPrint("}]}");
4721+
}
4722+
4723+
static void cliConfig(const char *cmdName, char *cmdline)
4724+
{
4725+
UNUSED(cmdline);
4726+
4727+
cliPrintLine("{");
4728+
for (uint32_t i = 0; i < valueTableEntryCount; i++)
4729+
{
4730+
if (i > 0)
4731+
{
4732+
cliPrintLine(",");
4733+
}
4734+
cliPrintValueJson(cmdName, i);
4735+
}
4736+
cliPidProfilesJson(cmdName);
4737+
cliRateProfilesJson(cmdName);
4738+
printFeatureJson(&featureConfig_Copy);
4739+
printSerialJson(serialConfig());
4740+
printAuxJson(modeActivationConditions(0));
4741+
printResourceJson();
4742+
cliPrintLine(",");
4743+
cliPrintf("\"name\":\"%s\"", pilotConfig()->name);
4744+
cliPrintf(",\"version\":\"%s|%s|%s|%s\"",
4745+
FC_FIRMWARE_NAME,
4746+
targetName,
4747+
systemConfig()->boardIdentifier,
4748+
FC_VERSION_STRING
4749+
);
4750+
#ifdef USE_GYRO_IMUF9001
4751+
cliPrintf(",\"imuf\":\"%lu\"", imufCurrentVersion);
4752+
#endif
4753+
cliPrintLine("}");
4754+
}
4755+
#endif
4756+
45174757
static uint8_t getWordLength(char *bufBegin, char *bufEnd)
45184758
{
45194759
while (*(bufEnd - 1) == ' ') {
@@ -6558,6 +6798,9 @@ const clicmd_t cmdTable[] = {
65586798
#endif
65596799
#endif
65606800
CLI_COMMAND_DEF("get", "get variable value", "[name]", cliGet),
6801+
#ifdef USE_PEGASUS_UI
6802+
CLI_COMMAND_DEF("config", "get all configuration information", NULL, cliConfig),
6803+
#endif
65616804
#ifdef USE_GPS
65626805
CLI_COMMAND_DEF("gpspassthrough", "passthrough gps to serial", NULL, cliGpsPassthrough),
65636806
#endif

src/main/target/common_pre.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ extern uint8_t _dmaram_end__;
295295
#define USE_MSP_OVER_TELEMETRY
296296
#define USE_OSD_OVER_MSP_DISPLAYPORT
297297
#define USE_LED_STRIP
298+
#define USE_PEGASUS_UI
298299
#endif
299300

300301
#if ((TARGET_FLASH_SIZE > 256) || (FEATURE_CUT_LEVEL < 11))

0 commit comments

Comments
 (0)