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; break;
} }
} }
return b - data == size; return (size_t) (b - data) == size;
} }
bool configReadBytes(int *address, uint8_t *data, size_t 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; break;
} }
} }
return b - data == size; return (size_t) (b - data) == size;
} }

View File

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

View File

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