console empty command FIX

This commit is contained in:
Patrick Haßel 2024-04-12 10:08:07 +02:00
parent 9952ebd6e4
commit 47d678cd23
3 changed files with 34 additions and 15 deletions

View File

@ -128,7 +128,7 @@ bool configWriteBytes(int *address, uint8_t *data, size_t size) {
break;
}
}
return b - data == size;
return (size_t) (b - data) == size;
}
bool configReadBytes(int *address, uint8_t *data, size_t size) {
@ -140,5 +140,5 @@ bool configReadBytes(int *address, uint8_t *data, size_t size) {
break;
}
}
return b - data == size;
return (size_t) (b - data) == size;
}

View File

@ -68,6 +68,10 @@ void consoleLoop() {
void consoleHandle(char *cmd) {
char *first = strtok(cmd, " ");
if (first == nullptr) {
_usage();
return;
}
if (strcmp(first, "help") == 0) {
_usage();
} else if (strcmp(first, "wifi") == 0) {
@ -88,19 +92,18 @@ void consoleHandle(char *cmd) {
}
void _usage() {
info("help");
info("info");
info("debug");
info("reboot");
info("config_reset");
info("wifi reconnect");
info("wifi ssid <SSID>");
info("wifi pkey <PKEY>");
info("mqtt reconnect");
info("mqtt host <HOST>");
info(R"(USAGE:
help
info
debug
reboot
config_reset
wifi reconnect
wifi ssid <SSID>
wifi pkey <PKEY>
mqtt reconnect
mqtt host <HOST>
)");
}
void _debug() {
@ -117,6 +120,10 @@ void _reboot() {
void _mqtt() {
char *sub = strtok(nullptr, " ");
if (sub == nullptr) {
_usage();
return;
}
if (strcmp(sub, "reconnect") == 0) {
info("Reconnecting MQTT...");
mqttDisconnect();
@ -127,6 +134,10 @@ void _mqtt() {
void _wifi() {
char *sub = strtok(nullptr, " ");
if (sub == nullptr) {
_usage();
return;
}
if (strcmp(sub, "reconnect") == 0) {
info("Reconnecting WiFi...");
wifiConnect();
@ -139,6 +150,10 @@ void _wifi() {
void _setConfigString(const char *name, bool allowEmpty) {
char *value = strtok(nullptr, "");
if (value == nullptr) {
_usage();
return;
}
if (!allowEmpty && strcmp(value, "") == 0) {
error(R"(Value for "%s" cannot be empty!")", name);
return;

View File

@ -82,6 +82,10 @@ void patrixLoop() {
bool setDouble(const char *name, double *destinationPtr, double min, double max) {
const char *valueStr = strtok(nullptr, "");
if (valueStr == nullptr) {
_usage();
return;
}
if (valueStr == nullptr) {
error("Missing value for \"%s\"", name);
return false;