updated uuid libs

This commit is contained in:
Proddy
2023-01-05 15:05:30 +01:00
parent 6370296c53
commit 3b196fc90d
27 changed files with 2013 additions and 1411 deletions

View File

@@ -1,71 +0,0 @@
/*
* EMS-ESP - https://github.com/emsesp/EMS-ESP
* Copyright 2020 Paul Derbyshire
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uuid/common.h>
// #ifdef ESP8266
// #include <pgmspace.h>
// #else
// #include <avr/pgmspace.h>
// #endif
#include <Arduino.h>
namespace uuid {
// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.
// class __FlashStringHelper;
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b) {
const char * aa = reinterpret_cast<const char *>(a);
const char * bb = reinterpret_cast<const char *>(b);
while (true) {
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb)
return (int)ca - (int)cb;
if (ca == 0)
return 0;
aa++;
bb++;
}
}
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b, size_t n) {
const char * aa = reinterpret_cast<const char *>(a);
const char * bb = reinterpret_cast<const char *>(b);
while (n > 0) {
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb)
return (int)ca - (int)cb;
if (ca == 0)
return 0;
aa++;
bb++;
n--;
}
return 0;
}
} // namespace uuid

View File

@@ -22,7 +22,7 @@
namespace uuid {
// added by proddy, modified
// added by proddy for EMS-ESP
static uint64_t now_millis = 0;
// returns system uptime in seconds

View File

@@ -1,39 +0,0 @@
/*
* uuid-common - Microcontroller common utilities
* Copyright 2019 Simon Arlott
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uuid/common.h>
#include <Arduino.h>
#include <string>
namespace uuid {
std::string read_flash_string(const __FlashStringHelper * flash_str) {
if (flash_str == nullptr) {
return std::string(""); // prevent crash
}
std::string str(::strlen_P(reinterpret_cast<PGM_P>(flash_str)), '\0');
::strncpy_P(&str[0], reinterpret_cast<PGM_P>(flash_str), str.capacity() + 1);
return str;
}
} // namespace uuid

View File

@@ -26,6 +26,20 @@
#include <string>
#include <vector>
#ifndef UUID_COMMON_STD_MUTEX_AVAILABLE
#if __has_include(<mutex>) && (!defined(_GLIBCXX_MUTEX) || defined(_GLIBCXX_HAS_GTHREADS))
#define UUID_COMMON_STD_MUTEX_AVAILABLE 1
#else
#define UUID_COMMON_STD_MUTEX_AVAILABLE 0
#endif
#endif
#if defined(ARDUINO_ARCH_ESP32) || UUID_COMMON_STD_MUTEX_AVAILABLE
#define UUID_COMMON_THREAD_SAFE 1
#else
#define UUID_COMMON_THREAD_SAFE 0
#endif
/**
* Common utilities.
*
@@ -35,31 +49,15 @@
namespace uuid {
/**
* String compare two flash strings
* Thread-safe status of the library.
*
* The flash string must be stored with appropriate alignment for
* reading it on the platform.
*
* @param[in] a Pointer to string stored in flash.
* @param[in] b Pointer to string stored in flash.
* @param[in] n optional max length
* @return 0 for match, otherwise diff
* @since 1.0.0
* @since 1.1.2
*/
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b);
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b, size_t n);
/**
* Read a string from flash and convert it to a std::string.
*
* The flash string must be stored with appropriate alignment for
* reading it on the platform.
*
* @param[in] flash_str Pointer to string stored in flash.
* @return A string copy of the flash string.
* @since 1.0.0
*/
std::string read_flash_string(const __FlashStringHelper * flash_str);
#if UUID_COMMON_THREAD_SAFE
static constexpr bool thread_safe = true;
#else
static constexpr bool thread_safe = false;
#endif
/**
* Append to a std::string by printing a Printable object.
@@ -104,8 +102,8 @@ void loop();
*/
uint64_t get_uptime_ms();
uint32_t get_uptime(); // added by proddy
uint32_t get_uptime_sec(); // added by proddy
uint32_t get_uptime(); // added by proddy for EMS-ESP
uint32_t get_uptime_sec(); // added by proddy for EMS-ESP
void set_uptime();