Skip to content

removing namespaces that may cause name clashes #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions extras/test/src/time/test_TimedAttempt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <Arduino.h>
#include <limits.h>

using namespace arduino::tattempt;

SCENARIO("Test broker connection retries") {
TimedAttempt _connection_attempt(0,0);

Expand Down
2 changes: 1 addition & 1 deletion src/Arduino_HEX.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
#pragma once

#include "./hex/hex.h"

using namespace arduino;
using namespace hex;
2 changes: 0 additions & 2 deletions src/Arduino_SHA256.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@
#pragma once

#include "./sha256/SHA256.h"
using namespace arduino;
using namespace sha256;
2 changes: 0 additions & 2 deletions src/Arduino_TimedAttempt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@
#pragma once

#include "./time/TimedAttempt.h"

using namespace arduino::tattempt;
28 changes: 13 additions & 15 deletions src/hex/hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ namespace arduino { namespace hex {
String encodeUpper(const uint8_t* in, uint32_t size);

bool decode(const String in, uint8_t* out, uint32_t size);
}} // arduino::hex

class THEXT {

public:
static inline String encode(const uint8_t* in, uint32_t size) {
return arduino::hex::encode(in, size);
}
static inline String encodeUpper(const uint8_t* in, uint32_t size) {
return arduino::hex::encodeUpper(in, size);
}

static inline bool decode(const String in, uint8_t* out, uint32_t size) {
return arduino::hex::decode(in, out, size);
}
class THEXT {
public:
static inline String encode(const uint8_t* in, uint32_t size) {
return arduino::hex::encode(in, size);
}
static inline String encodeUpper(const uint8_t* in, uint32_t size) {
return arduino::hex::encodeUpper(in, size);
}

};
static inline bool decode(const String in, uint8_t* out, uint32_t size) {
return arduino::hex::decode(in, out, size);
}

}} // arduino::hex
};
38 changes: 19 additions & 19 deletions src/sha256/SHA256.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ namespace arduino { namespace sha256 {
::acu_sha256(input, ilen, output);
}

class SHA256 {
public:
}} // arduino::sha256

static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;
class SHA256 {
public:

inline void begin() {
return arduino::sha256::begin(&_ctx);
}
inline void update(uint8_t const * data, uint32_t const len) {
return arduino::sha256::update(&_ctx, data, len);
}
inline void finalize(uint8_t * hash) {
return arduino::sha256::finalize(&_ctx, hash);
}
static inline void sha256(uint8_t const * data, uint32_t const len, uint8_t * hash) {
return arduino::sha256::sha256(data, len, hash);
}
static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;

private:
inline void begin() {
return arduino::sha256::begin(&_ctx);
}
inline void update(uint8_t const * data, uint32_t const len) {
return arduino::sha256::update(&_ctx, data, len);
}
inline void finalize(uint8_t * hash) {
return arduino::sha256::finalize(&_ctx, hash);
}
static inline void sha256(uint8_t const * data, uint32_t const len, uint8_t * hash) {
return arduino::sha256::sha256(data, len, hash);
}

acu_sha256_ctx _ctx;
};
private:

}} // arduino::sha256
acu_sha256_ctx _ctx;
};
124 changes: 60 additions & 64 deletions src/time/TimedAttempt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,63 @@
#include <Arduino.h>
#include "TimedAttempt.h"

namespace arduino { namespace tattempt {

TimedAttempt::TimedAttempt(unsigned long minDelay, unsigned long maxDelay)
: _minDelay(minDelay)
, _maxDelay(maxDelay) {
}

void TimedAttempt::begin(unsigned long delay) {
_retryCount = 0;
_retryDelay = 0;
_retryTick = 0;
_minDelay = delay;
_maxDelay = delay;
}

void TimedAttempt::begin(unsigned long minDelay, unsigned long maxDelay) {
_retryCount = 0;
_retryDelay = 0;
_retryTick = 0;
_minDelay = minDelay;
_maxDelay = maxDelay;
}

unsigned long TimedAttempt::reconfigure(unsigned long minDelay, unsigned long maxDelay) {
_minDelay = minDelay;
_maxDelay = maxDelay;
return reload();
}

unsigned long TimedAttempt::retry() {
_retryCount++;
return reload();
}

unsigned long TimedAttempt::reload() {
unsigned long shift = _retryCount > 31 ? 31 : _retryCount;
unsigned long delay = (1UL << shift) * _minDelay;
/* delay should always increase */
_retryDelay = (delay > _retryDelay) ? min(delay, _maxDelay): _maxDelay;
_retryTick = millis();
return _retryDelay;
}

void TimedAttempt::reset() {
_retryCount = 0;
}

bool TimedAttempt::isRetry() {
return _retryCount > 0;
}

bool TimedAttempt::isExpired() {
return millis() - _retryTick > _retryDelay;
}

unsigned int TimedAttempt::getRetryCount() {
return _retryCount;
}

unsigned int TimedAttempt::getWaitTime() {
return _retryDelay;
}

}} // arduino::tattempt
TimedAttempt::TimedAttempt(unsigned long minDelay, unsigned long maxDelay)
: _minDelay(minDelay)
, _maxDelay(maxDelay) {
}

void TimedAttempt::begin(unsigned long delay) {
_retryCount = 0;
_retryDelay = 0;
_retryTick = 0;
_minDelay = delay;
_maxDelay = delay;
}

void TimedAttempt::begin(unsigned long minDelay, unsigned long maxDelay) {
_retryCount = 0;
_retryDelay = 0;
_retryTick = 0;
_minDelay = minDelay;
_maxDelay = maxDelay;
}

unsigned long TimedAttempt::reconfigure(unsigned long minDelay, unsigned long maxDelay) {
_minDelay = minDelay;
_maxDelay = maxDelay;
return reload();
}

unsigned long TimedAttempt::retry() {
_retryCount++;
return reload();
}

unsigned long TimedAttempt::reload() {
unsigned long shift = _retryCount > 31 ? 31 : _retryCount;
unsigned long delay = (1UL << shift) * _minDelay;
/* delay should always increase */
_retryDelay = (delay > _retryDelay) ? min(delay, _maxDelay): _maxDelay;
_retryTick = millis();
return _retryDelay;
}

void TimedAttempt::reset() {
_retryCount = 0;
}

bool TimedAttempt::isRetry() {
return _retryCount > 0;
}

bool TimedAttempt::isExpired() {
return millis() - _retryTick > _retryDelay;
}

unsigned int TimedAttempt::getRetryCount() {
return _retryCount;
}

unsigned int TimedAttempt::getWaitTime() {
return _retryDelay;
}
Loading
Loading