Mirror of espurna firmware for wireless switches and more
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

1 year ago
  1. /*
  2. UTILS MODULE
  3. Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #pragma once
  6. #include <Arduino.h>
  7. #include "types.h"
  8. String prettyDuration(espurna::duration::Seconds);
  9. bool sslCheckFingerPrint(const char * fingerprint);
  10. bool sslFingerPrintArray(const char * fingerprint, unsigned char * bytearray);
  11. bool sslFingerPrintChar(const char * fingerprint, char * destination);
  12. char* strnstr(const char* buffer, const char* token, size_t n);
  13. bool isNumber(espurna::StringView);
  14. double roundTo(double num, unsigned char positions);
  15. bool almostEqual(double lhs, double rhs, int ulp);
  16. bool almostEqual(double lhs, double rhs);
  17. struct ParseUnsignedResult {
  18. bool ok;
  19. uint32_t value;
  20. };
  21. ParseUnsignedResult parseUnsigned(espurna::StringView, int base);
  22. ParseUnsignedResult parseUnsigned(espurna::StringView);
  23. String formatUnsigned(uint32_t value, int base);
  24. char* hexEncode(const uint8_t* in_begin, const uint8_t* in_end, char* out_begin, char* out_end);
  25. size_t hexEncode(const uint8_t* in, size_t in_size, char* out, size_t out_size);
  26. String hexEncode(const uint8_t* begin, const uint8_t* end);
  27. template <size_t Size>
  28. inline String hexEncode(const uint8_t (&data)[Size]) {
  29. return hexEncode(std::begin(data), std::end(data));
  30. }
  31. template <size_t Size>
  32. inline String hexEncode(const std::array<uint8_t, Size>& data) {
  33. return hexEncode(data.data(), data.data() + data.size());
  34. }
  35. inline String hexEncode(uint8_t value) {
  36. uint8_t buffer[1] { value };
  37. return hexEncode(buffer);
  38. }
  39. uint8_t* hexDecode(const char* in_begin, const char* in_end, uint8_t* out_begin, uint8_t* out_end);
  40. size_t hexDecode(const char* in, size_t in_size, uint8_t* out, size_t out_size);
  41. bool tryParseId(espurna::StringView, size_t limit, size_t& out);
  42. bool tryParseIdPath(espurna::StringView, size_t limit, size_t& out);
  43. espurna::StringView stripNewline(espurna::StringView);
  44. size_t consumeAvailable(Stream&);