mirror of https://github.com/ARMmbed/mbed-os.git
CpuUid: to save memory, overloaded type cast std::string operator uses minimal implementation instead of snprintf
parent
eb9910c509
commit
3406ff262f
|
@ -14,7 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include "hal/cpu_uid_api.h"
|
#include "hal/cpu_uid_api.h"
|
||||||
#include "drivers/CpuUid.h"
|
#include "drivers/CpuUid.h"
|
||||||
|
|
||||||
|
@ -22,6 +21,8 @@
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
|
const char CpuUid::_hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||||
|
|
||||||
CpuUid::CpuUid() : _data(NULL)
|
CpuUid::CpuUid() : _data(NULL)
|
||||||
{
|
{
|
||||||
_size = cpu_uid_get_length();
|
_size = cpu_uid_get_length();
|
||||||
|
@ -43,12 +44,11 @@ CpuUid::~CpuUid()
|
||||||
CpuUid::operator std::string()
|
CpuUid::operator std::string()
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
char buf[3];
|
|
||||||
|
|
||||||
for (int i = 0; i < _size; ++i)
|
for (int i = 0; i < _size; ++i)
|
||||||
{
|
{
|
||||||
snprintf(buf, 3, "%.2X", _data[i]);
|
str += _hexChars[_data[i] >> 4];
|
||||||
str += buf;
|
str += _hexChars[_data[i] & 0x0F];
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -87,6 +87,8 @@ public:
|
||||||
private:
|
private:
|
||||||
uint8_t * _data;
|
uint8_t * _data;
|
||||||
int _size;
|
int _size;
|
||||||
|
|
||||||
|
static const char _hexChars[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
Loading…
Reference in New Issue