1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 03:50:02 +03:00

Merge pull request #8666 from mikeller/add_timers_show

Added 'timer show' command to CLI.
This commit is contained in:
Michael Keller 2019-08-09 05:49:07 +12:00 committed by GitHub
commit 26bca16d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 264 additions and 176 deletions

View file

@ -61,6 +61,7 @@ uint8_t cliMode = 0;
#include "drivers/adc.h"
#include "drivers/buf_writer.h"
#include "drivers/bus_spi.h"
#include "drivers/dma.h"
#include "drivers/dma_reqmap.h"
#include "drivers/dshot.h"
#include "drivers/dshot_command.h"
@ -76,6 +77,7 @@ uint8_t cliMode = 0;
#include "drivers/light_led.h"
#include "drivers/motor.h"
#include "drivers/rangefinder/rangefinder_hcsr04.h"
#include "drivers/resource.h"
#include "drivers/sdcard.h"
#include "drivers/sensor.h"
#include "drivers/serial.h"
@ -4911,7 +4913,7 @@ static bool strToPin(char *pch, ioTag_t *tag)
}
#ifdef USE_DMA
static void printDma(void)
static void showDma(void)
{
cliPrintLinefeed();
@ -4922,15 +4924,13 @@ static void printDma(void)
cliRepeat('-', 20);
#endif
for (int i = 1; i <= DMA_LAST_HANDLER; i++) {
const char* owner;
owner = ownerNames[dmaGetOwner(i)];
const resourceOwner_t *owner = dmaGetOwner(i);
cliPrintf(DMA_OUTPUT_STRING, DMA_DEVICE_NO(i), DMA_DEVICE_INDEX(i));
uint8_t resourceIndex = dmaGetResourceIndex(i);
if (resourceIndex > 0) {
cliPrintLinef(" %s %d", owner, resourceIndex);
if (owner->resourceIndex > 0) {
cliPrintLinef(" %s %d", ownerNames[owner->owner], owner->resourceIndex);
} else {
cliPrintLinef(" %s", owner);
cliPrintLinef(" %s", ownerNames[owner->owner]);
}
}
}
@ -5323,7 +5323,7 @@ static void cliDma(char* cmdline)
{
int len = strlen(cmdline);
if (len && strncasecmp(cmdline, "show", len) == 0) {
printDma();
showDma();
return;
}
@ -5335,103 +5335,6 @@ static void cliDma(char* cmdline)
#endif
}
#endif
static void cliResource(char *cmdline)
{
char *pch = NULL;
char *saveptr;
pch = strtok_r(cmdline, " ", &saveptr);
if (!pch) {
printResource(DUMP_MASTER | HIDE_UNUSED, NULL);
return;
} else if (strcasecmp(pch, "show") == 0) {
#ifdef MINIMAL_CLI
cliPrintLine("IO");
#else
cliPrintLine("Currently active IO resource assignments:\r\n(reboot to update)");
cliRepeat('-', 20);
#endif
for (int i = 0; i < DEFIO_IO_USED_COUNT; i++) {
const char* owner;
owner = ownerNames[ioRecs[i].owner];
cliPrintf("%c%02d: %s", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner);
if (ioRecs[i].index > 0) {
cliPrintf(" %d", ioRecs[i].index);
}
cliPrintLinefeed();
}
#if defined(USE_DMA)
pch = strtok_r(NULL, " ", &saveptr);
if (strcasecmp(pch, "all") == 0) {
cliDma("show");
}
#endif
return;
}
uint8_t resourceIndex = 0;
int index = 0;
for (resourceIndex = 0; ; resourceIndex++) {
if (resourceIndex >= ARRAYLEN(resourceTable)) {
cliPrintErrorLinef("INVALID RESOURCE NAME: '%s'", pch);
return;
}
const char * resourceName = ownerNames[resourceTable[resourceIndex].owner];
if (strncasecmp(pch, resourceName, strlen(resourceName)) == 0) {
break;
}
}
pch = strtok_r(NULL, " ", &saveptr);
index = atoi(pch);
if (resourceTable[resourceIndex].maxIndex > 0 || index > 0) {
if (index <= 0 || index > MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex)) {
cliShowArgumentRangeError("INDEX", 1, MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex));
return;
}
index -= 1;
pch = strtok_r(NULL, " ", &saveptr);
}
ioTag_t *tag = getIoTag(resourceTable[resourceIndex], index);
if (strlen(pch) > 0) {
if (strToPin(pch, tag)) {
if (*tag == IO_TAG_NONE) {
#ifdef MINIMAL_CLI
cliPrintLine("Freed");
#else
cliPrintLine("Resource is freed");
#endif
return;
} else {
ioRec_t *rec = IO_Rec(IOGetByTag(*tag));
if (rec) {
resourceCheck(resourceIndex, index, *tag);
#ifdef MINIMAL_CLI
cliPrintLinef(" %c%02d set", IO_GPIOPortIdx(rec) + 'A', IO_GPIOPinIdx(rec));
#else
cliPrintLinef("\r\nResource is set to %c%02d", IO_GPIOPortIdx(rec) + 'A', IO_GPIOPinIdx(rec));
#endif
} else {
cliShowParseError();
}
return;
}
}
}
cliShowParseError();
}
#endif // USE_RESOURCE_MGMT
#ifdef USE_TIMER_MGMT
@ -5536,6 +5439,44 @@ static void alternateFunctionToString(const ioTag_t ioTag, const int index, char
}
}
static void showTimers(void)
{
cliPrintLinefeed();
#ifdef MINIMAL_CLI
cliPrintLine("Timers:");
#else
cliPrintLine("Currently active Timers:");
cliRepeat('-', 23);
#endif
int8_t timerNumber;
for (int i = 0; (timerNumber = timerGetNumberByIndex(i)); i++) {
cliPrintf("TIM%d:", timerNumber);
bool timerUsed = false;
for (unsigned timerIndex = 0; timerIndex < CC_CHANNELS_PER_TIMER; timerIndex++) {
const resourceOwner_t *timerOwner = timerGetOwner(timerNumber, CC_CHANNEL_FROM_INDEX(timerIndex));
if (timerOwner->owner) {
if (!timerUsed) {
timerUsed = true;
cliPrintLinefeed();
}
if (timerOwner->resourceIndex > 0) {
cliPrintLinef(" CH%d: %s %d", timerIndex + 1, ownerNames[timerOwner->owner], timerOwner->resourceIndex);
} else {
cliPrintLinef(" CH%d: %s", timerIndex + 1, ownerNames[timerOwner->owner]);
}
}
}
if (!timerUsed) {
cliPrintLine(" FREE");
}
}
}
static void cliTimer(char *cmdline)
{
int len = strlen(cmdline);
@ -5549,7 +5490,7 @@ static void cliTimer(char *cmdline)
return;
} else if (strncasecmp(cmdline, "show", len) == 0) {
cliPrintErrorLinef("NOT IMPLEMENTED YET");
showTimers();
return;
}
@ -5665,6 +5606,107 @@ static void cliTimer(char *cmdline)
}
#endif
#if defined(USE_RESOURCE_MGMT)
static void cliResource(char *cmdline)
{
char *pch = NULL;
char *saveptr;
pch = strtok_r(cmdline, " ", &saveptr);
if (!pch) {
printResource(DUMP_MASTER | HIDE_UNUSED, NULL);
return;
} else if (strcasecmp(pch, "show") == 0) {
#ifdef MINIMAL_CLI
cliPrintLine("IO");
#else
cliPrintLine("Currently active IO resource assignments:\r\n(reboot to update)");
cliRepeat('-', 20);
#endif
for (int i = 0; i < DEFIO_IO_USED_COUNT; i++) {
const char* owner;
owner = ownerNames[ioRecs[i].owner];
cliPrintf("%c%02d: %s", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner);
if (ioRecs[i].index > 0) {
cliPrintf(" %d", ioRecs[i].index);
}
cliPrintLinefeed();
}
pch = strtok_r(NULL, " ", &saveptr);
if (strcasecmp(pch, "all") == 0) {
#if defined(USE_TIMER_MGMT)
cliTimer("show");
#endif
#if defined(USE_DMA)
cliDma("show");
#endif
}
return;
}
uint8_t resourceIndex = 0;
int index = 0;
for (resourceIndex = 0; ; resourceIndex++) {
if (resourceIndex >= ARRAYLEN(resourceTable)) {
cliPrintErrorLinef("INVALID RESOURCE NAME: '%s'", pch);
return;
}
const char * resourceName = ownerNames[resourceTable[resourceIndex].owner];
if (strncasecmp(pch, resourceName, strlen(resourceName)) == 0) {
break;
}
}
pch = strtok_r(NULL, " ", &saveptr);
index = atoi(pch);
if (resourceTable[resourceIndex].maxIndex > 0 || index > 0) {
if (index <= 0 || index > MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex)) {
cliShowArgumentRangeError("INDEX", 1, MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex));
return;
}
index -= 1;
pch = strtok_r(NULL, " ", &saveptr);
}
ioTag_t *tag = getIoTag(resourceTable[resourceIndex], index);
if (strlen(pch) > 0) {
if (strToPin(pch, tag)) {
if (*tag == IO_TAG_NONE) {
#ifdef MINIMAL_CLI
cliPrintLine("Freed");
#else
cliPrintLine("Resource is freed");
#endif
return;
} else {
ioRec_t *rec = IO_Rec(IOGetByTag(*tag));
if (rec) {
resourceCheck(resourceIndex, index, *tag);
#ifdef MINIMAL_CLI
cliPrintLinef(" %c%02d set", IO_GPIOPortIdx(rec) + 'A', IO_GPIOPinIdx(rec));
#else
cliPrintLinef("\r\nResource is set to %c%02d", IO_GPIOPortIdx(rec) + 'A', IO_GPIOPinIdx(rec));
#endif
} else {
cliShowParseError();
}
return;
}
}
}
cliShowParseError();
}
#endif
#ifdef USE_DSHOT_TELEMETRY
static void cliDshotTelemetryInfo(char *cmdline)
{