feurig - I must admit, I tend to be conservative, and avoid complexity.
I am not super keen on that String implementation for this application. It isn't C++ string
or basic_string
, and seems much more sophisticated and complex than necessary. I am not keen on deriving from 'printable' class in a simple environment which lacks a robust file abstraction, and its use in many places in that code seems to be purely to get something printable. I'd try to avoid that.
WARNING - IIRC, malloc/realloc might not be set up properly on Maple, but I'd need to go check.
Scanning the Wirefree code, it will be work to remove String. So, if String does work, it may be best left in place in order to make progress.
Looking at WireFree's source (*.cpp), there are 35 uses of 'String'.
1 is a comment
4 are printable messages containing the word String.
13 are definitions of functions which take a String as an argument.
Of the remainder a lot of the uses of String are just to make something printable (8+).
In some places it concatenate several strings so that println can be called once, which would be unnecessary if String returned a const
pointer to its buffer (like C++ string c_str).
So all the machinery of that String implementation is being used to create a String, concatenate a value, print it, then destroy the String, and garbage collect the free'd space when it goes out of scope, just to avoid saying, e.g.
Serial1.println(cmd_tbl[cmd].cmd_str); Serial1.println(this->security_key);
A lot of the other uses of String are equivalent to strncmp()
. Others are concatenating a character onto the buffer.
So an adequate replacement for String might be very light-weight.
I'm not a big fan of converting things like 16bit IP port numbers into strings, IP addresses into strings, etc. I tend to try to encapsulate the semantics into a class (e.g. a URL might be a string or an IP address) rather than squish stuff into a type (like a String) which can later be used to reconstitute the semantics. But that is probably not worth any effort.
Possible approach:
Test String, and if it works, try to get Wirefree working with String.
Then add a (const char *) cast to String, so that String isn't needed just to print an array of char, and then ditch that print code.
Maybe build a wrapper which would unify Serial1 & Serial, so that the most of Wirefree doesn't care which MCU it is being compiled for.
If I could find the time and energy, I might replace that big, smart String, and build a small, light-weight string that is free-standing, and independent of the ability to print, but that seems like a lot of work for little benefit.
Just a comment: the only links found by Search on the Wiring site for WString are to bugs in a destructor which took about three weeks to fix. I downloaded the code, and can't find any unit tests for String, which saddens me.
Summary:
Test that String works. If it does, then get Wirefree working using it.
If you folks have the energy, consider unifying the output class (Serial & Serial1) so that Wirefree doesn't conditionally compile for two different boards. That appears to be a real improvement. Once that is done, replace the uses of String where its only behaviour is to print text.