diff options
author | David Crocker <dcrocker@eschertech.com> | 2018-06-23 13:45:38 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2018-06-23 13:45:38 +0300 |
commit | 4a525abb1663ab4817b303501d59760f36eb9ea7 (patch) | |
tree | 06c3c18608e33483c7aec1bb052cf4b901d42404 /src/Libraries | |
parent | 5db504363ecf7a00c2f1a687cadb29bda47c7f1e (diff) |
Version 2.01beta1
Bug fixes:
- When using a mixing extruder, the feed rate for extruder-only moves was incorrect
- If additional axes were not created in the order UVWABC then incorrect homing files might be run (thanks chrishamm)
- On the Duet Maestro, the 7th stepper step/dir pin numbers were swapped
- If you paused a print during a G2/G3 arc move, on resuming it the arc centre was at the wrong place. This release defers the pause until the arc move is completed.
- If a command that interrogated the network (e.g. M122 on the Duet WiFi) was sent from USB, PanelDue or another non-network channel, the network subsystem could be accessed by multiple tasks concurrently, causing network disconnections or other errors
- When using a bltouch, between probe points the pin retracted, deployed and retracted again
- M206 with no parameters didn't report the current axis offsets
- During heating, the firmware returned M408 S0 responses to the PanelDue port even if the last request was M408 S2
- Fixed VBUS detection (thanks chrishamm)
- If the resume threshold in the M911 command was set higher than the supply voltage then the save-on-power-off mechanism never got primed. It will now prime at thwe auto-save threshold plus 0.5V or the resume threshold, whichever is lower.
- Fixed "2dtstc2diva=u" in debug printout
- Where a G- or M-code command parameter was supposed to accept unsigned values only, if a negative value was supplied then it was accepted and converted to a large unsigned value
New features and changed behaviour:
- If the firmware gets stuck in a spin loop, the RTOS builds now discard LR and 16 stack dwords in order to get more useful information from the stack trace
- Increased M999 delay to 1 second
- The report generated by M122 now includes a list of mutexes and their owners
- Added SW_ENC pin on CONN_SD to available GPIO ports (thanks chrishamm)
Diffstat (limited to 'src/Libraries')
-rw-r--r-- | src/Libraries/General/SafeStrtod.cpp | 44 | ||||
-rw-r--r-- | src/Libraries/General/SafeStrtod.h | 11 | ||||
-rw-r--r-- | src/Libraries/General/SafeVsnprintf.cpp | 19 | ||||
-rw-r--r-- | src/Libraries/General/StringRef.h | 17 |
4 files changed, 70 insertions, 21 deletions
diff --git a/src/Libraries/General/SafeStrtod.cpp b/src/Libraries/General/SafeStrtod.cpp index 0701bc72..1c27a01f 100644 --- a/src/Libraries/General/SafeStrtod.cpp +++ b/src/Libraries/General/SafeStrtod.cpp @@ -4,18 +4,22 @@ * Created on: 4 Apr 2018 * Author: David * - * This is a replacement for strtof() in the C standard library. That version has two problems: + * This is a replacement for strtod() and strtof() in the C standard library. Those versions have two problems: * 1. It is not reentrant. We can make it so by defining configUSE_NEWLIB_REENTRANT in FreeRTOS, but that makes the tasks much bigger. * 2. It allocates and releases heap memory, which is not nice. * * Limitations of this version * 1. Rounding to nearest double may not always be correct. - * 2. May not handle overflow for stupidly large numbers correctly. + * 2. Does not handle overflow for stupidly large numbers correctly. */ #include <cctype> #include <cmath> #include <climits> +#include <cstdlib> + +#include "SafeStrtod.h" +#undef strtoul // Undo the macro definition of strtoul in SafeStrtod.h so that we can call it in this file double SafeStrtod(const char *s, const char **p) { @@ -131,4 +135,40 @@ float SafeStrtof(const char *s, const char **p) return (float)SafeStrtod(s, p); } +unsigned long SafeStrtoul(const char *s, const char **endptr, int base) +{ + // strtoul() accepts a leading minus-sign, which we don't want to allow + while (*s == ' ' || *s == '\t') + { + ++s; + } + if (*s == '-') + { + if (endptr != nullptr) + { + *endptr = s; + } + return 0; + } + return strtoul(s, const_cast<char**>(endptr), base); +} + +unsigned long SafeStrtoul(char *s, char **endptr, int base) +{ + // strtoul() accepts a leading minus-sign, which we don't want to allow + while (*s == ' ' || *s == '\t') + { + ++s; + } + if (*s == '-') + { + if (endptr != nullptr) + { + *endptr = s; + } + return 0; + } + return strtoul(s, endptr, base); +} + // End diff --git a/src/Libraries/General/SafeStrtod.h b/src/Libraries/General/SafeStrtod.h index ae83228c..d1dc1d5c 100644 --- a/src/Libraries/General/SafeStrtod.h +++ b/src/Libraries/General/SafeStrtod.h @@ -16,15 +16,8 @@ inline long SafeStrtol(const char *s, const char **endptr = nullptr, int base = return strtol(s, const_cast<char**>(endptr), base); } -inline unsigned long SafeStrtoul(const char *s, const char **endptr = nullptr, int base = 10) -{ - return strtoul(s, const_cast<char**>(endptr), base); -} - -inline unsigned long SafeStrtoul(char *s, char **endptr = nullptr, int base = 10) -{ - return strtoul(s, endptr, base); -} +unsigned long SafeStrtoul(const char *s, const char **endptr = nullptr, int base = 10); +unsigned long SafeStrtoul(char *s, char **endptr = nullptr, int base = 10); #define strtod(s, p) Do_not_use_strtod_use_SafeStrtod_instead #define strtof(s, p) Do_not_use_strtof_use_SafeStrtof_instead diff --git a/src/Libraries/General/SafeVsnprintf.cpp b/src/Libraries/General/SafeVsnprintf.cpp index 0952c243..9b171ce0 100644 --- a/src/Libraries/General/SafeVsnprintf.cpp +++ b/src/Libraries/General/SafeVsnprintf.cpp @@ -15,7 +15,7 @@ Changes for the FreeRTOS ports: - The dot in "%-8.8s" - - The specifiers 'l' (long) and 'L' (long long) + - The specifiers 'l' (long) and 'll' (long long) - The specifier 'u' for unsigned - Dot notation for IP addresses: sprintf("IP = %xip\n", 0xC0A80164); @@ -546,14 +546,15 @@ static void tiny_print(SStringBuf& apBuf, const char *format, va_list args) if (ch == 'l') { ch = *format++; - apBuf.flags.long32 = 1; - // Makes no difference as u32 == long - } - if (ch == 'L') - { - ch = *format++; - apBuf.flags.long64 = 1; - // Does make a difference + if (ch == 'l') + { + ch = *format++; + apBuf.flags.long64 = 1; + } + else + { + apBuf.flags.long32 = 1; + } } if (ch == 'f' || ch == 'e' || ch == 'F' || ch == 'E') diff --git a/src/Libraries/General/StringRef.h b/src/Libraries/General/StringRef.h index d6d84a31..74a52ddd 100644 --- a/src/Libraries/General/StringRef.h +++ b/src/Libraries/General/StringRef.h @@ -54,7 +54,7 @@ public: const char *c_str() const { return storage; } size_t strlen() const { return Strnlen(storage, Len); } bool IsEmpty() const { return storage[0] == 0; } -// char *Pointer() { return storage; } + bool IsFull() const { return strlen() == Len; } char& operator[](size_t index) { return storage[index]; } char operator[](size_t index) const { return storage[index]; } constexpr size_t Capacity() const { return Len; } @@ -74,6 +74,7 @@ public: bool ConstantTimeEquals(String<Len> other) const; void Truncate(size_t len); + void Erase(size_t pos, size_t count = 1); private: char storage[Len + 1]; @@ -133,6 +134,20 @@ template<size_t Len> void String<Len>::Truncate(size_t len) } } +template<size_t Len> void String<Len>::Erase(size_t pos, size_t count) +{ + const size_t len = strlen(); + if (pos < len) + { + while (pos + count < len) + { + storage[pos] = storage[pos + count]; + ++pos; + } + storage[pos] = 0; + } +} + template<size_t Len> bool String<Len>::EndsWith(char c) const { const size_t len = strlen(); |