mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Fix problem with empty string set as 'manufacturer_id'.
This commit is contained in:
parent
ab4328f293
commit
c14a388687
2 changed files with 23 additions and 14 deletions
|
@ -3017,12 +3017,14 @@ static void printBoardName(dumpFlags_t dumpMask)
|
||||||
static void cliBoardName(char *cmdline)
|
static void cliBoardName(char *cmdline)
|
||||||
{
|
{
|
||||||
const unsigned int len = strlen(cmdline);
|
const unsigned int len = strlen(cmdline);
|
||||||
if (len > 0 && boardInformationIsSet() && (len != strlen(getBoardName()) || strncmp(getBoardName(), cmdline, len))) {
|
const char *boardName = getBoardName();
|
||||||
cliPrintErrorLinef(ERROR_MESSAGE, "BOARD_NAME", getBoardName());
|
if (len > 0 && strlen(boardName) != 0 && boardInformationIsSet() && (len != strlen(boardName) || strncmp(boardName, cmdline, len))) {
|
||||||
|
cliPrintErrorLinef(ERROR_MESSAGE, "BOARD_NAME", boardName);
|
||||||
} else {
|
} else {
|
||||||
if (len > 0) {
|
if (len > 0 && !configIsInCopy && setBoardName(cmdline)) {
|
||||||
setBoardName(cmdline);
|
|
||||||
boardInformationUpdated = true;
|
boardInformationUpdated = true;
|
||||||
|
|
||||||
|
cliPrintHashLine("Set board_name.");
|
||||||
}
|
}
|
||||||
printBoardName(DUMP_ALL);
|
printBoardName(DUMP_ALL);
|
||||||
}
|
}
|
||||||
|
@ -3038,12 +3040,14 @@ static void printManufacturerId(dumpFlags_t dumpMask)
|
||||||
static void cliManufacturerId(char *cmdline)
|
static void cliManufacturerId(char *cmdline)
|
||||||
{
|
{
|
||||||
const unsigned int len = strlen(cmdline);
|
const unsigned int len = strlen(cmdline);
|
||||||
if (len > 0 && boardInformationIsSet() && (len != strlen(getManufacturerId()) || strncmp(getManufacturerId(), cmdline, len))) {
|
const char *manufacturerId = getManufacturerId();
|
||||||
cliPrintErrorLinef(ERROR_MESSAGE, "MANUFACTURER_ID", getManufacturerId());
|
if (len > 0 && boardInformationIsSet() && strlen(manufacturerId) != 0 && (len != strlen(manufacturerId) || strncmp(manufacturerId, cmdline, len))) {
|
||||||
|
cliPrintErrorLinef(ERROR_MESSAGE, "MANUFACTURER_ID", manufacturerId);
|
||||||
} else {
|
} else {
|
||||||
if (len > 0) {
|
if (len > 0 && !configIsInCopy && setManufacturerId(cmdline)) {
|
||||||
setManufacturerId(cmdline);
|
|
||||||
boardInformationUpdated = true;
|
boardInformationUpdated = true;
|
||||||
|
|
||||||
|
cliPrintHashLine("Set manufacturer_id.");
|
||||||
}
|
}
|
||||||
printManufacturerId(DUMP_ALL);
|
printManufacturerId(DUMP_ALL);
|
||||||
}
|
}
|
||||||
|
@ -3092,12 +3096,12 @@ static void cliSignature(char *cmdline)
|
||||||
writeSignature(signatureStr, getSignature());
|
writeSignature(signatureStr, getSignature());
|
||||||
cliPrintErrorLinef(ERROR_MESSAGE, "SIGNATURE", signatureStr);
|
cliPrintErrorLinef(ERROR_MESSAGE, "SIGNATURE", signatureStr);
|
||||||
} else {
|
} else {
|
||||||
if (len > 0) {
|
if (len > 0 && !configIsInCopy && setSignature(signature)) {
|
||||||
setSignature(signature);
|
|
||||||
|
|
||||||
signatureUpdated = true;
|
signatureUpdated = true;
|
||||||
|
|
||||||
writeSignature(signatureStr, getSignature());
|
writeSignature(signatureStr, getSignature());
|
||||||
|
|
||||||
|
cliPrintHashLine("Set signature.");
|
||||||
} else if (signatureUpdated || signatureIsSet()) {
|
} else if (signatureUpdated || signatureIsSet()) {
|
||||||
writeSignature(signatureStr, getSignature());
|
writeSignature(signatureStr, getSignature());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
static bool boardInformationSet = false;
|
static bool boardInformationSet = false;
|
||||||
static char manufacturerId[MAX_MANUFACTURER_ID_LENGTH + 1];
|
static char manufacturerId[MAX_MANUFACTURER_ID_LENGTH + 1];
|
||||||
static char boardName[MAX_BOARD_NAME_LENGTH + 1];
|
static char boardName[MAX_BOARD_NAME_LENGTH + 1];
|
||||||
|
static bool boardInformationWasUpdated = false;
|
||||||
|
|
||||||
static bool signatureSet = false;
|
static bool signatureSet = false;
|
||||||
static uint8_t signature[SIGNATURE_LENGTH];
|
static uint8_t signature[SIGNATURE_LENGTH];
|
||||||
|
@ -64,9 +65,11 @@ bool boardInformationIsSet(void)
|
||||||
|
|
||||||
bool setManufacturerId(const char *newManufacturerId)
|
bool setManufacturerId(const char *newManufacturerId)
|
||||||
{
|
{
|
||||||
if (!boardInformationSet) {
|
if (!boardInformationSet || strlen(manufacturerId) == 0) {
|
||||||
strncpy(manufacturerId, newManufacturerId, MAX_MANUFACTURER_ID_LENGTH);
|
strncpy(manufacturerId, newManufacturerId, MAX_MANUFACTURER_ID_LENGTH);
|
||||||
|
|
||||||
|
boardInformationWasUpdated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,9 +78,11 @@ bool setManufacturerId(const char *newManufacturerId)
|
||||||
|
|
||||||
bool setBoardName(const char *newBoardName)
|
bool setBoardName(const char *newBoardName)
|
||||||
{
|
{
|
||||||
if (!boardInformationSet) {
|
if (!boardInformationSet || strlen(boardName) == 0) {
|
||||||
strncpy(boardName, newBoardName, MAX_BOARD_NAME_LENGTH);
|
strncpy(boardName, newBoardName, MAX_BOARD_NAME_LENGTH);
|
||||||
|
|
||||||
|
boardInformationWasUpdated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -86,7 +91,7 @@ bool setBoardName(const char *newBoardName)
|
||||||
|
|
||||||
bool persistBoardInformation(void)
|
bool persistBoardInformation(void)
|
||||||
{
|
{
|
||||||
if (!boardInformationSet) {
|
if (boardInformationWasUpdated) {
|
||||||
strncpy(boardConfigMutable()->manufacturerId, manufacturerId, MAX_MANUFACTURER_ID_LENGTH);
|
strncpy(boardConfigMutable()->manufacturerId, manufacturerId, MAX_MANUFACTURER_ID_LENGTH);
|
||||||
strncpy(boardConfigMutable()->boardName, boardName, MAX_BOARD_NAME_LENGTH);
|
strncpy(boardConfigMutable()->boardName, boardName, MAX_BOARD_NAME_LENGTH);
|
||||||
boardConfigMutable()->boardInformationSet = true;
|
boardConfigMutable()->boardInformationSet = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue