diff --git a/firmware/controllers/core/error_handling.cpp b/firmware/controllers/core/error_handling.cpp index 0b63fb5dbf..f0f24dade6 100644 --- a/firmware/controllers/core/error_handling.cpp +++ b/firmware/controllers/core/error_handling.cpp @@ -6,7 +6,7 @@ */ #include "pch.h" -#include "efistringutil.h" +#include "rusefi/efistringutil.h" #include "backup_ram.h" #include "error_handling_led.h" diff --git a/firmware/libfirmware b/firmware/libfirmware index 8800977c78..28a7376a84 160000 --- a/firmware/libfirmware +++ b/firmware/libfirmware @@ -1 +1 @@ -Subproject commit 8800977c7803f2dbb4b4c8daa4e1acf3bd1210cf +Subproject commit 28a7376a84f131dc890f20b7eccd636a17a2feed diff --git a/firmware/pch/pch.h b/firmware/pch/pch.h index 4e5fa46509..17f6632ed2 100644 --- a/firmware/pch/pch.h +++ b/firmware/pch/pch.h @@ -16,10 +16,10 @@ #include #include #include +#include #include "global.h" #include "efifeatures.h" -#include "efistringutil.h" #include "rusefi_generated.h" #include "loggingcentral.h" #include "error_handling.h" diff --git a/firmware/util/cli_registry.cpp b/firmware/util/cli_registry.cpp index f85649ed75..2fca30ea1d 100644 --- a/firmware/util/cli_registry.cpp +++ b/firmware/util/cli_registry.cpp @@ -19,7 +19,7 @@ #include #include #include "efiprintf.h" -#include "efistringutil.h" +#include "rusefi/efistringutil.h" #include "cli_registry.h" /* for isspace() */ diff --git a/firmware/util/efistringutil.cpp b/firmware/util/efistringutil.cpp deleted file mode 100644 index 05441bccd1..0000000000 --- a/firmware/util/efistringutil.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -#include -#include "efiprintf.h" -#include "efistringutil.h" -#include "efiprintf.h" -#include - -uint32_t efiStrlen(const char *param) { - const char *s; - for (s = param; *s; ++s) - ; - return (s - param); -} - -int indexOf(const char *string, char ch) { - // a standard function for this is strnchr? - // todo: on the other hand MISRA wants us not to use standard headers - int len = efiStrlen(string); - for (int i = 0; i < len; i++) { - if (string[i] == ch) { - return i; - } - } - return -1; -} - -// string to integer -int atoi(const char *string) { - int len = strlen(string); - if (len == 0) { - return -ATOI_ERROR_CODE; - } - if (string[0] == '-') { - return -atoi(string + 1); - } - int result = 0; - - for (int i = 0; i < len; i++) { - char ch = string[i]; - if (ch < '0' || ch > '9') { - if (i > 0) { - break; - } else { - return ATOI_ERROR_CODE; - } - } - int c = ch - '0'; - result = result * 10 + c; - } - - return result; -} - -bool strEqualCaseInsensitive(const char *str1, const char *str2) { - int len1 = strlen(str1); - int len2 = strlen(str2); - if (len1 != len2) { - return false; - } - for (int i = 0; i < len1; i++) - if (TO_LOWER(str1[i]) != TO_LOWER(str2[i])) - return false; - return true; -} - -bool strEqual(const char *str1, const char *str2) { - // todo: there must be a standard function?! - int len1 = strlen(str1); - int len2 = strlen(str2); - if (len1 != len2) { - return false; - } - for (int i = 0; i < len1; i++) - if (str1[i] != str2[i]) - return false; - return true; -} - -/** - * string to float. NaN input is supported - * - * @return NAN in case of invalid string - * todo: explicit value for error code? probably not, NaN is only returned in case of an error - */ -float atoff(const char *param) { -static char todofixthismesswithcopy[100]; - - uint32_t totallen = strlen(param); - if (totallen > sizeof(todofixthismesswithcopy) - 1) - return (float) NAN; - strcpy(todofixthismesswithcopy, param); - char *string = todofixthismesswithcopy; - if (indexOf(string, 'n') != -1 || indexOf(string, 'N') != -1) { -#if ! EFI_SIMULATOR - efiPrintf("NAN from [%s]", string); -#endif - return (float) NAN; - } - - // todo: is there a standard function? - // unit-tested by 'testMisc()' - int dotIndex = indexOf(string, '.'); - if (dotIndex == -1) { - // just an integer - int result = atoi(string); - if (absI(result) == ATOI_ERROR_CODE) - return (float) NAN; - return (float) result; - } - // todo: this needs to be fixed - string[dotIndex] = 0; - int integerPart = atoi(string); - if (absI(integerPart) == ATOI_ERROR_CODE) - return (float) NAN; - string += (dotIndex + 1); - int decimalLen = strlen(string); - int decimal = atoi(string); - if (absI(decimal) == ATOI_ERROR_CODE) - return (float) NAN; - float divider = 1.0; - // todo: reuse 'pow10' function which we have anyway - for (int i = 0; i < decimalLen; i++) { - divider = divider * 10.0; - } - return integerPart + decimal / divider; -} diff --git a/firmware/util/efistringutil.h b/firmware/util/efistringutil.h deleted file mode 100644 index 2919c7e4f4..0000000000 --- a/firmware/util/efistringutil.h +++ /dev/null @@ -1,21 +0,0 @@ -#define ATOI_ERROR_CODE 311223344 - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#define TO_LOWER(x) (((x)>='A' && (x)<='Z') ? (x) - 'A' + 'a' : (x)) - -// todo: do we even need? does 'strlen' just work like we use it in cli_registry? -uint32_t efiStrlen(const char *param); - -int indexOf(const char *string, char ch); -bool strEqualCaseInsensitive(const char *str1, const char *str2); -bool strEqual(const char *str1, const char *str2); -int atoi(const char *string); -float atoff(const char *string); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ diff --git a/firmware/util/util.mk b/firmware/util/util.mk index b382b52c9c..c71723a71c 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -6,7 +6,6 @@ UTILSRC = \ UTILSRC_CPP = \ $(UTIL_DIR)/histogram.cpp \ $(UTIL_DIR)/efitime.cpp \ - $(UTIL_DIR)/efistringutil.cpp \ $(UTIL_DIR)/containers/listener_array.cpp \ $(UTIL_DIR)/containers/local_version_holder.cpp \ $(UTIL_DIR)/math/biquad.cpp \